This commit is contained in:
Christien Rioux
2023-09-02 18:50:12 -04:00
parent a77f80a8a9
commit b3354194e0
12 changed files with 70 additions and 161 deletions
+1 -1
View File
@@ -40,6 +40,6 @@ pub fn bytes_to_cache(bytes: &[u8], cache: &mut DHCache) {
let v = DHCacheValue {
shared_secret: SharedSecret::new(d[64..96].try_into().expect("asdf")),
};
cache.insert(k, v, |_k, _v| {});
cache.insert(k, v);
}
}
+4 -7
View File
@@ -310,13 +310,10 @@ impl Crypto {
secret: &SecretKey,
) -> VeilidAPIResult<SharedSecret> {
Ok(
match self.inner.lock().dh_cache.entry(
DHCacheKey {
key: *key,
secret: *secret,
},
|_k, _v| {},
) {
match self.inner.lock().dh_cache.entry(DHCacheKey {
key: *key,
secret: *secret,
}) {
Entry::Occupied(e) => e.get().shared_secret,
Entry::Vacant(e) => {
let shared_secret = vcrypto.compute_dh(key, secret)?;
@@ -168,9 +168,7 @@ impl ConnectionTable {
};
// Add the connection to the table
let res = inner.conn_by_id[protocol_index].insert(id, network_connection, |_k, _v| {
// never lrus, unbounded
});
let res = inner.conn_by_id[protocol_index].insert(id, network_connection);
assert!(res.is_none());
// if we have reached the maximum number of connections per protocol type
+2 -6
View File
@@ -454,9 +454,7 @@ impl NetworkManager {
pub fn update_client_whitelist(&self, client: TypedKey) {
let mut inner = self.inner.lock();
match inner.client_whitelist.entry(client, |_k, _v| {
// do nothing on LRU evict
}) {
match inner.client_whitelist.entry(client) {
hashlink::lru_cache::Entry::Occupied(mut entry) => {
entry.get_mut().last_seen_ts = get_aligned_timestamp()
}
@@ -472,9 +470,7 @@ impl NetworkManager {
pub fn check_client_whitelist(&self, client: TypedKey) -> bool {
let mut inner = self.inner.lock();
match inner.client_whitelist.entry(client, |_k, _v| {
// do nothing on LRU evict
}) {
match inner.client_whitelist.entry(client) {
hashlink::lru_cache::Entry::Occupied(mut entry) => {
entry.get_mut().last_seen_ts = get_aligned_timestamp();
true
+1 -1
View File
@@ -461,7 +461,7 @@ impl NetworkManager {
self.inner
.lock()
.node_contact_method_cache
.insert(ncm_key, ncm.clone(), |_, _| {});
.insert(ncm_key, ncm.clone());
Ok(ncm)
}
+2 -6
View File
@@ -45,9 +45,7 @@ impl NetworkManager {
inner
.stats
.per_address_stats
.entry(PerAddressStatsKey(addr), |_k, _v| {
// do nothing on LRU evict
})
.entry(PerAddressStatsKey(addr))
.or_insert(PerAddressStats::default())
.transfer_stats_accounting
.add_up(bytes);
@@ -63,9 +61,7 @@ impl NetworkManager {
inner
.stats
.per_address_stats
.entry(PerAddressStatsKey(addr), |_k, _v| {
// do nothing on LRU evict
})
.entry(PerAddressStatsKey(addr))
.or_insert(PerAddressStats::default())
.transfer_stats_accounting
.add_down(bytes);
@@ -117,9 +117,7 @@ impl NetworkManager {
.public_address_check_cache
.entry(addr_proto_type_key)
.or_insert_with(|| LruCache::new(PUBLIC_ADDRESS_CHECK_CACHE_SIZE));
pacc.insert(ipblock, socket_address, |_k, _v| {
// do nothing on LRU evict
});
pacc.insert(ipblock, socket_address);
// Determine if our external address has likely changed
let mut bad_public_address_detection_punishment: Option<
@@ -148,10 +148,13 @@ impl RouteSpecStoreCache {
}
let mut dead = None;
self.remote_private_route_set_cache
.insert(id, rprinfo, |dead_id, dead_rpri| {
self.remote_private_route_set_cache.insert_with_callback(
id,
rprinfo,
|dead_id, dead_rpri| {
dead = Some((dead_id, dead_rpri));
});
},
);
if let Some((dead_id, dead_rpri)) = dead {
// If anything LRUs out, remove from the by-key table
@@ -285,12 +288,7 @@ impl RouteSpecStoreCache {
pr_pubkey,
};
if let Some(v) = self
.compiled_route_cache
.insert(key, safety_route, |_k, _v| {
// Do nothing on LRU evict
})
{
if let Some(v) = self.compiled_route_cache.insert(key, safety_route) {
log_rtab!(error "route cache already contained key: sr_pubkey={:?}, pr_pubkey={:?}", v.public_key, pr_pubkey);
}
}
@@ -930,9 +930,7 @@ impl RoutingTableInner {
pub fn touch_recent_peer(&mut self, node_id: TypedKey, last_connection: ConnectionDescriptor) {
self.recent_peers
.insert(node_id, RecentPeersEntry { last_connection }, |_k, _v| {
// do nothing on lru eviction
});
.insert(node_id, RecentPeersEntry { last_connection });
}
//////////////////////////////////////////////////////////////////////
@@ -113,7 +113,7 @@ where
}
// add to index and ensure we deduplicate in the case of an error
if let Some(v) = self.record_index.insert(ri.0, ri.1, |k, v| {
if let Some(v) = self.record_index.insert_with_callback(ri.0, ri.1, |k, v| {
// If the configuration change, we only want to keep the 'limits.max_records' records
dead_records.push((k, v));
}) {
@@ -143,10 +143,13 @@ where
let record_data_total_size = record_data.total_size();
// Write to subkey cache
let mut dead_size = 0usize;
if let Some(old_record_data) = self.subkey_cache.insert(key, record_data, |_, v| {
// LRU out
dead_size += v.total_size();
}) {
if let Some(old_record_data) =
self.subkey_cache
.insert_with_callback(key, record_data, |_, v| {
// LRU out
dead_size += v.total_size();
})
{
// Old data
dead_size += old_record_data.total_size();
}
@@ -305,7 +308,7 @@ where
// Save to record index
let mut dead_records = Vec::new();
if let Some(v) = self.record_index.insert(rtk, record, |k, v| {
if let Some(v) = self.record_index.insert_with_callback(rtk, record, |k, v| {
dead_records.push((k, v));
}) {
// Shouldn't happen but log it