mirror of
https://github.com/Cuprate/cuprate.git
synced 2025-01-24 19:45:51 +00:00
Boog900
b510739701
* p2p changes * clippy * a few more docs * init cuprate-p2p * remove some unrelated code and add some docs * start documenting client_pool.rs * add more docs * typo * fix docs * use JoinSet in connection maintainer * small changes * add peer sync state svc * add broadcast svc * add more docs * add some tests * add a test * fix merge * add another test * unify PeerDisconnectFut and add more docs * start network init * add an inbound connection server * remove crate doc for now * fix address book docs * fix leak in client pool * correct comment * fix merge + add some docs * fix doc * dandelion_tower -> dandelion-tower * fix async-buffer builds * check if incoming peers are banned * add interface methods * update docs * use a JoinSet for background network tasks * Apply suggestions from code review Co-authored-by: hinto-janai <hinto.janai@protonmail.com> * Update p2p/monero-p2p/src/services.rs Co-authored-by: hinto-janai <hinto.janai@protonmail.com> --------- Co-authored-by: hinto-janai <hinto.janai@protonmail.com>
52 lines
2.1 KiB
Rust
52 lines
2.1 KiB
Rust
use cuprate_helper::network::Network;
|
|
use monero_address_book::AddressBookConfig;
|
|
use monero_p2p::NetworkZone;
|
|
use monero_wire::{common::PeerSupportFlags, BasicNodeData};
|
|
|
|
/// P2P config.
|
|
#[derive(Clone, Debug)]
|
|
pub struct P2PConfig<N: NetworkZone> {
|
|
/// The [`Network`] we should connect to.
|
|
pub network: Network,
|
|
|
|
/// 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,
|
|
/// The maximum amount of inbound connections, only relevant if [`P2PConfig::server_config`] is set to [`Some`]
|
|
pub max_inbound_connections: usize,
|
|
/// 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,
|
|
/// 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,
|
|
}
|
|
}
|
|
}
|