aboutsummaryrefslogtreecommitdiff
path: root/p2p/src/config.rs
blob: ebecbf05525fae8a41357d201e889f9aaed80de5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
use karyons_net::{Endpoint, Port};

use crate::utils::Version;

/// the Configuration for the P2P network.
pub struct Config {
    /// Represents the network version.
    pub version: Version,

    /////////////////
    // PeerPool
    ////////////////
    /// Timeout duration for the handshake with new peers, in seconds.
    pub handshake_timeout: u64,
    /// Interval at which the ping protocol sends ping messages to a peer to
    /// maintain connections, in seconds.
    pub ping_interval: u64,
    /// Timeout duration for receiving the pong message corresponding to the
    /// sent ping message, in seconds.
    pub ping_timeout: u64,
    /// The maximum number of retries for outbound connection establishment.
    pub max_connect_retries: usize,

    /////////////////
    // DISCOVERY
    ////////////////
    /// A list of bootstrap peers for the seeding process.
    pub bootstrap_peers: Vec<Endpoint>,
    /// An optional listening endpoint to accept incoming connections.
    pub listen_endpoint: Option<Endpoint>,
    /// A list of endpoints representing peers that the `Discovery` will
    /// manually connect to.
    pub peer_endpoints: Vec<Endpoint>,
    /// The number of available inbound slots for incoming connections.
    pub inbound_slots: usize,
    /// The number of available outbound slots for outgoing connections.
    pub outbound_slots: usize,
    /// TCP/UDP port for lookup and refresh processes.
    pub discovery_port: Port,
    /// Time interval, in seconds, at which the Discovery restarts the
    /// seeding process.
    pub seeding_interval: u64,

    /////////////////
    // LOOKUP
    ////////////////
    /// The number of available inbound slots for incoming connections during
    /// the lookup process.
    pub lookup_inbound_slots: usize,
    /// The number of available outbound slots for outgoing connections during
    /// the lookup process.
    pub lookup_outbound_slots: usize,
    /// Timeout duration for a peer response during the lookup process, in
    /// seconds.
    pub lookup_response_timeout: u64,
    /// Maximum allowable time for a live connection with a peer during the
    /// lookup process, in seconds.
    pub lookup_connection_lifespan: u64,
    /// The maximum number of retries for outbound connection establishment
    /// during the lookup process.
    pub lookup_connect_retries: usize,

    /////////////////
    // REFRESH
    ////////////////
    /// Interval at which the table refreshes its entries, in seconds.
    pub refresh_interval: u64,
    /// Timeout duration for a peer response during the table refresh process,
    /// in seconds.
    pub refresh_response_timeout: u64,
    /// The maximum number of retries for outbound connection establishment
    /// during the refresh process.
    pub refresh_connect_retries: usize,
}

impl Default for Config {
    fn default() -> Self {
        Config {
            version: "0.1.0".parse().unwrap(),

            handshake_timeout: 2,
            ping_interval: 20,
            ping_timeout: 2,

            bootstrap_peers: vec![],
            listen_endpoint: None,
            peer_endpoints: vec![],
            inbound_slots: 12,
            outbound_slots: 12,
            max_connect_retries: 3,
            discovery_port: 0,
            seeding_interval: 60,

            lookup_inbound_slots: 20,
            lookup_outbound_slots: 20,
            lookup_response_timeout: 1,
            lookup_connection_lifespan: 3,
            lookup_connect_retries: 3,

            refresh_interval: 1800,
            refresh_response_timeout: 1,
            refresh_connect_retries: 3,
        }
    }
}