Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(net): Improved Masking Function for Message IDs #5724

Merged
merged 2 commits into from
Dec 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions crates/net/eth-wire/src/muxdemux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,11 @@ impl<S> MuxDemuxStream<S> {
}

/// Masks message id with offset relative to the message id suffix reserved for capability
/// message ids. The p2p stream further masks the message id (todo: mask whole message id at
/// once to avoid copying message to mutate id byte or sink BytesMut).
/// message ids. The p2p stream further masks the message id
fn mask_msg_id(&self, msg: Bytes) -> Bytes {
let mut masked_bytes = BytesMut::zeroed(msg.len());
masked_bytes[0] = msg[0] + self.owner.relative_message_id_offset();
masked_bytes[1..].copy_from_slice(&msg[1..]);

let mut masked_bytes = BytesMut::with_capacity(msg.len());
masked_bytes.extend_from_slice(&msg);
masked_bytes[0] += self.owner.relative_message_id_offset();
masked_bytes.freeze()
}

Expand Down Expand Up @@ -310,10 +308,9 @@ pub struct StreamClone {

impl StreamClone {
fn mask_msg_id(&self, msg: Bytes) -> Bytes {
let mut masked_bytes = BytesMut::zeroed(msg.len());
masked_bytes[0] = msg[0] + self.cap.relative_message_id_offset();
masked_bytes[1..].copy_from_slice(&msg[1..]);

let mut masked_bytes = BytesMut::with_capacity(msg.len());
masked_bytes.extend_from_slice(&msg);
masked_bytes[0] += self.cap.relative_message_id_offset();
masked_bytes.freeze()
}
}
Expand Down
Loading