peering

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2021 License: Apache-2.0, BSD-2-Clause Imports: 15 Imported by: 1

Documentation

Overview

Package peering provides an overlay network for communicating between nodes in a peer-to-peer style with low overhead encoding and persistent connections. The network provides only the asynchronous communication.

It is intended to use for the committee consensus protocol.

Package peering provides an overlay network for communicating between nodes in a peer-to-peer style with low overhead encoding and persistent connections. The network provides only the asynchronous communication.

It is intended to use for the committee consensus protocol.

Package peering provides an overlay network for communicating between nodes in a peer-to-peer style with low overhead encoding and persistent connections. The network provides only the asynchronous communication.

It is intended to use for the committee consensus protocol.

Package peering provides an overlay network for communicating between nodes in a peer-to-peer style with low overhead encoding and persistent connections. The network provides only the asynchronous communication.

It is intended to use for the committee consensus protocol.

Index

Constants

View Source
const (
	// FirstUserMsgCode is the first committee message type.
	// All the equal and larger msg types are committee messages.
	// those with smaller are reserved by the package for heartbeat and handshake messages
	FirstUserMsgCode = byte(0x10)

	PeerMessageReceiverStateManager = byte(iota)
	PeerMessageReceiverConsensus
	PeerMessageReceiverCommonSubset
	PeerMessageReceiverChain
	PeerMessageReceiverDkg
	PeerMessageReceiverDkgInit
)

Variables

This section is empty.

Functions

func CheckMyNetID

func CheckMyNetID(myNetID string, configPort int) error

CheckMyNetID checks if NetID from the committee list represents current node.

func CheckNetID added in v0.2.0

func CheckNetID(netID string) error

Check, if NetID is of proper format.

func ParseNetID added in v0.2.0

func ParseNetID(netID string) (string, int, error)

ParseNetID parses the NetID and returns the corresponding host and port.

Types

type GroupProvider

type GroupProvider interface {
	SelfIndex() uint16
	PeerIndex(peer PeerSender) (uint16, error)
	PeerIndexByNetID(peerNetID string) (uint16, error)
	NetIDByIndex(index uint16) (string, error)
	Attach(receiver byte, callback func(recv *PeerMessageGroupIn)) interface{}
	Detach(attachID interface{})
	SendMsgByIndex(peerIdx uint16, msgReceiver byte, msgType byte, msgData []byte)
	SendMsgBroadcast(msgReceiver byte, msgType byte, msgData []byte, except ...uint16)
	ExchangeRound(
		peers map[uint16]PeerSender,
		recvCh chan *PeerMessageIn,
		retryTimeout time.Duration,
		giveUpTimeout time.Duration,
		sendCB func(peerIdx uint16, peer PeerSender),
		recvCB func(recv *PeerMessageGroupIn) (bool, error),
	) error
	AllNodes(except ...uint16) map[uint16]PeerSender   // Returns all the nodes in the group except specified.
	OtherNodes(except ...uint16) map[uint16]PeerSender // Returns other nodes in the group (excluding Self and specified).
	Close()
}

GroupProvider stands for a subset of a peer-to-peer network that is responsible for achieving some common goal, eg, consensus committee, DKG group, etc.

Indexes are only meaningful in the groups, not in the network or a particular peers.

type NetworkProvider

type NetworkProvider interface {
	Run(stopCh <-chan struct{})
	Self() PeerSender
	PeerGroup(peeringID PeeringID, peerAddrs []string) (GroupProvider, error)
	PeerDomain(peeringID PeeringID, peerAddrs []string) (PeerDomainProvider, error)
	PeerByNetID(peerNetID string) (PeerSender, error)
	PeerByPubKey(peerPub *ed25519.PublicKey) (PeerSender, error)
	PeerStatus() []PeerStatusProvider
	Attach(peeringID *PeeringID, receiver byte, callback func(recv *PeerMessageIn)) interface{}
	Detach(attachID interface{})
	SendMsgByNetID(netID string, msg *PeerMessageData)
}

NetworkProvider stands for the peer-to-peer network, as seen from the viewpoint of a single participant.

type PeerDomainProvider added in v0.2.0

type PeerDomainProvider interface {
	ReshufflePeers(seedBytes ...[]byte)
	GetRandomPeers(upToNumPeers int) []string
	Attach(receiver byte, callback func(recv *PeerMessageIn)) interface{}
	Detach(attachID interface{})
	SendMsgByNetID(netID string, msgReceiver byte, msgType byte, msgData []byte)
	SendPeerMsgToRandomPeers(upToNumPeers int, msgReceiver byte, msgType byte, msgData []byte)
	Close()
}

PeerDomainProvider implements unordered set of peers which can dynamically change All peers in the domain shares same peeringID. Each peer within domain is identified via its netID

type PeerMessageData added in v0.2.3

type PeerMessageData struct {
	PeeringID   PeeringID
	MsgReceiver byte
	MsgType     byte
	MsgData     []byte
}

PeerMessage is an envelope for all the messages exchanged via the peering module.

func NewPeerMessageDataFromBytes added in v0.2.3

func NewPeerMessageDataFromBytes(buf []byte) (*PeerMessageData, error)

type PeerMessageGroupIn added in v0.2.3

type PeerMessageGroupIn struct {
	PeerMessageIn
	SenderIndex uint16
}

