mirror of
https://gitlab.com/veilid/veilid.git
synced 2024-10-01 01:26:08 -04:00
peer scope refactor
This commit is contained in:
parent
27bca1a538
commit
cf2acc4bd5
11
Cargo.lock
generated
11
Cargo.lock
generated
@ -1662,21 +1662,12 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "if-addrs"
|
name = "if-addrs"
|
||||||
version = "0.6.7"
|
version = "0.7.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"if-addrs-sys",
|
|
||||||
"libc",
|
"libc",
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "if-addrs-sys"
|
|
||||||
version = "0.3.2"
|
|
||||||
dependencies = [
|
|
||||||
"cc",
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "impl-codec"
|
name = "impl-codec"
|
||||||
version = "0.5.1"
|
version = "0.5.1"
|
||||||
|
2
external/if-addrs
vendored
2
external/if-addrs
vendored
@ -1 +1 @@
|
|||||||
Subproject commit e985399095255f2d0ea3388a33f19e037255283a
|
Subproject commit 35f8eb3988c2786a4d982936b1b79a1ac9ba7383
|
@ -156,6 +156,7 @@ pub struct RPCProcessorInner {
|
|||||||
pub struct RPCProcessor {
|
pub struct RPCProcessor {
|
||||||
crypto: Crypto,
|
crypto: Crypto,
|
||||||
config: VeilidConfig,
|
config: VeilidConfig,
|
||||||
|
default_peer_scope: PeerScope,
|
||||||
inner: Arc<Mutex<RPCProcessorInner>>,
|
inner: Arc<Mutex<RPCProcessorInner>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,6 +178,16 @@ impl RPCProcessor {
|
|||||||
Self {
|
Self {
|
||||||
crypto: network_manager.crypto(),
|
crypto: network_manager.crypto(),
|
||||||
config: network_manager.config(),
|
config: network_manager.config(),
|
||||||
|
default_peer_scope: if !network_manager
|
||||||
|
.config()
|
||||||
|
.get()
|
||||||
|
.network
|
||||||
|
.enable_local_peer_scope
|
||||||
|
{
|
||||||
|
PeerScope::Global
|
||||||
|
} else {
|
||||||
|
PeerScope::All
|
||||||
|
},
|
||||||
inner: Arc::new(Mutex::new(Self::new_inner(network_manager))),
|
inner: Arc::new(Mutex::new(Self::new_inner(network_manager))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -203,6 +214,19 @@ impl RPCProcessor {
|
|||||||
get_random_u64()
|
get_random_u64()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn filter_peer_scope(&self, peer_info: &PeerInfo) -> bool {
|
||||||
|
// reject attempts to include non-public addresses in results
|
||||||
|
if self.default_peer_scope == PeerScope::Global {
|
||||||
|
for di in &peer_info.dial_infos {
|
||||||
|
if !di.is_global() {
|
||||||
|
// non-public address causes rejection
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// Search the DHT for a single node closest to a key unless we have that node in our routing table already, and return the node reference
|
// Search the DHT for a single node closest to a key unless we have that node in our routing table already, and return the node reference
|
||||||
@ -966,14 +990,8 @@ impl RPCProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// filter out attempts to pass non-public addresses in for peers
|
// filter out attempts to pass non-public addresses in for peers
|
||||||
let enable_local_peer_scope = self.config.get().network.enable_local_peer_scope;
|
if !self.filter_peer_scope(&peer_info) {
|
||||||
if !enable_local_peer_scope {
|
return Err(RPCError::InvalidFormat);
|
||||||
for di in &peer_info.dial_infos {
|
|
||||||
if !di.is_global() {
|
|
||||||
// non-public address causes rejection
|
|
||||||
return Err(RPCError::InvalidFormat);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add node information for the requesting node to our routing table
|
// add node information for the requesting node to our routing table
|
||||||
@ -983,18 +1001,15 @@ impl RPCProcessor {
|
|||||||
.map_err(map_error_string!())?;
|
.map_err(map_error_string!())?;
|
||||||
|
|
||||||
// find N nodes closest to the target node in our routing table
|
// find N nodes closest to the target node in our routing table
|
||||||
let peer_scope = if !enable_local_peer_scope {
|
let own_peer_info = routing_table.get_own_peer_info(self.default_peer_scope);
|
||||||
PeerScope::Global
|
|
||||||
} else {
|
|
||||||
PeerScope::All
|
|
||||||
};
|
|
||||||
let own_peer_info = routing_table.get_own_peer_info(peer_scope);
|
|
||||||
let closest_nodes = routing_table.find_closest_nodes(
|
let closest_nodes = routing_table.find_closest_nodes(
|
||||||
target_node_id,
|
target_node_id,
|
||||||
// filter
|
// filter
|
||||||
None,
|
None,
|
||||||
// transform
|
// transform
|
||||||
|e| RoutingTable::transform_to_peer_info(e, peer_scope, &own_peer_info),
|
|e| {
|
||||||
|
RoutingTable::transform_to_peer_info(e, self.default_peer_scope, &own_peer_info)
|
||||||
|
},
|
||||||
);
|
);
|
||||||
log_rpc!(">>>> Returning {} closest peers", closest_nodes.len());
|
log_rpc!(">>>> Returning {} closest peers", closest_nodes.len());
|
||||||
|
|
||||||
@ -1454,7 +1469,6 @@ impl RPCProcessor {
|
|||||||
safety_route: Option<&SafetyRouteSpec>,
|
safety_route: Option<&SafetyRouteSpec>,
|
||||||
respond_to: RespondTo,
|
respond_to: RespondTo,
|
||||||
) -> Result<FindNodeAnswer, RPCError> {
|
) -> Result<FindNodeAnswer, RPCError> {
|
||||||
let enable_local_peer_scope = self.config.get().network.enable_local_peer_scope;
|
|
||||||
let find_node_q_msg = {
|
let find_node_q_msg = {
|
||||||
let mut find_node_q_msg = ::capnp::message::Builder::new_default();
|
let mut find_node_q_msg = ::capnp::message::Builder::new_default();
|
||||||
let mut question = find_node_q_msg.init_root::<veilid_capnp::operation::Builder>();
|
let mut question = find_node_q_msg.init_root::<veilid_capnp::operation::Builder>();
|
||||||
@ -1467,13 +1481,9 @@ impl RPCProcessor {
|
|||||||
encode_public_key(&key, &mut node_id_builder)?;
|
encode_public_key(&key, &mut node_id_builder)?;
|
||||||
let mut peer_info_builder = fnq.reborrow().init_peer_info();
|
let mut peer_info_builder = fnq.reborrow().init_peer_info();
|
||||||
|
|
||||||
let own_peer_info =
|
let own_peer_info = self
|
||||||
self.routing_table()
|
.routing_table()
|
||||||
.get_own_peer_info(if !enable_local_peer_scope {
|
.get_own_peer_info(self.default_peer_scope);
|
||||||
PeerScope::Global
|
|
||||||
} else {
|
|
||||||
PeerScope::All
|
|
||||||
});
|
|
||||||
if own_peer_info.dial_infos.is_empty() {
|
if own_peer_info.dial_infos.is_empty() {
|
||||||
return Err(rpc_error_internal("No valid public dial info for own node"));
|
return Err(rpc_error_internal("No valid public dial info for own node"));
|
||||||
}
|
}
|
||||||
@ -1521,14 +1531,8 @@ impl RPCProcessor {
|
|||||||
for p in peers_reader.iter() {
|
for p in peers_reader.iter() {
|
||||||
let peer_info = decode_peer_info(&p)?;
|
let peer_info = decode_peer_info(&p)?;
|
||||||
|
|
||||||
// reject attempts to include non-public addresses in results
|
if !self.filter_peer_scope(&peer_info) {
|
||||||
if !enable_local_peer_scope {
|
return Err(RPCError::InvalidFormat);
|
||||||
for di in &peer_info.dial_infos {
|
|
||||||
if !di.is_global() {
|
|
||||||
// non-public address causes rejection
|
|
||||||
return Err(RPCError::InvalidFormat);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
peers.push(peer_info);
|
peers.push(peer_info);
|
||||||
|
Loading…
Reference in New Issue
Block a user