Skip to content

Commit

Permalink
migrate to timed-map crate and remove expirable_map module (#26)
Browse files Browse the repository at this point in the history
Signed-off-by: onur-ozkan <[email protected]>
  • Loading branch information
onur-ozkan authored Oct 21, 2024
1 parent 3c191bb commit 88f4a38
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 179 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ serde = "1.0.137"
serde_json = { version = "1.0.81", features = ["preserve_order", "raw_value"] }
sha3 = "0.9"
simple_logger = "2.1.0"
timed-map = "0.1.0"
tokio = { version = "1.12.0", default-features = false, features = ["macros", "rt-multi-thread", "sync", "time"] }
tokio-tungstenite = { version = "0.20.0", features = ["native-tls"] }
# From our sources
Expand Down
174 changes: 0 additions & 174 deletions src/expirable_map.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use server::serve;
mod address_status;
mod ctx;
mod db;
mod expirable_map;
#[path = "security/jwt.rs"]
mod jwt;
#[path = "net/kdf_rpc_interface.rs"]
Expand Down
8 changes: 4 additions & 4 deletions src/proxy/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use hyper::{StatusCode, Uri};
use libp2p::PeerId;
use proxy_signature::ProxySign;
use std::{net::SocketAddr, str::FromStr, sync::LazyLock, time::Duration};
use timed_map::{StdClock, TimedMap};
use tokio::sync::Mutex;

use crate::{
address_status::{AddressStatus, AddressStatusOperations},
ctx::{AppConfig, ProxyRoute},
db::Db,
expirable_map::ExpirableMap,
kdf_rpc_interface::peer_connection_healthcheck_rpc,
logger::tracked_log,
rate_limiter::RateLimitOperations,
Expand Down Expand Up @@ -109,8 +109,8 @@ async fn peer_connection_healthcheck(
// for 10 seconds without asking again.
let know_peer_expiration = Duration::from_secs(cfg.peer_healthcheck_caching_secs);

static KNOWN_PEERS: LazyLock<Mutex<ExpirableMap<PeerId, ()>>> =
LazyLock::new(|| Mutex::new(ExpirableMap::new()));
static KNOWN_PEERS: LazyLock<Mutex<TimedMap<StdClock, PeerId, ()>>> =
LazyLock::new(|| Mutex::new(TimedMap::new()));

let mut know_peers = KNOWN_PEERS.lock().await;

Expand All @@ -134,7 +134,7 @@ async fn peer_connection_healthcheck(
match peer_connection_healthcheck_rpc(cfg, &signed_message.address).await {
Ok(response) => {
if response["result"] == serde_json::json!(true) {
know_peers.insert(peer_id, (), know_peer_expiration);
know_peers.insert_expirable(peer_id, (), know_peer_expiration);
} else {
tracked_log(
log::Level::Warn,
Expand Down

0 comments on commit 88f4a38

Please sign in to comment.