nym_ip_packet_requests/
lib.rs

1use serde::{Deserialize, Serialize};
2use std::fmt::{Display, Formatter};
3use std::net::{Ipv4Addr, Ipv6Addr};
4
5pub mod codec;
6pub mod sign;
7pub mod v6;
8pub mod v7;
9pub mod v8;
10
11// version 3: initial version
12// version 4: IPv6 support
13// version 5: Add severity level to info response
14// version 6: Increase the available IPs
15// version 7: Add signature support (for the future)
16// version 8: Anonymous sends
17
18#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
19pub struct IpPair {
20    pub ipv4: Ipv4Addr,
21    pub ipv6: Ipv6Addr,
22}
23
24impl IpPair {
25    pub fn new(ipv4: Ipv4Addr, ipv6: Ipv6Addr) -> Self {
26        IpPair { ipv4, ipv6 }
27    }
28}
29
30impl Display for IpPair {
31    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
32        write!(f, "IPv4: {}, IPv6: {}", self.ipv4, self.ipv6)
33    }
34}
35
36fn make_bincode_serializer() -> impl bincode::Options {
37    use bincode::Options;
38    bincode::DefaultOptions::new()
39        .with_big_endian()
40        .with_varint_encoding()
41}
42
43fn generate_random() -> u64 {
44    use rand::RngCore;
45    let mut rng = rand::rngs::OsRng;
46    rng.next_u64()
47}