forked from paradigmxyz/reth
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//! RLPx subcommand of P2P Debugging tool. | ||
|
||
use clap::{Parser, Subcommand}; | ||
use discv5::Enr; | ||
use reth_discv5::enr::EnrCombinedKeyWrapper; | ||
use reth_ecies::stream::ECIESStream; | ||
use reth_eth_wire::{HelloMessage, UnauthedP2PStream}; | ||
use reth_network::config::rng_secret_key; | ||
use reth_network_peers::{pk2id, NodeRecord}; | ||
use secp256k1::SECP256K1; | ||
use tokio::net::TcpStream; | ||
|
||
/// The arguments for the `reth p2p rlpx` command | ||
#[derive(Parser, Debug)] | ||
pub struct Command { | ||
#[clap(subcommand)] | ||
subcommand: Subcommands, | ||
} | ||
|
||
impl Command { | ||
// Execute `p2p rlpx` command. | ||
pub async fn execute(self) -> eyre::Result<()> { | ||
match self.subcommand { | ||
Subcommands::Ping { node } => { | ||
let key = rng_secret_key(); | ||
let enr = node.parse::<Enr>().unwrap(); | ||
let enr = EnrCombinedKeyWrapper(enr).into(); | ||
let node_record = NodeRecord::try_from(&enr).unwrap(); | ||
let outgoing = | ||
TcpStream::connect((node_record.address, node_record.tcp_port)).await?; | ||
let ecies_stream = ECIESStream::connect(outgoing, key, node_record.id).await?; | ||
|
||
let peer_id = pk2id(&key.public_key(SECP256K1)); | ||
let hello = HelloMessage::builder(peer_id).build(); | ||
|
||
let (_, their_hello) = | ||
UnauthedP2PStream::new(ecies_stream).handshake(hello).await?; | ||
|
||
println!("{:#?}", their_hello); | ||
} | ||
} | ||
Ok(()) | ||
} | ||
} | ||
|
||
#[derive(Subcommand, Debug)] | ||
enum Subcommands { | ||
/// ping node | ||
Ping { | ||
/// The node to ping. | ||
#[arg(long, short)] | ||
node: String, | ||
}, | ||
} |