Changes to be committed:
modified: src/client.rs modified: src/main.rs
This commit is contained in:
parent
81fa1b1db3
commit
9e885b7bf8
@ -56,18 +56,18 @@ fn configure_routes() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn client_mode(remote_addr: &str) -> io::Result<()> {
|
pub async fn client_mode(remote_addr: String) -> io::Result<()> {
|
||||||
info!("Starting client...");
|
info!("Starting client...");
|
||||||
|
|
||||||
let mut config = tun2::Configuration::default();
|
let mut config = tun2::Configuration::default();
|
||||||
config.address("10.8.0.2");
|
config.address("10.8.0.2");
|
||||||
config.netmask("128.0.0.0");
|
config.netmask("128.0.0.0");
|
||||||
config.destination("0.0.0.0");
|
config.destination("0.0.0.0");
|
||||||
config.tun_name("tun0");
|
config.name("tun0");
|
||||||
config.up();
|
config.up();
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
config.platform_config(|config| {
|
config.platform(|config| {
|
||||||
config.packet_information(true);
|
config.packet_information(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -78,13 +78,14 @@ pub async fn client_mode(remote_addr: &str) -> io::Result<()> {
|
|||||||
configure_routes();
|
configure_routes();
|
||||||
|
|
||||||
let sock = UdpSocket::bind("0.0.0.0:59611").await?;
|
let sock = UdpSocket::bind("0.0.0.0:59611").await?;
|
||||||
sock.connect(remote_addr).await?;
|
sock.connect(&remote_addr).await?;
|
||||||
let r = Arc::new(sock);
|
let receive_sock = Arc::new(sock);
|
||||||
let s = r.clone();
|
let send_sock = Arc::new(UdpSocket::bind("0.0.0.0:59612").await?);
|
||||||
let (tx, mut rx) = mpsc::channel::<Vec<u8>>(1_000);
|
|
||||||
|
|
||||||
let mut set = JoinSet::new();
|
let mut set = JoinSet::new();
|
||||||
|
|
||||||
|
let srem = Arc::new(remote_addr.clone());
|
||||||
|
|
||||||
set.spawn(async move {
|
set.spawn(async move {
|
||||||
let mut buf = [0; 4096];
|
let mut buf = [0; 4096];
|
||||||
loop {
|
loop {
|
||||||
@ -92,7 +93,9 @@ pub async fn client_mode(remote_addr: &str) -> io::Result<()> {
|
|||||||
Ok(size) => {
|
Ok(size) => {
|
||||||
let pkt = &buf[..size];
|
let pkt = &buf[..size];
|
||||||
use std::io::{Error, ErrorKind::Other};
|
use std::io::{Error, ErrorKind::Other};
|
||||||
tx.send(pkt.to_vec()).await.unwrap();
|
//tx.send(pkt.to_vec()).await.unwrap();
|
||||||
|
send_sock.send_to(pkt, srem.parse::<SocketAddr>()
|
||||||
|
.expect("Unable to parse socket address"));
|
||||||
info!("Wrote to sock");
|
info!("Wrote to sock");
|
||||||
}
|
}
|
||||||
Err(error) => error!("Error with reading from tun")
|
Err(error) => error!("Error with reading from tun")
|
||||||
@ -101,17 +104,10 @@ pub async fn client_mode(remote_addr: &str) -> io::Result<()> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
set.spawn(async move {
|
|
||||||
while let Some(bytes) = rx.recv().await {
|
|
||||||
let len = s.send(&bytes).await.unwrap();
|
|
||||||
println!("{:?} bytes sent", len);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
set.spawn(async move {
|
set.spawn(async move {
|
||||||
let mut buf = [0; 1024];
|
let mut buf = [0; 1024];
|
||||||
loop {
|
loop {
|
||||||
match r.recv_from(&mut buf).await {
|
match receive_sock.recv_from(&mut buf).await {
|
||||||
Ok((len, addr)) => {
|
Ok((len, addr)) => {
|
||||||
println!("{:?} bytes received from {:?}", len, addr);
|
println!("{:?} bytes received from {:?}", len, addr);
|
||||||
writer.write_all(&buf[..len]);
|
writer.write_all(&buf[..len]);
|
||||||
|
@ -47,7 +47,7 @@ async fn main() {
|
|||||||
} else {
|
} else {
|
||||||
if let Some(vpn_server_ip) = matches.value_of("vpn-server") {
|
if let Some(vpn_server_ip) = matches.value_of("vpn-server") {
|
||||||
let server_address = format!("{}:8879", vpn_server_ip);
|
let server_address = format!("{}:8879", vpn_server_ip);
|
||||||
client::client_mode(server_address.as_str()).await;
|
client::client_mode(server_address).await;
|
||||||
} else {
|
} else {
|
||||||
eprintln!("Error: For client mode, you shall provide the '--vpn-server' argument.");
|
eprintln!("Error: For client mode, you shall provide the '--vpn-server' argument.");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user