transport

package
v0.6.0 Latest Latest
Warning

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

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

Documentation

Overview

Package transport defines the libp2p webmesh transport.

Index

Constants

View Source
const PrefixSize = 112

PrefixSize is the local prefix size assigned to each peer.

Variables

View Source
var ErrInvalidSecureTransport = fmt.Errorf("transport must be used with a webmesh keypair and security transport")

ErrInvalidSecureTransport is returned when the transport is not used with a webmesh keypair and security transport.

View Source
var ErrNotStarted = fmt.Errorf("transport is not started")

ErrNotStarted is returned when the transport is not started.

Functions

func New

New returns a new webmesh transport builder.

func NewLite

New returns a new lite webmesh transport builder.

Types

type LiteOptions

type LiteOptions struct {
	// Config is the configuration for the WireGuard interface.
	Config WireGuardOptions
	// EndpointDetection are options for doing public endpoint
	// detection for the wireguard interface.
	EndpointDetection *endpoints.DetectOpts
	// Logger is the logger to use for the webmesh transport.
	// If nil, an empty logger will be used.
	Logger *slog.Logger
}

LiteOptions are the options for the lite webmesh transport.

type LiteSecureConn

type LiteSecureConn struct {
	net.Conn
	// contains filtered or unexported fields
}

LiteSecureConn is a simple wrapper around a sec.SecureConn that just holds the peer information.

func (*LiteSecureConn) ConnState

func (l *LiteSecureConn) ConnState() network.ConnectionState

ConnState returns information about the connection state.

func (*LiteSecureConn) LocalPeer

func (l *LiteSecureConn) LocalPeer() peer.ID

LocalPeer returns our peer ID

func (*LiteSecureConn) RemotePeer

func (l *LiteSecureConn) RemotePeer() peer.ID

RemotePeer returns the peer ID of the remote peer.

func (*LiteSecureConn) RemotePublicKey

func (l *LiteSecureConn) RemotePublicKey() p2pcrypto.PubKey

RemotePublicKey returns the public key of the remote peer.

type LiteSecureTransport

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

LiteSecureTransport provides a sec.SecureTransport that will automatically set up routes and compute addresses for peers as connections are opened.

func (*LiteSecureTransport) ID

ID is the protocol ID of the security protocol.

func (*LiteSecureTransport) SecureInbound

func (l *LiteSecureTransport) SecureInbound(ctx context.Context, insecure net.Conn, p peer.ID) (sec.SecureConn, error)

SecureInbound secures an inbound connection. If p is empty, connections from any peer are accepted.

func (*LiteSecureTransport) SecureOutbound

func (l *LiteSecureTransport) SecureOutbound(ctx context.Context, insecure net.Conn, p peer.ID) (sec.SecureConn, error)

SecureOutbound secures an outbound connection.

type LiteTransport

type LiteTransport interface {
	// Closer for the underlying transport that shuts down the webmesh node.
	io.Closer
	// Transport is the underlying libp2p Transport.
	transport.Transport
	// Resolver is a resolver that uses the mesh storage to lookup peers.
	transport.Resolver
}

LiteTransport is the lite webmesh transport. This transport does not run a full mesh node, but rather utilizes libp2p streams to perform an authenticated keypair negotiation to compute IPv6 addresses for peers.

type LiteWebmeshTransport

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

LiteWebmeshTransport is the lite webmesh transport.

func (*LiteWebmeshTransport) BroadcastAddrs

func (t *LiteWebmeshTransport) BroadcastAddrs(addrs []ma.Multiaddr) []ma.Multiaddr

BroadcastAddrs implements AddrsFactory on top of this transport. It automatically appends our webmesh ID to the addresses.

func (*LiteWebmeshTransport) CanDial

func (t *LiteWebmeshTransport) CanDial(addr ma.Multiaddr) bool

CanDial returns true if this transport knows how to dial the given multiaddr.

Returning true does not guarantee that dialing this multiaddr will succeed. This function should *only* be used to preemptively filter out addresses that we can't dial.

func (*LiteWebmeshTransport) Close

func (t *LiteWebmeshTransport) Close() error

func (*LiteWebmeshTransport) Dial

Dial dials a remote peer. It should try to reuse local listener addresses if possible, but it may choose not to.

func (*LiteWebmeshTransport) Listen

Listen listens on the passed multiaddr.

