windows: autoProxy
As upstream's prober: the sites apps reach directly (the Clash API's direct connections here; upstream's inbound access log) are probed through each exit, direct first, every interval and at once for proxy-ctl proxy auto learn. One blocked directly but reached through an exit is routed through it: its exit's local rule-set, which sing-box reloads. Upstream's judgement, ported and tested: block pages, the walk over paths and exits, one exit per network first, strikes against exits that refuse, a new egress discarding what was learned, rechecks once per TTL. Blocks zapret can fix stay direct. The config gains a loopback probe listener per exit (with the hop login, pinned behind the loopback guard) and the learned rules after the user's. proxy-ctl proxy auto list|probe|learn|forget|clear over new API requests (autoProxy scope). Slow sites (slowBelowKiBps) are not routed yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
69e70d6f74
commit
5a89b8d11d
19 files changed
+1640
-10
No files matched your search
@@ -170,6 +170,39 @@ enum ProxyVerb {
|
||||
},
|
||||
/// The config the backend runs.
|
||||
Config,
|
||||
/// autoProxy: what it routed and where; probing, learning, forgetting.
|
||||
Auto {
|
||||
#[command(subcommand)]
|
||||
verb: Option<AutoVerb>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum AutoVerb {
|
||||
/// The routes learned, the exits, what waits.
|
||||
List,
|
||||
/// Probe a site (host, or host/path) through the exits, as autoProxy does.
|
||||
Probe {
|
||||
target: String,
|
||||
/// Only these exits (comma-separated), in this order.
|
||||
#[arg(long, value_delimiter = ',')]
|
||||
exits: Option<Vec<String>>,
|
||||
/// Whether this exit carries what direct reaches.
|
||||
#[arg(long)]
|
||||
via: Option<String>,
|
||||
/// Try every exit, not only up to the first that reaches it.
|
||||
#[arg(long)]
|
||||
keep_going: bool,
|
||||
},
|
||||
/// Probe these hosts now, and route them if they need it.
|
||||
Learn {
|
||||
#[arg(required = true)]
|
||||
hosts: Vec<String>,
|
||||
},
|
||||
/// Forget a domain's route: it is probed again when next dialled.
|
||||
Forget { domain: String },
|
||||
/// Forget everything learned.
|
||||
Clear,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
@@ -523,6 +556,78 @@ async fn proxy(ctl: &Ctl, verb: Option<ProxyVerb>) -> Result<()> {
|
||||
}
|
||||
},
|
||||
ProxyVerb::Config => ctl.print(&ctl.call(Request::RenderedConfig).await?),
|
||||
ProxyVerb::Auto { verb } => auto(ctl, verb).await?,
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn auto(ctl: &Ctl, verb: Option<AutoVerb>) -> Result<()> {
|
||||
match verb.unwrap_or(AutoVerb::List) {
|
||||
AutoVerb::List => {
|
||||
let r = ctl.call(Request::AutoList).await?;
|
||||
if ctl.json {
|
||||
ctl.print(&r);
|
||||
return Ok(());
|
||||
}
|
||||
let state = match (r["enabled"] == true, r["running"] == true) {
|
||||
(false, _) => "off (proxy.autoProxy.enable)",
|
||||
(true, false) => "on, waiting for the local proxy",
|
||||
(true, true) => "running",
|
||||
};
|
||||
println!("autoProxy: {state}");
|
||||
if let Some(e) = r["egress"].as_str() {
|
||||
println!(" egress {e}");
|
||||
}
|
||||
let domains = r["domains"].as_array().cloned().unwrap_or_default();
|
||||
if domains.is_empty() {
|
||||
println!(" nothing routed yet");
|
||||
} else {
|
||||
println!(" {:<32} {:<20} PROBED AS", "DOMAIN", "EXIT");
|
||||
for d in &domains {
|
||||
println!(" {:<32} {:<20} {}", d["domain"].as_str().unwrap_or(""), d["exit"].as_str().unwrap_or(""), d["host"].as_str().unwrap_or(""));
|
||||
}
|
||||
}
|
||||
for e in r["exits"].as_array().into_iter().flatten().filter(|e| e["bad"] == true) {
|
||||
let by: Vec<&str> = e["badBy"].as_array().into_iter().flatten().filter_map(Value::as_str).collect();
|
||||
println!(" bad exit {} (probed last): {}", e["tag"].as_str().unwrap_or(""), by.join(", "));
|
||||
}
|
||||
let censored = r["censored"].as_array().map_or(0, Vec::len);
|
||||
println!(" {} host(s) judged, {censored} left to zapret, {} waiting to be probed", r["hostsJudged"], r["backlog"]);
|
||||
}
|
||||
AutoVerb::Probe { target, exits, via, keep_going } => {
|
||||
let r = ctl.call(Request::AutoProbe { target, exits, via: via.clone(), keep_going }).await?;
|
||||
if ctl.json {
|
||||
ctl.print(&r);
|
||||
return Ok(());
|
||||
}
|
||||
println!(" domain {}", r["domain"].as_str().unwrap_or(""));
|
||||
let chosen = (r["exit"].as_str().unwrap_or(""), r["path"].as_str().unwrap_or(""));
|
||||
println!(" exits");
|
||||
for row in r["rows"].as_array().into_iter().flatten() {
|
||||
let (tag, path) = (row["tag"].as_str().unwrap_or(""), row["path"].as_str().unwrap_or(""));
|
||||
let f: ps_core::autoproxy::Fetch = serde_json::from_value(row["fetch"].clone()).unwrap_or_default();
|
||||
let mark = if (tag, path) == chosen { " <- chosen" } else { "" };
|
||||
println!(" {tag:<18} {path:<12} {:<44} {}{mark}", ps_core::autoproxy::describe(&f), row["judgement"].as_str().unwrap_or(""));
|
||||
}
|
||||
let verdict = r["verdict"].as_str().unwrap_or("");
|
||||
match via {
|
||||
Some(v) if verdict == "ok" => println!(" verdict {v} answers it as well as direct does - it can carry it"),
|
||||
Some(v) => println!(" verdict {v} answers it worse than direct does"),
|
||||
None => println!(" verdict {}", ps_core::autoproxy::verdict_text(verdict, r["exit"].as_str())),
|
||||
}
|
||||
}
|
||||
AutoVerb::Learn { hosts } => {
|
||||
let r = ctl.call(Request::AutoLearn { hosts }).await?;
|
||||
println!("{} host(s) queued; the prober runs now (proxy-ctl logs proxy-suite-autoproxy)", r["queued"]);
|
||||
}
|
||||
AutoVerb::Forget { domain } => {
|
||||
ctl.call(Request::AutoForget { domain: Some(domain.clone()) }).await?;
|
||||
println!("forgot {domain}");
|
||||
}
|
||||
AutoVerb::Clear => {
|
||||
ctl.call(Request::AutoForget { domain: None }).await?;
|
||||
println!("forgot everything learned");
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user