-
Notifications
You must be signed in to change notification settings - Fork 964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a peer id generator #583
Conversation
misc/peer-id-generator/src/main.rs
Outdated
let prefix = match env::args().nth(1) { | ||
Some(prefix) => prefix, | ||
None => { | ||
println!("Usage: {} <prefix>", env::args().nth(0).unwrap()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Usage {} , where prefix is a sequence of letters/numbers from the Base58 alfabet, starting with one of NPQRSTUVWXYZ
"
misc/peer-id-generator/src/main.rs
Outdated
} | ||
|
||
// 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this why the peer id always start with Qm
too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
Should also mention that it's only secp256k1. |
} | ||
|
||
loop { | ||
thread::sleep(Duration::from_secs(3600)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of executing for a certain amount of time, would you not rather want to generate a specific number of keys? How about a second command line parameter to specific that number and then maybe utilise rayon
with (0 .. number).into_par_iter().for_each(move |_| ...)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generating keys is super slow, so I don't think it really makes sense to stop after a certain number.
Do you think I should use rayon
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rayon works well but I was only suggesting it in the context of "I want n peer IDs". If you rather prefer time-based execution the existing approach is fine I think.
* Add a peer id generator * Improve usage message * Better help * Rustfmt
…e-handled_node_tasks * upstream/master: Inject event by value in ProtocolsHandler (libp2p#605) Add a PeriodicPingHandler and a PingListenHandler (libp2p#574) Fix stack overflow when printing a SubstreamRef (libp2p#599) Add a peer id generator (libp2p#583) eg. -> e.g.; ie. -> i.e. via repren (libp2p#592)
…rs-to-vecdeque * upstream/master: Inject event by value in ProtocolsHandler (libp2p#605) Add a PeriodicPingHandler and a PingListenHandler (libp2p#574) Fix stack overflow when printing a SubstreamRef (libp2p#599) Add a peer id generator (libp2p#583) eg. -> e.g.; ie. -> i.e. via repren (libp2p#592)
…_swarm * upstream/master: Inject event by value in ProtocolsHandler (libp2p#605) Add a PeriodicPingHandler and a PingListenHandler (libp2p#574) Fix stack overflow when printing a SubstreamRef (libp2p#599) Add a peer id generator (libp2p#583) eg. -> e.g.; ie. -> i.e. via repren (libp2p#592)
…lection_stream * upstream/master: Use vecdeque for fair polling (libp2p#610) Add back the Swarm (libp2p#613) Remove dependency on tokio_current_thread (libp2p#606) Use chashmap from crates (libp2p#615) Fix grammar in core/nodes etc. (libp2p#608) Inject event by value in ProtocolsHandler (libp2p#605) Add a PeriodicPingHandler and a PingListenHandler (libp2p#574) Fix stack overflow when printing a SubstreamRef (libp2p#599) Add a peer id generator (libp2p#583) eg. -> e.g.; ie. -> i.e. via repren (libp2p#592) Add a IdentifyTransport (libp2p#569) Tests for HandledNode (libp2p#546) Some minor fixes reported by clippy (libp2p#600) Add a PeriodicIdentification protocol handler (libp2p#579) Add ProtocolsHandler trait (libp2p#573) Use paritytech/rust-secp256k1 (libp2p#598) Use websocket 0.21.0 (libp2p#597) Reexport multihash from the facade (libp2p#587) Add substrate to the list of projects using libp2p (libp2p#595) Remove spaces before semicolons (libp2p#591)
Allows generating a peer id that starts with a specific prefix.
Useful for generating for example fancy network keys for bootstrap nodes.