api

package
v0.2300.10 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package api implements the P2P API.

Index

Constants

View Source
const (
	ImportantNodeCompute    = 1
	ImportantNodeKeyManager = 2
)

Variables

This section is empty.

Functions

func AddrInfoToString

func AddrInfoToString(info peer.AddrInfo) []string

AddrInfoToString converts AddressInfo to a list of p2p string multiaddresses.

For example, an address info with ID 1234 and multiaddresses /ip4/127.0.0.1/tcp/8080 and /ip6/::1/tcp/8080 would be converted to a list ["/ip4/127.0.0.1/tcp/8080/p2p/1234", "/ip6/::1/tcp/8080/p2p/1234"].

func AddrInfosFromConsensusAddrs

func AddrInfosFromConsensusAddrs(addrs []string) ([]peer.AddrInfo, error)

AddrInfosFromConsensusAddrs converts string consensus addresses to addr infos.

func PubKeyToPublicKey

func PubKeyToPublicKey(pubKey libp2pCrypto.PubKey) (signature.PublicKey, error)

PubKeyToPublicKey converts a libp2pCrypto.PubKey to a PublicKey.

func PublicKeyMapToPeerIDs

func PublicKeyMapToPeerIDs(pks map[signature.PublicKey]struct{}) ([]core.PeerID, error)

PublicKeyMapToPeerIDs converts a map of public keys to a list of peer identifiers.

func PublicKeyToPeerID

func PublicKeyToPeerID(pk signature.PublicKey) (core.PeerID, error)

PublicKeyToPeerID converts a public key to a peer identifier.

func SignerToPrivKey

func SignerToPrivKey(signer signature.Signer) libp2pCrypto.PrivKey

SignerToPrivKey converts a Signer to a libp2pCrypto.PrivKey.

Types

type CommitteeMessage

type CommitteeMessage struct {
	// Epoch is the epoch this message belongs to.
	Epoch beacon.EpochTime `json:"epoch,omitempty"`

	// Proposal is a batch proposal.
	Proposal *commitment.Proposal `json:",omitempty"`
}

CommitteeMessage is a message published to nodes via gossipsub on the committee topic.

type Handler

type Handler interface {
	// DecodeMessage decodes the given incoming message.
	DecodeMessage(msg []byte) (interface{}, error)

	// AuthorizeMessage handles authorizing an incoming message.
	//
	// The message handler will be re-invoked on error with a periodic backoff unless errors are
	// wrapped via `p2pError.Permanent`.
	AuthorizeMessage(ctx context.Context, peerID signature.PublicKey, msg interface{}) error

	// HandleMessage handles an incoming message from a peer.
	//
	// The message handler will be re-invoked on error with a periodic backoff unless errors are
	// wrapped via `p2pError.Permanent`.
	HandleMessage(ctx context.Context, peerID signature.PublicKey, msg interface{}, isOwn bool) error
}

Handler is a handler for P2P messages.

type ImportanceKind

type ImportanceKind uint8

ImportanceKind is the node importance kind.

func (ImportanceKind) Tag

func (ik ImportanceKind) Tag(runtimeID common.Namespace) string

Tag returns the connection manager tag associated with the given importance kind.

func (ImportanceKind) TagValue

func (ik ImportanceKind) TagValue() int

TagValue returns the connection manager tag value associated with the given importance kind.

type PeerManager

type PeerManager interface {
	// PeerRegistry returns the peer registry.
	PeerRegistry() PeerRegistry

	// PeerTagger returns the peer tagger.
	PeerTagger() PeerTagger
}

PeerManager is an interface for managing peers in the P2P network.

type PeerRegistry

type PeerRegistry interface {
	// Initialized returns a channel that will be closed once the first node refresh event from
	// the registry is received.
	Initialized() <-chan struct{}

	// NumPeers returns the number of registered peers.
	NumPeers() int
}

PeerRegistry is an interface for accessing peer information from the registry.

type PeerTagger

type PeerTagger interface {
	// SetPeerImportance configures peer importance for the given list of peers.
	//
	// This makes it less likely for those peers to be pruned.
	SetPeerImportance(kind ImportanceKind, runtimeID common.Namespace, pids []peer.ID)
}

PeerTagger is an interface for tagging important peers.

type SeedService

type SeedService interface {
	service.BackgroundService

	// Addresses returns the listen addresses of the host.
	Addresses() []string

	// Peers returns a list of peers located in the peer store.
	Peers() []string
}

SeedService is a P2P node service interface.

type Service

type Service interface {
	service.BackgroundService

	// GetStatus returns the P2P status of the node.
	GetStatus() *Status

	// Addresses returns the P2P addresses of the node.
	Addresses() []node.Address

	// Peers returns a list of connected P2P peers for the given runtime.
	Peers(runtimeID common.Namespace) []string

	// Publish publishes the given message to the given topic.
	Publish(ctx context.Context, topic string, msg interface{})

	// RegisterHandler registers a message handler for the specified runtime and topic kind.
	RegisterHandler(topic string, handler Handler)

	// BlockPeer blocks a specific peer from being used by the local node.
	BlockPeer(peerID core.PeerID)

	// Host returns the P2P host.
	Host() core.Host

	// PeerManager returns the P2P peer manager.
	PeerManager() PeerManager

	// RegisterProtocol starts tracking and managing peers that support the given protocol.
	RegisterProtocol(p core.ProtocolID, min int, total int)

	// RegisterProtocolServer registers a protocol server for the given protocol.
	RegisterProtocolServer(srv rpc.Server)

	// GetMinRepublishInterval returns the minimum republish interval that needs to be respected by
	// the caller when publishing the same message. If Publish is called for the same message more
	// quickly, the message may be dropped and not published.
	GetMinRepublishInterval() time.Duration
}

Service is a P2P node service interface.

type Status

type Status struct {
	// PubKey is the public key used for P2P communication.
	PubKey signature.PublicKey `json:"pub_key"`

	// PeerID is the peer ID derived by hashing peer's public key.
	PeerID peer.ID `json:"peer_id"`

	// Addresses is a list of configured P2P addresses used when registering the node.
	Addresses []node.Address `json:"addresses"`

	// NumPeers is the number of connected peers.
	NumPeers int `json:"num_peers"`

	// NumConnections is the number of peer connections.
	NumConnections int `json:"num_connections"`

	// Protocols is a set of registered protocols together with the number of connected peers.
	Protocols map[core.ProtocolID]int `json:"protocols"`

	// Topics is a set of registered topics together with the number of connected peers.
	Topics map[string]int `json:"topics"`
}

Status is the P2P status of a node.

type TopicKind

type TopicKind string

TopicKind is the gossipsub topic kind.

const (
	// TopicKindCommittee is the topic kind for the topic that is used to gossip batch proposals
	// and other committee messages.
	TopicKindCommittee TopicKind = "committee"
	// TopicKindTx is the topic kind for the topic that is used to gossip transactions.
	TopicKindTx TopicKind = "tx"
)

type TxMessage

type TxMessage []byte

TxMessage is a message published to nodes via gossipsub on the transaction topic. It contains the raw signed transaction with runtime-dependent semantics.

Jump to

Keyboard shortcuts

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