qft can now withstand loss=2% delay=500ms corrupt=2% duplicate=5% reorder=5% without losing connection, and it can get the same speed with 20ms ping and 1000ms ping
This commit is contained in:
parent
761831460f
commit
aa35f1bbe8
1 changed files with 24 additions and 2 deletions
26
src/main.rs
26
src/main.rs
|
@ -150,16 +150,17 @@ impl SafeReadWrite {
|
|||
continue;
|
||||
}
|
||||
}
|
||||
self.last_transmitted.insert(u16::from_be_bytes(id), vbuf);
|
||||
self.last_transmitted.insert(idn, vbuf);
|
||||
break;
|
||||
}
|
||||
let mut buf = [0, 0, 0];
|
||||
if self.last_transmitted.len() < 50 {
|
||||
if self.last_transmitted.len() < 100 {
|
||||
self.socket
|
||||
.set_read_timeout(Some(Duration::from_millis(1)))
|
||||
.unwrap();
|
||||
}
|
||||
let mut wait = idn == 0xffff || flush;
|
||||
let start = unix_millis();
|
||||
if idn == 0xffff {
|
||||
print!("\r\x1b[KPacket ID needs to wrap. Waiting for partner to catch up...")
|
||||
}
|
||||
|
@ -217,6 +218,27 @@ impl SafeReadWrite {
|
|||
}
|
||||
}
|
||||
None => {
|
||||
if unix_millis() - start > 10000 {
|
||||
println!("\r\x1b[K10s passed since last packet ==> Contact broke. Trying to resend packet...");
|
||||
loop {
|
||||
let buf = self
|
||||
.last_transmitted
|
||||
.get(&idn)
|
||||
.expect("Unable to recover from connection loss.");
|
||||
match self.socket.send(buf) {
|
||||
Ok(x) => {
|
||||
if x != buf.len() {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if !wait {
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue