mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
Use regular (ahash) IndexMap for PeerMaps
This commit is contained in:
parent
5f0971e952
commit
c76d7442e2
7 changed files with 16 additions and 8 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -68,6 +68,7 @@ dependencies = [
|
||||||
"hashbrown 0.12.3",
|
"hashbrown 0.12.3",
|
||||||
"hex",
|
"hex",
|
||||||
"hwloc",
|
"hwloc",
|
||||||
|
"indexmap",
|
||||||
"indexmap-amortized",
|
"indexmap-amortized",
|
||||||
"libc",
|
"libc",
|
||||||
"log",
|
"log",
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ duplicate = "0.4"
|
||||||
git-testament = "0.2"
|
git-testament = "0.2"
|
||||||
hashbrown = "0.12"
|
hashbrown = "0.12"
|
||||||
hex = "0.4"
|
hex = "0.4"
|
||||||
|
indexmap = "1"
|
||||||
indexmap-amortized = "1"
|
indexmap-amortized = "1"
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,9 @@ pub mod privileges;
|
||||||
#[cfg(feature = "rustls")]
|
#[cfg(feature = "rustls")]
|
||||||
pub mod rustls_config;
|
pub mod rustls_config;
|
||||||
|
|
||||||
|
/// IndexMap using AHash hasher
|
||||||
|
pub type IndexMap<K, V> = indexmap::IndexMap<K, V, RandomState>;
|
||||||
|
|
||||||
/// Amortized IndexMap using AHash hasher
|
/// Amortized IndexMap using AHash hasher
|
||||||
pub type AmortizedIndexMap<K, V> = indexmap_amortized::IndexMap<K, V, RandomState>;
|
pub type AmortizedIndexMap<K, V> = indexmap_amortized::IndexMap<K, V, RandomState>;
|
||||||
|
|
||||||
|
|
@ -104,7 +107,7 @@ impl Drop for PanicSentinel {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn extract_response_peers<K, V, R, F>(
|
pub fn extract_response_peers<K, V, R, F>(
|
||||||
rng: &mut impl Rng,
|
rng: &mut impl Rng,
|
||||||
peer_map: &AmortizedIndexMap<K, V>,
|
peer_map: &IndexMap<K, V>,
|
||||||
max_num_peers_to_take: usize,
|
max_num_peers_to_take: usize,
|
||||||
sender_peer_map_key: K,
|
sender_peer_map_key: K,
|
||||||
peer_conversion_function: F,
|
peer_conversion_function: F,
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ use rand::SeedableRng;
|
||||||
use smartstring::{LazyCompact, SmartString};
|
use smartstring::{LazyCompact, SmartString};
|
||||||
|
|
||||||
use aquatic_common::access_list::{create_access_list_cache, AccessListArcSwap, AccessListCache};
|
use aquatic_common::access_list::{create_access_list_cache, AccessListArcSwap, AccessListCache};
|
||||||
use aquatic_common::{extract_response_peers, PanicSentinel};
|
use aquatic_common::{extract_response_peers, IndexMap, PanicSentinel};
|
||||||
use aquatic_common::{AmortizedIndexMap, CanonicalSocketAddr};
|
use aquatic_common::{AmortizedIndexMap, CanonicalSocketAddr};
|
||||||
use aquatic_common::{SecondsSinceServerStart, ServerStartInstant, ValidUntil};
|
use aquatic_common::{SecondsSinceServerStart, ServerStartInstant, ValidUntil};
|
||||||
use aquatic_http_protocol::common::*;
|
use aquatic_http_protocol::common::*;
|
||||||
|
|
@ -78,7 +78,7 @@ pub struct PeerMapKey<I: Ip> {
|
||||||
pub ip_or_key: Either<I, SmartString<LazyCompact>>,
|
pub ip_or_key: Either<I, SmartString<LazyCompact>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type PeerMap<I> = AmortizedIndexMap<PeerMapKey<I>, Peer<I>>;
|
pub type PeerMap<I> = IndexMap<PeerMapKey<I>, Peer<I>>;
|
||||||
|
|
||||||
pub struct TorrentData<I: Ip> {
|
pub struct TorrentData<I: Ip> {
|
||||||
pub peers: PeerMap<I>,
|
pub peers: PeerMap<I>,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
use std::net::{Ipv4Addr, Ipv6Addr};
|
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||||
|
|
||||||
use aquatic_common::{AmortizedIndexMap, SecondsSinceServerStart, ServerStartInstant, ValidUntil};
|
use aquatic_common::{
|
||||||
|
AmortizedIndexMap, IndexMap, SecondsSinceServerStart, ServerStartInstant, ValidUntil,
|
||||||
|
};
|
||||||
use aquatic_http_protocol::common::{AnnounceEvent, InfoHash, PeerId};
|
use aquatic_http_protocol::common::{AnnounceEvent, InfoHash, PeerId};
|
||||||
use aquatic_http_protocol::response::ResponsePeer;
|
use aquatic_http_protocol::response::ResponsePeer;
|
||||||
|
|
||||||
|
|
@ -55,7 +57,7 @@ pub struct PeerMapKey<I: Ip> {
|
||||||
pub ip_address: I,
|
pub ip_address: I,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type PeerMap<I> = AmortizedIndexMap<PeerMapKey<I>, Peer<I>>;
|
pub type PeerMap<I> = IndexMap<PeerMapKey<I>, Peer<I>>;
|
||||||
|
|
||||||
pub struct TorrentData<I: Ip> {
|
pub struct TorrentData<I: Ip> {
|
||||||
pub peers: PeerMap<I>,
|
pub peers: PeerMap<I>,
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ use std::net::Ipv4Addr;
|
||||||
use std::net::Ipv6Addr;
|
use std::net::Ipv6Addr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use aquatic_common::IndexMap;
|
||||||
use aquatic_common::SecondsSinceServerStart;
|
use aquatic_common::SecondsSinceServerStart;
|
||||||
use aquatic_common::ServerStartInstant;
|
use aquatic_common::ServerStartInstant;
|
||||||
use aquatic_common::{
|
use aquatic_common::{
|
||||||
|
|
@ -35,7 +36,7 @@ impl<I: Ip> Peer<I> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type PeerMap<I> = AmortizedIndexMap<PeerId, Peer<I>>;
|
pub type PeerMap<I> = IndexMap<PeerId, Peer<I>>;
|
||||||
|
|
||||||
pub struct TorrentData<I: Ip> {
|
pub struct TorrentData<I: Ip> {
|
||||||
peers: PeerMap<I>,
|
peers: PeerMap<I>,
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ use hashbrown::HashMap;
|
||||||
use rand::{rngs::SmallRng, SeedableRng};
|
use rand::{rngs::SmallRng, SeedableRng};
|
||||||
|
|
||||||
use aquatic_common::{
|
use aquatic_common::{
|
||||||
extract_response_peers, AmortizedIndexMap, PanicSentinel, SecondsSinceServerStart,
|
extract_response_peers, AmortizedIndexMap, IndexMap, PanicSentinel, SecondsSinceServerStart,
|
||||||
ServerStartInstant,
|
ServerStartInstant,
|
||||||
};
|
};
|
||||||
use aquatic_ws_protocol::*;
|
use aquatic_ws_protocol::*;
|
||||||
|
|
@ -53,7 +53,7 @@ struct Peer {
|
||||||
pub valid_until: ValidUntil,
|
pub valid_until: ValidUntil,
|
||||||
}
|
}
|
||||||
|
|
||||||
type PeerMap = AmortizedIndexMap<PeerId, Peer>;
|
type PeerMap = IndexMap<PeerId, Peer>;
|
||||||
|
|
||||||
struct TorrentData {
|
struct TorrentData {
|
||||||
pub peers: PeerMap,
|
pub peers: PeerMap,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue