network

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Network contains a default implementation of the network.

Please see mtglib.Network interface to get some basic idea behind this abstraction.

This implementation is more simple that v1 because life shows that all this complexity, especially around circuit breakers and DoH is not really required. There is no chance that if DNS address is spoofed, that real IP would work as expected.

Index

Constants

View Source
const (
	// DefaultTimeout is a default timeout for establishing TCP connection.
	DefaultTimeout = 10 * time.Second

	// DefaultHTTPTimeout defines a default timeout for making HTTP request.
	DefaultHTTPTimeout = 10 * time.Second

	// DefaultIdleTimeout defines a timeout for idle HTTP connections
	DefaultIdleTimeout = time.Minute

	// DefaultTCPKeepAlivePeriod defines a time period between 2 consecuitive
	// probes.
	//
	// Deprecated: use DefaultKeepAliveConfig
	DefaultTCPKeepAlivePeriod = 10 * time.Second

	// DefaultKeepAliveIdle is the time a connection must be idle before
	// the first keepalive probe is sent.
	//
	// Deprecated: use DefaultKeepAliveConfig
	DefaultKeepAliveIdle = 30 * time.Second

	// DefaultKeepAliveInterval is the time between consecutive keepalive
	// probes.
	//
	// Deprecated: use DefaultKeepAliveConfig
	DefaultKeepAliveInterval = 10 * time.Second

	// DefaultKeepAliveCount is the number of unacknowledged probes before
	// the connection is considered dead.
	//
	// Deprecated: use DefaultKeepAliveConfig
	DefaultKeepAliveCount = 3

	// User Agent to use in HTTP client.
	UserAgent = "curl/8.5.0"
)
View Source
const DefaultTCPNotSentLowat = 128 * 1024

DefaultTCPNotSentLowat is the default value applied to TCP_NOTSENT_LOWAT on outbound sockets. It limits the amount of unsent data queued in the kernel write buffer per socket. When the unsent data drops below this threshold, the socket becomes writable again. This reduces per-connection memory usage and bufferbloat by applying back-pressure to the relay loop instead of piling up data in kernel buffers.

The default is conservative and biased towards interactive latency. On high-BDP links (fast pipe × high RTT) it can cap single-flow upload throughput at roughly DefaultTCPNotSentLowat / RTT. Raise it via the [network.tcp-not-sent-lowat] config option if uploads feel slow.

Variables

View Source
var (
	ErrCannotDial = errors.New("cannot dial to any address")

	// DefaultKeepAliveConfig defines a default configuration for
	// keep alive settings. As per official documentation, if keep alive
	// is enabled, then:
	//
	//  Idle = 15 * time.Second
	//  Interval = 15 * time.Second
	//  Count = 9
	DefaultKeepAliveConfig = net.KeepAliveConfig{
		Enable: true,
	}
)

Functions

func GetDNS

func GetDNS(u *url.URL) (*net.Resolver, error)

func Join

func Join(networks ...mtglib.Network) (mtglib.Network, error)

func New

func New(
	dnsResolver *net.Resolver,
	userAgent string,
	tcpTimeout,
	httpTimeout,
	idleTimeout time.Duration,
	keepAliveConfig net.KeepAliveConfig,
	tcpNotSentLowat int,
) mtglib.Network

func NewProxyNetwork

func NewProxyNetwork(base mtglib.Network, proxyURL *url.URL) (*proxyNetwork, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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