pool

package
v1.6.7 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPoolClosed    = errors.New("connection pool is closed")
	ErrNoConnections = errors.New("no available connections")
)

Functions

This section is empty.

Types

type Conn

type Conn struct {
	Host       string
	RemoteAddr net.Addr
	TLSConn    *utls.UConn
	HTTP2Conn  *http2.ClientConn
	CreatedAt  time.Time
	LastUsedAt time.Time
	UseCount   int64
	// contains filtered or unexported fields
}

Conn represents a persistent connection

func (*Conn) Age

func (c *Conn) Age() time.Duration

Age returns how long the connection has been open

func (*Conn) Close

func (c *Conn) Close() error

Close closes the connection

func (*Conn) IdleTime

func (c *Conn) IdleTime() time.Duration

IdleTime returns how long since the connection was last used

func (*Conn) IsHealthy

func (c *Conn) IsHealthy() bool

IsHealthy checks if the connection is still usable

func (*Conn) MarkUsed

func (c *Conn) MarkUsed()

MarkUsed updates the last used timestamp

type HostPool

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

HostPool manages connections to a single host

func NewHostPool

func NewHostPool(host, port string, preset *fingerprint.Preset, dnsCache *dns.Cache) *HostPool

NewHostPool creates a new pool for a specific host Note: This generates its own shuffled specs. For consistent session fingerprinting, use Manager.GetPool() instead which shares cached specs across all hosts.

func NewHostPoolWithConfig

func NewHostPoolWithConfig(host, sniHost, port string, preset *fingerprint.Preset, dnsCache *dns.Cache, insecureSkipVerify bool, proxyURL string, cachedSpec, cachedPSKSpec *utls.ClientHelloSpec, shuffleSeed int64, sessionCache utls.ClientSessionCache) *HostPool

NewHostPoolWithConfig creates a pool with TLS and proxy configuration host is the connection host (for DNS resolution, may be connectTo target) sniHost is the TLS ServerName host (original request host, used for SNI) If sniHost is empty, host is used for both DNS and SNI

func (*HostPool) Close

func (p *HostPool) Close()

Close closes all connections in the pool

func (*HostPool) CloseIdle

func (p *HostPool) CloseIdle()

CloseIdle closes connections that have been idle too long

func (*HostPool) GetConn

func (p *HostPool) GetConn(ctx context.Context) (*Conn, error)

GetConn returns an available connection or creates a new one

func (*HostPool) SetECHConfig added in v1.5.3

func (p *HostPool) SetECHConfig(echConfig []byte)

SetECHConfig sets a custom ECH configuration for this pool

func (*HostPool) SetECHConfigDomain added in v1.5.3

func (p *HostPool) SetECHConfigDomain(domain string)

SetECHConfigDomain sets a domain to fetch ECH config from

func (*HostPool) SetLocalAddr added in v1.6.0

func (p *HostPool) SetLocalAddr(addr string)

SetLocalAddr sets the local IP address for outgoing connections

func (*HostPool) SetMaxConns

func (p *HostPool) SetMaxConns(max int)

SetMaxConns sets the maximum connections for this pool (0 = unlimited)

func (*HostPool) Stats

func (p *HostPool) Stats() (total int, healthy int, totalRequests int64)

Stats returns pool statistics

type Manager

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

Manager manages connection pools for multiple hosts

func NewManager

func NewManager(preset *fingerprint.Preset) *Manager

NewManager creates a new connection pool manager

func NewManagerWithProxy

func NewManagerWithProxy(preset *fingerprint.Preset, proxyURL string, insecureSkipVerify bool) *Manager

NewManagerWithProxy creates a manager with proxy support

func NewManagerWithTLSConfig

func NewManagerWithTLSConfig(preset *fingerprint.Preset, insecureSkipVerify bool) *Manager

NewManagerWithTLSConfig creates a manager with TLS configuration

func (*Manager) Close

func (m *Manager) Close()

Close shuts down the manager and all pools

func (*Manager) CloseAllPools added in v1.5.8

func (m *Manager) CloseAllPools()

CloseAllPools closes all connection pools and clears session cache This is used when switching proxies - old connections are invalid for new proxy route

