Skip to content

Commit

Permalink
Merge 0.4.1 into mallory branch
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmygchen committed Feb 26, 2024
1 parent 7c0d16f commit 459d102
Show file tree
Hide file tree
Showing 38 changed files with 3,081 additions and 1,394 deletions.
17 changes: 17 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Description

<!--
A summary of what this pull request achieves and a rough list of changes.
-->

## Notes & open questions

<!--
Any notes, remarks or open questions you have to make about the PR. Feel free to remove this section if it's unnecessary
-->

## Change checklist

- [ ] Self-review
- [ ] Documentation updates if relevant
- [ ] Tests if relevant
30 changes: 19 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
cargo-fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Get latest version of stable rust
run: rustup update stable
- name: Check formatting with cargofmt
Expand All @@ -15,43 +15,51 @@ jobs:
runs-on: ubuntu-latest
needs: cargo-fmt
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Get latest version of stable rust
run: rustup update stable
- name: Install protobuf compiler for the libp2p-core dependency
uses: arduino/setup-protoc@v1
- name: Lint code for quality and style with Clippy
run: cargo clippy --workspace --tests --all-features -- -D warnings
release-tests-ubuntu:
runs-on: ubuntu-latest
needs: cargo-fmt
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Get latest version of stable rust
run: rustup update stable
- name: Run tests in release
run: cargo test --all --release --tests
run: cargo test --all --release
test-all-features:
runs-on: ubuntu-latest
container:
image: rust
needs: cargo-fmt
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Get latest version of stable rust
run: rustup update stable
- name: Install protobuf compiler for the libp2p-core dependency
uses: arduino/setup-protoc@v1
- name: Run tests in release
run: cargo test --all --release --all-features --tests
run: cargo test --all --release --all-features
check-rustdoc-links:
name: Check rustdoc intra-doc links
runs-on: ubuntu-latest
container:
image: rust
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Get latest version of stable rust
run: rustup update stable
- name: Check rustdoc links
run: RUSTDOCFLAGS="--deny broken_intra_doc_links" cargo doc --verbose --workspace --no-deps --document-private-items
cargo-udeps:
name: cargo-udeps
runs-on: ubuntu-latest
needs: cargo-fmt
steps:
- uses: actions/checkout@v3
- name: Install Rust nightly
run: rustup toolchain install nightly
- name: Install cargo-udeps
run: cargo install cargo-udeps --locked --force
- name: Run cargo udeps to identify unused crates in the dependency graph
run: cargo +nightly udeps --tests --all-targets --release
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/discv5-temp.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 33 additions & 37 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "discv5"
authors = ["Age Manning <[email protected]>"]
edition = "2018"
version = "0.1.0"
version = "0.4.1"
description = "Implementation of the p2p discv5 discovery protocol"
license = "Apache-2.0"
repository = "https:/sigp/discv5"
Expand All @@ -12,45 +12,41 @@ categories = ["network-programming", "asynchronous"]
exclude = [".gitignore", ".github/*"]

[dependencies]
enr = { version = "0.6.2", features = ["k256", "ed25519"] }
tokio = { version = "1.15.0", features = ["net", "sync", "macros", "rt"] }
tokio-stream = "0.1.8"
tokio-util = { version = "0.6.9", features = ["time"] }
libp2p-core = { version = "0.36.0", optional = true }
zeroize = { version = "1.4.3", features = ["zeroize_derive"] }
futures = "0.3.19"
uint = { version = "0.9.1", default-features = false }
rlp = "0.5.1"
enr = { version = "0.10", features = ["k256", "ed25519"] }
tokio = { version = "1", features = ["net", "sync", "macros", "rt"] }
libp2p = { version = "0.53", features = ["ed25519", "secp256k1"], optional = true }
zeroize = { version = "1", features = ["zeroize_derive"] }
futures = "0.3"
uint = { version = "0.9", default-features = false }
rlp = "0.5"
# This version must be kept up to date do it uses the same dependencies as ENR
hkdf = "0.12.3"
hex = "0.4.3"
fnv = "1.0.7"
arrayvec = "0.7.2"
rand = { version = "0.8.4", package = "rand" }
socket2 = "0.4.4"
smallvec = "1.7.0"
parking_lot = "0.11.2"
lazy_static = "1.4.0"
aes = { version = "0.7.5", features = ["ctr"] }
aes-gcm = "0.9.4"
tracing = { version = "0.1.29", features = ["log"] }
tracing-subscriber = { version = "0.3.3", features = ["env-filter"] }
lru = "0.7.1"
hashlink = "0.7.0"
delay_map = "0.1.1"
more-asserts = "0.2.2"
hkdf = "0.12"
hex = "0.4"
fnv = "1"
arrayvec = "0.7"
rand = { version = "0.8", package = "rand" }
socket2 = "0.4"
smallvec = "1"
parking_lot = "0.11"
lazy_static = "1"
aes = { version = "0.7", features = ["ctr"] }
aes-gcm = "0.9"
tracing = { version = "0.1", features = ["log"] }
lru = "0.12"
hashlink = "0.8"
delay_map = "0.3"
more-asserts = "0.3"

[dev-dependencies]
clap = { version = "4", features = ["derive"] }
if-addrs = "0.10"
quickcheck = "0.9"
rand_07 = { package = "rand", version = "0.7" }
quickcheck = "0.9.2"
env_logger = "0.9.0"
hex-literal = "0.3.4"
simple_logger = "1.16.0"
tokio-util = { version = "0.6.9", features = ["time"] }
tokio = { version = "1.15.0", features = ["full"] }
rand_xorshift = "0.3.0"
rand_core = "0.6.3"
clap = { version = "3.1", features = ["derive"] }
rand_core = "0.6"
rand_xorshift = "0.3"
tokio = { version = "1", features = ["full"] }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

