libp2p

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const DirectSendID = protocol.ID("/directsend/1.0.0")

DirectSendID represents the protocol ID for sending and receiving direct P2P messages

View Source
const ListenAddrWithIp4AndTcp = "/ip4/0.0.0.0/tcp/"

ListenAddrWithIp4AndTcp defines the listening address with ip v.4 and TCP

View Source
const ListenLocalhostAddrWithIp4AndTcp = "/ip4/127.0.0.1/tcp/"

ListenLocalhostAddrWithIp4AndTcp defines the local host listening ip v.4 address and TCP

Variables

View Source
var DurationBetweenReconnectAttempts = time.Duration(time.Second * 5)

DurationBetweenReconnectAttempts is used as to not call reconnecter.ReconnectToNetwork() to often when there are a lot of peers disconnecting and reconnection to initial nodes succeed

View Source
var ThresholdMinimumConnectedPeers = 3

ThresholdMinimumConnectedPeers if the number of connected peers drop under this value, for each disconnecting peer, a trigger to reconnect to initial peers is done

Functions

func NewConnectableHost

func NewConnectableHost(h host.Host) *connectableHost

NewConnectableHost creates a new connectable host implementation

func NewDirectSender

func NewDirectSender(
	ctx context.Context,
	h host.Host,
	messageHandler func(msg p2p.MessageP2P) error,
) (*directSender, error)

NewDirectSender returns a new instance of direct sender object

func NewMemoryMessenger

func NewMemoryMessenger(
	ctx context.Context,
	mockNet mocknet.Mocknet,
	peerDiscoverer p2p.PeerDiscoverer) (*networkMessenger, error)

NewMemoryMessenger creates a new sandbox testable instance of libP2P messenger It should not open ports on current machine Should be used only in testing!

func NewNetworkMessenger

func NewNetworkMessenger(
	ctx context.Context,
	port int,
	p2pPrivKey crypto.PrivKey,
	conMgr ifconnmgr.ConnManager,
	outgoingPLB p2p.ChannelLoadBalancer,
	peerDiscoverer p2p.PeerDiscoverer,
	listenAddress string,
) (*networkMessenger, error)

NewNetworkMessenger creates a libP2P messenger by opening a port on the current machine Should be used in production!

func NewNetworkMessengerOnFreePort

func NewNetworkMessengerOnFreePort(ctx context.Context,
	p2pPrivKey crypto.PrivKey,
	conMgr ifconnmgr.ConnManager,
	outgoingPLB p2p.ChannelLoadBalancer,
	peerDiscoverer p2p.PeerDiscoverer,
) (*networkMessenger, error)

NewNetworkMessengerOnFreePort tries to create a new NetworkMessenger on a free port found in the system Should be used only in testing!

Types

type ConnectableHost

type ConnectableHost interface {
	host.Host
	ConnectToPeer(ctx context.Context, address string) error
}

ConnectableHost is an enhanced Host interface that has the ability to connect to a string address

type Libp2pContext

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

Libp2pContext holds the context for the wrappers over libp2p implementation

func NewLibp2pContext

func NewLibp2pContext(ctx context.Context, connHost ConnectableHost) (*Libp2pContext, error)

NewLibp2pContext constructs a new Libp2pContext object

func (*Libp2pContext) Context

func (lctx *Libp2pContext) Context() context.Context

Context returns the context associated with this struct

func (*Libp2pContext) Host

func (lctx *Libp2pContext) Host() ConnectableHost

Host returns the connectable host

type Message

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

Message is a data holder struct

func NewMessage

func NewMessage(message *pubsub.Message) *Message

NewMessage returns a new instance of a Message object

func (*Message) Data

func (m *Message) Data() []byte

Data returns the message payload

func (*Message) From

func (m *Message) From() []byte

From returns the message originator's peer ID

func (*Message) Key

func (m *Message) Key() []byte

Key returns the message public key (if it can not be recovered from From field)

func (*Message) Peer

func (m *Message) Peer() p2p.PeerID

Peer returns the peer that originated the message

func (*Message) SeqNo

func (m *Message) SeqNo() []byte

SeqNo returns the message sequence number

func (*Message) Signature

func (m *Message) Signature() []byte

Signature returns the message signature

func (*Message) TopicIDs

func (m *Message) TopicIDs() []string

TopicIDs returns the topic on which the message was sent

type PeerInfoHandler

type PeerInfoHandler func(pInfo peerstore.PeerInfo)

PeerInfoHandler is the signature of the handler that gets called whenever an action for a peerInfo is triggered

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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