udp

package
v0.11.3 Latest Latest
Warning

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

Go to latest
Published: May 31, 2025 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MAGIC_TO_RELAY   = []byte{'_', 'p', 'g', 1}
	MAGIC_FROM_RELAY = []byte{'_', 'p', 'g', 3}
)
View Source
var (
	ErrUDPConnNotReady = errors.New("udpConn not ready yet")
	ErrUDPConnInactive = errors.New("udpConn inactive")
)

Functions

func SetModifyDiscoConfig

func SetModifyDiscoConfig(modify func(cfg *DiscoConfig))

Types

type DiscoConfig

type DiscoConfig struct {
	PortScanOffset            int           `yaml:"port_scan_offset"`
	PortScanCount             int           `yaml:"port_scan_count"`
	PortScanDuration          time.Duration `yaml:"port_scan_duration"`
	ChallengesRetry           int           `yaml:"challenges_retry"`
	ChallengesInitialInterval time.Duration `yaml:"challenges_initial_interval"`
	ChallengesBackoffRate     float64       `yaml:"challenges_backoff_rate"`
	IgnoredInterfaces         []string      `yaml:"ignored_interfaces"`
}

type PeerState

type PeerState struct {
	PeerID         disco.PeerID
	Addr           *net.UDPAddr
	LastActiveTime time.Time
}

type PeerStore

type PeerStore interface {
	// Peers load all peers (peers order is stable)
	Peers() []PeerState
}

type RelayToPeerError added in v0.11.3

type RelayToPeerError struct {
	PeerID disco.PeerID
	// contains filtered or unexported fields
}

func (RelayToPeerError) Error added in v0.11.3

func (e RelayToPeerError) Error() string

func (RelayToPeerError) Unwrap added in v0.11.3

func (e RelayToPeerError) Unwrap() error

type UDPConfig

type UDPConfig struct {
	Port                  int
	DisableIPv4           bool
	DisableIPv6           bool
	ID                    disco.PeerID
	PeerKeepaliveInterval time.Duration
	DiscoMagic            func() []byte
}

type UDPConn

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

func ListenUDP

func ListenUDP(cfg UDPConfig) (*UDPConn, error)

func (*UDPConn) Close

func (c *UDPConn) Close() error

func (*UDPConn) Datagrams

func (c *UDPConn) Datagrams() <-chan *disco.Datagram

func (*UDPConn) DetectNAT

func (c *UDPConn) DetectNAT(ctx context.Context, stunServers []string) (info disco.NATInfo)

func (*UDPConn) Endpoints added in v0.11.3

func (c *UDPConn) Endpoints() <-chan *disco.Endpoint

func (*UDPConn) Errors added in v0.11.3

func (c *UDPConn) Errors() <-chan error

func (*UDPConn) GenerateLocalAddrsSends

func (c *UDPConn) GenerateLocalAddrsSends(peerID disco.PeerID, stunServers []string)

func (*UDPConn) NATEvents

func (c *UDPConn) NATEvents() <-chan *disco.NATInfo

func (*UDPConn) Peers

func (c *UDPConn) Peers() []PeerState

Peers load all peers (peers order is stable)

func (*UDPConn) RelayTo

func (c *UDPConn) RelayTo(relay disco.PeerID, p []byte, peerID disco.PeerID) (int, error)

func (*UDPConn) RestartListener

func (c *UDPConn) RestartListener() error

func (*UDPConn) RunDiscoMessageSendLoop

func (c *UDPConn) RunDiscoMessageSendLoop(udpAddr disco.Endpoint)

func (*UDPConn) SetReadBuffer

func (c *UDPConn) SetReadBuffer(bytes int) error

SetReadBuffer sets the size of the operating system's receive buffer associated with the connection.

func (*UDPConn) SetWriteBuffer

func (c *UDPConn) SetWriteBuffer(bytes int) error

SetWriteBuffer sets the size of the operating system's transmit buffer associated with the connection.

func (*UDPConn) WriteTo

func (c *UDPConn) WriteTo(p []byte, peerID disco.PeerID) (int, error)

Jump to

Keyboard shortcuts

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