Cleaning and update

This commit is contained in:
Elvis Gallagher 2022-08-01 14:36:58 +00:00
parent 8af93a278e
commit 8d408bbe76
8 changed files with 295 additions and 252 deletions

View file

@ -1,43 +1,45 @@
#![feature(deque_make_contiguous)]
#![feature(deque_range)]
mod virtdevice;
mod socks5;
mod http;
mod socks5;
mod tun2proxy;
mod virtdevice;
use socks5::*;
use crate::http::HttpManager;
use crate::tun2proxy::TunToProxy;
use socks5::*;
use std::net::ToSocketAddrs;
fn main() {
let matches = clap::App::new(env!("CARGO_PKG_NAME"))
.version(env!("CARGO_PKG_VERSION"))
.about("Tunnel interface to proxy.")
.arg(clap::Arg::with_name("tun")
.short("t")
.long("tun")
.value_name("TUN")
.help("Name of the tun interface")
.required(true)
.takes_value(true))
.arg(clap::Arg::with_name("socks5_server")
.help("SOCKS5 server to use")
.short("s")
.long("socks5")
.value_name("IP:PORT"))
.arg(clap::Arg::with_name("http_server")
.help("HTTP server to use")
.short("h")
.long("http")
.value_name("IP:PORT"))
.arg(
clap::Arg::with_name("tun")
.short('t')
.long("tun")
.value_name("TUN")
.help("Name of the tun interface")
.required(true)
.takes_value(true),
)
.arg(
clap::Arg::with_name("socks5_server")
.help("SOCKS5 server to use")
.short('s')
.long("socks5")
.value_name("IP:PORT"),
)
.arg(
clap::Arg::with_name("http_server")
.help("HTTP server to use")
.short('h')
.long("http")
.value_name("IP:PORT"),
)
.get_matches();
if matches.value_of("socks5_server").is_some()
&& matches.value_of("http_server").is_some()
|| matches.value_of("socks5_server").is_none()
&& matches.value_of("http_server").is_none() {
if matches.value_of("socks5_server").is_some() && matches.value_of("http_server").is_some()
|| matches.value_of("socks5_server").is_none() && matches.value_of("http_server").is_none()
{
eprintln!("You need to specify exactly one server.");
return;
}
@ -45,8 +47,7 @@ fn main() {
let tun_name = matches.value_of("tun").unwrap();
let mut ttp = TunToProxy::new(tun_name);
if let Some(addr) = matches.value_of("socks5_server") {
if let Ok(mut servers) = addr.to_socket_addrs()
{
if let Ok(mut servers) = addr.to_socket_addrs() {
let server = servers.next().unwrap();
println!("SOCKS5 server: {}", server);
ttp.add_connection_manager(Box::new(Socks5Manager::new(server)));
@ -57,8 +58,7 @@ fn main() {
}
if let Some(addr) = matches.value_of("http_server") {
if let Ok(mut servers) = addr.to_socket_addrs()
{
if let Ok(mut servers) = addr.to_socket_addrs() {
let server = servers.next().unwrap();
println!("HTTP server: {}", server);
ttp.add_connection_manager(Box::new(HttpManager::new(server)));