Skip to content

Commit e8c0cbe

Browse files
committed
added Error::new() to OnionV2 and V3 with error message. Also changed the the Iter type into a vec::IntoIter
1 parent 38b50a0 commit e8c0cbe

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

lightning/src/ln/msgs.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ use core::fmt;
4444
use core::fmt::Debug;
4545
use core::ops::Deref;
4646
use core::str::FromStr;
47+
use std::net::SocketAddr;
4748
use crate::io::{self, Cursor, Read};
4849
use crate::io_extras::read_to_end;
4950

@@ -958,26 +959,31 @@ impl From<std::net::SocketAddr> for SocketAddress {
958959

959960
#[cfg(feature = "std")]
960961
impl std::net::ToSocketAddrs for SocketAddress {
961-
type Iter = std::option::IntoIter<std::net::SocketAddr>;
962+
type Iter = std::vec::IntoIter<std::net::SocketAddr>;
962963

963964
fn to_socket_addrs(&self) -> std::io::Result<Self::Iter> {
964965
match self {
965966
SocketAddress::TcpIpV4 { addr, port } => {
966967
let ip_addr = std::net::Ipv4Addr::from(*addr);
967-
(ip_addr, *port).to_socket_addrs()
968+
let socket_addr = SocketAddr::new(ip_addr.into(), *port);
969+
Ok(vec![socket_addr].into_iter())
968970
}
969971
SocketAddress::TcpIpV6 { addr, port } => {
970972
let ip_addr = std::net::Ipv6Addr::from(*addr);
971-
(ip_addr, *port).to_socket_addrs()
973+
let socket_addr = SocketAddr::new(ip_addr.into(), *port);
974+
Ok(vec![socket_addr].into_iter())
972975
}
973976
SocketAddress::Hostname { ref hostname, port } => {
974-
Ok((hostname.as_str(), *port).to_socket_addrs()?.next().into_iter())
977+
let socket_addr: Vec<SocketAddr> = (hostname.as_str(), *port).to_socket_addrs()?.collect();
978+
Ok(socket_addr.into_iter())
975979
}
976980
SocketAddress::OnionV2(..) => {
977-
Err(std::io::Error::from(std::io::ErrorKind::Other))
981+
Err(std::io::Error::new(std::io::ErrorKind::Other, "Resolution of these \
982+
addresses is currently unsupported."))
978983
}
979984
SocketAddress::OnionV3 { .. } => {
980-
Err(std::io::Error::from(std::io::ErrorKind::Other))
985+
Err(std::io::Error::new(std::io::ErrorKind::Other, "Resolution of these \
986+
addresses is currently unsupported."))
981987
}
982988
}
983989
}

0 commit comments

Comments
 (0)