mirror of
https://github.com/tun2proxy/tun2proxy.git
synced 2025-06-21 16:41:01 +00:00
Add file descriptor support
This commit is contained in:
parent
9437308283
commit
500f6ef21f
5 changed files with 31 additions and 10 deletions
19
src/lib.rs
19
src/lib.rs
|
@ -18,6 +18,11 @@ pub struct Proxy {
|
|||
pub credentials: Option<Credentials>,
|
||||
}
|
||||
|
||||
pub enum NetworkInterface {
|
||||
Named(String),
|
||||
Fd(std::os::fd::RawFd),
|
||||
}
|
||||
|
||||
impl Proxy {
|
||||
pub fn from_url(s: &str) -> Result<Proxy, Error> {
|
||||
let e = format!("`{s}` is not a valid proxy URL");
|
||||
|
@ -83,6 +88,7 @@ impl std::fmt::Display for ProxyType {
|
|||
#[derive(Default)]
|
||||
pub struct Options {
|
||||
virtdns: Option<virtdns::VirtualDns>,
|
||||
mtu: Option<usize>,
|
||||
}
|
||||
|
||||
impl Options {
|
||||
|
@ -94,6 +100,11 @@ impl Options {
|
|||
self.virtdns = Some(virtdns::VirtualDns::new());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_mtu(mut self, mtu: usize) -> Self {
|
||||
self.mtu = Some(mtu);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Debug)]
|
||||
|
@ -111,8 +122,12 @@ impl Credentials {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn main_entry(tun: &str, proxy: &Proxy, options: Options) -> Result<(), Error> {
|
||||
let mut ttp = TunToProxy::new(tun, options)?;
|
||||
pub fn main_entry(
|
||||
interface: &NetworkInterface,
|
||||
proxy: &Proxy,
|
||||
options: Options,
|
||||
) -> Result<(), Error> {
|
||||
let mut ttp = TunToProxy::new(interface, options)?;
|
||||
match proxy.proxy_type {
|
||||
ProxyType::Socks4 => {
|
||||
ttp.add_connection_manager(SocksManager::new(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue