snarkos_node_sync/helpers/
mod.rs1use snarkvm::prelude::Network;
17
18use core::hash::Hash;
19use indexmap::IndexSet;
20use std::net::SocketAddr;
21
22pub type PrepareSyncRequest<N> = (Option<<N as Network>::BlockHash>, Option<<N as Network>::BlockHash>, usize);
24
25pub type SyncRequest<N> = (Option<<N as Network>::BlockHash>, Option<<N as Network>::BlockHash>, IndexSet<SocketAddr>);
27
28#[derive(Copy, Clone, Debug)]
29pub(crate) struct PeerPair(pub SocketAddr, pub SocketAddr);
30
31impl PeerPair {
32 pub fn contains(&self, peer_ip: &SocketAddr) -> bool {
33 peer_ip == &self.0 || peer_ip == &self.1
34 }
35}
36
37impl Eq for PeerPair {}
38
39impl PartialEq for PeerPair {
40 fn eq(&self, other: &Self) -> bool {
41 (self.0 == other.0 && self.1 == other.1) || (self.0 == other.1 && self.1 == other.0)
42 }
43}
44
45impl Hash for PeerPair {
46 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
47 let (a, b) = if self.0 < self.1 { (self.0, self.1) } else { (self.1, self.0) };
48 a.hash(state);
49 b.hash(state);
50 }
51}