peering

package
v0.7.0-alpha.4 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2023 License: Apache-2.0 Imports: 18 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)
	ReceiverStateManager = byte(iota)
	ReceiverConsensus
	ReceiverCommonSubset
	ReceiverChain
	ReceiverChainDSS
	ReceiverChainCons
	ReceiverDkg
	ReceiverDkgInit
	ReceiverMempool
	ReceiverAccessMgr
)

Variables

This section is empty.

Functions

func CheckMyPeeringURL added in v1.0.3

func CheckMyPeeringURL(myPeeringURL string, configPort int) error

CheckMyPeeringURL checks if PeeringURL from the committee list represents current node.

func CheckPeeringURL added in v1.0.3

func CheckPeeringURL(url string) error

Check, if peeringURL is of proper format.

func ParsePeeringURL added in v1.0.3

func ParsePeeringURL(url string) (string, int, error)

ParsePeeringURL parses the peeringURL and returns the corresponding host and port.

func ValidateTrustedPeerParams added in v1.0.3

func ValidateTrustedPeerParams(name string, pubKey *cryptolib.PublicKey, peeringURL string) error

Basic checks, to be used in all the implementations.

Types

type ComparablePubKey added in v1.0.3

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

func NewComparablePubKey added in v1.0.3

func NewComparablePubKey(pubKey *cryptolib.PublicKey) *ComparablePubKey

func (*ComparablePubKey) Key added in v1.0.3

func (c *ComparablePubKey) Key() string

func (*ComparablePubKey) PubKey added in v1.0.3

func (c *ComparablePubKey) PubKey() *cryptolib.PublicKey

func (*ComparablePubKey) String added in v1.0.3

func (c *ComparablePubKey) String() string

type GroupProvider

type GroupProvider interface {
	SelfIndex() uint16
	PeerIndex(peer PeerSender) (uint16, error)
	PeerIndexByPubKey(peerPubKey *cryptolib.PublicKey) (uint16, error)
	PubKeyByIndex(index uint16) (*cryptolib.PublicKey, error)
	Attach(receiver byte, callback func(recv *PeerMessageGroupIn)) context.CancelFunc
	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 Metrics added in v1.0.3

type Metrics interface {
	PeerCount(peerCount int)
	RecvEnqueued(messageSize, newPipeSize int)
	RecvDequeued(messageSize, newPipeSize int)
	SendEnqueued(messageSize, newPipeSize int)
	SendDequeued(messageSize, newPipeSize int)
}

func NewEmptyMetrics added in v1.0.3

func NewEmptyMetrics() Metrics

type NetworkProvider

type NetworkProvider interface {
	Run(ctx context.Context)
	Self() PeerSender
	PeerGroup(peeringID PeeringID, peerPubKeys []*cryptolib.PublicKey) (GroupProvider, error)
	PeerDomain(peeringID PeeringID, peerAddrs []*cryptolib.PublicKey) (PeerDomainProvider, error)
	PeerByPubKey(peerPub *cryptolib.PublicKey) (PeerSender, error)
	SendMsgByPubKey(pubKey *cryptolib.PublicKey, msg *PeerMessageData)
	PeerStatus() []PeerStatusProvider
	Attach(peeringID *PeeringID, receiver byte, callback func(recv *PeerMessageIn)) context.CancelFunc
}

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()
	GetRandomOtherPeers(upToNumPeers int) []*cryptolib.PublicKey
	UpdatePeers(newPeerPubKeys []*cryptolib.PublicKey)
	Attach(receiver byte, callback func(recv *PeerMessageIn)) context.CancelFunc
	SendMsgByPubKey(pubKey *cryptolib.PublicKey, msgReceiver byte, msgType byte, msgData []byte)
	PeerStatus() []PeerStatusProvider
	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 peeringURL

type PeerMessageData added in v0.2.3

type PeerMessageData struct {
	PeeringID   PeeringID
	MsgReceiver byte
	MsgType     byte
	MsgData     []byte
	// contains filtered or unexported fields
}

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

func NewPeerMessageData added in v1.0.3

func NewPeerMessageData(peeringID PeeringID, receiver byte, msgType byte, msgData ...any) (ret *PeerMessageData)

func (*PeerMessageData) Bytes added in v1.0.3

func (m *PeerMessageData) Bytes() []byte

func (*PeerMessageData) Read added in v1.0.3

func (m *PeerMessageData) Read(r io.Reader) error

func (*PeerMessageData) Write added in v1.0.3

func (m *PeerMessageData) Write(w io.Writer) 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
	SenderPubKey *cryptolib.PublicKey
}

type PeerMessageNet added in v0.2.3

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

func PeerMessageNetFromBytes added in v1.0.3

func PeerMessageNetFromBytes(data []byte) (*PeerMessageNet, error)

PeerMessageNetFromBytes creates a new PeerMessageNet from bytes. The function takes ownership over "data" and the caller should not use "data" after this call.

func (*PeerMessageNet) Bytes added in v0.2.3

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

func (*PeerMessageNet) GetHash added in v0.2.3

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

type PeerSender

type PeerSender interface {
	// PeeringURL identifies the peer.
	PeeringURL() 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() *cryptolib.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

	// Provides a read-only representation of this sender.
	Status() PeerStatusProvider

	// 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 {
	Name() string
	PeeringURL() string
	PubKey() *cryptolib.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

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

func HashPeeringIDFromBytes added in v1.0.3

func HashPeeringIDFromBytes(src []byte, additional ...[]byte) PeeringID

HashPeeringIDFromBytes generates a PeeringID by concatenating all the given data and hash with Blake2b 256.

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 TrustedNetworkManager added in v0.2.0

type TrustedNetworkManager interface {
	IsTrustedPeer(pubKey *cryptolib.PublicKey) error
	TrustPeer(name string, pubKey *cryptolib.PublicKey, peeringURL string) (*TrustedPeer, error)
	DistrustPeer(pubKey *cryptolib.PublicKey) (*TrustedPeer, error)
	TrustedPeers() ([]*TrustedPeer, error)
	TrustedPeersByPubKeyOrName(pubKeysOrNames []string) ([]*TrustedPeer, error)
	// The following has to register a callback receiving updates to a set of trusted peers.
	// Upon subscription the initial set of peers has to be passed without waiting for updates.
	// The function returns a cancel func.The context is used to cancel the subscription.
	TrustedPeersListener(callback func([]*TrustedPeer)) context.CancelFunc
}

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 {
	Name string

	PeeringURL string
	// contains filtered or unexported fields
}

TrustedPeer carries a peer information we use to trust it.

func NewTrustedPeer added in v1.0.3

func NewTrustedPeer(name string, pubKey *cryptolib.PublicKey, peeringURL string) *TrustedPeer

func QueryByPubKeyOrName added in v1.0.3

func QueryByPubKeyOrName(trustedPeers []*TrustedPeer, pubKeysOrNames []string) ([]*TrustedPeer, error)

Resolves pubKeysOrNames to TrustedPeers. Fails if any of the names/keys cannot be resolved.

func (*TrustedPeer) Clone added in v1.0.3

func (*TrustedPeer) ID added in v1.0.3

func (tp *TrustedPeer) ID() *ComparablePubKey

func (*TrustedPeer) MarshalJSON added in v1.0.3

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

func (*TrustedPeer) PubKey added in v0.2.0

func (tp *TrustedPeer) PubKey() *cryptolib.PublicKey

func (*TrustedPeer) UnmarshalJSON added in v1.0.3

func (tp *TrustedPeer) UnmarshalJSON(bytes []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