Skip to content

Commit

Permalink
Rename Cache to PeerCache
Browse files Browse the repository at this point in the history
  • Loading branch information
vicsn committed Dec 6, 2023
1 parent d801f38 commit a96627d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions node/bft/src/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use crate::{
events::{EventCodec, PrimaryPing},
helpers::{assign_to_worker, Cache, PrimarySender, Resolver, SyncSender, WorkerSender},
helpers::{assign_to_worker, PeerCache, PrimarySender, Resolver, SyncSender, WorkerSender},
spawn_blocking,
CONTEXT,
MAX_BATCH_DELAY_IN_MS,
Expand Down Expand Up @@ -104,7 +104,7 @@ pub struct Gateway<N: Network> {
/// The TCP stack.
tcp: Tcp,
/// The cache.
cache: Arc<Cache<N>>,
cache: Arc<PeerCache<N>>,
/// The resolver.
resolver: Arc<Resolver<N>>,
/// The set of trusted validators.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::{
use time::OffsetDateTime;

#[derive(Debug)]
pub struct Cache<N: Network> {
pub struct PeerCache<N: Network> {
/// The ordered timestamp map of peer connections and cache hits.
seen_inbound_connections: RwLock<BTreeMap<i64, HashMap<IpAddr, u32>>>,
/// The ordered timestamp map of peer IPs and cache hits.
Expand All @@ -42,14 +42,14 @@ pub struct Cache<N: Network> {
seen_outbound_validators_requests: RwLock<HashMap<SocketAddr, u32>>,
}

impl<N: Network> Default for Cache<N> {
impl<N: Network> Default for PeerCache<N> {
/// Initializes a new instance of the cache.
fn default() -> Self {
Self::new()
}
}

impl<N: Network> Cache<N> {
impl<N: Network> PeerCache<N> {
/// Initializes a new instance of the cache.
pub fn new() -> Self {
Self {
Expand All @@ -65,7 +65,7 @@ impl<N: Network> Cache<N> {
}
}

impl<N: Network> Cache<N> {
impl<N: Network> PeerCache<N> {
/// Inserts a new timestamp for the given peer connection, returning the number of recent connection requests.
pub fn insert_inbound_connection(&self, peer_ip: IpAddr, interval_in_secs: i64) -> usize {
Self::retain_and_insert(&self.seen_inbound_connections, peer_ip, interval_in_secs)
Expand All @@ -87,7 +87,7 @@ impl<N: Network> Cache<N> {
}
}

impl<N: Network> Cache<N> {
impl<N: Network> PeerCache<N> {
/// Inserts a new timestamp for the given peer, returning the number of recent events.
pub fn insert_outbound_event(&self, peer_ip: SocketAddr, interval_in_secs: i64) -> usize {
Self::retain_and_insert(&self.seen_outbound_events, peer_ip, interval_in_secs)
Expand All @@ -104,7 +104,7 @@ impl<N: Network> Cache<N> {
}
}

impl<N: Network> Cache<N> {
impl<N: Network> PeerCache<N> {
/// Returns `true` if the cache contains a validators request from the given IP.
pub fn contains_outbound_validators_request(&self, peer_ip: SocketAddr) -> bool {
self.seen_outbound_validators_requests.read().get(&peer_ip).map(|r| *r > 0).unwrap_or(false)
Expand All @@ -121,7 +121,7 @@ impl<N: Network> Cache<N> {
}
}

impl<N: Network> Cache<N> {
impl<N: Network> PeerCache<N> {
/// Insert a new timestamp for the given key, returning the number of recent entries.
fn retain_and_insert<K: Copy + Clone + PartialEq + Eq + Hash>(
map: &RwLock<BTreeMap<i64, HashMap<K, u32>>>,
Expand Down Expand Up @@ -233,7 +233,7 @@ mod tests {
paste::paste! {
#[test]
fn [<test_seen_ $name s>]() {
let cache = Cache::<CurrentNetwork>::default();
let cache = PeerCache::<CurrentNetwork>::default();
let input = Input::input();

// Check that the cache is empty.
Expand Down
4 changes: 2 additions & 2 deletions node/bft/src/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

pub mod cache;
pub use cache::*;
pub mod cache_peer;
pub use cache_peer::*;

pub mod cache_round;
pub use cache_round::*;
Expand Down

0 comments on commit a96627d

Please sign in to comment.