Skip to content

Commit 30a550b

Browse files
committed
fix: linter warnings
1 parent a2fe791 commit 30a550b

3 files changed

Lines changed: 31 additions & 27 deletions

File tree

crates/charon-p2p/examples/p2p.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
use anyhow::Result;
88
use charon_eth2::enr::Record;
99
use charon_p2p::{
10-
behaviours::pluto::{PlutoBehaviourEvent},
11-
behaviours::pluto_mdns::{PlutoMdnsBehaviour, PlutoMdnsBehaviourEvent},
10+
behaviours::{
11+
pluto::PlutoBehaviourEvent,
12+
pluto_mdns::{PlutoMdnsBehaviour, PlutoMdnsBehaviourEvent},
13+
},
1214
config::P2PConfig,
1315
gater::ConnGater,
1416
p2p::{Node, NodeType},

crates/charon-p2p/src/behaviours/pluto_mdns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl PlutoMdnsBehaviour {
1818
Self {
1919
pluto: PlutoBehaviour::new(key, relay_client),
2020
mdns: mdns::tokio::Behaviour::new(mdns::Config::default(), key.public().to_peer_id())
21-
.unwrap(),
21+
.expect("Failed to create mDNS behaviour"),
2222
}
2323
}
2424
}

crates/charon-p2p/src/p2p.rs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
1-
#![allow(missing_docs)]
2-
#![allow(dead_code)]
3-
#![allow(unused)]
4-
51
//! P2P core concepts
62
7-
use std::{sync::Once, time::Duration};
3+
use std::time::Duration;
84

95
use libp2p::{
10-
Swarm, SwarmBuilder, identify,
11-
identity::Keypair,
12-
noise, ping, relay,
13-
swarm::{NetworkBehaviour, SwarmEvent},
14-
tcp, yamux,
6+
Swarm, SwarmBuilder, identity::Keypair, noise, relay, swarm::NetworkBehaviour, tcp, yamux,
157
};
168

17-
use libp2p::mdns;
18-
199
use crate::{config::P2PConfig, gater::ConnGater};
2010

11+
/// P2P error.
2112
#[derive(Debug, thiserror::Error)]
2213
pub enum P2PError {
2314
/// Failed to build the swarm.
2415
#[error("Failed to build the swarm: {0}")]
2516
FailedToBuildSwarm(Box<dyn std::error::Error + Send + Sync>),
2617

18+
/// Failed to convert the secret key to a libp2p keypair.
2719
#[error("Failed to convert the secret key to a libp2p keypair: {0}")]
2820
FailedToConvertSecretKeyToLibp2pKeypair(#[from] k256::pkcs8::der::Error),
2921

22+
/// Failed to decode the libp2p keypair.
3023
#[error("Failed to decode the libp2p keypair: {0}")]
3124
FailedToDecodeLibp2pKeypair(#[from] libp2p::identity::DecodingError),
3225
}
3326

3427
impl P2PError {
28+
/// Failed to build the swarm.
3529
pub fn failed_to_build_swarm(error: impl std::error::Error + Send + Sync + 'static) -> Self {
3630
Self::FailedToBuildSwarm(Box::new(error))
3731
}
3832
}
3933

4034
type Result<T> = std::result::Result<T, P2PError>;
4135

36+
/// Node type.
4237
pub enum NodeType {
38+
/// TCP node.
4339
TCP,
40+
/// QUIC node.
4441
QUIC,
4542
}
4643

44+
/// Node.
4745
pub struct Node<B: NetworkBehaviour> {
46+
/// Swarm.
4847
pub swarm: Swarm<B>,
4948
}
5049

5150
impl<B: NetworkBehaviour> Node<B> {
51+
/// Creates a new node.
5252
pub fn new<F>(
5353
cfg: P2PConfig,
5454
key: k256::SecretKey,
@@ -78,11 +78,12 @@ impl<B: NetworkBehaviour> Node<B> {
7878
tcp::Config::default()
7979
}
8080

81-
pub fn new_with_quic<F>(
82-
cfg: P2PConfig,
81+
/// Creates a new node with QUIC.
82+
fn new_with_quic<F>(
83+
_cfg: P2PConfig,
8384
key: k256::SecretKey,
84-
conn_gater: ConnGater,
85-
filter_private_addrs: bool,
85+
_conn_gater: ConnGater,
86+
_filter_private_addrs: bool,
8687
behaviour_fn: F,
8788
) -> Result<Self>
8889
where
@@ -91,7 +92,7 @@ impl<B: NetworkBehaviour> Node<B> {
9192
let mut der = key.to_sec1_der()?;
9293
let keypair = Keypair::secp256k1_from_der(&mut der)?;
9394

94-
let mut swarm = SwarmBuilder::with_existing_identity(keypair.clone())
95+
let swarm = SwarmBuilder::with_existing_identity(keypair.clone())
9596
.with_tokio()
9697
.with_tcp(
9798
Self::default_tcp_config(),
@@ -112,20 +113,21 @@ impl<B: NetworkBehaviour> Node<B> {
112113
Ok(Node { swarm })
113114
}
114115

115-
pub fn new_with_tcp<F>(
116-
cfg: P2PConfig,
116+
/// Creates a new node with TCP.
117+
fn new_with_tcp<F>(
118+
_cfg: P2PConfig,
117119
key: k256::SecretKey,
118-
conn_gater: ConnGater,
119-
filter_private_addrs: bool,
120+
_conn_gater: ConnGater,
121+
_filter_private_addrs: bool,
120122
behaviour_fn: F,
121123
) -> Result<Self>
122124
where
123125
F: Fn(&Keypair, relay::client::Behaviour) -> B,
124126
{
125-
let mut der = key.to_sec1_der().unwrap();
126-
let keypair = Keypair::secp256k1_from_der(&mut der).unwrap();
127+
let mut der = key.to_sec1_der()?;
128+
let keypair = Keypair::secp256k1_from_der(&mut der)?;
127129

128-
let mut swarm = SwarmBuilder::with_existing_identity(keypair.clone())
130+
let swarm = SwarmBuilder::with_existing_identity(keypair.clone())
129131
.with_tokio()
130132
.with_tcp(
131133
Self::default_tcp_config(),

0 commit comments

Comments
 (0)