type PeerMessageIn added in v0.2.3

type PeerMessageIn struct {
	PeerMessageData
	SenderNetID string
}

type PeerMessageNet added in v0.2.3

type PeerMessageNet struct {
	PeerMessageData
	// contains filtered or unexported fields
}

func NewPeerMessageNetFromBytes added in v0.2.3

func NewPeerMessageNetFromBytes(buf []byte) (*PeerMessageNet, error)

func (*PeerMessageNet) Bytes added in v0.2.3

func (m *PeerMessageNet) Bytes() ([]byte, error)

func (*PeerMessageNet) GetHash added in v0.2.3

func (m *PeerMessageNet) GetHash() hashing.HashValue

type PeerSender

type PeerSender interface {

	// NetID identifies the peer.
	NetID() string

	// PubKey of the peer is only available, when it is
	// authenticated, therefore it can return nil, if pub
	// key is not known yet. You can call await before calling
	// this function to ensure the public key is already resolved.
	PubKey() *ed25519.PublicKey

	// SendMsg works in an asynchronous way, and therefore the
	// errors are not returned here.
	SendMsg(msg *PeerMessageData)

	// IsAlive indicates, if there is a working connection with the peer.
	// It is always an approximate state.
	IsAlive() bool

	// Await for the connection to be established, handshaked, and the
	// public key resolved.
	Await(timeout time.Duration) error

	// Close releases the reference to the peer, this informs the network
	// implementation, that it can disconnect, cleanup resources, etc.
	// You need to get new reference to the peer (PeerSender) to use it again.
	Close()
}

PeerSender represents an interface to some remote peer.

type PeerStatusProvider

type PeerStatusProvider interface {
	NetID() string
	PubKey() *ed25519.PublicKey
	IsAlive() bool
	NumUsers() int
}

PeerStatusProvider is used to access the current state of the network peer without allocating it (increading usage counters, etc). This interface overlaps with the PeerSender, and most probably they both will be implemented by the same object.

type PeeringID added in v0.2.0

type PeeringID [ledgerstate.AddressLength]byte

PeeringID is relates peers in different nodes for a particular communication group. E.g. PeeringID identifies a committee in the consensus, etc.

func RandomPeeringID added in v0.2.0

func RandomPeeringID(seed ...[]byte) PeeringID

func (*PeeringID) Read added in v0.2.0

func (pid *PeeringID) Read(r io.Reader) error

func (*PeeringID) String added in v0.2.0

func (pid *PeeringID) String() string

func (*PeeringID) Write added in v0.2.0

func (pid *PeeringID) Write(w io.Writer) error

type StaticPeerNetworkConfig added in v0.2.0

type StaticPeerNetworkConfig struct {
	// contains filtered or unexported fields
}

StaticPeerNetworkConfig in an implementation of registry.PeerNetworkConfigProvider. It does not change Alternatively, the configuration of peers behind could change and be dependent on chain

func NewStaticPeerNetworkConfigProvider added in v0.2.0

func NewStaticPeerNetworkConfigProvider(ownNetID string, peeringPort int, neighbors ...string) (*StaticPeerNetworkConfig, error)

NewStaticPeerNetworkConfigProvider is a configuration of the peer environment which does not change

func (*StaticPeerNetworkConfig) Neighbors added in v0.2.0

func (p *StaticPeerNetworkConfig) Neighbors() []string

func (*StaticPeerNetworkConfig) OwnNetID added in v0.2.0

func (p *StaticPeerNetworkConfig) OwnNetID() string

func (*StaticPeerNetworkConfig) PeeringPort added in v0.2.0

func (p *StaticPeerNetworkConfig) PeeringPort() int

func (*StaticPeerNetworkConfig) String added in v0.2.0

func (p *StaticPeerNetworkConfig) String() string

type TrustedNetworkManager added in v0.2.0

type TrustedNetworkManager interface {
	IsTrustedPeer(pubKey ed25519.PublicKey) error
	TrustPeer(pubKey ed25519.PublicKey, netID string) (*TrustedPeer, error)
	DistrustPeer(pubKey ed25519.PublicKey) (*TrustedPeer, error)
	TrustedPeers() ([]*TrustedPeer, error)
}

TrustedNetworkManager is used maintain a configuration which peers are trusted. In a typical implementation, this interface should be implemented by the same struct, that implements the NetworkProvider. These implementations should interact, e.g. when we distrust some peer, all the connections to it should be cut immediately.

type TrustedPeer added in v0.2.0

type TrustedPeer struct {
	PubKey ed25519.PublicKey
	NetID  string
}

TrustedPeer carries a peer information we use to trust it.

func TrustedPeerFromBytes added in v0.2.0

func TrustedPeerFromBytes(buf []byte) (*TrustedPeer, error)

func (*TrustedPeer) Bytes added in v0.2.0

func (tp *TrustedPeer) Bytes() ([]byte, error)

func (*TrustedPeer) PubKeyBytes added in v0.2.0

func (tp *TrustedPeer) PubKeyBytes() ([]byte, error)

Directories

Path Synopsis
Package group implements a generic peering.GroupProvider.
Package group implements a generic peering.GroupProvider.
Package lpp implements a peering.NetworkProvider based on the libp2p.
Package lpp implements a peering.NetworkProvider based on the libp2p.

Jump to

Keyboard shortcuts

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