discovery

package
v1.4.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const DefAliveExpirationCheckInterval = DefAliveExpirationTimeout / 10
View Source
const DefAliveExpirationTimeout = 5 * DefAliveTimeInterval
View Source
const DefAliveTimeInterval = 5 * time.Second
View Source
const DefReconnectInterval = DefAliveExpirationTimeout

Variables

This section is empty.

Functions

func HasExternalEndpoint

func HasExternalEndpoint(member NetworkMember) bool

HaveExternalEndpoints selects network members that have external endpoints

func SetMaxConnAttempts

func SetMaxConnAttempts(attempts int)

SetMaxConnAttempts sets the maximum number of connection attempts the peer would perform when invoking Connect()

Types

type CommService

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
}

CommService is an interface that the discovery expects to be implemented and passed on creation

type CryptoService

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
}

CryptoService is an interface that the discovery expects to be implemented and passed on creation

type DisclosurePolicy

type DisclosurePolicy func(remotePeer *NetworkMember) (Sieve, EnvelopeFilter)

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 Discovery

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)
}

Discovery is the interface that represents a discovery module

func NewDiscoveryService

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

type DiscoveryConfig struct {
	AliveTimeInterval            time.Duration
	AliveExpirationTimeout       time.Duration
	AliveExpirationCheckInterval time.Duration
	ReconnectInterval            time.Duration
	BootstrapPeers               []string
}

type EnvelopeFilter

type EnvelopeFilter func(message *proto.SignedGossipMessage) *proto.Envelope

EnvelopeFilter may or may not remove part of the Envelope that the given SignedGossipMessage originates from.

type Members

type Members []NetworkMember

Members represents an aggregation of NetworkMembers

func (Members) ByID

func (members Members) ByID() map[string]NetworkMember

ByID returns a mapping from the PKI-IDs (in string form) to NetworkMember

func (Members) Filter

func (members Members) Filter(filter func(member NetworkMember) bool) Members

Filter returns only members that satisfy the given filter

func (Members) Intersect

func (members Members) Intersect(otherMembers Members) Members

Intersect returns the intersection of 2 Members

func (Members) Map

func (members Members) Map(f func(member NetworkMember) NetworkMember) Members

Map invokes the given function to every NetworkMember among the Members

type NetworkMember

type NetworkMember struct {
	Endpoint         string
	Metadata         []byte
	PKIid            common.PKIidType
	InternalEndpoint string
	Properties       *proto.Properties
	*proto.Envelope
}

NetworkMember is a peer's representation

func (NetworkMember) PreferredEndpoint

func (n NetworkMember) PreferredEndpoint() string

PreferredEndpoint computes the endpoint to connect to, while preferring internal endpoint over the standard endpoint

func (NetworkMember) String

func (n NetworkMember) String() string

String returns a string representation of the NetworkMember

type PeerIdentification

type PeerIdentification struct {
	ID      common.PKIidType
	SelfOrg bool
}

PeerIdentification encompasses a remote peer's PKI-ID and whether its in the same org as the current peer or not

type Sieve

type Sieve func(message *proto.SignedGossipMessage) 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL