Skip to content

Commit

Permalink
Add TokenMemoryCache
Browse files Browse the repository at this point in the history
The default TokenStore changes from None to a TokenMemoryCache.
  • Loading branch information
gretchenfrage committed Nov 30, 2024
1 parent d77379d commit 7422ca1
Show file tree
Hide file tree
Showing 4 changed files with 506 additions and 7 deletions.
11 changes: 7 additions & 4 deletions quinn-proto/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use crate::{
cid_generator::{ConnectionIdGenerator, HashedConnectionIdGenerator},
crypto::{self, HandshakeTokenKey, HmacKey},
shared::ConnectionId,
Duration, RandomConnectionIdGenerator, TokenLog, TokenStore, VarInt, VarIntBoundsExceeded,
DEFAULT_SUPPORTED_VERSIONS, MAX_CID_SIZE,
Duration, RandomConnectionIdGenerator, TokenLog, TokenMemoryCache, TokenStore, VarInt,
VarIntBoundsExceeded, DEFAULT_SUPPORTED_VERSIONS, MAX_CID_SIZE,
};

mod transport;
Expand Down Expand Up @@ -475,7 +475,7 @@ impl ClientConfig {
Self {
transport: Default::default(),
crypto,
token_store: None,
token_store: Some(Arc::new(TokenMemoryCache::<2>::default())),
initial_dst_cid_provider: Arc::new(|| {
RandomConnectionIdGenerator::new(MAX_CID_SIZE).generate_cid()
}),
Expand Down Expand Up @@ -507,7 +507,10 @@ impl ClientConfig {

/// Set a custom [`TokenStore`]
///
/// Defaults to `None`.
/// Defaults to a [`TokenMemoryCache`] limited to 256 servers and 2 tokens per server. This
/// default is chosen to complement `rustls`'s default [`ClientSessionStore`].
///
/// [`ClientSessionStore`]: rustls::client::ClientSessionStore
///
/// Setting to `None` disables the use of tokens from NEW_TOKEN frames as a client.
pub fn token_store(&mut self, store: Option<Arc<dyn TokenStore>>) -> &mut Self {
Expand Down
2 changes: 1 addition & 1 deletion quinn-proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ use token::{ResetToken, Token};
pub use token::{TokenLog, TokenReuseError};

mod token_store;
pub use token_store::TokenStore;
pub use token_store::{TokenMemoryCache, TokenStore};

#[cfg(feature = "fastbloom")]
mod bloom_token_log;
Expand Down
Loading

0 comments on commit 7422ca1

Please sign in to comment.