mirror of
https://gitlab.com/veilid/veilid.git
synced 2024-10-01 01:26:08 -04:00
cli
This commit is contained in:
parent
749ba91b8b
commit
e98fae711e
@ -7,6 +7,7 @@ use cursive::event::*;
|
|||||||
use cursive::theme::*;
|
use cursive::theme::*;
|
||||||
use cursive::traits::*;
|
use cursive::traits::*;
|
||||||
use cursive::utils::markup::StyledString;
|
use cursive::utils::markup::StyledString;
|
||||||
|
use cursive::view::ScrollStrategy;
|
||||||
use cursive::views::*;
|
use cursive::views::*;
|
||||||
use cursive::Cursive;
|
use cursive::Cursive;
|
||||||
use cursive::CursiveRunnable;
|
use cursive::CursiveRunnable;
|
||||||
@ -215,7 +216,13 @@ impl UI {
|
|||||||
UI::setup_quit_handler(s);
|
UI::setup_quit_handler(s);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
fn clear_handler(siv: &mut Cursive) {
|
||||||
|
cursive_flexi_logger_view::clear_log();
|
||||||
|
UI::update_cb(siv);
|
||||||
|
}
|
||||||
|
fn node_events(s: &mut Cursive) -> ViewRef<FlexiLoggerView> {
|
||||||
|
s.find_name("node-events").unwrap()
|
||||||
|
}
|
||||||
fn node_events_panel(
|
fn node_events_panel(
|
||||||
s: &mut Cursive,
|
s: &mut Cursive,
|
||||||
) -> ViewRef<Panel<ResizedView<NamedView<ScrollView<FlexiLoggerView>>>>> {
|
) -> ViewRef<Panel<ResizedView<NamedView<ScrollView<FlexiLoggerView>>>>> {
|
||||||
@ -737,8 +744,12 @@ impl UI {
|
|||||||
// Create layouts
|
// Create layouts
|
||||||
|
|
||||||
let node_events_view = Panel::new(
|
let node_events_view = Panel::new(
|
||||||
FlexiLoggerView::new_scrollable()
|
FlexiLoggerView::new()
|
||||||
.with_name("node-events")
|
.with_name("node-events")
|
||||||
|
.scrollable()
|
||||||
|
.scroll_x(true)
|
||||||
|
.scroll_y(true)
|
||||||
|
.scroll_strategy(ScrollStrategy::StickToBottom)
|
||||||
.full_screen(),
|
.full_screen(),
|
||||||
)
|
)
|
||||||
.title_position(HAlign::Left)
|
.title_position(HAlign::Left)
|
||||||
@ -822,6 +833,7 @@ impl UI {
|
|||||||
|
|
||||||
UI::setup_colors(&mut siv, &mut inner, settings);
|
UI::setup_colors(&mut siv, &mut inner, settings);
|
||||||
UI::setup_quit_handler(&mut siv);
|
UI::setup_quit_handler(&mut siv);
|
||||||
|
siv.set_global_callback(cursive::event::Event::Ctrl(Key::K), UI::clear_handler);
|
||||||
|
|
||||||
drop(inner);
|
drop(inner);
|
||||||
drop(siv);
|
drop(siv);
|
||||||
|
@ -977,7 +977,8 @@ impl RPCProcessor {
|
|||||||
self.unlocked_inner
|
self.unlocked_inner
|
||||||
.waiting_rpc_table
|
.waiting_rpc_table
|
||||||
.complete_op_waiter(msg.operation.op_id(), msg)
|
.complete_op_waiter(msg.operation.op_id(), msg)
|
||||||
.await
|
.await?;
|
||||||
|
Ok(NetworkResult::value(()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1005,7 +1006,13 @@ impl RPCProcessor {
|
|||||||
|
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
};
|
};
|
||||||
network_result_value_or_log!(debug res => {});
|
cfg_if::cfg_if! {
|
||||||
|
if #[cfg(debug_assertions)] {
|
||||||
|
network_result_value_or_log!(warn res => {});
|
||||||
|
} else {
|
||||||
|
network_result_value_or_log!(debug res => {});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,11 +88,8 @@ impl RPCProcessor {
|
|||||||
let app_call_a = RPCOperationAppCallA { message };
|
let app_call_a = RPCOperationAppCallA { message };
|
||||||
|
|
||||||
// Send status answer
|
// Send status answer
|
||||||
let res = self
|
self.answer(msg, RPCAnswer::new(RPCAnswerDetail::AppCallA(app_call_a)))
|
||||||
.answer(msg, RPCAnswer::new(RPCAnswerDetail::AppCallA(app_call_a)))
|
.await
|
||||||
.await?;
|
|
||||||
tracing::Span::current().record("res", &tracing::field::display(res));
|
|
||||||
Ok(res)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Exposed to API for apps to return app call answers
|
/// Exposed to API for apps to return app call answers
|
||||||
|
@ -13,9 +13,7 @@ impl RPCProcessor {
|
|||||||
let statement = RPCStatement::new(RPCStatementDetail::AppMessage(app_message));
|
let statement = RPCStatement::new(RPCStatementDetail::AppMessage(app_message));
|
||||||
|
|
||||||
// Send the app message request
|
// Send the app message request
|
||||||
network_result_try!(self.statement(dest, statement).await?);
|
self.statement(dest, statement).await
|
||||||
|
|
||||||
Ok(NetworkResult::value(()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "trace", skip(self, msg), fields(msg.operation.op_id), ret, err)]
|
#[instrument(level = "trace", skip(self, msg), fields(msg.operation.op_id), ret, err)]
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
impl RPCProcessor {
|
impl RPCProcessor {
|
||||||
#[instrument(level = "trace", skip(self, msg), fields(msg.operation.op_id, res), ret, err)]
|
#[instrument(level = "trace", skip(self, msg), fields(msg.operation.op_id), ret, err)]
|
||||||
pub(crate) async fn process_cancel_tunnel_q(&self, msg: RPCMessage) -> Result<NetworkResult<()>, RPCError> {
|
pub(crate) async fn process_cancel_tunnel_q(
|
||||||
// tracing::Span::current().record("res", &tracing::field::display(res));
|
&self,
|
||||||
|
msg: RPCMessage,
|
||||||
|
) -> Result<NetworkResult<()>, RPCError> {
|
||||||
Err(RPCError::unimplemented("process_cancel_tunnel_q"))
|
Err(RPCError::unimplemented("process_cancel_tunnel_q"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
impl RPCProcessor {
|
impl RPCProcessor {
|
||||||
#[instrument(level = "trace", skip(self, msg), fields(msg.operation.op_id, res), ret, err)]
|
#[instrument(level = "trace", skip(self, msg), fields(msg.operation.op_id), ret, err)]
|
||||||
pub(crate) async fn process_complete_tunnel_q(
|
pub(crate) async fn process_complete_tunnel_q(
|
||||||
&self,
|
&self,
|
||||||
msg: RPCMessage,
|
msg: RPCMessage,
|
||||||
) -> Result<NetworkResult<()>, RPCError> {
|
) -> Result<NetworkResult<()>, RPCError> {
|
||||||
// tracing::Span::current().record("res", &tracing::field::display(res));
|
|
||||||
Err(RPCError::unimplemented("process_complete_tunnel_q"))
|
Err(RPCError::unimplemented("process_complete_tunnel_q"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
impl RPCProcessor {
|
impl RPCProcessor {
|
||||||
#[instrument(level = "trace", skip(self, msg), fields(msg.operation.op_id, res), ret, err)]
|
#[instrument(level = "trace", skip(self, msg), fields(msg.operation.op_id), ret, err)]
|
||||||
pub(crate) async fn process_find_block_q(
|
pub(crate) async fn process_find_block_q(
|
||||||
&self,
|
&self,
|
||||||
msg: RPCMessage,
|
msg: RPCMessage,
|
||||||
) -> Result<NetworkResult<()>, RPCError> {
|
) -> Result<NetworkResult<()>, RPCError> {
|
||||||
// tracing::Span::current().record("res", &tracing::field::display(res));
|
|
||||||
Err(RPCError::unimplemented("process_find_block_q"))
|
Err(RPCError::unimplemented("process_find_block_q"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ impl RPCProcessor {
|
|||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "trace", skip(self, msg), fields(msg.operation.op_id, res), ret, err)]
|
#[instrument(level = "trace", skip(self, msg), fields(msg.operation.op_id), ret, err)]
|
||||||
pub(crate) async fn process_find_node_q(
|
pub(crate) async fn process_find_node_q(
|
||||||
&self,
|
&self,
|
||||||
msg: RPCMessage,
|
msg: RPCMessage,
|
||||||
@ -129,10 +129,7 @@ impl RPCProcessor {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Send status answer
|
// Send status answer
|
||||||
let res = self
|
self.answer(msg, RPCAnswer::new(RPCAnswerDetail::FindNodeA(find_node_a)))
|
||||||
.answer(msg, RPCAnswer::new(RPCAnswerDetail::FindNodeA(find_node_a)))
|
.await
|
||||||
.await?;
|
|
||||||
tracing::Span::current().record("res", &tracing::field::display(res));
|
|
||||||
Ok(res)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
impl RPCProcessor {
|
impl RPCProcessor {
|
||||||
#[instrument(level = "trace", skip(self, msg), fields(msg.operation.op_id, res), ret, err)]
|
#[instrument(level = "trace", skip(self, msg), fields(msg.operation.op_id), ret, err)]
|
||||||
pub(crate) async fn process_get_value_q(
|
pub(crate) async fn process_get_value_q(
|
||||||
&self,
|
&self,
|
||||||
msg: RPCMessage,
|
msg: RPCMessage,
|
||||||
) -> Result<NetworkResult<()>, RPCError> {
|
) -> Result<NetworkResult<()>, RPCError> {
|
||||||
//tracing::Span::current().record("res", &tracing::field::display(res));
|
|
||||||
Err(RPCError::unimplemented("process_get_value_q"))
|
Err(RPCError::unimplemented("process_get_value_q"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,12 +63,21 @@ impl RPCProcessor {
|
|||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
self.routing_table().register_node_with_signed_node_info(
|
if self
|
||||||
routing_domain,
|
.routing_table()
|
||||||
sender_node_id,
|
.register_node_with_signed_node_info(
|
||||||
node_info_update.signed_node_info,
|
routing_domain,
|
||||||
false,
|
sender_node_id,
|
||||||
);
|
node_info_update.signed_node_info,
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
.is_none()
|
||||||
|
{
|
||||||
|
return Ok(NetworkResult::invalid_message(format!(
|
||||||
|
"could not register node info update {}",
|
||||||
|
sender_node_id
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
Ok(NetworkResult::value(()))
|
Ok(NetworkResult::value(()))
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
xxx go through and convert errs to networkresult
|
|
||||||
|
|
||||||
impl RPCProcessor {
|
impl RPCProcessor {
|
||||||
#[instrument(level = "trace", skip_all, err)]
|
#[instrument(level = "trace", skip_all, err)]
|
||||||
async fn process_route_safety_route_hop(
|
async fn process_route_safety_route_hop(
|
||||||
@ -11,44 +9,48 @@ impl RPCProcessor {
|
|||||||
) -> Result<NetworkResult<()>, RPCError> {
|
) -> Result<NetworkResult<()>, RPCError> {
|
||||||
// Make sure hop count makes sense
|
// Make sure hop count makes sense
|
||||||
if route.safety_route.hop_count as usize > self.unlocked_inner.max_route_hop_count {
|
if route.safety_route.hop_count as usize > self.unlocked_inner.max_route_hop_count {
|
||||||
return Err(RPCError::protocol(
|
return Ok(NetworkResult::invalid_message(
|
||||||
"Safety route hop count too high to process",
|
"Safety route hop count too high to process",
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if route.safety_route.hop_count == 0 {
|
if route.safety_route.hop_count == 0 {
|
||||||
return Err(RPCError::protocol(
|
return Ok(NetworkResult::invalid_message(
|
||||||
"Safety route hop count should not be zero if there are more hops",
|
"Safety route hop count should not be zero if there are more hops",
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if route_hop.next_hop.is_none() {
|
if route_hop.next_hop.is_none() {
|
||||||
return Err(RPCError::protocol("Safety route hop must have next hop"));
|
return Ok(NetworkResult::invalid_message(
|
||||||
|
"Safety route hop must have next hop",
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get next hop node ref
|
// Get next hop node ref
|
||||||
let next_hop_nr = match route_hop.node {
|
let next_hop_nr = match route_hop.node {
|
||||||
RouteNode::NodeId(id) => {
|
RouteNode::NodeId(id) => {
|
||||||
//
|
//
|
||||||
self.routing_table
|
let Some(nr) = self.routing_table.lookup_node_ref(id.key) else {
|
||||||
.lookup_node_ref(id.key)
|
return Ok(NetworkResult::invalid_message(format!("node hop {} not found", id.key)));
|
||||||
.ok_or_else(|| RPCError::network(format!("node hop {} not found", id.key)))
|
};
|
||||||
|
nr
|
||||||
}
|
}
|
||||||
RouteNode::PeerInfo(pi) => {
|
RouteNode::PeerInfo(pi) => {
|
||||||
//
|
//
|
||||||
self.routing_table
|
let Some(nr) = self.routing_table
|
||||||
.register_node_with_signed_node_info(
|
.register_node_with_signed_node_info(
|
||||||
RoutingDomain::PublicInternet,
|
RoutingDomain::PublicInternet,
|
||||||
pi.node_id.key,
|
pi.node_id.key,
|
||||||
pi.signed_node_info,
|
pi.signed_node_info,
|
||||||
false,
|
false,
|
||||||
)
|
) else
|
||||||
.ok_or_else(|| {
|
{
|
||||||
RPCError::network(format!(
|
return Ok(NetworkResult::invalid_message(format!(
|
||||||
"node hop {} could not be registered",
|
"node hop {} could not be registered",
|
||||||
pi.node_id.key
|
pi.node_id.key
|
||||||
))
|
)));
|
||||||
})
|
};
|
||||||
|
nr
|
||||||
}
|
}
|
||||||
}?;
|
};
|
||||||
|
|
||||||
// Pass along the route
|
// Pass along the route
|
||||||
let next_hop_route = RPCOperationRoute {
|
let next_hop_route = RPCOperationRoute {
|
||||||
@ -62,13 +64,8 @@ impl RPCProcessor {
|
|||||||
let next_hop_route_stmt = RPCStatement::new(RPCStatementDetail::Route(next_hop_route));
|
let next_hop_route_stmt = RPCStatement::new(RPCStatementDetail::Route(next_hop_route));
|
||||||
|
|
||||||
// Send the next route statement
|
// Send the next route statement
|
||||||
network_result_value_or_log!(debug
|
self.statement(Destination::direct(next_hop_nr), next_hop_route_stmt)
|
||||||
self.statement(Destination::direct(next_hop_nr), next_hop_route_stmt)
|
.await
|
||||||
.await? => {
|
|
||||||
return Err(RPCError::network("unable to send route statement for next safety route hop"));
|
|
||||||
}
|
|
||||||
);
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "trace", skip_all, err)]
|
#[instrument(level = "trace", skip_all, err)]
|
||||||
@ -124,14 +121,8 @@ impl RPCProcessor {
|
|||||||
let next_hop_route_stmt = RPCStatement::new(RPCStatementDetail::Route(next_hop_route));
|
let next_hop_route_stmt = RPCStatement::new(RPCStatementDetail::Route(next_hop_route));
|
||||||
|
|
||||||
// Send the next route statement
|
// Send the next route statement
|
||||||
network_result_value_or_log!(debug
|
self.statement(Destination::direct(next_hop_nr), next_hop_route_stmt)
|
||||||
self.statement(Destination::direct(next_hop_nr), next_hop_route_stmt)
|
.await
|
||||||
.await? => {
|
|
||||||
return Err(RPCError::network("unable to send route statement for private route hop"));
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Process a routed operation that came in over a safety route but no private route
|
/// Process a routed operation that came in over a safety route but no private route
|
||||||
@ -164,21 +155,23 @@ impl RPCProcessor {
|
|||||||
.crypto
|
.crypto
|
||||||
.cached_dh(&safety_route.public_key, &node_id_secret)
|
.cached_dh(&safety_route.public_key, &node_id_secret)
|
||||||
.map_err(RPCError::protocol)?;
|
.map_err(RPCError::protocol)?;
|
||||||
let body = Crypto::decrypt_aead(
|
let body = match Crypto::decrypt_aead(
|
||||||
&routed_operation.data,
|
&routed_operation.data,
|
||||||
&routed_operation.nonce,
|
&routed_operation.nonce,
|
||||||
&dh_secret,
|
&dh_secret,
|
||||||
None,
|
None,
|
||||||
)
|
) {
|
||||||
.map_err(RPCError::map_internal(
|
Ok(v) => v,
|
||||||
"decryption of routed operation failed",
|
Err(e) => {
|
||||||
))?;
|
return Ok(NetworkResult::invalid_message(format!("decryption of routed operation failed: {}", e)));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Pass message to RPC system
|
// Pass message to RPC system
|
||||||
self.enqueue_safety_routed_message(sequencing, body)
|
self.enqueue_safety_routed_message(sequencing, body)
|
||||||
.map_err(RPCError::internal)?;
|
.map_err(RPCError::internal)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(NetworkResult::value(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Process a routed operation that came in over both a safety route and a private route
|
/// Process a routed operation that came in over both a safety route and a private route
|
||||||
@ -195,15 +188,17 @@ impl RPCProcessor {
|
|||||||
|
|
||||||
// Look up the private route and ensure it's one in our spec store
|
// Look up the private route and ensure it's one in our spec store
|
||||||
let rss = self.routing_table.route_spec_store();
|
let rss = self.routing_table.route_spec_store();
|
||||||
let (secret_key, safety_spec) = rss
|
let Some((secret_key, safety_spec)) = rss
|
||||||
.validate_signatures(
|
.validate_signatures(
|
||||||
&private_route.public_key,
|
&private_route.public_key,
|
||||||
&routed_operation.signatures,
|
&routed_operation.signatures,
|
||||||
&routed_operation.data,
|
&routed_operation.data,
|
||||||
sender_id,
|
sender_id,
|
||||||
)
|
)
|
||||||
.map_err(RPCError::protocol)?
|
.map_err(RPCError::protocol)?
|
||||||
.ok_or_else(|| RPCError::protocol("signatures did not validate for private route"))?;
|
else {
|
||||||
|
return Ok(NetworkResult::invalid_message("signatures did not validate for private route"));
|
||||||
|
};
|
||||||
|
|
||||||
// Now that things are valid, decrypt the routed operation with DEC(nonce, DH(the SR's public key, the PR's (or node's) secret)
|
// Now that things are valid, decrypt the routed operation with DEC(nonce, DH(the SR's public key, the PR's (or node's) secret)
|
||||||
// xxx: punish nodes that send messages that fail to decrypt eventually. How to do this for private routes?
|
// xxx: punish nodes that send messages that fail to decrypt eventually. How to do this for private routes?
|
||||||
@ -225,7 +220,7 @@ impl RPCProcessor {
|
|||||||
self.enqueue_private_routed_message(private_route.public_key, safety_spec, body)
|
self.enqueue_private_routed_message(private_route.public_key, safety_spec, body)
|
||||||
.map_err(RPCError::internal)?;
|
.map_err(RPCError::internal)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(NetworkResult::value(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "trace", skip_all, err)]
|
#[instrument(level = "trace", skip_all, err)]
|
||||||
@ -238,12 +233,12 @@ impl RPCProcessor {
|
|||||||
) -> Result<NetworkResult<()>, RPCError> {
|
) -> Result<NetworkResult<()>, RPCError> {
|
||||||
// Make sure hop count makes sense
|
// Make sure hop count makes sense
|
||||||
if safety_route.hop_count != 0 {
|
if safety_route.hop_count != 0 {
|
||||||
return Err(RPCError::protocol(
|
return Ok(NetworkResult::invalid_message(
|
||||||
"Safety hop count should be zero if switched to private route",
|
"Safety hop count should be zero if switched to private route",
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if private_route.hop_count != 0 {
|
if private_route.hop_count != 0 {
|
||||||
return Err(RPCError::protocol(
|
return Ok(NetworkResult::invalid_message(
|
||||||
"Private route hop count should be zero if we are at the end",
|
"Private route hop count should be zero if we are at the end",
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -271,7 +266,7 @@ impl RPCProcessor {
|
|||||||
private_route: &PrivateRoute,
|
private_route: &PrivateRoute,
|
||||||
) -> Result<NetworkResult<()>, RPCError> {
|
) -> Result<NetworkResult<()>, RPCError> {
|
||||||
let PrivateRouteHops::FirstHop(pr_first_hop) = &private_route.hops else {
|
let PrivateRouteHops::FirstHop(pr_first_hop) = &private_route.hops else {
|
||||||
return Err(RPCError::protocol("switching from safety route to private route requires first hop"));
|
return Ok(NetworkResult::invalid_message("switching from safety route to private route requires first hop"));
|
||||||
};
|
};
|
||||||
|
|
||||||
// Switching to private route from safety route
|
// Switching to private route from safety route
|
||||||
@ -355,12 +350,12 @@ impl RPCProcessor {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Switching from full safety route to private route first hop
|
// Switching from full safety route to private route first hop
|
||||||
self.process_private_route_first_hop(
|
network_result_try!(self.process_private_route_first_hop(
|
||||||
route.operation,
|
route.operation,
|
||||||
route.safety_route.public_key,
|
route.safety_route.public_key,
|
||||||
&private_route,
|
&private_route,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?);
|
||||||
} else if dec_blob_tag == 0 {
|
} else if dec_blob_tag == 0 {
|
||||||
// RouteHop
|
// RouteHop
|
||||||
let route_hop = {
|
let route_hop = {
|
||||||
@ -371,8 +366,8 @@ impl RPCProcessor {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Continue the full safety route with another hop
|
// Continue the full safety route with another hop
|
||||||
self.process_route_safety_route_hop(route, route_hop)
|
network_result_try!(self.process_route_safety_route_hop(route, route_hop)
|
||||||
.await?;
|
.await?);
|
||||||
} else {
|
} else {
|
||||||
return Ok(NetworkResult::invalid_message("invalid blob tag"));
|
return Ok(NetworkResult::invalid_message("invalid blob tag"));
|
||||||
}
|
}
|
||||||
@ -383,12 +378,12 @@ impl RPCProcessor {
|
|||||||
match &private_route.hops {
|
match &private_route.hops {
|
||||||
PrivateRouteHops::FirstHop(_) => {
|
PrivateRouteHops::FirstHop(_) => {
|
||||||
// Safety route was a stub, start with the beginning of the private route
|
// Safety route was a stub, start with the beginning of the private route
|
||||||
self.process_private_route_first_hop(
|
network_result_try!(self.process_private_route_first_hop(
|
||||||
route.operation,
|
route.operation,
|
||||||
route.safety_route.public_key,
|
route.safety_route.public_key,
|
||||||
private_route,
|
private_route,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?);
|
||||||
}
|
}
|
||||||
PrivateRouteHops::Data(route_hop_data) => {
|
PrivateRouteHops::Data(route_hop_data) => {
|
||||||
// Decrypt the blob with DEC(nonce, DH(the PR's public key, this hop's secret)
|
// Decrypt the blob with DEC(nonce, DH(the PR's public key, this hop's secret)
|
||||||
@ -397,13 +392,17 @@ impl RPCProcessor {
|
|||||||
.crypto
|
.crypto
|
||||||
.cached_dh(&private_route.public_key, &node_id_secret)
|
.cached_dh(&private_route.public_key, &node_id_secret)
|
||||||
.map_err(RPCError::protocol)?;
|
.map_err(RPCError::protocol)?;
|
||||||
let dec_blob_data = Crypto::decrypt_aead(
|
let dec_blob_data = match Crypto::decrypt_aead(
|
||||||
&route_hop_data.blob,
|
&route_hop_data.blob,
|
||||||
&route_hop_data.nonce,
|
&route_hop_data.nonce,
|
||||||
&dh_secret,
|
&dh_secret,
|
||||||
None,
|
None,
|
||||||
)
|
) {
|
||||||
.map_err(RPCError::protocol)?;
|
Ok(v) => v,
|
||||||
|
Err(e) => {
|
||||||
|
return Ok(NetworkResult::invalid_message(format!("unable to decrypt private route hop data: {}", e)));
|
||||||
|
}
|
||||||
|
};
|
||||||
let dec_blob_reader = RPCMessageData::new(dec_blob_data).get_reader()?;
|
let dec_blob_reader = RPCMessageData::new(dec_blob_data).get_reader()?;
|
||||||
|
|
||||||
// Decode next RouteHop
|
// Decode next RouteHop
|
||||||
@ -432,7 +431,7 @@ impl RPCProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Make next PrivateRoute and pass it on
|
// Make next PrivateRoute and pass it on
|
||||||
self.process_route_private_route_hop(
|
network_result_try!(self.process_route_private_route_hop(
|
||||||
route.operation,
|
route.operation,
|
||||||
route_hop.node,
|
route_hop.node,
|
||||||
route.safety_route.public_key,
|
route.safety_route.public_key,
|
||||||
@ -445,7 +444,7 @@ impl RPCProcessor {
|
|||||||
.unwrap_or(PrivateRouteHops::Empty),
|
.unwrap_or(PrivateRouteHops::Empty),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await?;
|
.await?);
|
||||||
}
|
}
|
||||||
PrivateRouteHops::Empty => {
|
PrivateRouteHops::Empty => {
|
||||||
// Ensure hop count == 0
|
// Ensure hop count == 0
|
||||||
@ -456,12 +455,12 @@ impl RPCProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// No hops left, time to process the routed operation
|
// No hops left, time to process the routed operation
|
||||||
self.process_routed_operation(
|
network_result_try!(self.process_routed_operation(
|
||||||
detail,
|
detail,
|
||||||
route.operation,
|
route.operation,
|
||||||
&route.safety_route,
|
&route.safety_route,
|
||||||
private_route,
|
private_route,
|
||||||
)?;
|
)?);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
impl RPCProcessor {
|
impl RPCProcessor {
|
||||||
#[instrument(level = "trace", skip(self, msg), fields(msg.operation.op_id), err)]
|
#[instrument(level = "trace", skip(self, msg), fields(msg.operation.op_id), ret, err)]
|
||||||
pub(crate) async fn process_set_value_q(
|
pub(crate) async fn process_set_value_q(
|
||||||
&self,
|
&self,
|
||||||
msg: RPCMessage,
|
msg: RPCMessage,
|
||||||
|
@ -26,9 +26,7 @@ impl RPCProcessor {
|
|||||||
let statement = RPCStatement::new(RPCStatementDetail::Signal(signal));
|
let statement = RPCStatement::new(RPCStatementDetail::Signal(signal));
|
||||||
|
|
||||||
// Send the signal request
|
// Send the signal request
|
||||||
network_result_try!(self.statement(dest, statement).await?);
|
self.statement(dest, statement).await
|
||||||
|
|
||||||
Ok(NetworkResult::value(()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "trace", skip(self, msg), fields(msg.operation.op_id), ret, err)]
|
#[instrument(level = "trace", skip(self, msg), fields(msg.operation.op_id), ret, err)]
|
||||||
@ -56,11 +54,9 @@ impl RPCProcessor {
|
|||||||
|
|
||||||
// Handle it
|
// Handle it
|
||||||
let network_manager = self.network_manager();
|
let network_manager = self.network_manager();
|
||||||
let res = network_manager
|
network_manager
|
||||||
.handle_signal(signal.signal_info)
|
.handle_signal(signal.signal_info)
|
||||||
.await
|
.await
|
||||||
.map_err(RPCError::network)?;
|
.map_err(RPCError::network)
|
||||||
|
|
||||||
Ok(res)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ impl RPCProcessor {
|
|||||||
&self,
|
&self,
|
||||||
msg: RPCMessage,
|
msg: RPCMessage,
|
||||||
) -> Result<NetworkResult<()>, RPCError> {
|
) -> Result<NetworkResult<()>, RPCError> {
|
||||||
// tracing::Span::current().record("res", &tracing::field::display(res));
|
|
||||||
Err(RPCError::unimplemented("process_start_tunnel_q"))
|
Err(RPCError::unimplemented("process_start_tunnel_q"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -179,7 +179,7 @@ impl RPCProcessor {
|
|||||||
Ok(NetworkResult::value(Answer::new(latency, opt_sender_info)))
|
Ok(NetworkResult::value(Answer::new(latency, opt_sender_info)))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "trace", skip(self, msg), fields(msg.operation.op_id, res), ret, err)]
|
#[instrument(level = "trace", skip(self, msg), fields(msg.operation.op_id), ret, err)]
|
||||||
pub(crate) async fn process_status_q(
|
pub(crate) async fn process_status_q(
|
||||||
&self,
|
&self,
|
||||||
msg: RPCMessage,
|
msg: RPCMessage,
|
||||||
@ -250,10 +250,7 @@ impl RPCProcessor {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Send status answer
|
// Send status answer
|
||||||
let res = self
|
self.answer(msg, RPCAnswer::new(RPCAnswerDetail::StatusA(status_a)))
|
||||||
.answer(msg, RPCAnswer::new(RPCAnswerDetail::StatusA(status_a)))
|
.await
|
||||||
.await?;
|
|
||||||
tracing::Span::current().record("res", &tracing::field::display(res));
|
|
||||||
Ok(res)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,6 @@ impl RPCProcessor {
|
|||||||
&self,
|
&self,
|
||||||
msg: RPCMessage,
|
msg: RPCMessage,
|
||||||
) -> Result<NetworkResult<()>, RPCError> {
|
) -> Result<NetworkResult<()>, RPCError> {
|
||||||
// tracing::Span::current().record("res", &tracing::field::display(res));
|
|
||||||
|
|
||||||
Err(RPCError::unimplemented("process_supply_block_q"))
|
Err(RPCError::unimplemented("process_supply_block_q"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,7 @@ impl RPCProcessor {
|
|||||||
|
|
||||||
// Send the validate_dial_info request
|
// Send the validate_dial_info request
|
||||||
// This can only be sent directly, as relays can not validate dial info
|
// This can only be sent directly, as relays can not validate dial info
|
||||||
let res = network_result_value_or_log!(debug self.statement(Destination::direct(peer), statement)
|
network_result_value_or_log!(debug self.statement(Destination::direct(peer), statement)
|
||||||
.await? => {
|
.await? => {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,6 @@ impl RPCProcessor {
|
|||||||
&self,
|
&self,
|
||||||
msg: RPCMessage,
|
msg: RPCMessage,
|
||||||
) -> Result<NetworkResult<()>, RPCError> {
|
) -> Result<NetworkResult<()>, RPCError> {
|
||||||
// tracing::Span::current().record("res", &tracing::field::display(res));
|
|
||||||
|
|
||||||
Err(RPCError::unimplemented("process_value_changed"))
|
Err(RPCError::unimplemented("process_value_changed"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ impl RPCProcessor {
|
|||||||
&self,
|
&self,
|
||||||
msg: RPCMessage,
|
msg: RPCMessage,
|
||||||
) -> Result<NetworkResult<()>, RPCError> {
|
) -> Result<NetworkResult<()>, RPCError> {
|
||||||
// tracing::Span::current().record("res", &tracing::field::display(res));
|
|
||||||
Err(RPCError::unimplemented("process_watch_value_q"))
|
Err(RPCError::unimplemented("process_watch_value_q"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -303,24 +303,73 @@ macro_rules! network_result_try {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! log_network_result {
|
||||||
|
($text:expr) => {
|
||||||
|
cfg_if::cfg_if! {
|
||||||
|
if #[cfg(debug_assertions)] {
|
||||||
|
info!(target: "network_result", "{}", $text)
|
||||||
|
} else {
|
||||||
|
debug!(target: "network_result", "{}", $text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
($fmt:literal, $($arg:expr),+) => {
|
||||||
|
cfg_if::cfg_if! {
|
||||||
|
if #[cfg(debug_assertions)] {
|
||||||
|
info!(target: "network_result", $fmt, $($arg),+);
|
||||||
|
} else {
|
||||||
|
debug!(target: "network_result", $fmt, $($arg),+);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! network_result_value_or_log {
|
macro_rules! network_result_value_or_log {
|
||||||
($level: ident $r: expr => $f:tt) => {
|
($level: ident $r: expr => $f:tt) => {
|
||||||
match $r {
|
match $r {
|
||||||
NetworkResult::Timeout => {
|
NetworkResult::Timeout => {
|
||||||
log_net!($level "{} at {}@{}:{}", "Timeout".green(), file!(), line!(), column!());
|
log_network_result!(
|
||||||
|
"{} at {}@{}:{}",
|
||||||
|
"Timeout".cyan(),
|
||||||
|
file!(),
|
||||||
|
line!(),
|
||||||
|
column!()
|
||||||
|
);
|
||||||
$f
|
$f
|
||||||
}
|
}
|
||||||
NetworkResult::NoConnection(e) => {
|
NetworkResult::NoConnection(e) => {
|
||||||
log_net!($level "{}({}) at {}@{}:{}", "No connection".green(), e.to_string(), file!(), line!(), column!());
|
log_network_result!(
|
||||||
|
"{}({}) at {}@{}:{}",
|
||||||
|
"No connection".cyan(),
|
||||||
|
e.to_string(),
|
||||||
|
file!(),
|
||||||
|
line!(),
|
||||||
|
column!()
|
||||||
|
);
|
||||||
$f
|
$f
|
||||||
}
|
}
|
||||||
NetworkResult::AlreadyExists(e) => {
|
NetworkResult::AlreadyExists(e) => {
|
||||||
log_net!($level "{}({}) at {}@{}:{}", "Already exists".green(), e.to_string(), file!(), line!(), column!());
|
log_network_result!(
|
||||||
|
"{}({}) at {}@{}:{}",
|
||||||
|
"Already exists".cyan(),
|
||||||
|
e.to_string(),
|
||||||
|
file!(),
|
||||||
|
line!(),
|
||||||
|
column!()
|
||||||
|
);
|
||||||
$f
|
$f
|
||||||
}
|
}
|
||||||
NetworkResult::InvalidMessage(s) => {
|
NetworkResult::InvalidMessage(s) => {
|
||||||
log_net!($level "{}({}) at {}@{}:{}", "Invalid message".green(), s, file!(), line!(), column!());
|
log_network_result!(
|
||||||
|
"{}({}) at {}@{}:{}",
|
||||||
|
"Invalid message".cyan(),
|
||||||
|
s,
|
||||||
|
file!(),
|
||||||
|
line!(),
|
||||||
|
column!()
|
||||||
|
);
|
||||||
$f
|
$f
|
||||||
}
|
}
|
||||||
NetworkResult::Value(v) => v,
|
NetworkResult::Value(v) => v,
|
||||||
|
Loading…
Reference in New Issue
Block a user