Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the consumer client.
func (*Client) Run ¶
Run is the main reconnect loop.
Architecture:
- A single persistent SOCKS5 TCP listener is created once and kept alive for the entire lifetime of the process. This means the SOCKS5 port is always available to the browser, even during reconnects.
- pollmux.ReconnectLoop re-registers with the broker (/tunnel/connect) each time, giving a fresh session. Consumer is the stream-opening end, not the stream-accepting end, so AcceptLoop doesn't apply here — Serve is a hand-written four-way select, same shape as before migration.
type Config ¶
type Config struct {
BrokerURL string
Endpoint string
Socks5Listen string // e.g. ":1080"
PollInterval time.Duration
RetryBackoff time.Duration
InsecureSkipVerify bool // Skip TLS certificate verification
AuthToken string // Authentication token for broker
// CoalesceWindow is passed through to pollmux.Connector; <= 0 uses
// pollmux.DefaultCoalesceWindow.
CoalesceWindow time.Duration
// PollMode is "" or "stream" (default) to request stream mode, or
// "batch" to opt out and force the older discrete poll mode.
PollMode string
// PollGrace is passed through to pollmux.Connector; <= 0 uses
// pollmux.DefaultPollGrace. Raise it when the broker sits behind a
// reverse proxy/CDN whose own latency can push a stream-mode poll's
// response headers past the default 10s.
PollGrace time.Duration
// UploadStreamPreference is passed through to
// pollmux.Connector.UploadStreamPreference: "" (default) auto-detects,
// "stream" forces it, "batch" disables it. See that field's doc.
UploadStreamPreference string
// UploadProbeTimeout is passed through to
// pollmux.Connector.UploadProbeTimeout; <= 0 uses pollmux's default (15s).
UploadProbeTimeout time.Duration
// PreferWebSocket is passed through to pollmux.Connector.PreferWebSocket.
// Takes effect only if the broker also has EnableWebSocket on; otherwise
// negotiation falls back to PollMode as if this were false.
PreferWebSocket bool
// PreferResume is passed through to pollmux.Connector.PreferResume. When
// the broker also has EnableResume on and the negotiated transport
// supports it, the Conn returned by Connect resumes the same session
// across transport failures instead of surfacing them, so the yamux
// session built on it (and every stream inside) carries on and Serve
// keeps running. Otherwise it is silently ignored and a transport
// failure ends Serve exactly as it does today.
PreferResume bool
}
Config holds consumer configuration.
type NoopResolver ¶
type NoopResolver struct{}
NoopResolver implements go-socks5's NameResolver interface. It returns the hostname as-is without DNS lookup, ensuring domain names are passed through the tunnel to be resolved by the provider's DNS.
func (*NoopResolver) Resolve ¶
Resolve returns the hostname without resolving it. The go-socks5 library calls this when a CONNECT request uses a domain name. We return nil IP so that AddrSpec.String() falls back to the FQDN, ensuring the original domain name is passed through the tunnel to be resolved by the provider's DNS — not replaced with 0.0.0.0.
type TunnelDialer ¶
type TunnelDialer struct {
// contains filtered or unexported fields
}
TunnelDialer is a custom dialer for go-socks5. Each SOCKS5 CONNECT request opens a new yamux stream to the broker.
func NewTunnelDialer ¶
func NewTunnelDialer(sess *yamux.Session, logger *zap.Logger) *TunnelDialer
NewTunnelDialer creates a new TunnelDialer with the given yamux session and logger.
func (*TunnelDialer) Dial ¶
Dial opens a new yamux stream and writes the target address header. Called by go-socks5 for each CONNECT request. addr is "host:port" (may contain a domain name, not just IP).
Target address format (must match broker's relay.go and provider's handler.go):
- Byte 0: uint8 = length of host:port string
- Bytes 1..N: host:port string (e.g., "example.com:443")