p2p

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2021 License: AGPL-3.0 Imports: 16 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
	// a 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 a configuration for the P2P transport.

type Mode added in v0.2.0

type Mode int

Mode describes operating mode of a 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 a little wrapper for the Node that implements the transport.Transport interface.

func New

func New(ctx context.Context, 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 added in v0.2.0

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

Messages implements the transport.Transport interface.

func (*P2P) Start added in v0.2.0

func (p *P2P) Start() error

Start implements the transport.Transport interface.

func (*P2P) Wait added in v0.2.0

func (p *P2P) Wait()

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