wgtransport

package
v0.6.2 Latest Latest
Warning

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

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

Documentation

Overview

Package wgtransport implements a Webmesh WireGuard transport for libp2p.

Index

Constants

View Source
const NewStreamMagic = "WEBMESH_NEW_STREAM\n"

NewStreamMagic is the magic string that is sent to the signaling server to request a new stream.

Variables

This section is empty.

Functions

func NewOptions

func NewOptions(log *slog.Logger) libp2p.Option

NewOptions returns a chained option for all the components of a webmesh transport.

Types

type CapableConn

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

CapableConn is a webmesh capable connection.

func (*CapableConn) AcceptStream

func (c *CapableConn) AcceptStream() (network.MuxedStream, error)

AcceptStream accepts a stream opened by the other side.

func (*CapableConn) Close

func (c *CapableConn) Close() error

Close closes the connection.

func (*CapableConn) ConnState

func (c *CapableConn) ConnState() network.ConnectionState

ConnState returns information about the connection state.

func (*CapableConn) IsClosed

func (c *CapableConn) IsClosed() bool

IsClosed returns whether a connection is fully closed, so it can be garbage collected.

func (*CapableConn) LocalMultiaddr

func (c *CapableConn) LocalMultiaddr() ma.Multiaddr

LocalMultiaddr returns the local Multiaddr associated with this connection

func (*CapableConn) LocalPeer

func (c *CapableConn) LocalPeer() peer.ID

LocalPeer returns our peer ID

func (*CapableConn) OpenStream

func (c *CapableConn) OpenStream(ctx context.Context) (network.MuxedStream, error)

OpenStream creates a new stream.

func (*CapableConn) RemoteMultiaddr

func (c *CapableConn) RemoteMultiaddr() ma.Multiaddr

RemoteMultiaddr returns the remote Multiaddr associated with this connection

func (*CapableConn) RemotePeer

func (c *CapableConn) RemotePeer() peer.ID

RemotePeer returns the peer ID of the remote peer.

func (*CapableConn) RemotePublicKey

func (c *CapableConn) RemotePublicKey() crypto.PubKey

RemotePublicKey returns the public key of the remote peer.

func (*CapableConn) Scope

func (c *CapableConn) Scope() network.ConnScope

Scoped returns the connection's scope.

func (*CapableConn) Transport

func (c *CapableConn) Transport() transport.Transport

Transport returns the underlying transport.

type Constructor

type Constructor func(tu transport.Upgrader, host host.Host, key crypto.PrivKey, psk pnet.PSK, gater connmgr.ConnectionGater, rcmgr network.ResourceManager) (WebmeshTransport, error)

Constructor is the constructor for the webmesh transport.

func NewWithLogger

func NewWithLogger(log *slog.Logger) Constructor

NewWithLogger returns a new constructor for a webmesh transport using the given logger.

type EndpointsMessage

type EndpointsMessage struct {
	// Endpoints is a comma-separated list of strings of the form
	// <addr>:<port> that the peer is listening on.
	Endpoints string
	// Signature is the signature of the endpoints string.
	Signature []byte
}

EndpointsMessage is the message sent between peers to exchange endpoints.

type MuxedStream

type MuxedStream struct {
	*net.TCPConn
}

MuxedStream is a multiplexed stream.

func (*MuxedStream) CloseRead

func (s *MuxedStream) CloseRead() error

CloseRead closes the stream for reading but leaves it open for writing.

When CloseRead is called, all in-progress Read calls are interrupted with a non-EOF error and no further calls to Read will succeed.

The handling of new incoming data on the stream after calling this function is implementation defined.

CloseRead does not free the stream, users must still call Close or Reset.

func (*MuxedStream) CloseWrite

func (s *MuxedStream) CloseWrite() error

CloseWrite closes the stream for writing but leaves it open for reading.

CloseWrite does not free the stream, users must still call Close or Reset.

func (*MuxedStream) Reset

func (s *MuxedStream) Reset() error

Reset closes both ends of the stream. Use this to tell the remote side to hang up and go away.

type SecureConn

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

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

func (*SecureConn) Close

func (c *SecureConn) Close() error

func (*SecureConn) ConnState

func (c *SecureConn) ConnState() network.ConnectionState

ConnState returns information about the connection state.

