-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathargs.rs
248 lines (201 loc) · 7.65 KB
/
args.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
// Copyright 2024 The Tari Project
// SPDX-License-Identifier: BSD-3-Clause
use std::{path::PathBuf, sync::Arc};
use clap::{Parser, Subcommand};
use tari_shutdown::ShutdownSignal;
use crate::cli::{
commands,
util::{cli_styles, validate_squad},
};
#[allow(clippy::struct_excessive_bools)]
#[derive(Clone, Parser, Debug)]
pub struct StartArgs {
/// (Optional) base dir.
#[arg(short, long, value_name = "base-dir")]
pub base_dir: Option<PathBuf>,
/// (Optional) gRPC port to use.
#[arg(short, long, value_name = "grpc-port")]
pub grpc_port: Option<u16>,
/// (Optional) p2p port to use. It is used to connect p2pool nodes.
#[arg(short, long, value_name = "p2p-port")]
pub p2p_port: Option<u16>,
/// (Optional) stats server port to use.
#[arg(long, value_name = "stats-server-port")]
pub stats_server_port: Option<u16>,
/// (Optional) External address to listen on.
#[arg(long, value_name = "external-address")]
pub external_address: Option<String>,
/// (Optional) Address of the Tari base node.
#[arg(long, value_name = "base-node-address", default_value = "http://127.0.0.1:18182")]
pub base_node_address: String,
/// (Optional) seed peers.
/// Any amount of seed peers can be added to join a p2pool network.
///
/// Please note that these addresses must be in libp2p multi address format and must contain peer ID
/// or use a dnsaddr multi address!
///
/// By default a Tari provided seed peer is added.
///
/// e.g.:
/// /ip4/127.0.0.1/tcp/52313/p2p/12D3KooWCUNCvi7PBPymgsHx39JWErYdSoT3EFPrn3xoVff4CHFu
/// /dnsaddr/esmeralda.sha-p2pool.tari.com
#[arg(short, long, value_name = "seed-peers")]
pub seed_peers: Option<Vec<String>>,
/// If set, Tari provided seed peers will NOT be automatically added to seed peers list.
#[arg(long, value_name = "no-default-seed-peers", default_value_t = false)]
pub no_default_seed_peers: bool,
/// Starts the node as a stable peer.
///
/// Identity of the peer will be saved locally (to --private-key-location)
/// and ID of the Peer remains the same.
#[arg(long, value_name = "stable-peer", default_value_t = false)]
pub stable_peer: bool,
/// Squad to enter (a team of miners).
/// A squad can have any name.
#[arg(
long, default_value = "default", value_parser = validate_squad
)]
pub squad_prefix: String,
#[arg(long)]
pub squad_override: Option<String>,
#[arg(long, value_name = "num-squads", default_value = "1")]
pub num_squads: usize,
/// Private key folder.
///
/// Needs --stable-peer to be set.
#[arg(
long,
value_name = "private-key-folder",
requires = "stable_peer",
default_value = "."
)]
pub private_key_folder: PathBuf,
#[arg(long, default_value_t = false)]
pub is_seed_peer: bool,
/// mDNS disabled
///
/// If set, mDNS local peer discovery is disabled.
#[arg(long, value_name = "mdns-disabled", default_value_t = false)]
pub mdns_disabled: bool,
/// Relay Server - Default is set to false. If the node
/// has an external address, it will relay
#[arg(long, value_name = "relay-server-disabled", default_value_t = false)]
pub relay_server_disabled: bool,
/// Relay Server Max Circuits
#[arg(long, value_name = "relay-server-max-circuits")]
pub relay_server_max_circuits: Option<usize>,
/// Relay Server Max Circuits per peer
#[arg(long, value_name = "relay-server-max-circuits-per-peer")]
pub relay_server_max_circuits_per_peer: Option<usize>,
/// HTTP server disabled
///
/// If set, local HTTP server (stats, health-check, status etc...) is disabled.
#[arg(long, value_name = "http-server-disabled", default_value_t = false)]
pub http_server_disabled: bool,
#[arg(long, value_name = "user-agent")]
pub user_agent: Option<String>,
#[arg(long)]
pub peer_publish_interval: Option<u64>,
#[arg(long)]
pub debug_print_chain: bool,
/// If set, basic connectivity statistics about seeds and normal peers will be collected and printed to a csv file.
#[arg(long, short, alias = "diag")]
pub diagnostic_mode: bool,
#[arg(long)]
pub max_connections: Option<u32>,
#[arg(long, default_value_t = false)]
pub randomx_disabled: bool,
#[arg(long, default_value_t = false)]
pub sha3x_disabled: bool,
#[arg(long, value_name = "bt")]
pub block_time: Option<u64>,
#[arg(long, value_name = "sw")]
pub share_window: Option<u64>,
/// Export libp2p info to a file - useful for testing where file handshake is required, e.g. cucumber.
#[arg(long)]
pub export_libp2p_info: Option<PathBuf>,
/// Amount of time the node will wait before assuming the network has been synced, before submitting mined blocks.
#[arg(long)]
pub network_silence_delay: Option<u16>,
/// Minimum SHA3 target difficulty.
#[arg(long)]
pub minimum_sha3_target_difficulty: Option<u64>,
/// Minimum RandomX target difficulty.
#[arg(long)]
pub minimum_randomx_target_difficulty: Option<u64>,
}
#[derive(Clone, Parser, Debug)]
pub struct ListSquadArgs {
/// List squad command timeout in seconds.
///
/// The list-squads commands tries to look for all the currently available squads
/// for this amount of time maximum.
#[arg(long, value_name = "timeout", default_value_t = 15)]
pub timeout: u64,
}
#[derive(Subcommand, Clone, Debug)]
pub enum Commands {
/// Starts sha-p2pool node.
Start {
#[clap(flatten)]
args: StartArgs,
},
/// Generating new identity.
GenerateIdentity,
/// Listing all squads that are present on the network.
ListSquads {
#[clap(flatten)]
args: StartArgs,
#[clap(flatten)]
list_squad_args: ListSquadArgs,
},
}
#[derive(Clone, Debug, Parser)]
#[command(version)]
#[command(styles = cli_styles())]
#[command(about = "⛏ Decentralized mining pool for Tari network ⛏", long_about = None)]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
}
impl Cli {
pub fn base_dir(&self) -> PathBuf {
match &self.command {
Commands::Start { args } => args
.base_dir
.clone()
.unwrap_or_else(|| dirs::home_dir().unwrap().join(".tari/p2pool")),
Commands::GenerateIdentity => dirs::home_dir().unwrap().join(".tari/p2pool"),
Commands::ListSquads {
args,
list_squad_args: _list_squad_args,
} => args
.base_dir
.clone()
.unwrap_or_else(|| dirs::home_dir().unwrap().join(".tari/p2pool")),
}
}
/// Handles CLI command.
/// [`Cli::parse`] must be called (to have all the args and params set properly)
/// before calling this method.
pub async fn handle_command(&self, cli_shutdown: ShutdownSignal) -> anyhow::Result<()> {
let cli_ref = Arc::new(self.clone());
run_with_cli(&self.command, cli_ref, cli_shutdown).await?;
Ok(())
}
}
/// Run with provided CLI command.
pub async fn run_with_cli(command: &Commands, cli_ref: Arc<Cli>, cli_shutdown: ShutdownSignal) -> anyhow::Result<()> {
match command {
Commands::Start { args } => {
commands::handle_start(cli_ref.clone(), args, cli_shutdown.clone()).await?;
},
Commands::GenerateIdentity => {
commands::handle_generate_identity().await?;
},
Commands::ListSquads { args, list_squad_args } => {
commands::handle_list_squads(cli_ref.clone(), args, list_squad_args, cli_shutdown.clone()).await?;
},
}
Ok(())
}