Skip to content

Commit c327a67

Browse files
committed
Account for NetAddress being renamed to SocketAddress
1 parent a17d108 commit c327a67

File tree

8 files changed

+63
-93
lines changed

8 files changed

+63
-93
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LDK Node is a self-custodial Lightning node in library form. Its central goal is
1111
The primary abstraction of the library is the [`Node`][api_docs_node], which can be retrieved by setting up and configuring a [`Builder`][api_docs_builder] to your liking and calling one of the `build` methods. `Node` can then be controlled via commands such as `start`, `stop`, `connect_open_channel`, `send_payment`, etc.
1212

1313
```rust
14-
use ldk_node::{Builder, NetAddress};
14+
use ldk_node::{Builder, SocketAddress};
1515
use ldk_node::lightning_invoice::Invoice;
1616
use ldk_node::bitcoin::secp256k1::PublicKey;
1717
use ldk_node::bitcoin::Network;
@@ -32,7 +32,7 @@ fn main() {
3232
// .. fund address ..
3333

3434
let node_id = PublicKey::from_str("NODE_ID").unwrap();
35-
let node_addr = NetAddress::from_str("IP_ADDR:PORT").unwrap();
35+
let node_addr = SocketAddress::from_str("IP_ADDR:PORT").unwrap();
3636
node.connect_open_channel(node_id, node_addr, 10000, None, None, false).unwrap();
3737

3838
let event = node.wait_next_event();

bindings/ldk_node.udl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ dictionary Config {
66
string storage_dir_path = "/tmp/ldk_node/";
77
string? log_dir_path = null;
88
Network network = "Bitcoin";
9-
NetAddress? listening_address = null;
9+
SocketAddress? listening_address = null;
1010
u32 default_cltv_expiry_delta = 144;
1111
u64 onchain_wallet_sync_interval_secs = 80;
1212
u64 wallet_sync_interval_secs = 30;
@@ -29,7 +29,7 @@ interface Builder {
2929
void set_gossip_source_rgs(string rgs_server_url);
3030
void set_storage_dir_path(string storage_dir_path);
3131
void set_network(Network network);
32-
void set_listening_address(NetAddress listening_address);
32+
void set_listening_address(SocketAddress listening_address);
3333
[Throws=BuildError]
3434
LDKNode build();
3535
};
@@ -43,7 +43,7 @@ interface LDKNode {
4343
Event wait_next_event();
4444
void event_handled();
4545
PublicKey node_id();
46-
NetAddress? listening_address();
46+
SocketAddress? listening_address();
4747
[Throws=NodeError]
4848
Address new_onchain_address();
4949
[Throws=NodeError]
@@ -55,11 +55,11 @@ interface LDKNode {
5555
[Throws=NodeError]
5656
u64 total_onchain_balance_sats();
5757
[Throws=NodeError]
58-
void connect(PublicKey node_id, NetAddress address, boolean persist);
58+
void connect(PublicKey node_id, SocketAddress address, boolean persist);
5959
[Throws=NodeError]
6060
void disconnect(PublicKey node_id);
6161
[Throws=NodeError]
62-
void connect_open_channel(PublicKey node_id, NetAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, ChannelConfig? channel_config, boolean announce_channel);
62+
void connect_open_channel(PublicKey node_id, SocketAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, ChannelConfig? channel_config, boolean announce_channel);
6363
[Throws=NodeError]
6464
void close_channel([ByRef]ChannelId channel_id, PublicKey counterparty_node_id);
6565
[Throws=NodeError]
@@ -110,7 +110,7 @@ enum NodeError {
110110
"TxSyncFailed",
111111
"GossipUpdateFailed",
112112
"InvalidAddress",
113-
"InvalidNetAddress",
113+
"InvalidSocketAddress",
114114
"InvalidPublicKey",
115115
"InvalidSecretKey",
116116
"InvalidPaymentHash",
@@ -199,7 +199,7 @@ dictionary ChannelDetails {
199199

200200
dictionary PeerDetails {
201201
PublicKey node_id;
202-
NetAddress address;
202+
SocketAddress address;
203203
boolean is_persisted;
204204
boolean is_connected;
205205
};
@@ -233,7 +233,7 @@ enum LogLevel {
233233
typedef string Txid;
234234

235235
[Custom]
236-
typedef string NetAddress;
236+
typedef string SocketAddress;
237237

238238
[Custom]
239239
typedef string PublicKey;

src/builder.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use crate::logger::{log_error, FilesystemLogger, Logger};
88
use crate::payment_store::PaymentStore;
99
use crate::peer_store::PeerStore;
1010
use crate::types::{
11-
ChainMonitor, ChannelManager, FakeMessageRouter, GossipSync, KeysManager, NetAddress,
12-
NetworkGraph, OnionMessenger, PeerManager,
11+
ChainMonitor, ChannelManager, FakeMessageRouter, GossipSync, KeysManager, NetworkGraph,
12+
OnionMessenger, PeerManager, SocketAddress,
1313
};
1414
use crate::wallet::Wallet;
1515
use crate::LogLevel;
@@ -217,7 +217,7 @@ impl NodeBuilder {
217217
}
218218

219219
/// Sets the IP address and TCP port on which [`Node`] will listen for incoming network connections.
220-
pub fn set_listening_address(&mut self, listening_address: NetAddress) -> &mut Self {
220+
pub fn set_listening_address(&mut self, listening_address: SocketAddress) -> &mut Self {
221221
self.config.listening_address = Some(listening_address);
222222
self
223223
}
@@ -353,7 +353,7 @@ impl ArcedNodeBuilder {
353353
}
354354

355355
/// Sets the IP address and TCP port on which [`Node`] will listen for incoming network connections.
356-
pub fn set_listening_address(&self, listening_address: NetAddress) {
356+
pub fn set_listening_address(&self, listening_address: SocketAddress) {
357357
self.inner.write().unwrap().set_listening_address(listening_address);
358358
}
359359

src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub enum Error {
3838
/// The given address is invalid.
3939
InvalidAddress,
4040
/// The given network address is invalid.
41-
InvalidNetAddress,
41+
InvalidSocketAddress,
4242
/// The given public key is invalid.
4343
InvalidPublicKey,
4444
/// The given secret key is invalid.
@@ -85,7 +85,7 @@ impl fmt::Display for Error {
8585
Self::TxSyncFailed => write!(f, "Failed to sync transactions."),
8686
Self::GossipUpdateFailed => write!(f, "Failed to update gossip data."),
8787
Self::InvalidAddress => write!(f, "The given address is invalid."),
88-
Self::InvalidNetAddress => write!(f, "The given network address is invalid."),
88+
Self::InvalidSocketAddress => write!(f, "The given network address is invalid."),
8989
Self::InvalidPublicKey => write!(f, "The given public key is invalid."),
9090
Self::InvalidSecretKey => write!(f, "The given secret key is invalid."),
9191
Self::InvalidPaymentHash => write!(f, "The given payment hash is invalid."),

src/lib.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
//! [`send_payment`], etc.:
2727
//!
2828
//! ```no_run
29-
//! use ldk_node::{Builder, NetAddress};
29+
//! use ldk_node::{Builder, SocketAddress};
3030
//! use ldk_node::lightning_invoice::Bolt11Invoice;
3131
//! use ldk_node::bitcoin::secp256k1::PublicKey;
3232
//! use ldk_node::bitcoin::Network;
@@ -47,7 +47,7 @@
4747
//! // .. fund address ..
4848
//!
4949
//! let node_id = PublicKey::from_str("NODE_ID").unwrap();
50-
//! let node_addr = NetAddress::from_str("IP_ADDR:PORT").unwrap();
50+
//! let node_addr = SocketAddress::from_str("IP_ADDR:PORT").unwrap();
5151
//! node.connect_open_channel(node_id, node_addr, 10000, None, None, false).unwrap();
5252
//!
5353
//! let event = node.wait_next_event();
@@ -100,7 +100,7 @@ use error::Error;
100100

