bittorrent_udp: response_to_bytes: simplify code for ipv6 announce

This commit is contained in:
Joakim Frostegård 2020-04-10 10:10:33 +02:00
parent 2fadbcc8f8
commit 44b0489521

View file

@ -112,20 +112,9 @@ pub fn response_from_bytes(
}).collect() }).collect()
} else { } else {
inner[position..].chunks_exact(18).map(|chunk| { inner[position..].chunks_exact(18).map(|chunk| {
let mut cursor: Cursor<&[u8]> = Cursor::new(&chunk[..]); let ip_bytes: [u8; 16] = (&chunk[..16]).try_into().unwrap();
let ip_address = IpAddr::V6(Ipv6Addr::from(ip_bytes));
let ip_address = IpAddr::V6(Ipv6Addr::new( let port = (&chunk[16..]).read_u16::<NetworkEndian>().unwrap();
cursor.read_u16::<NetworkEndian>().unwrap(),
cursor.read_u16::<NetworkEndian>().unwrap(),
cursor.read_u16::<NetworkEndian>().unwrap(),
cursor.read_u16::<NetworkEndian>().unwrap(),
cursor.read_u16::<NetworkEndian>().unwrap(),
cursor.read_u16::<NetworkEndian>().unwrap(),
cursor.read_u16::<NetworkEndian>().unwrap(),
cursor.read_u16::<NetworkEndian>().unwrap(),
));
let port = cursor.read_u16::<NetworkEndian>().unwrap();
ResponsePeer { ResponsePeer {
ip_address, ip_address,