Skip to main content

proxy_pilot/core/
mod.rs

1pub mod xray;
2
3use std::collections::HashMap;
4
5use async_trait::async_trait;
6
7use crate::error::Result;
8
9/// A temporary, isolated proxy instance exposing one local proxy URL per outbound tag
10/// so all profiles can be probed concurrently without restarting the live service.
11#[async_trait]
12pub trait BenchmarkSession: Send + Sync {
13    /// Map of `outbound_tag -> local proxy URL` (e.g. `socks5h://127.0.0.1:24501`).
14    fn endpoints(&self) -> &HashMap<String, String>;
15    /// Gracefully stop the temporary proxy instance and remove temporary files.
16    async fn shutdown(self: Box<Self>) -> Result<()>;
17}
18
19/// Abstraction over a proxy runtime core (e.g. Xray, sing-box).
20#[async_trait]
21pub trait ProxyCore: Send + Sync {
22    fn name(&self) -> &'static str;
23    async fn is_installed(&self) -> bool;
24    async fn install(&self) -> Result<()>;
25    async fn active_profile(&self) -> Result<Option<String>>;
26    async fn switch_profile(&self, outbound_tag: &str) -> Result<()>;
27    async fn reload(&self) -> Result<()>;
28
29    /// Optionally start an isolated, non-disruptive benchmark session exposing
30    /// a dedicated local proxy endpoint for each requested outbound tag.
31    /// Returning `Ok(None)` falls back to sequential switch+reload benchmarking.
32    async fn start_benchmark_session(
33        &self,
34        _outbound_tags: &[String],
35    ) -> Result<Option<Box<dyn BenchmarkSession>>> {
36        Ok(None)
37    }
38}