This commit is contained in:
John Smith
2022-12-08 12:48:01 -05:00
parent 3b1fb5aba1
commit 2b9044fdfa
16 changed files with 92 additions and 322 deletions

View File

@@ -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::*;

View File

@@ -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,

View File

@@ -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(())
}
}

View File

@@ -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())
}