libp2p

package
v1.0.79 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2020 License: GPL-3.0 Imports: 30 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.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

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 added in v1.0.3

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 libp2pCrypto.PrivKey,
	conMgr connmgr.ConnManager,
	outgoingPLB p2p.ChannelLoadBalancer,
	peerDiscoverer p2p.PeerDiscoverer,
	listenAddress string,
	targetConnCount int,
) (*networkMessenger, error)

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

func NewNetworkMessengerOnFreePort added in v1.0.3

func NewNetworkMessengerOnFreePort(
	ctx context.Context,
	p2pPrivKey libp2pCrypto.PrivKey,
	conMgr connmgr.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
	IsInterfaceNil() bool
}

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

type Libp2pContext added in v1.0.3

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

Libp2pContext holds the context for the wrappers over libp2p implementation

func NewLibp2pContext added in v1.0.3

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

NewLibp2pContext constructs a new Libp2pContext object

func (*Libp2pContext) Context added in v1.0.3

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

Context returns the context associated with this struct

func (*Libp2pContext) Host added in v1.0.3

func (lctx *Libp2pContext) Host() ConnectableHost

Host returns the connectable host

func (*Libp2pContext) IsInterfaceNil added in v1.0.16

func (lctx *Libp2pContext) IsInterfaceNil() bool

IsInterfaceNil returns true if there is no value under the interface

type Message added in v1.0.3

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 added in v1.0.3

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

Data returns the message payload

func (*Message) From added in v1.0.3

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

From returns the message originator's peer ID

func (*Message) IsInterfaceNil added in v1.0.16

func (m *Message) IsInterfaceNil() bool

IsInterfaceNil returns true if there is no value under the interface

func (*Message) Key added in v1.0.3

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

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

func (*Message) Peer added in v1.0.3

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

Peer returns the peer that originated the message

func (*Message) SeqNo added in v1.0.3

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

SeqNo returns the message sequence number

func (*Message) Signature added in v1.0.3

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

Signature returns the message signature

func (*Message) TopicIDs added in v1.0.3

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

TopicIDs returns the topic on which the message was sent

type MutexHolder

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

MutexHolder holds a cache of mutexes: pairs of (key, *sync.Mutex)

func NewMutexHolder

func NewMutexHolder(mutexesCapacity int) (*MutexHolder, error)

NewMutexHolder creates a new instance of MutexHolder with specified capacity.

func (*MutexHolder) Get

func (mh *MutexHolder) Get(key string) *sync.Mutex

Get returns a mutex for the provided key. If the key was not found, it will create a new mutex, save it in the cache and returns it.

type PeerInfoHandler

type PeerInfoHandler func(pInfo peer.AddrInfo)

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