Move some code from aquatic_udp into aquatic_common

This commit is contained in:
Joakim Frostegård 2020-05-11 17:06:37 +02:00
parent 1b8d74e26d
commit 5c83af9f88
10 changed files with 111 additions and 82 deletions

View file

@ -1,31 +1,17 @@
use std::net::{SocketAddr, IpAddr};
use std::sync::{Arc, atomic::AtomicUsize};
use std::time::{Duration, Instant};
use hashbrown::HashMap;
use indexmap::IndexMap;
use parking_lot::Mutex;
pub use aquatic_common::ValidUntil;
pub use bittorrent_udp::types::*;
pub const MAX_PACKET_SIZE: usize = 4096;
/// Peer or connection valid until this instant
///
/// Used instead of "last seen" or similar to hopefully prevent arithmetic
/// overflow when cleaning.
#[derive(Debug, Clone, Copy)]
pub struct ValidUntil(pub Instant);
impl ValidUntil {
pub fn new(offset_seconds: u64) -> Self {
Self(Instant::now() + Duration::from_secs(offset_seconds))
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ConnectionKey {