sl4f_lib/proxy/
commands.rs1use crate::server::Facade;
6use anyhow::{format_err, Error};
7use async_trait::async_trait;
8use serde_json::{to_value, Value};
9
10use crate::proxy::facade::ProxyFacade;
11
12#[async_trait(?Send)]
13impl Facade for ProxyFacade {
14 async fn handle_request(&self, method: String, args: Value) -> Result<Value, Error> {
15 match method.as_ref() {
16 "OpenProxy" => {
17 let ports: Vec<u16> = serde_json::from_value(args)?;
18 let target_port: u16 = ports[0];
19 let proxy_port: u16 = ports[1];
20 let open_port = self.open_proxy(target_port, proxy_port).await?;
21 Ok(to_value(open_port)?)
22 }
23 "DropProxy" => {
24 let target_port: u16 = serde_json::from_value(args)?;
25 self.drop_proxy(target_port).await;
26 Ok(to_value(())?)
27 }
28 "StopAllProxies" => {
29 self.stop_all_proxies().await;
30 Ok(to_value(())?)
31 }
32 _ => return Err(format_err!("Invalid proxy facade method: {:?}", method)),
33 }
34 }
35}