network: Implement net::ToSocketAddrs for address messages
This commit is contained in:
parent
4c70397a85
commit
ab1e9cbb9e
|
@ -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<SocketAddr>;
|
||||
fn to_socket_addrs(&self) -> Result<Self::Iter, io::Error> {
|
||||
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<SocketAddr>;
|
||||
fn to_socket_addrs(&self) -> Result<Self::Iter, io::Error> {
|
||||
Ok(iter::once(self.socket_addr()?))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::str::FromStr;
|
||||
|
|
Loading…
Reference in New Issue