api

package
v0.2202.2 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2022 License: Apache-2.0 Imports: 15 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 PubKeyToPublicKey

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

PubKeyToPublicKey converts a libp2pCrypto.PubKey to a PublicKey.

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 Service

type Service interface {
	service.BackgroundService

	// 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

	// PublishCommittee publishes a committee message.
	PublishCommittee(ctx context.Context, runtimeID common.Namespace, msg *CommitteeMessage)

	// PublishTx publishes a transaction message.
	PublishTx(ctx context.Context, runtimeID common.Namespace, msg TxMessage)

	// RegisterHandler registers a message handler for the specified runtime and topic kind.
	RegisterHandler(runtimeID common.Namespace, kind TopicKind, handler Handler)

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

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

	// 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

	// SetNodeImportance configures node importance for the given set of nodes.
	//
	// This makes it less likely for those nodes to be pruned.
	SetNodeImportance(kind ImportanceKind, runtimeID common.Namespace, p2pIDs map[signature.PublicKey]bool)
}

Service is a P2P node service interface.

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