Skip to content

Commit

Permalink
--amend
Browse files Browse the repository at this point in the history
  • Loading branch information
manforowicz committed Mar 26, 2024
1 parent bc3462a commit 12961f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[workspace]
edition = "2021"
resolver = "2"

members = [
Expand Down
17 changes: 14 additions & 3 deletions gday_server/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ impl State {
let mut interval = tokio::time::interval(Duration::from_secs(60));
loop {
interval.tick().await;
cloned_self.request_counts.lock().expect("Couldn't acquire state lock.").clear();
cloned_self
.request_counts
.lock()
.expect("Couldn't acquire state lock.")
.clear();
}
});

Expand All @@ -110,7 +114,11 @@ impl State {
let cloned_self = self.clone();
tokio::spawn(async move {
tokio::time::sleep(timeout).await;
cloned_self.rooms.lock().expect("Couldn't acquire state lock.").remove(&room_code);
cloned_self
.rooms
.lock()
.expect("Couldn't acquire state lock.")
.remove(&room_code);
});

Ok(room_code)
Expand Down Expand Up @@ -202,7 +210,10 @@ impl State {
/// Returns a [`Error::TooManyRequests`] if [`State::max_requests_per_minute`]
/// is exceeded.
fn increment_request_count(&mut self, ip: IpAddr) -> Result<(), Error> {
let mut request_counts = self.request_counts.lock().expect("Couldn't acquire state lock.");
let mut request_counts = self
.request_counts
.lock()
.expect("Couldn't acquire state lock.");
let conns_count = request_counts.entry(ip).or_insert(0);

if *conns_count > *self.max_requests_per_minute {
Expand Down

0 comments on commit 12961f0

Please sign in to comment.