cuprate_p2p_core/network_zones/
tor.rs

1//! Tor Zone
2//!
3//! This module define the Tor Zone that uses the Tor network and .onion service addressing.
4//!
5//! ### Anonymity
6//!
7//! This is an anonymous network and is therefore operating under the following behavior:
8//! - The node address is blend into its own address book.
9//! - This network is only use for relaying transactions.
10//!
11//! ### Addressing
12//!
13//! The Tor Zone is using [`OnionAddr`] as its address type.
14//!
15
16use cuprate_wire::network_address::OnionAddr;
17
18use crate::{NetZoneAddress, NetworkZone};
19
20impl NetZoneAddress for OnionAddr {
21    type BanID = [u8; 56];
22
23    fn set_port(&mut self, port: u16) {
24        self.port = port;
25    }
26
27    fn ban_id(&self) -> Self::BanID {
28        self.domain()
29    }
30
31    fn make_canonical(&mut self) {
32        // There are no canonical form of an onion address...
33    }
34
35    fn should_add_to_peer_list(&self) -> bool {
36        // Validation of the onion address has been done at the type construction...
37        true
38    }
39}
40
41#[derive(Clone, Copy)]
42pub struct Tor;
43
44impl NetworkZone for Tor {
45    const NAME: &'static str = "Tor";
46
47    const CHECK_NODE_ID: bool = false;
48
49    const BROADCAST_OWN_ADDR: bool = true;
50
51    type Addr = OnionAddr;
52}