[features]
libp2p = ["libp2p-core"]
libp2p = ["dep:libp2p"]
serde = ["enr/serde"]
28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ Status]][Crates Link]
This is a rust implementation of the [Discovery v5](https:/ethereum/devp2p/blob/master/discv5/discv5.md)
peer discovery protocol.

Discovery v5 is a protocol designed for encrypted peer discovery and topic advertisement. Each peer/node
on the network is identified via it's `ENR` ([Ethereum Node
Record](https://eips.ethereum.org/EIPS/eip-778)), which is essentially a signed key-value store
containing the node's public key and optionally IP address and port.
Discovery v5 is a protocol designed for encrypted peer discovery. Each peer/node on the network is
identified via it's `ENR` ([Ethereum Node Record](https://eips.ethereum.org/EIPS/eip-778)), which
is essentially a signed key-value store containing the node's public key and optionally IP address
and port.

Discv5 employs a kademlia-like routing table to store and manage discovered peers and topics. The
protocol allows for external IP discovery in NAT environments through regular PING/PONG's with
Expand All @@ -37,15 +37,13 @@ For a simple CLI discovery service see [discv5-cli](https:/AgeMannin
A simple example of creating this service is as follows:

```rust
use discv5::{enr, enr::{CombinedKey, NodeId}, TokioExecutor, Discv5, Discv5ConfigBuilder};
use discv5::{enr, enr::{CombinedKey, NodeId}, TokioExecutor, Discv5, ConfigBuilder};
use discv5::socket::ListenConfig;
use std::net::SocketAddr;

// listening address and port
let listen_addr = "0.0.0.0:9000".parse::<SocketAddr>().unwrap();

// construct a local ENR
let enr_key = CombinedKey::generate_secp256k1();
let enr = enr::EnrBuilder::new("v4").build(&enr_key).unwrap();
let enr = enr::Enr::empty(&enr_key).unwrap();

// build the tokio executor
let mut runtime = tokio::runtime::Builder::new_multi_thread()
Expand All @@ -54,18 +52,24 @@ A simple example of creating this service is as follows:
.build()
.unwrap();

// configuration for the sockets to listen on
let listen_config = ListenConfig::Ipv4 {
ip: Ipv4Addr::UNSPECIFIED,
port: 9000,
};

// default configuration
let config = Discv5ConfigBuilder::new().build();
let config = ConfigBuilder::new(listen_config).build();

// construct the discv5 server
let mut discv5 = Discv5::new(enr, enr_key, config).unwrap();
let mut discv5: Discv5 = Discv5::new(enr, enr_key, config).unwrap();

// In order to bootstrap the routing table an external ENR should be added
// This can be done via add_enr. I.e.:
// discv5.add_enr(<ENR>)

// start the discv5 server
runtime.block_on(discv5.start(listen_addr));
runtime.block_on(discv5.start());

// run a find_node query
runtime.block_on(async {
Expand Down
21 changes: 12 additions & 9 deletions examples/custom_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
//! $ cargo run --example custom_executor <BASE64ENR>
//! ```

use discv5::{enr, enr::CombinedKey, Discv5, Discv5ConfigBuilder, Discv5Event};
use std::net::SocketAddr;
use discv5::{enr, enr::CombinedKey, ConfigBuilder, Discv5, Event, ListenConfig};
use std::net::Ipv4Addr;

fn main() {
// allows detailed logging with the RUST_LOG env variable
Expand All @@ -22,11 +22,14 @@ fn main() {
.try_init();

// listening address and port
let listen_addr = "0.0.0.0:9000".parse::<SocketAddr>().unwrap();
let listen_config = ListenConfig::Ipv4 {
ip: Ipv4Addr::UNSPECIFIED,
port: 9000,
};

let enr_key = CombinedKey::generate_secp256k1();
// construct a local ENR
let enr = enr::EnrBuilder::new("v4").build(&enr_key).unwrap();
let enr = enr::Enr::empty(&enr_key).unwrap();

// build the tokio executor
let runtime = tokio::runtime::Builder::new_multi_thread()
Expand All @@ -36,10 +39,10 @@ fn main() {
.unwrap();

// default configuration - uses the current executor
let config = Discv5ConfigBuilder::new().build();
let config = ConfigBuilder::new(listen_config).build();

// construct the discv5 server
let mut discv5 = Discv5::new(enr, enr_key, config).unwrap();
let mut discv5: Discv5 = Discv5::new(enr, enr_key, config).unwrap();

// if we know of another peer's ENR, add it known peers
if let Some(base64_enr) = std::env::args().nth(1) {
Expand All @@ -61,18 +64,18 @@ fn main() {

runtime.block_on(async {
// start the discv5 service
discv5.start(listen_addr).await.unwrap();
discv5.start().await.unwrap();
println!("Server started");

// get an event stream
let mut event_stream = discv5.event_stream().await.unwrap();

loop {
match event_stream.recv().await {
Some(Discv5Event::SocketUpdated(addr)) => {
Some(Event::SocketUpdated(addr)) => {
println!("Nodes ENR socket address has been updated to: {addr:?}");
}
Some(Discv5Event::Discovered(enr)) => {
Some(Event::Discovered(enr)) => {
println!("A peer has been discovered: {}", enr.node_id());
}
_ => {}
Expand Down
Loading

0 comments on commit 459d102

Please sign in to comment.