bind

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Endpoint added in v0.30.3

type Endpoint = wgConn.StdNetEndpoint

type FilterFn

type FilterFn func(address netip.Addr) (bool, netip.Prefix, error)

FilterFn is a function that filters out candidates based on the address. If it returns true, the address is to be filtered. It also returns the prefix of matching route.

type ICEBind

type ICEBind struct {
	*wgConn.StdNetBind
	RecvChan chan RecvMessage
	// contains filtered or unexported fields
}

ICEBind is a bind implementation with two main features: 1. filter out STUN messages and handle them 2. forward the received packets to the WireGuard interface from the relayed connection

ICEBind.endpoints var is a map that stores the connection for each relayed peer. Fake address is just an IP address without port, in the format of 127.1.x.x where x.x is the last two octets of the peer address. We try to avoid to use the port because in the Send function the wgConn.Endpoint the port info is not exported.

func NewICEBind

func NewICEBind(transportNet transport.Net, filterFn FilterFn) *ICEBind

func (*ICEBind) Close added in v0.30.3

func (s *ICEBind) Close() error

func (*ICEBind) GetICEMux

func (s *ICEBind) GetICEMux() (*UniversalUDPMuxDefault, error)

GetICEMux returns the ICE UDPMux that was created and used by ICEBind

func (*ICEBind) Open added in v0.30.3

func (s *ICEBind) Open(uport uint16) ([]wgConn.ReceiveFunc, uint16, error)

func (*ICEBind) RemoveEndpoint added in v0.30.3

func (b *ICEBind) RemoveEndpoint(fakeUDPAddr *net.UDPAddr)

func (*ICEBind) Send added in v0.30.3

func (b *ICEBind) Send(bufs [][]byte, ep wgConn.Endpoint) error

func (*ICEBind) SetEndpoint added in v0.30.3

func (b *ICEBind) SetEndpoint(peerAddress *net.UDPAddr, conn net.Conn) (*net.UDPAddr, error)

type RecvMessage added in v0.30.3

type RecvMessage struct {
	Endpoint *Endpoint
	Buffer   []byte
}

type UDPMuxDefault

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

UDPMuxDefault is an implementation of the interface

func NewUDPMuxDefault

func NewUDPMuxDefault(params UDPMuxParams) *UDPMuxDefault

NewUDPMuxDefault creates an implementation of UDPMux

func (*UDPMuxDefault) Close

func (m *UDPMuxDefault) Close() error

Close the mux, no further connections could be created

func (*UDPMuxDefault) GetConn

func (m *UDPMuxDefault) GetConn(ufrag string, addr net.Addr) (net.PacketConn, error)

GetConn returns a PacketConn given the connection's ufrag and network address creates the connection if an existing one can't be found

func (*UDPMuxDefault) GetListenAddresses

func (m *UDPMuxDefault) GetListenAddresses() []net.Addr

GetListenAddresses returns the list of addresses that this mux is listening on

func (*UDPMuxDefault) HandleSTUNMessage

func (m *UDPMuxDefault) HandleSTUNMessage(msg *stun.Message, addr net.Addr) error

HandleSTUNMessage handles STUN packets and forwards them to underlying pion/ice library

func (*UDPMuxDefault) IsClosed

func (m *UDPMuxDefault) IsClosed() bool

IsClosed returns true if the mux had been closed

func (*UDPMuxDefault) LocalAddr

func (m *UDPMuxDefault) LocalAddr() net.Addr

LocalAddr returns the listening address of this UDPMuxDefault

func (*UDPMuxDefault) RemoveConnByUfrag

func (m *UDPMuxDefault) RemoveConnByUfrag(ufrag string)

RemoveConnByUfrag stops and removes the muxed packet connection

type UDPMuxParams

type UDPMuxParams struct {
	Logger  logging.LeveledLogger
	UDPConn net.PacketConn

	// Required for gathering local addresses
	// in case a un UDPConn is passed which does not
	// bind to a specific local address.
	Net             transport.Net
	InterfaceFilter func(interfaceName string) bool
}

UDPMuxParams are parameters for UDPMux.

type UniversalUDPMuxDefault

type UniversalUDPMuxDefault struct {
	*UDPMuxDefault
	// contains filtered or unexported fields
}

UniversalUDPMuxDefault handles STUN and TURN servers packets by wrapping the original UDPConn It then passes packets to the UDPMux that does the actual connection muxing.

func NewUniversalUDPMuxDefault

func NewUniversalUDPMuxDefault(params UniversalUDPMuxParams) *UniversalUDPMuxDefault

NewUniversalUDPMuxDefault creates an implementation of UniversalUDPMux embedding UDPMux

func (*UniversalUDPMuxDefault) GetConnForURL

func (m *UniversalUDPMuxDefault) GetConnForURL(ufrag string, url string, addr net.Addr) (net.PacketConn, error)

GetConnForURL add uniques to the muxed connection by concatenating ufrag and URL (e.g. STUN URL) to be able to support multiple STUN/TURN servers and return a unique connection per server.

func (*UniversalUDPMuxDefault) GetListenAddresses

func (m *UniversalUDPMuxDefault) GetListenAddresses() []net.Addr

GetListenAddresses returns the listen addr of this UDP

func (*UniversalUDPMuxDefault) GetRelayedAddr

func (m *UniversalUDPMuxDefault) GetRelayedAddr(turnAddr net.Addr, deadline time.Duration) (*net.Addr, error)

GetRelayedAddr creates relayed connection to the given TURN service and returns the relayed addr. Not implemented yet.

func (*UniversalUDPMuxDefault) GetSharedConn

func (m *UniversalUDPMuxDefault) GetSharedConn() net.PacketConn

GetSharedConn returns the shared udp conn

func (*UniversalUDPMuxDefault) GetXORMappedAddr

func (m *UniversalUDPMuxDefault) GetXORMappedAddr(serverAddr net.Addr, deadline time.Duration) (*stun.XORMappedAddress, error)

GetXORMappedAddr returns *stun.XORMappedAddress if already present for a given STUN server. Makes a STUN binding request to discover mapped address otherwise. Blocks until the stun.XORMappedAddress has been discovered or deadline. Method is safe for concurrent use.

func (*UniversalUDPMuxDefault) HandleSTUNMessage

func (m *UniversalUDPMuxDefault) HandleSTUNMessage(msg *stun.Message, addr net.Addr) error

HandleSTUNMessage discovers STUN packets that carry a XOR mapped address from a STUN server. All other STUN packets will be forwarded to the UDPMux

func (*UniversalUDPMuxDefault) ReadFromConn

func (m *UniversalUDPMuxDefault) ReadFromConn(ctx context.Context)

ReadFromConn reads from the m.params.UDPConn provided upon the creation. It expects STUN packets only, however, will just ignore other packets printing an warning message. It is a blocking method, consider running in a go routine.

type UniversalUDPMuxParams

type UniversalUDPMuxParams struct {
	Logger                logging.LeveledLogger
	UDPConn               net.PacketConn
	XORMappedAddrCacheTTL time.Duration
	Net                   transport.Net
	FilterFn              FilterFn
}

UniversalUDPMuxParams are parameters for UniversalUDPMux server reflexive.

Jump to

Keyboard shortcuts

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