Skip to content

Commit 5c35993

Browse files
committed
Regularly broadcast node announcement
1 parent 3f9d68e commit 5c35993

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
@@ -169,9 +169,12 @@ const BDK_CLIENT_CONCURRENCY: u8 = 8;
169169
// The timeout after which we abandon retrying failed payments.
170170
const 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.
173173
const PEER_RECONNECTION_INTERVAL: Duration = Duration::from_secs(10);
174174

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

@@ -748,10 +751,13 @@ impl Node {
748751
let stop_connect = Arc::clone(&stop_running);
749752
runtime.spawn(async move {
750753
let mut interval = tokio::time::interval(PEER_RECONNECTION_INTERVAL);
754+
interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);
751755
loop {
752756
if stop_connect.load(Ordering::Acquire) {
753757
return;
754758
}
759+
760+
interval.tick().await;
755761
let pm_peers = connect_pm
756762
.get_peer_node_ids()
757763
.iter()
@@ -773,7 +779,33 @@ impl Node {
773779
.await;
774780
}
775781
}
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+
}
777809
}
778810
});
779811

src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ pub struct PeerDetails {
393393
///
394394
/// Currently only IPv4, IPv6, and DNS hostnames are supported.
395395
#[derive(Debug, Clone, PartialEq, Eq)]
396-
pub struct NetAddress(LdkNetAddress);
396+
pub struct NetAddress(pub LdkNetAddress);
397397

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

0 commit comments

Comments
 (0)