karyon_p2p/routing_table/
entry.rs1use bincode::{Decode, Encode};
2
3use karyon_net::{Addr, Port};
4
5pub const KEY_SIZE: usize = 32;
7
8pub type Key = [u8; KEY_SIZE];
10
11#[derive(Encode, Decode, Clone, Debug)]
13pub struct Entry {
14 pub key: Key,
16 pub addr: Addr,
18 pub port: Port,
20 pub discovery_port: Port,
22}
23
24impl PartialEq for Entry {
25 fn eq(&self, other: &Self) -> bool {
26 self.key == other.key
28 }
29}
30
31pub fn xor_distance(key: &Key, other: &Key) -> Key {
36 let mut res = [0; 32];
37 for (i, (k, o)) in key.iter().zip(other.iter()).enumerate() {
38 res[i] = k ^ o;
39 }
40 res
41}