File tree Expand file tree Collapse file tree 2 files changed +9
-5
lines changed
Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Original file line number Diff line number Diff line change 22
33mod local;
44
5+ use std:: collections:: HashSet ;
56use std:: sync:: Arc ;
67use std:: { collections:: BTreeMap , time:: Duration } ;
78
@@ -301,6 +302,7 @@ pub fn cache_channel(
301302 let peers_state = peers_state. clone ( ) ;
302303 let peer_id = local_peer_id. clone ( ) ;
303304 let cmd = cmd. clone ( ) ;
305+ let mut ready_peers = HashSet :: new ( ) ;
304306 async move {
305307 match ev {
306308 DhtEvent :: Config ( cfg) => {
@@ -378,9 +380,10 @@ pub fn cache_channel(
378380 }
379381 }
380382 DhtEvent :: Ready ( peers) => {
381- if !peers. is_empty ( ) {
383+ if !peers. is_empty ( ) && peers != ready_peers {
384+ ready_peers = peers;
382385 Some ( Event :: ReadyPeers (
383- peers . into_iter ( ) . map ( |p| p. to_string ( ) ) . collect ( ) ) )
386+ ready_peers . into_iter ( ) . map ( |p| p. to_string ( ) ) . collect ( ) ) )
384387 } else {
385388 None
386389 }
Original file line number Diff line number Diff line change 11//! DHT Abstraction
22//!
33
4+ use std:: collections:: HashSet ;
45use std:: time:: Duration ;
56
67use crate :: domolibp2p:: { DomoBehaviour , OutEvent } ;
@@ -28,7 +29,7 @@ pub enum Event {
2829 VolatileData ( String ) ,
2930 Config ( String ) ,
3031 Discovered ( Vec < PeerId > ) ,
31- Ready ( Vec < PeerId > ) ,
32+ Ready ( HashSet < PeerId > ) ,
3233}
3334
3435fn handle_command ( swarm : & mut Swarm < DomoBehaviour > , cmd : Command ) -> bool {
@@ -177,7 +178,7 @@ pub fn dht_channel(
177178 . gossipsub
178179 . all_peers ( )
179180 . filter_map ( |( p, topics) | {
180- log:: info !( "{p}, {topics:?}" ) ;
181+ log:: debug !( "{p}, {topics:?}" ) ;
181182 ( topics. contains ( & & volatile)
182183 && topics. contains ( & & persistent)
183184 && topics. contains ( & & config) )
@@ -192,7 +193,7 @@ pub fn dht_channel(
192193 // the mdns event is not enough to ensure we can send messages
193194 _ = interval. tick( ) => {
194195 log:: debug!( "{} Checking for peers" , swarm. local_peer_id( ) ) ;
195- let peers: Vec <_> = check_peers( & mut swarm) ;
196+ let peers: HashSet <_> = check_peers( & mut swarm) ;
196197 if !peers. is_empty( ) &&
197198 ev_send. send( Event :: Ready ( peers) ) . is_err( ) {
198199 return swarm;
You can’t perform that action at this time.
0 commit comments