func (*Manager) GetConn

func (m *Manager) GetConn(ctx context.Context, host, port string) (*Conn, error)

GetConn gets a connection to the specified host

func (*Manager) GetDNSCache

func (m *Manager) GetDNSCache() *dns.Cache

GetDNSCache returns the DNS cache

func (*Manager) GetPool

func (m *Manager) GetPool(host, port string) (*HostPool, error)

GetPool returns a pool for the given host, creating one if needed

func (*Manager) GetProxy added in v1.5.8

func (m *Manager) GetProxy() string

GetProxy returns the current proxy URL

func (*Manager) GetSessionCache added in v1.5.10

func (m *Manager) GetSessionCache() utls.ClientSessionCache

GetSessionCache returns the shared TLS session cache

func (*Manager) SetConnectTo added in v1.5.2

func (m *Manager) SetConnectTo(requestHost, connectHost string)

SetConnectTo sets a host mapping for domain fronting

func (*Manager) SetECHConfig added in v1.5.2

func (m *Manager) SetECHConfig(echConfig []byte)

SetECHConfig sets a custom ECH configuration

func (*Manager) SetECHConfigDomain added in v1.5.2

func (m *Manager) SetECHConfigDomain(domain string)

SetECHConfigDomain sets a domain to fetch ECH config from

func (*Manager) SetMaxConnsPerHost

func (m *Manager) SetMaxConnsPerHost(max int)

SetMaxConnsPerHost sets the max connections per host for new pools (0 = unlimited)

func (*Manager) SetPreset

func (m *Manager) SetPreset(preset *fingerprint.Preset)

SetPreset changes the fingerprint preset for new connections

func (*Manager) SetProxy added in v1.5.8

func (m *Manager) SetProxy(proxyURL string)

SetProxy changes the proxy URL and closes all existing connections TLS sessions from old proxy route are invalid, so we clear everything

func (*Manager) SetSessionCache added in v1.5.10

func (m *Manager) SetSessionCache(cache utls.ClientSessionCache)

SetSessionCache sets the shared TLS session cache for all pools This allows session persistence to work across Save/Load

func (*Manager) Stats

func (m *Manager) Stats() map[string]struct {
	Total    int
	Healthy  int
	Requests int64
}

Stats returns overall manager statistics

type QUICConn

type QUICConn struct {
	Host       string
	RemoteAddr net.Addr
	QUICConn   *quic.Conn
	HTTP3RT    *http3.Transport
	CreatedAt  time.Time
	LastUsedAt time.Time
	UseCount   int64
	// contains filtered or unexported fields
}

QUICConn represents a persistent QUIC connection

func (*QUICConn) Age

func (c *QUICConn) Age() time.Duration

Age returns how long the connection has been open

func (*QUICConn) Close

func (c *QUICConn) Close() error

Close closes the QUIC connection

func (*QUICConn) IdleTime

func (c *QUICConn) IdleTime() time.Duration

IdleTime returns how long since the connection was last used

func (*QUICConn) IsHealthy

func (c *QUICConn) IsHealthy() bool

IsHealthy checks if the QUIC connection is still usable

func (*QUICConn) MarkUsed

func (c *QUICConn) MarkUsed()

MarkUsed updates the last used timestamp

type QUICHostPool

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

QUICHostPool manages QUIC connections to a single host

func NewQUICHostPool

func NewQUICHostPool(host, port string, preset *fingerprint.Preset, dnsCache *dns.Cache) *QUICHostPool

NewQUICHostPool creates a new QUIC pool for a specific host

func NewQUICHostPoolWithCachedSpec added in v1.1.4

func NewQUICHostPoolWithCachedSpec(host, sniHost, port string, preset *fingerprint.Preset, dnsCache *dns.Cache, cachedSpec *utls.ClientHelloSpec, cachedPSKSpec *utls.ClientHelloSpec, shuffleSeed int64) *QUICHostPool

NewQUICHostPoolWithCachedSpec creates a QUIC pool with a pre-cached ClientHelloSpec and shuffle seed This ensures consistent TLS extension order and transport parameter order across all hosts in a session cachedSpec is used for initial connections, cachedPSKSpec is used when resuming sessions host is the connection host (for DNS), sniHost is the TLS ServerName (original request host) If sniHost is empty, host is used for both

