-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
implement part of reth p2p rlpx ping
#9762
Merged
+281
−2
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,104 @@ | ||
# reth p2p rlpx | ||
|
||
RLPx commands | ||
|
||
```bash | ||
$ reth p2p rlpx --help | ||
Usage: reth p2p rlpx [OPTIONS] <COMMAND> | ||
|
||
Commands: | ||
ping ping node | ||
help Print this message or the help of the given subcommand(s) | ||
|
||
Options: | ||
--instance <INSTANCE> | ||
Add a new instance of a node. | ||
|
||
Configures the ports of the node to avoid conflicts with the defaults. This is useful for running multiple nodes on the same machine. | ||
|
||
Max number of instances is 200. It is chosen in a way so that it's not possible to have port numbers that conflict with each other. | ||
Changes to the following port numbers: - `DISCOVERY_PORT`: default + `instance` - 1 - `AUTH_PORT`: default + `instance` * 100 - 100 - `HTTP_RPC_PORT`: default - `instance` + 1 - `WS_RPC_PORT`: default + `instance` * 2 - 2 | ||
[default: 1] | ||
-h, --help | ||
Print help (see a summary with '-h') | ||
Logging: | ||
--log.stdout.format <FORMAT> | ||
The format to use for logs written to stdout | ||
[default: terminal] | ||
Possible values: | ||
- json: Represents JSON formatting for logs. This format outputs log records as JSON objects, making it suitable for structured logging | ||
- log-fmt: Represents logfmt (key=value) formatting for logs. This format is concise and human-readable, typically used in command-line applications | ||
- terminal: Represents terminal-friendly formatting for logs | ||
--log.stdout.filter <FILTER> | ||
The filter to use for logs written to stdout | ||
[default: ] | ||
--log.file.format <FORMAT> | ||
The format to use for logs written to the log file | ||
[default: terminal] | ||
Possible values: | ||
- json: Represents JSON formatting for logs. This format outputs log records as JSON objects, making it suitable for structured logging | ||
- log-fmt: Represents logfmt (key=value) formatting for logs. This format is concise and human-readable, typically used in command-line applications | ||
- terminal: Represents terminal-friendly formatting for logs | ||
--log.file.filter <FILTER> | ||
The filter to use for logs written to the log file | ||
[default: debug] | ||
--log.file.directory <PATH> | ||
The path to put log files in | ||
[default: <CACHE_DIR>/logs] | ||
--log.file.max-size <SIZE> | ||
The maximum size (in MB) of one log file | ||
[default: 200] | ||
--log.file.max-files <COUNT> | ||
The maximum amount of log files that will be stored. If set to 0, background file logging is disabled | ||
[default: 5] | ||
--log.journald | ||
Write logs to journald | ||
--log.journald.filter <FILTER> | ||
The filter to use for logs written to journald | ||
[default: error] | ||
--color <COLOR> | ||
Sets whether or not the formatter emits ANSI terminal escape codes for colors and other text formatting | ||
[default: always] | ||
Possible values: | ||
- always: Colors on | ||
- auto: Colors on | ||
- never: Colors off | ||
Display: | ||
-v, --verbosity... | ||
Set the minimum log level. | ||
-v Errors | ||
-vv Warnings | ||
-vvv Info | ||
-vvvv Debug | ||
-vvvvv Traces (warning: very verbose!) | ||
-q, --quiet | ||
Silence all log output | ||
``` |
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,104 @@ | ||
# reth p2p rlpx ping | ||
|
||
ping node | ||
|
||
```bash | ||
$ reth p2p rlpx ping --help | ||
Usage: reth p2p rlpx ping [OPTIONS] <NODE> | ||
|
||
Arguments: | ||
<NODE> | ||
The node to ping | ||
|
||
Options: | ||
--instance <INSTANCE> | ||
Add a new instance of a node. | ||
|
||
Configures the ports of the node to avoid conflicts with the defaults. This is useful for running multiple nodes on the same machine. | ||
|
||
Max number of instances is 200. It is chosen in a way so that it's not possible to have port numbers that conflict with each other. | ||
Changes to the following port numbers: - `DISCOVERY_PORT`: default + `instance` - 1 - `AUTH_PORT`: default + `instance` * 100 - 100 - `HTTP_RPC_PORT`: default - `instance` + 1 - `WS_RPC_PORT`: default + `instance` * 2 - 2 | ||
[default: 1] | ||
-h, --help | ||
Print help (see a summary with '-h') | ||
Logging: | ||
--log.stdout.format <FORMAT> | ||
The format to use for logs written to stdout | ||
[default: terminal] | ||
Possible values: | ||
- json: Represents JSON formatting for logs. This format outputs log records as JSON objects, making it suitable for structured logging | ||
- log-fmt: Represents logfmt (key=value) formatting for logs. This format is concise and human-readable, typically used in command-line applications | ||
- terminal: Represents terminal-friendly formatting for logs | ||
--log.stdout.filter <FILTER> | ||
The filter to use for logs written to stdout | ||
[default: ] | ||
--log.file.format <FORMAT> | ||
The format to use for logs written to the log file | ||
[default: terminal] | ||
Possible values: | ||
- json: Represents JSON formatting for logs. This format outputs log records as JSON objects, making it suitable for structured logging | ||
- log-fmt: Represents logfmt (key=value) formatting for logs. This format is concise and human-readable, typically used in command-line applications | ||
- terminal: Represents terminal-friendly formatting for logs | ||
--log.file.filter <FILTER> | ||
The filter to use for logs written to the log file | ||
[default: debug] | ||
--log.file.directory <PATH> | ||
The path to put log files in | ||
[default: <CACHE_DIR>/logs] | ||
--log.file.max-size <SIZE> | ||
The maximum size (in MB) of one log file | ||
[default: 200] | ||
--log.file.max-files <COUNT> | ||
The maximum amount of log files that will be stored. If set to 0, background file logging is disabled | ||
[default: 5] | ||
--log.journald | ||
Write logs to journald | ||
--log.journald.filter <FILTER> | ||
The filter to use for logs written to journald | ||
[default: error] | ||
--color <COLOR> | ||
Sets whether or not the formatter emits ANSI terminal escape codes for colors and other text formatting | ||
[default: always] | ||
Possible values: | ||
- always: Colors on | ||
- auto: Colors on | ||
- never: Colors off | ||
Display: | ||
-v, --verbosity... | ||
Set the minimum log level. | ||
-v Errors | ||
-vv Warnings | ||
-vvv Info | ||
-vvvv Debug | ||
-vvvvv Traces (warning: very verbose!) | ||
-q, --quiet | ||
Silence all log output | ||
``` |
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,51 @@ | ||
//! RLPx subcommand of P2P Debugging tool. | ||
use clap::{Parser, Subcommand}; | ||
use reth_ecies::stream::ECIESStream; | ||
use reth_eth_wire::{HelloMessage, UnauthedP2PStream}; | ||
use reth_network::config::rng_secret_key; | ||
use reth_network_peers::{pk2id, AnyNode}; | ||
use secp256k1::SECP256K1; | ||
use tokio::net::TcpStream; | ||
|
||
/// RLPx commands | ||
#[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 node_record = node | ||
.node_record() | ||
.ok_or_else(|| eyre::eyre!("failed to parse node {}", node))?; | ||
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. | ||
node: AnyNode, | ||
}, | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this should follow on to use the established session returned by the handshake (the first index in the tuple), and use that to send a ping
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.
@mattsse I try to implement this which need to refactor some core code of p2p, it may need some time. Or we could merge this first and I'll implement
send ping
in another PR :)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.
cool, let's get this over the line and followup separately
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.
please change the name of the pr then, since it only partially implements the ping command