libp2p

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2024 License: GPL-3.0 Imports: 52 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DirectSendID represents the protocol ID for sending and receiving direct P2P messages
	DirectSendID = protocol.ID("/moa/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 NewConnectionsHandler

func NewConnectionsHandler(args ArgConnectionsHandler) (*connectionsHandler, error)

NewConnectionsHandler creates a new connections manager

func NewDirectSender

func NewDirectSender(
	ctx context.Context,
	h host.Host,
	signer p2p.SignerVerifier,
	marshaller p2p.Marshaller,
	logger p2p.Logger,
) (*directSender, error)

NewDirectSender returns a new instance of direct sender object

func NewMessage

func NewMessage(msg *pubsub.Message, marshaller p2p.Marshaller, broadcastMethod p2p.BroadcastMethod) (*message.Message, error)

NewMessage returns a new instance of a Message object

func NewMessagesHandler

func NewMessagesHandler(args ArgMessagesHandler) (*messagesHandler, error)

NewMessagesHandler creates a new instance of messages handler

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 NewOutgoingChannelLoadBalancer

func NewOutgoingChannelLoadBalancer(logger p2p.Logger) (*outgoingChannelLoadBalancer, error)

NewOutgoingChannelLoadBalancer creates a new instance of a ChannelLoadBalancer instance

func NewTestNetMessenger

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

NewTestNetMessenger creates a wrapper over networkMessenger that exposes more functionality

Types

type ArgConnectionsHandler

type ArgConnectionsHandler struct {
	P2pHost              ConnectableHost
	PeersOnChannel       PeersOnChannel
	PeerShardResolver    p2p.PeerShardResolver
	Sharder              p2p.Sharder
	PreferredPeersHolder p2p.PreferredPeersHolderHandler
	ConnMonitor          ConnectionMonitor
	PeerDiscoverer       p2p.PeerDiscoverer
	PeerID               core.PeerID
	ConnectionsMetric    ConnectionsMetric
	NetworkType          p2p.NetworkType
	Logger               p2p.Logger
	ProtocolID           string
}

ArgConnectionsHandler is the DTO struct used to create a new instance of connections handler

type ArgMessagesHandler

type ArgMessagesHandler struct {
	PubSub             PubSub
	DirectSender       p2p.DirectSender
	Throttler          core.Throttler
	OutgoingCLB        ChannelLoadBalancer
	Marshaller         p2p.Marshaller
	ConnMonitor        ConnectionMonitor
	PeersRatingHandler p2p.PeersRatingHandler
	SyncTimer          p2p.SyncTimer
	PeerID             core.PeerID
	NetworkType        p2p.NetworkType
	Logger             p2p.Logger
}

ArgMessagesHandler is the DTO struct used to create a new instance of messages handler

type ArgsNetworkMessenger

type ArgsNetworkMessenger struct {
	Marshaller            p2p.Marshaller
	P2pConfig             config.P2PConfig
	SyncTimer             p2p.SyncTimer
	PreferredPeersHolder  p2p.PreferredPeersHolderHandler
	PeersRatingHandler    p2p.PeersRatingHandler
	ConnectionWatcherType string
	P2pPrivateKey         commonCrypto.PrivateKey
	P2pSingleSigner       commonCrypto.SingleSigner
	P2pKeyGenerator       commonCrypto.KeyGenerator
	NetworkType           p2p.NetworkType
	Logger                p2p.Logger
}

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
	SetPeerDenialEvaluator(handler p2p.PeerDenialEvaluator) error
	PeerDenialEvaluator() p2p.PeerDenialEvaluator
	Close() error
	IsInterfaceNil() bool
}

ConnectionMonitor defines the behavior of a connection monitor

type ConnectionsMetric

type ConnectionsMetric interface {
	network.Notifiee

	ResetNumConnections() uint32
	ResetNumDisconnections() uint32
	IsInterfaceNil() bool
}

ConnectionsMetric is an extension of the libp2p network notifiee able to track connections metrics

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 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 PeersOnChannel

type PeersOnChannel interface {
	ConnectedPeersOnChannel(topic string) []core.PeerID
	Close() error
	IsInterfaceNil() bool
}

PeersOnChannel interface defines what a component able to handle peers on a channel should do

type PubSub

type PubSub interface {
	Join(topic string, opts ...pubsub.TopicOpt) (*pubsub.Topic, error)
	ListPeers(topic string) []peer.ID
	RegisterTopicValidator(topic string, val interface{}, opts ...pubsub.ValidatorOpt) error
	UnregisterTopicValidator(topic string) error
	GetTopics() []string
}

PubSub interface defines what a publish/subscribe system should do

type PubSubSubscription

type PubSubSubscription interface {
	Topic() string
	Next(ctx context.Context) (*pubsub.Message, error)
	Cancel()
}

PubSubSubscription interface defines what a pubSub subscription can do

type PubSubTopic

type PubSubTopic interface {
	Subscribe(opts ...pubsub.SubOpt) (*pubsub.Subscription, error)
	Publish(ctx context.Context, data []byte, opts ...pubsub.PubOpt) error
	Close() error
}

PubSubTopic interface defines what a pubSub topic can do

type SendableData

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

SendableData represents the struct used in data throttler implementation

type TopicProcessor

type TopicProcessor interface {
	AddTopicProcessor(identifier string, processor p2p.MessageProcessor) error
	RemoveTopicProcessor(identifier string) error
	GetList() ([]string, []p2p.MessageProcessor)
	IsInterfaceNil() bool
}

TopicProcessor interface defines what a topic processor can do

Jump to

Keyboard shortcuts

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