Changes to be committed:

new file:   Cargo.lock
	modified:   src/client.rs
	modified:   src/main.rs
	modified:   src/server.rs
This commit is contained in:
Michael Wain 2024-08-10 21:27:18 +03:00
parent e213a817dc
commit edb9e01dd7
4 changed files with 1095 additions and 7 deletions

1082
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,7 @@ use tun::platform::Device;
use serde_derive::Serialize;
use serde_derive::Deserialize;
pub async fn client_mode() -> io::Result<()> {
pub async fn client_mode(remote_addr: &str) -> io::Result<()> {
info!("Starting client...");
let mut config = tun::Configuration::default();
@ -22,7 +22,6 @@ pub async fn client_mode() -> io::Result<()> {
let sock = Arc::new(Mutex::new(UdpSocket::bind("0.0.0.0:59611").await?));
let sock_main = sock.clone();
let remote_addr = "127.0.0.1:8879";
let sock_main_instance = sock_main.lock().await;
sock_main_instance.connect(remote_addr).await?;

View File

@ -41,6 +41,15 @@ async fn main() {
.get_matches();
let is_server_mode = matches.value_of("mode").unwrap() == "server";
if is_server_mode { server::server_mode().await; } else { client::client_mode().await; }
// "192.168.0.4:8879"
if is_server_mode {
server::server_mode().await;
} else {
if let Some(vpn_server_ip) = matches.value_of("vpn-server") {
let server_address = format!("{}:8879", vpn_server_ip);
client::client_mode(server_address.as_str()).await;
} else {
eprintln!("Error: For client mode, you shall provide the '--vpn-server' argument.");
}
}
}

View File

@ -19,7 +19,7 @@ pub async fn server_mode() -> io::Result<()> {
let tun_device = Arc::new(Mutex::new(tun::create(&config).unwrap()));
let sock = Arc::new(Mutex::new(UdpSocket::bind("127.0.0.1:8879".parse::<SocketAddr>().unwrap()).await?));
let sock = Arc::new(Mutex::new(UdpSocket::bind("192.168.0.5:8879".parse::<SocketAddr>().unwrap()).await?));
let clients = Arc::new(Mutex::new(HashMap::new()));
@ -42,9 +42,7 @@ pub async fn server_mode() -> io::Result<()> {
}*/
let sock_main = sock.clone();
let remote_addr = "127.0.0.1:8879";
let sock_main_instance = sock_main.lock().await;
sock_main_instance.connect(remote_addr).await?;
let clients_main = clients.clone();
let clients_main_instance = clients_main.lock().await;