udp

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: GPL-3.0 Imports: 18 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
	PortScanCount             int
	PortScanDuration          time.Duration
	ChallengesRetry           int
	ChallengesInitialInterval time.Duration
	ChallengesBackoffRate     float64
}

type PeerState

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

type PeerStore

type PeerStore interface {
	Peers() []PeerState
}

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(stunServers []string) (info disco.NATInfo)

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() (peers []PeerState)

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.PeerUDPAddr)

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) UDPAddrSends

func (c *UDPConn) UDPAddrSends() <-chan *disco.PeerUDPAddr

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