Skip to content

Commit

Permalink
Add non-zero defaults
Browse files Browse the repository at this point in the history
128 for clients, this will help a bit but not have much mem use
1024 * 1024 for servers, this will consume 32 mb and work up to 1 mil connections
  • Loading branch information
rklaehn committed Dec 16, 2024
1 parent d8db535 commit 015b28a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion iroh-relay/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ impl ClientBuilder {
#[cfg(any(test, feature = "test-utils"))]
insecure_skip_cert_verify: false,
proxy_url: None,
key_cache_capacity: 0,
key_cache_capacity: 128,
}
}

Expand Down
11 changes: 9 additions & 2 deletions iroh-relay/src/key_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ type SignatureError = <PublicKey as TryFrom<&'static [u8]>>::Error;
type PublicKeyBytes = [u8; PublicKey::LENGTH];

/// A cache for public keys.
#[derive(Debug, Clone, Default)]
///
/// This is used solely to make parsing public keys from byte slices more
/// efficient for the very common case where a large number of identical keys
/// are being parsed, like in the relay server.
///
/// The cache stores only successful parse results.
#[derive(Debug, Clone)]
pub enum KeyCache {
/// The key cache is disabled.
#[default]
Disabled,
/// The key cache is enabled with a fixed capacity. It is shared between
/// multiple threads.
Expand Down Expand Up @@ -43,6 +48,8 @@ impl KeyCache {
return PublicKey::try_from(slice);
};
let Ok(bytes) = PublicKeyBytes::try_from(slice) else {
// if the size is wrong, use PublicKey::try_from to fail with a
// SignatureError.
PublicKey::try_from(slice)?;
unreachable!();
};
Expand Down
2 changes: 1 addition & 1 deletion iroh-relay/src/server/http_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl ServerBuilder {
handlers: Default::default(),
headers: HeaderMap::new(),
client_rx_ratelimit: None,
key_cache_capacity: 0,
key_cache_capacity: 1024 * 1024,
}
}

Expand Down

0 comments on commit 015b28a

Please sign in to comment.