Skip to content

Commit 66e5b71

Browse files
committed
Only increment self.ack_nr when Data packet arrives
1 parent 1a578c6 commit 66e5b71

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/socket.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,11 @@ impl UtpSocket {
10231023
debug!("({:?}, {:?})", self.state, packet.get_type());
10241024

10251025
// Acknowledge only if the packet strictly follows the previous one
1026-
if packet.seq_nr().wrapping_sub(self.ack_nr) == 1 {
1026+
// and only if it is a payload packet. The restriction on PacketType
1027+
// is due to all other (non Data) packets are assigned seq_nr the
1028+
// same as the next Data packet, thus we could acknowledge what
1029+
// we have not received yet.
1030+
if packet.get_type() == PacketType::Data && packet.seq_nr().wrapping_sub(self.ack_nr) == 1 {
10271031
self.ack_nr = packet.seq_nr();
10281032
}
10291033

@@ -1056,6 +1060,12 @@ impl UtpSocket {
10561060
self.last_dropped = self.ack_nr;
10571061

10581062
self.state_packet = Some(self.prepare_reply(packet, PacketType::State));
1063+
1064+
// Advance the self.seq_nr (the sequence number of the next packet),
1065+
// this is because the other end will use the `seq_nr` of this state
1066+
// packet as his `self.last_acked`
1067+
self.seq_nr = self.seq_nr.wrapping_add(1);
1068+
10591069
Ok(self.state_packet.clone())
10601070
},
10611071
(SocketState::Connected, PacketType::Syn) if self.connected_to == src => {

0 commit comments

Comments
 (0)