From acd10995c7acef354cf1fbbeb9515c3840d13c58 Mon Sep 17 00:00:00 2001 From: Domenico De Guglielmo Date: Thu, 23 Nov 2023 15:06:41 +0100 Subject: [PATCH] dial always --- dht-cache/Cargo.toml | 2 +- dht-cache/src/domocache.rs | 7 +++++-- dht-cache/src/domolibp2p.rs | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/dht-cache/Cargo.toml b/dht-cache/Cargo.toml index ece9744..bf6d04f 100644 --- a/dht-cache/Cargo.toml +++ b/dht-cache/Cargo.toml @@ -13,7 +13,7 @@ async-trait = "0.1.68" futures = "0.3.21" futures-util = "0.3.29" jsonpath_lib = "0.3.0" -libp2p = { version="0.53.1", features = ["tokio", "mdns", "gossipsub", "noise", "ping", "yamux", "pnet", "rsa", "tcp", "macros"] } +libp2p = { git="https://github.com/libp2p/rust-libp2p.git", rev = "add1ff6e50b335f2c8cacdb9e0f4dba90ad22f3b" ,features = ["tokio", "mdns", "gossipsub", "noise", "ping", "yamux", "pnet", "rsa", "tcp", "macros"] } log = "0.4.17" rand = "0.8" sea-query = "0.28.3" diff --git a/dht-cache/src/domocache.rs b/dht-cache/src/domocache.rs index 9a719b6..2603018 100644 --- a/dht-cache/src/domocache.rs +++ b/dht-cache/src/domocache.rs @@ -20,7 +20,7 @@ use time::OffsetDateTime; use tokio::sync::mpsc; use tokio::sync::mpsc::{Receiver, Sender}; use crate::utils::get_epoch_ms; -use libp2p::swarm::dial_opts::DialOpts; +use libp2p::swarm::dial_opts::{DialOpts, PeerCondition}; fn generate_rsa_key() -> (Vec, Vec) { let mut rng = rand::thread_rng(); @@ -477,7 +477,10 @@ impl DomoCache { continue; } - let dial_opts = DialOpts::from(peer_id); + let dial_opts = DialOpts::peer_id(peer_id) + .condition(PeerCondition::Always) + .build(); + let _res = self.swarm.dial(dial_opts); println!("INSERT INTO MDNS CACHE {} {} ", peer_id.to_string(), get_epoch_ms()/1000); diff --git a/dht-cache/src/domolibp2p.rs b/dht-cache/src/domolibp2p.rs index 8d783ab..7c57990 100644 --- a/dht-cache/src/domolibp2p.rs +++ b/dht-cache/src/domolibp2p.rs @@ -127,7 +127,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(10))) .build();