func (*SecureConn) DialSignaler

func (c *SecureConn) DialSignaler(ctx context.Context) (*net.TCPConn, error)

DialSignals dials the signaling server on the other side of this connection.

func (*SecureConn) DialStream

func (c *SecureConn) DialStream(ctx context.Context, addr netip.AddrPort) (*net.TCPConn, error)

DialStreamListener dials the stream listener on the other side of this connection.

func (*SecureConn) LocalPeer

func (c *SecureConn) LocalPeer() peer.ID

LocalPeer returns our peer ID

func (*SecureConn) NewStreamListener

func (c *SecureConn) NewStreamListener() (*net.TCPListener, error)

NewStreamListener creates a new stream listener on this connection by allocating a random UDP port on the local wireguard interface.

func (*SecureConn) RemotePeer

func (c *SecureConn) RemotePeer() peer.ID

RemotePeer returns the peer ID of the remote peer.

func (*SecureConn) RemotePublicKey

func (c *SecureConn) RemotePublicKey() crypto.PubKey

RemotePublicKey returns the public key of the remote peer.

type SecureTransport

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

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

func (*SecureTransport) ID

func (st *SecureTransport) ID() protocol.ID

ID is the protocol ID of the security protocol.

func (*SecureTransport) NewSecureConn

func (st *SecureTransport) NewSecureConn(ctx context.Context, insecure net.Conn, rpeer peer.ID) (*SecureConn, error)

NewSecureConn upgrades an insecure connection with peer identity.

func (*SecureTransport) SecureInbound

func (st *SecureTransport) 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 (*SecureTransport) SecureOutbound

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

SecureOutbound secures an outbound connection.

type Transport

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

Transport is the webmesh wireguard transport.

func (*Transport) CanDial

func (t *Transport) 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 (*Transport) Close

func (t *Transport) Close() error

Close shuts down the wireguard interface.

func (*Transport) Dial

func (t *Transport) Dial(ctx context.Context, rmaddr ma.Multiaddr, p peer.ID) (transport.CapableConn, error)

Dial dials the given multiaddr.

func (*Transport) Listen

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

Listen listens on the passed multiaddr.

func (*Transport) Protocols

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

Protocol returns the set of protocols handled by this transport.

func (*Transport) Proxy

func (t *Transport) Proxy() bool

Proxy returns true if this is a proxy transport.

func (*Transport) WireGuardEndpoints

func (t *Transport) WireGuardEndpoints() []string

WireGuardEndpoints returns the exposed endpoints for our wireguard interface.

type Upgrader

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

Upgrader is the webmesh upgrader. It checks for a magic header on incoming connections and upgrades them to a full webmesh connection. Otherwise it passes them to the default libp2p upgrader.

func (*Upgrader) Upgrade

Upgrade upgrades the multiaddr/net connection into a full libp2p-transport connection. It looks for a magic header on the connection and upgrades it to a full webmesh connection. Otherwise it passes it to the default libp2p upgrader.

func (*Upgrader) UpgradeListener

func (u *Upgrader) UpgradeListener(t transport.Transport, ln mnet.Listener) transport.Listener

UpgradeListener upgrades the passed multiaddr-net listener into a full libp2p-transport listener.

type WebmeshListener

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

WebmeshListener wraps a basic listener to be upgraded and injects the transport into incoming connections.

func (*WebmeshListener) Accept

func (ln *WebmeshListener) Accept() (transport.CapableConn, error)

Accept waits for and returns the next connection to the listener.

func (*WebmeshListener) Addr

func (ln *WebmeshListener) Addr() net.Addr

Addr returns the local listener address.

func (*WebmeshListener) Close

func (ln *WebmeshListener) Close() error

Close closes the listener.

func (*WebmeshListener) Multiaddr

func (ln *WebmeshListener) Multiaddr() ma.Multiaddr

Multiaddr encapsulates the listener with the webmesh protocol.

type WebmeshTransport

type WebmeshTransport interface {
	// Closer for the underlying transport that shuts down the webmesh node.
	io.Closer
	// Transport is the underlying libp2p Transport.
	transport.Transport
}

WebmeshTransport is the webmesh wireguard 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.

func New

New is the standard constructor for a webmesh transport.

Jump to

Keyboard shortcuts

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