transport

package
v0.0.0-...-7d23d5e Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTimeout = 30

DefaultTimeout is the default connect timeout in seconds.

Variables

View Source
var ErrUDPUnderProxy = errors.New("UDP disabled under -proxy; the underlying feature cannot be tunneled")

ErrUDPUnderProxy is returned by DialUDP when a proxy is configured. SOCKS5 UDP ASSOCIATE is rarely supported by proxies and servers, and silently leaking UDP packets from the attacker host when a proxy is configured would reveal the operator's real source IP. Callers should arrange for direct operation, or skip the UDP-dependent feature under -proxy.

Functions

func Configure

func Configure(opts Options) error

Configure initializes the transport layer. Must be called exactly once, typically from flags.Parse at tool startup. Panics on subsequent calls so a misconfigured tool fails loudly rather than silently racing on package state.

func Dial

func Dial(network, address string) (net.Conn, error)

Dial opens a TCP connection. Routes through the configured proxy if one was set via Configure; otherwise uses the platform's direct dialer (libc connect() on Unix/cgo, net.Dialer elsewhere).

func DialContext

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

DialContext is a context-aware variant of Dial, suitable as an http.Transport.DialContext. Routes through the configured proxy if set. UDP under -proxy returns ErrUDPUnderProxy rather than letting a cryptic "network not implemented" bubble up from the SOCKS5 layer.

func DialTLS

func DialTLS(network, address string, config *tls.Config) (*tls.Conn, error)

DialTLS opens a TCP connection (via proxy if configured) and wraps it in TLS.

func DialTimeout

func DialTimeout(network, address string, timeoutSec int) (net.Conn, error)

DialTimeout is Dial with an explicit connect timeout in seconds. A non-positive timeoutSec is normalized to DefaultTimeout so the direct and proxy branches behave consistently.

func DialUDP

func DialUDP(address string) (*net.UDPConn, error)

DialUDP opens a connected UDP socket to address. Returns ErrUDPUnderProxy if a proxy is configured. SOCKS5 UDP ASSOCIATE is rarely supported and silently bypassing the proxy under -proxy would reveal the operator's real source IP.

func IsProxyConfigured

func IsProxyConfigured() bool

IsProxyConfigured reports whether a proxy is in effect. Callers that cannot meaningfully operate through a proxy (UDP probes, local-IP discovery) should consult this and short-circuit.

func ProxyURL

func ProxyURL() string

ProxyURL returns the configured proxy URL (redacted), or "" if none.

Types

type ContextDialer

type ContextDialer struct{}

ContextDialer is the value-typed counterpart of Dialer for APIs that expect a DialContext method (e.g. github.com/oiweiwei/go-msrpc/dcerpc.WithDialer, net/http.Transport.DialContext). Respects the configured proxy. The zero value works.

func (ContextDialer) DialContext

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

DialContext routes through the configured proxy if set, honoring ctx.

type Dialer

type Dialer struct {
	TimeoutSec int
}

Dialer is a value-typed dialer suitable for APIs that expect a struct with a Dial method (e.g. pkg/smb, pkg/ldap). Respects the configured proxy.

func (*Dialer) Dial

func (d *Dialer) Dial(network, address string) (net.Conn, error)

Dial establishes a TCP connection to address. Routes through the proxy if configured.

type Options

type Options struct {
	// Proxy, if non-empty, is a SOCKS5 URL that outbound TCP is routed through.
	// Accepted schemes: socks5, socks5h. When empty, the ALL_PROXY / all_proxy
	// environment variables are consulted.
	Proxy string
}

Options holds runtime configuration for the transport layer.

Jump to

Keyboard shortcuts

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