Documentation ¶
Overview ¶
Package datachannels provides a WebRTC data channel API for port forwarding.
Index ¶
- Constants
- type ClientChannel
- type ClientOptions
- type ManagedServerChannel
- type OfferOptions
- type PeerConnectionClient
- func (pc *PeerConnectionClient) Closed() <-chan struct{}
- func (pc *PeerConnectionClient) Errors() <-chan error
- func (pc *PeerConnectionClient) Handle(conn net.Conn)
- func (pc *PeerConnectionClient) ListenAndServe(ctx context.Context, proto, addr string) error
- func (pc *PeerConnectionClient) Ready() <-chan struct{}
- func (pc *PeerConnectionClient) Serve(ctx context.Context, l net.Listener) error
- type PeerConnectionServer
- func (pc *PeerConnectionServer) AddCandidate(cand string) error
- func (pc *PeerConnectionServer) AnswerOffer(answer string) error
- func (pc *PeerConnectionServer) Candidates() <-chan string
- func (pc *PeerConnectionServer) Closed() <-chan struct{}
- func (pc *PeerConnectionServer) IsClosed() bool
- func (pc *PeerConnectionServer) Offer() string
- func (pc *PeerConnectionServer) Ready() <-chan struct{}
- type ServerChannel
- type WireGuardProxyClient
- type WireGuardProxyServer
- func (w *WireGuardProxyServer) AddCandidate(cand string) error
- func (w *WireGuardProxyServer) AnswerOffer(answer string) error
- func (w *WireGuardProxyServer) Candidates() <-chan string
- func (w *WireGuardProxyServer) Close() error
- func (w *WireGuardProxyServer) Closed() <-chan struct{}
- func (w *WireGuardProxyServer) Offer() string
Constants ¶
const DefaultWireGuardProxyBuffer = 1024 * 1024
DefaultWireGuardProxyBuffer is the default buffer size for the WireGuard proxy. TODO: Make this configurable.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientChannel ¶
type ClientChannel interface { // Ready returns a channel that is closed when the data channel is ready. Ready() <-chan struct{} // Errors returns a channel for receiving errors. Errors() <-chan error // Closed returns a channel for receiving a notification when the data channel is closed. Closed() <-chan struct{} // Open opens a new data channel. Open(ctx context.Context, proto string) (io.ReadWriteCloser, error) // Close closes the peer connection and all data channels. Close() error }
ClientChannel is a client-side data channel.
func NewClientChannel ¶
func NewClientChannel(ctx context.Context, rt transport.WebRTCSignalTransport) (ClientChannel, error)
NewClientChannel creates a new client-side data channel.
type ClientOptions ¶
type ClientOptions struct { // Client is the webmesh client for performing ICE negotiation. Client v1.WebRTCClient // NodeID is the node ID to request for connection channels. NodeID string // Protocol is the protocol to request for connection channels. Protocol string // Destination is the destination address to request for connection channels. Destination string // Port is the destination port to request for connection channels. // A port of 0 with the udp protocol indicates WireGuard interface traffic. Port uint32 }
ClientOptions are options for configuring a client peer connection.
type ManagedServerChannel ¶
type ManagedServerChannel interface { // Offer returns the offer for the data channel. Offer() string // AnswerOffer answers the offer from the peer. AnswerOffer(offer string) error // Candidates returns a channel for receiving ICE candidates. Candidates() <-chan string // AddCandidate adds an ICE candidate. AddCandidate(candidate string) error // Closed returns a channel for receiving a notification when the data channel is closed. Closed() <-chan struct{} // Close closes the data channel. Close() error }
ManagedServerChannel is a channel that is managed for a particular purpose. This is currently used for the WireGuard proxy and the port-forwarding data channels.
type OfferOptions ¶
type OfferOptions struct { // Proto is the protocol used for the connection. // Defaults to "tcp". Proto string // SrcAddress is the source address and port of the client that // initiated the connection. SrcAddress string // DstAddress is the destination address and port of the connection. DstAddress string // STUNServers is a list of STUN servers to use for the connection. STUNServers []string }
Offer represents an offer to be sent to a peer.
type PeerConnectionClient ¶
type PeerConnectionClient struct { // PeerConnection is the underlying WebRTC peer connection. *webrtc.PeerConnection // contains filtered or unexported fields }
PeerConnectionClient is a WebRTC peer connection for port forwarding.
func NewPeerConnectionClient ¶
func NewPeerConnectionClient(ctx context.Context, protocol string, rt transport.WebRTCSignalTransport) (*PeerConnectionClient, error)
NewPeerConnectionClient creates a new peer connection client.
func (*PeerConnectionClient) Closed ¶
func (pc *PeerConnectionClient) Closed() <-chan struct{}
Closed returns a channel for receiving a notification when the peer connection is closed.
func (*PeerConnectionClient) Errors ¶
func (pc *PeerConnectionClient) Errors() <-chan error
Errors returns a channel for receiving errors from the peer connection.
func (*PeerConnectionClient) Handle ¶
func (pc *PeerConnectionClient) Handle(conn net.Conn)
Handle handles the given connection.
func (*PeerConnectionClient) ListenAndServe ¶
func (pc *PeerConnectionClient) ListenAndServe(ctx context.Context, proto, addr string) error
ListenAndServe creates a listener and passes incoming connections to the handler.
func (*PeerConnectionClient) Ready ¶
func (pc *PeerConnectionClient) Ready() <-chan struct{}
Ready returns a channel for receiving a notification when the peer connection is ready.
type PeerConnectionServer ¶
type PeerConnectionServer struct { // PeerConnection is the underlying WebRTC peer connection. *webrtc.PeerConnection // contains filtered or unexported fields }
PeerConnectionServer represents a connection to a peer where we forward traffic for the other end.
func NewPeerConnectionServer ¶
func NewPeerConnectionServer(ctx context.Context, opts *OfferOptions) (*PeerConnectionServer, error)
NewPeerConnectionServer creates a new peer connection server with the given options.
func (*PeerConnectionServer) AddCandidate ¶
func (pc *PeerConnectionServer) AddCandidate(cand string) error
AddCandidate adds an ICE candidate to the peer connection.
func (*PeerConnectionServer) AnswerOffer ¶
func (pc *PeerConnectionServer) AnswerOffer(answer string) error
AnswerOffer answers the given offer from the peer.
func (*PeerConnectionServer) Candidates ¶
func (pc *PeerConnectionServer) Candidates() <-chan string
Candidates returns a channel that will receive potential ICE candidates for the peer.
func (*PeerConnectionServer) Closed ¶
func (pc *PeerConnectionServer) Closed() <-chan struct{}
Closed returns a channel that will be closed when the peer connection is closed.
func (*PeerConnectionServer) IsClosed ¶
func (pc *PeerConnectionServer) IsClosed() bool
IsClosed returns true if the peer connection is closed.
func (*PeerConnectionServer) Offer ¶
func (pc *PeerConnectionServer) Offer() string
Offer returns the offer to be sent to the peer.
func (*PeerConnectionServer) Ready ¶
func (pc *PeerConnectionServer) Ready() <-chan struct{}
Ready returns a channel that will be closed when the peer connection is ready.
type ServerChannel ¶
type ServerChannel interface { // Accept accepts a new connection channel. Accept() (proto string, rw io.ReadWriteCloser, err error) // Ready returns a channel that is closed when the data channel is ready. Ready() <-chan struct{} // Errors returns a channel for receiving errors. Errors() <-chan error // Closed returns a channel for receiving a notification when the data channel is closed. Closed() <-chan struct{} // Close closes the data channel. Close() error }
ServerChannel is a server-side data channel.
func NewServerChannel ¶
func NewServerChannel(ctx context.Context, rt transport.WebRTCSignalTransport) (ServerChannel, error)
NewServerChannel creates a new server-side data channel.
type WireGuardProxyClient ¶
type WireGuardProxyClient struct {
// contains filtered or unexported fields
}
WireGuardProxyClient is a WireGuard proxy client. It is used for outgoing requests to establish a WireGuard proxy connection.
func NewWireGuardProxyClient ¶
func NewWireGuardProxyClient(ctx context.Context, rt transport.WebRTCSignalTransport, targetPort uint16) (*WireGuardProxyClient, error)
NewWireGuardProxyClient creates a new WireGuardProxyClient using the given signaling transport. Traffic will be proxied to the wireguard interface listening on targetPort. It contains a method for retrieving the local address to use as a WireGuard endpoint for the peer on the other side of the proxy.
func (*WireGuardProxyClient) Close ¶
func (w *WireGuardProxyClient) Close() error
Close closes the proxy.
func (*WireGuardProxyClient) Closed ¶
func (w *WireGuardProxyClient) Closed() <-chan struct{}
Closed returns a channel that is closed when the proxy is closed.
func (*WireGuardProxyClient) LocalAddr ¶
func (w *WireGuardProxyClient) LocalAddr() *net.UDPAddr
LocalAddr returns the local UDP address for the proxy. This should be used as the endpoint for the WireGuard interface.
type WireGuardProxyServer ¶
type WireGuardProxyServer struct {
// contains filtered or unexported fields
}
WireguardProxyServer is a WebRTC datachannel proxy for WireGuard. It is used for incoming requests to proxy traffic to a WireGuard interface.
func NewWireGuardProxyServer ¶
func NewWireGuardProxyServer(ctx context.Context, stunServers []string, targetPort uint16) (*WireGuardProxyServer, error)
NewWireGuardProxyServer creates a new WireGuardProxyServer using the given STUN servers for ICE negotiation. Traffic will be proxied to the wireguard interface listening on targetPort.
func (*WireGuardProxyServer) AddCandidate ¶
func (w *WireGuardProxyServer) AddCandidate(cand string) error
AddCandidate adds an ICE candidate to the peer connection.
func (*WireGuardProxyServer) AnswerOffer ¶
func (w *WireGuardProxyServer) AnswerOffer(answer string) error
AnswerOffer sets the answer to the offer returned by the peer.
func (*WireGuardProxyServer) Candidates ¶
func (w *WireGuardProxyServer) Candidates() <-chan string
Candidates returns a channel that will receive potential ICE candidates to be sent to the peer.
func (*WireGuardProxyServer) Close ¶
func (w *WireGuardProxyServer) Close() error
Close closes the peer connection.
func (*WireGuardProxyServer) Closed ¶
func (w *WireGuardProxyServer) Closed() <-chan struct{}
Closed returns a channel that will be closed when the peer connection is closed.
func (*WireGuardProxyServer) Offer ¶
func (w *WireGuardProxyServer) Offer() string
Offer returns the offer to be sent to the peer.