more clippy
This commit is contained in:
@@ -16,7 +16,7 @@ pub fn encode_node_info(
|
||||
.reborrow()
|
||||
.init_envelope_support(node_info.envelope_support().len() as u32);
|
||||
if let Some(s) = es_builder.as_slice() {
|
||||
s.clone_from_slice(&node_info.envelope_support());
|
||||
s.clone_from_slice(node_info.envelope_support());
|
||||
}
|
||||
|
||||
let mut cs_builder = builder
|
||||
@@ -100,7 +100,7 @@ pub fn decode_node_info(reader: &veilid_capnp::node_info::Reader) -> Result<Node
|
||||
if envelope_support.len() > MAX_ENVELOPE_VERSIONS {
|
||||
return Err(RPCError::protocol("too many envelope versions"));
|
||||
}
|
||||
if envelope_support.len() == 0 {
|
||||
if envelope_support.is_empty() {
|
||||
return Err(RPCError::protocol("no envelope versions"));
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ pub fn decode_node_info(reader: &veilid_capnp::node_info::Reader) -> Result<Node
|
||||
if crypto_support.len() > MAX_CRYPTO_KINDS {
|
||||
return Err(RPCError::protocol("too many crypto kinds"));
|
||||
}
|
||||
if crypto_support.len() == 0 {
|
||||
if crypto_support.is_empty() {
|
||||
return Err(RPCError::protocol("no crypto kinds"));
|
||||
}
|
||||
|
||||
|
||||
@@ -31,22 +31,22 @@ impl RPCAnswer {
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum RPCAnswerDetail {
|
||||
StatusA(RPCOperationStatusA),
|
||||
FindNodeA(RPCOperationFindNodeA),
|
||||
AppCallA(RPCOperationAppCallA),
|
||||
GetValueA(RPCOperationGetValueA),
|
||||
SetValueA(RPCOperationSetValueA),
|
||||
WatchValueA(RPCOperationWatchValueA),
|
||||
StatusA(Box<RPCOperationStatusA>),
|
||||
FindNodeA(Box<RPCOperationFindNodeA>),
|
||||
AppCallA(Box<RPCOperationAppCallA>),
|
||||
GetValueA(Box<RPCOperationGetValueA>),
|
||||
SetValueA(Box<RPCOperationSetValueA>),
|
||||
WatchValueA(Box<RPCOperationWatchValueA>),
|
||||
#[cfg(feature = "unstable-blockstore")]
|
||||
SupplyBlockA(RPCOperationSupplyBlockA),
|
||||
SupplyBlockA(Box<RPCOperationSupplyBlockA>),
|
||||
#[cfg(feature = "unstable-blockstore")]
|
||||
FindBlockA(RPCOperationFindBlockA),
|
||||
FindBlockA(Box<RPCOperationFindBlockA>),
|
||||
#[cfg(feature = "unstable-tunnels")]
|
||||
StartTunnelA(RPCOperationStartTunnelA),
|
||||
StartTunnelA(Box<RPCOperationStartTunnelA>),
|
||||
#[cfg(feature = "unstable-tunnels")]
|
||||
CompleteTunnelA(RPCOperationCompleteTunnelA),
|
||||
CompleteTunnelA(Box<RPCOperationCompleteTunnelA>),
|
||||
#[cfg(feature = "unstable-tunnels")]
|
||||
CancelTunnelA(RPCOperationCancelTunnelA),
|
||||
CancelTunnelA(Box<RPCOperationCancelTunnelA>),
|
||||
}
|
||||
|
||||
impl RPCAnswerDetail {
|
||||
@@ -98,62 +98,62 @@ impl RPCAnswerDetail {
|
||||
veilid_capnp::answer::detail::StatusA(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationStatusA::decode(&op_reader)?;
|
||||
RPCAnswerDetail::StatusA(out)
|
||||
RPCAnswerDetail::StatusA(Box::new(out))
|
||||
}
|
||||
veilid_capnp::answer::detail::FindNodeA(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationFindNodeA::decode(&op_reader)?;
|
||||
RPCAnswerDetail::FindNodeA(out)
|
||||
RPCAnswerDetail::FindNodeA(Box::new(out))
|
||||
}
|
||||
veilid_capnp::answer::detail::AppCallA(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationAppCallA::decode(&op_reader)?;
|
||||
RPCAnswerDetail::AppCallA(out)
|
||||
RPCAnswerDetail::AppCallA(Box::new(out))
|
||||
}
|
||||
veilid_capnp::answer::detail::GetValueA(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationGetValueA::decode(&op_reader)?;
|
||||
RPCAnswerDetail::GetValueA(out)
|
||||
RPCAnswerDetail::GetValueA(Box::new(out))
|
||||
}
|
||||
veilid_capnp::answer::detail::SetValueA(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationSetValueA::decode(&op_reader)?;
|
||||
RPCAnswerDetail::SetValueA(out)
|
||||
RPCAnswerDetail::SetValueA(Box::new(out))
|
||||
}
|
||||
veilid_capnp::answer::detail::WatchValueA(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationWatchValueA::decode(&op_reader)?;
|
||||
RPCAnswerDetail::WatchValueA(out)
|
||||
RPCAnswerDetail::WatchValueA(Box::new(out))
|
||||
}
|
||||
#[cfg(feature = "unstable-blockstore")]
|
||||
veilid_capnp::answer::detail::SupplyBlockA(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationSupplyBlockA::decode(&op_reader)?;
|
||||
RPCAnswerDetail::SupplyBlockA(out)
|
||||
RPCAnswerDetail::SupplyBlockA(Box::new(out))
|
||||
}
|
||||
#[cfg(feature = "unstable-blockstore")]
|
||||
veilid_capnp::answer::detail::FindBlockA(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationFindBlockA::decode(&op_reader)?;
|
||||
RPCAnswerDetail::FindBlockA(out)
|
||||
RPCAnswerDetail::FindBlockA(Box::new(out))
|
||||
}
|
||||
#[cfg(feature = "unstable-tunnels")]
|
||||
veilid_capnp::answer::detail::StartTunnelA(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationStartTunnelA::decode(&op_reader)?;
|
||||
RPCAnswerDetail::StartTunnelA(out)
|
||||
RPCAnswerDetail::StartTunnelA(Box::new(out))
|
||||
}
|
||||
#[cfg(feature = "unstable-tunnels")]
|
||||
veilid_capnp::answer::detail::CompleteTunnelA(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationCompleteTunnelA::decode(&op_reader)?;
|
||||
RPCAnswerDetail::CompleteTunnelA(out)
|
||||
RPCAnswerDetail::CompleteTunnelA(Box::new(out))
|
||||
}
|
||||
#[cfg(feature = "unstable-tunnels")]
|
||||
veilid_capnp::answer::detail::CancelTunnelA(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationCancelTunnelA::decode(&op_reader)?;
|
||||
RPCAnswerDetail::CancelTunnelA(out)
|
||||
RPCAnswerDetail::CancelTunnelA(Box::new(out))
|
||||
}
|
||||
};
|
||||
Ok(out)
|
||||
|
||||
@@ -2,9 +2,9 @@ use super::*;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum RPCOperationKind {
|
||||
Question(RPCQuestion),
|
||||
Statement(RPCStatement),
|
||||
Answer(RPCAnswer),
|
||||
Question(Box<RPCQuestion>),
|
||||
Statement(Box<RPCStatement>),
|
||||
Answer(Box<RPCAnswer>),
|
||||
}
|
||||
|
||||
impl RPCOperationKind {
|
||||
@@ -30,17 +30,17 @@ impl RPCOperationKind {
|
||||
veilid_capnp::operation::kind::Which::Question(r) => {
|
||||
let q_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCQuestion::decode(&q_reader)?;
|
||||
RPCOperationKind::Question(out)
|
||||
RPCOperationKind::Question(Box::new(out))
|
||||
}
|
||||
veilid_capnp::operation::kind::Which::Statement(r) => {
|
||||
let q_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCStatement::decode(&q_reader)?;
|
||||
RPCOperationKind::Statement(out)
|
||||
RPCOperationKind::Statement(Box::new(out))
|
||||
}
|
||||
veilid_capnp::operation::kind::Which::Answer(r) => {
|
||||
let q_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCAnswer::decode(&q_reader)?;
|
||||
RPCOperationKind::Answer(out)
|
||||
RPCOperationKind::Answer(Box::new(out))
|
||||
}
|
||||
};
|
||||
|
||||
@@ -73,7 +73,7 @@ impl RPCOperation {
|
||||
op_id: OperationId::new(get_random_u64()),
|
||||
opt_sender_peer_info: sender_peer_info.opt_sender_peer_info,
|
||||
target_node_info_ts: sender_peer_info.target_node_info_ts,
|
||||
kind: RPCOperationKind::Question(question),
|
||||
kind: RPCOperationKind::Question(Box::new(question)),
|
||||
}
|
||||
}
|
||||
pub fn new_statement(statement: RPCStatement, sender_peer_info: SenderPeerInfo) -> Self {
|
||||
@@ -81,7 +81,7 @@ impl RPCOperation {
|
||||
op_id: OperationId::new(get_random_u64()),
|
||||
opt_sender_peer_info: sender_peer_info.opt_sender_peer_info,
|
||||
target_node_info_ts: sender_peer_info.target_node_info_ts,
|
||||
kind: RPCOperationKind::Statement(statement),
|
||||
kind: RPCOperationKind::Statement(Box::new(statement)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ impl RPCOperation {
|
||||
op_id: request.op_id,
|
||||
opt_sender_peer_info: sender_peer_info.opt_sender_peer_info,
|
||||
target_node_info_ts: sender_peer_info.target_node_info_ts,
|
||||
kind: RPCOperationKind::Answer(answer),
|
||||
kind: RPCOperationKind::Answer(Box::new(answer)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ impl RPCOperation {
|
||||
builder.set_op_id(self.op_id.as_u64());
|
||||
if let Some(sender_peer_info) = &self.opt_sender_peer_info {
|
||||
let mut pi_builder = builder.reborrow().init_sender_peer_info();
|
||||
encode_peer_info(&sender_peer_info, &mut pi_builder)?;
|
||||
encode_peer_info(sender_peer_info, &mut pi_builder)?;
|
||||
}
|
||||
builder.set_target_node_info_ts(self.target_node_info_ts.as_u64());
|
||||
let mut k_builder = builder.reborrow().init_kind();
|
||||
|
||||
@@ -122,7 +122,7 @@ impl RPCOperationSetValueA {
|
||||
value: Option<SignedValueData>,
|
||||
peers: Vec<PeerInfo>,
|
||||
) -> Result<Self, RPCError> {
|
||||
if peers.len() as usize > MAX_SET_VALUE_A_PEERS_LEN {
|
||||
if peers.len() > MAX_SET_VALUE_A_PEERS_LEN {
|
||||
return Err(RPCError::protocol(
|
||||
"encoded SetValueA peers length too long",
|
||||
));
|
||||
|
||||
@@ -36,7 +36,7 @@ impl RPCOperationStatusQ {
|
||||
) -> Result<(), RPCError> {
|
||||
if let Some(ns) = &self.node_status {
|
||||
let mut ns_builder = builder.reborrow().init_node_status();
|
||||
encode_node_status(&ns, &mut ns_builder)?;
|
||||
encode_node_status(ns, &mut ns_builder)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -98,11 +98,11 @@ impl RPCOperationStatusA {
|
||||
) -> Result<(), RPCError> {
|
||||
if let Some(ns) = &self.node_status {
|
||||
let mut ns_builder = builder.reborrow().init_node_status();
|
||||
encode_node_status(&ns, &mut ns_builder)?;
|
||||
encode_node_status(ns, &mut ns_builder)?;
|
||||
}
|
||||
if let Some(si) = &self.sender_info {
|
||||
let mut si_builder = builder.reborrow().init_sender_info();
|
||||
encode_sender_info(&si, &mut si_builder)?;
|
||||
encode_sender_info(si, &mut si_builder)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ impl RPCOperationWatchValueQ {
|
||||
watcher: PublicKey,
|
||||
signature: Signature,
|
||||
) -> Result<Self, RPCError> {
|
||||
if subkeys.len() as usize > MAX_WATCH_VALUE_Q_SUBKEYS_LEN {
|
||||
if subkeys.len() > MAX_WATCH_VALUE_Q_SUBKEYS_LEN {
|
||||
return Err(RPCError::protocol("WatchValueQ subkeys length too long"));
|
||||
}
|
||||
Ok(Self {
|
||||
@@ -38,7 +38,7 @@ impl RPCOperationWatchValueQ {
|
||||
// signature covers: key, subkeys, expiration, count, using watcher key
|
||||
fn make_signature_data(&self) -> Vec<u8> {
|
||||
let mut sig_data =
|
||||
Vec::with_capacity(PUBLIC_KEY_LENGTH + 4 + (self.subkeys.len() as usize * 8) + 8 + 4);
|
||||
Vec::with_capacity(PUBLIC_KEY_LENGTH + 4 + (self.subkeys.len() * 8) + 8 + 4);
|
||||
sig_data.extend_from_slice(&self.key.kind.0);
|
||||
sig_data.extend_from_slice(&self.key.value.bytes);
|
||||
for sk in self.subkeys.ranges() {
|
||||
|
||||
@@ -43,22 +43,22 @@ impl RPCQuestion {
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum RPCQuestionDetail {
|
||||
StatusQ(RPCOperationStatusQ),
|
||||
FindNodeQ(RPCOperationFindNodeQ),
|
||||
AppCallQ(RPCOperationAppCallQ),
|
||||
GetValueQ(RPCOperationGetValueQ),
|
||||
SetValueQ(RPCOperationSetValueQ),
|
||||
WatchValueQ(RPCOperationWatchValueQ),
|
||||
StatusQ(Box<RPCOperationStatusQ>),
|
||||
FindNodeQ(Box<RPCOperationFindNodeQ>),
|
||||
AppCallQ(Box<RPCOperationAppCallQ>),
|
||||
GetValueQ(Box<RPCOperationGetValueQ>),
|
||||
SetValueQ(Box<RPCOperationSetValueQ>),
|
||||
WatchValueQ(Box<RPCOperationWatchValueQ>),
|
||||
#[cfg(feature = "unstable-blockstore")]
|
||||
SupplyBlockQ(RPCOperationSupplyBlockQ),
|
||||
SupplyBlockQ(Box<RPCOperationSupplyBlockQ>),
|
||||
#[cfg(feature = "unstable-blockstore")]
|
||||
FindBlockQ(RPCOperationFindBlockQ),
|
||||
FindBlockQ(Box<RPCOperationFindBlockQ>),
|
||||
#[cfg(feature = "unstable-tunnels")]
|
||||
StartTunnelQ(RPCOperationStartTunnelQ),
|
||||
StartTunnelQ(Box<RPCOperationStartTunnelQ>),
|
||||
#[cfg(feature = "unstable-tunnels")]
|
||||
CompleteTunnelQ(RPCOperationCompleteTunnelQ),
|
||||
CompleteTunnelQ(Box<RPCOperationCompleteTunnelQ>),
|
||||
#[cfg(feature = "unstable-tunnels")]
|
||||
CancelTunnelQ(RPCOperationCancelTunnelQ),
|
||||
CancelTunnelQ(Box<RPCOperationCancelTunnelQ>),
|
||||
}
|
||||
|
||||
impl RPCQuestionDetail {
|
||||
@@ -111,62 +111,62 @@ impl RPCQuestionDetail {
|
||||
veilid_capnp::question::detail::StatusQ(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationStatusQ::decode(&op_reader)?;
|
||||
RPCQuestionDetail::StatusQ(out)
|
||||
RPCQuestionDetail::StatusQ(Box::new(out))
|
||||
}
|
||||
veilid_capnp::question::detail::FindNodeQ(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationFindNodeQ::decode(&op_reader)?;
|
||||
RPCQuestionDetail::FindNodeQ(out)
|
||||
RPCQuestionDetail::FindNodeQ(Box::new(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)
|
||||
RPCQuestionDetail::AppCallQ(Box::new(out))
|
||||
}
|
||||
veilid_capnp::question::detail::GetValueQ(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationGetValueQ::decode(&op_reader)?;
|
||||
RPCQuestionDetail::GetValueQ(out)
|
||||
RPCQuestionDetail::GetValueQ(Box::new(out))
|
||||
}
|
||||
veilid_capnp::question::detail::SetValueQ(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationSetValueQ::decode(&op_reader)?;
|
||||
RPCQuestionDetail::SetValueQ(out)
|
||||
RPCQuestionDetail::SetValueQ(Box::new(out))
|
||||
}
|
||||
veilid_capnp::question::detail::WatchValueQ(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationWatchValueQ::decode(&op_reader)?;
|
||||
RPCQuestionDetail::WatchValueQ(out)
|
||||
RPCQuestionDetail::WatchValueQ(Box::new(out))
|
||||
}
|
||||
#[cfg(feature = "unstable-blockstore")]
|
||||
veilid_capnp::question::detail::SupplyBlockQ(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationSupplyBlockQ::decode(&op_reader)?;
|
||||
RPCQuestionDetail::SupplyBlockQ(out)
|
||||
RPCQuestionDetail::SupplyBlockQ(Box::new(out))
|
||||
}
|
||||
#[cfg(feature = "unstable-blockstore")]
|
||||
veilid_capnp::question::detail::FindBlockQ(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationFindBlockQ::decode(&op_reader)?;
|
||||
RPCQuestionDetail::FindBlockQ(out)
|
||||
RPCQuestionDetail::FindBlockQ(Box::new(out))
|
||||
}
|
||||
#[cfg(feature = "unstable-tunnels")]
|
||||
veilid_capnp::question::detail::StartTunnelQ(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationStartTunnelQ::decode(&op_reader)?;
|
||||
RPCQuestionDetail::StartTunnelQ(out)
|
||||
RPCQuestionDetail::StartTunnelQ(Box::new(out))
|
||||
}
|
||||
#[cfg(feature = "unstable-tunnels")]
|
||||
veilid_capnp::question::detail::CompleteTunnelQ(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationCompleteTunnelQ::decode(&op_reader)?;
|
||||
RPCQuestionDetail::CompleteTunnelQ(out)
|
||||
RPCQuestionDetail::CompleteTunnelQ(Box::new(out))
|
||||
}
|
||||
#[cfg(feature = "unstable-tunnels")]
|
||||
veilid_capnp::question::detail::CancelTunnelQ(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationCancelTunnelQ::decode(&op_reader)?;
|
||||
RPCQuestionDetail::CancelTunnelQ(out)
|
||||
RPCQuestionDetail::CancelTunnelQ(Box::new(out))
|
||||
}
|
||||
};
|
||||
Ok(out)
|
||||
|
||||
@@ -34,12 +34,12 @@ impl RPCStatement {
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum RPCStatementDetail {
|
||||
ValidateDialInfo(RPCOperationValidateDialInfo),
|
||||
Route(RPCOperationRoute),
|
||||
ValueChanged(RPCOperationValueChanged),
|
||||
Signal(RPCOperationSignal),
|
||||
ReturnReceipt(RPCOperationReturnReceipt),
|
||||
AppMessage(RPCOperationAppMessage),
|
||||
ValidateDialInfo(Box<RPCOperationValidateDialInfo>),
|
||||
Route(Box<RPCOperationRoute>),
|
||||
ValueChanged(Box<RPCOperationValueChanged>),
|
||||
Signal(Box<RPCOperationSignal>),
|
||||
ReturnReceipt(Box<RPCOperationReturnReceipt>),
|
||||
AppMessage(Box<RPCOperationAppMessage>),
|
||||
}
|
||||
|
||||
impl RPCStatementDetail {
|
||||
@@ -71,32 +71,32 @@ impl RPCStatementDetail {
|
||||
veilid_capnp::statement::detail::ValidateDialInfo(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationValidateDialInfo::decode(&op_reader)?;
|
||||
RPCStatementDetail::ValidateDialInfo(out)
|
||||
RPCStatementDetail::ValidateDialInfo(Box::new(out))
|
||||
}
|
||||
veilid_capnp::statement::detail::Route(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationRoute::decode(&op_reader)?;
|
||||
RPCStatementDetail::Route(out)
|
||||
RPCStatementDetail::Route(Box::new(out))
|
||||
}
|
||||
veilid_capnp::statement::detail::ValueChanged(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationValueChanged::decode(&op_reader)?;
|
||||
RPCStatementDetail::ValueChanged(out)
|
||||
RPCStatementDetail::ValueChanged(Box::new(out))
|
||||
}
|
||||
veilid_capnp::statement::detail::Signal(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationSignal::decode(&op_reader)?;
|
||||
RPCStatementDetail::Signal(out)
|
||||
RPCStatementDetail::Signal(Box::new(out))
|
||||
}
|
||||
veilid_capnp::statement::detail::ReturnReceipt(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationReturnReceipt::decode(&op_reader)?;
|
||||
RPCStatementDetail::ReturnReceipt(out)
|
||||
RPCStatementDetail::ReturnReceipt(Box::new(out))
|
||||
}
|
||||
veilid_capnp::statement::detail::AppMessage(r) => {
|
||||
let op_reader = r.map_err(RPCError::protocol)?;
|
||||
let out = RPCOperationAppMessage::decode(&op_reader)?;
|
||||
RPCStatementDetail::AppMessage(out)
|
||||
RPCStatementDetail::AppMessage(Box::new(out))
|
||||
}
|
||||
};
|
||||
Ok(out)
|
||||
|
||||
@@ -41,7 +41,7 @@ pub fn decode_peer_info(reader: &veilid_capnp::peer_info::Reader) -> Result<Peer
|
||||
node_ids.add(decode_typed_key(&nid_reader)?);
|
||||
}
|
||||
let signed_node_info = decode_signed_node_info(&sni_reader)?;
|
||||
if node_ids.len() == 0 {
|
||||
if node_ids.is_empty() {
|
||||
return Err(RPCError::protocol("no verified node ids"));
|
||||
}
|
||||
Ok(PeerInfo::new(node_ids, signed_node_info))
|
||||
|
||||
@@ -53,11 +53,11 @@ pub fn encode_route_hop(
|
||||
match &route_hop.node {
|
||||
RouteNode::NodeId(ni) => {
|
||||
let mut ni_builder = node_builder.init_node_id();
|
||||
encode_key256(&ni, &mut ni_builder);
|
||||
encode_key256(ni, &mut ni_builder);
|
||||
}
|
||||
RouteNode::PeerInfo(pi) => {
|
||||
let mut pi_builder = node_builder.init_peer_info();
|
||||
encode_peer_info(&pi, &mut pi_builder)?;
|
||||
encode_peer_info(pi, &mut pi_builder)?;
|
||||
}
|
||||
}
|
||||
if let Some(rhd) = &route_hop.next_hop {
|
||||
|
||||
@@ -361,9 +361,9 @@ impl RPCProcessor {
|
||||
if let Some(sender_noderef) = res {
|
||||
NetworkResult::value(Destination::relay(peer_noderef, sender_noderef))
|
||||
} else {
|
||||
return NetworkResult::invalid_message(
|
||||
NetworkResult::invalid_message(
|
||||
"not responding to sender that has no node info",
|
||||
);
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -371,9 +371,9 @@ impl RPCProcessor {
|
||||
match &request.header.detail {
|
||||
RPCMessageHeaderDetail::Direct(_) => {
|
||||
// If this was sent directly, we should only ever respond directly
|
||||
return NetworkResult::invalid_message(
|
||||
NetworkResult::invalid_message(
|
||||
"not responding to private route from direct question",
|
||||
);
|
||||
)
|
||||
}
|
||||
RPCMessageHeaderDetail::SafetyRouted(detail) => {
|
||||
// If this was sent via a safety route, but not received over our private route, don't respond with a safety route,
|
||||
@@ -387,7 +387,7 @@ impl RPCProcessor {
|
||||
// If this was received over our private route, it's okay to respond to a private route via our safety route
|
||||
NetworkResult::value(Destination::private_route(
|
||||
pr.clone(),
|
||||
SafetySelection::Safe(detail.safety_spec.clone()),
|
||||
SafetySelection::Safe(detail.safety_spec),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ where
|
||||
C: Fn(NodeRef) -> F,
|
||||
D: Fn(&[NodeRef]) -> Option<R>,
|
||||
{
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
routing_table: RoutingTable,
|
||||
node_id: TypedKey,
|
||||
@@ -103,7 +104,7 @@ where
|
||||
fn add_to_fanout_queue(self: Arc<Self>, new_nodes: &[NodeRef]) {
|
||||
let ctx = &mut *self.context.lock();
|
||||
let this = self.clone();
|
||||
ctx.fanout_queue.add(&new_nodes, |current_nodes| {
|
||||
ctx.fanout_queue.add(new_nodes, |current_nodes| {
|
||||
let mut current_nodes_vec = this
|
||||
.routing_table
|
||||
.sort_and_clean_closest_noderefs(this.node_id, current_nodes);
|
||||
@@ -180,8 +181,10 @@ where
|
||||
let entry = opt_entry.unwrap();
|
||||
|
||||
// Filter entries
|
||||
entry.with(rti, |_rti, e| {
|
||||
let Some(signed_node_info) = e.signed_node_info(RoutingDomain::PublicInternet) else {
|
||||
entry.with(rti, |_rti, e| {
|
||||
let Some(signed_node_info) =
|
||||
e.signed_node_info(RoutingDomain::PublicInternet)
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
// Ensure only things that are valid/signed in the PublicInternet domain are returned
|
||||
|
||||
@@ -447,7 +447,7 @@ impl RPCProcessor {
|
||||
capabilities: &[Capability],
|
||||
) -> bool {
|
||||
let routing_table = self.routing_table();
|
||||
routing_table.signed_node_info_is_valid_in_routing_domain(routing_domain, &signed_node_info)
|
||||
routing_table.signed_node_info_is_valid_in_routing_domain(routing_domain, signed_node_info)
|
||||
&& signed_node_info.node_info().has_capabilities(capabilities)
|
||||
}
|
||||
|
||||
@@ -684,7 +684,7 @@ impl RPCProcessor {
|
||||
let ssni_route =
|
||||
self.get_sender_peer_info(&Destination::direct(compiled_route.first_hop.clone()));
|
||||
let operation = RPCOperation::new_statement(
|
||||
RPCStatement::new(RPCStatementDetail::Route(route_operation)),
|
||||
RPCStatement::new(RPCStatementDetail::Route(Box::new(route_operation))),
|
||||
ssni_route,
|
||||
);
|
||||
|
||||
@@ -1021,6 +1021,7 @@ impl RPCProcessor {
|
||||
}
|
||||
|
||||
/// Record answer received from node or route
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn record_answer_received(
|
||||
&self,
|
||||
send_ts: Timestamp,
|
||||
@@ -1079,7 +1080,7 @@ impl RPCProcessor {
|
||||
|
||||
// If we sent to a private route without a safety route
|
||||
// We need to mark our own node info as having been seen so we can optimize sending it
|
||||
if let Err(e) = rss.mark_remote_private_route_seen_our_node_info(&rpr_pubkey, recv_ts) {
|
||||
if let Err(e) = rss.mark_remote_private_route_seen_our_node_info(rpr_pubkey, recv_ts) {
|
||||
log_rpc!(error "private route missing: {}", e);
|
||||
}
|
||||
|
||||
@@ -1116,7 +1117,6 @@ impl RPCProcessor {
|
||||
RPCMessageHeaderDetail::Direct(_) => {
|
||||
if let Some(sender_nr) = msg.opt_sender_nr.clone() {
|
||||
sender_nr.stats_question_rcvd(recv_ts, bytes);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Process messages that arrived with no private route (private route stub)
|
||||
|
||||
@@ -17,7 +17,7 @@ impl RPCProcessor {
|
||||
let app_call_q = RPCOperationAppCallQ::new(message)?;
|
||||
let question = RPCQuestion::new(
|
||||
network_result_try!(self.get_destination_respond_to(&dest)?),
|
||||
RPCQuestionDetail::AppCallQ(app_call_q),
|
||||
RPCQuestionDetail::AppCallQ(Box::new(app_call_q)),
|
||||
);
|
||||
|
||||
// Send the app call question
|
||||
@@ -117,8 +117,11 @@ impl RPCProcessor {
|
||||
let app_call_a = RPCOperationAppCallA::new(message_a)?;
|
||||
|
||||
// Send status answer
|
||||
self.answer(msg, RPCAnswer::new(RPCAnswerDetail::AppCallA(app_call_a)))
|
||||
.await
|
||||
self.answer(
|
||||
msg,
|
||||
RPCAnswer::new(RPCAnswerDetail::AppCallA(Box::new(app_call_a))),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Exposed to API for apps to return app call answers
|
||||
|
||||
@@ -13,7 +13,7 @@ impl RPCProcessor {
|
||||
message: Vec<u8>,
|
||||
) -> Result<NetworkResult<()>, RPCError> {
|
||||
let app_message = RPCOperationAppMessage::new(message)?;
|
||||
let statement = RPCStatement::new(RPCStatementDetail::AppMessage(app_message));
|
||||
let statement = RPCStatement::new(RPCStatementDetail::AppMessage(Box::new(app_message)));
|
||||
|
||||
// Send the app message request
|
||||
self.statement(dest, statement).await
|
||||
|
||||
@@ -38,7 +38,7 @@ impl RPCError {
|
||||
move |x| Self::Internal(format!("{}: {}", message.to_string(), x.to_string()))
|
||||
}
|
||||
pub fn else_internal<M: ToString>(message: M) -> impl FnOnce() -> Self {
|
||||
move || Self::Internal(format!("{}", message.to_string()))
|
||||
move || Self::Internal(message.to_string())
|
||||
}
|
||||
pub fn network<X: ToString>(x: X) -> Self {
|
||||
Self::Network(x.to_string())
|
||||
|
||||
@@ -30,8 +30,9 @@ impl RPCProcessor {
|
||||
));
|
||||
}
|
||||
|
||||
let find_node_q_detail =
|
||||
RPCQuestionDetail::FindNodeQ(RPCOperationFindNodeQ::new(node_id, capabilities.clone()));
|
||||
let find_node_q_detail = RPCQuestionDetail::FindNodeQ(Box::new(
|
||||
RPCOperationFindNodeQ::new(node_id, capabilities.clone()),
|
||||
));
|
||||
let find_node_q = RPCQuestion::new(
|
||||
network_result_try!(self.get_destination_respond_to(&dest)?),
|
||||
find_node_q_detail,
|
||||
@@ -111,7 +112,10 @@ impl RPCProcessor {
|
||||
let find_node_a = RPCOperationFindNodeA::new(closest_nodes)?;
|
||||
|
||||
// Send FindNode answer
|
||||
self.answer(msg, RPCAnswer::new(RPCAnswerDetail::FindNodeA(find_node_a)))
|
||||
.await
|
||||
self.answer(
|
||||
msg,
|
||||
RPCAnswer::new(RPCAnswerDetail::FindNodeA(Box::new(find_node_a))),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ impl RPCProcessor {
|
||||
let get_value_q = RPCOperationGetValueQ::new(key, subkey, last_descriptor.is_none());
|
||||
let question = RPCQuestion::new(
|
||||
network_result_try!(self.get_destination_respond_to(&dest)?),
|
||||
RPCQuestionDetail::GetValueQ(get_value_q),
|
||||
RPCQuestionDetail::GetValueQ(Box::new(get_value_q)),
|
||||
);
|
||||
|
||||
let question_context = QuestionContext::GetValue(ValidateGetValueContext {
|
||||
@@ -268,7 +268,7 @@ impl RPCProcessor {
|
||||
)?;
|
||||
|
||||
// Send GetValue answer
|
||||
self.answer(msg, RPCAnswer::new(RPCAnswerDetail::GetValueA(get_value_a)))
|
||||
self.answer(msg, RPCAnswer::new(RPCAnswerDetail::GetValueA(Box::new(get_value_a))))
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,8 @@ impl RPCProcessor {
|
||||
let receipt = receipt.as_ref().to_vec();
|
||||
|
||||
let return_receipt = RPCOperationReturnReceipt::new(receipt)?;
|
||||
let statement = RPCStatement::new(RPCStatementDetail::ReturnReceipt(return_receipt));
|
||||
let statement =
|
||||
RPCStatement::new(RPCStatementDetail::ReturnReceipt(Box::new(return_receipt)));
|
||||
|
||||
// Send the return_receipt request
|
||||
network_result_try!(self.statement(dest, statement).await?);
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
use super::*;
|
||||
|
||||
impl RPCProcessor {
|
||||
#[cfg_attr(feature="verbose-tracing", instrument(level = "trace", skip_all, err))]
|
||||
#[cfg_attr(
|
||||
feature = "verbose-tracing",
|
||||
instrument(level = "trace", skip_all, err)
|
||||
)]
|
||||
async fn process_route_safety_route_hop(
|
||||
&self,
|
||||
routed_operation: RoutedOperation,
|
||||
@@ -26,7 +29,10 @@ impl RPCProcessor {
|
||||
}
|
||||
|
||||
// Get next hop node ref
|
||||
let Some(mut next_hop_nr) = route_hop.node.node_ref(self.routing_table.clone(), safety_route.public_key.kind) else {
|
||||
let Some(mut next_hop_nr) = route_hop
|
||||
.node
|
||||
.node_ref(self.routing_table.clone(), safety_route.public_key.kind)
|
||||
else {
|
||||
return Err(RPCError::network(format!(
|
||||
"could not get route node hop ref: {}",
|
||||
route_hop.node.describe(safety_route.public_key.kind)
|
||||
@@ -45,14 +51,18 @@ impl RPCProcessor {
|
||||
},
|
||||
routed_operation,
|
||||
);
|
||||
let next_hop_route_stmt = RPCStatement::new(RPCStatementDetail::Route(next_hop_route));
|
||||
let next_hop_route_stmt =
|
||||
RPCStatement::new(RPCStatementDetail::Route(Box::new(next_hop_route)));
|
||||
|
||||
// Send the next route statement
|
||||
self.statement(Destination::direct(next_hop_nr), next_hop_route_stmt)
|
||||
.await
|
||||
}
|
||||
|
||||
#[cfg_attr(feature="verbose-tracing", instrument(level = "trace", skip_all, err))]
|
||||
#[cfg_attr(
|
||||
feature = "verbose-tracing",
|
||||
instrument(level = "trace", skip_all, err)
|
||||
)]
|
||||
async fn process_route_private_route_hop(
|
||||
&self,
|
||||
routed_operation: RoutedOperation,
|
||||
@@ -68,7 +78,9 @@ impl RPCProcessor {
|
||||
}
|
||||
|
||||
// Get next hop node ref
|
||||
let Some(mut next_hop_nr) = next_route_node.node_ref(self.routing_table.clone(), safety_route_public_key.kind) else {
|
||||
let Some(mut next_hop_nr) =
|
||||
next_route_node.node_ref(self.routing_table.clone(), safety_route_public_key.kind)
|
||||
else {
|
||||
return Err(RPCError::network(format!(
|
||||
"could not get route node hop ref: {}",
|
||||
next_route_node.describe(safety_route_public_key.kind)
|
||||
@@ -87,7 +99,8 @@ impl RPCProcessor {
|
||||
},
|
||||
routed_operation,
|
||||
);
|
||||
let next_hop_route_stmt = RPCStatement::new(RPCStatementDetail::Route(next_hop_route));
|
||||
let next_hop_route_stmt =
|
||||
RPCStatement::new(RPCStatementDetail::Route(Box::new(next_hop_route)));
|
||||
|
||||
// Send the next route statement
|
||||
self.statement(Destination::direct(next_hop_nr), next_hop_route_stmt)
|
||||
@@ -99,7 +112,10 @@ impl RPCProcessor {
|
||||
/// Note: it is important that we never respond with a safety route to questions that come
|
||||
/// in without a private route. Giving away a safety route when the node id is known is
|
||||
/// a privacy violation!
|
||||
#[cfg_attr(feature="verbose-tracing", instrument(level = "trace", skip_all, err))]
|
||||
#[cfg_attr(
|
||||
feature = "verbose-tracing",
|
||||
instrument(level = "trace", skip_all, err)
|
||||
)]
|
||||
fn process_safety_routed_operation(
|
||||
&self,
|
||||
detail: RPCMessageHeaderDetailDirect,
|
||||
@@ -111,7 +127,9 @@ impl RPCProcessor {
|
||||
// xxx: punish nodes that send messages that fail to decrypt eventually? How to do this for safety routes?
|
||||
let node_id_secret = self.routing_table.node_id_secret_key(remote_sr_pubkey.kind);
|
||||
let Ok(dh_secret) = vcrypto.cached_dh(&remote_sr_pubkey.value, &node_id_secret) else {
|
||||
return Ok(NetworkResult::invalid_message("dh failed for remote safety route for safety routed operation"));
|
||||
return Ok(NetworkResult::invalid_message(
|
||||
"dh failed for remote safety route for safety routed operation",
|
||||
));
|
||||
};
|
||||
let body = match vcrypto.decrypt_aead(
|
||||
routed_operation.data(),
|
||||
@@ -141,7 +159,10 @@ impl RPCProcessor {
|
||||
}
|
||||
|
||||
/// Process a routed operation that came in over both a safety route and a private route
|
||||
#[cfg_attr(feature="verbose-tracing", instrument(level = "trace", skip_all, err))]
|
||||
#[cfg_attr(
|
||||
feature = "verbose-tracing",
|
||||
instrument(level = "trace", skip_all, err)
|
||||
)]
|
||||
fn process_private_routed_operation(
|
||||
&self,
|
||||
detail: RPCMessageHeaderDetailDirect,
|
||||
@@ -152,49 +173,54 @@ impl RPCProcessor {
|
||||
) -> Result<NetworkResult<()>, RPCError> {
|
||||
// Get sender id of the peer with the crypto kind of the route
|
||||
let Some(sender_id) = detail.peer_noderef.node_ids().get(pr_pubkey.kind) else {
|
||||
return Ok(NetworkResult::invalid_message("route node doesnt have a required crypto kind for routed operation"));
|
||||
return Ok(NetworkResult::invalid_message(
|
||||
"route node doesnt have a required crypto kind for routed operation",
|
||||
));
|
||||
};
|
||||
|
||||
// Look up the private route and ensure it's one in our spec store
|
||||
// Ensure the route is validated, and construct a return safetyspec that matches the inbound preferences
|
||||
let rss = self.routing_table.route_spec_store();
|
||||
let preferred_route = rss.get_route_id_for_key(&pr_pubkey.value);
|
||||
let Some((secret_key, safety_spec)) = rss
|
||||
.with_signature_validated_route(
|
||||
&pr_pubkey,
|
||||
routed_operation.signatures(),
|
||||
routed_operation.data(),
|
||||
sender_id.value,
|
||||
|rssd, rsd| {
|
||||
(
|
||||
rsd.secret_key,
|
||||
SafetySpec {
|
||||
preferred_route,
|
||||
hop_count: rssd.hop_count(),
|
||||
stability: rssd.get_stability(),
|
||||
sequencing: routed_operation.sequencing(),
|
||||
},
|
||||
)
|
||||
}
|
||||
)
|
||||
else {
|
||||
return Ok(NetworkResult::invalid_message("signatures did not validate for private route"));
|
||||
};
|
||||
let Some((secret_key, safety_spec)) = rss.with_signature_validated_route(
|
||||
&pr_pubkey,
|
||||
routed_operation.signatures(),
|
||||
routed_operation.data(),
|
||||
sender_id.value,
|
||||
|rssd, rsd| {
|
||||
(
|
||||
rsd.secret_key,
|
||||
SafetySpec {
|
||||
preferred_route,
|
||||
hop_count: rssd.hop_count(),
|
||||
stability: rssd.get_stability(),
|
||||
sequencing: routed_operation.sequencing(),
|
||||
},
|
||||
)
|
||||
},
|
||||
) 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)
|
||||
// xxx: punish nodes that send messages that fail to decrypt eventually. How to do this for private routes?
|
||||
let Ok(dh_secret) = vcrypto.cached_dh(&remote_sr_pubkey.value, &secret_key) else {
|
||||
return Ok(NetworkResult::invalid_message("dh failed for remote safety route for private routed operation"));
|
||||
return Ok(NetworkResult::invalid_message(
|
||||
"dh failed for remote safety route for private routed operation",
|
||||
));
|
||||
};
|
||||
let Ok(body) = vcrypto.decrypt_aead(
|
||||
routed_operation.data(),
|
||||
routed_operation.nonce(),
|
||||
&dh_secret,
|
||||
None,
|
||||
) else {
|
||||
return Ok(NetworkResult::invalid_message(
|
||||
"decryption of routed operation failed",
|
||||
));
|
||||
};
|
||||
let Ok(body) = vcrypto
|
||||
.decrypt_aead(
|
||||
routed_operation.data(),
|
||||
routed_operation.nonce(),
|
||||
&dh_secret,
|
||||
None,
|
||||
) else {
|
||||
return Ok(NetworkResult::invalid_message("decryption of routed operation failed"));
|
||||
};
|
||||
|
||||
// Pass message to RPC system
|
||||
self.enqueue_private_routed_message(
|
||||
@@ -209,7 +235,10 @@ impl RPCProcessor {
|
||||
Ok(NetworkResult::value(()))
|
||||
}
|
||||
|
||||
#[cfg_attr(feature="verbose-tracing", instrument(level = "trace", skip_all, err))]
|
||||
#[cfg_attr(
|
||||
feature = "verbose-tracing",
|
||||
instrument(level = "trace", skip_all, err)
|
||||
)]
|
||||
fn process_routed_operation(
|
||||
&self,
|
||||
detail: RPCMessageHeaderDetailDirect,
|
||||
@@ -239,7 +268,10 @@ impl RPCProcessor {
|
||||
)
|
||||
}
|
||||
}
|
||||
#[cfg_attr(feature="verbose-tracing", instrument(level = "trace", skip_all, err))]
|
||||
#[cfg_attr(
|
||||
feature = "verbose-tracing",
|
||||
instrument(level = "trace", skip_all, err)
|
||||
)]
|
||||
pub(crate) async fn process_private_route_first_hop(
|
||||
&self,
|
||||
mut routed_operation: RoutedOperation,
|
||||
@@ -247,14 +279,18 @@ impl RPCProcessor {
|
||||
mut private_route: PrivateRoute,
|
||||
) -> Result<NetworkResult<()>, RPCError> {
|
||||
let Some(pr_first_hop) = private_route.pop_first_hop() else {
|
||||
return Ok(NetworkResult::invalid_message("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",
|
||||
));
|
||||
};
|
||||
|
||||
// Check for loopback test where private route is the same as safety route
|
||||
if sr_pubkey == private_route.public_key {
|
||||
// If so, we're going to turn this thing right around without transiting the network
|
||||
let PrivateRouteHops::Data(route_hop_data) = private_route.hops else {
|
||||
return Ok(NetworkResult::invalid_message("Loopback test requires hops"));
|
||||
return Ok(NetworkResult::invalid_message(
|
||||
"Loopback test requires hops",
|
||||
));
|
||||
};
|
||||
|
||||
// Decrypt route hop data
|
||||
@@ -282,7 +318,7 @@ impl RPCProcessor {
|
||||
hop_count: private_route.hop_count - 1,
|
||||
hops: route_hop
|
||||
.next_hop
|
||||
.map(|rhd| PrivateRouteHops::Data(rhd))
|
||||
.map(PrivateRouteHops::Data)
|
||||
.unwrap_or(PrivateRouteHops::Empty),
|
||||
},
|
||||
)
|
||||
@@ -342,9 +378,11 @@ impl RPCProcessor {
|
||||
.map_err(RPCError::protocol)?;
|
||||
decode_route_hop(&rh_reader)?
|
||||
};
|
||||
|
||||
|
||||
// Validate the RouteHop
|
||||
route_hop.validate(self.crypto.clone()).map_err(RPCError::protocol)?;
|
||||
route_hop
|
||||
.validate(self.crypto.clone())
|
||||
.map_err(RPCError::protocol)?;
|
||||
|
||||
// Sign the operation if this is not our last hop
|
||||
// as the last hop is already signed by the envelope
|
||||
@@ -360,7 +398,10 @@ impl RPCProcessor {
|
||||
Ok(NetworkResult::value(route_hop))
|
||||
}
|
||||
|
||||
#[cfg_attr(feature="verbose-tracing", instrument(level = "trace", skip(self), ret, err))]
|
||||
#[cfg_attr(
|
||||
feature = "verbose-tracing",
|
||||
instrument(level = "trace", skip(self), ret, err)
|
||||
)]
|
||||
pub(crate) async fn process_route(
|
||||
&self,
|
||||
msg: RPCMessage,
|
||||
@@ -374,16 +415,10 @@ impl RPCProcessor {
|
||||
}
|
||||
|
||||
let opi = routing_table.get_own_peer_info(msg.header.routing_domain());
|
||||
if !opi
|
||||
.signed_node_info()
|
||||
.node_info()
|
||||
.has_capability(CAP_ROUTE)
|
||||
{
|
||||
return Ok(NetworkResult::service_unavailable(
|
||||
"route is not available",
|
||||
));
|
||||
if !opi.signed_node_info().node_info().has_capability(CAP_ROUTE) {
|
||||
return Ok(NetworkResult::service_unavailable("route is not available"));
|
||||
}
|
||||
|
||||
|
||||
// Get header detail, must be direct and not inside a route itself
|
||||
let detail = match msg.header.detail {
|
||||
RPCMessageHeaderDetail::Direct(detail) => detail,
|
||||
@@ -395,7 +430,7 @@ impl RPCProcessor {
|
||||
};
|
||||
|
||||
// Get the statement
|
||||
let (_,_,_,kind) = msg.operation.destructure();
|
||||
let (_, _, _, kind) = msg.operation.destructure();
|
||||
let route = match kind {
|
||||
RPCOperationKind::Statement(s) => match s.destructure() {
|
||||
RPCStatementDetail::Route(s) => s,
|
||||
@@ -419,19 +454,22 @@ impl RPCProcessor {
|
||||
SafetyRouteHops::Data(ref route_hop_data) => {
|
||||
// Decrypt the blob with DEC(nonce, DH(the SR's public key, this hop's secret)
|
||||
let node_id_secret = self.routing_table.node_id_secret_key(crypto_kind);
|
||||
let Ok(dh_secret) = vcrypto
|
||||
.cached_dh(&safety_route.public_key.value, &node_id_secret) else {
|
||||
return Ok(NetworkResult::invalid_message("dh failed for safety route hop"));
|
||||
let Ok(dh_secret) =
|
||||
vcrypto.cached_dh(&safety_route.public_key.value, &node_id_secret)
|
||||
else {
|
||||
return Ok(NetworkResult::invalid_message(
|
||||
"dh failed for safety route hop",
|
||||
));
|
||||
};
|
||||
let Ok(mut dec_blob_data) = vcrypto
|
||||
.decrypt_aead(
|
||||
&route_hop_data.blob,
|
||||
&route_hop_data.nonce,
|
||||
&dh_secret,
|
||||
None,
|
||||
)
|
||||
else {
|
||||
return Ok(NetworkResult::invalid_message("failed to decrypt route hop data for safety route hop"));
|
||||
let Ok(mut dec_blob_data) = vcrypto.decrypt_aead(
|
||||
&route_hop_data.blob,
|
||||
&route_hop_data.nonce,
|
||||
&dh_secret,
|
||||
None,
|
||||
) else {
|
||||
return Ok(NetworkResult::invalid_message(
|
||||
"failed to decrypt route hop data for safety route hop",
|
||||
));
|
||||
};
|
||||
|
||||
// See if this is last hop in safety route, if so, we're decoding a PrivateRoute not a RouteHop
|
||||
@@ -440,26 +478,35 @@ impl RPCProcessor {
|
||||
};
|
||||
|
||||
let Ok(dec_blob_reader) = RPCMessageData::new(dec_blob_data).get_reader() else {
|
||||
return Ok(NetworkResult::invalid_message("Failed to decode RPCMessageData from blob"));
|
||||
return Ok(NetworkResult::invalid_message(
|
||||
"Failed to decode RPCMessageData from blob",
|
||||
));
|
||||
};
|
||||
|
||||
// Decode the blob appropriately
|
||||
if dec_blob_tag == 1 {
|
||||
// PrivateRoute
|
||||
let private_route = {
|
||||
let Ok(pr_reader) = dec_blob_reader
|
||||
.get_root::<veilid_capnp::private_route::Reader>() else {
|
||||
return Ok(NetworkResult::invalid_message("failed to get private route reader for blob"));
|
||||
let Ok(pr_reader) =
|
||||
dec_blob_reader.get_root::<veilid_capnp::private_route::Reader>()
|
||||
else {
|
||||
return Ok(NetworkResult::invalid_message(
|
||||
"failed to get private route reader for blob",
|
||||
));
|
||||
};
|
||||
let Ok(private_route) = decode_private_route(&pr_reader) else {
|
||||
return Ok(NetworkResult::invalid_message("failed to decode private route"));
|
||||
return Ok(NetworkResult::invalid_message(
|
||||
"failed to decode private route",
|
||||
));
|
||||
};
|
||||
private_route
|
||||
};
|
||||
|
||||
|
||||
// Validate the private route
|
||||
if let Err(_) = private_route.validate(self.crypto.clone()) {
|
||||
return Ok(NetworkResult::invalid_message("failed to validate private route"));
|
||||
if private_route.validate(self.crypto.clone()).is_err() {
|
||||
return Ok(NetworkResult::invalid_message(
|
||||
"failed to validate private route",
|
||||
));
|
||||
}
|
||||
|
||||
// Switching from full safety route to private route first hop
|
||||
@@ -474,19 +521,26 @@ impl RPCProcessor {
|
||||
} else if dec_blob_tag == 0 {
|
||||
// RouteHop
|
||||
let route_hop = {
|
||||
let Ok(rh_reader) = dec_blob_reader
|
||||
.get_root::<veilid_capnp::route_hop::Reader>() else {
|
||||
return Ok(NetworkResult::invalid_message("failed to get route hop reader for blob"));
|
||||
let Ok(rh_reader) =
|
||||
dec_blob_reader.get_root::<veilid_capnp::route_hop::Reader>()
|
||||
else {
|
||||
return Ok(NetworkResult::invalid_message(
|
||||
"failed to get route hop reader for blob",
|
||||
));
|
||||
};
|
||||
let Ok(route_hop) = decode_route_hop(&rh_reader) else {
|
||||
return Ok(NetworkResult::invalid_message("failed to decode route hop"));
|
||||
return Ok(NetworkResult::invalid_message(
|
||||
"failed to decode route hop",
|
||||
));
|
||||
};
|
||||
route_hop
|
||||
};
|
||||
|
||||
// Validate the route hop
|
||||
if let Err(_) = route_hop.validate(self.crypto.clone()) {
|
||||
return Ok(NetworkResult::invalid_message("failed to validate route hop"));
|
||||
if route_hop.validate(self.crypto.clone()).is_err() {
|
||||
return Ok(NetworkResult::invalid_message(
|
||||
"failed to validate route hop",
|
||||
));
|
||||
}
|
||||
|
||||
// Continue the full safety route with another hop
|
||||
@@ -543,7 +597,7 @@ impl RPCProcessor {
|
||||
hop_count: private_route.hop_count - 1,
|
||||
hops: route_hop
|
||||
.next_hop
|
||||
.map(|rhd| PrivateRouteHops::Data(rhd))
|
||||
.map(PrivateRouteHops::Data)
|
||||
.unwrap_or(PrivateRouteHops::Empty),
|
||||
},
|
||||
)
|
||||
|
||||
@@ -80,7 +80,7 @@ impl RPCProcessor {
|
||||
);
|
||||
let question = RPCQuestion::new(
|
||||
network_result_try!(self.get_destination_respond_to(&dest)?),
|
||||
RPCQuestionDetail::SetValueQ(set_value_q),
|
||||
RPCQuestionDetail::SetValueQ(Box::new(set_value_q)),
|
||||
);
|
||||
let question_context = QuestionContext::SetValue(ValidateSetValueContext {
|
||||
descriptor,
|
||||
@@ -292,7 +292,7 @@ impl RPCProcessor {
|
||||
let set_value_a = RPCOperationSetValueA::new(set, new_value, closer_to_key_peers)?;
|
||||
|
||||
// Send SetValue answer
|
||||
self.answer(msg, RPCAnswer::new(RPCAnswerDetail::SetValueA(set_value_a)))
|
||||
self.answer(msg, RPCAnswer::new(RPCAnswerDetail::SetValueA(Box::new(set_value_a))))
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ impl RPCProcessor {
|
||||
}
|
||||
|
||||
let signal = RPCOperationSignal::new(signal_info);
|
||||
let statement = RPCStatement::new(RPCStatementDetail::Signal(signal));
|
||||
let statement = RPCStatement::new(RPCStatementDetail::Signal(Box::new(signal)));
|
||||
|
||||
// Send the signal request
|
||||
self.statement(dest, statement).await
|
||||
|
||||
@@ -101,7 +101,7 @@ impl RPCProcessor {
|
||||
let status_q = RPCOperationStatusQ::new(node_status);
|
||||
let question = RPCQuestion::new(
|
||||
network_result_try!(self.get_destination_respond_to(&dest)?),
|
||||
RPCQuestionDetail::StatusQ(status_q),
|
||||
RPCQuestionDetail::StatusQ(Box::new(status_q)),
|
||||
);
|
||||
|
||||
let debug_string = format!("Status => {}", dest);
|
||||
@@ -249,7 +249,10 @@ impl RPCProcessor {
|
||||
let status_a = RPCOperationStatusA::new(node_status, sender_info);
|
||||
|
||||
// Send status answer
|
||||
self.answer(msg, RPCAnswer::new(RPCAnswerDetail::StatusA(status_a)))
|
||||
.await
|
||||
self.answer(
|
||||
msg,
|
||||
RPCAnswer::new(RPCAnswerDetail::StatusA(Box::new(status_a))),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,9 @@ impl RPCProcessor {
|
||||
.map_err(RPCError::internal)?;
|
||||
|
||||
let validate_dial_info = RPCOperationValidateDialInfo::new(dial_info, receipt, redirect)?;
|
||||
let statement = RPCStatement::new(RPCStatementDetail::ValidateDialInfo(validate_dial_info));
|
||||
let statement = RPCStatement::new(RPCStatementDetail::ValidateDialInfo(Box::new(
|
||||
validate_dial_info,
|
||||
)));
|
||||
|
||||
// Send the validate_dial_info request
|
||||
// This can only be sent directly, as relays can not validate dial info
|
||||
@@ -153,8 +155,9 @@ impl RPCProcessor {
|
||||
// Make a copy of the request, without the redirect flag
|
||||
let validate_dial_info =
|
||||
RPCOperationValidateDialInfo::new(dial_info.clone(), receipt.clone(), false)?;
|
||||
let statement =
|
||||
RPCStatement::new(RPCStatementDetail::ValidateDialInfo(validate_dial_info));
|
||||
let statement = RPCStatement::new(RPCStatementDetail::ValidateDialInfo(Box::new(
|
||||
validate_dial_info,
|
||||
)));
|
||||
|
||||
// Send the validate_dial_info request
|
||||
// This can only be sent directly, as relays can not validate dial info
|
||||
|
||||
Reference in New Issue
Block a user