Documentation
¶
Overview ¶
Package transport defines the libp2p webmesh transport.
Index ¶
- Constants
- Variables
- func New(opts Options) (TransportBuilder, *WebmeshTransport)
- func NewLite(opts LiteOptions) (TransportBuilder, SecurityTransportBuilder, *LiteWebmeshTransport)
- type LiteOptions
- type LiteSecureConn
- type LiteSecureTransport
- type LiteTransport
- type LiteWebmeshTransport
- func (t *LiteWebmeshTransport) BroadcastAddrs(addrs []ma.Multiaddr) []ma.Multiaddr
- func (t *LiteWebmeshTransport) CanDial(addr ma.Multiaddr) bool
- func (t *LiteWebmeshTransport) Close() error
- func (t *LiteWebmeshTransport) Dial(ctx context.Context, rmaddr ma.Multiaddr, p peer.ID) (transport.CapableConn, error)
- func (t *LiteWebmeshTransport) Listen(laddr ma.Multiaddr) (transport.Listener, error)
- func (t *LiteWebmeshTransport) Protocols() []int
- func (t *LiteWebmeshTransport) Proxy() bool
- func (t *LiteWebmeshTransport) Resolve(ctx context.Context, maddr ma.Multiaddr) ([]ma.Multiaddr, error)
- type Options
- type SecurityTransportBuilder
- type Transport
- type TransportBuilder
- type WebmeshTransport
- func (t *WebmeshTransport) BroadcastAddrs(addrs []ma.Multiaddr) []ma.Multiaddr
- func (t *WebmeshTransport) CanDial(addr ma.Multiaddr) bool
- func (t *WebmeshTransport) Close() error
- func (t *WebmeshTransport) Dial(ctx context.Context, raddr ma.Multiaddr, p peer.ID) (transport.CapableConn, error)
- func (t *WebmeshTransport) Listen(laddr ma.Multiaddr) (transport.Listener, error)
- func (t *WebmeshTransport) Protocols() []int
- func (t *WebmeshTransport) Proxy() bool
- func (t *WebmeshTransport) Resolve(ctx context.Context, maddr ma.Multiaddr) ([]ma.Multiaddr, error)
- type WireGuardOptions
Constants ¶
const PrefixSize = 112
PrefixSize is the local prefix size assigned to each peer.
Variables ¶
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.
var ErrNotStarted = fmt.Errorf("transport is not started")
ErrNotStarted is returned when the transport is not started.
Functions ¶
func New ¶
func New(opts Options) (TransportBuilder, *WebmeshTransport)
New returns a new webmesh transport builder.
func NewLite ¶
func NewLite(opts LiteOptions) (TransportBuilder, SecurityTransportBuilder, *LiteWebmeshTransport)
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 ¶
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 ¶
func (l *LiteSecureTransport) ID() p2pproto.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 ¶
func (t *LiteWebmeshTransport) Dial(ctx context.Context, rmaddr ma.Multiaddr, p peer.ID) (transport.CapableConn, error)
Dial dials a remote peer. It should try to reuse local listener addresses if possible, but it may choose not to.
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.
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 ¶
func (t *WebmeshTransport) Dial(ctx context.Context, raddr ma.Multiaddr, p peer.ID) (transport.CapableConn, error)
Dial dials a remote peer. It should try to reuse local listener addresses if possible, but it may choose not to.
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.
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()