@@ -169,12 +169,15 @@ const BDK_CLIENT_CONCURRENCY: u8 = 8;
169169// The timeout after which we abandon retrying failed payments.
170170const LDK_PAYMENT_RETRY_TIMEOUT : Duration = Duration :: from_secs ( 10 ) ;
171171
172- // The time in between peer reconnection attempts.
172+ // The time in- between peer reconnection attempts.
173173const PEER_RECONNECTION_INTERVAL : Duration = Duration :: from_secs ( 10 ) ;
174174
175175// The time in-between RGS sync attempts.
176176const RGS_SYNC_INTERVAL : Duration = Duration :: from_secs ( 60 * 60 ) ;
177177
178+ // The time in-between node announcement broadcast attempts.
179+ const NODE_ANN_BCAST_INTERVAL : Duration = Duration :: from_secs ( 60 * 60 ) ;
180+
178181// The length in bytes of our wallets' keys seed.
179182const WALLET_KEYS_SEED_LEN : usize = 64 ;
180183
@@ -870,6 +873,7 @@ impl Node {
870873 let mut stop_connect = self . stop_receiver . clone ( ) ;
871874 runtime. spawn ( async move {
872875 let mut interval = tokio:: time:: interval ( PEER_RECONNECTION_INTERVAL ) ;
876+ interval. set_missed_tick_behavior ( tokio:: time:: MissedTickBehavior :: Skip ) ;
873877 loop {
874878 tokio:: select! {
875879 _ = stop_connect. changed( ) => {
@@ -902,6 +906,39 @@ impl Node {
902906 }
903907 } ) ;
904908
909+ // Regularly broadcast node announcements.
910+ let bcast_cm = Arc :: clone ( & self . channel_manager ) ;
911+ let bcast_pm = Arc :: clone ( & self . peer_manager ) ;
912+ let bcast_config = Arc :: clone ( & self . config ) ;
913+ let mut stop_bcast = self . stop_receiver . clone ( ) ;
914+ runtime. spawn ( async move {
915+ let mut interval = tokio:: time:: interval ( NODE_ANN_BCAST_INTERVAL ) ;
916+ loop {
917+ tokio:: select! {
918+ _ = stop_bcast. changed( ) => {
919+ return ;
920+ }
921+ _ = interval. tick( ) , if bcast_cm. list_channels( ) . iter( ) . any( |chan| chan. is_public) => {
922+ while bcast_pm. get_peer_node_ids( ) . is_empty( ) {
923+ // Sleep a bit and retry if we don't have any peers yet.
924+ tokio:: time:: sleep( Duration :: from_secs( 5 ) ) . await ;
925+
926+ // Check back if we need to stop.
927+ match stop_bcast. has_changed( ) {
928+ Ok ( false ) => { } ,
929+ Ok ( true ) => return ,
930+ Err ( _) => return ,
931+ }
932+ }
933+
934+ let addresses =
935+ bcast_config. listening_address. iter( ) . cloned( ) . map( |a| a. 0 ) . collect( ) ;
936+ bcast_pm. broadcast_node_announcement( [ 0 ; 3 ] , [ 0 ; 32 ] , addresses) ;
937+ }
938+ }
939+ }
940+ } ) ;
941+
905942 // Setup background processing
906943 let background_persister = Arc :: clone ( & self . kv_store ) ;
907944 let background_event_handler = Arc :: clone ( & event_handler) ;
0 commit comments