Skip to content

Commit

Permalink
feat: パケットを読み込みおわったら破棄するようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
megumish committed Sep 5, 2022
1 parent d62665c commit 313011c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion crates/refuic-endpoint/src/crypto_kit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ impl CryptoKit {
self.client_server_names = Vec::new();
return Ok(());
}
Err(NegotiationError::NoCertificateServerName)
// client_server_names が空の場合は空の文字列を詰めておく
self.server_name = Some(b"".to_vec());
Ok(())
}
pub(crate) fn is_negotiated_server_name(&self) -> bool {
self.client_server_names.is_empty() && self.server_name.is_some()
Expand Down
4 changes: 2 additions & 2 deletions crates/refuic-endpoint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ where
unimplemented!("recv no support version packet")
}
Err(e) => return Err(e).map_err(Into::into),
Ok(packet_length) => {
Ok(_) => {
// bufを消費して次のパケットに進む
let _ = buf.drain(..packet_length);
buf = Vec::new();
continue;
}
}
Expand Down
8 changes: 6 additions & 2 deletions crates/refuic-frame/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ pub enum FrameRfc9000 {
impl FrameRfc9000 {
pub fn to_vec(&self) -> Vec<u8> {
match self {
Self::Padding => vec![0x00],
Self::Ping => vec![0x01],
Self::Crypto(f) => {
let frame_type = VarInt::try_new(6).unwrap();
[frame_type.to_vec(), f.to_vec()].concat()
Expand All @@ -64,6 +66,8 @@ impl FrameRfc9000 {

pub fn vec_len(&self) -> usize {
match self {
Self::Padding => 1,
Self::Ping => 1,
Self::Crypto(f) => {
let frame_type = VarInt::try_new(6).unwrap();
frame_type.len() + f.vec_len()
Expand All @@ -72,7 +76,6 @@ impl FrameRfc9000 {
let frame_type = f.frame_type();
frame_type.len() + f.vec_len()
}
Self::Padding => 1,
_ => unimplemented!(),
}
}
Expand All @@ -86,8 +89,9 @@ pub fn parse_from_bytes_v1(bytes: &[u8]) -> Result<Vec<FrameRfc9000>, ParseFrame
while sum_of_length < length {
let frame_type = input.read_var_int()?;
let frame = match frame_type.u64() {
6 => FrameRfc9000::Crypto(read_crypto_frame(&mut input)?),
0 => FrameRfc9000::Padding,
1 => FrameRfc9000::Ping,
6 => FrameRfc9000::Crypto(read_crypto_frame(&mut input)?),
_ => unimplemented!(),
};
sum_of_length += frame_type.len() + frame.vec_len();
Expand Down

0 comments on commit 313011c

Please sign in to comment.