Skip to content

Commit

Permalink
check of connection
Browse files Browse the repository at this point in the history
  • Loading branch information
ddeguglielmo committed Nov 21, 2023
1 parent 2861826 commit e499285
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
18 changes: 14 additions & 4 deletions dht-cache/src/domocache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use time::OffsetDateTime;
use tokio::sync::mpsc;
use tokio::sync::mpsc::{Receiver, Sender};
use crate::utils::get_epoch_ms;

use std::str::FromStr;
fn generate_rsa_key() -> (Vec<u8>, Vec<u8>) {
let mut rng = rand::thread_rng();
let bits = 2048;
Expand Down Expand Up @@ -419,7 +419,7 @@ impl DomoCache {
println!("Connection closed {peer_id:?}, {connection_id:?}, {endpoint:?} -> {cause:?}");
}
SwarmEvent::ListenerError { listener_id, error } => {
log::warn!("Listener Error {listener_id:?} -> {error:?}");
println!("Listener Error {listener_id:?} -> {error:?}");
}
SwarmEvent::OutgoingConnectionError { connection_id, peer_id, error } => {
println!("Outgoing connection error {peer_id:?}, {connection_id:?} -> {error:?}");
Expand All @@ -429,6 +429,15 @@ impl DomoCache {
}
SwarmEvent::NewListenAddr { address, .. } => {
println!("Listening in {address:?}");
/* if address.to_string().contains("10.44.89") {
if let Ok(wg_server_addr) = libp2p::Multiaddr::from_str("/ip4/10.44.89.1/tcp/4489") {
if let Ok(ret) = self.swarm.dial(wg_server_addr) {
println!("CONNECTED TO WG_SERVER");
} else {
println!("CONNECTION TO WG_SERVER FAILED");
}
}
}*/
}
SwarmEvent::Behaviour(crate::domolibp2p::OutEvent::Gossipsub(
libp2p::gossipsub::Event::Message {
Expand Down Expand Up @@ -459,8 +468,8 @@ impl DomoCache {
)) => {
let local = OffsetDateTime::now_utc();

for (peer, _) in list {
println!("MDNS for peer {peer} expired {local:?}");
for (peer, addr) in list {
println!("MDNS for peer {peer} expired {local:?} {}", addr);
self.swarm.behaviour_mut().gossipsub.remove_explicit_peer(&peer);
}
}
Expand All @@ -476,6 +485,7 @@ impl DomoCache {
log::info!("Skipping peer since it is not local");
continue;
}

self.swarm
.behaviour_mut()
.gossipsub
Expand Down
5 changes: 3 additions & 2 deletions dht-cache/src/domolibp2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ pub async fn start(
};

let gossipsub_config = gossipsub::ConfigBuilder::default()
.heartbeat_interval(Duration::from_secs(10)) // This is set to aid debugging by not cluttering the log space
.heartbeat_interval(Duration::from_secs(1))
.check_explicit_peers_ticks(5)// This is set to aid debugging by not cluttering the log space
.validation_mode(gossipsub::ValidationMode::Strict) // This sets the kind of message validation. The default is Strict (enforce message signing)
.message_id_fn(message_id_fn) // content-address messages. No two messages of the same content will be propagated.
.build()
Expand All @@ -130,7 +131,7 @@ pub async fn start(
Ok(behaviour)

})?
.with_swarm_config(|c| c.with_idle_connection_timeout(Duration::from_secs(1)))
.with_swarm_config(|c| c.with_idle_connection_timeout(Duration::from_secs(60)))
.build();


Expand Down

0 comments on commit e499285

Please sign in to comment.