udp: consistently use NonZeroU16 for announce request port

This commit is contained in:
Joakim Frostegård 2024-02-03 11:46:38 +01:00
parent b4e27903dc
commit 3513b714b4
8 changed files with 18 additions and 14 deletions

View file

@ -1,5 +1,6 @@
use std::fmt::Debug;
use std::net::{Ipv4Addr, Ipv6Addr};
use std::num::NonZeroU16;
pub use aquatic_peer_id::{PeerClient, PeerId};
use zerocopy::network_endian::{I32, I64, U16, U32};
@ -76,8 +77,8 @@ impl NumberOfDownloads {
pub struct Port(pub U16);
impl Port {
pub fn new(v: u16) -> Self {
Self(U16::new(v))
pub fn new(v: NonZeroU16) -> Self {
Self(U16::new(v.into()))
}
}

View file

@ -281,7 +281,7 @@ impl RequestParseError {
mod tests {
use quickcheck::TestResult;
use quickcheck_macros::quickcheck;
use zerocopy::network_endian::{I32, I64, U16};
use zerocopy::network_endian::{I32, I64};
use super::*;
@ -319,7 +319,7 @@ mod tests {
ip_address: Ipv4AddrBytes::arbitrary(g),
key: PeerKey::new(i32::arbitrary(g)),
peers_wanted: NumberOfPeers(I32::new(i32::arbitrary(g))),
port: Port(U16::new(u16::arbitrary(g))),
port: Port::new(quickcheck::Arbitrary::arbitrary(g)),
}
}
}