From 94305ae77960aa82e466710b4f5a781200070c0d Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Thu, 5 Aug 2021 17:21:36 -0400 Subject: [PATCH] Path/node cleanup stuff, build fixes. --- network-hypervisor/src/util/pool.rs | 4 ++-- network-hypervisor/src/vl1/constants.rs | 3 +++ network-hypervisor/src/vl1/node.rs | 7 ++++++ network-hypervisor/src/vl1/path.rs | 12 +++++++--- service/Cargo.lock | 31 ++----------------------- service/Cargo.toml | 2 +- 6 files changed, 24 insertions(+), 35 deletions(-) diff --git a/network-hypervisor/src/util/pool.rs b/network-hypervisor/src/util/pool.rs index 151c90a86..5b858d7ef 100644 --- a/network-hypervisor/src/util/pool.rs +++ b/network-hypervisor/src/util/pool.rs @@ -157,12 +157,12 @@ unsafe impl> Send for Pool {} #[cfg(test)] mod tests { - use std::sync::atomic::{AtomicUsize, Ordering}; use std::ops::DerefMut; + use std::sync::Arc; + use std::sync::atomic::{AtomicUsize, Ordering}; use std::time::Duration; use crate::util::pool::*; - use std::sync::Arc; struct TestPoolFactory; diff --git a/network-hypervisor/src/vl1/constants.rs b/network-hypervisor/src/vl1/constants.rs index aa3c736af..4287f0bd9 100644 --- a/network-hypervisor/src/vl1/constants.rs +++ b/network-hypervisor/src/vl1/constants.rs @@ -108,3 +108,6 @@ pub const WHOIS_RETRY_MAX: u16 = 3; /// Maximum number of endpoints allowed in a Locator. pub const LOCATOR_MAX_ENDPOINTS: usize = 32; + +/// Keepalive interval for paths in milliseconds. +pub const PATH_KEEPALIVE_INTERVAL: i64 = 20000; diff --git a/network-hypervisor/src/vl1/node.rs b/network-hypervisor/src/vl1/node.rs index 94992a5de..64c8e0bac 100644 --- a/network-hypervisor/src/vl1/node.rs +++ b/network-hypervisor/src/vl1/node.rs @@ -116,6 +116,7 @@ pub trait VL1PacketHandler { #[derive(Default)] struct BackgroundTaskIntervals { whois: IntervalGate<{ WhoisQueue::INTERVAL }>, + paths: IntervalGate<{ Path::INTERVAL }>, } pub struct Node { @@ -212,6 +213,12 @@ impl Node { if intervals.whois.gate(tt) { self.whois.on_interval(self, ci, tt); } + if intervals.paths.gate(tt) { + self.paths.retain(|_, path| { + path.on_interval(ci, tt); + true + }); + } Duration::from_millis(1000) } diff --git a/network-hypervisor/src/vl1/path.rs b/network-hypervisor/src/vl1/path.rs index ed72d1ba4..9e11a4c11 100644 --- a/network-hypervisor/src/vl1/path.rs +++ b/network-hypervisor/src/vl1/path.rs @@ -10,6 +10,10 @@ use crate::vl1::fragmentedpacket::FragmentedPacket; use crate::vl1::node::{PacketBuffer, VL1CallerInterface}; use crate::vl1::protocol::PacketID; +/// A remote endpoint paired with a local socket and a local interface. +/// These are maintained in Node and canonicalized so that all unique paths have +/// one and only one unique path object. That enables statistics to be tracked +/// for them and uniform application of things like keepalives. pub struct Path { pub(crate) endpoint: Endpoint, pub(crate) local_socket: i64, @@ -20,6 +24,8 @@ pub struct Path { } impl Path { + pub(crate) const INTERVAL: i64 = PATH_KEEPALIVE_INTERVAL; + #[inline(always)] pub fn new(endpoint: Endpoint, local_socket: i64, local_interface: i64) -> Self { Self { @@ -42,7 +48,8 @@ impl Path { self.last_receive_time_ticks.load(Ordering::Relaxed) } - /// Receive a fragment and return a FragmentedPacket if the entire packet is assembled. + /// Receive a fragment and return a FragmentedPacket if the entire packet was assembled. + /// This returns None if more fragments are needed to assemble the packet. #[inline(always)] pub(crate) fn receive_fragment(&self, packet_id: PacketID, fragment_no: u8, fragment_expecting_count: u8, packet: PacketBuffer, time_ticks: i64) -> Option { self.last_receive_time_ticks.store(time_ticks, Ordering::Relaxed); @@ -85,8 +92,7 @@ impl Path { } #[inline(always)] - pub fn do_background_tasks(&self, ct: &CI) { - let time_ticks = ct.time_ticks(); + pub fn on_interval(&self, ct: &CI, time_ticks: i64) { self.fragmented_packets.lock().retain(|packet_id, frag| (time_ticks - frag.ts_ticks) < FRAGMENT_EXPIRATION); } } diff --git a/service/Cargo.lock b/service/Cargo.lock index 560aca4f6..7511f53a4 100644 --- a/service/Cargo.lock +++ b/service/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "ansi_term" version = "0.11.0" @@ -26,22 +28,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" -[[package]] -name = "base64" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" - -[[package]] -name = "base64-serde" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e964e3e0a930303c7c0bdb28ebf691dd98d9eee4b8b68019d2c995710b58a18" -dependencies = [ - "base64", - "serde", -] - [[package]] name = "bitflags" version = "1.2.1" @@ -928,18 +914,6 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "45af6a010d13e4cf5b54c94ba5a2b2eba5596b9e46bf5875612d332a1f2b3f86" -[[package]] -name = "zerotier-core" -version = "0.1.0" -dependencies = [ - "base64", - "base64-serde", - "hex", - "num-derive", - "num-traits", - "serde", -] - [[package]] name = "zerotier-service" version = "0.1.0" @@ -961,5 +935,4 @@ dependencies = [ "socket2", "tokio", "winapi", - "zerotier-core", ] diff --git a/service/Cargo.toml b/service/Cargo.toml index 114a34aa8..44c5167e3 100644 --- a/service/Cargo.toml +++ b/service/Cargo.toml @@ -12,7 +12,6 @@ codegen-units = 1 panic = 'abort' [dependencies] -zerotier-core = { path = "../rust-zerotier-core" } num_cpus = "*" tokio = { version = "1", features = ["rt", "net", "time", "signal", "macros"] } serde = { version = "1", features = ["derive"] } @@ -29,6 +28,7 @@ socket2 = { version = "0", features = ["reuseport", "unix", "pair"] } dialoguer = "0" digest_auth = "0.2.4" colored = "2" +#zerotier-core = { path = "../rust-zerotier-core" } [target."cfg(windows)".dependencies] winapi = { version = "0.3.9", features = ["handleapi", "ws2ipdef", "ws2tcpip"] }