Documentation ¶
Overview ¶
Package datachannels provides a WebRTC data channel API for port forwarding.
Index ¶
- Variables
- type ClientOptions
- type ClientPeerConnection
- func (pc *ClientPeerConnection) Closed() <-chan struct{}
- func (pc *ClientPeerConnection) Errors() <-chan error
- func (pc *ClientPeerConnection) Handle(conn net.Conn)
- func (pc *ClientPeerConnection) ListenAndServe(ctx context.Context, proto, addr string) error
- func (pc *ClientPeerConnection) Ready() <-chan struct{}
- func (pc *ClientPeerConnection) Serve(ctx context.Context, l net.Listener) error
- type OfferOptions
- type ServerChannel
- type ServerPeerConnection
- func (pc *ServerPeerConnection) AddCandidate(candidate string) error
- func (pc *ServerPeerConnection) AnswerOffer(answer string) error
- func (pc *ServerPeerConnection) Candidates() <-chan string
- func (pc *ServerPeerConnection) Closed() <-chan struct{}
- func (pc *ServerPeerConnection) IsClosed() bool
- func (pc *ServerPeerConnection) Offer() string
- type WireGuardProxyClient
- type WireGuardProxyServer
Constants ¶
This section is empty.
Variables ¶
var WebRTC *webrtc.API
WebRTC is the WebRTC API.
Functions ¶
This section is empty.
Types ¶
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 ClientPeerConnection ¶
type ClientPeerConnection struct { // PeerConnection is the underlying WebRTC peer connection. *webrtc.PeerConnection // contains filtered or unexported fields }
ClientPeerConnection is a WebRTC peer connection for port forwarding.
func NewClientPeerConnection ¶
func NewClientPeerConnection(ctx context.Context, opts *ClientOptions) (*ClientPeerConnection, error)
NewClientPeerConnection creates a new peer connection.
func (*ClientPeerConnection) Closed ¶
func (pc *ClientPeerConnection) Closed() <-chan struct{}
Closed returns a channel for receiving a notification when the peer connection is closed.
func (*ClientPeerConnection) Errors ¶
func (pc *ClientPeerConnection) Errors() <-chan error
Errors returns a channel for receiving errors from the peer connection.
func (*ClientPeerConnection) Handle ¶
func (pc *ClientPeerConnection) Handle(conn net.Conn)
Handle handles the given connection.
func (*ClientPeerConnection) ListenAndServe ¶
func (pc *ClientPeerConnection) ListenAndServe(ctx context.Context, proto, addr string) error
ListenAndServe creates a listener and passes incoming connections to the handler.
func (*ClientPeerConnection) Ready ¶
func (pc *ClientPeerConnection) Ready() <-chan struct{}
Ready returns a channel for receiving a notification when the peer connection is ready.
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 ServerChannel ¶
type ServerChannel 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 }
ServerChannel is a server-side data channel.
type ServerPeerConnection ¶
type ServerPeerConnection struct { // PeerConnection is the underlying WebRTC peer connection. *webrtc.PeerConnection // contains filtered or unexported fields }
ServerPeerConnection represents a connection to a peer where we forward traffic for the other end.
func NewServerPeerConnection ¶
func NewServerPeerConnection(opts *OfferOptions) (*ServerPeerConnection, error)
NewServerPeerConnection creates a new peer connection with the given options.
func (*ServerPeerConnection) AddCandidate ¶
func (pc *ServerPeerConnection) AddCandidate(candidate string) error
AddCandidate adds an ICE candidate to the peer connection.
func (*ServerPeerConnection) AnswerOffer ¶
func (pc *ServerPeerConnection) AnswerOffer(answer string) error
AnswerOffer answers the given offer from the peer.
func (*ServerPeerConnection) Candidates ¶
func (pc *ServerPeerConnection) Candidates() <-chan string
Candidates returns a channel that will receive potential ICE candidates for the peer.
func (*ServerPeerConnection) Closed ¶
func (pc *ServerPeerConnection) Closed() <-chan struct{}
Closed returns a channel that will be closed when the peer connection is closed.
func (*ServerPeerConnection) IsClosed ¶
func (pc *ServerPeerConnection) IsClosed() bool
IsClosed returns true if the peer connection is closed.
func (*ServerPeerConnection) Offer ¶
func (pc *ServerPeerConnection) Offer() string
Offer returns the offer to be sent to the peer.
type WireGuardProxyClient ¶
type WireGuardProxyClient struct { *webrtc.PeerConnection // contains filtered or unexported fields }
func NewWireGuardProxyClient ¶
func NewWireGuardProxyClient(ctx context.Context, cli v1.WebRTCClient, targetNode string, targetPort int) (*WireGuardProxyClient, error)
NewWireGuardProxyClient creates a new WireGuard proxy client.
func (*WireGuardProxyClient) Closed ¶
func (w *WireGuardProxyClient) Closed() <-chan struct{}
func (*WireGuardProxyClient) LocalAddr ¶
func (w *WireGuardProxyClient) LocalAddr() *net.UDPAddr
type WireGuardProxyServer ¶
type WireGuardProxyServer struct { *webrtc.PeerConnection // contains filtered or unexported fields }
func NewWireGuardProxyServer ¶
func (*WireGuardProxyServer) AddCandidate ¶
func (w *WireGuardProxyServer) AddCandidate(candidate string) error
AddCandidate adds an ICE candidate to the peer connection.
func (*WireGuardProxyServer) AnswerOffer ¶
func (w *WireGuardProxyServer) AnswerOffer(answer string) error
AnswerOffer answers the given offer from the peer.
func (*WireGuardProxyServer) Candidates ¶
func (w *WireGuardProxyServer) Candidates() <-chan string
Candidates returns a channel that will receive potential ICE candidates for the peer.
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.