reverse connect fix

This commit is contained in:
John Smith 2023-07-16 00:21:19 -04:00
parent 113fb82469
commit 823db3adf2
2 changed files with 17 additions and 14 deletions

View File

@ -676,7 +676,11 @@ impl NetworkManager {
// Process a received signal
#[instrument(level = "trace", skip(self), err)]
pub async fn handle_signal(&self, signal_info: SignalInfo) -> EyreResult<NetworkResult<()>> {
pub async fn handle_signal(
&self,
connection_descriptor: ConnectionDescriptor,
signal_info: SignalInfo,
) -> EyreResult<NetworkResult<()>> {
match signal_info {
SignalInfo::ReverseConnect { receipt, peer_info } => {
let routing_table = self.routing_table();
@ -697,6 +701,10 @@ impl NetworkManager {
}
};
// Restrict reverse connection to same protocol as inbound signal
let peer_nr = peer_nr
.filtered_clone(NodeRefFilter::from(connection_descriptor.protocol_type()));
// Make a reverse connection to the peer and send the receipt to it
rpc.rpc_call_return_receipt(Destination::direct(peer_nr), receipt)
.await
@ -1038,16 +1046,11 @@ impl NetworkManager {
};
if let Some(relay_nr) = some_relay_nr {
// Force sequencing if this came in sequenced.
// The sender did the prefer/ensure calculation when it did get_contact_method,
// so we don't need to do it here.
let relay_nr = if connection_descriptor.remote().protocol_type().is_ordered() {
let mut relay_nr = relay_nr.clone();
relay_nr.set_sequencing(Sequencing::EnsureOrdered);
relay_nr
} else {
relay_nr
};
// Ensure the protocol is forwarded exactly as is
// Address type is allowed to change if connectivity is better
let relay_nr = relay_nr.filtered_clone(
NodeRefFilter::new().with_protocol_type(connection_descriptor.protocol_type()),
);
// Relay the packet to the desired destination
log_net!("relaying {} bytes to {}", data.len(), relay_nr);

View File

@ -52,8 +52,8 @@ impl RPCProcessor {
// Can't allow anything other than direct packets here, as handling reverse connections
// or anything like via signals over private routes would deanonymize the route
match &msg.header.detail {
RPCMessageHeaderDetail::Direct(_) => {}
let connection_descriptor = match &msg.header.detail {
RPCMessageHeaderDetail::Direct(d) => d.connection_descriptor,
RPCMessageHeaderDetail::SafetyRouted(_) | RPCMessageHeaderDetail::PrivateRouted(_) => {
return Ok(NetworkResult::invalid_message("signal must be direct"));
}
@ -73,7 +73,7 @@ impl RPCProcessor {
let network_manager = self.network_manager();
let signal_info = signal.destructure();
network_manager
.handle_signal(signal_info)
.handle_signal(connection_descriptor, signal_info)
.await
.map_err(RPCError::network)
}