@@ -169,9 +169,12 @@ const BDK_CLIENT_CONCURRENCY: u8 = 8;
169
169
// The timeout after which we abandon retrying failed payments.
170
170
const LDK_PAYMENT_RETRY_TIMEOUT : Duration = Duration :: from_secs ( 10 ) ;
171
171
172
- // The time in between peer reconnection attempts.
172
+ // The time in- between peer reconnection attempts.
173
173
const PEER_RECONNECTION_INTERVAL : Duration = Duration :: from_secs ( 10 ) ;
174
174
175
+ // The time in-between node announcement broadcast attempts.
176
+ const NODE_ANN_BCAST_INTERVAL : Duration = Duration :: from_secs ( 60 * 10 ) ;
177
+
175
178
// The length in bytes of our wallets' keys seed.
176
179
const WALLET_KEYS_SEED_LEN : usize = 64 ;
177
180
@@ -748,10 +751,13 @@ impl Node {
748
751
let stop_connect = Arc :: clone ( & stop_running) ;
749
752
runtime. spawn ( async move {
750
753
let mut interval = tokio:: time:: interval ( PEER_RECONNECTION_INTERVAL ) ;
754
+ interval. set_missed_tick_behavior ( tokio:: time:: MissedTickBehavior :: Skip ) ;
751
755
loop {
752
756
if stop_connect. load ( Ordering :: Acquire ) {
753
757
return ;
754
758
}
759
+
760
+ interval. tick ( ) . await ;
755
761
let pm_peers = connect_pm
756
762
. get_peer_node_ids ( )
757
763
. iter ( )
@@ -773,7 +779,33 @@ impl Node {
773
779
. await ;
774
780
}
775
781
}
776
- interval. tick ( ) . await ;
782
+ }
783
+ } ) ;
784
+
785
+ // Regularly broadcast node announcements.
786
+ let bcast_cm = Arc :: clone ( & self . channel_manager ) ;
787
+ let bcast_pm = Arc :: clone ( & self . peer_manager ) ;
788
+ let bcast_config = Arc :: clone ( & self . config ) ;
789
+ let stop_bcast = Arc :: clone ( & stop_running) ;
790
+ runtime. spawn ( async move {
791
+ let mut interval = tokio:: time:: interval ( NODE_ANN_BCAST_INTERVAL ) ;
792
+ loop {
793
+ if stop_bcast. load ( Ordering :: Acquire ) {
794
+ return ;
795
+ }
796
+
797
+ if bcast_cm. list_channels ( ) . iter ( ) . any ( |chan| chan. is_public ) {
798
+ interval. tick ( ) . await ;
799
+
800
+ while bcast_pm. get_peer_node_ids ( ) . is_empty ( ) {
801
+ // Sleep a bit and retry if we don't have any peers yet.
802
+ tokio:: time:: sleep ( Duration :: from_secs ( 5 ) ) . await ;
803
+ }
804
+
805
+ let addresses =
806
+ bcast_config. listening_address . iter ( ) . cloned ( ) . map ( |a| a. 0 ) . collect ( ) ;
807
+ bcast_pm. broadcast_node_announcement ( [ 0 ; 3 ] , [ 0 ; 32 ] , addresses) ;
808
+ }
777
809
}
778
810
} ) ;
779
811
0 commit comments