Skip to content

Commit

Permalink
Renet: warn user of large unreliable messages
Browse files Browse the repository at this point in the history
Large unreliable message are susceptible to packet loss. Lets warn the user in case they are hitting this problem without noticing.

Note: this is similar to what is done in the steam sockets. They also convert message to reliable, but we can't to this, so we just warn them.
  • Loading branch information
lucaspoffo committed Jan 5, 2024
1 parent 28092ca commit 0aa1a4d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions renet/src/channel/unreliable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ impl SendChannelUnreliable {
return;
}

let num_fragments = message.len() / SLICE_SIZE;
if num_fragments > 20 {
log::warn!(
"Sending an unreliable message with {num_fragments} fragments, messages with this many fragments are susceptible to packet loss. \
Consider breaking your message into smaller ones or using a reliable channel");
}

self.memory_usage_bytes += message.len();
self.unreliable_messages.push_back(message);
}
Expand Down

0 comments on commit 0aa1a4d

Please sign in to comment.