Skip to content

Commit

Permalink
Adds code comments
Browse files Browse the repository at this point in the history
  • Loading branch information
arya2 committed Nov 21, 2023
1 parent 120b6a5 commit 48f419e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion zebrad/src/components/inbound/cached_peer_addr_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{

use super::*;

/// The minumum duration that a `CachedPeerAddrResponse` is considered fresh before the inbound service
/// The minimum duration that a `CachedPeerAddrResponse` is considered fresh before the inbound service
/// 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.
Expand Down Expand Up @@ -68,6 +68,7 @@ impl CachedPeerAddrResponse {
self.value = zn::Response::Peers(peers);
}

// Clear the cached response if the time has past the cache expiry time.
Ok(_) if now > cache_expiry => {
self.value = zn::Response::Nil;
}
Expand All @@ -77,6 +78,8 @@ impl CachedPeerAddrResponse {
self.value = zn::Response::Nil;
}

// Don't update the cached response or refresh time if unable to get new peer addresses
// from the address book and `now` is before the cache expiry.
Ok(_) => {
debug!(
"could not refresh cached response because our address \
Expand All @@ -86,6 +89,7 @@ impl CachedPeerAddrResponse {

Err(TryLockError::WouldBlock) => {}

// Panic if the address book lock is poisoned
Err(TryLockError::Poisoned(_)) => {
panic!("previous thread panicked while holding the address book lock")
}
Expand Down

0 comments on commit 48f419e

Please sign in to comment.