cuprate_p2p_core/constants.rs
1//! Constants used around monero-p2p
2
3use std::time::Duration;
4
5/// The request timeout - the time we give a peer to respond to a request.
6pub(crate) const REQUEST_TIMEOUT: Duration = Duration::from_secs(60);
7
8/// The timeout put on the given peer request handler to prevent the connection task from getting stuck
9/// if handling a request takes too long.
10pub(crate) const REQUEST_HANDLER_TIMEOUT: Duration = Duration::from_secs(10);
11
12/// The timeout used when sending messages to a peer.
13///
14/// TODO: Make this configurable?
15/// TODO: Is this a good default.
16pub(crate) const SENDING_TIMEOUT: Duration = Duration::from_secs(20);
17
18/// The interval between timed syncs.
19///
20/// TODO: Make this configurable?
21/// TODO: Is this a good default.
22pub(crate) const TIMEOUT_INTERVAL: Duration = Duration::from_secs(61);
23
24/// This is a Cuprate specific constant.
25///
26/// When completing a handshake monerod might send protocol messages before the handshake is actually
27/// complete, this is a problem for Cuprate as we must complete the handshake before responding to any
28/// protocol requests. So when we receive a protocol message during a handshake we keep them around to handle
29/// after the handshake.
30///
31/// Because we use the [bytes crate](https://crates.io/crates/bytes) in monero-wire for zero-copy parsing
32/// it is not safe to keep too many of these messages around for long.
33pub(crate) const MAX_EAGER_PROTOCOL_MESSAGES: usize = 1;
34
35/// The maximum amount of requests allowed in the queue to the connection task.
36pub(crate) const CLIENT_QUEUE_SIZE: usize = 5;
37
38/// A timeout put on pings during handshakes.
39///
40/// When we receive an inbound connection we open an outbound connection to the node and send a ping message
41/// to see if we can reach the node, so we can add it to our address book.
42///
43/// This timeout must be significantly shorter than [`HANDSHAKE_TIMEOUT`] so we don't drop inbound connections that
44/// don't have ports open.
45pub(crate) const PING_TIMEOUT: Duration = Duration::from_secs(10);
46
47/// A timeout for a handshake - the handshake must complete before this.
48pub(crate) const HANDSHAKE_TIMEOUT: Duration = Duration::from_secs(60);
49
50pub(crate) const MAX_PEERS_IN_PEER_LIST_MESSAGE: usize = 250;