Skip to content

Commit

Permalink
Update to latest version of discv5 and bump to 0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AgeManning committed Sep 17, 2024
1 parent dc95156 commit a5d945a
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 31 deletions.
18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "discv5-cli"
version = "0.5.0"
version = "0.6.0"
description = "Simple CLI utility for creating and debugging discovery v5 servers"
authors = ["Age Manning <[email protected]>"]
edition = "2018"
Expand All @@ -15,20 +15,20 @@ exclude = [
]

[dependencies]
discv5 = { version = "0.3.0", features = ["libp2p"] }
discv5 = { version = "0.7", features = ["libp2p"] }
sha2 = "0.10"
libsecp256k1 = "0.7"
libp2p-identity = { version = "0.1.2", features = ["secp256k1"] }
libp2p-core = "0.39"
clap = { version = "4.3", features = ["derive"] }
libp2p-identity = { version = "0.2.9", features = ["secp256k1"] }
libp2p-core = "0.42"
clap = { version = "4.5", features = ["derive"] }
hex = "0.4"
log = "0.4"
simple_logger = "4.1"
simple_logger = "5.0"
futures = "0.3"
tokio = { version = "1", features = ["full"] }
eyre = "0.6.8"
serde = "1.0.163"
serde_json = "1.0.96"
eyre = "0.6.12"
serde = "1.0.210"
serde_json = "1.0.128"

[[bin]]
name = "discv5-cli"
Expand Down
8 changes: 0 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![warn(missing_docs)]
#![warn(unused_extern_crates)]
#![forbid(unsafe_code)]
#![forbid(where_clauses_object_safety)]

//! Core library for the discv5 cli.
Expand All @@ -19,10 +18,3 @@ pub mod server;

/// Utility functions
pub mod utils;

/// A prelude for re-exporting commonly used items.
pub mod prelude {
pub use crate::packet::*;
pub use crate::request_enr::*;
pub use crate::server::*;
}
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![doc=include_str!("../README.md")]

use clap::Parser;
use discv5_cli::{cli, packet, prelude::Packet};
use discv5_cli::{cli, packet};

#[tokio::main]
async fn main() {
Expand All @@ -19,7 +19,7 @@ async fn main() {
Some(cli::Subcommand::RequestEnr(ref request_enr)) => {
discv5_cli::request_enr::run(request_enr).await;
}
Some(cli::Subcommand::Packet(Packet { subcommand })) => match subcommand {
Some(cli::Subcommand::Packet(packet::Packet { subcommand })) => match subcommand {
packet::PacketSubcommand::Decode(ref decode) => {
packet::decode(decode);
}
Expand Down
1 change: 1 addition & 0 deletions src/request_enr/enr_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub trait CombinedKeyPublicExt {
}

/// Extend ENR CombinedKey for conversion to libp2p keys.
#[allow(dead_code)]
pub trait CombinedKeyExt {
/// Converts a libp2p key into an ENR combined key.
fn from_libp2p(key: &Keypair) -> Result<CombinedKey, &'static str>;
Expand Down
4 changes: 2 additions & 2 deletions src/request_enr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ pub async fn run(req: &RequestEnr) {
let enr_key = enr::CombinedKey::generate_secp256k1();

// Build a local ENR
let enr = enr::EnrBuilder::new("v4")
let enr = enr::Builder::default()
.ip4(listen_address)
.udp4(listen_port)
.build(&enr_key)
.unwrap();

// Construct the discv5 service
let config = discv5::Discv5ConfigBuilder::new(listen_config).build();
let config = discv5::ConfigBuilder::new(listen_config).build();
let mut discv5: discv5::Discv5 = discv5::Discv5::new(enr, enr_key, config).unwrap();

// Start the server
Expand Down
2 changes: 1 addition & 1 deletion src/server/enr_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub fn build(
server: &super::command::Server,
enr_key: &enr::CombinedKey,
) -> eyre::Result<enr::Enr<enr::CombinedKey>> {
let mut builder = enr::EnrBuilder::new("v4");
let mut builder = enr::Builder::default();

// Extract params from server config
let mut ipv4_address = None;
Expand Down
4 changes: 2 additions & 2 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use discv5::{enr, Discv5, Discv5ConfigBuilder, ListenConfig};
use discv5::{enr, ConfigBuilder, Discv5, ListenConfig};
use std::{
convert::TryInto,
net::{IpAddr, SocketAddrV4, SocketAddrV6},
Expand Down Expand Up @@ -59,7 +59,7 @@ pub async fn run(server: &Server) {

log::info!("Server listening on {:?}", listen_config);
// Build the discv5 server using a default config
let config = Discv5ConfigBuilder::new(listen_config)
let config = ConfigBuilder::new(listen_config)
.enr_peer_update_min(peer_update_min.try_into().unwrap())
.build();
let mut discv5 = Discv5::new(enr, enr_key, config).unwrap();
Expand Down
14 changes: 7 additions & 7 deletions src/server/services/events.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
use std::sync::Arc;

use discv5::{Discv5, Discv5Event};
use discv5::{Discv5, Event};

/// Streams the discv5 server event stream.
pub async fn run(discv5: Arc<Discv5>) {
let mut event_stream = discv5.event_stream().await.unwrap();
loop {
match event_stream.recv().await {
Some(Discv5Event::SocketUpdated(addr)) => {
Some(Event::SocketUpdated(addr)) => {
log::info!("Nodes ENR socket address has been updated to: {:?}", addr);
}
Some(Discv5Event::Discovered(enr)) => {
Some(Event::Discovered(enr)) => {
log::info!("A peer has been discovered: {}", enr.node_id());
}
Some(discv5::Discv5Event::EnrAdded { enr, .. }) => {
Some(Event::UnverifiableEnr { enr, .. }) => {
log::info!(
"A peer has been added to the routing table with enr: {}",
enr
);
}
Some(discv5::Discv5Event::NodeInserted { node_id, .. }) => {
Some(Event::NodeInserted { node_id, .. }) => {
log::info!(
"A peer has been added to the routing table with node_id: {}",
node_id
);
}
Some(discv5::Discv5Event::SessionEstablished(enr, addr)) => {
Some(Event::SessionEstablished(enr, addr)) => {
log::info!(
"A session has been established with peer: {} at address: {}",
enr,
addr
);
}
Some(discv5::Discv5Event::TalkRequest(talk_request)) => {
Some(Event::TalkRequest(talk_request)) => {
log::info!(
"A talk request has been received from peer: {}",
talk_request.node_id()
Expand Down

0 comments on commit a5d945a

Please sign in to comment.