Skip to main content

hotmint_network/
pex.rs

1use serde::{Deserialize, Serialize};
2
3use crate::peer::{PeerInfo, PeerRole};
4
5/// PEX (Peer Exchange) request messages.
6#[derive(Debug, Serialize, Deserialize)]
7pub enum PexRequest {
8    /// Request a list of known peers.
9    GetPeers,
10    /// Advertise this node's presence and role.
11    Advertise {
12        role: PeerRole,
13        validator_id: Option<u64>,
14        addresses: Vec<String>,
15    },
16}
17
18/// PEX response messages.
19#[derive(Debug, Serialize, Deserialize)]
20pub enum PexResponse {
21    /// List of known peers (up to max_peers_per_response).
22    Peers(Vec<PeerInfo>),
23    /// Acknowledgment of an Advertise message.
24    Ack,
25}
26
27/// PEX configuration.
28#[derive(Debug, Clone, Serialize, Deserialize)]
29pub struct PexConfig {
30    pub enabled: bool,
31    pub max_peers: usize,
32    pub request_interval_secs: u64,
33    pub max_peers_per_response: usize,
34    /// Peer IDs that should not be shared in PEX responses (sentry protection).
35    #[serde(default)]
36    pub private_peer_ids: Vec<String>,
37}
38
39impl Default for PexConfig {
40    fn default() -> Self {
41        Self {
42            enabled: true,
43            max_peers: 50,
44            request_interval_secs: 30,
45            max_peers_per_response: 32,
46            private_peer_ids: vec![],
47        }
48    }
49}