Skip to content

Commit

Permalink
Allow losing unacknowledged packets
Browse files Browse the repository at this point in the history
  • Loading branch information
vladbat00 committed Mar 28, 2021
1 parent 858bf79 commit 4639e4e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 24 deletions.
2 changes: 1 addition & 1 deletion libs/client_lib/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ pub fn send_network_updates(
network_params
.connection_state
// Clients don't resend updates, so we can forget about unacknowledged packets.
.add_outcoming_packet_unchecked(time.frame_number, Instant::now());
.add_outcoming_packet(time.frame_number, Instant::now());
let first_unacknowledged_frame = network_params
.connection_state
.first_unacknowledged_outcoming_packet()
Expand Down
8 changes: 1 addition & 7 deletions libs/server_lib/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,7 @@ pub fn send_network_updates(
log::error!("Failed to send a message: {:?}", err);
}

if let Err(err) =
connection_state.add_outcoming_packet(time.frame_number, Instant::now())
{
// TODO: disconnect players.
log::error!("Failed to add an outcoming packet: {:?}", err);
continue;
}
connection_state.add_outcoming_packet(time.frame_number, Instant::now());
}

// Broadcasting updates about new connected players.
Expand Down
17 changes: 1 addition & 16 deletions libs/shared_lib/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,7 @@ impl ConnectionState {
.map(|ack| ack.frame_number)
}

pub fn add_outcoming_packet(
&mut self,
frame_number: FrameNumber,
sent: Instant,
) -> Result<(), AddOutcomingPacketError> {
if self.outcoming_packets_acks.len() == 64 {
let oldest_packet = self.outcoming_packets_acks.front().unwrap();
if !oldest_packet.acknowledged {
return Err(AddOutcomingPacketError::WouldLoseUnacknowledged);
}
}
self.add_outcoming_packet_unchecked(frame_number, sent);
Ok(())
}

pub fn add_outcoming_packet_unchecked(&mut self, frame_number: FrameNumber, sent: Instant) {
pub fn add_outcoming_packet(&mut self, frame_number: FrameNumber, sent: Instant) {
if self.outcoming_packets_acks.len() == 64 {
self.outcoming_packets_acks.pop_front();
}
Expand Down

0 comments on commit 4639e4e

Please sign in to comment.