network: Move AddrV2Message definition down
So that it is grouped together with the impls.
This commit is contained in:
parent
3f465d56eb
commit
c7ec4f171f
|
@ -40,7 +40,7 @@ const ONION : [u16; 3] = [0xFD87, 0xD87E, 0xEB43];
|
|||
|
||||
impl Address {
|
||||
/// Create an address message for a socket
|
||||
pub fn new (socket :&SocketAddr, services: ServiceFlags) -> Address {
|
||||
pub fn new(socket :&SocketAddr, services: ServiceFlags) -> Address {
|
||||
let (address, port) = match *socket {
|
||||
SocketAddr::V4(addr) => (addr.ip().to_ipv6_mapped().segments(), addr.port()),
|
||||
SocketAddr::V6(addr) => (addr.ip().segments(), addr.port())
|
||||
|
@ -48,9 +48,10 @@ impl Address {
|
|||
Address { address: address, port: port, services: services }
|
||||
}
|
||||
|
||||
/// extract socket address from an address message
|
||||
/// This will return io::Error ErrorKind::AddrNotAvailable if the message contains a Tor address.
|
||||
pub fn socket_addr (&self) -> Result<SocketAddr, io::Error> {
|
||||
/// Extract socket address from an [Address] message.
|
||||
/// This will return [io::Error] [ErrorKind::AddrNotAvailable]
|
||||
/// if the message contains a Tor address.
|
||||
pub fn socket_addr(&self) -> Result<SocketAddr, io::Error> {
|
||||
let addr = &self.address;
|
||||
if addr[0..3] == ONION {
|
||||
return Err(io::Error::from(io::ErrorKind::AddrNotAvailable));
|
||||
|
@ -61,8 +62,7 @@ impl Address {
|
|||
);
|
||||
if let Some(ipv4) = ipv6.to_ipv4() {
|
||||
Ok(SocketAddr::V4(SocketAddrV4::new(ipv4, self.port)))
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Ok(SocketAddr::V6(SocketAddrV6::new(ipv6, self.port, 0, 0)))
|
||||
}
|
||||
}
|
||||
|
@ -110,19 +110,6 @@ impl fmt::Debug for Address {
|
|||
}
|
||||
}
|
||||
|
||||
/// Address received from BIP155 addrv2 message
|
||||
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
||||
pub struct AddrV2Message {
|
||||
/// Time that this node was last seen as connected to the network
|
||||
pub time: u32,
|
||||
/// Service bits
|
||||
pub services: ServiceFlags,
|
||||
/// Network ID + Network Address
|
||||
pub addr: AddrV2,
|
||||
/// Network port, 0 if not applicable
|
||||
pub port: u16
|
||||
}
|
||||
|
||||
/// Supported networks for use in BIP155 addrv2 message
|
||||
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
||||
pub enum AddrV2 {
|
||||
|
@ -241,6 +228,19 @@ impl Decodable for AddrV2 {
|
|||
}
|
||||
}
|
||||
|
||||
/// Address received from BIP155 addrv2 message
|
||||
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
||||
pub struct AddrV2Message {
|
||||
/// Time that this node was last seen as connected to the network
|
||||
pub time: u32,
|
||||
/// Service bits
|
||||
pub services: ServiceFlags,
|
||||
/// Network ID + Network Address
|
||||
pub addr: AddrV2,
|
||||
/// Network port, 0 if not applicable
|
||||
pub port: u16
|
||||
}
|
||||
|
||||
impl Encodable for AddrV2Message {
|
||||
fn consensus_encode<W: io::Write>(&self, mut e: W) -> Result<usize, encode::Error> {
|
||||
let mut len = 0;
|
||||
|
@ -252,7 +252,6 @@ impl Encodable for AddrV2Message {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
impl Decodable for AddrV2Message {
|
||||
fn consensus_decode<D: io::Read>(mut d: D) -> Result<Self, encode::Error> {
|
||||
Ok(AddrV2Message{
|
||||
|
|
Loading…
Reference in New Issue