Open yfhk opened 6 years ago
// IsChannelRestricted returns whether this GossipMessage should be routed // only in its channel func (m *GossipMessage) IsChannelRestricted() bool { return m.Tag == GossipMessage_CHAN_AND_ORG || m.Tag == GossipMessage_CHAN_ONLY || m.Tag == GossipMessage_CHAN_OR_ORG }
fabric/gossip/gossip/gossip_impl.go
func (g *gossipServiceImpl) handleMessage(m proto.ReceivedMessage) { if g.toDie() { return }
if m == nil || m.GetGossipMessage() == nil {
return
}
msg := m.GetGossipMessage()
g.logger.Debug("Entering,", m.GetConnectionInfo(), "sent us", msg)
defer g.logger.Debug("Exiting")
if !g.validateMsg(m) {
g.logger.Warning("Message", msg, "isn't valid")
return
}
if msg.IsChannelRestricted() {
if gc := g.chanState.lookupChannelForMsg(m); gc == nil {
// If we're not in the channel, we should still forward to peers of our org
// in case it's a StateInfo message
if g.isInMyorg(discovery.NetworkMember{ERC20ADDR: m.GetConnectionInfo().ID}) && msg.IsStateInfoMsg() {
if g.stateInfoMsgStore.Add(msg) {
g.emitter.Add(&emittedGossipMessage{
SignedGossipMessage: msg,
filter: m.GetConnectionInfo().ID.IsNotSameFilter,
})
}
}
if !g.toDie() {
g.logger.Debug("No such channel", msg.Channel, "discarding message", msg)
}
// Gossip sends a message to other peers to the network func (g gossipServiceImpl) Gossip(msg proto.GossipMessage) { // Educate developers to Gossip messages with the right tags. // See IsTagLegal() for wanted behavior. if err := msg.IsTagLegal(); err != nil { panic(errors.WithStack(err)) }
sMsg := &proto.SignedGossipMessage{
GossipMessage: msg,
}
var err error
if sMsg.IsDataMsg() {
sMsg, err = sMsg.NoopSign()
} else {
_, err = sMsg.Sign(func(msg []byte) ([]byte, error) {
return g.mcs.Sign(msg)
})
}
if err != nil {
g.logger.Warningf("Failed signing message: %+v", errors.WithStack(err))
return
}
if msg.IsChannelRestricted() {
gc := g.chanState.getGossipChannelByChainID(msg.Channel)
if gc == nil {
g.logger.Warning("Failed obtaining gossipChannel of", msg.Channel, "aborting")
return
}
if msg.IsDataMsg() {
gc.AddToMsgStore(sMsg)
}
}
http://wutongtree.github.io/translations/Kafka-based-Ordering-Service_zh 从这个里面的图可以看出,OSN不用relay给其他的order节点
// Fetcher interface which defines API to fetch missing // private data elements type Fetcher interface { fetch(dig2src dig2sources) ([]*gossip2.PvtDataElement, error) }