该文件位于fabric项目的gossip文件夹下子gossip目录下,主要定义gossip service相关接口规范定义,实现可见GossipServiceImpl.go文件中。
package gossip
// 定义Gossip组件的接口规范
// Gossip is the interface of the gossip component
type Gossip interface {
// 自身成员信息
// SelfMembershipInfo returns the peer's membership information
SelfMembershipInfo() discovery.NetworkMember
// 自身通道信息:通过给定的channel获取对等节点最新的状态细信息
// SelfChannelInfo returns the peer's latest StateInfo message of a given channel
SelfChannelInfo(common.ChainID) *proto.SignedGossipMessage
// 给远程的对等节点发送信息
// Send sends a message to remote peers
Send(msg *proto.GossipMessage, peers ...*comm.RemotePeer)
// 给所有符合发送条件的对等节点发送信息
// SendByCriteria sends a given message to all peers that match the given SendCriteria
SendByCriteria(*proto.SignedGossipMessage, SendCriteria) error
// 获取网络中还活着的成员
// GetPeers returns the NetworkMembers considered alive
Peers() []discovery.NetworkMember
// 获取指定channel的网络中还活着的成员
// PeersOfChannel returns the NetworkMembers considered alive
// and also subscribed to the channel given
PeersOfChannel(common.ChainID) []discovery.NetworkMember
// 更新发现层自身的元数据 再由该对等节点向其他对等节点发布
// UpdateMetadata updates the self metadata of the discovery layer
// the peer publishes to other peers
UpdateMetadata(metadata []byte)
// 更新对等节点账本的高度
// 通过指定的channel发布给其他对等节点
// UpdateLedgerHeight updates the ledger height the peer
// publishes to other peers in the channel
UpdateLedgerHeight(height uint64, chainID common.ChainID)
// 更新链码 该对等节点通过指定的channel发布给其他的对等节点
// UpdateChaincodes updates the chaincodes the peer publishes
// to other peers in the channel
UpdateChaincodes(chaincode []*proto.Chaincode, chainID common.ChainID)
// 向网络中其他对等节点发送信息
// Gossip sends a message to other peers to the network
Gossip(msg *proto.GossipMessage)
// 接受一个子通道选择条件,返回符合指定条件对等节点身份
// PeerFilter receives a SubChannelSelectionCriteria and returns a RoutingFilter that selects
// only peer identities that match the given criteria, and that they published their channel participation
PeerFilter(channel common.ChainID, messagePredicate api.SubChannelSelectionCriteria) (filter.RoutingFilter, error)
// 返回一个专用的只读通道 发送消息给符合特定判断的其他节点
// 当passThrough = false 消息有gossip层预先处理
// 当passThrough = true gossip层并不干涉,对应的消息能够发送一个回复给发送者
// Accept returns a dedicated read-only channel for messages sent by other nodes that match a certain predicate.
// If passThrough is false, the messages are processed by the gossip layer beforehand.
// If passThrough is true, the gossip layer doesn't intervene and the messages
// can be used to send a reply back to the sender
Accept(acceptor common.MessageAcceptor, passThrough bool) (<-chan *proto.GossipMessage, <-chan proto.ReceivedMessage)
// Gossip实例加入到channel
// JoinChan makes the Gossip instance join a channel
JoinChan(joinMsg api.JoinChannelMessage, chainID common.ChainID)
// Gossip实例离开channel,不过该实例仍能发布状态信息 不再参与block pull的操作 也不再返回channel的其他对等节点列表
// LeaveChan makes the Gossip instance leave a channel.
// It still disseminates stateInfo message, but doesn't participate
// in block pulling anymore, and can't return anymore a list of peers
// in the channel.
LeaveChan(chainID common.ChainID)
// gossip实例来验证可疑对等节点的身份,一旦发现对应的peer身份无效 则会关闭其连接
// SuspectPeers makes the gossip instance validate identities of suspected peers, and close
// any connections to peers with identities that are found invalid
SuspectPeers(s api.PeerSuspector)
// 返回已知对等节点的身份
// IdentityInfo returns information known peer identities
IdentityInfo() api.PeerIdentitySet
// 停止gossip组件
// Stop stops the gossip component
Stop()
}
// 组装gossip签名信息 在转发消息时提供给路由过滤器使用
// emittedGossipMessage encapsulates signed gossip message to compose
// with routing filter to be used while message is forwarded
type emittedGossipMessage struct {
*proto.SignedGossipMessage // 签名的Gossip信息
filter func(id common.PKIidType) bool // 过滤器根据指定公钥id来做筛选
}
// 定义如何发送一个消息(发送条件)
// SendCriteria defines how to send a specific message
type SendCriteria struct {
Timeout time.Duration // Timeout defines the time to wait for acknowledgements 发送信息后等待确认的时长
MinAck int // MinAck defines the amount of peers to collect acknowledgements from 定义收集确认信息的最小对等节点数
MaxPeers int // MaxPeers defines the maximum number of peers to send the message to 定义信息发送的最大对等节点数
IsEligible filter.RoutingFilter // IsEligible defines whether a specific peer is eligible of receiving the message 定义指定的对等节点是否符合接收信息的条件[通过routefilter筛选合适的对等节点]
Channel common.ChainID // Channel specifies a channel to send this message on. \ 指定发送信息的通道[联盟路是可以存在多个账本,不同账本需要不同的通道来传递接收;指定通道的消息只有加入到通道的对等节点才能接收信息]
// Only peers that joined the channel would receive this message
}
// 发送条件的字符串形式
// String returns a string representation of this SendCriteria
func (sc SendCriteria) String() string {
return fmt.Sprintf("channel: %s, tout: %v, minAck: %d, maxPeers: %d", sc.Channel, sc.Timeout, sc.MinAck, sc.MaxPeers)
}
// gossip组件的配置项
// Config is the configuration of the gossip component
type Config struct {
BindPort int // Port we bind to, used only for tests Gossip绑定的端口,仅用于测试环境
ID string // ID of this instance gossip的唯一标识ID
BootstrapPeers []string // Peers we connect to at startup 启动时连接的对等节点
PropagateIterations int // Number of times a message is pushed to remote peers 消息推送次数
PropagatePeerNum int // Number of peers selected to push messages to 消息推送节点数
MaxBlockCountToStore int // Maximum count of blocks we store in memory 区块缓冲区大小
MaxPropagationBurstSize int // Max number of messages stored until it triggers a push to remote peers 消息推送缓冲区大小: 默认10条消息
MaxPropagationBurstLatency time.Duration // Max time between consecutive message pushes 消息推送间隔(毫秒)
PullInterval time.Duration // Determines frequency of pull phases 消息获取间隔(毫秒)
PullPeerNum int // Number of peers to pull from 消息获取节点数
SkipBlockVerification bool // Should we skip verifying block messages or not 是否验证区块消息
PublishCertPeriod time.Duration // Time from startup certificates are included in Alive messages 存活消息中推送证书的周期(秒)
PublishStateInfoInterval time.Duration // Determines frequency of pushing state info messages to peers 状态消息推送间隔(秒)
RequestStateInfoInterval time.Duration // Determines frequency of pulling state info messages from peers 状态消息获取间隔(秒)
TLSCerts *common.TLSCertificates // TLS certificates of the peer peer节点tls证书
InternalEndpoint string // Endpoint we publish to peers in our organization 组织内部节点
ExternalEndpoint string // Peer publishes this endpoint instead of SelfEndpoint to foreign organizations 组织外部节点
}