mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-13 18:11:22 +00:00
*: Fix clippy warnings (#2139)
* Fix needless question mark operator * Don't convert from u64 to u64 LocalStreamId is already a u64, no need to convert. * Don't use `.into()` to convert to the same type * Don't specify lifetime if it can be inferred * Use `vec!` macro if we immediately push to it This creates the vector with the appropriate capacity. * Don't index array when taking a reference is enough Co-authored-by: Max Inden <mail@max-inden.de>
This commit is contained in:
@ -68,8 +68,8 @@ impl PeerId {
|
|||||||
|
|
||||||
/// Parses a `PeerId` from bytes.
|
/// Parses a `PeerId` from bytes.
|
||||||
pub fn from_bytes(data: &[u8]) -> Result<PeerId, Error> {
|
pub fn from_bytes(data: &[u8]) -> Result<PeerId, Error> {
|
||||||
Ok(PeerId::from_multihash(Multihash::from_bytes(&data)?)
|
PeerId::from_multihash(Multihash::from_bytes(&data)?)
|
||||||
.map_err(|mh| Error::UnsupportedCode(mh.code()))?)
|
.map_err(|mh| Error::UnsupportedCode(mh.code()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tries to turn a `Multihash` into a `PeerId`.
|
/// Tries to turn a `Multihash` into a `PeerId`.
|
||||||
|
@ -244,25 +244,25 @@ impl Encoder for Codec {
|
|||||||
fn encode(&mut self, item: Self::Item, dst: &mut BytesMut) -> Result<(), Self::Error> {
|
fn encode(&mut self, item: Self::Item, dst: &mut BytesMut) -> Result<(), Self::Error> {
|
||||||
let (header, data) = match item {
|
let (header, data) = match item {
|
||||||
Frame::Open { stream_id } => {
|
Frame::Open { stream_id } => {
|
||||||
(u64::from(stream_id.num) << 3, Bytes::new())
|
(stream_id.num << 3, Bytes::new())
|
||||||
},
|
},
|
||||||
Frame::Data { stream_id: LocalStreamId { num, role: Endpoint::Listener }, data } => {
|
Frame::Data { stream_id: LocalStreamId { num, role: Endpoint::Listener }, data } => {
|
||||||
(u64::from(num) << 3 | 1, data)
|
(num << 3 | 1, data)
|
||||||
},
|
},
|
||||||
Frame::Data { stream_id: LocalStreamId { num, role: Endpoint::Dialer }, data } => {
|
Frame::Data { stream_id: LocalStreamId { num, role: Endpoint::Dialer }, data } => {
|
||||||
(u64::from(num) << 3 | 2, data)
|
(num << 3 | 2, data)
|
||||||
},
|
},
|
||||||
Frame::Close { stream_id: LocalStreamId { num, role: Endpoint::Listener } } => {
|
Frame::Close { stream_id: LocalStreamId { num, role: Endpoint::Listener } } => {
|
||||||
(u64::from(num) << 3 | 3, Bytes::new())
|
(num << 3 | 3, Bytes::new())
|
||||||
},
|
},
|
||||||
Frame::Close { stream_id: LocalStreamId { num, role: Endpoint::Dialer } } => {
|
Frame::Close { stream_id: LocalStreamId { num, role: Endpoint::Dialer } } => {
|
||||||
(u64::from(num) << 3 | 4, Bytes::new())
|
(num << 3 | 4, Bytes::new())
|
||||||
},
|
},
|
||||||
Frame::Reset { stream_id: LocalStreamId { num, role: Endpoint::Listener } } => {
|
Frame::Reset { stream_id: LocalStreamId { num, role: Endpoint::Listener } } => {
|
||||||
(u64::from(num) << 3 | 5, Bytes::new())
|
(num << 3 | 5, Bytes::new())
|
||||||
},
|
},
|
||||||
Frame::Reset { stream_id: LocalStreamId { num, role: Endpoint::Dialer } } => {
|
Frame::Reset { stream_id: LocalStreamId { num, role: Endpoint::Dialer } } => {
|
||||||
(u64::from(num) << 3 | 6, Bytes::new())
|
(num << 3 | 6, Bytes::new())
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -211,7 +211,7 @@ impl ProtocolsHandler for IdentifyHandler {
|
|||||||
};
|
};
|
||||||
Poll::Ready(ev)
|
Poll::Ready(ev)
|
||||||
}
|
}
|
||||||
Poll::Ready(Err(err)) => Poll::Ready(ProtocolsHandlerEvent::Close(err.into()))
|
Poll::Ready(Err(err)) => Poll::Ready(ProtocolsHandlerEvent::Close(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -207,7 +207,7 @@ where
|
|||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
debug!("Invalid message: {:?}", err);
|
debug!("Invalid message: {:?}", err);
|
||||||
return Err(err.into())
|
return Err(err)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -186,7 +186,7 @@ where
|
|||||||
///
|
///
|
||||||
/// The buckets are ordered by proximity to the `local_key`, i.e. the first
|
/// The buckets are ordered by proximity to the `local_key`, i.e. the first
|
||||||
/// bucket is the closest bucket (containing at most one key).
|
/// bucket is the closest bucket (containing at most one key).
|
||||||
pub fn iter<'a>(&'a mut self) -> impl Iterator<Item = KBucketRef<'a, TKey, TVal>> + 'a {
|
pub fn iter(&mut self) -> impl Iterator<Item = KBucketRef<'_, TKey, TVal>> + '_ {
|
||||||
let applied_pending = &mut self.applied_pending;
|
let applied_pending = &mut self.applied_pending;
|
||||||
self.buckets.iter_mut().enumerate().map(move |(i, b)| {
|
self.buckets.iter_mut().enumerate().map(move |(i, b)| {
|
||||||
if let Some(applied) = b.apply_pending() {
|
if let Some(applied) = b.apply_pending() {
|
||||||
|
@ -371,8 +371,7 @@ fn append_txt_record(
|
|||||||
if value.len() > MAX_TXT_VALUE_LENGTH {
|
if value.len() > MAX_TXT_VALUE_LENGTH {
|
||||||
return Err(MdnsResponseError::TxtRecordTooLong);
|
return Err(MdnsResponseError::TxtRecordTooLong);
|
||||||
}
|
}
|
||||||
let mut buffer = Vec::new();
|
let mut buffer = vec![value.len() as u8];
|
||||||
buffer.push(value.len() as u8);
|
|
||||||
append_character_string(&mut buffer, value)?;
|
append_character_string(&mut buffer, value)?;
|
||||||
|
|
||||||
append_u16(out, buffer.len() as u16);
|
append_u16(out, buffer.len() as u16);
|
||||||
|
@ -235,7 +235,7 @@ impl snow::types::Dh for Keypair<X25519> {
|
|||||||
|
|
||||||
fn set(&mut self, sk: &[u8]) {
|
fn set(&mut self, sk: &[u8]) {
|
||||||
let mut secret = [0u8; 32];
|
let mut secret = [0u8; 32];
|
||||||
secret.copy_from_slice(&sk[..]);
|
secret.copy_from_slice(&sk);
|
||||||
self.secret = SecretKey(X25519(secret)); // Copy
|
self.secret = SecretKey(X25519(secret)); // Copy
|
||||||
self.public = PublicKey(X25519(x25519(secret, X25519_BASEPOINT_BYTES)));
|
self.public = PublicKey(X25519(x25519(secret, X25519_BASEPOINT_BYTES)));
|
||||||
secret.zeroize();
|
secret.zeroize();
|
||||||
|
@ -146,7 +146,7 @@ impl snow::types::Dh for Keypair<X25519Spec> {
|
|||||||
|
|
||||||
fn set(&mut self, sk: &[u8]) {
|
fn set(&mut self, sk: &[u8]) {
|
||||||
let mut secret = [0u8; 32];
|
let mut secret = [0u8; 32];
|
||||||
secret.copy_from_slice(&sk[..]);
|
secret.copy_from_slice(&sk);
|
||||||
self.secret = SecretKey(X25519Spec(secret)); // Copy
|
self.secret = SecretKey(X25519Spec(secret)); // Copy
|
||||||
self.public = PublicKey(X25519Spec(x25519(secret, X25519_BASEPOINT_BYTES)));
|
self.public = PublicKey(X25519Spec(x25519(secret, X25519_BASEPOINT_BYTES)));
|
||||||
secret.zeroize();
|
secret.zeroize();
|
||||||
|
Reference in New Issue
Block a user