http: use CompactString in AnnounceRequest, ignore key in tracker

This commit is contained in:
Joakim Frostegård 2023-02-25 22:51:25 +01:00
parent 2fa1a046d7
commit 1afe45c6f6
5 changed files with 29 additions and 26 deletions

37
Cargo.lock generated
View file

@ -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"

View file

@ -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]

View file

@ -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<I: Ip> Peer<I> {
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct PeerMapKey<I: Ip> {
pub peer_id: PeerId,
pub ip_or_key: Either<I, SmartString<LazyCompact>>,
pub ip: I,
}
pub type PeerMap<I> = IndexMap<PeerMapKey<I>, Peer<I>>;
@ -390,14 +388,9 @@ pub fn upsert_peer_and_get_response_peers<I: Ip>(
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 {

View file

@ -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]

View file

@ -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<usize>,
pub key: Option<SmartString<LazyCompact>>,
pub key: Option<CompactString>,
}
impl AnnounceRequest {