karyon_p2p/config.rs
1use karyon_net::{Endpoint, Port};
2
3use crate::Version;
4
5/// the Configuration for the P2P network.
6pub struct Config {
7 /// Represents the network version.
8 pub version: Version,
9
10 /// Enable monitor
11 pub enable_monitor: bool,
12
13 /////////////////
14 // PeerPool
15 ////////////////
16 /// Timeout duration for the handshake with new peers, in seconds.
17 pub handshake_timeout: u64,
18 /// Interval at which the ping protocol sends ping messages to a peer to
19 /// maintain connections, in seconds.
20 pub ping_interval: u64,
21 /// Timeout duration for receiving the pong message corresponding to the
22 /// sent ping message, in seconds.
23 pub ping_timeout: u64,
24 /// The maximum number of retries for outbound connection establishment.
25 pub max_connect_retries: usize,
26
27 /////////////////
28 // DISCOVERY
29 ////////////////
30 /// A list of bootstrap peers for the seeding process.
31 pub bootstrap_peers: Vec<Endpoint>,
32 /// An optional listening endpoint to accept incoming connections.
33 pub listen_endpoint: Option<Endpoint>,
34 /// A list of endpoints representing peers that the `Discovery` will
35 /// manually connect to.
36 pub peer_endpoints: Vec<Endpoint>,
37 /// The number of available inbound slots for incoming connections.
38 pub inbound_slots: usize,
39 /// The number of available outbound slots for outgoing connections.
40 pub outbound_slots: usize,
41 /// TCP/UDP port for lookup and refresh processes.
42 pub discovery_port: Port,
43 /// Time interval, in seconds, at which the Discovery restarts the
44 /// seeding process.
45 pub seeding_interval: u64,
46
47 /////////////////
48 // LOOKUP
49 ////////////////
50 /// The number of available inbound slots for incoming connections during
51 /// the lookup process.
52 pub lookup_inbound_slots: usize,
53 /// The number of available outbound slots for outgoing connections during
54 /// the lookup process.
55 pub lookup_outbound_slots: usize,
56 /// Timeout duration for a peer response during the lookup process, in
57 /// seconds.
58 pub lookup_response_timeout: u64,
59 /// Maximum allowable time for a live connection with a peer during the
60 /// lookup process, in seconds.
61 pub lookup_connection_lifespan: u64,
62 /// The maximum number of retries for outbound connection establishment
63 /// during the lookup process.
64 pub lookup_connect_retries: usize,
65
66 /////////////////
67 // REFRESH
68 ////////////////
69 /// Interval at which the table refreshes its entries, in seconds.
70 pub refresh_interval: u64,
71 /// Timeout duration for a peer response during the table refresh process,
72 /// in seconds.
73 pub refresh_response_timeout: u64,
74 /// The maximum number of retries for outbound connection establishment
75 /// during the refresh process.
76 pub refresh_connect_retries: usize,
77
78 /// Enables TLS for all connections.
79 pub enable_tls: bool,
80}
81
82impl Default for Config {
83 fn default() -> Self {
84 Config {
85 version: "0.1.0".parse().unwrap(),
86
87 enable_monitor: false,
88
89 handshake_timeout: 2,
90 ping_interval: 20,
91 ping_timeout: 2,
92
93 bootstrap_peers: vec![],
94 listen_endpoint: None,
95 peer_endpoints: vec![],
96 inbound_slots: 12,
97 outbound_slots: 12,
98 max_connect_retries: 3,
99 discovery_port: 0,
100 seeding_interval: 60,
101
102 lookup_inbound_slots: 20,
103 lookup_outbound_slots: 20,
104 lookup_response_timeout: 1,
105 lookup_connection_lifespan: 3,
106 lookup_connect_retries: 3,
107
108 refresh_interval: 1800,
109 refresh_response_timeout: 1,
110 refresh_connect_retries: 3,
111
112 enable_tls: false,
113 }
114 }
115}