Skip to content

Commit 9a63f5f

Browse files
committed
add comments + fmt
1 parent 2bdaae9 commit 9a63f5f

File tree

7 files changed

+30
-18
lines changed

7 files changed

+30
-18
lines changed

binaries/cuprated/src/config.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ mod tracing_config;
4242
mod macros;
4343
mod default;
4444

45-
pub use crate::config::p2p::p2p_port;
4645
use fs::FileSystemConfig;
47-
use p2p::P2PConfig;
46+
pub use p2p::{p2p_port, P2PConfig};
4847
use rayon::RayonConfig;
4948
pub use rpc::{restricted_rpc_port, unrestricted_rpc_port, RpcConfig};
5049
pub use storage::{StorageConfig, TxpoolConfig};

binaries/cuprated/src/config/default.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
use serde::{Deserialize, Serialize};
22

3+
/// An enum that can be either a default value or a custom value.
4+
///
5+
/// Useful when config value's defaults depend on other values, i.e. the default ports to listen on
6+
/// depend on the network chosen.
7+
///
8+
/// The [`DefaultOrCustom::Default`] variant will be serialised as a string: "Default",
9+
/// [`DefaultOrCustom::Custom`] will just use the serialisation of the inner value.
310
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
411
pub enum DefaultOrCustom<T> {
512
Default,

binaries/cuprated/src/config/p2p.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ use cuprate_p2p_core::{
2121
use cuprate_p2p_transport::{Arti, ArtiClientConfig, ArtiServerConfig};
2222
use cuprate_wire::OnionAddr;
2323

24-
use super::macros::config_struct;
25-
use crate::config::default::DefaultOrCustom;
2624
use crate::{p2p::ProxySettings, tor::TorMode};
2725

26+
use super::{default::DefaultOrCustom, macros::config_struct};
27+
2828
config_struct! {
2929
/// P2P config.
3030
#[derive(Debug, Default, Deserialize, Serialize, PartialEq)]
@@ -259,6 +259,7 @@ config_struct! {
259259
}
260260
}
261261

262+
/// Gets the port to listen on for p2p connections.
262263
pub const fn p2p_port(setting: DefaultOrCustom<u16>, network: Network) -> u16 {
263264
match setting {
264265
DefaultOrCustom::Default => match network {
@@ -271,7 +272,8 @@ pub const fn p2p_port(setting: DefaultOrCustom<u16>, network: Network) -> u16 {
271272
}
272273

273274
impl ClearNetConfig {
274-
pub fn tor_transport_config(&self, network: Network) -> TransportConfig<ClearNet, Tcp> {
275+
/// Gets the transport config for [`ClearNet`] over [`Tcp`].
276+
pub fn tcp_transport_config(&self, network: Network) -> TransportConfig<ClearNet, Tcp> {
275277
let server_config = if self.enable_inbound {
276278
let mut sc = TcpServerConfig::default();
277279
sc.ipv4 = Some(self.listen_on);

binaries/cuprated/src/config/rpc.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
use crate::config::default::DefaultOrCustom;
2-
use crate::config::macros::config_struct;
3-
use cuprate_helper::network::Network;
4-
use serde::{Deserialize, Serialize};
5-
use std::net::IpAddr;
61
use std::{
7-
net::{Ipv4Addr, SocketAddr, SocketAddrV4},
2+
net::{IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4},
83
time::Duration,
94
};
105

6+
use serde::{Deserialize, Serialize};
7+
8+
use cuprate_helper::network::Network;
9+
10+
use super::{default::DefaultOrCustom, macros::config_struct};
11+
1112
config_struct! {
1213
/// RPC config.
1314
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
@@ -28,14 +29,14 @@ config_struct! {
2829
/// The address the RPC server will listen on.
2930
///
3031
/// Type | IPv4/IPv6 address
31-
/// Examples | "", "127.0.0.1:18081", "192.168.1.50:18085"
32+
/// Examples | "", "127.0.0.1", "192.168.1.50"
3233
pub address: IpAddr,
3334

3435
/// The port the RPC server will listen on.
3536
///
3637
/// Type | Number
3738
/// Valid values | 0..65534
38-
/// Examples | 18080, 9999, 5432
39+
/// Examples | 18081, 18089, 5432
3940
pub port: DefaultOrCustom<u16>,
4041

4142
/// Toggle the RPC server.
@@ -118,6 +119,7 @@ impl Default for RestrictedRpcConfig {
118119
}
119120
}
120121

122+
/// Gets the port to listen on for restricted RPC connections.
121123
pub const fn restricted_rpc_port(config: DefaultOrCustom<u16>, network: Network) -> u16 {
122124
match config {
123125
DefaultOrCustom::Default => match network {
@@ -129,6 +131,7 @@ pub const fn restricted_rpc_port(config: DefaultOrCustom<u16>, network: Network)
129131
}
130132
}
131133

134+
/// Gets the port to listen on for unrestricted RPC connections.
132135
pub const fn unrestricted_rpc_port(config: DefaultOrCustom<u16>, network: Network) -> u16 {
133136
match config {
134137
DefaultOrCustom::Default => match network {

binaries/cuprated/src/p2p.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub async fn initialize_zones_p2p(
110110
context_svc.clone(),
111111
txpool_read_handle.clone(),
112112
config.clearnet_p2p_config(),
113-
config.p2p.clear_net.tor_transport_config(config.network),
113+
config.p2p.clear_net.tcp_transport_config(config.network),
114114
)
115115
.await
116116
.unwrap()

binaries/cuprated/src/rpc/server.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ use cuprate_helper::network::Network;
1717
use cuprate_rpc_interface::{RouterBuilder, RpcHandler};
1818
use cuprate_txpool::service::TxpoolReadHandle;
1919

20-
use crate::config::{restricted_rpc_port, unrestricted_rpc_port};
2120
use crate::{
22-
config::RpcConfig,
21+
config::{restricted_rpc_port, unrestricted_rpc_port, RpcConfig},
2322
rpc::{rpc_handler::BlockchainManagerHandle, CupratedRpcHandler},
2423
txpool::IncomingTxHandler,
2524
};

binaries/cuprated/src/tor.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ use cuprate_p2p_transport::{
2525
};
2626
use cuprate_wire::OnionAddr;
2727

28-
use crate::config::p2p_port;
29-
use crate::{config::Config, p2p::ProxySettings};
28+
use crate::{
29+
config::{p2p_port, Config},
30+
p2p::ProxySettings,
31+
};
3032
//---------------------------------------------------------------------------------------------------- Initialization
3133

3234
#[derive(Clone, Default, Debug, Copy, PartialEq, Eq, Serialize, Deserialize)]

0 commit comments

Comments
 (0)