Skip to content

Commit

Permalink
Randomize fixed bit for compatible peers
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralith committed Jan 22, 2022
1 parent ff642b3 commit e764386
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion quinn-proto/src/connection/packet_builder.rs
Expand Up @@ -7,7 +7,7 @@ use tracing::{trace, trace_span};
use super::{spaces::SentPacket, Connection, SentFrames, State};
use crate::{
frame::{self, Close},
packet::{Header, LongType, PacketNumber, PartialEncode, SpaceId},
packet::{Header, LongType, PacketNumber, PartialEncode, SpaceId, FIXED_BIT},
TransportError, TransportErrorCode,
};

Expand Down Expand Up @@ -115,6 +115,10 @@ impl PacketBuilder {
},
};
let partial_encode = header.encode(buffer);
if conn.peer_params.grease_quic_bit && conn.rng.gen() {
buffer[partial_encode.start] ^= FIXED_BIT;
}

let (sample_size, tag_len) = if let Some(ref crypto) = space.crypto {
(
crypto.header.local.sample_size(),
Expand Down
2 changes: 1 addition & 1 deletion quinn-proto/src/packet.rs
Expand Up @@ -770,7 +770,7 @@ impl From<coding::UnexpectedEnd> for PacketDecodeError {
}

pub(crate) const LONG_HEADER_FORM: u8 = 0x80;
const FIXED_BIT: u8 = 0x40;
pub(crate) const FIXED_BIT: u8 = 0x40;
pub(crate) const SPIN_BIT: u8 = 0x20;
const SHORT_RESERVED_BITS: u8 = 0x18;
const LONG_RESERVED_BITS: u8 = 0x0c;
Expand Down

0 comments on commit e764386

Please sign in to comment.