This commit is contained in:
John Smith
2023-06-16 11:57:55 -04:00
parent d114ea3b72
commit 14ba85efda
18 changed files with 158 additions and 75 deletions

View File

@@ -1331,9 +1331,9 @@ impl RouteSpecStore {
}
// 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");
}
// 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);

View File

@@ -99,10 +99,14 @@ impl RPCProcessor {
}
/// Exposed to API for apps to return app call answers
pub async fn app_call_reply(&self, id: OperationId, message: Vec<u8>) -> Result<(), RPCError> {
pub async fn app_call_reply(
&self,
call_id: OperationId,
message: Vec<u8>,
) -> Result<(), RPCError> {
self.unlocked_inner
.waiting_app_call_table
.complete_op_waiter(id, message)
.complete_op_waiter(call_id, message)
.await
}
}

View File

@@ -258,10 +258,14 @@ impl VeilidAPI {
// App Calls
#[instrument(level = "debug", skip(self))]
pub async fn app_call_reply(&self, id: OperationId, message: Vec<u8>) -> VeilidAPIResult<()> {
pub async fn app_call_reply(
&self,
call_id: OperationId,
message: Vec<u8>,
) -> VeilidAPIResult<()> {
let rpc_processor = self.rpc_processor()?;
rpc_processor
.app_call_reply(id, message)
.app_call_reply(call_id, message)
.await
.map_err(|e| e.into())
}

View File

@@ -31,16 +31,22 @@ fn get_string(text: &str) -> Option<String> {
Some(text.to_owned())
}
fn get_route_id(rss: RouteSpecStore, allow_remote: bool) -> impl Fn(&str) -> Option<RouteId> {
fn get_route_id(
rss: RouteSpecStore,
allow_allocated: bool,
allow_remote: bool,
) -> impl Fn(&str) -> Option<RouteId> {
return move |text: &str| {
if text.is_empty() {
return None;
}
match RouteId::from_str(text).ok() {
Some(key) => {
let routes = rss.list_allocated_routes(|k, _| Some(*k));
if routes.contains(&key) {
return Some(key);
if allow_allocated {
let routes = rss.list_allocated_routes(|k, _| Some(*k));
if routes.contains(&key) {
return Some(key);
}
}
if allow_remote {
let rroutes = rss.list_remote_routes(|k, _| Some(*k));
@@ -50,11 +56,13 @@ fn get_route_id(rss: RouteSpecStore, allow_remote: bool) -> impl Fn(&str) -> Opt
}
}
None => {
let routes = rss.list_allocated_routes(|k, _| Some(*k));
for r in routes {
let rkey = r.encode();
if rkey.starts_with(text) {
return Some(r);
if allow_allocated {
let routes = rss.list_allocated_routes(|k, _| Some(*k));
for r in routes {
let rkey = r.encode();
if rkey.starts_with(text) {
return Some(r);
}
}
}
if allow_remote {
@@ -90,7 +98,7 @@ fn get_safety_selection(text: &str, routing_table: RoutingTable) -> Option<Safet
let mut sequencing = Sequencing::default();
for x in text.split(",") {
let x = x.trim();
if let Some(pr) = get_route_id(rss.clone(), false)(x) {
if let Some(pr) = get_route_id(rss.clone(), true, false)(x) {
preferred_route = Some(pr)
}
if let Some(n) = get_number(x) {
@@ -143,19 +151,29 @@ fn get_destination(routing_table: RoutingTable) -> impl FnOnce(&str) -> Option<D
return None;
}
if &text[0..1] == "#" {
let rss = routing_table.route_spec_store();
// Private route
let text = &text[1..];
let n = get_number(text)?;
let mut dc = DEBUG_CACHE.lock();
let private_route_id = dc.imported_routes.get(n)?.clone();
let rss = routing_table.route_spec_store();
let Some(private_route) = rss.best_remote_private_route(&private_route_id) else {
// Remove imported route
dc.imported_routes.remove(n);
info!("removed dead imported route {}", n);
return None;
let private_route = if let Some(prid) = get_route_id(rss.clone(), false, true)(text) {
let Some(private_route) = rss.best_remote_private_route(&prid) else {
return None;
};
private_route
} else {
let mut dc = DEBUG_CACHE.lock();
let n = get_number(text)?;
let prid = dc.imported_routes.get(n)?.clone();
let Some(private_route) = rss.best_remote_private_route(&prid) else {
// Remove imported route
dc.imported_routes.remove(n);
info!("removed dead imported route {}", n);
return None;
};
private_route
};
Some(Destination::private_route(
private_route,
ss.unwrap_or(SafetySelection::Unsafe(Sequencing::default())),
@@ -663,7 +681,7 @@ impl VeilidAPI {
1,
"debug_route",
"route_id",
get_route_id(rss.clone(), true),
get_route_id(rss.clone(), true, true),
)?;
// Release route
@@ -695,7 +713,7 @@ impl VeilidAPI {
1,
"debug_route",
"route_id",
get_route_id(rss.clone(), false),
get_route_id(rss.clone(), true, false),
)?;
let full = {
if args.len() > 2 {
@@ -747,7 +765,7 @@ impl VeilidAPI {
1,
"debug_route",
"route_id",
get_route_id(rss.clone(), false),
get_route_id(rss.clone(), true, false),
)?;
// Unpublish route
@@ -769,7 +787,7 @@ impl VeilidAPI {
1,
"debug_route",
"route_id",
get_route_id(rss.clone(), true),
get_route_id(rss.clone(), true, true),
)?;
match rss.debug_route(&route_id) {
@@ -831,7 +849,7 @@ impl VeilidAPI {
1,
"debug_route",
"route_id",
get_route_id(rss.clone(), true),
get_route_id(rss.clone(), true, true),
)?;
let success = rss

View File

@@ -67,15 +67,15 @@ pub struct VeilidAppCall {
/// The id to reply to
#[serde(with = "json_as_string")]
#[schemars(with = "String")]
id: OperationId,
call_id: OperationId,
}
impl VeilidAppCall {
pub fn new(sender: Option<TypedKey>, message: Vec<u8>, id: OperationId) -> Self {
pub fn new(sender: Option<TypedKey>, message: Vec<u8>, call_id: OperationId) -> Self {
Self {
sender,
message,
id,
call_id,
}
}
@@ -86,6 +86,6 @@ impl VeilidAppCall {
&self.message
}
pub fn id(&self) -> OperationId {
self.id
self.call_id
}
}