Path/node cleanup stuff, build fixes.

This commit is contained in:
Adam Ierymenko 2021-08-05 17:21:36 -04:00
parent 4ca8b30044
commit 94305ae779
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3
6 changed files with 24 additions and 35 deletions

View file

@ -157,12 +157,12 @@ unsafe impl<O, F: PoolFactory<O>> Send for Pool<O, F> {}
#[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;

View file

@ -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;

View file

@ -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)
}

View file

@ -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<FragmentedPacket> {
self.last_receive_time_ticks.store(time_ticks, Ordering::Relaxed);
@ -85,8 +92,7 @@ impl Path {
}
#[inline(always)]
pub fn do_background_tasks<CI: VL1CallerInterface>(&self, ct: &CI) {
let time_ticks = ct.time_ticks();
pub fn on_interval<CI: VL1CallerInterface>(&self, ct: &CI, time_ticks: i64) {
self.fragmented_packets.lock().retain(|packet_id, frag| (time_ticks - frag.ts_ticks) < FRAGMENT_EXPIRATION);
}
}

31
service/Cargo.lock generated
View file

@ -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",
]

View file

@ -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"] }