Skip to content

Commit 7225d42

Browse files
committed
Regularly broadcast node announcement
1 parent c1ad3d0 commit 7225d42

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/lib.rs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,12 @@ const BDK_CLIENT_CONCURRENCY: u8 = 8;
170170
// The timeout after which we abandon retrying failed payments.
171171
const LDK_PAYMENT_RETRY_TIMEOUT: Duration = Duration::from_secs(10);
172172

173-
// The time in between peer reconnection attempts.
173+
// The time in-between peer reconnection attempts.
174174
const PEER_RECONNECTION_INTERVAL: Duration = Duration::from_secs(10);
175175

176+
// The time in-between node announcement broadcast attempts.
177+
const NODE_ANN_BCAST_INTERVAL: Duration = Duration::from_secs(60 * 10);
178+
176179
// The length in bytes of our wallets' keys seed.
177180
const WALLET_KEYS_SEED_LEN: usize = 64;
178181

@@ -749,10 +752,13 @@ impl Node {
749752
let stop_connect = Arc::clone(&stop_running);
750753
runtime.spawn(async move {
751754
let mut interval = tokio::time::interval(PEER_RECONNECTION_INTERVAL);
755+
interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);
752756
loop {
753757
if stop_connect.load(Ordering::Acquire) {
754758
return;
755759
}
760+
761+
interval.tick().await;
756762
let pm_peers = connect_pm
757763
.get_peer_node_ids()
758764
.iter()
@@ -774,7 +780,33 @@ impl Node {
774780
.await;
775781
}
776782
}
777-
interval.tick().await;
783+
}
784+
});
785+
786+
// Regularly broadcast node announcements.
787+
let bcast_cm = Arc::clone(&self.channel_manager);
788+
let bcast_pm = Arc::clone(&self.peer_manager);
789+
let bcast_config = Arc::clone(&self.config);
790+
let stop_bcast = Arc::clone(&stop_running);
791+
runtime.spawn(async move {
792+
let mut interval = tokio::time::interval(NODE_ANN_BCAST_INTERVAL);
793+
loop {
794+
if stop_bcast.load(Ordering::Acquire) {
795+
return;
796+
}
797+
798+
if bcast_cm.list_channels().iter().any(|chan| chan.is_public) {
799+
interval.tick().await;
800+
801+
while bcast_pm.get_peer_node_ids().is_empty() {
802+
// Sleep a bit and retry if we don't have any peers yet.
803+
tokio::time::sleep(Duration::from_secs(5)).await;
804+
}
805+
806+
let addresses =
807+
bcast_config.listening_address.iter().cloned().map(|a| a.0).collect();
808+
bcast_pm.broadcast_node_announcement([0; 3], [0; 32], addresses);
809+
}
778810
}
779811
});
780812

src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ impl UniffiCustomTypeConverter for Txid {
282282
///
283283
/// Currently only IPv4, IPv6, and DNS hostnames are supported.
284284
#[derive(Debug, Clone, PartialEq, Eq)]
285-
pub struct NetAddress(LdkNetAddress);
285+
pub struct NetAddress(pub LdkNetAddress);
286286

287287
impl Display for NetAddress {
288288
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {

0 commit comments

Comments
 (0)