Set outgoing IP address for incomming peers after Ext. handshake

This commit is contained in:
Ivan 2024-09-26 18:11:05 +02:00
parent a483bc6586
commit 4bd757173d
2 changed files with 35 additions and 9 deletions

View file

@ -69,6 +69,28 @@ where
ut_pex: self.ut_pex(),
}
}
pub fn ip_addr(&self) -> Option<IpAddr> {
if let Some(b) = self.ipv4 {
let b = b.as_slice();
if b.len() == 4 {
let ip_bytes: &[u8; 4] = b[0..4].try_into().unwrap(); // Safe to unwrap as we check slice length
return Some(IpAddr::from(*ip_bytes));
}
}
if let Some(b) = self.ipv6 {
let b = b.as_slice();
if b.len() == 16 {
let ip_bytes: &[u8; 16] = b[0..16].try_into().unwrap(); // Safe to unwrap as we check slice length
return Some(IpAddr::from(*ip_bytes));
}
}
None
}
pub fn port(&self) -> Option<u16> {
self.p.and_then(|p| u16::try_from(p).ok())
}
}
impl<ByteBuf> CloneToOwned for ExtendedHandshake<ByteBuf>