libp2p

package
v1.0.18 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: GPL-3.0 Imports: 51 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// DirectSendID represents the protocol ID for sending and receiving direct P2P messages
	DirectSendID = protocol.ID("/erd/directsend/1.0.0")
)

Variables

This section is empty.

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 *pubsub.Message, fromConnectedPeer core.PeerID) error,
	signer p2p.SignerVerifier,
) (*directSender, error)

NewDirectSender returns a new instance of direct sender object

func NewMessage

func NewMessage(msg *pubsub.Message, marshalizer p2p.Marshalizer) (*message.Message, error)

NewMessage returns a new instance of a Message object

func NewMockMessenger

func NewMockMessenger(
	args ArgsNetworkMessenger,
	mockNet mocknet.Mocknet,
) (*networkMessenger, error)

NewMockMessenger 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(args ArgsNetworkMessenger) (*networkMessenger, error)

NewNetworkMessenger creates a libP2P messenger by opening a port on the current machine

func NewTestNetMessenger added in v1.0.17

func NewTestNetMessenger(args ArgsNetworkMessenger) (*testNetMessenger, error)

NewTestNetMessenger creates a wrapper over networkMessenger that exposes more functionality

Types

type ArgsNetworkMessenger

type ArgsNetworkMessenger struct {
	Marshalizer           p2p.Marshalizer
	P2pConfig             config.P2PConfig
	SyncTimer             p2p.SyncTimer
	PreferredPeersHolder  p2p.PreferredPeersHolderHandler
	NodeOperationMode     p2p.NodeOperation
	PeersRatingHandler    p2p.PeersRatingHandler
	ConnectionWatcherType string
	P2pPrivateKey         commonCrypto.PrivateKey
	P2pSingleSigner       commonCrypto.SingleSigner
	P2pKeyGenerator       commonCrypto.KeyGenerator
}

ArgsNetworkMessenger defines the options used to create a p2p wrapper

type ChannelLoadBalancer

type ChannelLoadBalancer interface {
	AddChannel(channel string) error
	RemoveChannel(channel string) error
	GetChannelOrDefault(channel string) chan *SendableData
	CollectOneElementFromChannels() *SendableData
	Close() error
	IsInterfaceNil() bool
}

ChannelLoadBalancer defines what a load balancer that uses chans should do

type ConnectableHost

type ConnectableHost interface {
	host.Host
	ConnectToPeer(ctx context.Context, address string) error
	AddressToPeerInfo(address string) (*peer.AddrInfo, error)
	IsInterfaceNil() bool
}

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

type ConnectionMonitor

type ConnectionMonitor interface {
	network.Notifiee
	IsConnectedToTheNetwork(netw network.Network) bool
	SetThresholdMinConnectedPeers(thresholdMinConnectedPeers int, netw network.Network)
	ThresholdMinConnectedPeers() int
	Close() error
	IsInterfaceNil() bool
}

ConnectionMonitor defines the behavior of a connection monitor

type LocalSyncTimer

type LocalSyncTimer struct {
}

LocalSyncTimer uses the local system to provide the current time

func (*LocalSyncTimer) CurrentTime

func (lst *LocalSyncTimer) CurrentTime() time.Time

CurrentTime returns the local current time

func (*LocalSyncTimer) IsInterfaceNil

func (lst *LocalSyncTimer) IsInterfaceNil() bool

IsInterfaceNil returns true if there is no value under the interface

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 OutgoingChannelLoadBalancer

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

OutgoingChannelLoadBalancer is a component that evenly balances requests to be sent

func NewOutgoingChannelLoadBalancer

func NewOutgoingChannelLoadBalancer() *OutgoingChannelLoadBalancer

NewOutgoingChannelLoadBalancer creates a new instance of a ChannelLoadBalancer instance

func (*OutgoingChannelLoadBalancer) AddChannel

func (oplb *OutgoingChannelLoadBalancer) AddChannel(channel string) error

AddChannel adds a new channel to the throttler, if it does not exists

func (*OutgoingChannelLoadBalancer) Close

func (oplb *OutgoingChannelLoadBalancer) Close() error

Close finishes all started go routines in this instance

func (*OutgoingChannelLoadBalancer) CollectOneElementFromChannels

func (oplb *OutgoingChannelLoadBalancer) CollectOneElementFromChannels() *SendableData

CollectOneElementFromChannels gets the waiting object from mainChan. It is a blocking call.

func (*OutgoingChannelLoadBalancer) GetChannelOrDefault

func (oplb *OutgoingChannelLoadBalancer) GetChannelOrDefault(channel string) chan *SendableData

GetChannelOrDefault fetches the required channel or the default if the channel is not present

func (*OutgoingChannelLoadBalancer) IsInterfaceNil

func (oplb *OutgoingChannelLoadBalancer) IsInterfaceNil() bool

IsInterfaceNil returns true if there is no value under the interface

func (*OutgoingChannelLoadBalancer) RemoveChannel

func (oplb *OutgoingChannelLoadBalancer) RemoveChannel(channel string) error

RemoveChannel removes an existing channel from the throttler

type PeerDiscovererWithSharder

type PeerDiscovererWithSharder interface {
	p2p.PeerDiscoverer
	SetSharder(sharder p2p.Sharder) error
}

PeerDiscovererWithSharder extends the PeerDiscoverer with the possibility to set the sharder

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

type SendableData

type SendableData struct {
	Buff  []byte
	Topic string
	Sk    crypto.PrivKey
	ID    peer.ID
}

SendableData represents the struct used in data throttler implementation

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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