首页
登录 | 注册

15.Fabric 1.0源代码分析(15)gossip(流言算法)

Fabric 1.0源代码笔记 之 gossip(流言算法) #GossipServer(Gossip服务端)

Fabric 1.0源代码笔记 之 Peer #committer(提交者)

5.2.5、func (s *GossipStateProviderImpl) listen()

func (s *GossipStateProviderImpl) listen() {
    defer s.done.Done()

    for {
        select {
        case msg := <-s.gossipChan:
            //处理从通道中其他节点分发的消息
            go s.queueNewMessage(msg)
        case msg := <-s.commChan:
            logger.Debug("Direct message ", msg)
            go s.directMessage(msg)
        case <-s.stopCh:
            s.stopCh <- struct{}{}
            return
        }
    }
}
//代码在gossip/state/state.go

go s.queueNewMessage(msg)代码如下:

func (s *GossipStateProviderImpl) queueNewMessage(msg *proto.GossipMessage) {
    dataMsg := msg.GetDataMsg()
    if dataMsg != nil {
        err := s.addPayload(dataMsg.GetPayload(), nonBlocking) //写入本地
    }
}
//代码在gossip/state/state.go

10、MessageCryptoService接口及实现

MessageCryptoService接口定义:消息加密服务。

type MessageCryptoService interface {
    //获取Peer身份的PKI ID(Public Key Infrastructure,公钥基础设施)
    GetPKIidOfCert(peerIdentity PeerIdentityType) common.PKIidType
    //校验块签名
    VerifyBlock(chainID common.ChainID, seqNum uint64, signedBlock []byte) error
    //使用Peer的签名密钥对消息签名
    Sign(msg []byte) ([]byte, error)
    //校验签名是否为有效签名
    Verify(peerIdentity PeerIdentityType, signature, message []byte) error
    //在特定通道下校验签名是否为有效签名
    VerifyByChannel(chainID common.ChainID, peerIdentity PeerIdentityType, signature, message []byte) error
    //校验Peer身份
    ValidateIdentity(peerIdentity PeerIdentityType) error
}
//代码在gossip/api/crypto.go

MessageCryptoService接口实现,即mspMessageCryptoService结构体及方法:

type mspMessageCryptoService struct {
    channelPolicyManagerGetter policies.ChannelPolicyManagerGetter //通道策略管理器,type ChannelPolicyManagerGetter interface
    localSigner                crypto.LocalSigner //本地签名者,type LocalSigner interface
    deserializer               mgmt.DeserializersManager //反序列化管理器,type DeserializersManager interface
}

//构造mspMessageCryptoService
func NewMCS(channelPolicyManagerGetter policies.ChannelPolicyManagerGetter, localSigner crypto.LocalSigner, deserializer mgmt.DeserializersManager) api.MessageCryptoService
//调取s.getValidatedIdentity(peerIdentity)
func (s *mspMessageCryptoService) ValidateIdentity(peerIdentity api.PeerIdentityType) error
func (s *mspMessageCryptoService) GetPKIidOfCert(peerIdentity api.PeerIdentityType) common.PKIidType
func (s *mspMessageCryptoService) VerifyBlock(chainID common.ChainID, seqNum uint64, signedBlock []byte) error
func (s *mspMessageCryptoService) Sign(msg []byte) ([]byte, error)
func (s *mspMessageCryptoService) Verify(peerIdentity api.PeerIdentityType, signature, message []byte) error
func (s *mspMessageCryptoService) VerifyByChannel(chainID common.ChainID, peerIdentity api.PeerIdentityType, signature, message []byte) error
func (s *mspMessageCryptoService) getValidatedIdentity(peerIdentity api.PeerIdentityType) (msp.Identity, common.ChainID, error)
//代码在peer/gossip/mcs.go



2020 jeepxie.net webmaster#jeepxie.net
10 q. 0.009 s.
京ICP备10005923号