Skip to content

Commit 8580620

Browse files
committed
support separate node announcement addresses
1 parent 22cb1df commit 8580620

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

bindings/ldk_node.udl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ dictionary Config {
77
string storage_dir_path;
88
Network network;
99
sequence<SocketAddress>? listening_addresses;
10+
sequence<SocketAddress>? announcement_addresses;
1011
NodeAlias? node_alias;
1112
sequence<PublicKey> trusted_peers_0conf;
1213
u64 probing_liquidity_limit_multiplier;
@@ -80,6 +81,8 @@ interface Builder {
8081
[Throws=BuildError]
8182
void set_listening_addresses(sequence<SocketAddress> listening_addresses);
8283
[Throws=BuildError]
84+
void set_announcement_addresses(sequence<SocketAddress> announcement_addresses);
85+
[Throws=BuildError]
8386
void set_node_alias(string node_alias);
8487
[Throws=BuildError]
8588
Node build();
@@ -107,6 +110,7 @@ interface Node {
107110
void event_handled();
108111
PublicKey node_id();
109112
sequence<SocketAddress>? listening_addresses();
113+
sequence<SocketAddress>? announcement_addresses();
110114
NodeAlias? node_alias();
111115
Bolt11Payment bolt11_payment();
112116
Bolt12Payment bolt12_payment();
@@ -314,6 +318,7 @@ enum BuildError {
314318
"InvalidSystemTime",
315319
"InvalidChannelMonitor",
316320
"InvalidListeningAddresses",
321+
"InvalidAnnouncementAddresses",
317322
"InvalidNodeAlias",
318323
"ReadFailed",
319324
"WriteFailed",

src/builder.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ pub enum BuildError {
148148
InvalidChannelMonitor,
149149
/// The given listening addresses are invalid, e.g. too many were passed.
150150
InvalidListeningAddresses,
151+
/// The given announcement addresses are invalid, e.g. too many were passed.
152+
InvalidAnnouncementAddresses,
151153
/// The provided alias is invalid.
152154
InvalidNodeAlias,
153155
/// We failed to read data from the [`KVStore`].
@@ -182,6 +184,9 @@ impl fmt::Display for BuildError {
182184
write!(f, "Failed to watch a deserialized ChannelMonitor")
183185
},
184186
Self::InvalidListeningAddresses => write!(f, "Given listening addresses are invalid."),
187+
Self::InvalidAnnouncementAddresses => {
188+
write!(f, "Given announcement addresses are invalid.")
189+
},
185190
Self::ReadFailed => write!(f, "Failed to read from store."),
186191
Self::WriteFailed => write!(f, "Failed to write to store."),
187192
Self::StoragePathAccessFailed => write!(f, "Failed to access the given storage path."),
@@ -412,6 +417,18 @@ impl NodeBuilder {
412417
Ok(self)
413418
}
414419

420+
/// Sets the IP address and TCP port which [`Node`] will announce to the gossip network that it accepts connections on.
421+
pub fn set_announcement_addresses(
422+
&mut self, announcement_addresses: Vec<SocketAddress>,
423+
) -> Result<&mut Self, BuildError> {
424+
if announcement_addresses.len() > 100 {
425+
return Err(BuildError::InvalidAnnouncementAddresses);
426+
}
427+
428+
self.config.announcement_addresses = Some(announcement_addresses);
429+
Ok(self)
430+
}
431+
415432
/// Sets the node alias that will be used when broadcasting announcements to the gossip
416433
/// network.
417434
///
@@ -766,6 +783,13 @@ impl ArcedNodeBuilder {
766783
self.inner.write().unwrap().set_listening_addresses(listening_addresses).map(|_| ())
767784
}
768785

786+
/// Sets the IP address and TCP port which [`Node`] will announce to the gossip network that it accepts connections on.
787+
pub fn set_announcement_addresses(
788+
&self, announcement_addresses: Vec<SocketAddress>,
789+
) -> Result<(), BuildError> {
790+
self.inner.write().unwrap().set_announcement_addresses(announcement_addresses).map(|_| ())
791+
}
792+
769793
/// Sets the node alias that will be used when broadcasting announcements to the gossip
770794
/// network.
771795
///

src/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ pub struct Config {
117117
/// **Note**: We will only allow opening and accepting public channels if the `node_alias` and the
118118
/// `listening_addresses` are set.
119119
pub listening_addresses: Option<Vec<SocketAddress>>,
120+
/// The addresses which the node will announce to the gossip network that it accepts connections on.
121+
///
122+
/// **Note**: If unset, the `listening_addresses` will be used as the list of addresses to announce.
123+
pub announcement_addresses: Option<Vec<SocketAddress>>,
120124
/// The node alias that will be used when broadcasting announcements to the gossip network.
121125
///
122126
/// The provided alias must be a valid UTF-8 string and no longer than 32 bytes in total.
@@ -168,6 +172,7 @@ impl Default for Config {
168172
storage_dir_path: DEFAULT_STORAGE_DIR_PATH.to_string(),
169173
network: DEFAULT_NETWORK,
170174
listening_addresses: None,
175+
announcement_addresses: None,
171176
trusted_peers_0conf: Vec::new(),
172177
probing_liquidity_limit_multiplier: DEFAULT_PROBING_LIQUIDITY_LIMIT_MULTIPLIER,
173178
anchor_channels_config: Some(AnchorChannelsConfig::default()),

src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,9 @@ impl Node {
457457
continue;
458458
}
459459

460-
let addresses = if let Some(addresses) = bcast_config.listening_addresses.clone() {
460+
let addresses = if let Some(addresses) = bcast_config.announcement_addresses.clone() {
461+
addresses
462+
} else if let Some(addresses) = bcast_config.listening_addresses.clone() {
461463
addresses
462464
} else {
463465
debug_assert!(false, "We checked whether the node may announce, so listening addresses should always be set");
@@ -802,6 +804,11 @@ impl Node {
802804
self.config.listening_addresses.clone()
803805
}
804806

807+
/// Returns our own announcement addresses.
808+
pub fn announcement_addresses(&self) -> Option<Vec<SocketAddress>> {
809+
self.config.announcement_addresses.clone()
810+
}
811+
805812
/// Returns our node alias.
806813
pub fn node_alias(&self) -> Option<NodeAlias> {
807814
self.config.node_alias

0 commit comments

Comments
 (0)