mirror of
https://github.com/tun2proxy/tun2proxy.git
synced 2025-06-21 16:41:01 +00:00
Refactor
This commit moves some essential types to lib and fixes one clippy warning: https://rust-lang.github.io/rust-clippy/master/index.html#enum_variant_names
This commit is contained in:
parent
e6e6c70006
commit
20dc6f78f1
7 changed files with 57 additions and 57 deletions
44
src/lib.rs
44
src/lib.rs
|
@ -1,15 +1,14 @@
|
|||
use crate::error::Error;
|
||||
use crate::socks5::SocksVersion;
|
||||
use crate::tun2proxy::{Credentials, Options};
|
||||
use crate::{http::HttpManager, socks5::SocksManager, tun2proxy::TunToProxy};
|
||||
use std::net::{SocketAddr, ToSocketAddrs};
|
||||
|
||||
pub mod error;
|
||||
pub mod http;
|
||||
pub mod socks5;
|
||||
pub mod tun2proxy;
|
||||
pub mod virtdevice;
|
||||
pub mod virtdns;
|
||||
mod error;
|
||||
mod http;
|
||||
mod socks5;
|
||||
mod tun2proxy;
|
||||
mod virtdevice;
|
||||
mod virtdns;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Proxy {
|
||||
|
@ -80,6 +79,37 @@ impl std::fmt::Display for ProxyType {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Options {
|
||||
virtdns: Option<virtdns::VirtualDns>,
|
||||
}
|
||||
|
||||
impl Options {
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
pub fn with_virtual_dns(mut self) -> Self {
|
||||
self.virtdns = Some(virtdns::VirtualDns::new());
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Debug)]
|
||||
pub struct Credentials {
|
||||
pub(crate) username: Vec<u8>,
|
||||
pub(crate) password: Vec<u8>,
|
||||
}
|
||||
|
||||
impl Credentials {
|
||||
pub fn new(username: &str, password: &str) -> Self {
|
||||
Self {
|
||||
username: username.as_bytes().to_vec(),
|
||||
password: password.as_bytes().to_vec(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main_entry(tun: &str, proxy: Proxy, options: Options) -> Result<(), Error> {
|
||||
let mut ttp = TunToProxy::new(tun, options)?;
|
||||
match proxy.proxy_type {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue