proxyroute

package
v1.3.112 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package proxyroute pkg/proxyroute/proxyroute.go c2-app-proxy

Per-domain upstream selection for the resolving proxies. A resolver forwards every host it does not resolve itself to one upstream SOCKS5 proxy (normally skysocks-client). Rules pick a different upstream for chosen domains, so one browser proxy entry can send example.com out through one exit, a second skysocks-client instance for another domain, and leave a third domain direct.

Index

Constants

View Source
const Direct = "direct"

Direct is the upstream value that dials the destination from this host instead of through a SOCKS5 proxy.

View Source
const None = "none"

None is the upstream value that refuses the destination, for a resolver that should reach only its own mesh names and never the clearnet.

Variables

View Source
var ErrRefused = errors.New("refused: the upstream for this host is none")

ErrRefused is the error a dial to a host routed to None returns.

Functions

func Pick

func Pick(rules []Rule, def, host string) string

Pick returns the upstream for host: the longest matching rule, else def. host may carry a port. An empty result means dial directly.

Types

type Forwarder

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

Forwarder dials a destination through the upstream its rules pick. It caches one SOCKS5 dialer per upstream (proxy.SOCKS5 returns a dialer that is safe to share), and after a failed dial fast-fails that upstream for upstreamCooldown rather than blocking or queueing requests. There is no clean "skysocks-client connected" signal to wait on, so the cached dialer plus cooldown stands in for one.

func NewForwarder

func NewForwarder(def string, rules []Rule) *Forwarder

NewForwarder builds a Forwarder. def is the upstream for hosts no rule matches; empty or Direct dials directly and None refuses. rules must already be Normalized.

func (*Forwarder) Active

func (f *Forwarder) Active() bool

Active reports whether the forwarder sends anything anywhere but direct.

func (*Forwarder) Dial

func (f *Forwarder) Dial(network, addr string) (net.Conn, error)

Dial connects to addr (host:port) through the upstream its host picks.

func (*Forwarder) Upstream

func (f *Forwarder) Upstream(host string) string

Upstream returns the upstream Dial would use for host, empty for direct.

type Rule

type Rule struct {
	// Suffix is a domain: "example.com" matches example.com and every
	// subdomain of it. A leading dot is ignored.
	Suffix string `json:"suffix"`
	// Upstream is a SOCKS5 host:port, "direct" or "none".
	Upstream string `json:"upstream"`
}

Rule sends hosts matching Suffix to Upstream.

func Normalize

func Normalize(rules []Rule) ([]Rule, error)

Normalize validates rules and orders them most specific first, so the first match is the longest suffix. A later rule for the same suffix replaces an earlier one.

func ParseRule

func ParseRule(s string) (Rule, error)

ParseRule reads "suffix=upstream".

func (Rule) String

func (r Rule) String() string

String renders the rule the way ParseRule reads it.

Jump to

Keyboard shortcuts

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