mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-07 21:13:44 +02:00
cleanup
This commit is contained in:
parent
9c82aa2b29
commit
f3433a9840
1 changed files with 18 additions and 57 deletions
|
@ -205,9 +205,6 @@ pub trait InnerProtocolLayer: Sync + Send {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// How often to check the root cluster definitions against the root list and update.
|
|
||||||
const ROOT_SYNC_INTERVAL_MS: i64 = 1000;
|
|
||||||
|
|
||||||
struct RootInfo {
|
struct RootInfo {
|
||||||
/// Root sets to which we are a member.
|
/// Root sets to which we are a member.
|
||||||
sets: HashMap<String, Verified<RootSet>>,
|
sets: HashMap<String, Verified<RootSet>>,
|
||||||
|
@ -226,7 +223,9 @@ struct RootInfo {
|
||||||
online: bool,
|
online: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Interval gate objects used ot fire off background tasks, see do_background_tasks().
|
/// How often to check the root cluster definitions against the root list and update.
|
||||||
|
const ROOT_SYNC_INTERVAL_MS: i64 = 1000;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct BackgroundTaskIntervals {
|
struct BackgroundTaskIntervals {
|
||||||
root_sync: IntervalGate<{ ROOT_SYNC_INTERVAL_MS }>,
|
root_sync: IntervalGate<{ ROOT_SYNC_INTERVAL_MS }>,
|
||||||
|
@ -237,7 +236,6 @@ struct BackgroundTaskIntervals {
|
||||||
whois_queue_retry: IntervalGate<{ WHOIS_RETRY_INTERVAL }>,
|
whois_queue_retry: IntervalGate<{ WHOIS_RETRY_INTERVAL }>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// WHOIS requests and any packets that are waiting on them to be decrypted and authenticated.
|
|
||||||
struct WhoisQueueItem {
|
struct WhoisQueueItem {
|
||||||
v1_proto_waiting_packets: RingBuffer<(Weak<Path>, PooledPacketBuffer), WHOIS_MAX_WAITING_PACKETS>,
|
v1_proto_waiting_packets: RingBuffer<(Weak<Path>, PooledPacketBuffer), WHOIS_MAX_WAITING_PACKETS>,
|
||||||
last_retry_time: i64,
|
last_retry_time: i64,
|
||||||
|
@ -250,9 +248,6 @@ type PathMap<LocalSocket> = HashMap<PathKey<'static, 'static, LocalSocket>, Arc<
|
||||||
/// A ZeroTier VL1 node that can communicate securely with the ZeroTier peer-to-peer network.
|
/// A ZeroTier VL1 node that can communicate securely with the ZeroTier peer-to-peer network.
|
||||||
pub struct Node {
|
pub struct Node {
|
||||||
/// A random ID generated to identify this particular running instance.
|
/// A random ID generated to identify this particular running instance.
|
||||||
///
|
|
||||||
/// This can be used to implement multi-homing by allowing remote nodes to distinguish instances
|
|
||||||
/// that share an identity.
|
|
||||||
pub instance_id: [u8; 16],
|
pub instance_id: [u8; 16],
|
||||||
|
|
||||||
/// This node's identity and permanent keys.
|
/// This node's identity and permanent keys.
|
||||||
|
@ -327,30 +322,36 @@ impl Node {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn peer(&self, a: Address) -> Option<Arc<Peer>> {
|
pub fn peer(&self, a: Address) -> Option<Arc<Peer>> {
|
||||||
self.peers.read().unwrap().get(&a).cloned()
|
self.peers.read().unwrap().get(&a).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn is_online(&self) -> bool {
|
pub fn is_online(&self) -> bool {
|
||||||
self.roots.read().unwrap().online
|
self.roots.read().unwrap().online
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the current "best" root from among this node's trusted roots.
|
/// Get the current "best" root from among this node's trusted roots.
|
||||||
|
#[inline]
|
||||||
pub fn best_root(&self) -> Option<Arc<Peer>> {
|
pub fn best_root(&self) -> Option<Arc<Peer>> {
|
||||||
self.best_root.read().unwrap().clone()
|
self.best_root.read().unwrap().clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check whether a peer is a root according to any root set trusted by this node.
|
/// Check whether a peer is a root according to any root set trusted by this node.
|
||||||
|
#[inline]
|
||||||
pub fn is_peer_root(&self, peer: &Peer) -> bool {
|
pub fn is_peer_root(&self, peer: &Peer) -> bool {
|
||||||
self.roots.read().unwrap().roots.keys().any(|p| p.identity.eq(&peer.identity))
|
self.roots.read().unwrap().roots.keys().any(|p| p.identity.eq(&peer.identity))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this node is a member of a root set (that it knows about).
|
/// Returns true if this node is a member of a root set (that it knows about).
|
||||||
|
#[inline]
|
||||||
pub fn this_node_is_root(&self) -> bool {
|
pub fn this_node_is_root(&self) -> bool {
|
||||||
self.roots.read().unwrap().this_root_sets.is_some()
|
self.roots.read().unwrap().this_root_sets.is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a new root set or update the existing root set if the new root set is newer and otherwise matches.
|
/// Add a new root set or update the existing root set if the new root set is newer and otherwise matches.
|
||||||
|
#[inline]
|
||||||
pub fn add_update_root_set(&self, rs: Verified<RootSet>) -> bool {
|
pub fn add_update_root_set(&self, rs: Verified<RootSet>) -> bool {
|
||||||
let mut roots = self.roots.write().unwrap();
|
let mut roots = self.roots.write().unwrap();
|
||||||
if let Some(entry) = roots.sets.get_mut(&rs.name) {
|
if let Some(entry) = roots.sets.get_mut(&rs.name) {
|
||||||
|
@ -369,11 +370,13 @@ impl Node {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether or not this node has any root sets defined.
|
/// Returns whether or not this node has any root sets defined.
|
||||||
|
#[inline]
|
||||||
pub fn has_roots_defined(&self) -> bool {
|
pub fn has_roots_defined(&self) -> bool {
|
||||||
self.roots.read().unwrap().sets.iter().any(|rs| !rs.1.members.is_empty())
|
self.roots.read().unwrap().sets.iter().any(|rs| !rs.1.members.is_empty())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Initialize with default roots if there are no roots defined, otherwise do nothing.
|
/// Initialize with default roots if there are no roots defined, otherwise do nothing.
|
||||||
|
#[inline]
|
||||||
pub fn init_default_roots(&self) -> bool {
|
pub fn init_default_roots(&self) -> bool {
|
||||||
if !self.has_roots_defined() {
|
if !self.has_roots_defined() {
|
||||||
self.add_update_root_set(RootSet::zerotier_default())
|
self.add_update_root_set(RootSet::zerotier_default())
|
||||||
|
@ -383,6 +386,7 @@ impl Node {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the root sets that this node trusts.
|
/// Get the root sets that this node trusts.
|
||||||
|
#[inline]
|
||||||
pub fn root_sets(&self) -> Vec<RootSet> {
|
pub fn root_sets(&self) -> Vec<RootSet> {
|
||||||
self.roots.read().unwrap().sets.values().cloned().map(|s| s.unwrap()).collect()
|
self.roots.read().unwrap().sets.values().cloned().map(|s| s.unwrap()).collect()
|
||||||
}
|
}
|
||||||
|
@ -392,60 +396,18 @@ impl Node {
|
||||||
const INTERVAL: Duration = Duration::from_millis(INTERVAL_MS as u64);
|
const INTERVAL: Duration = Duration::from_millis(INTERVAL_MS as u64);
|
||||||
let time_ticks = app.time_ticks();
|
let time_ticks = app.time_ticks();
|
||||||
|
|
||||||
let (root_sync, root_hello, mut root_spam_hello, peer_service, path_service, whois_queue_retry) = {
|
let (root_sync, root_hello, root_spam_hello, peer_service, path_service, whois_queue_retry) = {
|
||||||
let mut intervals = self.intervals.lock().unwrap();
|
let mut intervals = self.intervals.lock().unwrap();
|
||||||
(
|
(
|
||||||
intervals.root_sync.gate(time_ticks),
|
intervals.root_sync.gate(time_ticks),
|
||||||
intervals.root_hello.gate(time_ticks),
|
intervals.root_hello.gate(time_ticks),
|
||||||
intervals.root_spam_hello.gate(time_ticks),
|
intervals.root_spam_hello.gate(time_ticks) && !self.is_online(),
|
||||||
intervals.peer_service.gate(time_ticks),
|
intervals.peer_service.gate(time_ticks),
|
||||||
intervals.path_service.gate(time_ticks),
|
intervals.path_service.gate(time_ticks),
|
||||||
intervals.whois_queue_retry.gate(time_ticks),
|
intervals.whois_queue_retry.gate(time_ticks),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
// We only "spam" (try to contact roots more often) if we are offline.
|
|
||||||
if root_spam_hello {
|
|
||||||
root_spam_hello = !self.is_online();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
debug_event!(
|
|
||||||
host_system,
|
|
||||||
"[vl1] do_background_tasks:{}{}{}{}{}{} ----",
|
|
||||||
if root_sync {
|
|
||||||
" root_sync"
|
|
||||||
} else {
|
|
||||||
""
|
|
||||||
},
|
|
||||||
if root_hello {
|
|
||||||
" root_hello"
|
|
||||||
} else {
|
|
||||||
""
|
|
||||||
},
|
|
||||||
if root_spam_hello {
|
|
||||||
" root_spam_hello"
|
|
||||||
} else {
|
|
||||||
""
|
|
||||||
},
|
|
||||||
if peer_service {
|
|
||||||
" peer_service"
|
|
||||||
} else {
|
|
||||||
""
|
|
||||||
},
|
|
||||||
if path_service {
|
|
||||||
" path_service"
|
|
||||||
} else {
|
|
||||||
""
|
|
||||||
},
|
|
||||||
if whois_queue_retry {
|
|
||||||
" whois_queue_retry"
|
|
||||||
} else {
|
|
||||||
""
|
|
||||||
}
|
|
||||||
);
|
|
||||||
*/
|
|
||||||
|
|
||||||
if root_sync {
|
if root_sync {
|
||||||
if {
|
if {
|
||||||
let mut roots = self.roots.write().unwrap();
|
let mut roots = self.roots.write().unwrap();
|
||||||
|
@ -719,7 +681,6 @@ impl Node {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//debug_event!(host_system, "[vl1] do_background_tasks DONE ----");
|
|
||||||
INTERVAL
|
INTERVAL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1058,7 +1019,7 @@ enum PathKey<'a, 'b, LocalSocket: Hash + PartialEq + Eq + Clone> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<LocalSocket: Hash + PartialEq + Eq + Clone> Hash for PathKey<'_, '_, LocalSocket> {
|
impl<LocalSocket: Hash + PartialEq + Eq + Clone> Hash for PathKey<'_, '_, LocalSocket> {
|
||||||
#[inline]
|
#[inline(always)]
|
||||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||||
match self {
|
match self {
|
||||||
Self::Copied(ep, ls) => {
|
Self::Copied(ep, ls) => {
|
||||||
|
@ -1074,7 +1035,7 @@ impl<LocalSocket: Hash + PartialEq + Eq + Clone> Hash for PathKey<'_, '_, LocalS
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<LocalSocket: Hash + PartialEq + Eq + Clone> PartialEq for PathKey<'_, '_, LocalSocket> {
|
impl<LocalSocket: Hash + PartialEq + Eq + Clone> PartialEq for PathKey<'_, '_, LocalSocket> {
|
||||||
#[inline]
|
#[inline(always)]
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
match (self, other) {
|
match (self, other) {
|
||||||
(Self::Copied(ep1, ls1), Self::Copied(ep2, ls2)) => ep1.eq(ep2) && ls1.eq(ls2),
|
(Self::Copied(ep1, ls1), Self::Copied(ep2, ls2)) => ep1.eq(ep2) && ls1.eq(ls2),
|
||||||
|
@ -1088,7 +1049,7 @@ impl<LocalSocket: Hash + PartialEq + Eq + Clone> PartialEq for PathKey<'_, '_, L
|
||||||
impl<LocalSocket: Hash + PartialEq + Eq + Clone> Eq for PathKey<'_, '_, LocalSocket> {}
|
impl<LocalSocket: Hash + PartialEq + Eq + Clone> Eq for PathKey<'_, '_, LocalSocket> {}
|
||||||
|
|
||||||
impl<LocalSocket: Hash + PartialEq + Eq + Clone> PathKey<'_, '_, LocalSocket> {
|
impl<LocalSocket: Hash + PartialEq + Eq + Clone> PathKey<'_, '_, LocalSocket> {
|
||||||
#[inline]
|
#[inline(always)]
|
||||||
fn local_socket(&self) -> &LocalSocket {
|
fn local_socket(&self) -> &LocalSocket {
|
||||||
match self {
|
match self {
|
||||||
Self::Copied(_, ls) => ls,
|
Self::Copied(_, ls) => ls,
|
||||||
|
@ -1096,7 +1057,7 @@ impl<LocalSocket: Hash + PartialEq + Eq + Clone> PathKey<'_, '_, LocalSocket> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline(always)]
|
||||||
fn to_copied(&self) -> PathKey<'static, 'static, LocalSocket> {
|
fn to_copied(&self) -> PathKey<'static, 'static, LocalSocket> {
|
||||||
match self {
|
match self {
|
||||||
Self::Copied(ep, ls) => PathKey::<'static, 'static, LocalSocket>::Copied(ep.clone(), ls.clone()),
|
Self::Copied(ep, ls) => PathKey::<'static, 'static, LocalSocket>::Copied(ep.clone(), ls.clone()),
|
||||||
|
|
Loading…
Add table
Reference in a new issue