代码拉取完成,页面将自动刷新
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package gossip
import (
"github.com/hyperledger/fabric/gossip/common"
"github.com/hyperledger/fabric/gossip/discovery"
gossip2 "github.com/hyperledger/fabric/gossip/gossip"
"github.com/hyperledger/fabric/protos/gossip"
)
// DiscoverySupport implements support that is used for service discovery
// that is obtained from gossip
type DiscoverySupport struct {
gossip2.Gossip
}
// NewDiscoverySupport creates a new DiscoverySupport
func NewDiscoverySupport(g gossip2.Gossip) *DiscoverySupport {
return &DiscoverySupport{g}
}
// ChannelExists returns whether a given channel exists or not
func (s *DiscoverySupport) ChannelExists(channel string) bool {
return s.SelfChannelInfo(common.ChainID(channel)) != nil
}
// PeersOfChannel returns the NetworkMembers considered alive
// and also subscribed to the channel given
func (s *DiscoverySupport) PeersOfChannel(chain common.ChainID) discovery.Members {
msg := s.SelfChannelInfo(chain)
if msg == nil {
return nil
}
stateInf := msg.GetStateInfo()
selfMember := discovery.NetworkMember{
Properties: stateInf.Properties,
PKIid: stateInf.PkiId,
Envelope: msg.Envelope,
}
return append(s.Gossip.PeersOfChannel(chain), selfMember)
}
// Peers returns the NetworkMembers considered alive
func (s *DiscoverySupport) Peers() discovery.Members {
peers := s.Gossip.Peers()
peers = append(peers, s.Gossip.SelfMembershipInfo())
// Return only the peers that have an external endpoint, and sanitizes the envelopes.
return discovery.Members(peers).Filter(discovery.HasExternalEndpoint).Map(sanitizeEnvelope)
}
func sanitizeEnvelope(member discovery.NetworkMember) discovery.NetworkMember {
// Make a local copy of the member
returnedMember := member
if returnedMember.Envelope == nil {
return returnedMember
}
returnedMember.Envelope = &gossip.Envelope{
Payload: member.Envelope.Payload,
Signature: member.Envelope.Signature,
}
return returnedMember
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。