epdisc

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2023 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Overview

Package epdisc implements endpoint (EP) discovery using Interactive Connection Establishment (ICE).

Index

Constants

View Source
const (
	ConnectionStateNew          = epdiscproto.ConnectionState_NEW
	ConnectionStateChecking     = epdiscproto.ConnectionState_CHECKING
	ConnectionStateConnected    = epdiscproto.ConnectionState_CONNECTED
	ConnectionStateCompleted    = epdiscproto.ConnectionState_COMPLETED
	ConnectionStateFailed       = epdiscproto.ConnectionState_FAILED
	ConnectionStateDisconnected = epdiscproto.ConnectionState_DISCONNECTED
	ConnectionStateClosed       = epdiscproto.ConnectionState_CLOSED
)
View Source
const (
	StunMagicCookie uint32 = 0x2112A442
)

Variables

View Source
var Get = daemon.RegisterFeature(New, 50) //nolint:gochecknoglobals

Functions

func CandidatePairCanBeNATted

func CandidatePairCanBeNATted(cp *ice.CandidatePair) bool

CandidatePairCanBeNATted checks if a given candidate pair can be used with kernel-space port address translation / natting.

func NftablesUserDataGet

func NftablesUserDataGet(udata []byte, styp NftablesUserDataType) []byte

func NftablesUserDataGetInt

func NftablesUserDataGetInt(udata []byte, typ NftablesUserDataType) (uint32, bool)

func NftablesUserDataGetString

func NftablesUserDataGetString(udata []byte, typ NftablesUserDataType) (string, bool)

func NftablesUserDataPut

func NftablesUserDataPut(udata []byte, typ NftablesUserDataType, data []byte) []byte

func NftablesUserDataPutInt

func NftablesUserDataPutInt(udata []byte, typ NftablesUserDataType, num uint32) []byte

func NftablesUserDataPutString

func NftablesUserDataPutString(udata []byte, typ NftablesUserDataType, str string) []byte

Types

type BindProxy

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

func NewBindProxy

func NewBindProxy(bind *wg.Bind, cp *ice.CandidatePair, conn *ice.Conn, logger *log.Logger) (*BindProxy, *net.UDPAddr, error)

func (*BindProxy) BindClose

func (p *BindProxy) BindClose() error

func (*BindProxy) Close

func (p *BindProxy) Close() error

func (*BindProxy) ListenPort

func (p *BindProxy) ListenPort() (uint16, bool)

func (*BindProxy) Receive

func (p *BindProxy) Receive(buf []byte) (int, wgconn.Endpoint, error)

func (*BindProxy) Send

func (p *BindProxy) Send(buf []byte, ep wgconn.Endpoint) (int, error)

func (*BindProxy) SetMark

func (p *BindProxy) SetMark(_ uint32) error

type ConnectionState

type ConnectionState = epdiscproto.ConnectionState
const (
	ConnectionStateConnecting ConnectionState = 100 + iota
	ConnectionStateClosing
	ConnectionStateCreating
	ConnectionStateRestarting
	ConnectionStateIdle
	ConnectionStateGathering
	ConnectionStateGatheringLocal  // After first remote candidate has been received
	ConnectionStateGatheringRemote // After first local candidate has been received
)

The following connection states are an extension to the states by the ICE RFC in order to mitigate race conditions when handling the pion/ice.Agent. They are mainly used for transitioning between the states above.

type Interface

type Interface struct {
	*daemon.Interface

	Peers map[*daemon.Peer]*Peer
	// contains filtered or unexported fields
}

func New

func New(di *daemon.Interface) (*Interface, error)

func (*Interface) Close

func (i *Interface) Close() error

func (*Interface) Endpoint

func (i *Interface) Endpoint() (*net.UDPAddr, error)

Endpoint returns the best guess about our own endpoint

func (*Interface) Marshal

func (i *Interface) Marshal() *epdiscproto.Interface

func (*Interface) OnBindOpen

func (i *Interface) OnBindOpen(b *wg.Bind, _ uint16)

func (*Interface) OnInterfaceModified

func (i *Interface) OnInterfaceModified(_ *daemon.Interface, _ *wg.Interface, m daemon.InterfaceModifier)

