Documentation
¶
Index ¶
- Constants
- Variables
- func Configure(opts Options) error
- func Dial(network, address string) (net.Conn, error)
- func DialContext(ctx context.Context, network, address string) (net.Conn, error)
- func DialTLS(network, address string, config *tls.Config) (*tls.Conn, error)
- func DialTimeout(network, address string, timeoutSec int) (net.Conn, error)
- func DialUDP(address string) (*net.UDPConn, error)
- func IsProxyConfigured() bool
- func ProxyURL() string
- type ContextDialer
- type Dialer
- type Options
Constants ¶
const DefaultTimeout = 30
DefaultTimeout is the default connect timeout in seconds.
Variables ¶
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 ¶
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 ¶
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 ¶
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 DialTimeout ¶
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 ¶
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.
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 ¶
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.
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.