diff --git a/src/network/address.rs b/src/network/address.rs index c4d58b3c..4375bd7e 100644 --- a/src/network/address.rs +++ b/src/network/address.rs @@ -18,9 +18,8 @@ //! network addresses in Bitcoin messages. //! -use std::io; -use std::fmt; -use std::net::{SocketAddr, Ipv6Addr, SocketAddrV4, SocketAddrV6, Ipv4Addr}; +use std::{fmt, io, iter}; +use std::net::{SocketAddr, Ipv6Addr, SocketAddrV4, SocketAddrV6, Ipv4Addr, ToSocketAddrs}; use network::constants::ServiceFlags; use consensus::encode::{self, Decodable, Encodable, VarInt, ReadExt, WriteExt}; @@ -110,6 +109,13 @@ impl fmt::Debug for Address { } } +impl ToSocketAddrs for Address { + type Iter = iter::Once; + fn to_socket_addrs(&self) -> Result { + Ok(iter::once(self.socket_addr()?)) + } +} + /// Supported networks for use in BIP155 addrv2 message #[derive(Clone, PartialEq, Eq, Hash, Debug)] pub enum AddrV2 { @@ -276,6 +282,13 @@ impl Decodable for AddrV2Message { } } +impl ToSocketAddrs for AddrV2Message { + type Iter = iter::Once; + fn to_socket_addrs(&self) -> Result { + Ok(iter::once(self.socket_addr()?)) + } +} + #[cfg(test)] mod test { use std::str::FromStr;