mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 10:15:31 +00:00
udp: split AnnounceResponse into V4 and V6 versions
This commit is contained in:
parent
4b07e007f3
commit
f3e41148fe
9 changed files with 255 additions and 119 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||
|
||||
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
|
||||
pub enum IpVersion {
|
||||
|
|
@ -37,8 +37,14 @@ pub struct PeerId(pub [u8; 20]);
|
|||
pub struct PeerKey(pub u32);
|
||||
|
||||
#[derive(Hash, PartialEq, Eq, Clone, Debug)]
|
||||
pub struct ResponsePeer {
|
||||
pub ip_address: IpAddr,
|
||||
pub struct ResponsePeerIpv4 {
|
||||
pub ip_address: Ipv4Addr,
|
||||
pub port: Port,
|
||||
}
|
||||
|
||||
#[derive(Hash, PartialEq, Eq, Clone, Debug)]
|
||||
pub struct ResponsePeerIpv6 {
|
||||
pub ip_address: Ipv6Addr,
|
||||
pub port: Port,
|
||||
}
|
||||
|
||||
|
|
@ -80,11 +86,21 @@ impl quickcheck::Arbitrary for PeerId {
|
|||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl quickcheck::Arbitrary for ResponsePeer {
|
||||
impl quickcheck::Arbitrary for ResponsePeerIpv4 {
|
||||
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||
Self {
|
||||
ip_address: ::std::net::IpAddr::arbitrary(g),
|
||||
port: Port(u16::arbitrary(g)),
|
||||
ip_address: quickcheck::Arbitrary::arbitrary(g),
|
||||
port: Port(u16::arbitrary(g).into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl quickcheck::Arbitrary for ResponsePeerIpv6 {
|
||||
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||
Self {
|
||||
ip_address: quickcheck::Arbitrary::arbitrary(g),
|
||||
port: Port(u16::arbitrary(g).into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue