close #169
This commit is contained in:
@@ -7,7 +7,6 @@ mod operation_complete_tunnel;
|
||||
mod operation_find_block;
|
||||
mod operation_find_node;
|
||||
mod operation_get_value;
|
||||
mod operation_node_info_update;
|
||||
mod operation_return_receipt;
|
||||
mod operation_route;
|
||||
mod operation_set_value;
|
||||
@@ -31,7 +30,6 @@ pub use operation_complete_tunnel::*;
|
||||
pub use operation_find_block::*;
|
||||
pub use operation_find_node::*;
|
||||
pub use operation_get_value::*;
|
||||
pub use operation_node_info_update::*;
|
||||
pub use operation_return_receipt::*;
|
||||
pub use operation_route::*;
|
||||
pub use operation_set_value::*;
|
||||
|
@@ -16,10 +16,7 @@ impl RPCOperationKind {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode(
|
||||
kind_reader: &veilid_capnp::operation::kind::Reader,
|
||||
opt_sender_node_id: Option<&DHTKey>,
|
||||
) -> Result<Self, RPCError> {
|
||||
pub fn decode(kind_reader: &veilid_capnp::operation::kind::Reader) -> Result<Self, RPCError> {
|
||||
let which_reader = kind_reader.which().map_err(RPCError::protocol)?;
|
||||
let out = match which_reader {
|
||||
veilid_capnp::operation::kind::Which::Question(r) => {
|
||||
@@ -29,7 +26,7 @@ impl RPCOperationKind {
|
||||
}
|
||||
veilid_capnp::operation::kind::Which::Statement(r) => {
|
||||
let q_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCStatement::decode(&q_reader, opt_sender_node_id)?;
|
||||
let out = RPCStatement::decode(&q_reader)?;
|
||||
RPCOperationKind::Statement(out)
|
||||
}
|
||||
veilid_capnp::operation::kind::Which::Answer(r) => {
|
||||
@@ -141,7 +138,7 @@ impl RPCOperation {
|
||||
let target_node_info_ts = operation_reader.get_target_node_info_ts();
|
||||
|
||||
let kind_reader = operation_reader.get_kind();
|
||||
let kind = RPCOperationKind::decode(&kind_reader, opt_sender_node_id)?;
|
||||
let kind = RPCOperationKind::decode(&kind_reader)?;
|
||||
|
||||
Ok(RPCOperation {
|
||||
op_id,
|
||||
|
@@ -1,32 +0,0 @@
|
||||
use super::*;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct RPCOperationNodeInfoUpdate {
|
||||
pub signed_node_info: SignedNodeInfo,
|
||||
}
|
||||
|
||||
impl RPCOperationNodeInfoUpdate {
|
||||
pub fn decode(
|
||||
reader: &veilid_capnp::operation_node_info_update::Reader,
|
||||
opt_sender_node_id: Option<&DHTKey>,
|
||||
) -> Result<RPCOperationNodeInfoUpdate, RPCError> {
|
||||
if opt_sender_node_id.is_none() {
|
||||
return Err(RPCError::protocol(
|
||||
"can't decode node info update without sender node id",
|
||||
));
|
||||
}
|
||||
let sender_node_id = opt_sender_node_id.unwrap();
|
||||
let sni_reader = reader.get_signed_node_info().map_err(RPCError::protocol)?;
|
||||
let signed_node_info = decode_signed_node_info(&sni_reader, sender_node_id)?;
|
||||
|
||||
Ok(RPCOperationNodeInfoUpdate { signed_node_info })
|
||||
}
|
||||
pub fn encode(
|
||||
&self,
|
||||
builder: &mut veilid_capnp::operation_node_info_update::Builder,
|
||||
) -> Result<(), RPCError> {
|
||||
let mut sni_builder = builder.reborrow().init_signed_node_info();
|
||||
encode_signed_node_info(&self.signed_node_info, &mut sni_builder)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
@@ -18,12 +18,9 @@ impl RPCStatement {
|
||||
pub fn desc(&self) -> &'static str {
|
||||
self.detail.desc()
|
||||
}
|
||||
pub fn decode(
|
||||
reader: &veilid_capnp::statement::Reader,
|
||||
opt_sender_node_id: Option<&DHTKey>,
|
||||
) -> Result<RPCStatement, RPCError> {
|
||||
pub fn decode(reader: &veilid_capnp::statement::Reader) -> Result<RPCStatement, RPCError> {
|
||||
let d_reader = reader.get_detail();
|
||||
let detail = RPCStatementDetail::decode(&d_reader, opt_sender_node_id)?;
|
||||
let detail = RPCStatementDetail::decode(&d_reader)?;
|
||||
Ok(RPCStatement { detail })
|
||||
}
|
||||
pub fn encode(&self, builder: &mut veilid_capnp::statement::Builder) -> Result<(), RPCError> {
|
||||
@@ -36,7 +33,6 @@ impl RPCStatement {
|
||||
pub enum RPCStatementDetail {
|
||||
ValidateDialInfo(RPCOperationValidateDialInfo),
|
||||
Route(RPCOperationRoute),
|
||||
NodeInfoUpdate(RPCOperationNodeInfoUpdate),
|
||||
ValueChanged(RPCOperationValueChanged),
|
||||
Signal(RPCOperationSignal),
|
||||
ReturnReceipt(RPCOperationReturnReceipt),
|
||||
@@ -48,7 +44,6 @@ impl RPCStatementDetail {
|
||||
match self {
|
||||
RPCStatementDetail::ValidateDialInfo(_) => "ValidateDialInfo",
|
||||
RPCStatementDetail::Route(_) => "Route",
|
||||
RPCStatementDetail::NodeInfoUpdate(_) => "NodeInfoUpdate",
|
||||
RPCStatementDetail::ValueChanged(_) => "ValueChanged",
|
||||
RPCStatementDetail::Signal(_) => "Signal",
|
||||
RPCStatementDetail::ReturnReceipt(_) => "ReturnReceipt",
|
||||
@@ -57,7 +52,6 @@ impl RPCStatementDetail {
|
||||
}
|
||||
pub fn decode(
|
||||
reader: &veilid_capnp::statement::detail::Reader,
|
||||
opt_sender_node_id: Option<&DHTKey>,
|
||||
) -> Result<RPCStatementDetail, RPCError> {
|
||||
let which_reader = reader.which().map_err(RPCError::protocol)?;
|
||||
let out = match which_reader {
|
||||
@@ -71,11 +65,6 @@ impl RPCStatementDetail {
|
||||
let out = RPCOperationRoute::decode(&op_reader)?;
|
||||
RPCStatementDetail::Route(out)
|
||||
}
|
||||
veilid_capnp::statement::detail::NodeInfoUpdate(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationNodeInfoUpdate::decode(&op_reader, opt_sender_node_id)?;
|
||||
RPCStatementDetail::NodeInfoUpdate(out)
|
||||
}
|
||||
veilid_capnp::statement::detail::ValueChanged(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationValueChanged::decode(&op_reader)?;
|
||||
@@ -108,9 +97,6 @@ impl RPCStatementDetail {
|
||||
d.encode(&mut builder.reborrow().init_validate_dial_info())
|
||||
}
|
||||
RPCStatementDetail::Route(d) => d.encode(&mut builder.reborrow().init_route()),
|
||||
RPCStatementDetail::NodeInfoUpdate(d) => {
|
||||
d.encode(&mut builder.reborrow().init_node_info_update())
|
||||
}
|
||||
RPCStatementDetail::ValueChanged(d) => {
|
||||
d.encode(&mut builder.reborrow().init_value_changed())
|
||||
}
|
||||
|
@@ -9,7 +9,6 @@ mod rpc_error;
|
||||
mod rpc_find_block;
|
||||
mod rpc_find_node;
|
||||
mod rpc_get_value;
|
||||
mod rpc_node_info_update;
|
||||
mod rpc_return_receipt;
|
||||
mod rpc_route;
|
||||
mod rpc_set_value;
|
||||
@@ -113,16 +112,6 @@ impl RPCMessageData {
|
||||
}
|
||||
}
|
||||
|
||||
// impl ReaderSegments for RPCMessageData {
|
||||
// fn get_segment(&self, idx: u32) -> Option<&[u8]> {
|
||||
// if idx > 0 {
|
||||
// None
|
||||
// } else {
|
||||
// Some(self.contents.as_slice())
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
#[derive(Debug)]
|
||||
struct RPCMessageEncoded {
|
||||
header: RPCMessageHeader,
|
||||
@@ -145,25 +134,8 @@ where
|
||||
.map_err(RPCError::protocol)
|
||||
.map_err(logthru_rpc!())?;
|
||||
Ok(buffer)
|
||||
// let wordvec = builder
|
||||
// .into_reader()
|
||||
// .canonicalize()
|
||||
// .map_err(RPCError::protocol)
|
||||
// .map_err(logthru_rpc!())?;
|
||||
// Ok(capnp::Word::words_to_bytes(wordvec.as_slice()).to_vec())
|
||||
}
|
||||
|
||||
// fn reader_to_vec<'a, T>(reader: &capnp::message::Reader<T>) -> Result<Vec<u8>, RPCError>
|
||||
// where
|
||||
// T: capnp::message::ReaderSegments + 'a,
|
||||
// {
|
||||
// let wordvec = reader
|
||||
// .canonicalize()
|
||||
// .map_err(RPCError::protocol)
|
||||
// .map_err(logthru_rpc!())?;
|
||||
// Ok(capnp::Word::words_to_bytes(wordvec.as_slice()).to_vec())
|
||||
// }
|
||||
|
||||
#[derive(Debug)]
|
||||
struct WaitableReply {
|
||||
handle: OperationWaitHandle<RPCMessage>,
|
||||
@@ -209,7 +181,7 @@ struct RenderedOperation {
|
||||
|
||||
/// Node information exchanged during every RPC message
|
||||
#[derive(Default, Debug, Clone)]
|
||||
struct SenderSignedNodeInfo {
|
||||
pub struct SenderSignedNodeInfo {
|
||||
/// The current signed node info of the sender if required
|
||||
signed_node_info: Option<SignedNodeInfo>,
|
||||
/// The last timestamp of the target's node info to assist remote node with sending its latest node info
|
||||
@@ -558,8 +530,8 @@ impl RPCProcessor {
|
||||
safety_route: compiled_route.safety_route,
|
||||
operation,
|
||||
};
|
||||
let ssni_route =
|
||||
self.get_sender_signed_node_info(&Destination::direct(compiled_route.first_hop))?;
|
||||
let ssni_route = self
|
||||
.get_sender_signed_node_info(&Destination::direct(compiled_route.first_hop.clone()))?;
|
||||
let operation = RPCOperation::new_statement(
|
||||
RPCStatement::new(RPCStatementDetail::Route(route_operation)),
|
||||
ssni_route,
|
||||
@@ -1334,7 +1306,6 @@ impl RPCProcessor {
|
||||
self.process_validate_dial_info(msg).await
|
||||
}
|
||||
RPCStatementDetail::Route(_) => self.process_route(msg).await,
|
||||
RPCStatementDetail::NodeInfoUpdate(_) => self.process_node_info_update(msg).await,
|
||||
RPCStatementDetail::ValueChanged(_) => self.process_value_changed(msg).await,
|
||||
RPCStatementDetail::Signal(_) => self.process_signal(msg).await,
|
||||
RPCStatementDetail::ReturnReceipt(_) => self.process_return_receipt(msg).await,
|
||||
|
@@ -1,84 +0,0 @@
|
||||
use super::*;
|
||||
|
||||
impl RPCProcessor {
|
||||
// Sends a our node info to another node
|
||||
#[instrument(level = "trace", skip(self), ret, err)]
|
||||
pub async fn rpc_call_node_info_update(
|
||||
self,
|
||||
target: NodeRef,
|
||||
routing_domain: RoutingDomain,
|
||||
) -> Result<NetworkResult<()>, RPCError> {
|
||||
// Get the signed node info for the desired routing domain to send update with
|
||||
let signed_node_info = self
|
||||
.routing_table()
|
||||
.get_own_peer_info(routing_domain)
|
||||
.signed_node_info;
|
||||
let node_info_update = RPCOperationNodeInfoUpdate { signed_node_info };
|
||||
let statement = RPCStatement::new(RPCStatementDetail::NodeInfoUpdate(node_info_update));
|
||||
|
||||
// Send the node_info_update request to the specific routing domain requested
|
||||
network_result_try!(
|
||||
self.statement(
|
||||
Destination::direct(
|
||||
target.filtered_clone(NodeRefFilter::new().with_routing_domain(routing_domain))
|
||||
),
|
||||
statement,
|
||||
)
|
||||
.await?
|
||||
);
|
||||
|
||||
Ok(NetworkResult::value(()))
|
||||
}
|
||||
|
||||
#[instrument(level = "trace", skip(self, msg), fields(msg.operation.op_id), ret, err)]
|
||||
pub(crate) async fn process_node_info_update(
|
||||
&self,
|
||||
msg: RPCMessage,
|
||||
) -> Result<NetworkResult<()>, RPCError> {
|
||||
let detail = match msg.header.detail {
|
||||
RPCMessageHeaderDetail::Direct(detail) => detail,
|
||||
RPCMessageHeaderDetail::SafetyRouted(_) | RPCMessageHeaderDetail::PrivateRouted(_) => {
|
||||
return Ok(NetworkResult::invalid_message(
|
||||
"node_info_update must be direct",
|
||||
));
|
||||
}
|
||||
};
|
||||
let sender_node_id = detail.envelope.get_sender_id();
|
||||
let routing_domain = detail.routing_domain;
|
||||
|
||||
// Get the statement
|
||||
let node_info_update = match msg.operation.into_kind() {
|
||||
RPCOperationKind::Statement(s) => match s.into_detail() {
|
||||
RPCStatementDetail::NodeInfoUpdate(s) => s,
|
||||
_ => panic!("not a node info update"),
|
||||
},
|
||||
_ => panic!("not a statement"),
|
||||
};
|
||||
|
||||
// Update our routing table with signed node info
|
||||
if !self.filter_node_info(routing_domain, &node_info_update.signed_node_info) {
|
||||
return Ok(NetworkResult::invalid_message(format!(
|
||||
"node info doesn't belong in {:?} routing domain: {}",
|
||||
routing_domain, sender_node_id
|
||||
)));
|
||||
}
|
||||
|
||||
if self
|
||||
.routing_table()
|
||||
.register_node_with_signed_node_info(
|
||||
routing_domain,
|
||||
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(()))
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user