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
@@ -136,6 +136,7 @@ fn scope_of(req: &Request) -> Option<Scope> {
|
||||
Request::RenderedConfig | Request::Logs { .. } | Request::TgLinks => Some(Scope::Secrets),
|
||||
Request::Restart { .. } | Request::Start { .. } | Request::Stop { .. } => Some(Scope::Services),
|
||||
Request::WlList | Request::WlLink { .. } | Request::WlAuth { .. } | Request::WlJoin { .. } | Request::WlNew { .. } => Some(Scope::WhitelistBypass),
|
||||
Request::AutoList | Request::AutoProbe { .. } | Request::AutoLearn { .. } | Request::AutoForget { .. } => Some(Scope::AutoProxy),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -577,6 +578,48 @@ pub async fn handle(req: Request, peer: &Peer, shared: &Shared) -> Response {
|
||||
wl_restart(&mut s, &format!("{}{name}", crate::wl::CREATOR_PREFIX)).await
|
||||
}
|
||||
|
||||
Request::AutoList => {
|
||||
let s = shared.lock().await;
|
||||
let exits = crate::autoproxy::exits(&s);
|
||||
Response::ok(crate::autoproxy::listing(s.paths(), exits.as_ref(), &s.cfg().proxy.auto_proxy))
|
||||
}
|
||||
|
||||
Request::AutoProbe { target, exits, via, keep_going } => {
|
||||
let Some(probe_exits) = crate::autoproxy::exits(&*shared.lock().await) else {
|
||||
return Response::err("autoProxy is not running: it needs proxy.autoProxy.enable and the local proxy on");
|
||||
};
|
||||
// The network, outside the lock.
|
||||
match probe_exits.probe(&target, exits.as_deref(), via.as_deref(), keep_going).await {
|
||||
Ok(p) => Response::ok(serde_json::to_value(&p).unwrap()),
|
||||
Err(e) => Response::err(format!("{e:#}")),
|
||||
}
|
||||
}
|
||||
|
||||
Request::AutoLearn { hosts } => {
|
||||
let s = shared.lock().await;
|
||||
if crate::autoproxy::exits(&s).is_none() {
|
||||
return Response::err("autoProxy is not running: it needs proxy.autoProxy.enable and the local proxy on");
|
||||
}
|
||||
let bad: Vec<&String> = hosts.iter().filter(|h| !ps_core::autoproxy::host_ok(h.trim())).collect();
|
||||
if !bad.is_empty() {
|
||||
return Response::err(format!("not host names: {}", bad.iter().map(|h| h.as_str()).collect::<Vec<_>>().join(", ")));
|
||||
}
|
||||
let queued = {
|
||||
let mut r = s.ap.requests.lock().unwrap();
|
||||
// Bounded: every request is a probe.
|
||||
let room = 10_000usize.saturating_sub(r.len());
|
||||
r.extend(hosts.iter().take(room).map(|h| h.trim().to_owned()));
|
||||
hosts.len().min(room)
|
||||
};
|
||||
s.ap.wake.notify_one();
|
||||
Response::ok(json!({ "queued": queued }))
|
||||
}
|
||||
|
||||
Request::AutoForget { domain } => match crate::autoproxy::edit(shared, domain.as_deref()).await {
|
||||
Ok(()) => Response::ok(json!({ "forgot": domain.unwrap_or_else(|| "everything".into()) })),
|
||||
Err(e) => Response::err(format!("{e:#}")),
|
||||
},
|
||||
|
||||
Request::ComponentsInstall { names } => {
|
||||
// Programs the service runs as SYSTEM: an administrator's call, whatever the scopes.
|
||||
if !peer.admin {
|
||||
|
||||
Reference in new issue
Block a user