]> git.bitcoin.ninja Git - ldk-sample/commitdiff
Switch to ToSocketAddrs to support connecting to hostnames not IPs
authorMatt Corallo <git@bluematt.me>
Tue, 4 May 2021 22:06:13 +0000 (22:06 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 4 May 2021 22:06:13 +0000 (22:06 +0000)
src/cli.rs

index d7a76bc03c9768c7f076afc1ec777fd8d296dec5..d2d5a218a3e123299aac3fecf33d1ecd17ea39a6 100644 (file)
@@ -18,7 +18,7 @@ use lightning_invoice::{utils, Currency, Invoice};
 use std::env;
 use std::io;
 use std::io::{BufRead, Write};
-use std::net::SocketAddr;
+use std::net::{SocketAddr, ToSocketAddrs};
 use std::ops::Deref;
 use std::path::Path;
 use std::str::FromStr;
@@ -639,12 +639,12 @@ pub(crate) fn parse_peer_info(
                return Err(std::io::Error::new(
                        std::io::ErrorKind::Other,
                        "ERROR: incorrectly formatted peer
-        info. Should be formatted as: `pubkey@host:port`",
+               info. Should be formatted as: `pubkey@host:port`",
                ));
        }
 
-       let peer_addr: Result<SocketAddr, _> = peer_addr_str.unwrap().parse();
-       if peer_addr.is_err() {
+       let peer_addr = peer_addr_str.unwrap().to_socket_addrs().map(|mut r| r.next());
+       if peer_addr.is_err() || peer_addr.as_ref().unwrap().is_none() {
                return Err(std::io::Error::new(
                        std::io::ErrorKind::Other,
                        "ERROR: couldn't parse pubkey@host:port into a socket address",
@@ -659,5 +659,5 @@ pub(crate) fn parse_peer_info(
                ));
        }
 
-       Ok((pubkey.unwrap(), peer_addr.unwrap()))
+       Ok((pubkey.unwrap(), peer_addr.unwrap().unwrap()))
 }