app call/message and private routing checkpoint
This commit is contained in:
@@ -11,9 +11,6 @@ impl RPCAnswer {
|
||||
pub fn new(detail: RPCAnswerDetail) -> Self {
|
||||
Self { detail }
|
||||
}
|
||||
// pub fn detail(&self) -> &RPCAnswerDetail {
|
||||
// &self.detail
|
||||
// }
|
||||
pub fn into_detail(self) -> RPCAnswerDetail {
|
||||
self.detail
|
||||
}
|
||||
@@ -35,6 +32,7 @@ impl RPCAnswer {
|
||||
pub enum RPCAnswerDetail {
|
||||
StatusA(RPCOperationStatusA),
|
||||
FindNodeA(RPCOperationFindNodeA),
|
||||
AppCallA(RPCOperationAppCallA),
|
||||
GetValueA(RPCOperationGetValueA),
|
||||
SetValueA(RPCOperationSetValueA),
|
||||
WatchValueA(RPCOperationWatchValueA),
|
||||
@@ -50,6 +48,7 @@ impl RPCAnswerDetail {
|
||||
match self {
|
||||
RPCAnswerDetail::StatusA(_) => "StatusA",
|
||||
RPCAnswerDetail::FindNodeA(_) => "FindNodeA",
|
||||
RPCAnswerDetail::AppCallA(_) => "AppCallA",
|
||||
RPCAnswerDetail::GetValueA(_) => "GetValueA",
|
||||
RPCAnswerDetail::SetValueA(_) => "SetValueA",
|
||||
RPCAnswerDetail::WatchValueA(_) => "WatchValueA",
|
||||
@@ -76,6 +75,11 @@ impl RPCAnswerDetail {
|
||||
let out = RPCOperationFindNodeA::decode(&op_reader)?;
|
||||
RPCAnswerDetail::FindNodeA(out)
|
||||
}
|
||||
veilid_capnp::answer::detail::AppCallA(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationAppCallA::decode(&op_reader)?;
|
||||
RPCAnswerDetail::AppCallA(out)
|
||||
}
|
||||
veilid_capnp::answer::detail::GetValueA(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationGetValueA::decode(&op_reader)?;
|
||||
@@ -126,6 +130,7 @@ impl RPCAnswerDetail {
|
||||
match self {
|
||||
RPCAnswerDetail::StatusA(d) => d.encode(&mut builder.reborrow().init_status_a()),
|
||||
RPCAnswerDetail::FindNodeA(d) => d.encode(&mut builder.reborrow().init_find_node_a()),
|
||||
RPCAnswerDetail::AppCallA(d) => d.encode(&mut builder.reborrow().init_app_call_a()),
|
||||
RPCAnswerDetail::GetValueA(d) => d.encode(&mut builder.reborrow().init_get_value_a()),
|
||||
RPCAnswerDetail::SetValueA(d) => d.encode(&mut builder.reborrow().init_set_value_a()),
|
||||
RPCAnswerDetail::WatchValueA(d) => {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
mod answer;
|
||||
mod operation;
|
||||
mod operation_app_call;
|
||||
mod operation_app_message;
|
||||
mod operation_cancel_tunnel;
|
||||
mod operation_complete_tunnel;
|
||||
mod operation_find_block;
|
||||
@@ -22,6 +24,8 @@ mod statement;
|
||||
|
||||
pub use answer::*;
|
||||
pub use operation::*;
|
||||
pub use operation_app_call::*;
|
||||
pub use operation_app_message::*;
|
||||
pub use operation_cancel_tunnel::*;
|
||||
pub use operation_complete_tunnel::*;
|
||||
pub use operation_find_block::*;
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
use crate::*;
|
||||
use rpc_processor::*;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct RPCOperationAppCallQ {
|
||||
pub message: Vec<u8>,
|
||||
}
|
||||
|
||||
impl RPCOperationAppCallQ {
|
||||
pub fn decode(
|
||||
reader: &veilid_capnp::operation_app_call_q::Reader,
|
||||
) -> Result<RPCOperationAppCallQ, RPCError> {
|
||||
let message = reader.get_message().map_err(RPCError::protocol)?.to_vec();
|
||||
Ok(RPCOperationAppCallQ { message })
|
||||
}
|
||||
pub fn encode(
|
||||
&self,
|
||||
builder: &mut veilid_capnp::operation_app_call_q::Builder,
|
||||
) -> Result<(), RPCError> {
|
||||
builder.set_message(&self.message);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct RPCOperationAppCallA {
|
||||
pub message: Vec<u8>,
|
||||
}
|
||||
|
||||
impl RPCOperationAppCallA {
|
||||
pub fn decode(
|
||||
reader: &veilid_capnp::operation_app_call_a::Reader,
|
||||
) -> Result<RPCOperationAppCallA, RPCError> {
|
||||
let message = reader.get_message().map_err(RPCError::protocol)?.to_vec();
|
||||
Ok(RPCOperationAppCallA { message })
|
||||
}
|
||||
pub fn encode(
|
||||
&self,
|
||||
builder: &mut veilid_capnp::operation_app_call_a::Builder,
|
||||
) -> Result<(), RPCError> {
|
||||
builder.set_message(&self.message);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
use crate::*;
|
||||
use rpc_processor::*;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct RPCOperationAppMessage {
|
||||
pub message: Vec<u8>,
|
||||
}
|
||||
|
||||
impl RPCOperationAppMessage {
|
||||
pub fn decode(
|
||||
reader: &veilid_capnp::operation_app_message::Reader,
|
||||
) -> Result<RPCOperationAppMessage, RPCError> {
|
||||
let message = reader.get_message().map_err(RPCError::protocol)?.to_vec();
|
||||
Ok(RPCOperationAppMessage { message })
|
||||
}
|
||||
pub fn encode(
|
||||
&self,
|
||||
builder: &mut veilid_capnp::operation_app_message::Builder,
|
||||
) -> Result<(), RPCError> {
|
||||
builder.set_message(&self.message);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,7 @@ impl RPCQuestion {
|
||||
pub enum RPCQuestionDetail {
|
||||
StatusQ(RPCOperationStatusQ),
|
||||
FindNodeQ(RPCOperationFindNodeQ),
|
||||
AppCallQ(RPCOperationAppCallQ),
|
||||
GetValueQ(RPCOperationGetValueQ),
|
||||
SetValueQ(RPCOperationSetValueQ),
|
||||
WatchValueQ(RPCOperationWatchValueQ),
|
||||
@@ -55,6 +56,7 @@ impl RPCQuestionDetail {
|
||||
match self {
|
||||
RPCQuestionDetail::StatusQ(_) => "StatusQ",
|
||||
RPCQuestionDetail::FindNodeQ(_) => "FindNodeQ",
|
||||
RPCQuestionDetail::AppCallQ(_) => "AppCallQ",
|
||||
RPCQuestionDetail::GetValueQ(_) => "GetValueQ",
|
||||
RPCQuestionDetail::SetValueQ(_) => "SetValueQ",
|
||||
RPCQuestionDetail::WatchValueQ(_) => "WatchValueQ",
|
||||
@@ -81,6 +83,11 @@ impl RPCQuestionDetail {
|
||||
let out = RPCOperationFindNodeQ::decode(&op_reader)?;
|
||||
RPCQuestionDetail::FindNodeQ(out)
|
||||
}
|
||||
veilid_capnp::question::detail::Which::AppCallQ(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationAppCallQ::decode(&op_reader)?;
|
||||
RPCQuestionDetail::AppCallQ(out)
|
||||
}
|
||||
veilid_capnp::question::detail::GetValueQ(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationGetValueQ::decode(&op_reader)?;
|
||||
@@ -131,6 +138,7 @@ impl RPCQuestionDetail {
|
||||
match self {
|
||||
RPCQuestionDetail::StatusQ(d) => d.encode(&mut builder.reborrow().init_status_q()),
|
||||
RPCQuestionDetail::FindNodeQ(d) => d.encode(&mut builder.reborrow().init_find_node_q()),
|
||||
RPCQuestionDetail::AppCallQ(d) => d.encode(&mut builder.reborrow().init_app_call_q()),
|
||||
RPCQuestionDetail::GetValueQ(d) => d.encode(&mut builder.reborrow().init_get_value_q()),
|
||||
RPCQuestionDetail::SetValueQ(d) => d.encode(&mut builder.reborrow().init_set_value_q()),
|
||||
RPCQuestionDetail::WatchValueQ(d) => {
|
||||
|
||||
@@ -42,6 +42,7 @@ pub enum RPCStatementDetail {
|
||||
ValueChanged(RPCOperationValueChanged),
|
||||
Signal(RPCOperationSignal),
|
||||
ReturnReceipt(RPCOperationReturnReceipt),
|
||||
AppMessage(RPCOperationAppMessage),
|
||||
}
|
||||
|
||||
impl RPCStatementDetail {
|
||||
@@ -53,6 +54,7 @@ impl RPCStatementDetail {
|
||||
RPCStatementDetail::ValueChanged(_) => "ValueChanged",
|
||||
RPCStatementDetail::Signal(_) => "Signal",
|
||||
RPCStatementDetail::ReturnReceipt(_) => "ReturnReceipt",
|
||||
RPCStatementDetail::AppMessage(_) => "AppMessage",
|
||||
}
|
||||
}
|
||||
pub fn decode(
|
||||
@@ -91,6 +93,11 @@ impl RPCStatementDetail {
|
||||
let out = RPCOperationReturnReceipt::decode(&op_reader)?;
|
||||
RPCStatementDetail::ReturnReceipt(out)
|
||||
}
|
||||
veilid_capnp::statement::detail::AppMessage(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationAppMessage::decode(&op_reader)?;
|
||||
RPCStatementDetail::AppMessage(out)
|
||||
}
|
||||
};
|
||||
Ok(out)
|
||||
}
|
||||
@@ -113,6 +120,9 @@ impl RPCStatementDetail {
|
||||
RPCStatementDetail::ReturnReceipt(d) => {
|
||||
d.encode(&mut builder.reborrow().init_return_receipt())
|
||||
}
|
||||
RPCStatementDetail::AppMessage(d) => {
|
||||
d.encode(&mut builder.reborrow().init_app_message())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,80 +2,6 @@ use super::*;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RouteHopData {
|
||||
pub nonce: Nonce,
|
||||
pub blob: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RouteHop {
|
||||
pub dial_info: NodeDialInfo,
|
||||
pub next_hop: Option<RouteHopData>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct PrivateRoute {
|
||||
pub public_key: DHTKey,
|
||||
pub hop_count: u8,
|
||||
pub hops: Option<RouteHop>,
|
||||
}
|
||||
|
||||
impl PrivateRoute {
|
||||
pub fn new_stub(public_key: DHTKey) -> Self {
|
||||
Self {
|
||||
public_key,
|
||||
hop_count: 0,
|
||||
hops: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for PrivateRoute {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"PR({:?}+{}{})",
|
||||
self.public_key,
|
||||
self.hop_count,
|
||||
if let Some(hops) = &self.hops {
|
||||
format!("->{}", hops.dial_info)
|
||||
} else {
|
||||
"".to_owned()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum SafetyRouteHops {
|
||||
Data(RouteHopData),
|
||||
Private(PrivateRoute),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct SafetyRoute {
|
||||
pub public_key: DHTKey,
|
||||
pub hop_count: u8,
|
||||
pub hops: SafetyRouteHops,
|
||||
}
|
||||
|
||||
impl fmt::Display for SafetyRoute {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"SR({:?}+{}{})",
|
||||
self.public_key,
|
||||
self.hop_count,
|
||||
match &self.hops {
|
||||
SafetyRouteHops::Data(_) => "".to_owned(),
|
||||
SafetyRouteHops::Private(p) => format!("->{}", p),
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
pub fn encode_route_hop_data(
|
||||
route_hop_data: &RouteHopData,
|
||||
builder: &mut veilid_capnp::route_hop_data::Builder,
|
||||
|
||||
Reference in New Issue
Block a user