route spec store work
This commit is contained in:
@@ -792,73 +792,6 @@ impl RPCProcessor {
|
||||
Ok(NetworkResult::value(()))
|
||||
}
|
||||
|
||||
// Convert the 'RespondTo' into a 'Destination' for a response
|
||||
fn get_respond_to_destination(&self, request: &RPCMessage) -> NetworkResult<Destination> {
|
||||
// Get the question 'respond to'
|
||||
let respond_to = match request.operation.kind() {
|
||||
RPCOperationKind::Question(q) => q.respond_to(),
|
||||
_ => {
|
||||
panic!("not a question");
|
||||
}
|
||||
};
|
||||
|
||||
// To where should we respond?
|
||||
match respond_to {
|
||||
RespondTo::Sender => {
|
||||
// Parse out the header detail from the question
|
||||
let detail = match &request.header.detail {
|
||||
RPCMessageHeaderDetail::Direct(detail) => detail,
|
||||
RPCMessageHeaderDetail::SafetyRouted(_)
|
||||
| RPCMessageHeaderDetail::PrivateRouted(_) => {
|
||||
// If this was sent via a private route, we don't know what the sender was, so drop this
|
||||
return NetworkResult::invalid_message(
|
||||
"can't respond directly to non-direct question",
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
// Reply directly to the request's source
|
||||
let sender_id = detail.envelope.get_sender_id();
|
||||
|
||||
// This may be a different node's reference than the 'sender' in the case of a relay
|
||||
let peer_noderef = detail.peer_noderef.clone();
|
||||
|
||||
// If the sender_id is that of the peer, then this is a direct reply
|
||||
// else it is a relayed reply through the peer
|
||||
if peer_noderef.node_id() == sender_id {
|
||||
NetworkResult::value(Destination::direct(peer_noderef))
|
||||
} else {
|
||||
NetworkResult::value(Destination::relay(peer_noderef, sender_id))
|
||||
}
|
||||
}
|
||||
RespondTo::PrivateRoute(pr) => {
|
||||
match &request.header.detail {
|
||||
RPCMessageHeaderDetail::Direct(_) => {
|
||||
// If this was sent directly, we should only ever respond directly
|
||||
return 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,
|
||||
// it would give away which safety routes belong to this node
|
||||
NetworkResult::value(Destination::private_route(
|
||||
pr.clone(),
|
||||
SafetySelection::Unsafe(detail.sequencing),
|
||||
))
|
||||
}
|
||||
RPCMessageHeaderDetail::PrivateRouted(detail) => {
|
||||
// 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()),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Issue a reply over the network, possibly using an anonymized route
|
||||
// The request must want a response, or this routine fails
|
||||
#[instrument(level = "debug", skip(self, request, answer), err)]
|
||||
|
||||
Reference in New Issue
Block a user