Skip to content

Commit

Permalink
Stricter request limits on node
Browse files Browse the repository at this point in the history
  • Loading branch information
keyvank committed Jul 13, 2023
1 parent 2071de0 commit 7d768b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ async fn run_node<K: KvStore, B: Blockchain<K>>(

let bootstrap_nodes = bazuka_config.bootstrap.clone();

// 60 request per minute / 4GB per 15min
let firewall = Firewall::new(360, 4 * GB);
// (10 request, 100MB) per minute
let firewall = Firewall::new(10, 100 * MB);

// Async loop that is responsible for answering external requests and gathering
// data from external world through a heartbeat loop.
Expand Down
10 changes: 5 additions & 5 deletions src/node/firewall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ pub struct Firewall {
request_count_last_reset: Timestamp,
request_count: HashMap<IpAddr, usize>,

traffic_limit_per_15m: u64,
traffic_limit_per_minute: u64,
traffic_last_reset: Timestamp,
traffic: HashMap<IpAddr, u64>,
}

impl Firewall {
pub fn new(request_count_limit_per_minute: usize, traffic_limit_per_15m: u64) -> Self {
pub fn new(request_count_limit_per_minute: usize, traffic_limit_per_minute: u64) -> Self {
Self {
request_count_limit_per_minute,
traffic_limit_per_15m,
traffic_limit_per_minute,
request_count_last_reset: 0,
request_count: HashMap::new(),
traffic_last_reset: 0,
Expand All @@ -27,7 +27,7 @@ impl Firewall {
self.request_count_last_reset = now;
}

if now.saturating_sub(self.traffic_last_reset) > 900 {
if now.saturating_sub(self.traffic_last_reset) > 60 {
self.traffic.clear();
self.traffic_last_reset = now;
}
Expand All @@ -41,7 +41,7 @@ impl Firewall {
return true;
}

if self.traffic.get(&client.ip()).cloned().unwrap_or(0) > self.traffic_limit_per_15m {
if self.traffic.get(&client.ip()).cloned().unwrap_or(0) > self.traffic_limit_per_minute {
return false;
}

Expand Down

0 comments on commit 7d768b4

Please sign in to comment.