func (*Interface) OnPeerAdded

func (i *Interface) OnPeerAdded(cp *daemon.Peer)

func (*Interface) OnPeerModified

func (i *Interface) OnPeerModified(cp *daemon.Peer, _ *wgtypes.Peer, m daemon.PeerModifier, _, _ []net.IPNet)

func (*Interface) OnPeerRemoved

func (i *Interface) OnPeerRemoved(cp *daemon.Peer)

func (*Interface) PeerByPublicKey

func (i *Interface) PeerByPublicKey(pk crypto.Key) *Peer

func (*Interface) Start

func (i *Interface) Start() error

type KernelConnProxy

type KernelConnProxy struct {
	*BindProxy
	// contains filtered or unexported fields
}

func NewKernelConnProxy

func NewKernelConnProxy(bind *wg.Bind, cp *ice.CandidatePair, conn *ice.Conn, listenPort int, logger *log.Logger) (*KernelConnProxy, *net.UDPAddr, error)

func (*KernelConnProxy) Close

func (p *KernelConnProxy) Close() error

Close releases all resources of the proxy

func (*KernelConnProxy) WriteKernel

func (p *KernelConnProxy) WriteKernel(b []byte) (int, error)

type KernelNATProxy

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

func NewKernelNATProxy

func NewKernelNATProxy(cp *ice.CandidatePair, nat *NAT, listenPort int, logger *log.Logger) (*KernelNATProxy, *net.UDPAddr, error)

func (*KernelNATProxy) Close

func (p *KernelNATProxy) Close() error

type NAT

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

func NewNAT

func NewNAT(ident string) (*NAT, error)

func (*NAT) AddRule

func (n *NAT) AddRule(r *nftables.Rule, comment string) (*NATRule, error)

func (*NAT) Close

func (n *NAT) Close() error

func (*NAT) MasqueradeSourcePort

func (n *NAT) MasqueradeSourcePort(fromPort, toPort int, dest *net.UDPAddr) (*NATRule, error)

Perform SNAT to the source port of WireGuard UDP traffic to match port of our local ICE candidate

func (*NAT) RedirectNonSTUN

func (n *NAT) RedirectNonSTUN(origPort, newPort int) (*NATRule, error)

RedirectNonSTUN redirects non-STUN UDP ingress traffic directed at port 'toPort' to port 'toPort'.

type NATRule

type NATRule struct {
	*nftables.Rule
	// contains filtered or unexported fields
}

func (*NATRule) Delete

func (nr *NATRule) Delete() error

type NftablesUserDataType

type NftablesUserDataType byte
const (
	NftablesUserDataTypeComment NftablesUserDataType = iota
	NftablesUserDataTypeRuleID  NftablesUserDataType = 100 // custom extension
)

type Peer

type Peer struct {
	*daemon.Peer
	Interface *Interface
	// contains filtered or unexported fields
}

func NewPeer

func NewPeer(cp *daemon.Peer, e *Interface) (*Peer, error)

func (*Peer) Close

func (p *Peer) Close() error

Close destroys the peer as well as the ICE agent and proxies

func (*Peer) ConnectionState

func (p *Peer) ConnectionState() ConnectionState

func (*Peer) Marshal

func (p *Peer) Marshal() *epdiscproto.Peer

Marshal marshals a description of the peer into a Protobuf description

func (*Peer) OnBindOpen

func (p *Peer) OnBindOpen(b *wg.Bind, _ uint16)

func (*Peer) OnSignalingMessage

func (p *Peer) OnSignalingMessage(_ *crypto.PublicKeyPair, msg *signaling.Message)

OnSignalingMessage is invoked for every message received via the signaling backend

func (*Peer) Reachability

func (p *Peer) Reachability() coreproto.ReachabilityType

func (*Peer) Restart

func (p *Peer) Restart() error

Restart the ICE agent by creating a new one

func (*Peer) Resubscribe

func (p *Peer) Resubscribe(ctx context.Context, skOld crypto.Key) error

type Proxy

type Proxy interface {
	io.Closer
}

type ProxyConn

type ProxyConn struct {
	Proxy

	io.Closer
}

Jump to

Keyboard shortcuts

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