Merge branch 'clap-v3' into 'main'
Upgrade to clap 3 Closes #616 See merge request tpo/core/arti!830
This commit is contained in:
commit
4f893648b8
|
@ -49,15 +49,6 @@ dependencies = [
|
|||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ansi_term"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.66"
|
||||
|
@ -646,17 +637,26 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "2.34.0"
|
||||
version = "3.2.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c"
|
||||
checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5"
|
||||
dependencies = [
|
||||
"ansi_term",
|
||||
"atty",
|
||||
"bitflags",
|
||||
"strsim 0.8.0",
|
||||
"clap_lex",
|
||||
"indexmap",
|
||||
"strsim",
|
||||
"termcolor",
|
||||
"textwrap",
|
||||
"unicode-width",
|
||||
"vec_map",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5"
|
||||
dependencies = [
|
||||
"os_str_bytes",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -861,7 +861,7 @@ dependencies = [
|
|||
"ident_case",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"strsim 0.10.0",
|
||||
"strsim",
|
||||
"syn",
|
||||
]
|
||||
|
||||
|
@ -875,7 +875,7 @@ dependencies = [
|
|||
"ident_case",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"strsim 0.10.0",
|
||||
"strsim",
|
||||
"syn",
|
||||
]
|
||||
|
||||
|
@ -1628,6 +1628,16 @@ dependencies = [
|
|||
"unicode-normalization",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "inotify"
|
||||
version = "0.9.6"
|
||||
|
@ -2171,6 +2181,12 @@ dependencies = [
|
|||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "os_str_bytes"
|
||||
version = "6.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3baf96e39c5359d2eb0dd6ccb42c62b91d9678aa68160d261b9e0ccbf9e9dea9"
|
||||
|
||||
[[package]]
|
||||
name = "overload"
|
||||
version = "0.1.1"
|
||||
|
@ -3129,12 +3145,6 @@ dependencies = [
|
|||
"rand 0.8.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.10.0"
|
||||
|
@ -3228,12 +3238,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "textwrap"
|
||||
version = "0.11.0"
|
||||
version = "0.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
|
||||
dependencies = [
|
||||
"unicode-width",
|
||||
]
|
||||
checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d"
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
|
@ -4227,12 +4234,6 @@ dependencies = [
|
|||
"tinyvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.4"
|
||||
|
@ -4294,12 +4295,6 @@ version = "0.2.15"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||
|
||||
[[package]]
|
||||
name = "vec_map"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.4"
|
||||
|
|
|
@ -15,7 +15,7 @@ repository = "https://gitlab.torproject.org/tpo/core/arti.git/"
|
|||
anyhow = "1.0.23"
|
||||
arti = { path = "../arti", version = "1.0.1" }
|
||||
arti-client = { package = "arti-client", path = "../arti-client", version = "0.7.0" }
|
||||
clap = "2.33.0"
|
||||
clap = "3.2.20"
|
||||
float-ord = "0.3"
|
||||
fs-mistrust = { path = "../fs-mistrust", version = "0.5.0" }
|
||||
futures = "0.3.14"
|
||||
|
|
|
@ -46,12 +46,13 @@
|
|||
use anyhow::{anyhow, Result};
|
||||
use arti::cfg::ArtiCombinedConfig;
|
||||
use arti_client::{IsolationToken, TorAddr, TorClient, TorClientConfig};
|
||||
use clap::{App, Arg};
|
||||
use clap::{value_parser, Arg, ArgAction};
|
||||
use futures::StreamExt;
|
||||
use rand::distributions::Standard;
|
||||
use rand::Rng;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use std::ffi::OsString;
|
||||
use std::fmt;
|
||||
use std::fmt::Formatter;
|
||||
use std::future::Future;
|
||||
|
@ -281,83 +282,84 @@ async fn client<S: AsyncRead + AsyncWrite + Unpin>(
|
|||
fn main() -> Result<()> {
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
let matches = App::new("arti-bench")
|
||||
let matches = clap::Command::new("arti-bench")
|
||||
.version(env!("CARGO_PKG_VERSION"))
|
||||
.author("The Tor Project Developers")
|
||||
.about("A simple benchmarking utility for Arti.")
|
||||
.arg(
|
||||
Arg::with_name("arti-config")
|
||||
.short("c")
|
||||
Arg::new("arti-config")
|
||||
.short('c')
|
||||
.long("arti-config")
|
||||
.takes_value(true)
|
||||
.action(ArgAction::Set)
|
||||
.required(true)
|
||||
.value_name("CONFIG")
|
||||
.value_parser(value_parser!(OsString))
|
||||
.help(
|
||||
"Path to the Arti configuration to use (usually, a Chutney-generated config).",
|
||||
),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("num-samples")
|
||||
.short("s")
|
||||
Arg::new("num-samples")
|
||||
.short('s')
|
||||
.long("num-samples")
|
||||
.takes_value(true)
|
||||
.required(true)
|
||||
.action(ArgAction::Set)
|
||||
.value_name("COUNT")
|
||||
.value_parser(value_parser!(usize))
|
||||
.default_value("3")
|
||||
.help("How many samples to take per benchmark run.")
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("num-streams")
|
||||
.short("p")
|
||||
Arg::new("num-streams")
|
||||
.short('p')
|
||||
.long("streams")
|
||||
.aliases(&["num-parallel"])
|
||||
.takes_value(true)
|
||||
.required(true)
|
||||
.action(ArgAction::Set)
|
||||
.value_name("COUNT")
|
||||
.value_parser(value_parser!(usize))
|
||||
.default_value("3")
|
||||
.help("How many simultaneous streams per circuit.")
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("num-circuits")
|
||||
.short("C")
|
||||
Arg::new("num-circuits")
|
||||
.short('C')
|
||||
.long("num-circuits")
|
||||
.takes_value(true)
|
||||
.required(false)
|
||||
.action(ArgAction::Set)
|
||||
.value_name("COUNT")
|
||||
.value_parser(value_parser!(usize))
|
||||
.default_value("1")
|
||||
.help("How many simultaneous circuits per run.")
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("output")
|
||||
.short("o")
|
||||
.takes_value(true)
|
||||
Arg::new("output")
|
||||
.short('o')
|
||||
.action(ArgAction::Set)
|
||||
.value_name("/path/to/output.json")
|
||||
.help("A path to write benchmark results to, in JSON format.")
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("download-bytes")
|
||||
.short("d")
|
||||
Arg::new("download-bytes")
|
||||
.short('d')
|
||||
.long("download-bytes")
|
||||
.takes_value(true)
|
||||
.required(true)
|
||||
.action(ArgAction::Set)
|
||||
.value_name("SIZE")
|
||||
.value_parser(value_parser!(usize))
|
||||
.default_value("10485760")
|
||||
.help("How much fake payload data to generate for the download benchmark."),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("upload-bytes")
|
||||
.short("u")
|
||||
Arg::new("upload-bytes")
|
||||
.short('u')
|
||||
.long("upload-bytes")
|
||||
.takes_value(true)
|
||||
.required(true)
|
||||
.action(ArgAction::Set)
|
||||
.value_name("SIZE")
|
||||
.value_parser(value_parser!(usize))
|
||||
.default_value("10485760")
|
||||
.help("How much fake payload data to generate for the upload benchmark."),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("socks-proxy")
|
||||
Arg::new("socks-proxy")
|
||||
.long("socks5")
|
||||
.takes_value(true)
|
||||
.action(ArgAction::Set)
|
||||
.value_name("addr:port")
|
||||
.help("SOCKS5 proxy address for a node to benchmark through as well (usually a Chutney node). Optional."),
|
||||
)
|
||||
|
@ -365,7 +367,7 @@ fn main() -> Result<()> {
|
|||
info!("Parsing Arti configuration...");
|
||||
let mut config_sources = ConfigurationSources::new_empty();
|
||||
matches
|
||||
.values_of_os("arti-config")
|
||||
.get_many::<OsString>("arti-config")
|
||||
.unwrap_or_default()
|
||||
.for_each(|f| {
|
||||
config_sources.push_source(
|
||||
|
@ -386,14 +388,11 @@ fn main() -> Result<()> {
|
|||
let local_addr = listener.local_addr()?;
|
||||
let connect_addr = SocketAddr::new(IpAddr::from_str("127.0.0.1").unwrap(), local_addr.port());
|
||||
info!("Bound to {}.", local_addr);
|
||||
let upload_bytes = matches.value_of("upload-bytes").unwrap().parse::<usize>()?;
|
||||
let download_bytes = matches
|
||||
.value_of("download-bytes")
|
||||
.unwrap()
|
||||
.parse::<usize>()?;
|
||||
let samples = matches.value_of("num-samples").unwrap().parse::<usize>()?;
|
||||
let streams_per_circ = matches.value_of("num-streams").unwrap().parse::<usize>()?;
|
||||
let circs_per_sample = matches.value_of("num-circuits").unwrap().parse::<usize>()?;
|
||||
let upload_bytes = *matches.get_one::<usize>("upload-bytes").unwrap();
|
||||
let download_bytes = *matches.get_one::<usize>("download-bytes").unwrap();
|
||||
let samples = *matches.get_one::<usize>("num-samples").unwrap();
|
||||
let streams_per_circ = *matches.get_one::<usize>("num-streams").unwrap();
|
||||
let circs_per_sample = *matches.get_one::<usize>("num-circuits").unwrap();
|
||||
info!("Generating test payloads, please wait...");
|
||||
let upload_payload = random_payload(upload_bytes).into();
|
||||
let download_payload = random_payload(download_bytes).into();
|
||||
|
@ -421,7 +420,7 @@ fn main() -> Result<()> {
|
|||
};
|
||||
|
||||
benchmark.without_arti()?;
|
||||
if let Some(addr) = matches.value_of("socks-proxy") {
|
||||
if let Some(addr) = matches.get_one::<String>("socks-proxy") {
|
||||
benchmark.with_proxy(addr)?;
|
||||
}
|
||||
benchmark.with_arti(tcc)?;
|
||||
|
@ -439,7 +438,7 @@ fn main() -> Result<()> {
|
|||
info!(" TTFB (down): {} msec", results.download_ttfb_msec);
|
||||
}
|
||||
|
||||
if let Some(output) = matches.value_of("output") {
|
||||
if let Some(output) = matches.get_one::<String>("output") {
|
||||
info!("Writing benchmark results to {}...", output);
|
||||
let file = std::fs::File::create(output)?;
|
||||
serde_json::to_writer(
|
||||
|
|
|
@ -22,7 +22,7 @@ arti-client = { package = "arti-client", path = "../arti-client", version = "0.7
|
|||
] }
|
||||
async-trait = "0.1.2"
|
||||
cfg-if = "1.0.0"
|
||||
clap = "2.33.0"
|
||||
clap = "3.2.20"
|
||||
config = { version = "0.13", default-features = false }
|
||||
futures = "0.3.14"
|
||||
pin-project = "1"
|
||||
|
|
|
@ -4,129 +4,129 @@ use crate::rt::badtcp::ConditionalAction;
|
|||
use crate::{Action, Job, TcpBreakage};
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
use clap::{App, AppSettings, Arg, SubCommand};
|
||||
use clap::{value_parser, Arg, ArgAction, Command};
|
||||
use std::ffi::OsString;
|
||||
use std::str::FromStr;
|
||||
use std::time::Duration;
|
||||
|
||||
use tor_config::{ConfigurationSource, ConfigurationSources};
|
||||
|
||||
/// Helper: parse an optional string as a number of seconds.
|
||||
fn int_str_to_secs(s: Option<&str>) -> Result<Option<Duration>> {
|
||||
match s {
|
||||
Some(s) => Ok(Some(Duration::from_secs(s.parse()?))),
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
/// Parse the command line into a Job description.
|
||||
pub(crate) fn parse_cmdline() -> Result<Job> {
|
||||
let matches = App::new("Arti testing tool")
|
||||
let matches = Command::new("Arti testing tool")
|
||||
.version(env!("CARGO_PKG_VERSION"))
|
||||
.author("The Tor Project Developers")
|
||||
.about("Testing program for unusual arti behaviors")
|
||||
// HACK: see note in arti/src/main.rs
|
||||
.usage("arti-testing <SUBCOMMAND> [OPTIONS]")
|
||||
.override_usage("arti-testing <SUBCOMMAND> [OPTIONS]")
|
||||
.arg(
|
||||
Arg::with_name("config-files")
|
||||
.short("c")
|
||||
Arg::new("config-files")
|
||||
.short('c')
|
||||
.long("config")
|
||||
.takes_value(true)
|
||||
.action(ArgAction::Set)
|
||||
.value_name("FILE")
|
||||
.multiple(true)
|
||||
.value_parser(value_parser!(OsString))
|
||||
.action(ArgAction::Append)
|
||||
.global(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("o")
|
||||
.takes_value(true)
|
||||
Arg::new("option")
|
||||
.short('o')
|
||||
.action(ArgAction::Set)
|
||||
.value_name("KEY=VALUE")
|
||||
.multiple(true)
|
||||
.action(ArgAction::Append)
|
||||
.global(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("log")
|
||||
.short("l")
|
||||
Arg::new("log")
|
||||
.short('l')
|
||||
.long("log")
|
||||
.takes_value(true)
|
||||
.action(ArgAction::Set)
|
||||
.value_name("FILTER")
|
||||
.default_value("debug")
|
||||
.global(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("timeout")
|
||||
Arg::new("timeout")
|
||||
.long("timeout")
|
||||
.takes_value(true)
|
||||
.action(ArgAction::Set)
|
||||
.value_name("SECS")
|
||||
.value_parser(value_parser!(u64))
|
||||
.default_value("30")
|
||||
.global(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("expect")
|
||||
Arg::new("expect")
|
||||
.long("expect")
|
||||
.takes_value(true)
|
||||
.action(ArgAction::Set)
|
||||
.value_name("success|failure|timeout")
|
||||
.global(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("tcp-failure")
|
||||
Arg::new("tcp-failure")
|
||||
.long("tcp-failure")
|
||||
.takes_value(true)
|
||||
.action(ArgAction::Set)
|
||||
.value_name("none|timeout|error|blackhole")
|
||||
.global(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("tcp-failure-on")
|
||||
Arg::new("tcp-failure-on")
|
||||
.long("tcp-failure-on")
|
||||
.takes_value(true)
|
||||
.action(ArgAction::Set)
|
||||
.value_name("all|v4|v6|non443")
|
||||
.global(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("tcp-failure-stage")
|
||||
Arg::new("tcp-failure-stage")
|
||||
.long("tcp-failure-stage")
|
||||
.takes_value(true)
|
||||
.action(ArgAction::Set)
|
||||
.value_name("bootstrap|connect")
|
||||
.global(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("tcp-failure-delay")
|
||||
Arg::new("tcp-failure-delay")
|
||||
.long("tcp-failure-delay")
|
||||
.takes_value(true)
|
||||
.action(ArgAction::Set)
|
||||
.value_name("SECS")
|
||||
.global(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("dir-filter")
|
||||
Arg::new("dir-filter")
|
||||
.long("dir-filter")
|
||||
.takes_value(true)
|
||||
.action(ArgAction::Set)
|
||||
.value_name("FILTER_NAME")
|
||||
.global(true),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("connect")
|
||||
Command::new("connect")
|
||||
.about("Try to bootstrap and connect to an address")
|
||||
.arg(
|
||||
Arg::with_name("target")
|
||||
Arg::new("target")
|
||||
.long("target")
|
||||
.takes_value(true)
|
||||
.action(ArgAction::Set)
|
||||
.value_name("ADDR:PORT")
|
||||
.required(true),
|
||||
.default_value("www.torproject.org:443"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("retry")
|
||||
Arg::new("retry")
|
||||
.long("retry")
|
||||
.takes_value(true)
|
||||
.action(ArgAction::Set)
|
||||
.value_name("DELAY")
|
||||
.required(false),
|
||||
.value_parser(value_parser!(u64)),
|
||||
),
|
||||
)
|
||||
.subcommand(SubCommand::with_name("bootstrap").about("Try to bootstrap only"))
|
||||
.setting(AppSettings::SubcommandRequiredElseHelp)
|
||||
.subcommand(Command::new("bootstrap").about("Try to bootstrap only"))
|
||||
.subcommand_required(true)
|
||||
.arg_required_else_help(true)
|
||||
.get_matches();
|
||||
|
||||
let config = {
|
||||
// TODO: this is mostly duplicate code.
|
||||
let mut cfg_sources = ConfigurationSources::new_empty();
|
||||
|
||||
let config_files = matches.values_of_os("config-files").unwrap_or_default();
|
||||
let config_files = matches
|
||||
.get_many::<OsString>("config-files")
|
||||
.unwrap_or_default();
|
||||
|
||||
if config_files.len() == 0 {
|
||||
// Not using the regular default here; we don't want interference
|
||||
|
@ -143,36 +143,45 @@ pub(crate) fn parse_cmdline() -> Result<Job> {
|
|||
}
|
||||
|
||||
matches
|
||||
.values_of("option")
|
||||
.get_many::<String>("option")
|
||||
.unwrap_or_default()
|
||||
.for_each(|s| cfg_sources.push_option(s));
|
||||
|
||||
cfg_sources
|
||||
};
|
||||
|
||||
let timeout =
|
||||
int_str_to_secs(matches.value_of("timeout"))?.unwrap_or_else(|| Duration::from_secs(30));
|
||||
let timeout = Duration::from_secs(
|
||||
*matches
|
||||
.get_one::<u64>("timeout")
|
||||
.expect("Failed to pick default timeout"),
|
||||
);
|
||||
|
||||
let console_log = matches.value_of("log").unwrap_or("debug").to_string();
|
||||
let console_log = matches
|
||||
.get_one::<String>("log")
|
||||
.expect("Failed to get default log level")
|
||||
.clone();
|
||||
|
||||
let expectation = matches
|
||||
.value_of("expect")
|
||||
.map(crate::Expectation::from_str)
|
||||
.get_one::<String>("expect")
|
||||
.map(|s| crate::Expectation::from_str(s.as_str()))
|
||||
.transpose()?;
|
||||
|
||||
let tcp_breakage = {
|
||||
let action = matches.value_of("tcp-failure").unwrap_or("none").parse()?;
|
||||
let action = matches
|
||||
.get_one::<String>("tcp-failure")
|
||||
.unwrap_or(&"none".to_string())
|
||||
.parse()?;
|
||||
let stage = matches
|
||||
.value_of("tcp-failure-stage")
|
||||
.unwrap_or("bootstrap")
|
||||
.get_one::<String>("tcp-failure-stage")
|
||||
.unwrap_or(&"bootstrap".to_string())
|
||||
.parse()?;
|
||||
let delay = matches
|
||||
.value_of("tcp-failure-delay")
|
||||
.get_one::<String>("tcp-failure-delay")
|
||||
.map(|d| d.parse().map(Duration::from_secs))
|
||||
.transpose()?;
|
||||
let when = matches
|
||||
.value_of("tcp-failure-on")
|
||||
.unwrap_or("all")
|
||||
.get_one::<String>("tcp-failure-on")
|
||||
.unwrap_or(&"all".to_string())
|
||||
.parse()?;
|
||||
let action = ConditionalAction { action, when };
|
||||
|
||||
|
@ -184,8 +193,8 @@ pub(crate) fn parse_cmdline() -> Result<Job> {
|
|||
};
|
||||
|
||||
let dir_filter = matches
|
||||
.value_of("dir-filter")
|
||||
.map(crate::dirfilter::new_filter)
|
||||
.get_one::<String>("dir-filter")
|
||||
.map(|s| crate::dirfilter::new_filter(s.as_str()))
|
||||
.transpose()?
|
||||
.unwrap_or_else(crate::dirfilter::nil_filter);
|
||||
|
||||
|
@ -193,10 +202,12 @@ pub(crate) fn parse_cmdline() -> Result<Job> {
|
|||
Action::Bootstrap
|
||||
} else if let Some(matches) = matches.subcommand_matches("connect") {
|
||||
let target = matches
|
||||
.value_of("target")
|
||||
.unwrap_or("www.torproject.org:443")
|
||||
.to_owned();
|
||||
let retry_delay = int_str_to_secs(matches.value_of("retry"))?;
|
||||
.get_one::<String>("target")
|
||||
.expect("Failed to set default connect target")
|
||||
.clone();
|
||||
let retry_delay = matches
|
||||
.get_one::<u64>("retry")
|
||||
.map(|d| Duration::from_secs(*d));
|
||||
|
||||
Action::Connect {
|
||||
target,
|
||||
|
|
|
@ -49,7 +49,7 @@ anyhow = "1.0.23"
|
|||
arti-client = { package = "arti-client", path = "../arti-client", version = "0.7.0", default-features = false }
|
||||
async-ctrlc = { version = "1.2.0", optional = true }
|
||||
cfg-if = "1.0.0"
|
||||
clap = "2.33.0"
|
||||
clap = "3.2.20"
|
||||
config = { version = "0.13", default-features = false, features = ["toml"] }
|
||||
derive_builder = { version = "0.11", package = "derive_builder_fork_arti" }
|
||||
educe = "0.4.6"
|
||||
|
|
|
@ -66,6 +66,7 @@ mod reload_cfg;
|
|||
#[cfg(not(feature = "experimental-api"))]
|
||||
mod socks;
|
||||
|
||||
use std::ffi::OsString;
|
||||
use std::fmt::Write;
|
||||
|
||||
pub use cfg::{
|
||||
|
@ -81,7 +82,7 @@ use tor_config::ConfigurationSources;
|
|||
use tor_rtcompat::{BlockOn, Runtime};
|
||||
|
||||
use anyhow::{Context, Error, Result};
|
||||
use clap::{App, AppSettings, Arg, SubCommand};
|
||||
use clap::{value_parser, Arg, ArgAction, Command};
|
||||
use tracing::{error, info, warn};
|
||||
|
||||
/// Shorthand for a boxed and pinned Future.
|
||||
|
@ -236,7 +237,7 @@ where
|
|||
);
|
||||
|
||||
let clap_app =
|
||||
App::new("Arti")
|
||||
Command::new("Arti")
|
||||
.version(env!("CARGO_PKG_VERSION"))
|
||||
.long_version(&long_version as &str)
|
||||
.author("The Tor Project Developers")
|
||||
|
@ -246,64 +247,66 @@ where
|
|||
// before the subcommand.
|
||||
// We just declare all options as `global` and then require them to be
|
||||
// put after the subcommand, hence this new usage string.
|
||||
.usage("arti <SUBCOMMAND> [OPTIONS]")
|
||||
.override_usage("arti <SUBCOMMAND> [OPTIONS]")
|
||||
.arg(
|
||||
Arg::with_name("config-files")
|
||||
.short("c")
|
||||
Arg::new("config-files")
|
||||
.short('c')
|
||||
.long("config")
|
||||
.takes_value(true)
|
||||
.action(ArgAction::Set)
|
||||
.value_name("FILE")
|
||||
.multiple(true)
|
||||
.value_parser(value_parser!(OsString))
|
||||
.action(ArgAction::Append)
|
||||
// NOTE: don't forget the `global` flag on all arguments declared at this level!
|
||||
.global(true)
|
||||
.help(&config_file_help),
|
||||
.help(config_file_help.as_str()),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("o")
|
||||
.takes_value(true)
|
||||
Arg::new("option")
|
||||
.short('o')
|
||||
.action(ArgAction::Set)
|
||||
.value_name("KEY=VALUE")
|
||||
.multiple(true)
|
||||
.action(ArgAction::Append)
|
||||
.global(true)
|
||||
.help("Override config file parameters, using TOML-like syntax."),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("loglevel")
|
||||
.short("l")
|
||||
Arg::new("loglevel")
|
||||
.short('l')
|
||||
.long("log-level")
|
||||
.global(true)
|
||||
.takes_value(true)
|
||||
.action(ArgAction::Set)
|
||||
.value_name("LEVEL")
|
||||
.help("Override the log level (usually one of 'trace', 'debug', 'info', 'warn', 'error')."),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("disable-fs-permission-checks")
|
||||
Arg::new("disable-fs-permission-checks")
|
||||
.long("disable-fs-permission-checks")
|
||||
.takes_value(false)
|
||||
.global(true)
|
||||
.action(ArgAction::SetTrue)
|
||||
.help("Don't check permissions on the files we use."),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("proxy")
|
||||
Command::new("proxy")
|
||||
.about(
|
||||
"Run Arti in SOCKS proxy mode, proxying connections through the Tor network.",
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("socks-port")
|
||||
.short("p")
|
||||
.takes_value(true)
|
||||
Arg::new("socks-port")
|
||||
.short('p')
|
||||
.action(ArgAction::Set)
|
||||
.value_name("PORT")
|
||||
.help("Port to listen on for SOCKS connections (overrides the port in the config if specified).")
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("dns-port")
|
||||
.short("d")
|
||||
.takes_value(true)
|
||||
Arg::new("dns-port")
|
||||
.short('d')
|
||||
.action(ArgAction::Set)
|
||||
.value_name("PORT")
|
||||
.help("Port to listen on for DNS request (overrides the port in the config if specified).")
|
||||
)
|
||||
)
|
||||
.setting(AppSettings::SubcommandRequiredElseHelp);
|
||||
.subcommand_required(true)
|
||||
.arg_required_else_help(true);
|
||||
|
||||
// Tracing doesn't log anything when there is no subscriber set. But we want to see
|
||||
// logging messages from config parsing etc. We can't set the global default subscriber
|
||||
|
@ -324,9 +327,9 @@ where
|
|||
.finish();
|
||||
let pre_config_logging = tracing::Dispatch::new(pre_config_logging);
|
||||
let pre_config_logging_ret = tracing::dispatcher::with_default(&pre_config_logging, || {
|
||||
let matches = clap_app.get_matches_from_safe(cli_args)?;
|
||||
let matches = clap_app.try_get_matches_from(cli_args)?;
|
||||
|
||||
let fs_mistrust_disabled = matches.is_present("disable-fs-permission-checks");
|
||||
let fs_mistrust_disabled = matches.get_flag("disable-fs-permission-checks");
|
||||
|
||||
// A Mistrust object to use for loading our configuration. Elsewhere, we
|
||||
// use the value _from_ the configuration.
|
||||
|
@ -339,16 +342,21 @@ where
|
|||
.expect("Could not construct default fs-mistrust")
|
||||
};
|
||||
|
||||
let mut override_options: Vec<&str> =
|
||||
matches.values_of("option").unwrap_or_default().collect();
|
||||
let mut override_options: Vec<String> = matches
|
||||
.get_many::<String>("option")
|
||||
.unwrap_or_default()
|
||||
.cloned()
|
||||
.collect();
|
||||
if fs_mistrust_disabled {
|
||||
override_options.push("storage.permissions.dangerously_trust_everyone=true");
|
||||
override_options.push("storage.permissions.dangerously_trust_everyone=true".to_owned());
|
||||
}
|
||||
|
||||
let cfg_sources = {
|
||||
let mut cfg_sources = ConfigurationSources::from_cmdline(
|
||||
default_config_files()?,
|
||||
matches.values_of_os("config-files").unwrap_or_default(),
|
||||
matches
|
||||
.get_many::<OsString>("config-files")
|
||||
.unwrap_or_default(),
|
||||
override_options,
|
||||
);
|
||||
cfg_sources.set_mistrust(cfg_mistrust);
|
||||
|
@ -370,7 +378,7 @@ where
|
|||
let _log_guards = logging::setup_logging(
|
||||
config.logging(),
|
||||
&log_mistrust,
|
||||
matches.value_of("loglevel"),
|
||||
matches.get_one::<String>("loglevel").map(|s| s.as_str()),
|
||||
)?;
|
||||
|
||||
if !config.application().allow_running_as_root {
|
||||
|
@ -387,7 +395,7 @@ where
|
|||
|
||||
if let Some(proxy_matches) = matches.subcommand_matches("proxy") {
|
||||
let socks_port = match (
|
||||
proxy_matches.value_of("socks-port"),
|
||||
proxy_matches.get_one::<String>("socks-port"),
|
||||
config.proxy().socks_listen.localhost_port_legacy()?,
|
||||
) {
|
||||
(Some(p), _) => p.parse().expect("Invalid port specified"),
|
||||
|
@ -396,7 +404,7 @@ where
|
|||
};
|
||||
|
||||
let dns_port = match (
|
||||
proxy_matches.value_of("dns-port"),
|
||||
proxy_matches.get_one::<String>("dns-port"),
|
||||
config.proxy().dns_listen.localhost_port_legacy()?,
|
||||
) {
|
||||
(Some(p), _) => p.parse().expect("Invalid port specified"),
|
||||
|
|
|
@ -13,17 +13,17 @@ set -euo pipefail
|
|||
# If you add anything to this section, make sure to add a comment
|
||||
# explaining why it's safe to do so.
|
||||
IGNORE=(
|
||||
# This is not a vulnerability but an unmaintained warning for `ansi_term`.
|
||||
# The upstream issue does not offer good alternatives, and anyway we get
|
||||
# this crate via clap and tracing-*.
|
||||
# It does not seem at all likely that this is really a problem for us.
|
||||
--ignore RUSTSEC-2021-0139
|
||||
)
|
||||
|
||||
${CARGO:-cargo} audit -D warnings "${IGNORE[@]}"
|
||||
|
||||
|
||||
OBSOLETE_IGNORE=(
|
||||
# This is not a vulnerability but an unmaintained warning for `ansi_term`.
|
||||
# The upstream issue does not offer good alternatives, and anyway we get
|
||||
# this crate via clap and tracing-*.
|
||||
# It does not seem at all likely that this is really a problem for us.
|
||||
--ignore RUSTSEC-2021-0139
|
||||
# This is not a vulnerability but an unmaintained warn for the
|
||||
# `net2` crate. It was pulled indirectly by `notify` 4.0.
|
||||
# It's fixed in `notify` 5.0.
|
||||
|
|
Loading…
Reference in New Issue