Skip to content

Commit

Permalink
address review
Browse files Browse the repository at this point in the history
  • Loading branch information
jxs committed Oct 20, 2023
1 parent 1220543 commit a77fdcf
Show file tree
Hide file tree
Showing 3 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 @@ -40,7 +40,7 @@ more-asserts = "0.3"

[dev-dependencies]
rand_07 = { package = "rand", version = "0.7" }
quickcheck = "1"
quickcheck = "0.9"
tokio = { version = "1", features = ["full"] }
rand_xorshift = "0.3"
rand_core = "0.6"
Expand Down
2 changes: 1 addition & 1 deletion src/handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ impl Handler {
trace!("Request queued for node: {}", node_address);
self.pending_requests
.entry(node_address)
.or_insert_with(Vec::new)
.or_default()
.push(PendingRequest {
contact,
request_id,
Expand Down
16 changes: 12 additions & 4 deletions src/socket/filter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::{
collections::HashSet,
convert::TryInto,
net::{IpAddr, SocketAddr},
num::NonZeroUsize,
sync::atomic::Ordering,
time::{Duration, Instant},
};
Expand All @@ -20,9 +21,16 @@ pub use config::FilterConfig;
use rate_limiter::{LimitKind, RateLimiter};

/// The maximum number of IPs to retain when calculating the number of nodes per IP.
const KNOWN_ADDRS_SIZE: usize = 500;
const KNOWN_ADDRS_SIZE: NonZeroUsize = match NonZeroUsize::new(500) {
Some(non_zero) => non_zero,
None => unreachable!(),
};
/// The number of IPs to retain at any given time that have banned nodes.
const BANNED_NODES_SIZE: usize = 50;
const BANNED_NODES_SIZE: NonZeroUsize = match NonZeroUsize::new(50) {
Some(non_zero) => non_zero,
None => unreachable!(),
};

/// The maximum number of packets to keep record of for metrics if the rate limiter is not
/// specified.
const DEFAULT_PACKETS_PER_SECOND: usize = 20;
Expand Down Expand Up @@ -68,8 +76,8 @@ impl Filter {
expected_packets_per_second,
METRICS.moving_window,
),
known_addrs: LruCache::new(KNOWN_ADDRS_SIZE.try_into().unwrap()),
banned_nodes: LruCache::new(BANNED_NODES_SIZE.try_into().unwrap()),
known_addrs: LruCache::new(KNOWN_ADDRS_SIZE),
banned_nodes: LruCache::new(BANNED_NODES_SIZE),
ban_duration,
max_nodes_per_ip: config.max_nodes_per_ip,
max_bans_per_ip: config.max_bans_per_ip,
Expand Down

0 comments on commit a77fdcf

Please sign in to comment.