Skip to content

Commit 3f9d68e

Browse files
committed
Switch listening_address to use NetAddress
1 parent 9d75bb0 commit 3f9d68e

File tree

3 files changed

+14
-27
lines changed

3 files changed

+14
-27
lines changed

bindings/ldk_node.udl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ dictionary Config {
55
string storage_dir_path;
66
string esplora_server_url;
77
Network network;
8-
SocketAddr? listening_address;
8+
NetAddress? listening_address;
99
u32 default_cltv_expiry_delta;
1010
};
1111

@@ -24,7 +24,7 @@ interface Node {
2424
Event next_event();
2525
void event_handled();
2626
PublicKey node_id();
27-
SocketAddr? listening_address();
27+
NetAddress? listening_address();
2828
[Throws=NodeError]
2929
Address new_funding_address();
3030
[Throws=NodeError]
@@ -154,9 +154,6 @@ dictionary PeerDetails {
154154
[Custom]
155155
typedef string Txid;
156156

157-
[Custom]
158-
typedef string SocketAddr;
159-
160157
[Custom]
161158
typedef string NetAddress;
162159

src/lib.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ use rand::Rng;
151151
use std::convert::TryInto;
152152
use std::default::Default;
153153
use std::fs;
154-
use std::net::{SocketAddr, ToSocketAddrs};
154+
use std::net::ToSocketAddrs;
155155
use std::str::FromStr;
156156
use std::sync::atomic::{AtomicBool, Ordering};
157157
use std::sync::{Arc, Mutex, RwLock};
@@ -185,7 +185,7 @@ pub struct Config {
185185
/// The used Bitcoin network.
186186
pub network: Network,
187187
/// The IP address and TCP port the node will listen on.
188-
pub listening_address: Option<SocketAddr>,
188+
pub listening_address: Option<NetAddress>,
189189
/// The default CLTV expiry delta to be used for payments.
190190
pub default_cltv_expiry_delta: u32,
191191
}
@@ -285,7 +285,7 @@ impl Builder {
285285
/// Sets the IP address and TCP port on which [`Node`] will listen for incoming network connections.
286286
///
287287
/// Default: `0.0.0.0:9735`
288-
pub fn set_listening_address(&mut self, listening_address: SocketAddr) -> &mut Self {
288+
pub fn set_listening_address(&mut self, listening_address: NetAddress) -> &mut Self {
289289
self.config.listening_address = Some(listening_address);
290290
self
291291
}
@@ -712,9 +712,15 @@ impl Node {
712712
let stop_listen = Arc::clone(&stop_running);
713713
let listening_address = listening_address.clone();
714714

715+
let bind_addr = listening_address
716+
.to_socket_addrs()
717+
.expect("Unable to resolve listing address")
718+
.next()
719+
.expect("Unable to resolve listing address");
720+
715721
runtime.spawn(async move {
716722
let listener =
717-
tokio::net::TcpListener::bind(listening_address).await.expect(
723+
tokio::net::TcpListener::bind(bind_addr).await.expect(
718724
"Failed to bind to listen address/port - is something else already listening on it?",
719725
);
720726
loop {
@@ -849,8 +855,8 @@ impl Node {
849855
}
850856

851857
/// Returns our own listening address.
852-
pub fn listening_address(&self) -> Option<SocketAddr> {
853-
self.config.listening_address
858+
pub fn listening_address(&self) -> Option<NetAddress> {
859+
self.config.listening_address.clone()
854860
}
855861

856862
/// Retrieve a new on-chain/funding address.

src/types.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -389,22 +389,6 @@ pub struct PeerDetails {
389389
pub is_connected: bool,
390390
}
391391

392-
impl UniffiCustomTypeConverter for SocketAddr {
393-
type Builtin = String;
394-
395-
fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> {
396-
if let Ok(addr) = SocketAddr::from_str(&val) {
397-
return Ok(addr);
398-
}
399-
400-
Err(Error::InvalidPublicKey.into())
401-
}
402-
403-
fn from_custom(obj: Self) -> Self::Builtin {
404-
obj.to_string()
405-
}
406-
}
407-
408392
/// The network address of a Lightning node.
409393
///
410394
/// Currently only IPv4, IPv6, and DNS hostnames are supported.

0 commit comments

Comments
 (0)