Skip to content

Commit

Permalink
uses longer cache expiry time
Browse files Browse the repository at this point in the history
  • Loading branch information
arya2 committed Nov 20, 2023
1 parent f902adb commit 120b6a5
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions zebrad/src/components/inbound/cached_peer_addr_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ use std::{

use super::*;

/// The maximum duration that a `CachedPeerAddrResponse` is considered fresh before the inbound service
/// The minumum duration that a `CachedPeerAddrResponse` is considered fresh before the inbound service

Check warning on line 12 in zebrad/src/components/inbound/cached_peer_addr_response.rs

View workflow job for this annotation

GitHub Actions / codespell

[codespell] zebrad/src/components/inbound/cached_peer_addr_response.rs#L12

minumum ==> minimum
Raw output
./zebrad/src/components/inbound/cached_peer_addr_response.rs:12: minumum ==> minimum
/// should get new peer addresses from the address book to send as a `GetAddr` response.
///
/// Cached responses are considered stale and should be cleared after twice this duration.
pub const CACHED_ADDRS_REFRESH_INTERVAL: Duration = Duration::from_secs(10 * 60);

/// The maximum duration that a `CachedPeerAddrResponse` is considered fresh after the normal refresh time
/// before it should return `Response::Nil` until it can get new peer addresses from the address book.
const INBOUND_CACHED_ADDRS_MAX_FRESH_DURATION: Duration = Duration::from_secs(60);

/// Caches and refreshes a partial list of peer addresses to be returned as a `GetAddr` response.
pub struct CachedPeerAddrResponse {
/// A shared list of peer addresses.
Expand Down Expand Up @@ -52,7 +50,7 @@ impl CachedPeerAddrResponse {
return;
}

let max_fresh_time = self.refresh_time + INBOUND_CACHED_ADDRS_MAX_FRESH_DURATION;
let cache_expiry = self.refresh_time + CACHED_ADDRS_REFRESH_INTERVAL;

// try getting a lock on the address book if it's time to refresh the cached addresses
match self
Expand All @@ -70,11 +68,11 @@ impl CachedPeerAddrResponse {
self.value = zn::Response::Peers(peers);
}

Ok(_) if now > max_fresh_time => {
Ok(_) if now > cache_expiry => {
self.value = zn::Response::Nil;
}

Err(TryLockError::WouldBlock) if now > max_fresh_time => {
Err(TryLockError::WouldBlock) if now > cache_expiry => {
warn!("getaddrs response hasn't been refreshed in some time");
self.value = zn::Response::Nil;
}
Expand Down

0 comments on commit 120b6a5

Please sign in to comment.