mirror of
https://github.com/mimblewimble/grin.git
synced 2025-02-01 17:01:09 +03:00
Attempt to read ipv4-mapped ipv6 to ipv4 if possible (#3221)
This commit is contained in:
parent
65e4f7efe0
commit
b400a4b1cf
1 changed files with 8 additions and 6 deletions
|
@ -143,16 +143,18 @@ impl Readable for PeerAddr {
|
||||||
))))
|
))))
|
||||||
} else {
|
} else {
|
||||||
let ip = try_iter_map_vec!(0..8, |_| reader.read_u16());
|
let ip = try_iter_map_vec!(0..8, |_| reader.read_u16());
|
||||||
|
let ipv6 = Ipv6Addr::new(ip[0], ip[1], ip[2], ip[3], ip[4], ip[5], ip[6], ip[7]);
|
||||||
let port = reader.read_u16()?;
|
let port = reader.read_u16()?;
|
||||||
|
if let Some(ipv4) = ipv6.to_ipv4() {
|
||||||
|
Ok(PeerAddr(SocketAddr::V4(SocketAddrV4::new(ipv4, port))))
|
||||||
|
} else {
|
||||||
Ok(PeerAddr(SocketAddr::V6(SocketAddrV6::new(
|
Ok(PeerAddr(SocketAddr::V6(SocketAddrV6::new(
|
||||||
Ipv6Addr::new(ip[0], ip[1], ip[2], ip[3], ip[4], ip[5], ip[6], ip[7]),
|
ipv6, port, 0, 0,
|
||||||
port,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
))))
|
))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl std::hash::Hash for PeerAddr {
|
impl std::hash::Hash for PeerAddr {
|
||||||
/// If loopback address then we care about ip and port.
|
/// If loopback address then we care about ip and port.
|
||||||
|
|
Loading…
Reference in a new issue