2024-06-04 17:19:25 +00:00
|
|
|
use cuprate_helper::network::Network;
|
|
|
|
use monero_address_book::AddressBookConfig;
|
|
|
|
use monero_p2p::NetworkZone;
|
|
|
|
use monero_wire::{common::PeerSupportFlags, BasicNodeData};
|
|
|
|
|
2024-05-17 13:52:51 +00:00
|
|
|
/// P2P config.
|
|
|
|
#[derive(Clone, Debug)]
|
2024-06-04 17:19:25 +00:00
|
|
|
pub struct P2PConfig<N: NetworkZone> {
|
|
|
|
/// The [`Network`] we should connect to.
|
|
|
|
pub network: Network,
|
|
|
|
|
2024-05-17 13:52:51 +00:00
|
|
|
/// The number of outbound connections to make and try keep.
|
|
|
|
pub outbound_connections: usize,
|
|
|
|
/// The amount of extra connections we can make if we are under load from the rest of Cuprate.
|
|
|
|
pub extra_outbound_connections: usize,
|
2024-06-04 17:19:25 +00:00
|
|
|
/// The maximum amount of inbound connections, only relevant if [`P2PConfig::server_config`] is set to [`Some`]
|
|
|
|
pub max_inbound_connections: usize,
|
2024-05-17 13:52:51 +00:00
|
|
|
/// The percent of outbound peers that should be gray aka never connected to before.
|
|
|
|
///
|
|
|
|
/// Only values 0..=1 are valid.
|
|
|
|
pub gray_peers_percent: f64,
|
2024-06-04 17:19:25 +00:00
|
|
|
/// The inbound server configuration,
|
|
|
|
///
|
|
|
|
/// If this is [`None`] no inbound connections will be accepted.
|
|
|
|
pub server_config: Option<N::ServerCfg>,
|
|
|
|
|
|
|
|
/// The port to listen on for inbound connections, only relevant if [`P2PConfig::server_config`] is set to [`Some`].
|
|
|
|
pub p2p_port: u16,
|
|
|
|
/// The public RPC port to tell peers about so wallets can use our node. `0` if we do not have a public RPC port.
|
|
|
|
pub rpc_port: u16,
|
|
|
|
|
|
|
|
/// The [`AddressBookConfig`].
|
|
|
|
pub address_book_config: AddressBookConfig,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<N: NetworkZone> P2PConfig<N> {
|
|
|
|
/// Returns the [`BasicNodeData`] for this [`P2PConfig`].
|
|
|
|
///
|
|
|
|
/// [`BasicNodeData::peer_id`] is set to a random u64, so this function should only be called once
|
|
|
|
/// per [`NetworkZone`] per run.
|
|
|
|
pub(crate) fn basic_node_data(&self) -> BasicNodeData {
|
|
|
|
BasicNodeData {
|
|
|
|
my_port: u32::from(self.p2p_port),
|
|
|
|
network_id: self.network.network_id(),
|
|
|
|
peer_id: rand::random(),
|
|
|
|
support_flags: PeerSupportFlags::FLUFFY_BLOCKS,
|
|
|
|
rpc_port: self.rpc_port,
|
|
|
|
// We do not (and probably will never) support paying for RPC with hashes.
|
|
|
|
rpc_credits_per_hash: 0,
|
|
|
|
}
|
|
|
|
}
|
2024-05-17 13:52:51 +00:00
|
|
|
}
|