Documentation ¶
Overview ¶
Package wgtransport implements a Webmesh WireGuard transport for libp2p.
Index ¶
- Constants
- func NewOptions(log *slog.Logger) libp2p.Option
- type CapableConn
- func (c *CapableConn) AcceptStream() (network.MuxedStream, error)
- func (c *CapableConn) Close() error
- func (c *CapableConn) ConnState() network.ConnectionState
- func (c *CapableConn) IsClosed() bool
- func (c *CapableConn) LocalMultiaddr() ma.Multiaddr
- func (c *CapableConn) LocalPeer() peer.ID
- func (c *CapableConn) OpenStream(ctx context.Context) (network.MuxedStream, error)
- func (c *CapableConn) RemoteMultiaddr() ma.Multiaddr
- func (c *CapableConn) RemotePeer() peer.ID
- func (c *CapableConn) RemotePublicKey() crypto.PubKey
- func (c *CapableConn) Scope() network.ConnScope
- func (c *CapableConn) Transport() transport.Transport
- type Constructor
- type EndpointsMessage
- type MuxedStream
- type SecureConn
- func (c *SecureConn) Close() error
- func (c *SecureConn) ConnState() network.ConnectionState
- func (c *SecureConn) DialSignaler(ctx context.Context) (*net.TCPConn, error)
- func (c *SecureConn) DialStream(ctx context.Context, addr netip.AddrPort) (*net.TCPConn, error)
- func (c *SecureConn) LocalPeer() peer.ID
- func (c *SecureConn) NewStreamListener() (*net.TCPListener, error)
- func (c *SecureConn) RemotePeer() peer.ID
- func (c *SecureConn) RemotePublicKey() crypto.PubKey
- type SecureTransport
- func (st *SecureTransport) ID() protocol.ID
- func (st *SecureTransport) NewSecureConn(ctx context.Context, insecure net.Conn, rpeer peer.ID) (*SecureConn, error)
- func (st *SecureTransport) SecureInbound(ctx context.Context, insecure net.Conn, p peer.ID) (sec.SecureConn, error)
- func (st *SecureTransport) SecureOutbound(ctx context.Context, insecure net.Conn, p peer.ID) (sec.SecureConn, error)
- type Transport
- func (t *Transport) CanDial(addr ma.Multiaddr) bool
- func (t *Transport) Close() error
- func (t *Transport) Dial(ctx context.Context, rmaddr ma.Multiaddr, p peer.ID) (transport.CapableConn, error)
- func (t *Transport) Listen(laddr ma.Multiaddr) (transport.Listener, error)
- func (t *Transport) Protocols() []int
- func (t *Transport) Proxy() bool
- func (t *Transport) WireGuardEndpoints() []string
- type Upgrader
- type WebmeshListener
- type WebmeshTransport
Constants ¶
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 ¶
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) 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 ¶
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 ¶
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 ¶
DialSignals dials the signaling server on the other side of this connection.
func (*SecureConn) DialStream ¶
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 ¶
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) Dial ¶
func (t *Transport) Dial(ctx context.Context, rmaddr ma.Multiaddr, p peer.ID) (transport.CapableConn, error)
Dial dials the given multiaddr.
func (*Transport) WireGuardEndpoints ¶
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 ¶
func (u *Upgrader) Upgrade(ctx context.Context, t transport.Transport, maconn mnet.Conn, dir network.Direction, p peer.ID, scope network.ConnManagementScope) (transport.CapableConn, error)
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.
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) 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.