datachannels

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package datachannels provides a WebRTC data channel API for port forwarding.

Index

Constants

View Source
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 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.

func (*ClientPeerConnection) Serve

Serve handles connections on the given listener.

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 {
	// 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, cli v1.WebRTCClient, targetNode string, targetPort int) (*WireGuardProxyClient, error)

NewWireGuardProxyClient creates a new WireGuard proxy client.

func (*WireGuardProxyClient) Close added in v0.1.10

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. Traffix will be proxied to the wireguard interface listening on targetPort.

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 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 added in v0.1.10

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.

Jump to

Keyboard shortcuts

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