libp2p

package
v0.0.0-...-b915c30 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const LoggerTag = "LIBP2P"
View Source
const TransportName = "libp2p"

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Mode describes in what mode the node should operate.
	Mode Mode

	// Topics is a list of subscribed topics. A value of the map a type of
	// message given as a nil pointer, e.g.: (*Message)(nil).
	Topics map[string]transport.Message

	// PeerPrivKey is a key used for peer identity. If empty, then random key
	// is used. Ignored in bootstrap mode.
	PeerPrivKey crypto.PrivKey

	// MessagePrivKey is a key used to sign messages. If empty, then message
	// are signed with the same key which is used for peer identity. Ignored
	// in bootstrap mode.
	MessagePrivKey crypto.PrivKey

	// ListenAddrs is a list of multiaddresses on which this node will be
	// listening on. If empty, the localhost, and a random port will be used.
	ListenAddrs []string

	// ExternalAddr is a multiaddress of the node that will be advertised to peers.
	ExternalAddr multiaddr.Multiaddr

	// BootstrapAddrs is a list multiaddresses of initial peers to connect to.
	// This option is ignored when discovery is disabled.
	BootstrapAddrs []string

	// DirectPeersAddrs is a list multiaddresses of peers to which messages
	// will be sent directly. This option has to be configured symmetrically
	// at both ends.
	DirectPeersAddrs []string

	// BlockedAddrs is a list of multiaddresses to which connection will be
	// blocked. If an address on that list contains an IP and a peer ID, both
	// will be blocked separately.
	BlockedAddrs []string

	// AuthorAllowlist is a list of allowed message authors. Only messages from
	// these addresses will be accepted.
	AuthorAllowlist []types.Address

	// Discovery indicates whenever peer discovery should be enabled.
	// If discovery is disabled, then DirectPeersAddrs must be used
	// to connect to the network. Always enabled in bootstrap mode.
	Discovery bool

	// Signer used to verify price messages. Ignored in bootstrap mode.
	Signer wallet.Key

	// Logger is a custom logger instance. If not provided then null
	// logger is used.
	Logger log.Logger

	// Application info:
	AppName    string
	AppVersion string
}

Config is the configuration for the P2P transport. TODO: This Config should not be responsible for parsing multiAddresses.

type Mode

type Mode int

Mode describes operating mode of the node.

const (
	// ClientMode operates the node as client. ClientMode can publish and read messages
	// and provides peer discovery service for other nodes.
	ClientMode Mode = iota
	// BootstrapMode operates the node as a bootstrap node. BootstrapMode node provides
	// only peer discovery service for other nodes.
	BootstrapMode
)

type P2P

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

P2P is the wrapper for the Node that implements the transport.Transport interface.

func New

func New(cfg Config) (*P2P, error)

New returns a new instance of a transport, implemented with the libp2p library.

func (*P2P) Broadcast

func (p *P2P) Broadcast(topic string, message transport.Message) error

Broadcast implements the transport.Transport interface.

func (*P2P) Messages

func (p *P2P) Messages(topic string) <-chan transport.ReceivedMessage

Messages implements the transport.Transport interface.

func (*P2P) ServiceName

func (p *P2P) ServiceName() string

ServiceName implements the supervisor.WithName interface.

func (*P2P) Start

func (p *P2P) Start(ctx context.Context) error

Start implements the transport.Transport interface.

func (*P2P) Wait

func (p *P2P) Wait() <-chan error

Wait implements the transport.Transport interface.

Directories

Path Synopsis
crypto

Jump to

Keyboard shortcuts

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