const DefAliveExpirationCheckInterval = DefAliveExpirationTimeout / 10
const DefAliveExpirationTimeout = 5 * DefAliveTimeInterval
const DefAliveTimeInterval = 5 * time.Second
const DefReconnectInterval = DefAliveExpirationTimeout
func HasExternalEndpoint(member NetworkMember) bool
HaveExternalEndpoints selects network members that have external endpoints
func SetMaxConnAttempts(attempts int)
SetMaxConnAttempts sets the maximum number of connection attempts the peer would perform when invoking Connect()
CommService is an interface that the discovery expects to be implemented and passed on creation
type CommService interface { // Gossip gossips a message Gossip(msg *proto.SignedGossipMessage) // SendToPeer sends to a given peer a message. // The nonce can be anything since the communication module handles the nonce itself SendToPeer(peer *NetworkMember, msg *proto.SignedGossipMessage) // Ping probes a remote peer and returns if it's responsive or not Ping(peer *NetworkMember) bool // Accept returns a read-only channel for membership messages sent from remote peers Accept() <-chan proto.ReceivedMessage // PresumedDead returns a read-only channel for peers that are presumed to be dead PresumedDead() <-chan common.PKIidType // CloseConn orders to close the connection with a certain peer CloseConn(peer *NetworkMember) // Forward sends message to the next hop, excluding the hop // from which message was initially received Forward(msg proto.ReceivedMessage) // IdentitySwitch returns a read-only channel about identity change events IdentitySwitch() <-chan common.PKIidType }
CryptoService is an interface that the discovery expects to be implemented and passed on creation
type CryptoService interface { // ValidateAliveMsg validates that an Alive message is authentic ValidateAliveMsg(message *proto.SignedGossipMessage) bool // SignMessage signs a message SignMessage(m *proto.GossipMessage, internalEndpoint string) *proto.Envelope }
DisclosurePolicy defines which messages a given remote peer is eligible of knowing about, and also what is it eligible to know about out of a given SignedGossipMessage. Returns: 1) A Sieve for a given remote peer.
The Sieve is applied for each peer in question and outputs whether the message should be disclosed to the remote peer.
2) A EnvelopeFilter for a given SignedGossipMessage, which may remove
part of the Envelope the SignedGossipMessage originates from
type DisclosurePolicy func(remotePeer *NetworkMember) (Sieve, EnvelopeFilter)
Discovery is the interface that represents a discovery module
type Discovery interface { // Lookup returns a network member, or nil if not found Lookup(PKIID common.PKIidType) *NetworkMember // Self returns this instance's membership information Self() NetworkMember // UpdateMetadata updates this instance's metadata UpdateMetadata([]byte) // UpdateEndpoint updates this instance's endpoint UpdateEndpoint(string) // Stops this instance Stop() // GetMembership returns the alive members in the view GetMembership() []NetworkMember // InitiateSync makes the instance ask a given number of peers // for their membership information InitiateSync(peerNum int) // Connect makes this instance to connect to a remote instance // The identifier param is a function that can be used to identify // the peer, and to assert its PKI-ID, whether its in the peer's org or not, // and whether the action was successful or not Connect(member NetworkMember, id identifier) }
func NewDiscoveryService(self NetworkMember, comm CommService, crypt CryptoService, disPol DisclosurePolicy, config DiscoveryConfig) Discovery
NewDiscoveryService returns a new discovery service with the comm module passed and the crypto service passed
type DiscoveryConfig struct { AliveTimeInterval time.Duration AliveExpirationTimeout time.Duration AliveExpirationCheckInterval time.Duration ReconnectInterval time.Duration BootstrapPeers []string }
EnvelopeFilter may or may not remove part of the Envelope that the given SignedGossipMessage originates from.
type EnvelopeFilter func(message *proto.SignedGossipMessage) *proto.Envelope
Members represents an aggregation of NetworkMembers
type Members []NetworkMember
func (members Members) ByID() map[string]NetworkMember
ByID returns a mapping from the PKI-IDs (in string form) to NetworkMember
func (members Members) Filter(filter func(member NetworkMember) bool) Members
Filter returns only members that satisfy the given filter
func (members Members) Intersect(otherMembers Members) Members
Intersect returns the intersection of 2 Members
func (members Members) Map(f func(member NetworkMember) NetworkMember) Members
Map invokes the given function to every NetworkMember among the Members
NetworkMember is a peer's representation
type NetworkMember struct { Endpoint string Metadata []byte PKIid common.PKIidType InternalEndpoint string Properties *proto.Properties *proto.Envelope }
func (n NetworkMember) PreferredEndpoint() string
PreferredEndpoint computes the endpoint to connect to, while preferring internal endpoint over the standard endpoint
func (n NetworkMember) String() string
String returns a string representation of the NetworkMember
PeerIdentification encompasses a remote peer's PKI-ID and whether its in the same org as the current peer or not
type PeerIdentification struct { ID common.PKIidType SelfOrg bool }
Sieve defines the messages that are allowed to be sent to some remote peer, based on some criteria. Returns whether the sieve permits sending a given message.
type Sieve func(message *proto.SignedGossipMessage) bool