From 1afe45c6f6b018987ef4cbf657b6ebc3e0ce3408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Sat, 25 Feb 2023 22:51:25 +0100 Subject: [PATCH] http: use CompactString in AnnounceRequest, ignore key in tracker --- Cargo.lock | 37 ++++++++++++++++++---------- aquatic_http/Cargo.toml | 1 - aquatic_http/src/workers/swarm.rs | 11 ++------- aquatic_http_protocol/Cargo.toml | 2 +- aquatic_http_protocol/src/request.rs | 4 +-- 5 files changed, 29 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d5ce2ab..0dcb145 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -122,7 +122,6 @@ dependencies = [ "serde", "signal-hook", "slab", - "smartstring", "socket2 0.4.7", ] @@ -180,6 +179,7 @@ dependencies = [ "anyhow", "axum", "bendy", + "compact_str", "criterion", "hex", "httparse", @@ -190,7 +190,6 @@ dependencies = [ "quickcheck_macros", "serde", "serde_bencode", - "smartstring", "urlencoding", ] @@ -601,6 +600,15 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" +[[package]] +name = "castaway" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a17ed5635fc8536268e5d4de1e22e81ac34419e5f052d4d51f4e01dcc263fcc" +dependencies = [ + "rustversion", +] + [[package]] name = "cc" version = "1.0.79" @@ -635,6 +643,20 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "compact_str" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bff0805f79ecb1b35163f3957a6934ea8d04fcd36ef98b52e7316f63e72e73d1" +dependencies = [ + "castaway", + "cfg-if", + "itoa", + "ryu", + "serde", + "static_assertions", +] + [[package]] name = "concurrent-queue" version = "1.2.4" @@ -2542,17 +2564,6 @@ version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" -[[package]] -name = "smartstring" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29" -dependencies = [ - "autocfg", - "static_assertions", - "version_check", -] - [[package]] name = "snafu" version = "0.7.4" diff --git a/aquatic_http/Cargo.toml b/aquatic_http/Cargo.toml index d160bea..de3640c 100644 --- a/aquatic_http/Cargo.toml +++ b/aquatic_http/Cargo.toml @@ -46,7 +46,6 @@ rustls-pemfile = "1" serde = { version = "1", features = ["derive"] } signal-hook = { version = "0.3" } slab = "0.4" -smartstring = "1" socket2 = { version = "0.4", features = ["all"] } [dev-dependencies] diff --git a/aquatic_http/src/workers/swarm.rs b/aquatic_http/src/workers/swarm.rs index ded87d8..a6a5aeb 100644 --- a/aquatic_http/src/workers/swarm.rs +++ b/aquatic_http/src/workers/swarm.rs @@ -5,7 +5,6 @@ use std::rc::Rc; use std::sync::Arc; use std::time::Duration; -use either::Either; use futures_lite::{Stream, StreamExt}; use glommio::channels::channel_mesh::{MeshBuilder, Partial, Role}; use glommio::timer::TimerActionRepeat; @@ -13,7 +12,6 @@ use glommio::{enclose, prelude::*}; use rand::prelude::SmallRng; use rand::Rng; use rand::SeedableRng; -use smartstring::{LazyCompact, SmartString}; use aquatic_common::access_list::{create_access_list_cache, AccessListArcSwap, AccessListCache}; use aquatic_common::{ @@ -92,7 +90,7 @@ impl Peer { #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct PeerMapKey { pub peer_id: PeerId, - pub ip_or_key: Either>, + pub ip: I, } pub type PeerMap = IndexMap, Peer>; @@ -390,14 +388,9 @@ pub fn upsert_peer_and_get_response_peers( let peer_status = PeerStatus::from_event_and_bytes_left(request.event, Some(request.bytes_left)); - let ip_or_key = request - .key - .map(Either::Right) - .unwrap_or_else(|| Either::Left(peer_ip_address)); - let peer_map_key = PeerMapKey { peer_id: request.peer_id, - ip_or_key, + ip: peer_ip_address, }; let opt_removed_peer = match peer_status { diff --git a/aquatic_http_protocol/Cargo.toml b/aquatic_http_protocol/Cargo.toml index 9a1d599..606fb32 100644 --- a/aquatic_http_protocol/Cargo.toml +++ b/aquatic_http_protocol/Cargo.toml @@ -26,6 +26,7 @@ harness = false [dependencies] anyhow = "1" axum = { version = "0.5", optional = true, default-features = false } +compact_str = { version = "0.7", features = ["serde"] } hex = { version = "0.4", default-features = false } httparse = "1" itoa = "1" @@ -33,7 +34,6 @@ log = "0.4" memchr = "2" serde = { version = "1", features = ["derive"] } serde_bencode = "0.2" -smartstring = "1" urlencoding = "2" [dev-dependencies] diff --git a/aquatic_http_protocol/src/request.rs b/aquatic_http_protocol/src/request.rs index 520e0d1..db4c7e2 100644 --- a/aquatic_http_protocol/src/request.rs +++ b/aquatic_http_protocol/src/request.rs @@ -1,7 +1,7 @@ use std::io::Write; use anyhow::Context; -use smartstring::{LazyCompact, SmartString}; +use compact_str::CompactString; use super::common::*; use super::utils::*; @@ -17,7 +17,7 @@ pub struct AnnounceRequest { pub event: AnnounceEvent, /// Number of response peers wanted pub numwant: Option, - pub key: Option>, + pub key: Option, } impl AnnounceRequest {