@@ -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
@@ -852,10 +855,13 @@ impl Node {
852
855
let stop_connect = Arc :: clone ( & stop_running) ;
853
856
runtime. spawn ( async move {
854
857
let mut interval = tokio:: time:: interval ( PEER_RECONNECTION_INTERVAL ) ;
858
+ interval. set_missed_tick_behavior ( tokio:: time:: MissedTickBehavior :: Skip ) ;
855
859
loop {
856
860
if stop_connect. load ( Ordering :: Acquire ) {
857
861
return ;
858
862
}
863
+
864
+ interval. tick ( ) . await ;
859
865
let pm_peers = connect_pm
860
866
. get_peer_node_ids ( )
861
867
. iter ( )
@@ -877,7 +883,33 @@ impl Node {
877
883
. await ;
878
884
}
879
885
}
880
- interval. tick ( ) . await ;
886
+ }
887
+ } ) ;
888
+
889
+ // Regularly broadcast node announcements.
890
+ let bcast_cm = Arc :: clone ( & self . channel_manager ) ;
891
+ let bcast_pm = Arc :: clone ( & self . peer_manager ) ;
892
+ let bcast_config = Arc :: clone ( & self . config ) ;
893
+ let stop_bcast = Arc :: clone ( & stop_running) ;
894
+ runtime. spawn ( async move {
895
+ let mut interval = tokio:: time:: interval ( NODE_ANN_BCAST_INTERVAL ) ;
896
+ loop {
897
+ if stop_bcast. load ( Ordering :: Acquire ) {
898
+ return ;
899
+ }
900
+
901
+ if bcast_cm. list_channels ( ) . iter ( ) . any ( |chan| chan. is_public ) {
902
+ interval. tick ( ) . await ;
903
+
904
+ while bcast_pm. get_peer_node_ids ( ) . is_empty ( ) {
905
+ // Sleep a bit and retry if we don't have any peers yet.
906
+ tokio:: time:: sleep ( Duration :: from_secs ( 5 ) ) . await ;
907
+ }
908
+
909
+ let addresses =
910
+ bcast_config. listening_address . iter ( ) . cloned ( ) . map ( |a| a. 0 ) . collect ( ) ;
911
+ bcast_pm. broadcast_node_announcement ( [ 0 ; 3 ] , [ 0 ; 32 ] , addresses) ;
912
+ }
881
913
}
882
914
} ) ;
883
915
0 commit comments