fix resyncing

This commit is contained in:
Daniella 2023-10-04 13:17:13 +02:00
parent 1e03ee8002
commit 637fdcae58
Signed by: TudbuT
GPG key ID: 7D63D5634B7C417F
4 changed files with 9 additions and 8 deletions

View file

@ -3,7 +3,7 @@ name = "revpfw3"
repository = "https://github.com/tudbut/revpfw3" repository = "https://github.com/tudbut/revpfw3"
description = "A tool to bypass portforwarding restrictions using some cheap VServer" description = "A tool to bypass portforwarding restrictions using some cheap VServer"
license = "MIT" license = "MIT"
version = "0.3.1" version = "0.4.0"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -107,7 +107,6 @@ fn resync(tcp: &mut SocketAdapter) {
eprintln!("Resync was not successful. Stopping."); eprintln!("Resync was not successful. Stopping.");
panic!("broken connection or server version mismatch."); panic!("broken connection or server version mismatch.");
} }
tcp.set_nonblocking(true);
tcp.internal.set_print(true); tcp.internal.set_print(true);
} }
@ -138,11 +137,11 @@ pub fn client(params: ClientParams) {
println!("READY!"); println!("READY!");
let mut tcp = SocketAdapter::new(tcp); let mut tcp = SocketAdapter::new(tcp);
tcp.set_nonblocking(true);
let mut sockets: HashMap<u64, SocketAdapter> = HashMap::new(); let mut sockets: HashMap<u64, SocketAdapter> = HashMap::new();
let mut id = 0; let mut id = 0;
let mut last_keep_alive = SystemTime::now(); let mut last_keep_alive = SystemTime::now();
loop { loop {
tcp.set_nonblocking(true);
thread::sleep(Duration::from_millis(params.rate_limit_sleep)); thread::sleep(Duration::from_millis(params.rate_limit_sleep));
let mut did_anything = false; let mut did_anything = false;

View file

@ -20,7 +20,6 @@ fn resync(tcp: &mut SocketAdapter) {
eprintln!( eprintln!(
"Sent resync packet. Client should now wait 8 seconds and then send a resync packet back, initiating a normal re-sync." "Sent resync packet. Client should now wait 8 seconds and then send a resync packet back, initiating a normal re-sync."
); );
tcp.set_nonblocking(true);
let mut buf = [0; 4096]; let mut buf = [0; 4096];
// read all packets that are still pending. // read all packets that are still pending.
while Some(Some(4096)) == tcp.poll(&mut buf).ok() {} while Some(Some(4096)) == tcp.poll(&mut buf).ok() {}
@ -31,7 +30,6 @@ fn resync(tcp: &mut SocketAdapter) {
// server should now have stopped sending packets. waiting 5 more seconds so the client has time to // server should now have stopped sending packets. waiting 5 more seconds so the client has time to
// send the resync packet. // send the resync packet.
thread::sleep(Duration::from_secs(5)); thread::sleep(Duration::from_secs(5));
tcp.set_nonblocking(true);
tcp.internal.set_print(true); tcp.internal.set_print(true);
} }
@ -67,13 +65,13 @@ pub fn server(port: u16, key: &str, sleep_delay_ms: u64) {
tcpl.set_nonblocking(true).unwrap(); tcpl.set_nonblocking(true).unwrap();
let mut tcp = SocketAdapter::new(Connection::new_tcp(tcp, false)); let mut tcp = SocketAdapter::new(Connection::new_tcp(tcp, true));
tcp.set_nonblocking(true);
let mut sockets: HashMap<u64, SocketAdapter> = HashMap::new(); let mut sockets: HashMap<u64, SocketAdapter> = HashMap::new();
let mut id = 0; let mut id = 0;
let mut last_keep_alive_sent = SystemTime::now(); let mut last_keep_alive_sent = SystemTime::now();
let mut last_keep_alive = SystemTime::now(); let mut last_keep_alive = SystemTime::now();
loop { loop {
tcp.set_nonblocking(true);
let mut did_anything = false; let mut did_anything = false;
if last_keep_alive_sent.elapsed().unwrap().as_secs() >= 10 { if last_keep_alive_sent.elapsed().unwrap().as_secs() >= 10 {

View file

@ -104,7 +104,11 @@ impl SocketAdapter {
self.internal.set_nonblocking(self.is_nonblocking)?; self.internal.set_nonblocking(self.is_nonblocking)?;
r r
} { } {
Ok(()) => Ok(()), Ok(()) => {
self.written = 0;
self.to_write = 0;
Ok(())
}
Err(x) => { Err(x) => {
self.broken = Some(Broken::DirectErr(x.kind(), "io error")); self.broken = Some(Broken::DirectErr(x.kind(), "io error"));
Err(x) Err(x)