This commit is contained in:
John Smith 2023-03-06 16:36:15 -05:00
parent 9ae16680c6
commit 5ae3cc0d72

View File

@ -547,7 +547,7 @@ impl RPCProcessor {
operation, operation,
}; };
let ssni_route = let ssni_route =
self.get_sender_peer_info(&Destination::direct(compiled_route.first_hop.clone()))?; self.get_sender_peer_info(&Destination::direct(compiled_route.first_hop.clone()));
let operation = RPCOperation::new_statement( let operation = RPCOperation::new_statement(
RPCStatement::new(RPCStatementDetail::Route(route_operation)), RPCStatement::new(RPCStatementDetail::Route(route_operation)),
ssni_route, ssni_route,
@ -704,15 +704,17 @@ impl RPCProcessor {
/// Get signed node info to package with RPC messages to improve /// Get signed node info to package with RPC messages to improve
/// routing table caching when it is okay to do so /// routing table caching when it is okay to do so
#[instrument(level = "trace", skip(self), ret, err)] /// Also check target's timestamp of our own node info, to see if we should send that
fn get_sender_peer_info(&self, dest: &Destination) -> Result<SenderPeerInfo, RPCError> { /// And send our timestamp of the target's node info so they can determine if they should update us on their next rpc
#[instrument(level = "trace", skip(self), ret)]
fn get_sender_peer_info(&self, dest: &Destination) -> SenderPeerInfo {
// Don't do this if the sender is to remain private // Don't do this if the sender is to remain private
// Otherwise we would be attaching the original sender's identity to the final destination, // Otherwise we would be attaching the original sender's identity to the final destination,
// thus defeating the purpose of the safety route entirely :P // thus defeating the purpose of the safety route entirely :P
match dest.get_safety_selection() { match dest.get_safety_selection() {
SafetySelection::Unsafe(_) => {} SafetySelection::Unsafe(_) => {}
SafetySelection::Safe(_) => { SafetySelection::Safe(_) => {
return Ok(SenderPeerInfo::default()); return SenderPeerInfo::default();
} }
} }
@ -732,13 +734,14 @@ impl RPCProcessor {
private_route: _, private_route: _,
safety_selection: _, safety_selection: _,
} => { } => {
return Ok(SenderPeerInfo::default()); return SenderPeerInfo::default();
} }
}; };
let Some(routing_domain) = target.best_routing_domain() else { let Some(routing_domain) = target.best_routing_domain() else {
// No routing domain for target? // No routing domain for target, no node info
return Err(RPCError::internal(format!("No routing domain for target: {}", target))); // Only a stale connection or no connection exists
return SenderPeerInfo::default();
}; };
// Get the target's node info timestamp // Get the target's node info timestamp
@ -746,7 +749,7 @@ impl RPCProcessor {
// Don't return our node info if it's not valid yet // Don't return our node info if it's not valid yet
let Some(own_peer_info) = routing_table.get_own_peer_info(routing_domain) else { let Some(own_peer_info) = routing_table.get_own_peer_info(routing_domain) else {
return Ok(SenderPeerInfo::new_no_peer_info(target_node_info_ts)); return SenderPeerInfo::new_no_peer_info(target_node_info_ts);
}; };
// Get our node info timestamp // Get our node info timestamp
@ -754,10 +757,10 @@ impl RPCProcessor {
// If the target has seen our node info already don't send it again // If the target has seen our node info already don't send it again
if target.has_seen_our_node_info_ts(routing_domain, our_node_info_ts) { if target.has_seen_our_node_info_ts(routing_domain, our_node_info_ts) {
return Ok(SenderPeerInfo::new_no_peer_info(target_node_info_ts)); return SenderPeerInfo::new_no_peer_info(target_node_info_ts);
} }
Ok(SenderPeerInfo::new(own_peer_info, target_node_info_ts)) SenderPeerInfo::new(own_peer_info, target_node_info_ts)
} }
/// Record failure to send to node or route /// Record failure to send to node or route
@ -1002,7 +1005,7 @@ impl RPCProcessor {
question: RPCQuestion, question: RPCQuestion,
) -> Result<NetworkResult<WaitableReply>, RPCError> { ) -> Result<NetworkResult<WaitableReply>, RPCError> {
// Get sender peer info if we should send that // Get sender peer info if we should send that
let spi = self.get_sender_peer_info(&dest)?; let spi = self.get_sender_peer_info(&dest);
// Wrap question in operation // Wrap question in operation
let operation = RPCOperation::new_question(question, spi); let operation = RPCOperation::new_question(question, spi);
@ -1077,7 +1080,7 @@ impl RPCProcessor {
statement: RPCStatement, statement: RPCStatement,
) -> Result<NetworkResult<()>, RPCError> { ) -> Result<NetworkResult<()>, RPCError> {
// Get sender peer info if we should send that // Get sender peer info if we should send that
let spi = self.get_sender_peer_info(&dest)?; let spi = self.get_sender_peer_info(&dest);
// Wrap statement in operation // Wrap statement in operation
let operation = RPCOperation::new_statement(statement, spi); let operation = RPCOperation::new_statement(statement, spi);
@ -1138,7 +1141,7 @@ impl RPCProcessor {
let dest = network_result_try!(self.get_respond_to_destination(&request)); let dest = network_result_try!(self.get_respond_to_destination(&request));
// Get sender signed node info if we should send that // Get sender signed node info if we should send that
let spi = self.get_sender_peer_info(&dest)?; let spi = self.get_sender_peer_info(&dest);
// Wrap answer in operation // Wrap answer in operation
let operation = RPCOperation::new_answer(&request.operation, answer, spi); let operation = RPCOperation::new_answer(&request.operation, answer, spi);