libp2p

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2023 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Overview

Package libp2p provides discovery mechanisms using Kademlia DHT.

Index

Constants

View Source
const JoinProtocol = protocol.ID("/webmesh/join/0.0.1")

JoinProtocol is the protocol used for joining a mesh.

View Source
const RaftProtocol = protocol.ID("/webmesh/raft/0.0.1")

RaftProtocol is the protocol used for webmesh raft.

View Source
const WebRTCSignalProtocol = protocol.ID("/webmesh/signal/0.0.1")

WebRTCSignalProtocol is the protocol used for webrtc-signaling.

Variables

This section is empty.

Functions

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 NewExternalSignalTransport added in v0.4.0

func NewExternalSignalTransport(ctx context.Context, opts WebRTCExternalSignalOptions) (transport.WebRTCSignalTransport, error)

NewExternalSignalTransport returns a new WebRTC signaling transport that attempts to negotiate a WebRTC connection using the Webmesh WebRTC signaling server. This is typically used by clients trying to create a proxy connection to a server.

func NewJoinAnnouncer added in v0.4.0

func NewJoinAnnouncer(ctx context.Context, opts JoinAnnounceOptions, 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 NewJoinRoundTripper

func NewJoinRoundTripper(opts RoundTripOptions) transport.JoinRoundTripper

NewJoinRoundTripper returns a round tripper that uses the libp2p kademlia DHT to join a cluster.

func NewRaftTransport added in v0.3.3

func NewRaftTransport(ctx context.Context, opts RaftTransportOptions) (raft.Transport, error)

NewRaftTransport creates a new Raft transport over the Kademlia DHT.

func NewRoundTripper

func NewRoundTripper[REQ, RESP any](opts RoundTripOptions, method string) transport.RoundTripper[REQ, RESP]

NewRoundTripper returns a round tripper that uses the libp2p kademlia DHT.

func SetBuffers added in v0.4.0

func SetBuffers(ctx context.Context)

SetBuffers sets the buffers to use for libp2p.

func WebRTCRendevousFrom added in v0.4.0

func WebRTCRendevousFrom(id protocol.ID) string

WebRTCRendevousFrom returns the rendevous string from the given protocol ID.

func WebRTCSignalProtocolFor added in v0.4.0

func WebRTCSignalProtocolFor(id string) protocol.ID

WebRTCSignalProtocolFor returns the protocol used for webrtc-signaling for the given rendevous string or peer ID.

Types

type DataChannelAnnounceOptions added in v0.4.0

type DataChannelAnnounceOptions struct {
	// RendevousStrings is a map of peer IDs to rendezvous strings
	// for allowing signaling through libp2p.
	RendezvousStrings map[string]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
	// Options are options for configuring the libp2p host.
	Options []config.Option
	// AnnounceTTL is the TTL for each announcement.
	AnnounceTTL time.Duration
	// 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
	// STUNServers is a list of STUN servers to use for NAT traversal.
	// If empty, the default STUN servers will be used.
	STUNServers []string
	// DataChannelTimeout is the timeout for starting data channel connections.
	DataChannelTimeout time.Duration
	// WireGuardPort is the port to use for WireGuard connections.
	WireGuardPort int
	// ConnectTimeout is the timeout for connecting to peers.
	ConnectTimeout time.Duration
}

DataChannelAnnounceOptions are options for announcing webrtc signaling for data channels to remote peers.

type DataChannelAnnouncer added in v0.4.0

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

func NewDataChannelAnnouncer added in v0.4.0

func NewDataChannelAnnouncer(ctx context.Context, opts DataChannelAnnounceOptions) (*DataChannelAnnouncer, error)

NewDataChannelAnnouncer creates a new announcer on the kadmilia DHT and executes received signaling requests against the local node.

func (*DataChannelAnnouncer) Close added in v0.4.0

func (a *DataChannelAnnouncer) Close() error

Close closes the announcer.

type JoinAnnounceOptions added in v0.4.0

type JoinAnnounceOptions 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
	// Options are options for configuring the libp2p host.
	Options []libp2p.Option
	// AnnounceTTL is the TTL to use for the discovery service.
	AnnounceTTL time.Duration
	// 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 to use when connecting to peers.
	ConnectTimeout time.Duration
}

JoinAnnounceOptions are options for announcing the host or discovering peers on the libp2p kademlia DHT.

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
	// Options are options for configuring the libp2p host.
	Options []libp2p.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 {
	// 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
	// Options are options for configuring the libp2p host.
	Options []libp2p.Option
	// ConnectTimeout is the per-address timeout for connecting to a peer.
	ConnectTimeout time.Duration
	// LocalAddrs is a list of local addresses to listen on.
	// If empty or nil, the default local addresses will be used.
	LocalAddrs []multiaddr.Multiaddr
}

RoundTripOptions are options for performing a round trip against a libp2p host.

type WebRTCExternalSignalOptions added in v0.4.0

type WebRTCExternalSignalOptions struct {
	// NodeID is the node ID to advertise to the peer. Contrary to other
	// uses of signaling, this is the node ID of the local node and not
	// the remote node. The remote node should be expecting this node ID
	// on the rendevous string.
	NodeID string
	// Rendevous is the rendevous string to use for the DHT.
	// The remote peer should be expecting NodeID on this rendevous string.
	Rendevous 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
	// Options are options for configuring the libp2p host.
	Options []libp2p.Option
	// ConnectTimeout is the per-address timeout for connecting to a peer.
	ConnectTimeout time.Duration
	// LocalAddrs is a list of local addresses to listen on.
	// If empty or nil, the default local addresses will be used.
	LocalAddrs []multiaddr.Multiaddr
	// TargetProto is the target protocol to request from the remote node.
	TargetProto string
	// TargetAddr is the target address to request from the remote node.
	TargetAddr netip.AddrPort
}

WebRTCExternalSignalOptions are options for configuring a WebRTC signaling transport.

Jump to

Keyboard shortcuts

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