NLinker icon

Minimal rust socks5 server

NLinker | PRO | 12/26/18 10:41:07 AM UTC | 0 ⭐ | 1340 👁️ | Never ⏰ | []
Rust |

1.47 KB

|

None

|

0 👍

/

0 👎

use hyper::client::Client;
use std::net::SocketAddr;
 
const DEFAULT_HTTPS_DNS_WORKER_THREADS: usize = 1;
 
pub trait Executor {
}
 
struct HyperExecutor<C> {
    inner: Client<C>
}
 
impl<C> HyperExecutor<C> {
    fn new(inner: Client<C>) -> Self {
        HyperExecutor { inner }
    }
}
 
impl<C> Executor for HyperExecutor<C> {
}
 
fn default_executor() -> impl Executor {
    let connector = hyper_tls::HttpsConnector::new(DEFAULT_HTTPS_DNS_WORKER_THREADS).unwrap();
    let client = Client::builder().build(connector);
    HyperExecutor::new(client)
}
 
fn socks_proxy_executor(proxy: &str) -> impl Executor {
    let client = Client::builder().build(hyper_socks2::Connector::new(parse_socks_proxy(proxy)));
    HyperExecutor::new(client)
}
 
fn http_proxy_executor() -> impl Executor {
    let uri = "http://my-proxy:8080".parse().unwrap();
    let mut proxy = hyper_proxy::Proxy::new(hyper_proxy::Intercept::All, uri);
    proxy.set_authorization(typed_headers::Credentials::basic("John Doe", "Agent1234").unwrap());
    let connector = hyper_tls::HttpsConnector::new(DEFAULT_HTTPS_DNS_WORKER_THREADS).unwrap();
    let proxy_connector = hyper_proxy::ProxyConnector::from_proxy(connector, proxy).unwrap();
    let client = Client::builder().build(proxy_connector);
    HyperExecutor::new(client)
}
 
fn parse_socks_proxy(dsn: &str) -> hyper_socks2::Proxy<SocketAddr> {
    hyper_socks2::Proxy::Socks5 {
        addrs: "host:port",
        auth: None
    }
}

Comments