mirror of
https://github.com/Cuprate/cuprate.git
synced 2025-03-09 10:15:01 +00:00
remove some unrelated code and add some docs
This commit is contained in:
parent
b9caee9335
commit
4d61b100f5
8 changed files with 8 additions and 64 deletions
p2p/cuprate-p2p
|
@ -16,7 +16,7 @@ cuprate-helper = { path = "../../helper", features = ["asynch"] }
|
||||||
monero-serai = { workspace = true, features = ["std"] }
|
monero-serai = { workspace = true, features = ["std"] }
|
||||||
|
|
||||||
tower = { workspace = true }
|
tower = { workspace = true }
|
||||||
tokio = { workspace = true, features = ["full"] }
|
tokio = { workspace = true, features = ["rt"] }
|
||||||
rayon = { workspace = true }
|
rayon = { workspace = true }
|
||||||
tokio-util = { workspace = true }
|
tokio-util = { workspace = true }
|
||||||
tokio-stream = { workspace = true, features = ["sync", "time"] }
|
tokio-stream = { workspace = true, features = ["sync", "time"] }
|
||||||
|
|
|
@ -6,7 +6,7 @@ use std::{
|
||||||
|
|
||||||
use monero_p2p::NetworkZone;
|
use monero_p2p::NetworkZone;
|
||||||
|
|
||||||
use crate::peer_set::ClientPool;
|
use crate::client_pool::ClientPool;
|
||||||
|
|
||||||
pub struct ClientPoolGuard<N: NetworkZone> {
|
pub struct ClientPoolGuard<N: NetworkZone> {
|
||||||
pub(super) pool: Arc<ClientPool<N>>,
|
pub(super) pool: Arc<ClientPool<N>>,
|
|
@ -1,15 +1,6 @@
|
||||||
use cuprate_helper::network::Network;
|
|
||||||
use monero_address_book::AddressBookConfig;
|
|
||||||
|
|
||||||
/// P2P config.
|
/// P2P config.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct P2PConfig {
|
pub struct P2PConfig {
|
||||||
pub p2p_port: u16,
|
|
||||||
|
|
||||||
pub rpc_port: u16,
|
|
||||||
|
|
||||||
pub network: Network,
|
|
||||||
|
|
||||||
/// The number of outbound connections to make and try keep.
|
/// The number of outbound connections to make and try keep.
|
||||||
pub outbound_connections: usize,
|
pub outbound_connections: usize,
|
||||||
/// The absolute maximum number of held outbound connections.
|
/// The absolute maximum number of held outbound connections.
|
||||||
|
@ -18,21 +9,10 @@ pub struct P2PConfig {
|
||||||
/// to get peers from that node, these connections are not held for long though.
|
/// to get peers from that node, these connections are not held for long though.
|
||||||
pub max_outbound_connections: usize,
|
pub max_outbound_connections: usize,
|
||||||
|
|
||||||
/// The number of anchor connections to make.
|
|
||||||
///
|
|
||||||
/// An anchor connection is a connection which was held before last shutdown, anchor connections
|
|
||||||
/// help to prevent certain attacks.
|
|
||||||
pub anchor_connections: usize,
|
|
||||||
|
|
||||||
/// The percent of outbound peers that should be gray aka never connected to before.
|
/// The percent of outbound peers that should be gray aka never connected to before.
|
||||||
///
|
///
|
||||||
/// Only values 0..=1 are valid.
|
/// Only values 0..=1 are valid.
|
||||||
pub gray_peers_percent: f64,
|
pub gray_peers_percent: f64,
|
||||||
|
|
||||||
/// The maximum amount of inbound peers
|
|
||||||
pub max_inbound_connections: usize,
|
|
||||||
|
|
||||||
pub address_book_config: AddressBookConfig,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl P2PConfig {
|
impl P2PConfig {
|
||||||
|
|
|
@ -21,11 +21,11 @@ use monero_p2p::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
client_pool::ClientPool,
|
||||||
config::P2PConfig,
|
config::P2PConfig,
|
||||||
constants::{
|
constants::{
|
||||||
HANDSHAKE_TIMEOUT, MAX_SEED_CONNECTIONS, OUTBOUND_CONNECTION_TIMEOUT, PEER_FIND_TIMEOUT,
|
HANDSHAKE_TIMEOUT, MAX_SEED_CONNECTIONS, OUTBOUND_CONNECTION_TIMEOUT, PEER_FIND_TIMEOUT,
|
||||||
},
|
},
|
||||||
peer_set::ClientPool,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum OutboundConnectorError {
|
enum OutboundConnectorError {
|
||||||
|
@ -47,9 +47,9 @@ pub struct MakeConnectionRequest {
|
||||||
///
|
///
|
||||||
/// This handles maintaining a minimum number of connections and making extra connections when needed, upto a maximum.
|
/// This handles maintaining a minimum number of connections and making extra connections when needed, upto a maximum.
|
||||||
pub struct OutboundConnectionKeeper<N: NetworkZone, A, C> {
|
pub struct OutboundConnectionKeeper<N: NetworkZone, A, C> {
|
||||||
/// TODO.
|
/// The pool of currently connected peers.
|
||||||
pub client_pool: Arc<ClientPool<N>>,
|
pub client_pool: Arc<ClientPool<N>>,
|
||||||
/// The channel that tells us to make new outbound connections
|
/// The channel that tells us to make new _extra_ outbound connections.
|
||||||
pub make_connection_rx: mpsc::Receiver<MakeConnectionRequest>,
|
pub make_connection_rx: mpsc::Receiver<MakeConnectionRequest>,
|
||||||
/// The address book service
|
/// The address book service
|
||||||
pub address_book_svc: A,
|
pub address_book_svc: A,
|
||||||
|
@ -58,7 +58,7 @@ pub struct OutboundConnectionKeeper<N: NetworkZone, A, C> {
|
||||||
/// A semaphore to keep the amount of outbound peers constant.
|
/// A semaphore to keep the amount of outbound peers constant.
|
||||||
pub outbound_semaphore: Arc<Semaphore>,
|
pub outbound_semaphore: Arc<Semaphore>,
|
||||||
/// The amount of peers we connected to because we needed more peers. If the `outbound_semaphore`
|
/// The amount of peers we connected to because we needed more peers. If the `outbound_semaphore`
|
||||||
/// is full, and we need to connect to more peers for blocks ro because not enough peers are ready
|
/// is full, and we need to connect to more peers for blocks or because not enough peers are ready
|
||||||
/// we add a permit to the semaphore and keep track here, upto a value in config.
|
/// we add a permit to the semaphore and keep track here, upto a value in config.
|
||||||
pub extra_peers: usize,
|
pub extra_peers: usize,
|
||||||
/// The p2p config.
|
/// The p2p config.
|
||||||
|
|
|
@ -2,44 +2,8 @@ use std::time::Duration;
|
||||||
|
|
||||||
pub(crate) const HANDSHAKE_TIMEOUT: Duration = Duration::from_secs(30);
|
pub(crate) const HANDSHAKE_TIMEOUT: Duration = Duration::from_secs(30);
|
||||||
|
|
||||||
pub(crate) const CHAIN_REQUEST_TIMEOUT: Duration = Duration::from_secs(10);
|
|
||||||
|
|
||||||
pub(crate) const BLOCK_REQUEST_TIMEOUT: Duration = Duration::from_secs(20);
|
|
||||||
|
|
||||||
pub(crate) const BLOCK_REQUEST_TIMEOUT_INTERVAL: Duration = Duration::from_secs(5);
|
|
||||||
|
|
||||||
pub(crate) const SEED_CONNECTION_RETRY_TIMEOUT: Duration = Duration::from_secs(60);
|
|
||||||
|
|
||||||
pub(crate) const CONCURRENT_PEER_LIST_REQUESTS: usize = 3;
|
|
||||||
|
|
||||||
pub(crate) const MAX_SEED_CONNECTIONS: usize = 3;
|
pub(crate) const MAX_SEED_CONNECTIONS: usize = 3;
|
||||||
|
|
||||||
pub(crate) const PEER_FIND_TIMEOUT: Duration = Duration::from_secs(30);
|
pub(crate) const PEER_FIND_TIMEOUT: Duration = Duration::from_secs(30);
|
||||||
|
|
||||||
pub(crate) const OUTBOUND_CONNECTION_TIMEOUT: Duration = Duration::from_secs(10);
|
pub(crate) const OUTBOUND_CONNECTION_TIMEOUT: Duration = Duration::from_secs(5);
|
||||||
|
|
||||||
/// The duration of a short ban (1 hour).
|
|
||||||
pub(crate) const SHORT_BAN: Duration = Duration::from_secs(60 * 60);
|
|
||||||
|
|
||||||
/// The duration of a medium ban (24 hours).
|
|
||||||
pub(crate) const MEDIUM_BAN: Duration = Duration::from_secs(60 * 60 * 24);
|
|
||||||
|
|
||||||
pub(crate) const DIFFUSION_FLUSH_AVERAGE_SECONDS_INBOUND: Duration = Duration::from_secs(5);
|
|
||||||
|
|
||||||
pub(crate) const DIFFUSION_FLUSH_AVERAGE_SECONDS_OUTBOUND: Duration = Duration::from_millis(2500);
|
|
||||||
|
|
||||||
pub(crate) const SOFT_TX_MESSAGE_SIZE_SIZE_LIMIT: usize = 1024 * 1024 * 60;
|
|
||||||
|
|
||||||
/// The limit on the amount of transactions kept in the broadcast channel.
|
|
||||||
///
|
|
||||||
/// A transaction is kept in the broadcast channel until all nodes have broadcast it.
|
|
||||||
///
|
|
||||||
/// Because of internal implementation details this limit will ALWAYS be hit i.e. a tx will stay in the
|
|
||||||
/// channel until [`MAX_TXS_IN_BROADCAST_CHANNEL`] more txs are added.
|
|
||||||
pub(crate) const MAX_TXS_IN_BROADCAST_CHANNEL: usize = 50;
|
|
||||||
|
|
||||||
pub(crate) const INCOMING_BLOCKS_CACHE_SIZE: usize = 10 * 1024 * 1024;
|
|
||||||
|
|
||||||
pub(crate) const NUMBER_OF_BLOCKS_TO_REQUEST: usize = 100;
|
|
||||||
|
|
||||||
pub(crate) const CHAIN_REQUESTS_TO_SEND: usize = 2;
|
|
||||||
|
|
|
@ -10,9 +10,9 @@
|
||||||
|
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
|
mod client_pool;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod connection_maintainer;
|
pub mod connection_maintainer;
|
||||||
mod constants;
|
mod constants;
|
||||||
mod peer_set;
|
|
||||||
|
|
||||||
pub use config::P2PConfig;
|
pub use config::P2PConfig;
|
||||||
|
|
Loading…
Reference in a new issue