chore(clippy): make clippy happy (#334)

This commit is contained in:
Matthias Seitz
2022-12-05 18:36:20 +01:00
committed by Georgios Konstantopoulos
parent a68cb3f357
commit a4472ca1c6
6 changed files with 37 additions and 36 deletions

View File

@ -1,3 +1,5 @@
//! All capability related types
use crate::{version::ParseVersionError, EthMessage, EthVersion};
use bytes::{BufMut, Bytes};
use reth_rlp::{Decodable, DecodeError, Encodable, RlpDecodable, RlpEncodable};
@ -121,6 +123,7 @@ impl Decodable for Capabilities {
/// This represents a shared capability, its version, and its offset.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[allow(missing_docs)]
pub enum SharedCapability {
/// The `eth` capability.
Eth { version: EthVersion, offset: u8 },
@ -139,7 +142,7 @@ impl SharedCapability {
}
/// Returns the name of the capability.
pub(crate) fn name(&self) -> &str {
pub fn name(&self) -> &str {
match self {
SharedCapability::Eth { .. } => "eth",
SharedCapability::UnknownCapability { name, .. } => name,
@ -147,7 +150,7 @@ impl SharedCapability {
}
/// Returns the version of the capability.
pub(crate) fn version(&self) -> u8 {
pub fn version(&self) -> u8 {
match self {
SharedCapability::Eth { version, .. } => *version as u8,
SharedCapability::UnknownCapability { version, .. } => *version,
@ -155,7 +158,7 @@ impl SharedCapability {
}
/// Returns the message ID offset of the current capability.
pub(crate) fn offset(&self) -> u8 {
pub fn offset(&self) -> u8 {
match self {
SharedCapability::Eth { offset, .. } => *offset,
SharedCapability::UnknownCapability { offset, .. } => *offset,
@ -163,7 +166,7 @@ impl SharedCapability {
}
/// Returns the number of protocol messages supported by this capability.
pub(crate) fn num_messages(&self) -> Result<u8, SharedCapabilityError> {
pub fn num_messages(&self) -> Result<u8, SharedCapabilityError> {
match self {
SharedCapability::Eth { version, .. } => Ok(version.total_messages()),
_ => Err(SharedCapabilityError::UnknownCapability),

View File

@ -1,7 +1,8 @@
use std::fmt::Display;
//! Disconnect
use bytes::Buf;
use reth_rlp::{Decodable, DecodeError, Encodable, EMPTY_LIST_CODE};
use std::fmt::Display;
use thiserror::Error;
/// RLPx disconnect reason.
@ -21,8 +22,11 @@ pub enum DisconnectReason {
AlreadyConnected = 0x05,
/// `p2p` protocol version is incompatible
IncompatibleP2PProtocolVersion = 0x06,
/// Received a null node identity.
NullNodeIdentity = 0x07,
/// Reason when the client is shutting down.
ClientQuitting = 0x08,
/// When the received handshake's identify is different from what is expected.
UnexpectedHandshakeIdentity = 0x09,
/// The node is connected to itself
ConnectedToSelf = 0x0a,
@ -149,9 +153,8 @@ mod tests {
};
use reth_rlp::{Decodable, Encodable};
#[test]
fn disconnect_round_trip() {
let all_reasons = vec![
fn all_reasons() -> Vec<DisconnectReason> {
vec![
DisconnectReason::DisconnectRequested,
DisconnectReason::TcpSubsystemError,
DisconnectReason::ProtocolBreach,
@ -165,7 +168,12 @@ mod tests {
DisconnectReason::ConnectedToSelf,
DisconnectReason::PingTimeout,
DisconnectReason::SubprotocolSpecific,
];
]
}
#[test]
fn disconnect_round_trip() {
let all_reasons = all_reasons();
for reason in all_reasons {
let disconnect = P2PMessage::Disconnect(reason);
@ -186,21 +194,7 @@ mod tests {
#[test]
fn disconnect_encoding_length() {
let all_reasons = vec![
DisconnectReason::DisconnectRequested,
DisconnectReason::TcpSubsystemError,
DisconnectReason::ProtocolBreach,
DisconnectReason::UselessPeer,
DisconnectReason::TooManyPeers,
DisconnectReason::AlreadyConnected,
DisconnectReason::IncompatibleP2PProtocolVersion,
DisconnectReason::NullNodeIdentity,
DisconnectReason::ClientQuitting,
DisconnectReason::UnexpectedHandshakeIdentity,
DisconnectReason::ConnectedToSelf,
DisconnectReason::PingTimeout,
DisconnectReason::SubprotocolSpecific,
];
let all_reasons = all_reasons();
for reason in all_reasons {
let disconnect = P2PMessage::Disconnect(reason);
@ -232,8 +226,7 @@ mod tests {
// ensure that the two encodings are equal
assert_eq!(
disconnect_expected, disconnect_encoded,
"left: {:#x?}, right: {:#x?}",
disconnect_expected, disconnect_encoded
"left: {disconnect_expected:#x?}, right: {disconnect_encoded:#x?}"
);
// also ensure that the length is correct

View File

@ -57,6 +57,7 @@ pub enum HandshakeError {
/// Errors when sending/receiving p2p messages. These should result in kicking the peer.
#[derive(thiserror::Error, Debug)]
#[allow(missing_docs)]
pub enum P2PStreamError {
#[error(transparent)]
Io(#[from] io::Error),
@ -104,7 +105,8 @@ impl P2PStreamError {
}
/// Errors when conducting a p2p handshake
#[derive(thiserror::Error, Debug)]
#[derive(thiserror::Error, Debug, Clone, Eq, PartialEq)]
#[allow(missing_docs)]
pub enum P2PHandshakeError {
#[error("hello message can only be recv/sent in handshake")]
HelloNotInHandshake,

View File

@ -1,6 +1,4 @@
#![allow(dead_code)] // TODO: REMOVE once eth-wire is done.
// #![warn(missing_docs, unreachable_pub)]
#![allow(missing_docs, unreachable_pub)]
#![warn(missing_docs, unreachable_pub)]
#![deny(unused_must_use, rust_2018_idioms)]
#![doc(test(
no_crate_inject,

View File

@ -201,6 +201,11 @@ impl<S> P2PStream<S> {
}
}
/// Returns the shared capability for this stream.
pub fn shared_capability(&self) -> &SharedCapability {
&self.shared_capability
}
/// Returns `true` if the connection is about to disconnect.
pub fn is_disconnecting(&self) -> bool {
self.disconnecting
@ -815,8 +820,7 @@ mod tests {
// ensure that the two encodings are equal
assert_eq!(
ping_expected, ping_encoded,
"left: {:#x?}, right: {:#x?}",
ping_expected, ping_encoded
"left: {ping_expected:#x?}, right: {ping_encoded:#x?}"
);
// also ensure that the length is correct
@ -852,8 +856,7 @@ mod tests {
// ensure that the two encodings are equal
assert_eq!(
pong_expected, pong_encoded,
"left: {:#x?}, right: {:#x?}",
pong_expected, pong_encoded
"left: {pong_expected:#x?}, right: {pong_encoded:#x?}"
);
// also ensure that the length is correct

View File

@ -1,8 +1,10 @@
//! Support for representing the version of the `eth`. [`Capability`].
use crate::capability::Capability;
use std::str::FromStr;
use thiserror::Error;
use crate::capability::Capability;
/// Error thrown when failed to parse a valid [`EthVersion`].
#[derive(Debug, Clone, PartialEq, Eq, Error)]
#[error("Unknown eth protocol version: {0}")]
pub struct ParseVersionError(String);