diff --git a/Cargo.lock b/Cargo.lock index 8701a0b..ed0f217 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -72,7 +72,7 @@ dependencies = [ [[package]] name = "revpfw3" -version = "0.3.0" +version = "0.3.1" dependencies = [ "enum-ordinalize", ] diff --git a/Cargo.toml b/Cargo.toml index 1d41bf9..a2c3dff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "revpfw3" repository = "https://github.com/tudbut/revpfw3" description = "A tool to bypass portforwarding restrictions using some cheap VServer" license = "MIT" -version = "0.3.0" +version = "0.3.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/client.rs b/src/client.rs index 3abc4fd..b37f7ca 100644 --- a/src/client.rs +++ b/src/client.rs @@ -69,6 +69,7 @@ pub fn client(ip: &str, port: u16, dest_ip: &str, dest_port: u16, key: &str, sle .unwrap(); tcp.write(&i.to_be_bytes()).unwrap(); tcp.write(&x.to_be_bytes()).unwrap(); + socket.punish(x); } } for i in to_remove.into_iter().rev() { diff --git a/src/server.rs b/src/server.rs index 97d34fa..7ad7a53 100644 --- a/src/server.rs +++ b/src/server.rs @@ -92,6 +92,7 @@ pub fn server(port: u16, key: &str, sleep_delay_ms: u64) { .unwrap(); tcp.write(&i.to_be_bytes()).unwrap(); tcp.write(&x.to_be_bytes()).unwrap(); + socket.punish(x); } } for i in to_remove.into_iter().rev() { diff --git a/src/socket_adapter.rs b/src/socket_adapter.rs index 728cbf7..6f2ae5e 100644 --- a/src/socket_adapter.rs +++ b/src/socket_adapter.rs @@ -2,7 +2,7 @@ use std::{ io::{Error, Read}, io::{ErrorKind, Write}, net::TcpStream, - time::SystemTime, + time::{SystemTime, Duration}, }; use crate::io_sync; @@ -73,7 +73,7 @@ impl SocketAdapter { self.written = 0; self.to_write = buf.len(); self.write[..buf.len()].copy_from_slice(buf); - self.accumulated_delay += sa.elapsed().unwrap().as_millis(); + self.accumulated_delay += sa.elapsed().unwrap().as_micros(); return Ok(()); }; x.copy_from_slice(buf); @@ -87,7 +87,7 @@ impl SocketAdapter { } pub fn update(&mut self) -> Result<(), Error> { - if Some(SystemTime::UNIX_EPOCH.elapsed().unwrap().as_millis()) < self.ignore_until { + if Some(SystemTime::UNIX_EPOCH.elapsed().unwrap().as_micros()) < self.ignore_until { return Ok(()); } if let Some(ref x) = self.broken { @@ -121,7 +121,7 @@ impl SocketAdapter { } pub fn poll(&mut self, buf: &mut [u8]) -> Result, Error> { - if Some(SystemTime::UNIX_EPOCH.elapsed().unwrap().as_millis()) < self.ignore_until { + if Some(SystemTime::UNIX_EPOCH.elapsed().unwrap().as_micros()) < self.ignore_until { return Ok(None); } self.update()?; @@ -134,7 +134,7 @@ impl SocketAdapter { pub fn punish(&mut self, time: u128) { if self.ignore_until == None { - self.ignore_until = Some(SystemTime::UNIX_EPOCH.elapsed().unwrap().as_millis()); + self.ignore_until = Some(SystemTime::UNIX_EPOCH.elapsed().unwrap().as_micros()); } self.ignore_until = self.ignore_until.map(|x| x + time); }