tunnel

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package tunnel provides outbound SOCKS5 connection pooling for agbero backends.

A Pool wraps one or more SOCKS5 proxy servers and selects among them using either round-robin (default) or random strategy. It exposes a DialContext function compatible with http.Transport and net.Dialer, making it trivial to inject into any outbound connection path.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Name is optional — used in error messages for named tunnel blocks.
	Name string

	// Servers is a list of host:port SOCKS5 proxy addresses.
	Servers []string

	// Username and Password are optional SOCKS5 credentials.
	// When empty, the proxy is used without authentication.
	Username string
	Password string

	// Strategy controls server selection: "round_robin" (default) or "random".
	Strategy string
}

Config holds the parameters required to construct a Pool.

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Pool is a thread-safe SOCKS5 proxy pool. All methods are safe for concurrent use by multiple goroutines.

func New

func New(cfg Config) (*Pool, error)

New constructs a Pool from the given config. Returns an error if any server address is invalid or if the SOCKS5 dialer cannot be initialised.

func NewFromURL

func NewFromURL(rawURL string) (*Pool, error)

NewFromURL builds a single-server Pool from a socks5://[user:pass@]host:port URI. Used for the inline `tunnel = "socks5://..."` backend shorthand.

func (*Pool) Addrs

func (p *Pool) Addrs() []string

Addrs returns the sanitised (credential-free) server addresses for logging.

func (*Pool) DialContext

func (p *Pool) DialContext(ctx context.Context, network, addr string) (net.Conn, error)

DialContext implements the DialContext signature expected by http.Transport. It picks a server per the configured strategy and dials through it.

func (*Pool) Len

func (p *Pool) Len() int

Len returns the number of proxy servers in this pool.

func (*Pool) Name

func (p *Pool) Name() string

Name returns the pool's name (empty for inline/anonymous pools).

func (*Pool) WrapTransport

func (p *Pool) WrapTransport(t *http.Transport) *http.Transport

WrapTransport clones t and returns a new *http.Transport whose DialContext routes every outbound TCP connection through this pool.

The cloned transport has Proxy set to nil — SOCKS5 is the proxy. All other transport settings (TLS config, timeouts, connection pooling) are preserved from the original.

Jump to

Keyboard shortcuts

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