func (*LiteWebmeshTransport) Protocols

func (t *LiteWebmeshTransport) Protocols() []int

Protocol returns the set of protocols handled by this transport.

func (*LiteWebmeshTransport) Proxy

func (t *LiteWebmeshTransport) Proxy() bool

Proxy returns true if this is a proxy transport.

func (*LiteWebmeshTransport) Resolve

func (t *LiteWebmeshTransport) Resolve(ctx context.Context, maddr ma.Multiaddr) ([]ma.Multiaddr, error)

Resolve attempts to resolve the given multiaddr to a list of addresses.

type Options

type Options struct {
	// Config is the webmesh config.
	Config *config.Config
	// LogLevel is the log level for the webmesh transport.
	LogLevel string
	// StartTimeout is the timeout for starting the webmesh node.
	StartTimeout time.Duration
	// StopTimeout is the timeout for stopping the webmesh node.
	StopTimeout time.Duration
	// ListenTimeout is the timeout for starting a listener on the webmesh node.
	ListenTimeout time.Duration
	// Logger is the logger to use for the webmesh transport.
	// If nil, an empty logger will be used.
	Logger *slog.Logger
}

Options are the options for the webmesh transport.

type SecurityTransportBuilder

type SecurityTransportBuilder func() sec.SecureTransport

type Transport

type Transport interface {
	// Closer for the underlying transport that shuts down the webmesh node.
	io.Closer
	// Transport is the underlying libp2p Transport.
	transport.Transport
	// Resolver is a resolver that uses the mesh storage to lookup peers.
	transport.Resolver
}

Transport is the webmesh transport.

type TransportBuilder

type TransportBuilder func(upgrader transport.Upgrader, host host.Host, rcmgr network.ResourceManager, privKey pcrypto.PrivKey) (Transport, error)

TransportBuilder is the signature of a function that builds a webmesh transport.

type WebmeshTransport

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

WebmeshTransport is the webmesh libp2p transport. It must be used with a webmesh keypair and security transport.

func (*WebmeshTransport) BroadcastAddrs

func (t *WebmeshTransport) BroadcastAddrs(addrs []ma.Multiaddr) []ma.Multiaddr

BroadcastAddrs implements AddrsFactory on top of this transport. It automatically appends our webmesh ID and any DNS addresses we have to the list of addresses.

func (*WebmeshTransport) CanDial

func (t *WebmeshTransport) CanDial(addr ma.Multiaddr) bool

CanDial returns true if this transport knows how to dial the given multiaddr.

Returning true does not guarantee that dialing this multiaddr will succeed. This function should *only* be used to preemptively filter out addresses that we can't dial.

func (*WebmeshTransport) Close

func (t *WebmeshTransport) Close() error

Close closes the transport.

func (*WebmeshTransport) Dial

Dial dials a remote peer. It should try to reuse local listener addresses if possible, but it may choose not to.

func (*WebmeshTransport) Listen

func (t *WebmeshTransport) Listen(laddr ma.Multiaddr) (transport.Listener, error)

Listen listens on the passed multiaddr.

func (*WebmeshTransport) Protocols

func (t *WebmeshTransport) Protocols() []int

Protocol returns the set of protocols handled by this transport.

func (*WebmeshTransport) Proxy

func (t *WebmeshTransport) Proxy() bool

Proxy returns true if this is a proxy transport.

func (*WebmeshTransport) Resolve

func (t *WebmeshTransport) Resolve(ctx context.Context, maddr ma.Multiaddr) ([]ma.Multiaddr, error)

Resolve attempts to resolve the given multiaddr to a list of addresses.

type WireGuardOptions

type WireGuardOptions struct {
	// ListenPort is the port to listen on.
	// If 0, a default port of 51820 will be used.
	ListenPort uint16
	// InterfaceName is the name of the interface to use.
	// If empty, a default platform dependent name will be used.
	InterfaceName string
	// ForceInterfaceName forces the interface name to be used.
	// If false, the interface name will be changed if it already exists.
	ForceInterfaceName bool
	// MTU is the MTU to use for the interface.
	// If 0, a default MTU of 1420 will be used.
	MTU int
}

WireGuardOptions are options for configuring the WireGuard interface on the transport.

func (*WireGuardOptions) Default

func (w *WireGuardOptions) Default()

Jump to

Keyboard shortcuts

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