adjust routes
This commit is contained in:
@@ -14,6 +14,7 @@ mod peer_info;
|
||||
mod private_safety_route;
|
||||
mod protocol_type_set;
|
||||
mod sender_info;
|
||||
mod sequencing;
|
||||
mod signal_info;
|
||||
mod signed_direct_node_info;
|
||||
mod signed_node_info;
|
||||
@@ -39,6 +40,7 @@ pub use peer_info::*;
|
||||
pub use private_safety_route::*;
|
||||
pub use protocol_type_set::*;
|
||||
pub use sender_info::*;
|
||||
pub use sequencing::*;
|
||||
pub use signal_info::*;
|
||||
pub use signed_direct_node_info::*;
|
||||
pub use signed_node_info::*;
|
||||
|
@@ -3,15 +3,17 @@ use super::*;
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct RoutedOperation {
|
||||
pub version: u8,
|
||||
pub sequencing: Sequencing,
|
||||
pub signatures: Vec<DHTSignature>,
|
||||
pub nonce: Nonce,
|
||||
pub data: Vec<u8>,
|
||||
}
|
||||
|
||||
impl RoutedOperation {
|
||||
pub fn new(version: u8, nonce: Nonce, data: Vec<u8>) -> Self {
|
||||
pub fn new(version: u8, sequencing: Sequencing, nonce: Nonce, data: Vec<u8>) -> Self {
|
||||
Self {
|
||||
version,
|
||||
sequencing,
|
||||
signatures: Vec::new(),
|
||||
nonce,
|
||||
data,
|
||||
@@ -34,12 +36,14 @@ impl RoutedOperation {
|
||||
}
|
||||
|
||||
let version = reader.get_version();
|
||||
let sequencing = decode_sequencing(reader.get_sequencing().map_err(RPCError::protocol)?);
|
||||
let n_reader = reader.get_nonce().map_err(RPCError::protocol)?;
|
||||
let nonce = decode_nonce(&n_reader);
|
||||
let data = reader.get_data().map_err(RPCError::protocol)?.to_vec();
|
||||
|
||||
Ok(RoutedOperation {
|
||||
version,
|
||||
sequencing,
|
||||
signatures,
|
||||
nonce,
|
||||
data,
|
||||
@@ -51,6 +55,9 @@ impl RoutedOperation {
|
||||
builder: &mut veilid_capnp::routed_operation::Builder,
|
||||
) -> Result<(), RPCError> {
|
||||
builder.reborrow().set_version(self.version);
|
||||
builder
|
||||
.reborrow()
|
||||
.set_sequencing(encode_sequencing(self.sequencing));
|
||||
let mut sigs_builder = builder.reborrow().init_signatures(
|
||||
self.signatures
|
||||
.len()
|
||||
|
@@ -520,7 +520,12 @@ impl RPCProcessor {
|
||||
|
||||
// Make the routed operation
|
||||
// xxx: replace MAX_CRYPTO_VERSION with the version from the factory
|
||||
let operation = RoutedOperation::new(MAX_CRYPTO_VERSION, nonce, enc_msg_data);
|
||||
let operation = RoutedOperation::new(
|
||||
MAX_CRYPTO_VERSION,
|
||||
safety_selection.get_sequencing(),
|
||||
nonce,
|
||||
enc_msg_data,
|
||||
);
|
||||
|
||||
// Prepare route operation
|
||||
let sr_hop_count = compiled_route.safety_route.hop_count;
|
||||
|
@@ -121,6 +121,7 @@ where
|
||||
Ok(res
|
||||
.on_timeout(|| {
|
||||
log_rpc!(debug "op wait timed out: {}", handle.op_id);
|
||||
log_rpc!(debug "backtrace: {}", debug_backtrace());
|
||||
self.cancel_op_waiter(handle.op_id);
|
||||
})
|
||||
.map(|res| {
|
||||
|
@@ -26,7 +26,7 @@ impl RPCProcessor {
|
||||
}
|
||||
|
||||
// Get next hop node ref
|
||||
let next_hop_nr = match route_hop.node {
|
||||
let mut next_hop_nr = match route_hop.node {
|
||||
RouteNode::NodeId(id) => {
|
||||
//
|
||||
let Some(nr) = self.routing_table.lookup_node_ref(id.key) else {
|
||||
@@ -53,6 +53,9 @@ impl RPCProcessor {
|
||||
}
|
||||
};
|
||||
|
||||
// Apply sequencing preference
|
||||
next_hop_nr.set_sequencing(routed_operation.sequencing);
|
||||
|
||||
// Pass along the route
|
||||
let next_hop_route = RPCOperationRoute {
|
||||
safety_route: SafetyRoute {
|
||||
@@ -85,7 +88,7 @@ impl RPCProcessor {
|
||||
}
|
||||
|
||||
// Get next hop node ref
|
||||
let next_hop_nr = match &next_route_node {
|
||||
let mut next_hop_nr = match &next_route_node {
|
||||
RouteNode::NodeId(id) => {
|
||||
//
|
||||
self.routing_table
|
||||
@@ -110,6 +113,9 @@ impl RPCProcessor {
|
||||
}
|
||||
}?;
|
||||
|
||||
// Apply sequencing preference
|
||||
next_hop_nr.set_sequencing(routed_operation.sequencing);
|
||||
|
||||
// Pass along the route
|
||||
let next_hop_route = RPCOperationRoute {
|
||||
safety_route: SafetyRoute {
|
||||
@@ -134,20 +140,10 @@ impl RPCProcessor {
|
||||
#[instrument(level = "trace", skip_all, err)]
|
||||
fn process_safety_routed_operation(
|
||||
&self,
|
||||
detail: RPCMessageHeaderDetailDirect,
|
||||
_detail: RPCMessageHeaderDetailDirect,
|
||||
routed_operation: RoutedOperation,
|
||||
remote_sr_pubkey: DHTKey,
|
||||
) -> Result<NetworkResult<()>, RPCError> {
|
||||
// Get sequencing preference
|
||||
let sequencing = if detail
|
||||
.connection_descriptor
|
||||
.protocol_type()
|
||||
.is_connection_oriented()
|
||||
{
|
||||
Sequencing::EnsureOrdered
|
||||
} else {
|
||||
Sequencing::NoPreference
|
||||
};
|
||||
|
||||
// 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 safety routes?
|
||||
@@ -169,7 +165,7 @@ impl RPCProcessor {
|
||||
};
|
||||
|
||||
// Pass message to RPC system
|
||||
self.enqueue_safety_routed_message(remote_sr_pubkey, sequencing, body)
|
||||
self.enqueue_safety_routed_message(remote_sr_pubkey, routed_operation.sequencing, body)
|
||||
.map_err(RPCError::internal)?;
|
||||
|
||||
Ok(NetworkResult::value(()))
|
||||
@@ -188,18 +184,31 @@ impl RPCProcessor {
|
||||
let sender_id = detail.envelope.get_sender_id();
|
||||
|
||||
// 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 Some((secret_key, safety_spec)) = rss
|
||||
.validate_signatures(
|
||||
.with_signature_validated_route(
|
||||
&pr_pubkey,
|
||||
&routed_operation.signatures,
|
||||
&routed_operation.data,
|
||||
sender_id,
|
||||
|rsd| {
|
||||
(
|
||||
rsd.get_secret_key(),
|
||||
SafetySpec {
|
||||
preferred_route: Some(pr_pubkey),
|
||||
hop_count: rsd.hop_count(),
|
||||
stability: rsd.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 dh_secret = self
|
||||
@@ -231,7 +240,7 @@ impl RPCProcessor {
|
||||
remote_sr_pubkey: DHTKey,
|
||||
pr_pubkey: DHTKey,
|
||||
) -> Result<NetworkResult<()>, RPCError> {
|
||||
|
||||
|
||||
// If the private route public key is our node id, then this was sent via safety route to our node directly
|
||||
// so there will be no signatures to validate
|
||||
if pr_pubkey == self.routing_table.node_id() {
|
||||
|
Reference in New Issue
Block a user