func (*QUICHostPool) Close

func (p *QUICHostPool) Close()

Close closes all connections in the pool

func (*QUICHostPool) CloseConnections added in v1.5.7

func (p *QUICHostPool) CloseConnections()

CloseConnections closes all connections but keeps the pool usable This allows testing session resumption by forcing new connections

func (*QUICHostPool) CloseIdle

func (p *QUICHostPool) CloseIdle()

CloseIdle closes connections that have been idle too long

func (*QUICHostPool) GetConn

func (p *QUICHostPool) GetConn(ctx context.Context) (*QUICConn, error)

GetConn returns an available QUIC connection or creates a new one

func (*QUICHostPool) SetLocalAddr added in v1.6.0

func (p *QUICHostPool) SetLocalAddr(addr string)

SetLocalAddr sets the local IP address for outgoing connections

func (*QUICHostPool) SetMaxConns

func (p *QUICHostPool) SetMaxConns(max int)

SetMaxConns sets the maximum connections for this pool (0 = unlimited)

func (*QUICHostPool) Stats

func (p *QUICHostPool) Stats() (total int, healthy int, totalRequests int64)

Stats returns pool statistics

type QUICManager

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

QUICManager manages QUIC connection pools for multiple hosts

func NewQUICManager

func NewQUICManager(preset *fingerprint.Preset, dnsCache *dns.Cache) *QUICManager

NewQUICManager creates a new QUIC connection pool manager

func (*QUICManager) Close

func (m *QUICManager) Close()

Close shuts down the manager and all pools

func (*QUICManager) CloseAllConnections added in v1.5.7

func (m *QUICManager) CloseAllConnections()

CloseAllConnections closes all QUIC connections across all pools but keeps the pools usable with their session caches intact This is useful for testing session resumption

func (*QUICManager) CloseAllPools added in v1.5.8

func (m *QUICManager) CloseAllPools()

CloseAllPools closes all pools and removes them entirely This is used when switching proxies - old connections/sessions are invalid for new proxy route

func (*QUICManager) GetConn

func (m *QUICManager) GetConn(ctx context.Context, host, port string) (*QUICConn, error)

GetConn gets a QUIC connection to the specified host

func (*QUICManager) GetPool

func (m *QUICManager) GetPool(host, port string) (*QUICHostPool, error)

GetPool returns a pool for the given host, creating one if needed

func (*QUICManager) SetConnectTo added in v1.5.2

func (m *QUICManager) SetConnectTo(requestHost, connectHost string)

SetConnectTo sets a host mapping for domain fronting

func (*QUICManager) SetDisableECH added in v1.5.8

func (m *QUICManager) SetDisableECH(disable bool)

SetDisableECH disables automatic ECH fetching Chrome doesn't always use ECH even when available from DNS

func (*QUICManager) SetECHConfig added in v1.5.2

func (m *QUICManager) SetECHConfig(echConfig []byte)

SetECHConfig sets a custom ECH configuration

func (*QUICManager) SetECHConfigDomain added in v1.5.2

func (m *QUICManager) SetECHConfigDomain(domain string)

SetECHConfigDomain sets a domain to fetch ECH config from

func (*QUICManager) SetInsecureSkipVerify added in v1.5.8

func (m *QUICManager) SetInsecureSkipVerify(skip bool)

SetInsecureSkipVerify sets whether to skip TLS certificate verification

func (*QUICManager) SetLocalAddr added in v1.6.0

func (m *QUICManager) SetLocalAddr(addr string)

SetLocalAddr sets the local IP address for outgoing connections

func (*QUICManager) SetMaxConnsPerHost

func (m *QUICManager) SetMaxConnsPerHost(max int)

SetMaxConnsPerHost sets the max connections per host for new pools (0 = unlimited)

func (*QUICManager) Stats

func (m *QUICManager) Stats() map[string]struct {
	Total    int
	Healthy  int
	Requests int64
}

Stats returns overall manager statistics

Jump to

Keyboard shortcuts

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