Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ddeguglielmo committed Nov 22, 2023
1 parent 057eb59 commit 2b8785d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions dht-cache/src/domocache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,8 @@ impl DomoCache {

pub fn remove_connections_of_peers(&mut self) {
for (peer_id, last_mdns_rec_timestamp) in self.mdns_peers_cache.iter() {
if last_mdns_rec_timestamp.to_owned() < (get_epoch_ms() - 20 * 1000) {

if last_mdns_rec_timestamp.to_owned() < (utils::get_epoch_ms() - 1000 * 10 as u128) {
if let Ok(peer_id) = PeerId::from_str(peer_id) {
if let Ok(_res) = self.swarm.disconnect_peer_id(peer_id) {
println!("DISCONNECTING LOCAL CONNECTIONS TO {peer_id}");
Expand Down Expand Up @@ -469,7 +470,7 @@ impl DomoCache {
SwarmEvent::Behaviour(crate::domolibp2p::OutEvent::Mdns(
mdns::Event::Expired(_list),
)) => {
self.remove_connections_of_peers();
println!("MDNS TTL Expired");
}
SwarmEvent::Behaviour(crate::domolibp2p::OutEvent::Mdns(
mdns::Event::Discovered(list),
Expand All @@ -486,7 +487,10 @@ impl DomoCache {

let dial_opts = DialOpts::from(peer_id);
let _res = self.swarm.dial(dial_opts);
println!("INSERT INTO MDNS CACHE {} {} ", peer_id.to_string(), get_epoch_ms());

self.mdns_peers_cache.insert(peer_id.to_string(), get_epoch_ms());
println!("{:?}", self.mdns_peers_cache);

// self.swarm
// .behaviour_mut()
Expand All @@ -513,6 +517,7 @@ impl DomoCache {
self.send_cache_state_timer = tokio::time::Instant::now()
+ Duration::from_secs(u64::from(SEND_CACHE_HASH_PERIOD));
self.send_cache_state().await;
self.remove_connections_of_peers();
}
PersistentData(data) => {
return self.handle_persistent_message_data(&data).await;
Expand Down

0 comments on commit 2b8785d

Please sign in to comment.