From bdd43706588794e7d9a1a0eb96d1895319c7d783 Mon Sep 17 00:00:00 2001 From: Fabricio Dematte Date: Thu, 27 Jan 2022 10:59:42 -0300 Subject: [PATCH 1/8] draft --- misc/keygen/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 misc/keygen/.gitkeep diff --git a/misc/keygen/.gitkeep b/misc/keygen/.gitkeep new file mode 100644 index 00000000000..e69de29bb2d From 49a728dad54014228d39ee232a17c9e312297720 Mon Sep 17 00:00:00 2001 From: Fabricio Dematte Date: Thu, 3 Feb 2022 22:03:08 -0300 Subject: [PATCH 2/8] setup keygen crate --- misc/keygen/.gitkeep | 0 misc/keygen/Cargo.toml | 14 ++++++++++++++ misc/keygen/src/main.rs | 3 +++ 3 files changed, 17 insertions(+) delete mode 100644 misc/keygen/.gitkeep create mode 100644 misc/keygen/Cargo.toml create mode 100644 misc/keygen/src/main.rs diff --git a/misc/keygen/.gitkeep b/misc/keygen/.gitkeep deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/misc/keygen/Cargo.toml b/misc/keygen/Cargo.toml new file mode 100644 index 00000000000..058d46c328c --- /dev/null +++ b/misc/keygen/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "keygen" +version = "0.1.0" +edition = "2021" +authors = ["demfabris demfabris@gmail.com"] +license = "MIT" +repository = "https://github.com/libp2p/rust-libp2p" +keywords = ["peer-to-peer", "libp2p", "networking"] +categories = ["network-programming", "asynchronous"] + +[dependencies] +clap = "3.0.14" +directories = "4.0.1" +zeroize = "1.5.2" diff --git a/misc/keygen/src/main.rs b/misc/keygen/src/main.rs new file mode 100644 index 00000000000..e7a11a969c0 --- /dev/null +++ b/misc/keygen/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} From db461281a731bf098f86266821521bfd002d0075 Mon Sep 17 00:00:00 2001 From: Fabricio Dematte Date: Fri, 4 Feb 2022 00:14:50 -0300 Subject: [PATCH 3/8] implement keygen cli --- Cargo.toml | 1 + misc/keygen/Cargo.toml | 7 ++- misc/keygen/src/cli.rs | 45 +++++++++++++++++++ misc/keygen/src/config.rs | 30 +++++++++++++ misc/keygen/src/main.rs | 95 ++++++++++++++++++++++++++++++++++++++- 5 files changed, 175 insertions(+), 3 deletions(-) create mode 100644 misc/keygen/src/cli.rs create mode 100644 misc/keygen/src/config.rs diff --git a/Cargo.toml b/Cargo.toml index 961c167f640..5dca0aa0d43 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -126,6 +126,7 @@ members = [ "misc/metrics", "misc/multistream-select", "misc/peer-id-generator", + "misc/keygen", "muxers/mplex", "muxers/yamux", "protocols/dcutr", diff --git a/misc/keygen/Cargo.toml b/misc/keygen/Cargo.toml index 058d46c328c..7bea12c76b3 100644 --- a/misc/keygen/Cargo.toml +++ b/misc/keygen/Cargo.toml @@ -9,6 +9,11 @@ keywords = ["peer-to-peer", "libp2p", "networking"] categories = ["network-programming", "asynchronous"] [dependencies] -clap = "3.0.14" +argh = "0.1.7" directories = "4.0.1" zeroize = "1.5.2" +serde = { version = "1.0.136", features = ["derive"] } +serde_json = "1.0.78" +libp2p = { version = "0.42.1", default-features = false } +base64 = "0.13.0" +num_cpus = "1.13.1" diff --git a/misc/keygen/src/cli.rs b/misc/keygen/src/cli.rs new file mode 100644 index 00000000000..de9ecb775e8 --- /dev/null +++ b/misc/keygen/src/cli.rs @@ -0,0 +1,45 @@ +use std::ffi::OsString; + +use argh::FromArgs; + +#[derive(FromArgs, PartialEq, Debug)] +/// Libp2p keygen +pub struct Cli { + #[argh(subcommand)] + subcommand: Subcommand, +} + +impl Cli { + pub fn subcommand(&self) -> &Subcommand { + &self.subcommand + } +} + +#[derive(FromArgs, PartialEq, Debug)] +#[argh(subcommand)] +pub enum Subcommand { + Random(RandCmd), + From(FromCmd), +} + +#[derive(FromArgs, PartialEq, Debug)] +/// generate random key material +#[argh(subcommand, name = "rand")] +pub struct RandCmd { + #[argh(option, default = "String::new()")] + /// prefix + pub prefix: String, + + #[argh(option, default = "String::from(\"ed25519\")")] + /// encryption type + pub r#type: String, +} + +#[derive(FromArgs, PartialEq, Debug)] +/// generate key material from ... +#[argh(subcommand, name = "from")] +pub struct FromCmd { + /// generate keypair from `IPFS` config file + #[argh(option)] + pub config: OsString, +} diff --git a/misc/keygen/src/config.rs b/misc/keygen/src/config.rs new file mode 100644 index 00000000000..071a8c28176 --- /dev/null +++ b/misc/keygen/src/config.rs @@ -0,0 +1,30 @@ +use serde::Deserialize; +use std::error::Error; +use std::path::Path; + +#[derive(Clone, Deserialize)] +#[serde(rename_all = "PascalCase")] +pub struct Config { + pub identity: Identity, +} + +impl Config { + pub fn from_file(path: &Path) -> Result> { + Ok(serde_json::from_str(&std::fs::read_to_string(path)?)?) + } +} + +#[derive(Clone, Deserialize)] +#[serde(rename_all = "PascalCase")] +pub struct Identity { + #[serde(rename = "PeerID")] + pub peer_id: String, + pub priv_key: String, +} + +impl zeroize::Zeroize for Config { + fn zeroize(&mut self) { + self.identity.peer_id.zeroize(); + self.identity.priv_key.zeroize(); + } +} diff --git a/misc/keygen/src/main.rs b/misc/keygen/src/main.rs index e7a11a969c0..5a07025d157 100644 --- a/misc/keygen/src/main.rs +++ b/misc/keygen/src/main.rs @@ -1,3 +1,94 @@ -fn main() { - println!("Hello, world!"); +use std::error::Error; +use std::str::{self, FromStr}; +use std::sync::mpsc; +use std::thread; + +mod cli; +mod config; + +use cli::{FromCmd, RandCmd, Subcommand}; +use libp2p::identity::{self, ed25519}; +use libp2p::PeerId; +use zeroize::Zeroizing; + +// Due to the fact that a peer id uses a SHA-256 multihash, it always starts with the +// bytes 0x1220, meaning that only some characters are valid. +const ALLOWED_FIRST_BYTE: &[u8] = b"NPQRSTUVWXYZ"; + +// The base58 alphabet is not necessarily obvious. +const ALPHABET: &[u8] = b"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; + +fn main() -> Result<(), Box> { + let args: cli::Cli = argh::from_env(); + + let (local_peer_id, local_keypair) = match args.subcommand() { + // Generate keypair from some sort of key material. Currently supporting `IPFS` config file + Subcommand::From(FromCmd { config }) => { + let config = Zeroizing::new(config::Config::from_file(config.as_ref())?); + + let keypair = identity::Keypair::from_protobuf_encoding(&Zeroizing::new( + base64::decode(config.identity.priv_key.as_bytes())?, + ))?; + + let peer_id = keypair.public().into(); + assert_eq!( + PeerId::from_str(&config.identity.peer_id)?, + peer_id, + "Expect peer id derived from private key and peer id retrieved from config to match." + ); + + (peer_id, keypair) + } + + // Generate a random keypair, optionally with a prefix + Subcommand::Random(RandCmd { prefix, .. }) => { + if prefix.is_empty() { + let keypair = identity::Keypair::Ed25519(ed25519::Keypair::generate()); + (keypair.public().into(), keypair) + } else { + if prefix.as_bytes().iter().any(|c| !ALPHABET.contains(c)) { + eprintln!("Prefix {} is not valid base58", prefix); + std::process::exit(1); // error + } + + // Checking conformity to ALLOWED_FIRST_BYTE. + if !prefix.is_empty() && !ALLOWED_FIRST_BYTE.contains(&prefix.as_bytes()[0]) { + eprintln!("Prefix {} is not reachable", prefix); + eprintln!( + "Only the following bytes are possible as first byte: {}", + str::from_utf8(ALLOWED_FIRST_BYTE).unwrap() + ); + std::process::exit(1); // error + } + + let (tx, rx) = mpsc::channel::<(PeerId, identity::Keypair)>(); + + // Find peer IDs in a multithreaded fashion. + for _ in 0..num_cpus::get() { + let prefix = prefix.clone(); + let tx = tx.clone(); + + thread::spawn(move || loop { + let keypair = ed25519::Keypair::generate(); + let peer_id = identity::PublicKey::Ed25519(keypair.public()).to_peer_id(); + let base58 = peer_id.to_base58(); + if base58[8..].starts_with(&prefix) { + tx.send((peer_id, identity::Keypair::Ed25519(keypair))) + .expect("to send"); + } + }); + } + + rx.recv().expect("to recv") + } + } + }; + + println!( + "PeerId: {:?} Keypair: {:?}", + local_peer_id, + local_keypair.to_protobuf_encoding() + ); + + Ok(()) } From c55acd98b1767c535f0b0be7253a2eac3ef2c17f Mon Sep 17 00:00:00 2001 From: Fabricio Dematte Date: Sat, 19 Feb 2022 19:01:55 -0300 Subject: [PATCH 4/8] refactors and remove peer-id-generator --- Cargo.toml | 1 - misc/keygen/Cargo.toml | 9 ++-- misc/keygen/src/cli.rs | 45 ---------------- misc/keygen/src/config.rs | 17 ++++-- misc/keygen/src/main.rs | 66 +++++++++++++++++------ misc/peer-id-generator/Cargo.toml | 16 ------ misc/peer-id-generator/src/main.rs | 87 ------------------------------ 7 files changed, 67 insertions(+), 174 deletions(-) delete mode 100644 misc/keygen/src/cli.rs delete mode 100644 misc/peer-id-generator/Cargo.toml delete mode 100644 misc/peer-id-generator/src/main.rs diff --git a/Cargo.toml b/Cargo.toml index 5dca0aa0d43..b29df2a6ee2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -125,7 +125,6 @@ members = [ "core", "misc/metrics", "misc/multistream-select", - "misc/peer-id-generator", "misc/keygen", "muxers/mplex", "muxers/yamux", diff --git a/misc/keygen/Cargo.toml b/misc/keygen/Cargo.toml index 7bea12c76b3..3dcf57002ec 100644 --- a/misc/keygen/Cargo.toml +++ b/misc/keygen/Cargo.toml @@ -2,18 +2,17 @@ name = "keygen" version = "0.1.0" edition = "2021" -authors = ["demfabris demfabris@gmail.com"] +authors = ["demfabris "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" keywords = ["peer-to-peer", "libp2p", "networking"] categories = ["network-programming", "asynchronous"] [dependencies] -argh = "0.1.7" -directories = "4.0.1" +structopt = "0.3.26" zeroize = "1.5.2" serde = { version = "1.0.136", features = ["derive"] } -serde_json = "1.0.78" -libp2p = { version = "0.42.1", default-features = false } +serde_json = "1.0.79" +libp2p = { version = "0.42.2", default-features = false } base64 = "0.13.0" num_cpus = "1.13.1" diff --git a/misc/keygen/src/cli.rs b/misc/keygen/src/cli.rs deleted file mode 100644 index de9ecb775e8..00000000000 --- a/misc/keygen/src/cli.rs +++ /dev/null @@ -1,45 +0,0 @@ -use std::ffi::OsString; - -use argh::FromArgs; - -#[derive(FromArgs, PartialEq, Debug)] -/// Libp2p keygen -pub struct Cli { - #[argh(subcommand)] - subcommand: Subcommand, -} - -impl Cli { - pub fn subcommand(&self) -> &Subcommand { - &self.subcommand - } -} - -#[derive(FromArgs, PartialEq, Debug)] -#[argh(subcommand)] -pub enum Subcommand { - Random(RandCmd), - From(FromCmd), -} - -#[derive(FromArgs, PartialEq, Debug)] -/// generate random key material -#[argh(subcommand, name = "rand")] -pub struct RandCmd { - #[argh(option, default = "String::new()")] - /// prefix - pub prefix: String, - - #[argh(option, default = "String::from(\"ed25519\")")] - /// encryption type - pub r#type: String, -} - -#[derive(FromArgs, PartialEq, Debug)] -/// generate key material from ... -#[argh(subcommand, name = "from")] -pub struct FromCmd { - /// generate keypair from `IPFS` config file - #[argh(option)] - pub config: OsString, -} diff --git a/misc/keygen/src/config.rs b/misc/keygen/src/config.rs index 071a8c28176..fa4bec84a5c 100644 --- a/misc/keygen/src/config.rs +++ b/misc/keygen/src/config.rs @@ -1,8 +1,11 @@ -use serde::Deserialize; +use serde::{Deserialize, Serialize}; use std::error::Error; use std::path::Path; -#[derive(Clone, Deserialize)] +use libp2p::identity::Keypair; +use libp2p::PeerId; + +#[derive(Clone, Serialize, Deserialize)] #[serde(rename_all = "PascalCase")] pub struct Config { pub identity: Identity, @@ -12,9 +15,17 @@ impl Config { pub fn from_file(path: &Path) -> Result> { Ok(serde_json::from_str(&std::fs::read_to_string(path)?)?) } + + pub fn from_key_material(peer_id: PeerId, keypair: &Keypair) -> Result> { + let priv_key = base64::encode(keypair.to_protobuf_encoding()?); + let peer_id = peer_id.to_base58(); + Ok(Self { + identity: Identity { peer_id, priv_key }, + }) + } } -#[derive(Clone, Deserialize)] +#[derive(Clone, Serialize, Deserialize)] #[serde(rename_all = "PascalCase")] pub struct Identity { #[serde(rename = "PeerID")] diff --git a/misc/keygen/src/main.rs b/misc/keygen/src/main.rs index 5a07025d157..96e0fbaae2e 100644 --- a/misc/keygen/src/main.rs +++ b/misc/keygen/src/main.rs @@ -1,16 +1,43 @@ use std::error::Error; +use std::path::PathBuf; use std::str::{self, FromStr}; use std::sync::mpsc; use std::thread; -mod cli; mod config; -use cli::{FromCmd, RandCmd, Subcommand}; use libp2p::identity::{self, ed25519}; use libp2p::PeerId; +use structopt::StructOpt; use zeroize::Zeroizing; +#[derive(Debug, StructOpt)] +#[structopt(name = "libp2p key material generator")] +struct Args { + /// JSON formatted output + #[structopt(long, global = true)] + json: bool, + + #[structopt(subcommand)] + cmd: Command, +} + +#[derive(Debug, StructOpt)] +enum Command { + /// Generate from... + From { + /// Provide a IPFS config file + #[structopt(parse(from_os_str))] + config: PathBuf, + }, + /// Generate random + Rand { + /// The keypair prefix + #[structopt(long)] + prefix: Option, + }, +} + // Due to the fact that a peer id uses a SHA-256 multihash, it always starts with the // bytes 0x1220, meaning that only some characters are valid. const ALLOWED_FIRST_BYTE: &[u8] = b"NPQRSTUVWXYZ"; @@ -19,11 +46,11 @@ const ALLOWED_FIRST_BYTE: &[u8] = b"NPQRSTUVWXYZ"; const ALPHABET: &[u8] = b"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; fn main() -> Result<(), Box> { - let args: cli::Cli = argh::from_env(); + let args = Args::from_args(); - let (local_peer_id, local_keypair) = match args.subcommand() { + let (local_peer_id, local_keypair) = match args.cmd { // Generate keypair from some sort of key material. Currently supporting `IPFS` config file - Subcommand::From(FromCmd { config }) => { + Command::From { config } => { let config = Zeroizing::new(config::Config::from_file(config.as_ref())?); let keypair = identity::Keypair::from_protobuf_encoding(&Zeroizing::new( @@ -41,14 +68,11 @@ fn main() -> Result<(), Box> { } // Generate a random keypair, optionally with a prefix - Subcommand::Random(RandCmd { prefix, .. }) => { - if prefix.is_empty() { - let keypair = identity::Keypair::Ed25519(ed25519::Keypair::generate()); - (keypair.public().into(), keypair) - } else { + Command::Rand { prefix } => { + if let Some(prefix) = prefix { if prefix.as_bytes().iter().any(|c| !ALPHABET.contains(c)) { eprintln!("Prefix {} is not valid base58", prefix); - std::process::exit(1); // error + std::process::exit(1); } // Checking conformity to ALLOWED_FIRST_BYTE. @@ -58,7 +82,7 @@ fn main() -> Result<(), Box> { "Only the following bytes are possible as first byte: {}", str::from_utf8(ALLOWED_FIRST_BYTE).unwrap() ); - std::process::exit(1); // error + std::process::exit(1); } let (tx, rx) = mpsc::channel::<(PeerId, identity::Keypair)>(); @@ -80,15 +104,23 @@ fn main() -> Result<(), Box> { } rx.recv().expect("to recv") + } else { + let keypair = identity::Keypair::Ed25519(ed25519::Keypair::generate()); + (keypair.public().into(), keypair) } } }; - println!( - "PeerId: {:?} Keypair: {:?}", - local_peer_id, - local_keypair.to_protobuf_encoding() - ); + if args.json { + let config = config::Config::from_key_material(local_peer_id, &local_keypair)?; + println!("{}", serde_json::to_string(&config)?); + } else { + println!( + "PeerId: {:?} Keypair: {:?}", + local_peer_id, + local_keypair.to_protobuf_encoding() + ); + } Ok(()) } diff --git a/misc/peer-id-generator/Cargo.toml b/misc/peer-id-generator/Cargo.toml deleted file mode 100644 index fc6960279f2..00000000000 --- a/misc/peer-id-generator/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "peer-id-generator" -edition = "2021" -rust-version = "1.56.1" -version = "0.1.0" -description = "Generate peer ids that are prefixed with a specific string" -authors = ["Parity Technologies "] -license = "MIT" -repository = "https://github.com/libp2p/rust-libp2p" -keywords = ["peer-to-peer", "libp2p", "networking"] -categories = ["network-programming", "asynchronous"] -publish = false - -[dependencies] -libp2p-core = { path = "../../core", default-features = false, version = "0.32.0"} -num_cpus = "1.8" diff --git a/misc/peer-id-generator/src/main.rs b/misc/peer-id-generator/src/main.rs deleted file mode 100644 index 45239317396..00000000000 --- a/misc/peer-id-generator/src/main.rs +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2018 Parity Technologies (UK) Ltd. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -use libp2p_core::identity; -use std::{env, str, thread, time::Duration}; - -fn main() { - // Due to the fact that a peer id uses a SHA-256 multihash, it always starts with the - // bytes 0x1220, meaning that only some characters are valid. - const ALLOWED_FIRST_BYTE: &'static [u8] = b"NPQRSTUVWXYZ"; - - let prefix = match env::args().nth(1) { - Some(prefix) => prefix, - None => { - println!( - "Usage: {} \n\n\ - Generates a peer id that starts with the chosen prefix using a secp256k1 public \ - key.\n\n\ - Prefix must be a sequence of characters in the base58 \ - alphabet, and must start with one of the following: {}", - env::current_exe() - .unwrap() - .file_name() - .unwrap() - .to_str() - .unwrap(), - str::from_utf8(ALLOWED_FIRST_BYTE).unwrap() - ); - return; - } - }; - - // The base58 alphabet is not necessarily obvious. - const ALPHABET: &'static [u8] = b"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; - if prefix.as_bytes().iter().any(|c| !ALPHABET.contains(c)) { - println!("Prefix {} is not valid base58", prefix); - return; - } - - // Checking conformity to ALLOWED_FIRST_BYTE. - if !prefix.is_empty() { - if !ALLOWED_FIRST_BYTE.contains(&prefix.as_bytes()[0]) { - println!("Prefix {} is not reachable", prefix); - println!( - "Only the following bytes are possible as first byte: {}", - str::from_utf8(ALLOWED_FIRST_BYTE).unwrap() - ); - return; - } - } - - // Find peer IDs in a multithreaded fashion. - for _ in 0..num_cpus::get() { - let prefix = prefix.clone(); - thread::spawn(move || loop { - let keypair = identity::ed25519::Keypair::generate(); - let secret = keypair.secret(); - let peer_id = identity::PublicKey::Ed25519(keypair.public()).to_peer_id(); - let base58 = peer_id.to_base58(); - if base58[2..].starts_with(&prefix) { - println!("Found {:?}", peer_id); - println!("=> Private key = {:?}", secret.as_ref()); - } - }); - } - - loop { - thread::sleep(Duration::from_secs(3600)); - } -} From 1b7422ba96c52b0e1f910413351664ffa8a5418c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabricio=20Dematt=C3=AA?= <46208058+demfabris@users.noreply.github.com> Date: Wed, 9 Mar 2022 14:12:34 -0300 Subject: [PATCH 5/8] Update misc/keygen/Cargo.toml Co-authored-by: Max Inden --- misc/keygen/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/keygen/Cargo.toml b/misc/keygen/Cargo.toml index 3dcf57002ec..7c178fd3334 100644 --- a/misc/keygen/Cargo.toml +++ b/misc/keygen/Cargo.toml @@ -10,7 +10,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] structopt = "0.3.26" -zeroize = "1.5.2" +zeroize = "1" serde = { version = "1.0.136", features = ["derive"] } serde_json = "1.0.79" libp2p = { version = "0.42.2", default-features = false } From e13b52e38f86030d25f00df787e5bcd7c374328f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabricio=20Dematt=C3=AA?= <46208058+demfabris@users.noreply.github.com> Date: Wed, 9 Mar 2022 14:12:39 -0300 Subject: [PATCH 6/8] Update misc/keygen/Cargo.toml Co-authored-by: Max Inden --- misc/keygen/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/keygen/Cargo.toml b/misc/keygen/Cargo.toml index 7c178fd3334..d5433593265 100644 --- a/misc/keygen/Cargo.toml +++ b/misc/keygen/Cargo.toml @@ -13,6 +13,6 @@ structopt = "0.3.26" zeroize = "1" serde = { version = "1.0.136", features = ["derive"] } serde_json = "1.0.79" -libp2p = { version = "0.42.2", default-features = false } + libp2p-core = { path = "../../core", default-features = false, version = "0.32.0"} base64 = "0.13.0" num_cpus = "1.13.1" From 7be0a04690d587c3cc4deff415552b9d46959dad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabricio=20Dematt=C3=AA?= <46208058+demfabris@users.noreply.github.com> Date: Wed, 9 Mar 2022 14:12:48 -0300 Subject: [PATCH 7/8] Update misc/keygen/src/main.rs Co-authored-by: Max Inden --- misc/keygen/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/keygen/src/main.rs b/misc/keygen/src/main.rs index 96e0fbaae2e..ff1d7597bf1 100644 --- a/misc/keygen/src/main.rs +++ b/misc/keygen/src/main.rs @@ -24,7 +24,7 @@ struct Args { #[derive(Debug, StructOpt)] enum Command { - /// Generate from... + /// Read from config file From { /// Provide a IPFS config file #[structopt(parse(from_os_str))] From 63cd28473bfebf7ed2a62dbdfffa82723037eb19 Mon Sep 17 00:00:00 2001 From: Fabricio Dematte Date: Wed, 9 Mar 2022 14:33:55 -0300 Subject: [PATCH 8/8] Remove 'num_cpus' --- misc/keygen/Cargo.toml | 3 +-- misc/keygen/src/config.rs | 4 ++-- misc/keygen/src/main.rs | 6 +++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/misc/keygen/Cargo.toml b/misc/keygen/Cargo.toml index d5433593265..b30ea23bc70 100644 --- a/misc/keygen/Cargo.toml +++ b/misc/keygen/Cargo.toml @@ -13,6 +13,5 @@ structopt = "0.3.26" zeroize = "1" serde = { version = "1.0.136", features = ["derive"] } serde_json = "1.0.79" - libp2p-core = { path = "../../core", default-features = false, version = "0.32.0"} +libp2p-core = { path = "../../core", default-features = false, version = "0.32.0"} base64 = "0.13.0" -num_cpus = "1.13.1" diff --git a/misc/keygen/src/config.rs b/misc/keygen/src/config.rs index fa4bec84a5c..996cfd268b1 100644 --- a/misc/keygen/src/config.rs +++ b/misc/keygen/src/config.rs @@ -2,8 +2,8 @@ use serde::{Deserialize, Serialize}; use std::error::Error; use std::path::Path; -use libp2p::identity::Keypair; -use libp2p::PeerId; +use libp2p_core::identity::Keypair; +use libp2p_core::PeerId; #[derive(Clone, Serialize, Deserialize)] #[serde(rename_all = "PascalCase")] diff --git a/misc/keygen/src/main.rs b/misc/keygen/src/main.rs index ff1d7597bf1..a3544137261 100644 --- a/misc/keygen/src/main.rs +++ b/misc/keygen/src/main.rs @@ -6,8 +6,8 @@ use std::thread; mod config; -use libp2p::identity::{self, ed25519}; -use libp2p::PeerId; +use libp2p_core::identity::{self, ed25519}; +use libp2p_core::PeerId; use structopt::StructOpt; use zeroize::Zeroizing; @@ -88,7 +88,7 @@ fn main() -> Result<(), Box> { let (tx, rx) = mpsc::channel::<(PeerId, identity::Keypair)>(); // Find peer IDs in a multithreaded fashion. - for _ in 0..num_cpus::get() { + for _ in 0..thread::available_parallelism()?.get() { let prefix = prefix.clone(); let tx = tx.clone();