udp

package
v2.0.0-...-8205865 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package udp implements DTLS specific UDP networking primitives. NOTE: this package is an adaption of pion/transport/udp that allows for routing datagrams based on identifiers other than the remote address. The primary use case for this functionality is routing based on DTLS connection IDs. In order to allow for consumers of this package to treat connections as generic net.PackageConn, routing and identitier establishment is based on custom introspecion of datagrams, rather than direct intervention by consumers. If possible, the updates made in this repository will be reflected back upstream. If not, it is likely that this will be moved to a public package in this repository.

This package was migrated from pion/transport/udp at https://github.com/pion/transport/commit/6890c795c807a617c054149eee40a69d7fdfbfdb

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClosedListener      = errors.New("udp: listener closed")
	ErrListenQueueExceeded = errors.New("udp: listen queue exceeded")
)

Typed errors

Functions

func Listen

func Listen(network string, laddr *net.UDPAddr) (dtlsnet.PacketListener, error)

Listen creates a new listener using default ListenConfig.

Types

type ListenConfig

type ListenConfig struct {
	// Backlog defines the maximum length of the queue of pending
	// connections. It is equivalent of the backlog argument of
	// POSIX listen function.
	// If a connection request arrives when the queue is full,
	// the request will be silently discarded, unlike TCP.
	// Set zero to use default value 128 which is same as Linux default.
	Backlog int

	// AcceptFilter determines whether the new conn should be made for
	// the incoming packet. If not set, any packet creates new conn.
	AcceptFilter func([]byte) bool

	// DatagramRouter routes an incoming datagram to a connection by extracting
	// an identifier from the its paylod
	DatagramRouter func([]byte) (string, bool)

	// ConnectionIdentifier extracts an identifier from an outgoing packet. If
	// the identifier is not already associated with the connection, it will be
	// added.
	ConnectionIdentifier func([]byte) (string, bool)
}

ListenConfig stores options for listening to an address.

func (*ListenConfig) Listen

func (lc *ListenConfig) Listen(network string, laddr *net.UDPAddr) (dtlsnet.PacketListener, error)

Listen creates a new listener based on the ListenConfig.

type PacketConn

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

PacketConn is a net.PacketConn implementation that is able to dictate its routing ID via an alternate identifier from its remote address. Internal buffering is performed for reads, and writes are passed through to the underlying net.PacketConn.

func (*PacketConn) Close

func (c *PacketConn) Close() error

Close closes the conn and releases any Read calls

func (*PacketConn) LocalAddr

func (c *PacketConn) LocalAddr() net.Addr

LocalAddr implements net.PacketConn.LocalAddr.

func (*PacketConn) ReadFrom

func (c *PacketConn) ReadFrom(p []byte) (int, net.Addr, error)

ReadFrom reads a single packet payload and its associated remote address from the underlying buffer.

func (*PacketConn) SetDeadline

func (c *PacketConn) SetDeadline(t time.Time) error

SetDeadline implements net.PacketConn.SetDeadline.

func (*PacketConn) SetReadDeadline

func (c *PacketConn) SetReadDeadline(t time.Time) error

SetReadDeadline implements net.PacketConn.SetReadDeadline.

func (*PacketConn) SetWriteDeadline

func (c *PacketConn) SetWriteDeadline(t time.Time) error

SetWriteDeadline implements net.PacketConn.SetWriteDeadline.

func (*PacketConn) WriteTo

func (c *PacketConn) WriteTo(p []byte, addr net.Addr) (n int, err error)

WriteTo writes len(p) bytes from p to the specified address.

Jump to

Keyboard shortcuts

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