Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
kpp committed Sep 11, 2021
1 parent 70a067a commit 2286537
Show file tree
Hide file tree
Showing 25 changed files with 96 additions and 122 deletions.
2 changes: 1 addition & 1 deletion core/src/connection/manager/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ where
Poll::Ready(Ok(())) => {
let event = Event::Closed {
id: this.id,
error: error.map(|limit| ConnectionError::ConnectionLimit(limit)),
error: error.map(ConnectionError::ConnectionLimit),
handler,
};
this.state = State::Terminating(event);
Expand Down
2 changes: 1 addition & 1 deletion core/src/connection/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ impl<THandler: IntoConnectionHandler, TTransErr> Pool<THandler, TTransErr> {
/// Returns an iterator for information on all pending outgoing connections.
pub fn iter_pending_outgoing(&self) -> impl Iterator<Item = OutgoingInfo<'_>> {
self.iter_pending_info()
.filter_map(|(_, ref endpoint, ref peer_id)| match endpoint {
.filter_map(|(_, ref endpoint, peer_id)| match endpoint {
ConnectedPoint::Listener { .. } => None,
ConnectedPoint::Dialer { address } => Some(OutgoingInfo {
address,
Expand Down
9 changes: 4 additions & 5 deletions core/src/identity/rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl Keypair {
///
/// [RFC5208]: https://tools.ietf.org/html/rfc5208#section-5
pub fn from_pkcs8(der: &mut [u8]) -> Result<Keypair, DecodingError> {
let kp = RsaKeyPair::from_pkcs8(&der)
let kp = RsaKeyPair::from_pkcs8(der)
.map_err(|e| DecodingError::new("RSA PKCS#8 PrivateKeyInfo").source(e))?;
der.zeroize();
Ok(Keypair(Arc::new(kp)))
Expand All @@ -54,7 +54,7 @@ impl Keypair {
pub fn sign(&self, data: &[u8]) -> Result<Vec<u8>, SigningError> {
let mut signature = vec![0; self.0.public_modulus_len()];
let rng = SystemRandom::new();
match self.0.sign(&RSA_PKCS1_SHA256, &rng, &data, &mut signature) {
match self.0.sign(&RSA_PKCS1_SHA256, &rng, data, &mut signature) {
Ok(()) => Ok(signature),
Err(e) => Err(SigningError::new("RSA").source(e)),
}
Expand Down Expand Up @@ -94,11 +94,10 @@ impl PublicKey {
subjectPublicKey: Asn1SubjectPublicKey(self.clone()),
};
let mut buf = Vec::new();
let buf = spki
spki
.encode(&mut buf)
.map(|_| buf)
.expect("RSA X.509 public key encoding failed.");
buf
.expect("RSA X.509 public key encoding failed.")
}

/// Decode an RSA public key from a DER-encoded X.509 SubjectPublicKeyInfo
Expand Down
2 changes: 1 addition & 1 deletion core/src/peer_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl PeerId {

/// Parses a `PeerId` from bytes.
pub fn from_bytes(data: &[u8]) -> Result<PeerId, Error> {
PeerId::from_multihash(Multihash::from_bytes(&data)?)
PeerId::from_multihash(Multihash::from_bytes(data)?)
.map_err(|mh| Error::UnsupportedCode(mh.code()))
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/signed_envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl SignedEnvelope {
domain_separation: String,
expected_payload_type: &[u8],
) -> Result<&[u8], ReadPayloadError> {
if &self.payload_type != expected_payload_type {
if self.payload_type != expected_payload_type {
return Err(ReadPayloadError::UnexpectedPayloadType {
expected: expected_payload_type.to_vec(),
got: self.payload_type.clone(),
Expand Down
2 changes: 1 addition & 1 deletion misc/multistream-select/src/length_delimited.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl<R> LengthDelimited<R> {
let mut this = self.project();

while !this.write_buffer.is_empty() {
match this.inner.as_mut().poll_write(cx, &this.write_buffer) {
match this.inner.as_mut().poll_write(cx, this.write_buffer) {
Poll::Pending => return Poll::Pending,
Poll::Ready(Ok(0)) => {
return Poll::Ready(Err(io::Error::new(
Expand Down
40 changes: 20 additions & 20 deletions protocols/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ enum PublishConfig {
impl PublishConfig {
pub fn get_own_id(&self) -> Option<&PeerId> {
match self {
Self::Signing { author, .. } => Some(&author),
Self::Author(author) => Some(&author),
Self::Signing { author, .. } => Some(author),
Self::Author(author) => Some(author),
_ => None,
}
}
Expand Down Expand Up @@ -381,7 +381,7 @@ where

// We do not allow configurations where a published message would also be rejected if it
// were received locally.
validate_config(&privacy, &config.validation_mode())?;
validate_config(&privacy, config.validation_mode())?;

// Set up message publishing parameters.

Expand Down Expand Up @@ -990,7 +990,7 @@ where
get_random_peers(
&self.topic_peers,
&self.connected_peers,
&topic_hash,
topic_hash,
self.config.prune_peers(),
|p| p != peer && !self.score_below_threshold(p, |_| 0.0).0,
)
Expand Down Expand Up @@ -1337,7 +1337,7 @@ where
*peer_id,
vec![&topic_hash],
&self.mesh,
self.peer_topics.get(&peer_id),
self.peer_topics.get(peer_id),
&mut self.events,
&self.connected_peers,
);
Expand Down Expand Up @@ -1396,7 +1396,7 @@ where
always_update_backoff: bool,
) {
let mut update_backoff = always_update_backoff;
if let Some(peers) = self.mesh.get_mut(&topic_hash) {
if let Some(peers) = self.mesh.get_mut(topic_hash) {
// remove the peer if it exists in the mesh
if peers.remove(peer_id) {
debug!(
Expand All @@ -1416,7 +1416,7 @@ where
*peer_id,
topic_hash,
&self.mesh,
self.peer_topics.get(&peer_id),
self.peer_topics.get(peer_id),
&mut self.events,
&self.connected_peers,
);
Expand All @@ -1429,7 +1429,7 @@ where
self.config.prune_backoff()
};
// is there a backoff specified by the peer? if so obey it.
self.backoffs.update_backoff(&topic_hash, peer_id, time);
self.backoffs.update_backoff(topic_hash, peer_id, time);
}
}

Expand Down Expand Up @@ -1570,7 +1570,7 @@ where
own_id != propagation_source
&& raw_message.source.as_ref().map_or(false, |s| s == own_id)
} else {
self.published_message_ids.contains(&msg_id)
self.published_message_ids.contains(msg_id)
};

if self_published {
Expand Down Expand Up @@ -2176,7 +2176,7 @@ where
"HEARTBEAT: Fanout topic removed due to timeout. Topic: {:?}",
topic_hash
);
fanout.remove(&topic_hash);
fanout.remove(topic_hash);
return false;
}
true
Expand All @@ -2195,7 +2195,7 @@ where
// is the peer still subscribed to the topic?
match self.peer_topics.get(peer) {
Some(topics) => {
if !topics.contains(&topic_hash) || score(peer) < publish_threshold {
if !topics.contains(topic_hash) || score(peer) < publish_threshold {
debug!(
"HEARTBEAT: Peer removed from fanout for topic: {:?}",
topic_hash
Expand Down Expand Up @@ -2291,7 +2291,7 @@ where
fn emit_gossip(&mut self) {
let mut rng = thread_rng();
for (topic_hash, peers) in self.mesh.iter().chain(self.fanout.iter()) {
let mut message_ids = self.mcache.get_gossip_message_ids(&topic_hash);
let mut message_ids = self.mcache.get_gossip_message_ids(topic_hash);
if message_ids.is_empty() {
return;
}
Expand Down Expand Up @@ -2319,7 +2319,7 @@ where
let to_msg_peers = get_random_peers_dynamic(
&self.topic_peers,
&self.connected_peers,
&topic_hash,
topic_hash,
n_map,
|peer| {
!peers.contains(peer)
Expand Down Expand Up @@ -2438,7 +2438,7 @@ where
*peer,
topic_hash,
&self.mesh,
self.peer_topics.get(&peer),
self.peer_topics.get(peer),
&mut self.events,
&self.connected_peers,
);
Expand Down Expand Up @@ -2483,7 +2483,7 @@ where
// add mesh peers
let topic = &message.topic;
// mesh
if let Some(mesh_peers) = self.mesh.get(&topic) {
if let Some(mesh_peers) = self.mesh.get(topic) {
for peer_id in mesh_peers {
if Some(peer_id) != propagation_source && Some(peer_id) != message.source.as_ref() {
recipient_peers.insert(*peer_id);
Expand Down Expand Up @@ -2877,13 +2877,13 @@ where
// remove peer from all mappings
for topic in topics {
// check the mesh for the topic
if let Some(mesh_peers) = self.mesh.get_mut(&topic) {
if let Some(mesh_peers) = self.mesh.get_mut(topic) {
// check if the peer is in the mesh and remove it
mesh_peers.remove(peer_id);
}

// remove from topic_peers
if let Some(peer_list) = self.topic_peers.get_mut(&topic) {
if let Some(peer_list) = self.topic_peers.get_mut(topic) {
if !peer_list.remove(peer_id) {
// debugging purposes
warn!(
Expand All @@ -2900,7 +2900,7 @@ where

// remove from fanout
self.fanout
.get_mut(&topic)
.get_mut(topic)
.map(|peers| peers.remove(peer_id));
}
}
Expand Down Expand Up @@ -2943,7 +2943,7 @@ where
// Add the IP to the peer scoring system
if let Some((peer_score, ..)) = &mut self.peer_score {
if let Some(ip) = get_ip_addr(endpoint.get_remote_address()) {
peer_score.add_ip(&peer_id, ip);
peer_score.add_ip(peer_id, ip);
} else {
trace!(
"Couldn't extract ip from endpoint of peer {} with endpoint {:?}",
Expand Down Expand Up @@ -3041,7 +3041,7 @@ where
)
}
if let Some(ip) = get_ip_addr(endpoint_new.get_remote_address()) {
peer_score.add_ip(&peer, ip);
peer_score.add_ip(peer, ip);
} else {
trace!(
"Couldn't extract ip from endpoint of peer {} with endpoint {:?}",
Expand Down
6 changes: 3 additions & 3 deletions protocols/gossipsub/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl GossipsubCodec {
}
};

let source = match PeerId::from_bytes(&from) {
let source = match PeerId::from_bytes(from) {
Ok(v) => v,
Err(_) => {
debug!("Signature verification failed: Invalid Peer Id");
Expand All @@ -214,8 +214,8 @@ impl GossipsubCodec {
// obtained from the inlined source peer_id.
let public_key = match message
.key
.as_ref()
.map(|key| PublicKey::from_protobuf_encoding(&key))
.as_deref()
.map(PublicKey::from_protobuf_encoding)
{
Some(Ok(key)) => key,
_ => match PublicKey::from_protobuf_encoding(&source.to_bytes()[2..]) {
Expand Down
48 changes: 18 additions & 30 deletions protocols/kad/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -803,16 +803,12 @@ fn advance_substream<TUserData>(
true,
),
Err(error) => {
let event = if let Some(user_data) = user_data {
Some(ProtocolsHandlerEvent::Custom(
KademliaHandlerEvent::QueryError {
error: KademliaHandlerQueryErr::Io(error),
user_data,
},
))
} else {
None
};
let event = user_data.map(|user_data| {
ProtocolsHandlerEvent::Custom(KademliaHandlerEvent::QueryError {
error: KademliaHandlerQueryErr::Io(error),
user_data,
})
});

(None, event, false)
}
Expand All @@ -823,16 +819,12 @@ fn advance_substream<TUserData>(
false,
),
Poll::Ready(Err(error)) => {
let event = if let Some(user_data) = user_data {
Some(ProtocolsHandlerEvent::Custom(
KademliaHandlerEvent::QueryError {
error: KademliaHandlerQueryErr::Io(error),
user_data,
},
))
} else {
None
};
let event = user_data.map(|user_data| {
ProtocolsHandlerEvent::Custom(KademliaHandlerEvent::QueryError {
error: KademliaHandlerQueryErr::Io(error),
user_data,
})
});

(None, event, false)
}
Expand All @@ -857,16 +849,12 @@ fn advance_substream<TUserData>(
false,
),
Poll::Ready(Err(error)) => {
let event = if let Some(user_data) = user_data {
Some(ProtocolsHandlerEvent::Custom(
KademliaHandlerEvent::QueryError {
error: KademliaHandlerQueryErr::Io(error),
user_data,
},
))
} else {
None
};
let event = user_data.map(|user_data| {
ProtocolsHandlerEvent::Custom(KademliaHandlerEvent::QueryError {
error: KademliaHandlerQueryErr::Io(error),
user_data,
})
});

(None, event, false)
}
Expand Down
2 changes: 1 addition & 1 deletion protocols/kad/src/kbucket/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ where
let (node, status, _pos) = self
.0
.bucket
.remove(&self.0.key)
.remove(self.0.key)
.expect("We can only build a PresentEntry if the entry is in the bucket; QED");
EntryView { node, status }
}
Expand Down
6 changes: 4 additions & 2 deletions protocols/kad/src/query/peers/fixed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,18 @@ enum PeerState {
}

impl FixedPeersIter {
#[allow(clippy::needless_collect)]
pub fn new<I>(peers: I, parallelism: NonZeroUsize) -> Self
where
I: IntoIterator<Item = PeerId>,
{
let peers = peers.into_iter().collect::<Vec<_>>();
let peers_vec = peers.into_iter().collect::<Vec<_>>();

Self {
parallelism,
peers: FnvHashMap::default(),
iter: peers.into_iter(),

iter: peers_vec.into_iter(),
state: State::Waiting { num_waiting: 0 },
}
}
Expand Down
2 changes: 1 addition & 1 deletion protocols/mdns/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ impl Mdns {

let mut addrs: Vec<Multiaddr> = Vec::new();
for addr in peer.addresses() {
if let Some(new_addr) = address_translation(&addr, &observed) {
if let Some(new_addr) = address_translation(addr, &observed) {
addrs.push(new_addr.clone())
}
addrs.push(addr.clone())
Expand Down
4 changes: 2 additions & 2 deletions protocols/mdns/src/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,11 @@ fn query_response_packet(id: u16, peer_id: &[u8], records: &[Vec<u8>], ttl: u32)

// Peer Id.
append_u16(&mut out, peer_id.len() as u16);
out.extend_from_slice(&peer_id);
out.extend_from_slice(peer_id);

// The TXT records.
for record in records {
out.extend_from_slice(&record);
out.extend_from_slice(record);
}

out
Expand Down
Loading

0 comments on commit 2286537

Please sign in to comment.