embedded_td/config/
p2p.rs

1use time::Duration;
2
3use super::define_build_mode_setter;
4
5#[derive(Debug, Clone)]
6pub struct P2PConfig {
7    /// Address to listen for incoming connections.
8    pub laddr: String,
9
10    /// Address to advertise to peers for them to dial
11    /// If empty, will use the same port as the laddr,
12    /// and will introspect on the listener or use UPnP
13    /// to figure out the address. ip and port are required
14    /// example: 159.89.10.97:26656
15    pub external_address: String,
16
17    /// List of seeds
18    pub seeds: Vec<String>,
19
20    /// List of persistent peers.
21    pub persistent_peers: Vec<String>,
22
23    /// UPNP port forwarding
24    pub upnp: bool,
25
26    /// Private or local net.
27    pub local_net: bool,
28
29    /// Maximum number of inbound peers
30    pub max_num_inbound_peers: u64,
31
32    /// Maximum number of outbound peers to connect to, excluding persistent peers
33    pub max_num_outbound_peers: u64,
34
35    /// List of node IDs, to which a connection will be (re)established ignoring any existing limits
36    pub unconditional_peer_ids: Vec<String>,
37
38    /// Maximum pause when redialing a persistent peer (if zero, exponential backoff is used)
39    pub persistent_peers_max_dial_period: Duration,
40
41    /// Time to wait before flushing messages out on the connection
42    pub flush_throttle_timeout: Duration,
43
44    /// Maximum size of a message packet payload, in bytes
45    pub max_packet_msg_payload_size: u64,
46
47    /// Rate at which packets can be sent, in bytes/second
48    pub send_rate: u64,
49
50    /// Rate at which packets can be received, in bytes/second
51    pub recv_rate: u64,
52
53    /// Set true to enable the peer-exchange reactor
54    pub pex: bool,
55
56    /// Seed mode, in which node constantly crawls the network and looks for
57    /// peers. If another node asks it for addresses, it responds and disconnects.
58    ///
59    /// Does not work if the peer-exchange reactor is disabled.
60    pub seed_mode: bool,
61
62    /// Comma separated list of peer IDs to keep private (will not be gossiped to other peers)
63    pub private_peer_ids: Vec<String>,
64
65    /// Toggle to disable guard against peers connecting from the same ip.
66    pub allow_duplicate_ip: bool,
67
68    /// Peer connection configuration.
69    pub handshake_timeout: Duration,
70    pub dial_timeout: Duration,
71}
72
73impl Default for P2PConfig {
74    fn default() -> Self {
75        Self {
76            laddr: String::from("tcp://0.0.0.0:26656"),
77            external_address: Default::default(),
78            seeds: Default::default(),
79            persistent_peers: Default::default(),
80            upnp: false,
81            local_net: false,
82            max_num_inbound_peers: 40,
83            max_num_outbound_peers: 10,
84            unconditional_peer_ids: Default::default(),
85            persistent_peers_max_dial_period: Duration::new(0, 0),
86            flush_throttle_timeout: Duration::milliseconds(100),
87            max_packet_msg_payload_size: 1024,
88            send_rate: 5120000,
89            recv_rate: 5120000,
90            pex: true,
91            seed_mode: false,
92            private_peer_ids: Default::default(),
93            allow_duplicate_ip: Default::default(),
94            handshake_timeout: Duration::new(20, 0),
95            dial_timeout: Duration::new(3, 0),
96        }
97    }
98}
99
100impl P2PConfig {
101    define_build_mode_setter!(laddr, str);
102
103    define_build_mode_setter!(external_address, str);
104
105    define_build_mode_setter!(seeds, Vec<String>);
106
107    define_build_mode_setter!(persistent_peers, Vec<String>);
108
109    define_build_mode_setter!(upnp, bool);
110
111    define_build_mode_setter!(local_net, bool);
112
113    define_build_mode_setter!(max_num_inbound_peers, u64);
114
115    define_build_mode_setter!(max_num_outbound_peers, u64);
116
117    define_build_mode_setter!(unconditional_peer_ids, Vec<String>);
118
119    define_build_mode_setter!(persistent_peers_max_dial_period, Duration);
120
121    define_build_mode_setter!(flush_throttle_timeout, Duration);
122
123    define_build_mode_setter!(send_rate, u64);
124
125    define_build_mode_setter!(recv_rate, u64);
126
127    define_build_mode_setter!(pex, bool);
128
129    define_build_mode_setter!(seed_mode, bool);
130
131    define_build_mode_setter!(private_peer_ids, Vec<String>);
132
133    define_build_mode_setter!(allow_duplicate_ip, bool);
134
135    define_build_mode_setter!(handshake_timeout, Duration);
136
137    define_build_mode_setter!(dial_timeout, Duration);
138}