This commit is contained in:
Adam Ierymenko 2022-10-23 10:50:34 -07:00
parent 7cb52b112a
commit 07eed995e7
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3
4 changed files with 22 additions and 37 deletions

View file

@ -263,7 +263,7 @@ impl<DatabaseImpl: Database> InnerProtocol for Handler<DatabaseImpl> {
PacketHandlerResult::NotHandled
}
fn should_communicate_with(&self, _: &Identity) -> bool {
fn should_respond_to(&self, _: &Identity) -> bool {
true
}
}

View file

@ -93,15 +93,23 @@ pub trait NodeStorage: Sync + Send {
/// Trait to be implemented to provide path hints and a filter to approve physical paths.
pub trait PathFilter: Sync + Send {
/// Called to check and see if a physical address should be used for ZeroTier traffic to a node.
///
/// The default implementation always returns true.
#[allow(unused_variables)]
fn should_use_physical_path<HostSystemImpl: HostSystem + ?Sized>(
&self,
id: &Identity,
endpoint: &Endpoint,
local_socket: Option<&HostSystemImpl::LocalSocket>,
local_interface: Option<&HostSystemImpl::LocalInterface>,
) -> bool;
) -> bool {
true
}
/// Called to look up any statically defined or memorized paths to known nodes.
///
/// The default implementation always returns None.
#[allow(unused_variables)]
fn get_path_hints<HostSystemImpl: HostSystem + ?Sized>(
&self,
id: &Identity,
@ -111,7 +119,9 @@ pub trait PathFilter: Sync + Send {
Option<HostSystemImpl::LocalSocket>,
Option<HostSystemImpl::LocalInterface>,
)>,
>;
> {
None
}
}
/// Result of a packet handler.
@ -177,8 +187,8 @@ pub trait InnerProtocol: Sync + Send {
cursor: &mut usize,
) -> PacketHandlerResult;
/// Check if this peer should communicate with another at all.
fn should_communicate_with(&self, id: &Identity) -> bool;
/// Check if this node should respond to messages from a given peer.
fn should_respond_to(&self, id: &Identity) -> bool;
}
/// How often to check the root cluster definitions against the root list and update.
@ -945,7 +955,7 @@ impl Node {
let mut whois_queue = self.whois_queue.lock().unwrap();
if let Some(qi) = whois_queue.get_mut(&received_identity.address) {
let address = received_identity.address;
if inner.should_communicate_with(&received_identity) {
if inner.should_respond_to(&received_identity) {
let mut peers = self.peers.write().unwrap();
if let Some(peer) = peers.get(&address).cloned().or_else(|| {
Peer::new(&self.identity, received_identity, time_ticks)
@ -1122,7 +1132,7 @@ impl InnerProtocol for DummyInnerProtocol {
}
#[inline(always)]
fn should_communicate_with(&self, _id: &Identity) -> bool {
fn should_respond_to(&self, _id: &Identity) -> bool {
true
}
}
@ -1131,29 +1141,4 @@ impl InnerProtocol for DummyInnerProtocol {
#[derive(Default)]
pub struct DummyPathFilter;
impl PathFilter for DummyPathFilter {
#[inline(always)]
fn should_use_physical_path<HostSystemImpl: HostSystem + ?Sized>(
&self,
_id: &Identity,
_endpoint: &Endpoint,
_local_socket: Option<&<HostSystemImpl as HostSystem>::LocalSocket>,
_local_interface: Option<&<HostSystemImpl as HostSystem>::LocalInterface>,
) -> bool {
true
}
#[inline(always)]
fn get_path_hints<HostSystemImpl: HostSystem + ?Sized>(
&self,
_id: &Identity,
) -> Option<
Vec<(
Endpoint,
Option<<HostSystemImpl as HostSystem>::LocalSocket>,
Option<<HostSystemImpl as HostSystem>::LocalInterface>,
)>,
> {
None
}
}
impl PathFilter for DummyPathFilter {}

View file

@ -603,7 +603,7 @@ impl Peer {
source_path: &Arc<Path>,
payload: &PacketBuffer,
) -> PacketHandlerResult {
if !(inner.should_communicate_with(&self.identity) || node.this_node_is_root() || node.is_peer_root(self)) {
if !(inner.should_respond_to(&self.identity) || node.this_node_is_root() || node.is_peer_root(self)) {
debug_event!(
host_system,
"[vl1] dropping HELLO from {} due to lack of trust relationship",
@ -800,7 +800,7 @@ impl Peer {
message_id: MessageId,
payload: &PacketBuffer,
) -> PacketHandlerResult {
if node.this_node_is_root() || inner.should_communicate_with(&self.identity) {
if node.this_node_is_root() || inner.should_respond_to(&self.identity) {
let mut addresses = payload.as_bytes();
while addresses.len() >= ADDRESS_SIZE {
if !self
@ -846,7 +846,7 @@ impl Peer {
message_id: MessageId,
payload: &PacketBuffer,
) -> PacketHandlerResult {
if inner.should_communicate_with(&self.identity) || node.is_peer_root(self) {
if inner.should_respond_to(&self.identity) || node.is_peer_root(self) {
self.send(host_system, node, None, time_ticks, |packet| {
let mut f: &mut OkHeader = packet.append_struct_get_mut().unwrap();
f.verb = verbs::VL1_OK;

View file

@ -58,7 +58,7 @@ impl InnerProtocol for Switch {
PacketHandlerResult::NotHandled
}
fn should_communicate_with(&self, id: &Identity) -> bool {
fn should_respond_to(&self, id: &Identity) -> bool {
true
}
}