p2p

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2022 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const LoggerTag = "P2P"

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
	// 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 send 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
	// FeedersAddrs is a list of price feeders. Only feeders can create new
	// messages in the network.
	FeedersAddrs []ethereum.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 ethereum.Signer
	// 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.

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 provide
	// 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. nolint:gocyclo,funlen

func (*P2P) Broadcast

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

Broadcast implements the transport.Transport interface.

func (*P2P) ID added in v0.4.9

func (p *P2P) ID() []byte

ID 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) 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