Documentation ¶
Index ¶
- Constants
- Variables
- func NewConnectableHost(h host.Host) *connectableHost
- func NewDirectSender(ctx context.Context, h host.Host, ...) (*directSender, error)
- func NewMemoryMessenger(ctx context.Context, mockNet mocknet.Mocknet, ...) (*networkMessenger, error)
- func NewNetworkMessenger(ctx context.Context, port int, p2pPrivKey crypto.PrivKey, ...) (*networkMessenger, error)
- func NewNetworkMessengerOnFreePort(ctx context.Context, p2pPrivKey crypto.PrivKey, conMgr ifconnmgr.ConnManager, ...) (*networkMessenger, error)
- type ConnectableHost
- type Libp2pContext
- type Message
- type PeerInfoHandler
Constants ¶
const DirectSendID = protocol.ID("/directsend/1.0.0")
DirectSendID represents the protocol ID for sending and receiving direct P2P messages
const ListenAddrWithIp4AndTcp = "/ip4/0.0.0.0/tcp/"
ListenAddrWithIp4AndTcp defines the listening address with ip v.4 and TCP
const ListenLocalhostAddrWithIp4AndTcp = "/ip4/127.0.0.1/tcp/"
ListenLocalhostAddrWithIp4AndTcp defines the local host listening ip v.4 address and TCP
Variables ¶
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
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 ¶
NewMessage returns a new instance of a Message object
func (*Message) Key ¶
Key returns the message public key (if it can not be recovered from From field)
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