From e2be31c7debb28b103f65d25fa2c53d49c9920bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Mon, 18 Oct 2021 01:27:16 +0200 Subject: [PATCH] aquatic_udp: move ConnectionKey and ConnectionMap to network.rs --- aquatic_udp/src/lib/common.rs | 19 +------------------ aquatic_udp/src/lib/network.rs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/aquatic_udp/src/lib/common.rs b/aquatic_udp/src/lib/common.rs index 3f48017..c89b94f 100644 --- a/aquatic_udp/src/lib/common.rs +++ b/aquatic_udp/src/lib/common.rs @@ -1,5 +1,5 @@ use std::hash::Hash; -use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}; +use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; use std::sync::{atomic::AtomicUsize, Arc}; use std::time::Instant; @@ -49,23 +49,6 @@ impl Into for ConnectedResponse { } } -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ConnectionKey { - pub connection_id: ConnectionId, - pub socket_addr: SocketAddr, -} - -impl ConnectionKey { - pub fn new(connection_id: ConnectionId, socket_addr: SocketAddr) -> Self { - Self { - connection_id, - socket_addr, - } - } -} - -pub type ConnectionMap = HashMap; - #[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)] pub enum PeerStatus { Seeding, diff --git a/aquatic_udp/src/lib/network.rs b/aquatic_udp/src/lib/network.rs index c8cd776..82d1117 100644 --- a/aquatic_udp/src/lib/network.rs +++ b/aquatic_udp/src/lib/network.rs @@ -8,6 +8,7 @@ use std::time::{Duration, Instant}; use std::vec::Drain; use crossbeam_channel::{Receiver, Sender}; +use hashbrown::HashMap; use mio::net::UdpSocket; use mio::{Events, Interest, Poll, Token}; use rand::prelude::{Rng, SeedableRng, StdRng}; @@ -18,6 +19,23 @@ use aquatic_udp_protocol::{IpVersion, Request, Response}; use crate::common::*; use crate::config::Config; +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct ConnectionKey { + pub connection_id: ConnectionId, + pub socket_addr: SocketAddr, +} + +impl ConnectionKey { + pub fn new(connection_id: ConnectionId, socket_addr: SocketAddr) -> Self { + Self { + connection_id, + socket_addr, + } + } +} + +pub type ConnectionMap = HashMap; + pub fn run_socket_worker( state: State, config: Config,