Documentation
¶
Index ¶
- func ApplyKeepalive(conn net.Conn, cfg net.KeepAliveConfig)
- func ApplyNoDelay(conn net.Conn)
- func CopyBuffer(dst io.Writer, src io.Reader, bufSize int) error
- func IsIPv4(address string) bool
- func NewReadWriteConn(r io.Reader, w io.Writer, c net.Conn) net.Conn
- func ParseInterfaceAddr(ifceName, network string) (ifce string, addr []net.Addr, isIP bool, err error)
- func Pipe(ctx context.Context, rw1, rw2 io.ReadWriteCloser, opts ...PipeOption) error
- func Resolve(ctx context.Context, network, addr string, r resolver.Resolver, ...) (string, error)
- func ResolveAll(ctx context.Context, network, addr string, r resolver.Resolver, ...) ([]string, error)
- func Transport(rw1, rw2 io.ReadWriter) error
- func WrapKeepaliveListener(ln net.Listener, cfg net.KeepAliveConfig) net.Listener
- func WrapNoDelayListener(ln net.Listener) net.Listener
- type AddrPortRange
- type IPRange
- type ListenConfig
- type PipeOption
- type PortRange
- type RemoteAddr
- type SetBuffer
- type SetDSCP
- type SyscallConn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyKeepalive ¶ added in v0.28.1
func ApplyKeepalive(conn net.Conn, cfg net.KeepAliveConfig)
ApplyKeepalive applies cfg to conn if it is a *net.TCPConn.
func ApplyNoDelay ¶ added in v0.28.1
ApplyNoDelay disables Nagle's algorithm on conn if it is a *net.TCPConn.
tnet tunnels carry small, latency-sensitive datagrams (e.g. WireGuard UDP over relay+ws/wss). Without this, Nagle coalesces each frame until a peer ACK returns, adding up to one RTT per datagram — the root cause of the latency regression reported in dolfly/tnet#858. Match wstunnel, which sets TCP_NODELAY on its tunnel socket by default.
func CopyBuffer ¶
CopyBuffer copies from src to dst using a buffer of bufSize obtained from the buffer pool, reducing allocation overhead for repeated copies.
func IsIPv4 ¶
IsIPv4 reports whether address is an IPv4 address by checking whether it starts with ':' or '[' (IPv6) vs a digit (IPv4).
func NewReadWriteConn ¶ added in v0.0.3
NewReadWriteConn returns a net.Conn that reads from r and writes to w, delegating all other operations to c. If c supports CloseRead or CloseWrite, those are forwarded; otherwise they return ErrUnsupported.
func ParseInterfaceAddr ¶ added in v0.0.3
func ParseInterfaceAddr(ifceName, network string) (ifce string, addr []net.Addr, isIP bool, err error)
ParseInterfaceAddr resolves ifceName to a network interface name and its addresses. If ifceName is an IP address, it finds the corresponding interface and returns a single address with port 0. If ifceName is an interface name, it returns all addresses assigned to that interface. The network parameter determines the address type (TCPAddr for "tcp"/"tcp4"/"tcp6", UDPAddr for "udp"/"udp4"/"udp6", IPAddr otherwise).
isIP reports whether ifceName was parsed as an IP address (true) rather than an interface name (false). When isIP is true, callers should skip SO_BINDTODEVICE — the user's intent is source IP binding for policy routing, not device binding.
func Pipe ¶ added in v0.0.3
func Pipe(ctx context.Context, rw1, rw2 io.ReadWriteCloser, opts ...PipeOption) error
Pipe establishes a bidirectional data channel between two connections. Data read from rw1 is written to rw2, and data read from rw2 is written to rw1. Each direction runs in its own goroutine. Pipe returns the first non-EOF error encountered, or nil if both directions complete cleanly. When ctx is cancelled, both connections are forcefully closed.
func Resolve ¶ added in v0.0.3
func Resolve(ctx context.Context, network, addr string, r resolver.Resolver, hosts hosts.HostMapper, log logger.Logger) (string, error)
Resolve resolves addr to a single concrete IP address. It is a thin wrapper around ResolveAll that keeps the first candidate, see ResolveAll for the lookup order.
func ResolveAll ¶ added in v0.28.1
func ResolveAll(ctx context.Context, network, addr string, r resolver.Resolver, hosts hosts.HostMapper, log logger.Logger) ([]string, error)
ResolveAll resolves addr to all candidate IP:port addresses, preserving the order returned by the hosts mapper and the resolver. If hosts is non-nil, it is consulted first. If r is non-nil and no host mapping matched, the resolver is used. If neither is available, the address is returned unchanged so that the original hostname is preserved for downstream connectors (e.g., SOCKS5 ATYP=domain). DNS resolution is deferred to the final TCP dialer, which uses a pure-Go resolver to avoid cgo thread exhaustion.
func Transport ¶
func Transport(rw1, rw2 io.ReadWriter) error
Transport copies data bidirectionally between rw1 and rw2 using two goroutines. It waits for both directions to finish and returns the first non-EOF error encountered.
It must not return as soon as the first direction is done: the direction that finishes first is often the one without an error, and returning early would swallow the error of the other direction.
func WrapKeepaliveListener ¶ added in v0.28.1
WrapKeepaliveListener wraps ln so that TCP keepalive config is applied to every accepted *net.TCPConn before it enters the middleware wrapper chain.
Types ¶
type AddrPortRange ¶
type AddrPortRange string
AddrPortRange is the network address with port range supported. e.g. 192.168.1.1:0-65535
func (AddrPortRange) Addrs ¶
func (p AddrPortRange) Addrs() (addrs []string)
Addrs expands the port range into individual "host:port" strings.
type IPRange ¶ added in v0.0.3
IPRange represents a range of IP addresses.
type ListenConfig ¶ added in v0.0.3
type ListenConfig struct {
Netns string
net.ListenConfig
}
ListenConfig extends net.ListenConfig with network namespace support.
func (*ListenConfig) Listen ¶ added in v0.0.3
Listen announces on the local network address, switching into the configured network namespace first if one is set.
func (*ListenConfig) ListenPacket ¶ added in v0.0.3
func (lc *ListenConfig) ListenPacket(ctx context.Context, network, address string) (net.PacketConn, error)
ListenPacket announces on the local network address for packet connections, switching into the configured network namespace first if one is set.
type PipeOption ¶ added in v0.28.1
type PipeOption func(*pipeOptions)
PipeOption configures the behaviour of Pipe.
func WithReadTimeout ¶ added in v0.28.1
func WithReadTimeout(d time.Duration) PipeOption
WithReadTimeout sets an idle read timeout on each pipe half. When a read blocks for longer than d the connection is closed. A value of 0 disables the timeout entirely, relying on TCP keepalives or context cancellation to detect dead connections.
type PortRange ¶
Port range is a range of port list.
type RemoteAddr ¶
RemoteAddr is a connection that exposes its remote address.
type SyscallConn ¶
SyscallConn is a connection that exposes its raw system file descriptor.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package httptunnel provides the pieces shared by the HTTP tunnel dialers and connectors: a replayable tunnel body and the redirect policy a tunnel client must use.
|
Package httptunnel provides the pieces shared by the HTTP tunnel dialers and connectors: a replayable tunnel body and the redirect policy a tunnel client must use. |