-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
112 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,51 @@ | ||
use cuprate_helper::network::Network; | ||
use monero_address_book::AddressBookConfig; | ||
use monero_p2p::NetworkZone; | ||
use monero_wire::common::PeerSupportFlags; | ||
use monero_wire::BasicNodeData; | ||
|
||
/// P2P config. | ||
#[derive(Clone, Debug)] | ||
pub struct P2PConfig { | ||
pub struct P2PConfig<N: NetworkZone> { | ||
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, | ||
|
||
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`]. | ||
pub(crate) fn basic_node_data(&self) -> BasicNodeData { | ||
BasicNodeData { | ||
my_port: self.p2p_port as u32, | ||
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, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters