aquatic_udp: move ConnectionKey and ConnectionMap to network.rs

This commit is contained in:
Joakim Frostegård 2021-10-18 01:27:16 +02:00
parent de85feec9a
commit e2be31c7de
2 changed files with 19 additions and 18 deletions

View file

@ -1,5 +1,5 @@
use std::hash::Hash; 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::sync::{atomic::AtomicUsize, Arc};
use std::time::Instant; use std::time::Instant;
@ -49,23 +49,6 @@ impl Into<Response> 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<ConnectionKey, ValidUntil>;
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)] #[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
pub enum PeerStatus { pub enum PeerStatus {
Seeding, Seeding,

View file

@ -8,6 +8,7 @@ use std::time::{Duration, Instant};
use std::vec::Drain; use std::vec::Drain;
use crossbeam_channel::{Receiver, Sender}; use crossbeam_channel::{Receiver, Sender};
use hashbrown::HashMap;
use mio::net::UdpSocket; use mio::net::UdpSocket;
use mio::{Events, Interest, Poll, Token}; use mio::{Events, Interest, Poll, Token};
use rand::prelude::{Rng, SeedableRng, StdRng}; use rand::prelude::{Rng, SeedableRng, StdRng};
@ -18,6 +19,23 @@ use aquatic_udp_protocol::{IpVersion, Request, Response};
use crate::common::*; use crate::common::*;
use crate::config::Config; 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<ConnectionKey, ValidUntil>;
pub fn run_socket_worker( pub fn run_socket_worker(
state: State, state: State,
config: Config, config: Config,