Documentation ¶
Overview ¶
Package libp2p provides discovery mechanisms using Kademlia DHT.
Index ¶
- Constants
- func NewAnnouncer[REQ, RESP any](ctx context.Context, opts AnnounceOptions, rt transport.UnaryServer[REQ, RESP]) (io.Closer, error)
- func NewAnnouncerWithHost[REQ, RESP any](ctx context.Context, host Host, opts AnnounceOptions, ...) io.Closer
- func NewDHT(ctx context.Context, host host.Host, bootstrapPeers []multiaddr.Multiaddr, ...) (*dht.IpfsDHT, error)
- func NewJoinAnnouncer(ctx context.Context, opts AnnounceOptions, join transport.JoinServer) (io.Closer, error)
- func NewJoinAnnouncerWithHost(ctx context.Context, host Host, opts AnnounceOptions, ...) io.Closer
- func NewJoinRoundTripper(ctx context.Context, opts RoundTripOptions) (transport.JoinRoundTripper, error)
- func NewJoinRoundTripperWithHost(host Host, opts RoundTripOptions) transport.JoinRoundTripper
- func NewLibP2PHost(ctx context.Context, opts HostOptions) (host.Host, error)
- func NewRaftTransport(ctx context.Context, opts RaftTransportOptions) (raft.Transport, error)
- func NewRoundTripper[REQ, RESP any](ctx context.Context, opts RoundTripOptions) (transport.RoundTripper[REQ, RESP], error)
- func NewRoundTripperWithHost[REQ, RESP any](host Host, opts RoundTripOptions) transport.RoundTripper[REQ, RESP]
- func RPCProtocolFor(method string) protocol.ID
- func SetMaxSystemBuffers(ctx context.Context)
- func SetSystemBuffers(ctx context.Context, size int)
- func UDPRelayProtocolFor(node string) protocol.ID
- type AnnounceOptions
- type Announcer
- type BootstrapOptions
- type BootstrapTransport
- type Host
- type HostOptions
- type RaftTransportOptions
- type RoundTripOptions
- type UDPRelay
- type UDPRelayOptions
Constants ¶
const ( // BootstrapProtocol is the protocol used for bootstrapping a mesh. BootstrapProtocol = protocol.ID("/webmesh/bootstrap/0.0.1") // RPCProtocol is the protocol used for executing RPCs against a mesh. // The method should be appended to the end of the protocol. RPCProtocol = protocol.ID("/webmesh/rpc/0.0.1") // RaftProtocol is the protocol used for webmesh raft. // This is not used yet. RaftProtocol = protocol.ID("/webmesh/raft/0.0.1") // UDPRelayProtocol is the protocol used for relaying UDP packets. // The destination node should be appended to the end of the protocol. UDPRelayProtocol = protocol.ID("/webmesh/udp-relay/0.0.1") )
const MaxBuffer = 2500000
MaxBuffer is the maximum buffer size for libp2p.
Variables ¶
This section is empty.
Functions ¶
func NewAnnouncer ¶ added in v0.4.1
func NewAnnouncer[REQ, RESP any](ctx context.Context, opts AnnounceOptions, rt transport.UnaryServer[REQ, RESP]) (io.Closer, error)
NewAnnouncer creates a generic announcer for the given method, request, and response objects.
func NewAnnouncerWithHost ¶ added in v0.4.1
func NewAnnouncerWithHost[REQ, RESP any](ctx context.Context, host Host, opts AnnounceOptions, rt transport.UnaryServer[REQ, RESP]) io.Closer
NewAnnouncerWithHost creates a generic announcer for the given method, request, and response objects.
func NewDHT ¶ added in v0.4.0
func NewDHT(ctx context.Context, host host.Host, bootstrapPeers []multiaddr.Multiaddr, connectTimeout time.Duration) (*dht.IpfsDHT, error)
NewDHT returns a DHT for given host. If bootstrap peers is empty, the default bootstrap peers will be used.
func NewJoinAnnouncer ¶ added in v0.4.0
func NewJoinAnnouncer(ctx context.Context, opts AnnounceOptions, join transport.JoinServer) (io.Closer, error)
NewJoinAnnouncer creates a new announcer on the kadmilia DHT and executes received join requests against the given join Server.
func NewJoinAnnouncerWithHost ¶ added in v0.4.1
func NewJoinAnnouncerWithHost(ctx context.Context, host Host, opts AnnounceOptions, join transport.JoinServer) io.Closer
NewJoinAnnouncerWithHost creates a new announcer on the kadmilia DHT and executes received join requests against the given join Server.
func NewJoinRoundTripper ¶
func NewJoinRoundTripper(ctx context.Context, opts RoundTripOptions) (transport.JoinRoundTripper, error)
NewJoinRoundTripper returns a round tripper that uses the libp2p kademlia DHT to join a cluster. The created host is closed when the round tripper is closed.
func NewJoinRoundTripperWithHost ¶ added in v0.4.1
func NewJoinRoundTripperWithHost(host Host, opts RoundTripOptions) transport.JoinRoundTripper
NewJoinRoundTripperHost returns a round tripper that uses the libp2p kademlia DHT to join a cluster.
func NewLibP2PHost ¶ added in v0.4.1
NewLibP2PHost creates a new libp2p host with the given options.
func NewRaftTransport ¶ added in v0.3.3
NewRaftTransport creates a new Raft transport over the Kademlia DHT.
func NewRoundTripper ¶
func NewRoundTripper[REQ, RESP any](ctx context.Context, opts RoundTripOptions) (transport.RoundTripper[REQ, RESP], error)
NewRoundTripper returns a round tripper that uses the libp2p kademlia DHT. The created host is closed when the round tripper is closed.
func NewRoundTripperWithHost ¶ added in v0.4.1
func NewRoundTripperWithHost[REQ, RESP any](host Host, opts RoundTripOptions) transport.RoundTripper[REQ, RESP]
NewRoundTripper returns a round tripper that uses the libp2p kademlia DHT.
func RPCProtocolFor ¶ added in v0.4.1
RPCProtocolFor returns the RPCProtocol for the given method.
func SetMaxSystemBuffers ¶ added in v0.4.1
SetMaxSystemBuffers sets the system buffers to the maximum size for libp2p.
func SetSystemBuffers ¶ added in v0.4.1
SetSystemBuffers sets the system buffers to use for libp2p.
func UDPRelayProtocolFor ¶ added in v0.4.1
UDPRelayProtocolFor returns the UDPRelayProtocol for accepting connections from the given node.
Types ¶
type AnnounceOptions ¶ added in v0.4.1
type AnnounceOptions struct { // Rendezvous is the pre-shared key to use as a rendezvous point for the DHT. Rendezvous string // AnnounceTTL is the TTL to use for the discovery service. AnnounceTTL time.Duration // HostOptions are options for configuring the host. These can be left // empty if using a pre-created host. HostOptions HostOptions // Method is the method to announce. Method string // Host is a pre-started host to use for announcing. Host Host }
AnnounceOptions are options for announcing the host or discovering peers on the libp2p kademlia DHT.
type Announcer ¶ added in v0.4.1
type Announcer interface { // AnnounceToDHT should announce the join protocol to the DHT, // such that it can be used by a libp2p transport.JoinRoundTripper. AnnounceToDHT(ctx context.Context, opts AnnounceOptions) error // LeaveDHT should remove the join protocol from the DHT for the // given rendezvous string. LeaveDHT(ctx context.Context, rendezvous string) error }
Announcer is an interface for nodes that can announce themselves to the network.
type BootstrapOptions ¶ added in v0.4.1
type BootstrapOptions struct { // Rendezvous is the rendezvous string to use for the transport. // This should be the same for all sides of the transport. Rendezvous string // Signer is provided to sign and verify the UUIDs of the voters. Signer crypto.PSK // Host are options for configuring a host if one is not provided. Host HostOptions // ElectionTimeout is the election timeout. The election timeout should // be larger than the host's connection timeout. Otherwise, chances // of a successful election are low. This does not apply when all sides // provide an already bootstrapped host to the transport. All sides of // the transport should use the same election timeout. ElectionTimeout time.Duration // Linger is the time to wait for non-leaders to join before closing the host. Linger time.Duration // NodeID is the node ID to use for leader election. This should be the // local node ID. NodeID string // NodeIDs are the other node IDs to use for leader election. NodeIDs []string }
BootstrapOptions are options for the bootstrap transport.
type BootstrapTransport ¶ added in v0.4.1
type BootstrapTransport interface { transport.BootstrapTransport // UUID returns the local UUID that was used for voting. UUID() uuid.UUID // LeaderUUID returns the UUID of the leader that was elected. // This is only populated after leader election is complete. LeaderUUID() uuid.UUID }
BootstrapTransport implements bootstrap transport and returns the local UUID that was used for voting.
func NewBootstrapTransport ¶ added in v0.4.1
func NewBootstrapTransport(ctx context.Context, announcer Announcer, opts BootstrapOptions) (BootstrapTransport, error)
NewBootstrapTransport creates a new bootstrap transport. The host is closed when leader election is complete.
func NewBootstrapTransportWithHost ¶ added in v0.4.1
func NewBootstrapTransportWithHost(host Host, announcer Announcer, opts BootstrapOptions) (BootstrapTransport, error)
NewBootstrapTransportWithHost creates a new bootstrap transport with a host. The host will remain open after leader election is complete.
type Host ¶ added in v0.4.1
type Host interface { // ID returns the peer ID of the host. ID() peer.ID // Host is the underlying libp2p host. Host() host.Host // DHT is the underlying libp2p DHT. DHT() *dht.IpfsDHT // JoinAnnouncer returns a new join announcer using this host. JoinAnnouncer(ctx context.Context, opts AnnounceOptions, rt transport.JoinServer) io.Closer // JoinRoundTripper returns a round tripper for executing a join request. JoinRoundTripper(ctx context.Context, opts RoundTripOptions) transport.JoinRoundTripper // Close closes the host and its DHT. Close(ctx context.Context) error }
Host is an interface that provides facilities for discovering and connecting to peers over libp2p. It can be used to avoid the need for re-creating a libp2p host and bootstrapping the DHT for each new connection.
func NewFromHostAndDHT ¶ added in v0.4.1
NewFromHostAndDHT creates a new libp2p host from an existing host and DHT. This is primarily used for testing.
type HostOptions ¶ added in v0.4.1
type HostOptions struct { // BootstrapPeers is a list of bootstrap peers to use for the DHT. // If empty or nil, the default bootstrap peers will be used. BootstrapPeers []multiaddr.Multiaddr // Options are options for configuring the libp2p host. Options []config.Option // LocalAddrs is a list of local addresses to announce the host with. // If empty or nil, the default local addresses will be used. LocalAddrs []multiaddr.Multiaddr // ConnectTimeout is the timeout for connecting to peers when bootstrapping. ConnectTimeout time.Duration }
HostOptions are options for creating a new libp2p host.
type RaftTransportOptions ¶ added in v0.3.3
type RaftTransportOptions struct { // PSK is the pre-shared key to use as a rendezvous point for the DHT. PSK string // BootstrapPeers is a list of bootstrap peers to use for the DHT. // If empty or nil, the default bootstrap peers will be used. BootstrapPeers []multiaddr.Multiaddr // LocalAddrs is a list of local addresses to use for the host. // If empty or nil, the default local addresses will be used. LocalAddrs []multiaddr.Multiaddr // Options are options for configuring the libp2p host. Options []config.Option // DiscoveryTTL is the TTL to use for the discovery service. DiscoveryTTL time.Duration // ConnectTimeout is the timeout to use when connecting to a peer. ConnectTimeout time.Duration // LeaderDialer is the function that will be used to dial the leader. LeaderDialer transport.LeaderDialer }
RaftTransportOptions are options for the TCP transport.
type RoundTripOptions ¶
type RoundTripOptions struct { // Rendezvous is the pre-shared key to use as a rendezvous point for the DHT. Rendezvous string // HostOptions are options for configuring the host. These can be left // empty if using a pre-created host. HostOptions HostOptions // Method is the method to try to execute. Method string // Host is a pre-started host to use for the round trip Host Host }
RoundTripOptions are options for performing a round trip against a libp2p host.
type UDPRelay ¶ added in v0.4.1
type UDPRelay struct { UDPRelayOptions // contains filtered or unexported fields }
UDPRelay is a UDP relay.
func NewUDPRelay ¶ added in v0.4.1
func NewUDPRelay(ctx context.Context, opts UDPRelayOptions) (*UDPRelay, error)
NewUDPRelay creates a new UDP relay.
func NewUDPRelayWithHost ¶ added in v0.4.1
NewUDPRelay creates a new UDP relay with the given host.
func (*UDPRelay) Closed ¶ added in v0.4.1
func (u *UDPRelay) Closed() <-chan struct{}
Closed returns a channel that is closed when the relay is closed.
type UDPRelayOptions ¶ added in v0.4.1
type UDPRelayOptions struct { // LocalNode is the local node to negotiate a UDP relay with. LocalNode string // RemoteNode is the remote node to negotiate a UDP relay with. RemoteNode string // Rendezvous is the rendezvous string to use for negotiating a UDP relay. Rendezvous string // Relay are options for the relay Relay relay.UDPOptions // Host are options for configuring the host Host HostOptions }
UDPRelayOptions are the options for negotiating a UDP relay.