dialer

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const SocketBufferSize = 7 << 20

UDP socket read/write buffer size (7MB). The value of 7MB is chosen as it is the max supported by a default configuration of macOS. Some platforms will silently clamp the value to other maximums, such as linux clamping to net.core.{r,w}mem_max (see _linux.go for additional implementation that works around this limitation)

Variables

View Source
var (
	DefaultInterfaceName  = ""
	DefaultInterfaceIndex = 0
	DefaultRoutingMark    = 0 // maybe need root permission
	DefaultMarkSymbol     func(socket int32) bool
)

Functions

func DialContext

func DialContext(ctx context.Context, network, address string) (net.Conn, error)

func DialContextWithOptions

func DialContextWithOptions(ctx context.Context, network, address string, opts *Options) (net.Conn, error)

func DialHappyEyeballs added in v0.3.5

func DialHappyEyeballs(ctx context.Context, ips []*net.TCPAddr) (net.Conn, error)

DialHappyEyeballs is a function that implements Happy Eyeballs algorithm for IPv4 and IPv6 addresses. It divides given TCP addresses into primaries and fallbacks and then calls DialParallel function.

It takes a context and a slice of TCP addresses as input and returns a net.Conn and an error.

https://www.rfc-editor.org/rfc/rfc8305

func DialParallel added in v0.3.5

func DialParallel(ctx context.Context, primaries []*net.TCPAddr, fallbacks []*net.TCPAddr) (net.Conn, error)

https://github.com/golang/go/blob/315b6ae682a2a4e7718924a45b8b311a0fe10043/src/net/dial.go#L534

dialParallel races two copies of dialSerial, giving the first a head start. It returns the first established connection and closes the others. Otherwise it returns an error from the first primary address.

func DialSerial added in v0.3.5

func DialSerial(ctx context.Context, ras []*net.TCPAddr) (net.Conn, error)

DialSerial connects to a list of addresses in sequence, returning either the first successful connection, or the first error.

func LinuxMarkSymbol

func LinuxMarkSymbol(fd int32, mark int) error

func ListenContext

func ListenContext(ctx context.Context, network string, address string) (net.Listener, error)

func ListenContextWithOptions

func ListenContextWithOptions(ctx context.Context, network string, address string, opts *Options) (net.Listener, error)

func ListenPacket

func ListenPacket(network, address string) (net.PacketConn, error)

func ListenPacketWithOptions

func ListenPacketWithOptions(network, address string, opts *Options) (net.PacketConn, error)

func PartialDeadline added in v0.3.5

func PartialDeadline(now, deadline time.Time, addrsRemaining int) (time.Time, error)

PartialDeadline returns the deadline to use for a single address, when multiple addresses are pending.

func PartialDeadlineCtx added in v0.3.5

func PartialDeadlineCtx(ctx context.Context, addrsRemaining int) (context.Context, context.CancelFunc, error)

Types

type Options

type Options struct {
	// InterfaceName is the name of interface/device to bind.
	// If a socket is bound to an interface, only packets received
	// from that particular interface are processed by the socket.
	InterfaceName string

	// InterfaceIndex is the index of interface/device to bind.
	// It is almost the same as InterfaceName except it uses the
	// index of the interface instead of the name.
	InterfaceIndex int

	// RoutingMark is the mark for each packet sent through this
	// socket. Changing the mark can be used for mark-based routing
	// without netfilter or for packet filtering.
	MarkSymbol func(socket int32) bool
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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