mirror of
https://gitlab.com/veilid/veilid.git
synced 2024-12-25 07:19:26 -05:00
private route respondto fix
This commit is contained in:
parent
c33b00fe32
commit
277aed5d40
@ -1462,14 +1462,14 @@ impl RouteSpecStore {
|
|||||||
Ok(out)
|
Ok(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Import a remote private route for compilation
|
/// Import a remote private route set blob for compilation
|
||||||
/// It is safe to import the same route more than once and it will return the same route id
|
/// It is safe to import the same route more than once and it will return the same route id
|
||||||
/// Returns a route set id
|
/// Returns a route set id
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "verbose-tracing",
|
feature = "verbose-tracing",
|
||||||
instrument(level = "trace", skip(self, blob), ret, err)
|
instrument(level = "trace", skip(self, blob), ret, err)
|
||||||
)]
|
)]
|
||||||
pub fn import_remote_private_route(&self, blob: Vec<u8>) -> VeilidAPIResult<RouteId> {
|
pub fn import_remote_private_route_blob(&self, blob: Vec<u8>) -> VeilidAPIResult<RouteId> {
|
||||||
let cur_ts = get_aligned_timestamp();
|
let cur_ts = get_aligned_timestamp();
|
||||||
|
|
||||||
// decode the pr blob
|
// decode the pr blob
|
||||||
@ -1502,6 +1502,46 @@ impl RouteSpecStore {
|
|||||||
Ok(id)
|
Ok(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Add a single remote private route for compilation
|
||||||
|
/// It is safe to add the same route more than once and it will return the same route id
|
||||||
|
/// Returns a route set id
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "verbose-tracing",
|
||||||
|
instrument(level = "trace", skip(self, blob), ret, err)
|
||||||
|
)]
|
||||||
|
pub fn add_remote_private_route(
|
||||||
|
&self,
|
||||||
|
private_route: PrivateRoute,
|
||||||
|
) -> VeilidAPIResult<RouteId> {
|
||||||
|
let cur_ts = get_aligned_timestamp();
|
||||||
|
|
||||||
|
// Make a single route set
|
||||||
|
let private_routes = vec![private_route];
|
||||||
|
|
||||||
|
// make the route id
|
||||||
|
let id = self.generate_remote_route_id(&private_routes)?;
|
||||||
|
|
||||||
|
// validate the private routes
|
||||||
|
let inner = &mut *self.inner.lock();
|
||||||
|
for private_route in &private_routes {
|
||||||
|
// ensure private route has first hop
|
||||||
|
if !matches!(private_route.hops, PrivateRouteHops::FirstHop(_)) {
|
||||||
|
apibail_generic!("private route must have first hop");
|
||||||
|
}
|
||||||
|
|
||||||
|
// ensure this isn't also an allocated route
|
||||||
|
// if inner.content.get_id_by_key(&private_route.public_key.value).is_some() {
|
||||||
|
// bail!("should not import allocated route");
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
inner
|
||||||
|
.cache
|
||||||
|
.cache_remote_private_route(cur_ts, id, private_routes);
|
||||||
|
|
||||||
|
Ok(id)
|
||||||
|
}
|
||||||
|
|
||||||
/// Release a remote private route that is no longer in use
|
/// Release a remote private route that is no longer in use
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "verbose-tracing",
|
feature = "verbose-tracing",
|
||||||
|
@ -114,7 +114,7 @@ impl Destination {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_target(&self) -> Target {
|
pub fn get_target(&self, rss: RouteSpecStore) -> Result<Target, RPCError> {
|
||||||
match self {
|
match self {
|
||||||
Destination::Direct {
|
Destination::Direct {
|
||||||
node,
|
node,
|
||||||
@ -124,11 +124,36 @@ impl Destination {
|
|||||||
relay: _,
|
relay: _,
|
||||||
node,
|
node,
|
||||||
safety_selection: _,
|
safety_selection: _,
|
||||||
} => Target::NodeId(node.best_node_id()),
|
} => Ok(Target::NodeId(node.best_node_id())),
|
||||||
Destination::PrivateRoute {
|
Destination::PrivateRoute {
|
||||||
private_route,
|
private_route,
|
||||||
safety_selection: _,
|
safety_selection: _,
|
||||||
} => Target::PrivateRoute(private_route.public_key.value),
|
} => {
|
||||||
|
// Add the remote private route if we're going to keep the id
|
||||||
|
let route_id = rss
|
||||||
|
.add_remote_private_route(private_route.clone())
|
||||||
|
.map_err(RPCError::protocol)?;
|
||||||
|
|
||||||
|
Ok(Target::PrivateRoute(route_id))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_private_route(&self) -> Option<PrivateRoute> {
|
||||||
|
match self {
|
||||||
|
Destination::Direct {
|
||||||
|
node: _,
|
||||||
|
safety_selection: _,
|
||||||
|
}
|
||||||
|
| Destination::Relay {
|
||||||
|
relay: _,
|
||||||
|
node: _,
|
||||||
|
safety_selection: _,
|
||||||
|
} => None,
|
||||||
|
Destination::PrivateRoute {
|
||||||
|
private_route,
|
||||||
|
safety_selection: _,
|
||||||
|
} => Some(private_route.clone()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -188,6 +188,8 @@ impl RPCProcessor {
|
|||||||
) ->RPCNetworkResult<()> {
|
) ->RPCNetworkResult<()> {
|
||||||
// Ignore if disabled
|
// Ignore if disabled
|
||||||
let routing_table = self.routing_table();
|
let routing_table = self.routing_table();
|
||||||
|
let rss = routing_table.route_spec_store();
|
||||||
|
|
||||||
let opi = routing_table.get_own_peer_info(msg.header.routing_domain());
|
let opi = routing_table.get_own_peer_info(msg.header.routing_domain());
|
||||||
if !opi
|
if !opi
|
||||||
.signed_node_info()
|
.signed_node_info()
|
||||||
@ -224,7 +226,7 @@ impl RPCProcessor {
|
|||||||
|
|
||||||
// Get target for ValueChanged notifications
|
// Get target for ValueChanged notifications
|
||||||
let dest = network_result_try!(self.get_respond_to_destination(&msg));
|
let dest = network_result_try!(self.get_respond_to_destination(&msg));
|
||||||
let target = dest.get_target();
|
let target = dest.get_target(rss)?;
|
||||||
|
|
||||||
// Get the nodes that we know about that are closer to the the key than our own node
|
// Get the nodes that we know about that are closer to the the key than our own node
|
||||||
let routing_table = self.routing_table();
|
let routing_table = self.routing_table();
|
||||||
|
@ -145,6 +145,9 @@ impl RPCProcessor {
|
|||||||
|
|
||||||
#[cfg_attr(feature="verbose-tracing", instrument(level = "trace", skip(self, msg), fields(msg.operation.op_id), ret, err))]
|
#[cfg_attr(feature="verbose-tracing", instrument(level = "trace", skip(self, msg), fields(msg.operation.op_id), ret, err))]
|
||||||
pub(crate) async fn process_watch_value_q(&self, msg: RPCMessage) -> RPCNetworkResult<()> {
|
pub(crate) async fn process_watch_value_q(&self, msg: RPCMessage) -> RPCNetworkResult<()> {
|
||||||
|
let routing_table = self.routing_table();
|
||||||
|
let rss = routing_table.route_spec_store();
|
||||||
|
|
||||||
// Ensure this never came over a private route, safety route is okay though
|
// Ensure this never came over a private route, safety route is okay though
|
||||||
match &msg.header.detail {
|
match &msg.header.detail {
|
||||||
RPCMessageHeaderDetail::Direct(_) | RPCMessageHeaderDetail::SafetyRouted(_) => {}
|
RPCMessageHeaderDetail::Direct(_) | RPCMessageHeaderDetail::SafetyRouted(_) => {}
|
||||||
@ -177,7 +180,7 @@ impl RPCProcessor {
|
|||||||
|
|
||||||
// Get target for ValueChanged notifications
|
// Get target for ValueChanged notifications
|
||||||
let dest = network_result_try!(self.get_respond_to_destination(&msg));
|
let dest = network_result_try!(self.get_respond_to_destination(&msg));
|
||||||
let target = dest.get_target();
|
let target = dest.get_target(rss)?;
|
||||||
|
|
||||||
#[cfg(feature = "debug-dht")]
|
#[cfg(feature = "debug-dht")]
|
||||||
{
|
{
|
||||||
@ -195,7 +198,6 @@ impl RPCProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the nodes that we know about that are closer to the the key than our own node
|
// Get the nodes that we know about that are closer to the the key than our own node
|
||||||
let routing_table = self.routing_table();
|
|
||||||
let closer_to_key_peers = network_result_try!(
|
let closer_to_key_peers = network_result_try!(
|
||||||
routing_table.find_preferred_peers_closer_to_key(key, vec![CAP_DHT])
|
routing_table.find_preferred_peers_closer_to_key(key, vec![CAP_DHT])
|
||||||
);
|
);
|
||||||
|
@ -295,7 +295,7 @@ impl VeilidAPI {
|
|||||||
/// Returns a route id that can be used to send private messages to the node creating this route.
|
/// Returns a route id that can be used to send private messages to the node creating this route.
|
||||||
pub fn import_remote_private_route(&self, blob: Vec<u8>) -> VeilidAPIResult<RouteId> {
|
pub fn import_remote_private_route(&self, blob: Vec<u8>) -> VeilidAPIResult<RouteId> {
|
||||||
let rss = self.routing_table()?.route_spec_store();
|
let rss = self.routing_table()?.route_spec_store();
|
||||||
rss.import_remote_private_route(blob)
|
rss.import_remote_private_route_blob(blob)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Release either a locally allocated or remotely imported private route
|
/// Release either a locally allocated or remotely imported private route
|
||||||
|
@ -1307,7 +1307,7 @@ impl VeilidAPI {
|
|||||||
.map_err(VeilidAPIError::generic)?;
|
.map_err(VeilidAPIError::generic)?;
|
||||||
let rss = self.routing_table()?.route_spec_store();
|
let rss = self.routing_table()?.route_spec_store();
|
||||||
let route_id = rss
|
let route_id = rss
|
||||||
.import_remote_private_route(blob_dec)
|
.import_remote_private_route_blob(blob_dec)
|
||||||
.map_err(VeilidAPIError::generic)?;
|
.map_err(VeilidAPIError::generic)?;
|
||||||
|
|
||||||
let mut dc = DEBUG_CACHE.lock();
|
let mut dc = DEBUG_CACHE.lock();
|
||||||
|
Loading…
Reference in New Issue
Block a user