Skip to content

Commit

Permalink
Replace the hashlru crate with the lru crate
Browse files Browse the repository at this point in the history
  • Loading branch information
iyangsj committed Jul 15, 2024
1 parent 8e08afb commit b827177
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ strum = "0.24"
strum_macros = "0.24"
rand = "0.8.5"
smallvec = { version = "1.10", features = ["serde", "union"] }
hashlru = "0.11"
lru = "0.12"
serde = { version = "1.0.139", features = ["derive"] }
serde_json = { version = "1.0", features = ["preserve_order"] }
serde_derive = "1.0"
Expand Down
1 change: 1 addition & 0 deletions include/tquic.h
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ void quic_config_set_send_batch_size(struct quic_config_t *config, uint16_t v);

/**
* Set the buffer size for disordered zerortt packets on the server.
* The default value is `1000`. A value of 0 will be treated as default value.
* Applicable to Server only.
*/
void quic_config_set_zerortt_buffer_size(struct quic_config_t *config, uint16_t v);
Expand Down
9 changes: 5 additions & 4 deletions src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1001,13 +1001,14 @@ const MAX_ZERORTT_PACKETS_PER_CONN: usize = 10;
/// PacketBuffer is used for buffering early incoming ZeroRTT packets on the server.
/// Buffered packets are indexed by odcid.
struct PacketBuffer {
packets: hashlru::Cache<ConnectionId, Vec<(Vec<u8>, PacketInfo)>>,
packets: lru::LruCache<ConnectionId, Vec<(Vec<u8>, PacketInfo)>>,
}

impl PacketBuffer {
fn new(cache_size: usize) -> Self {
let size = std::num::NonZeroUsize::new(cache_size).unwrap();
Self {
packets: hashlru::Cache::new(cache_size / MAX_ZERORTT_PACKETS_PER_CONN),
packets: lru::LruCache::new(size),
}
}

Expand All @@ -1022,12 +1023,12 @@ impl PacketBuffer {

let mut v = Vec::with_capacity(MAX_ZERORTT_PACKETS_PER_CONN);
v.push((buffer, info));
self.packets.insert(dcid, v);
self.packets.put(dcid, v);
}

/// Remove all packets for the specified connection
fn del(&mut self, dcid: &ConnectionId) -> Option<Vec<(Vec<u8>, PacketInfo)>> {
self.packets.remove(dcid)
self.packets.pop(dcid)
}
}

Expand Down
1 change: 1 addition & 0 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ pub extern "C" fn quic_config_set_send_batch_size(config: &mut Config, v: u16) {
}

/// Set the buffer size for disordered zerortt packets on the server.
/// The default value is `1000`. A value of 0 will be treated as default value.
/// Applicable to Server only.
#[no_mangle]
pub extern "C" fn quic_config_set_zerortt_buffer_size(config: &mut Config, v: u16) {
Expand Down
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,9 +685,14 @@ impl Config {
}

/// Set the buffer size for disordered zerortt packets on the server.
/// The default value is `1000`. A value of 0 will be treated as default value.
/// Applicable to Server only.
pub fn set_zerortt_buffer_size(&mut self, v: usize) {
self.zerortt_buffer_size = v;
if v > 0 {
self.zerortt_buffer_size = v;
} else {
self.zerortt_buffer_size = 1000;
}
}

/// Set TLS config.
Expand Down

0 comments on commit b827177

Please sign in to comment.