From 71a55bd3eea270b60c5676f11fc1893e4d72b804 Mon Sep 17 00:00:00 2001 From: hanabi1224 Date: Thu, 28 Nov 2024 08:44:55 +0800 Subject: [PATCH 1/2] chore(deps): upgrade uint to 0.10 --- Cargo.lock | 4 ++-- protocols/kad/Cargo.toml | 2 +- protocols/kad/src/kbucket.rs | 4 ++-- protocols/kad/src/kbucket/key.rs | 8 ++++---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d405464f58f..ed365bab595 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6379,9 +6379,9 @@ checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" [[package]] name = "uint" -version = "0.9.5" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" +checksum = "909988d098b2f738727b161a106cfc7cab00c539c2687a8836f8e565976fb53e" dependencies = [ "byteorder", "crunchy", diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index 295414f6ddd..63ce1e2f90c 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -26,7 +26,7 @@ libp2p-identity = { workspace = true, features = ["rand"] } rand = "0.8" sha2 = "0.10.8" smallvec = "1.13.2" -uint = "0.9" +uint = "0.10" futures-timer = "3.0.3" web-time = { workspace = true } serde = { version = "1.0", optional = true, features = ["derive"] } diff --git a/protocols/kad/src/kbucket.rs b/protocols/kad/src/kbucket.rs index 28d7df03917..420433f5482 100644 --- a/protocols/kad/src/kbucket.rs +++ b/protocols/kad/src/kbucket.rs @@ -177,7 +177,7 @@ impl BucketIndex { let lower = usize::pow(2, rem); let upper = usize::pow(2, rem + 1); bytes[31 - quot] = rng.gen_range(lower..upper) as u8; - Distance(U256::from(bytes)) + Distance(U256::from_big_endian(bytes.as_slice())) } } @@ -651,7 +651,7 @@ mod tests { fn rand_distance() { fn prop(ix: u8) -> bool { let d = BucketIndex(ix as usize).rand_distance(&mut rand::thread_rng()); - let n = U256::from(<[u8; 32]>::from(d.0)); + let n = d.0; let b = U256::from(2); let e = U256::from(ix); let lower = b.pow(e); diff --git a/protocols/kad/src/kbucket/key.rs b/protocols/kad/src/kbucket/key.rs index f35849c6b26..debc8f0c07f 100644 --- a/protocols/kad/src/kbucket/key.rs +++ b/protocols/kad/src/kbucket/key.rs @@ -163,8 +163,8 @@ impl KeyBytes { where U: AsRef, { - let a = U256::from(self.0.as_slice()); - let b = U256::from(other.as_ref().0.as_slice()); + let a = U256::from_big_endian(self.0.as_slice()); + let b = U256::from_big_endian(other.as_ref().0.as_slice()); Distance(a ^ b) } @@ -174,8 +174,8 @@ impl KeyBytes { /// /// `self xor other = distance <==> other = self xor distance` pub fn for_distance(&self, d: Distance) -> KeyBytes { - let key_int = U256::from(self.0.as_slice()) ^ d.0; - KeyBytes(GenericArray::from(<[u8; 32]>::from(key_int))) + let key_int = U256::from_big_endian(self.0.as_slice()) ^ d.0; + KeyBytes(GenericArray::from(key_int.to_big_endian())) } } From f23bea54688267f57adb5b36081bdd11d508a6a1 Mon Sep 17 00:00:00 2001 From: hanabi1224 Date: Thu, 28 Nov 2024 09:04:08 +0800 Subject: [PATCH 2/2] fix clippy(beta) --- swarm/src/connection/pool.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swarm/src/connection/pool.rs b/swarm/src/connection/pool.rs index b2accf745ef..7964ecbfa69 100644 --- a/swarm/src/connection/pool.rs +++ b/swarm/src/connection/pool.rs @@ -207,7 +207,7 @@ struct PendingConnection { impl PendingConnection { fn is_for_same_remote_as(&self, other: PeerId) -> bool { - self.peer_id.map_or(false, |peer| peer == other) + self.peer_id == Some(other) } /// Aborts the connection attempt, closing the connection.