101101
pub use event::Event;
102102
pub use types::ChannelConfig;
103-
pub use types::NetAddress;
103+
pub use types::SocketAddress;
104104

105105
pub use io::utils::generate_entropy_mnemonic;
106106

@@ -225,7 +225,7 @@ pub struct Config {
225225
/// The used Bitcoin network.
226226
pub network: Network,
227227
/// The IP address and TCP port the node will listen on.
228-
pub listening_address: Option<NetAddress>,
228+
pub listening_address: Option<SocketAddress>,
229229
/// The default CLTV expiry delta to be used for payments.
230230
pub default_cltv_expiry_delta: u32,
231231
/// The time in-between background sync attempts of the onchain wallet, in seconds.
@@ -504,7 +504,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
504504
"Unable to resolve listing address: {:?}",
505505
listening_address
506506
);
507-
Error::InvalidNetAddress
507+
Error::InvalidSocketAddress
508508
})?
509509
.next()
510510
.ok_or_else(|| {
@@ -513,7 +513,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
513513
"Unable to resolve listing address: {:?}",
514514
listening_address
515515
);
516-
Error::InvalidNetAddress
516+
Error::InvalidSocketAddress
517517
})?;
518518

519519
runtime.spawn(async move {
@@ -776,7 +776,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
776776
}
777777

778778
/// Returns our own listening address.
779-
pub fn listening_address(&self) -> Option<NetAddress> {
779+
pub fn listening_address(&self) -> Option<SocketAddress> {
780780
self.config.listening_address.clone()
781781
}
782782

@@ -833,7 +833,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
833833
///
834834
/// If `persist` is set to `true`, we'll remember the peer and reconnect to it on restart.
835835
pub fn connect(
836-
&self, node_id: PublicKey, address: NetAddress, persist: bool,
836+
&self, node_id: PublicKey, address: SocketAddress, persist: bool,
837837
) -> Result<(), Error> {
838838
let rt_lock = self.runtime.read().unwrap();
839839
if rt_lock.is_none() {
@@ -898,7 +898,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
898898
///
899899
/// Returns a temporary channel id.
900900
pub fn connect_open_channel(
901-
&self, node_id: PublicKey, address: NetAddress, channel_amount_sats: u64,
901+
&self, node_id: PublicKey, address: SocketAddress, channel_amount_sats: u64,
902902
push_to_counterparty_msat: Option<u64>, channel_config: Option<Arc<ChannelConfig>>,
903903
announce_channel: bool,
904904
) -> Result<(), Error> {
@@ -1536,7 +1536,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
15361536
let stored_peer = self.peer_store.get_peer(&node_id);
15371537
let stored_addr_opt = stored_peer.as_ref().map(|p| p.address.clone());
15381538
let address = match (con_addr_opt, stored_addr_opt) {
1539-
(Some(con_addr), _) => NetAddress(con_addr),
1539+
(Some(con_addr), _) => SocketAddress(con_addr),
15401540
(None, Some(stored_addr)) => stored_addr,
15411541
(None, None) => continue,
15421542
};
@@ -1590,7 +1590,7 @@ impl<K: KVStore + Sync + Send + 'static> Drop for Node<K> {
15901590
}
15911591

15921592
async fn connect_peer_if_necessary<K: KVStore + Sync + Send + 'static>(
1593-
node_id: PublicKey, addr: NetAddress, peer_manager: Arc<PeerManager<K>>,
1593+
node_id: PublicKey, addr: SocketAddress, peer_manager: Arc<PeerManager<K>>,
15941594
logger: Arc<FilesystemLogger>,
15951595
) -> Result<(), Error> {
15961596
for (pman_node_id, _pman_addr) in peer_manager.get_peer_node_ids() {
@@ -1603,7 +1603,7 @@ async fn connect_peer_if_necessary<K: KVStore + Sync + Send + 'static>(
16031603
}
16041604

16051605
async fn do_connect_peer<K: KVStore + Sync + Send + 'static>(
1606-
node_id: PublicKey, addr: NetAddress, peer_manager: Arc<PeerManager<K>>,
1606+
node_id: PublicKey, addr: SocketAddress, peer_manager: Arc<PeerManager<K>>,
16071607
logger: Arc<FilesystemLogger>,
16081608
) -> Result<(), Error> {
16091609
log_info!(logger, "Connecting to peer: {}@{}", node_id, addr);
@@ -1612,7 +1612,7 @@ async fn do_connect_peer<K: KVStore + Sync + Send + 'static>(
16121612
.to_socket_addrs()
16131613
.map_err(|e| {
16141614
log_error!(logger, "Failed to resolve network address: {}", e);
1615-
Error::InvalidNetAddress
1615+
Error::InvalidSocketAddress
16161616
})?
16171617
.next()
16181618
.ok_or(Error::ConnectionFailed)?;

src/peer_store.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::io::{KVStore, PEER_INFO_PERSISTENCE_KEY, PEER_INFO_PERSISTENCE_NAMESPACE};
22
use crate::logger::{log_error, Logger};
3-
use crate::{Error, NetAddress};
3+
use crate::{Error, SocketAddress};
44

55
use lightning::impl_writeable_tlv_based;
66
use lightning::util::ser::{Readable, ReadableArgs, Writeable, Writer};
@@ -122,7 +122,7 @@ impl Writeable for PeerStoreSerWrapper<'_> {
122122
#[derive(Clone, Debug, PartialEq, Eq)]
123123
pub(crate) struct PeerInfo {
124124
pub node_id: PublicKey,
125-
pub address: NetAddress,
125+
pub address: SocketAddress,
126126
}
127127

128128
impl_writeable_tlv_based!(PeerInfo, {
@@ -147,7 +147,7 @@ mod tests {
147147
"0276607124ebe6a6c9338517b6f485825b27c2dcc0b9fc2aa6a4c0df91194e5993",
148148
)
149149
.unwrap();
150-
let address = NetAddress::from_str("127.0.0.1:9738").unwrap();
150+
let address = SocketAddress::from_str("127.0.0.1:9738").unwrap();
151151
let expected_peer_info = PeerInfo { node_id, address };
152152
peer_store.add_peer(expected_peer_info.clone()).unwrap();
153153
assert!(store.get_and_clear_did_persist());

0 commit comments

Comments
 (0)