diff --git a/network/Cargo.toml b/network/Cargo.toml index 58ae4dd59b..f2b4f4581a 100644 --- a/network/Cargo.toml +++ b/network/Cargo.toml @@ -28,7 +28,7 @@ tokio = { version = "1.14", default-features = false, features = ["io-util", "ma tokio-stream = { version = "0.1.2", default-features = false } #tracing and metrics tracing = { version = "0.1", default-features = false, features = ["attributes"]} -prometheus = { version = "0.12", default-features = false, optional = true } +prometheus = { version = "0.13", default-features = false, optional = true } #async futures-core = { version = "0.3", default-features = false } futures-util = { version = "0.3.7", default-features = false, features = ["std"] } @@ -46,19 +46,19 @@ lz-fear = { version = "0.1.1", optional = true } async-trait = "0.1.42" bytes = "^1" # faster HashMaps -hashbrown = { version = ">=0.9, <0.12" } +hashbrown = { version = ">=0.9, <0.13" } [dev-dependencies] tracing-subscriber = { version = "0.3.7", default-features = false, features = ["env-filter", "fmt", "time", "ansi", "smallvec"] } tokio = { version = "1.14", default-features = false, features = ["io-std", "fs", "rt-multi-thread"] } futures-util = { version = "0.3.7", default-features = false, features = ["sink", "std"] } -clap = { version = "2.33", default-features = false } +clap = { version = "3.1.8", default-features = false, features = ["std", "color"] } shellexpand = "2.0.0" serde = { version = "1.0", features = ["derive"] } prometheus-hyper = "0.1.2" criterion = { version = "0.3.4", features = ["default", "async_tokio"] } #quic -rcgen = { version = "0.8.10"} +rcgen = { version = "0.9"} [[bench]] name = "speed" diff --git a/network/examples/chat.rs b/network/examples/chat.rs index 2dc1e56e78..37327f179a 100644 --- a/network/examples/chat.rs +++ b/network/examples/chat.rs @@ -3,7 +3,7 @@ //! RUST_BACKTRACE=1 cargo run --example chat -- --trace=info --port 15006 //! RUST_BACKTRACE=1 cargo run --example chat -- --trace=info --port 15006 --mode=client //! ``` -use clap::{App, Arg}; +use clap::{Command, Arg}; use std::{sync::Arc, thread, time::Duration}; use tokio::{io, io::AsyncBufReadExt, runtime::Runtime, sync::RwLock}; use tracing::*; @@ -14,13 +14,13 @@ use veloren_network::{ConnectAddr, ListenAddr, Network, Participant, Pid, Promis /// between participants, it's neither pretty nor perfect, but it should show /// how to integrate network fn main() { - let matches = App::new("Chat example") + let matches = Command::new("Chat example") .version("0.1.0") .author("Marcel Märtens ") .about("example chat implemented with veloren-network") .arg( - Arg::with_name("mode") - .short("m") + Arg::new("mode") + .short('m') .long("mode") .takes_value(true) .possible_values(&["server", "client", "both"]) @@ -31,22 +31,22 @@ fn main() { ), ) .arg( - Arg::with_name("port") - .short("p") + Arg::new("port") + .short('p') .long("port") .takes_value(true) .default_value("52000") .help("port to listen on"), ) .arg( - Arg::with_name("ip") + Arg::new("ip") .long("ip") .takes_value(true) .default_value("127.0.0.1") .help("ip to listen and connect to"), ) .arg( - Arg::with_name("protocol") + Arg::new("protocol") .long("protocol") .takes_value(true) .default_value("tcp") @@ -56,8 +56,8 @@ fn main() { ), ) .arg( - Arg::with_name("trace") - .short("t") + Arg::new("trace") + .short('t') .long("trace") .takes_value(true) .default_value("warn") diff --git a/network/examples/fileshare/main.rs b/network/examples/fileshare/main.rs index 158b825073..5a04c96de8 100644 --- a/network/examples/fileshare/main.rs +++ b/network/examples/fileshare/main.rs @@ -4,7 +4,7 @@ //! --profile=release -Z unstable-options -- --trace=info --port 15006) //! (cd network/examples/fileshare && RUST_BACKTRACE=1 cargo run //! --profile=release -Z unstable-options -- --trace=info --port 15007) ``` -use clap::{App, Arg, SubCommand}; +use clap::{Command, Arg}; use std::{path::PathBuf, sync::Arc, thread, time::Duration}; use tokio::{io, io::AsyncBufReadExt, runtime::Runtime, sync::mpsc}; use tracing::*; @@ -16,21 +16,21 @@ use commands::{FileInfo, LocalCommand}; use server::Server; fn main() { - let matches = App::new("File Server") + let matches = Command::new("File Server") .version("0.1.0") .author("Marcel Märtens ") .about("example file server implemented with veloren-network") .arg( - Arg::with_name("port") - .short("p") + Arg::new("port") + .short('p') .long("port") .takes_value(true) .default_value("15006") .help("port to listen on"), ) .arg( - Arg::with_name("trace") - .short("t") + Arg::new("trace") + .short('t') .long("trace") .takes_value(true) .default_value("warn") @@ -61,8 +61,8 @@ fn main() { runtime.block_on(client(cmd_sender)); } -fn file_exists(file: String) -> Result<(), String> { - let file: std::path::PathBuf = shellexpand::tilde(&file).parse().unwrap(); +fn file_exists(file: &str) -> Result<(), String> { + let file: std::path::PathBuf = shellexpand::tilde(file).parse().unwrap(); if file.exists() { Ok(()) } else { @@ -70,22 +70,21 @@ fn file_exists(file: String) -> Result<(), String> { } } -fn get_options<'a, 'b>() -> App<'a, 'b> { - App::new("") - .setting(clap::AppSettings::NoBinaryName) - .setting(clap::AppSettings::SubcommandRequired) - .setting(clap::AppSettings::VersionlessSubcommands) - .setting(clap::AppSettings::SubcommandRequiredElseHelp) - .setting(clap::AppSettings::ColorAuto) - .subcommand(SubCommand::with_name("quit").about("closes program")) - .subcommand(SubCommand::with_name("disconnect").about("stop connections to all servers")) - .subcommand(SubCommand::with_name("t").about("quick test by connecting to 127.0.0.1:1231")) +fn get_options<'a>() -> Command<'a> { + Command::new("") + .no_binary_name(true) + .subcommand_required(true) + .arg_required_else_help(true) + .color(clap::ColorChoice::Auto) + .subcommand(Command::new("quit").about("closes program")) + .subcommand(Command::new("disconnect").about("stop connections to all servers")) + .subcommand(Command::new("t").about("quick test by connecting to 127.0.0.1:1231")) .subcommand( - SubCommand::with_name("connect") + Command::new("connect") .about("opens a connection to another instance of this fileserver network") - .setting(clap::AppSettings::NoBinaryName) + .no_binary_name(true) .arg( - Arg::with_name("ip:port") + Arg::new("ip:port") .help("ip and port to connect to, example '127.0.0.1:1231'") .required(true) .validator(|ipport| match ipport.parse::() { @@ -94,26 +93,26 @@ fn get_options<'a, 'b>() -> App<'a, 'b> { }), ), ) - .subcommand(SubCommand::with_name("list").about("lists all available files on the network")) + .subcommand(Command::new("list").about("lists all available files on the network")) .subcommand( - SubCommand::with_name("serve") + Command::new("serve") .about("make file available on the network") .arg( - Arg::with_name("file") + Arg::new("file") .help("file to serve") .required(true) .validator(file_exists), ), ) .subcommand( - SubCommand::with_name("get") + Command::new("get") .about( "downloads file with the id from the `list` command. Optionally provide a \ storage path, if none is provided it will be saved in the current directory \ with the remote filename", ) .arg( - Arg::with_name("id") + Arg::new("id") .help("id to download. get the id from the `list` command") .required(true) .validator(|id| match id.parse::() { @@ -121,7 +120,7 @@ fn get_options<'a, 'b>() -> App<'a, 'b> { Err(e) => Err(format!("must be a number {:?}", e)), }), ) - .arg(Arg::with_name("file").help("local path to store the file to")), + .arg(Arg::new("file").help("local path to store the file to")), ) } @@ -134,24 +133,28 @@ async fn client(cmd_sender: mpsc::UnboundedSender) { print!("==> "); std::io::stdout().flush().unwrap(); input_lines.read_line(&mut line).await.unwrap(); - let matches = match get_options().get_matches_from_safe(line.split_whitespace()) { + let matches = match get_options().try_get_matches_from(line.split_whitespace()) { Err(e) => { - println!("{}", e.message); + println!("{}", e); continue; }, Ok(matches) => matches, }; match matches.subcommand() { - ("quit", _) => { + None => { + println!("unknown subcommand"); + break; + }, + Some(("quit", _)) => { cmd_sender.send(LocalCommand::Shutdown).unwrap(); println!("goodbye"); break; }, - ("disconnect", _) => { + Some(("disconnect", _)) => { cmd_sender.send(LocalCommand::Disconnect).unwrap(); }, - ("connect", Some(connect_matches)) => { + Some(("connect", connect_matches)) => { let socketaddr = connect_matches .value_of("ip:port") .unwrap() @@ -161,24 +164,24 @@ async fn client(cmd_sender: mpsc::UnboundedSender) { .send(LocalCommand::Connect(ConnectAddr::Tcp(socketaddr))) .unwrap(); }, - ("t", _) => { + Some(("t", _)) => { cmd_sender .send(LocalCommand::Connect(ConnectAddr::Tcp( "127.0.0.1:1231".parse().unwrap(), ))) .unwrap(); }, - ("serve", Some(serve_matches)) => { + Some(("serve", serve_matches)) => { let path = shellexpand::tilde(serve_matches.value_of("file").unwrap()); let path: PathBuf = path.parse().unwrap(); if let Some(fileinfo) = FileInfo::new(&path).await { cmd_sender.send(LocalCommand::Serve(fileinfo)).unwrap(); } }, - ("list", _) => { + Some(("list", _)) => { cmd_sender.send(LocalCommand::List).unwrap(); }, - ("get", Some(get_matches)) => { + Some(("get", get_matches)) => { let id: u32 = get_matches.value_of("id").unwrap().parse().unwrap(); let file = get_matches.value_of("file"); cmd_sender @@ -186,7 +189,7 @@ async fn client(cmd_sender: mpsc::UnboundedSender) { .unwrap(); }, - (_, _) => { + Some((_, _)) => { unreachable!("this subcommand isn't yet handled"); }, } diff --git a/network/examples/network-speed/main.rs b/network/examples/network-speed/main.rs index e8ccc8f278..f464d7d3cf 100644 --- a/network/examples/network-speed/main.rs +++ b/network/examples/network-speed/main.rs @@ -3,7 +3,7 @@ /// (cd network/examples/network-speed && RUST_BACKTRACE=1 cargo run --profile=debuginfo -Z unstable-options -- --trace=error --protocol=tcp --mode=server) /// (cd network/examples/network-speed && RUST_BACKTRACE=1 cargo run --profile=debuginfo -Z unstable-options -- --trace=error --protocol=tcp --mode=client) /// ``` -use clap::{App, Arg}; +use clap::{Command, Arg}; use prometheus::Registry; use prometheus_hyper::Server; use serde::{Deserialize, Serialize}; @@ -27,13 +27,13 @@ enum Msg { /// This utility tests the speed of veloren network by creating a client that /// opens a stream and pipes as many messages through it as possible. fn main() { - let matches = App::new("Veloren Speed Test Utility") + let matches = Command::new("Veloren Speed Test Utility") .version("0.1.0") .author("Marcel Märtens ") .about("Runs speedtests regarding different parameter to benchmark veloren-network") .arg( - Arg::with_name("mode") - .short("m") + Arg::new("mode") + .short('m') .long("mode") .takes_value(true) .possible_values(&["server", "client", "both"]) @@ -44,22 +44,22 @@ fn main() { ), ) .arg( - Arg::with_name("port") - .short("p") + Arg::new("port") + .short('p') .long("port") .takes_value(true) .default_value("52000") .help("port to listen on"), ) .arg( - Arg::with_name("ip") + Arg::new("ip") .long("ip") .takes_value(true) .default_value("127.0.0.1") .help("ip to listen and connect to"), ) .arg( - Arg::with_name("protocol") + Arg::new("protocol") .long("protocol") .takes_value(true) .default_value("tcp") @@ -69,8 +69,8 @@ fn main() { ), ) .arg( - Arg::with_name("trace") - .short("t") + Arg::new("trace") + .short('t') .long("trace") .takes_value(true) .default_value("warn") diff --git a/network/protocol/Cargo.toml b/network/protocol/Cargo.toml index 2207d919f8..c1814f893b 100644 --- a/network/protocol/Cargo.toml +++ b/network/protocol/Cargo.toml @@ -17,14 +17,14 @@ default = ["metrics"] #tracing and metrics tracing = { version = "0.1", default-features = false } -prometheus = { version = "0.12", default-features = false, optional = true } +prometheus = { version = "0.13", default-features = false, optional = true } #stream flags bitflags = "1.2.1" rand = { version = "0.8" } # async traits async-trait = "0.1.42" bytes = "^1" -hashbrown = { version = ">=0.9, <0.12" } +hashbrown = { version = ">=0.9, <0.13" } [dev-dependencies] async-channel = "1.5.1"