mirror of
https://github.com/tun2proxy/tun2proxy.git
synced 2025-04-21 14:29:10 +00:00
ArgProxy issues
This commit is contained in:
parent
5514da71f9
commit
9f60eee2e1
3 changed files with 19 additions and 2 deletions
|
@ -18,7 +18,7 @@ pub(crate) fn tun2proxy_internal_run(args: Args, tun_mtu: u16) -> c_int {
|
||||||
}
|
}
|
||||||
|
|
||||||
let block = async move {
|
let block = async move {
|
||||||
log::info!("Proxy {} server: {}", args.proxy.proxy_type, args.proxy.addr);
|
log::info!("Proxying {}", args.proxy);
|
||||||
|
|
||||||
let mut config = tun2::Configuration::default();
|
let mut config = tun2::Configuration::default();
|
||||||
config.raw_fd(args.tun_fd.ok_or(crate::Error::from("tun_fd"))?);
|
config.raw_fd(args.tun_fd.ok_or(crate::Error::from("tun_fd"))?);
|
||||||
|
|
17
src/args.rs
17
src/args.rs
|
@ -190,6 +190,20 @@ impl Default for ArgProxy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for ArgProxy {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
let auth = match &self.credentials {
|
||||||
|
Some(creds) => format!("{}", creds),
|
||||||
|
None => "".to_owned(),
|
||||||
|
};
|
||||||
|
if auth.is_empty() {
|
||||||
|
write!(f, "{}://{}", &self.proxy_type, &self.addr)
|
||||||
|
} else {
|
||||||
|
write!(f, "{}://{}@{}", &self.proxy_type, auth, &self.addr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ArgProxy {
|
impl ArgProxy {
|
||||||
pub fn from_url(s: &str) -> Result<ArgProxy> {
|
pub fn from_url(s: &str) -> Result<ArgProxy> {
|
||||||
let e = format!("`{s}` is not a valid proxy URL");
|
let e = format!("`{s}` is not a valid proxy URL");
|
||||||
|
@ -235,12 +249,13 @@ impl ArgProxy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Default)]
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Default)]
|
||||||
pub enum ProxyType {
|
pub enum ProxyType {
|
||||||
|
Http = 0,
|
||||||
Socks4,
|
Socks4,
|
||||||
#[default]
|
#[default]
|
||||||
Socks5,
|
Socks5,
|
||||||
Http,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for ProxyType {
|
impl std::fmt::Display for ProxyType {
|
||||||
|
|
|
@ -63,6 +63,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
tproxy_config::tproxy_setup(&tproxy_args)?;
|
tproxy_config::tproxy_setup(&tproxy_args)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log::info!("Proxying {}", args.proxy);
|
||||||
|
|
||||||
let shutdown_token = CancellationToken::new();
|
let shutdown_token = CancellationToken::new();
|
||||||
let cloned_token = shutdown_token.clone();
|
let cloned_token = shutdown_token.clone();
|
||||||
let join_handle = tokio::spawn(tun2proxy::run(device, MTU, args, cloned_token));
|
let join_handle = tokio::spawn(tun2proxy::run(device, MTU, args, cloned_token));
|
||||||
|
|
Loading…
Add table
Reference in a new issue