Documentation
¶
Index ¶
- Variables
- type Command
- type CommandExecutor
- type Flow
- type FlowStore
- type Infra
- type MitmCommand
- type ProxyHub
- func (h *ProxyHub) CAPath() string
- func (h *ProxyHub) Capturing() bool
- func (h *ProxyHub) ProxyURL() string
- func (h *ProxyHub) SetCapture(record, decryptHTTPS bool)
- func (h *ProxyHub) Shutdown(ctx context.Context)
- func (h *ProxyHub) Start(caRootPath string) error
- func (h *ProxyHub) Store() *FlowStore
- func (h *ProxyHub) Subscribe(buffer int) (<-chan *traffic.Flow, func())
- type QueryOpts
- type State
- func (s *State) ActiveNodeName() string
- func (s *State) ActiveProxy() string
- func (s *State) Clear()
- func (s *State) CurrentDial() proxyclient.Dial
- func (s *State) IsAutoMode() bool
- func (s *State) LoadSubscription(sub *clash.Subscription, subscribeURL string)
- func (s *State) Nodes() []clash.ProxyNode
- func (s *State) OriginalProxy() string
- func (s *State) SetAutoDial(clashURL string, dial proxyclient.Dial)
- func (s *State) SetProxyURL(rawURL string) error
- func (s *State) Switch(nameOrIndex string) error
- func (s *State) TestNode(ctx context.Context, node *clash.ProxyNode) (time.Duration, error)
- func (s *State) WithOverrideDial(proxyURL string) (func(), error)
- type TrafficHandler
Constants ¶
This section is empty.
Variables ¶
var InfraKey = deps.NewKey[*Infra]("proxy.infra")
InfraKey carries the long-lived proxy infrastructure from the assembly layer into the proxy command factory through the Deps bag.
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
func (*Command) SetCommandExecutor ¶
func (c *Command) SetCommandExecutor(fn CommandExecutor)
type CommandExecutor ¶
type FlowStore ¶
type FlowStore struct {
// contains filtered or unexported fields
}
func NewFlowStore ¶
type Infra ¶
Infra bundles the runner-level proxy infrastructure that must exist BEFORE tool factories run: the egress State (source of truth), the shared capture FlowStore, and the long-lived MITM ProxyHub. Creating it up front lets the assembly set Deps.ScannerProxy to the stable hub address, so bash and every scanner engine route through the hub uniformly with no factory-order coupling.
func InstallInfra ¶
InstallInfra creates and starts the proxy infrastructure, points Deps at the hub (ScannerProxy + ScannerProxyCA), and stores the Infra in the bag for the proxy factory. The originating Deps.ScannerProxy becomes the hub's default upstream, so tool → hub → configured-proxy holds. On hub start failure it leaves Deps unchanged (tools fall back to the original proxy / direct) and still returns the Infra so the factory can register verbs against the State.
capture selects the hub mode (see NewProxyHub): true records traffic (mitm on), false is a pure routing relay (mitm off). Routing works in both, so `proxy` keeps managing egress either way; only capture is gated.
type MitmCommand ¶
type MitmCommand struct {
// contains filtered or unexported fields
}
func NewMitmCommand ¶
func NewMitmCommand(reg *commands.CommandRegistry, store *FlowStore, hub *ProxyHub) *MitmCommand
NewMitmCommand wires the mitm verbs to the long-lived hub's shared FlowStore so `mitm flows/analyze/flow` query traffic captured from every tool, not just a per-invocation proxy.
func (*MitmCommand) Name ¶
func (c *MitmCommand) Name() string
func (*MitmCommand) SetCommandExecutor ¶
func (c *MitmCommand) SetCommandExecutor(fn CommandExecutor)
func (*MitmCommand) Usage ¶
func (c *MitmCommand) Usage() string
type ProxyHub ¶
type ProxyHub struct {
// contains filtered or unexported fields
}
ProxyHub is the runner-level, long-lived MITM proxy that every tool routes through. It is the STABLE front hop: its local address is injected once into child process env and in-process HTTP clients and never changes. The DYNAMIC back hop — the actual egress proxy chain — lives in State and is swapped live via State.CurrentDial(), which hub.dial reads on every connection. Switching proxy nodes therefore takes effect immediately without re-injecting anything into already-running children.
hub.dial is installed as mitmproxy Options.Dialer so it covers plain HTTP as well as HTTPS/CONNECT (see the local mitmproxy fork patch adding that field).
func NewProxyHub ¶
NewProxyHub builds the hub around an existing State (egress source of truth) and FlowStore (capture sink). Both are owned by the caller so the mitm query verbs and the hub share one store.
capture selects the mode. The hub is ALWAYS the routing substrate — tools route through it and `proxy switch` swaps its upstream live in either mode.
- capture=true (mitm on): intercept + record HTTPS (MITM) and HTTP flows.
- capture=false (mitm off): pure relay — no interception, no recording, no CA needed. Routing still works; nothing is decrypted or stored.
Start must be called before use.
func (*ProxyHub) CAPath ¶
CAPath is the exported CA PEM path to advertise to children, or "" when the hub is not currently MITM-decrypting HTTPS. It returns a path only while capture and decrypt are both on: a child must trust the hub's CA exactly when the hub forges certificates for it, and must not when HTTPS is tunneled (a CA-only bundle would then fail to validate the real server certificate).
func (*ProxyHub) Capturing ¶
Capturing reports whether the hub currently records traffic (mitm on) or only relays.
func (*ProxyHub) ProxyURL ¶
ProxyURL is the stable http:// address injected into children and in-process clients. Empty until Start succeeds.
func (*ProxyHub) SetCapture ¶
SetCapture toggles capture at runtime without restarting the listener. record gates storing/streaming; decryptHTTPS gates HTTPS MITM interception, which only affects connections opened after the change because a child's CA trust is fixed at spawn time.
type State ¶
type State struct {
// contains filtered or unexported fields
}
func (*State) ActiveNodeName ¶
func (*State) ActiveProxy ¶
func (*State) CurrentDial ¶
func (s *State) CurrentDial() proxyclient.Dial
func (*State) IsAutoMode ¶
func (*State) LoadSubscription ¶
func (s *State) LoadSubscription(sub *clash.Subscription, subscribeURL string)
func (*State) OriginalProxy ¶
func (*State) SetAutoDial ¶
func (s *State) SetAutoDial(clashURL string, dial proxyclient.Dial)
func (*State) SetProxyURL ¶
SetProxyURL routes egress through a single persistent proxy URL (socks5://, trojan://, …). Unlike WithOverrideDial it is not scoped to one command; it stays the active egress until changed or cleared.
func (*State) WithOverrideDial ¶
type TrafficHandler ¶
type TrafficHandler struct {
// contains filtered or unexported fields
}
TrafficHandler bridges the AOP traffic namespace to the runner's traffic infrastructure: it applies Configure (routing + capture) against State/Hub, answers Query with a State snapshot or recorded flows, and streams captured flows back while a stream is requested. One handler is created per connection so its stream lifecycle is tied to that connection.
func NewTrafficHandler ¶
func NewTrafficHandler(infra *Infra) *TrafficHandler
NewTrafficHandler returns a handler backed by infra. infra must be non-nil and fully started (hub listening).
func (*TrafficHandler) Close ¶
func (h *TrafficHandler) Close()
Close tears down any active stream. Call when the connection ends.
func (*TrafficHandler) Register ¶
func (h *TrafficHandler) Register(mux *aop.NamespaceMux) error
Register installs the traffic namespace on mux. The returned mux routes traffic.ProtocolMessage envelopes to this handler.