aquatic_http: add ipv6 compact responses; fix ipv4/ipv6 issue

This commit is contained in:
Joakim Frostegård 2020-07-08 12:26:41 +02:00
parent 5ff00e866d
commit 43a33d80c4
6 changed files with 127 additions and 27 deletions

View file

@ -1,4 +1,5 @@
use std::time::{Duration, Instant};
use std::net::IpAddr;
use indexmap::IndexMap;
use rand::Rng;
@ -77,4 +78,18 @@ pub fn extract_response_peers<K, V, R, F>(
peers
}
}
#[inline]
pub fn convert_ipv4_mapped_ipv4(ip_address: IpAddr) -> IpAddr {
if let IpAddr::V6(ip) = ip_address {
if let [0, 0, 0, 0, 0, 0xffff, ..] = ip.segments(){
ip.to_ipv4().expect("convert ipv4-mapped ip").into()
} else {
ip_address
}
} else {
ip_address
}
}