Skip to content

Commit c1ad3d0

Browse files
committed
Switch listening_address to use NetAddress
1 parent 3042d2b commit c1ad3d0

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]
@@ -127,9 +127,6 @@ dictionary OutPoint {
127127
[Custom]
128128
typedef string Txid;
129129

130-
[Custom]
131-
typedef string SocketAddr;
132-
133130
[Custom]
134131
typedef string NetAddress;
135132

src/lib.rs

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

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

852858
/// Returns our own listening address.
853-
pub fn listening_address(&self) -> Option<SocketAddr> {
854-
self.config.listening_address
859+
pub fn listening_address(&self) -> Option<NetAddress> {
860+
self.config.listening_address.clone()
855861
}
856862

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

src/types.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -278,22 +278,6 @@ impl UniffiCustomTypeConverter for Txid {
278278
}
279279
}
280280

281-
impl UniffiCustomTypeConverter for SocketAddr {
282-
type Builtin = String;
283-
284-
fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> {
285-
if let Ok(addr) = SocketAddr::from_str(&val) {
286-
return Ok(addr);
287-
}
288-
289-
Err(Error::InvalidPublicKey.into())
290-
}
291-
292-
fn from_custom(obj: Self) -> Self::Builtin {
293-
obj.to_string()
294-
}
295-
}
296-
297281
/// The network address of a Lightning node.
298282
///
299283
/// Currently only IPv4, IPv6, and DNS hostnames are supported.

0 commit comments

Comments
 (0)