Allow IPR reconnect to session (#5562)
This commit is contained in:
@@ -59,23 +59,24 @@ impl ConnectedClients {
|
||||
.any(|client| client.client_id == *client_id)
|
||||
}
|
||||
|
||||
//fn lookup_ip_from_client_id(&self, client_id: &ConnectedClientId) -> Option<IpPair> {
|
||||
// self.clients_ipv4_mapping
|
||||
// .iter()
|
||||
// .find_map(|(ipv4, connected_client)| {
|
||||
// if connected_client.client_id == *client_id {
|
||||
// Some(IpPair::new(*ipv4, connected_client.ipv6))
|
||||
// } else {
|
||||
// None
|
||||
// }
|
||||
// })
|
||||
//}
|
||||
//
|
||||
//fn lookup_client(&self, client_id: &ConnectedClientId) -> Option<&ConnectedClient> {
|
||||
// self.clients_ipv4_mapping
|
||||
// .values()
|
||||
// .find(|connected_client| connected_client.client_id == *client_id)
|
||||
//}
|
||||
pub(crate) fn lookup_ip_from_client_id(&self, client_id: &ConnectedClientId) -> Option<IpPair> {
|
||||
self.clients_ipv4_mapping
|
||||
.iter()
|
||||
.find_map(|(ipv4, connected_client)| {
|
||||
if connected_client.client_id == *client_id {
|
||||
Some(IpPair::new(*ipv4, connected_client.ipv6))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
fn lookup_client(&self, client_id: &ConnectedClientId) -> Option<&ConnectedClient> {
|
||||
self.clients_ipv4_mapping
|
||||
.values()
|
||||
.find(|connected_client| connected_client.client_id == *client_id)
|
||||
}
|
||||
|
||||
pub(crate) fn connect(
|
||||
&mut self,
|
||||
|
||||
@@ -90,9 +90,6 @@ pub(crate) struct DynamicConnectSuccess {
|
||||
|
||||
#[derive(Clone, Debug, thiserror::Error)]
|
||||
pub(crate) enum DynamicConnectFailureReason {
|
||||
#[error("client already connected")]
|
||||
ClientAlreadyConnected,
|
||||
|
||||
#[error("no available ip address")]
|
||||
NoAvailableIp,
|
||||
|
||||
|
||||
@@ -119,9 +119,6 @@ impl From<DynamicConnectResponse> for DynamicConnectResponseReplyV6 {
|
||||
impl From<DynamicConnectFailureReason> for DynamicConnectFailureReasonV6 {
|
||||
fn from(reason: DynamicConnectFailureReason) -> Self {
|
||||
match reason {
|
||||
DynamicConnectFailureReason::ClientAlreadyConnected => {
|
||||
DynamicConnectFailureReasonV6::RequestedNymAddressAlreadyInUse
|
||||
}
|
||||
DynamicConnectFailureReason::NoAvailableIp => {
|
||||
DynamicConnectFailureReasonV6::NoAvailableIp
|
||||
}
|
||||
|
||||
@@ -119,9 +119,6 @@ impl From<DynamicConnectResponse> for DynamicConnectResponseReplyV7 {
|
||||
impl From<DynamicConnectFailureReason> for DynamicConnectFailureReasonV7 {
|
||||
fn from(reason: DynamicConnectFailureReason) -> Self {
|
||||
match reason {
|
||||
DynamicConnectFailureReason::ClientAlreadyConnected => {
|
||||
DynamicConnectFailureReasonV7::RequestedNymAddressAlreadyInUse
|
||||
}
|
||||
DynamicConnectFailureReason::NoAvailableIp => {
|
||||
DynamicConnectFailureReasonV7::NoAvailableIp
|
||||
}
|
||||
|
||||
@@ -82,9 +82,6 @@ impl From<DynamicConnectResponse> for ConnectResponseReplyV8 {
|
||||
impl From<DynamicConnectFailureReason> for ConnectFailureReasonV8 {
|
||||
fn from(reason: DynamicConnectFailureReason) -> Self {
|
||||
match reason {
|
||||
DynamicConnectFailureReason::ClientAlreadyConnected => {
|
||||
ConnectFailureReasonV8::ClientAlreadyConnected
|
||||
}
|
||||
DynamicConnectFailureReason::NoAvailableIp => ConnectFailureReasonV8::NoAvailableIp,
|
||||
DynamicConnectFailureReason::Other(err) => ConnectFailureReasonV8::Other(err),
|
||||
}
|
||||
|
||||
@@ -242,13 +242,14 @@ impl MixnetListener {
|
||||
.map(Duration::from_millis)
|
||||
.unwrap_or(nym_ip_packet_requests::codec::BUFFER_TIMEOUT);
|
||||
|
||||
if self.connected_clients.is_client_connected(&reply_to) {
|
||||
if let Some(ips) = self.connected_clients.lookup_ip_from_client_id(&reply_to) {
|
||||
log::debug!("Reconnecting to the previous session");
|
||||
return Ok(Some(VersionedResponse {
|
||||
version,
|
||||
reply_to,
|
||||
response: Response::DynamicConnect {
|
||||
request_id,
|
||||
reply: DynamicConnectFailureReason::ClientAlreadyConnected.into(),
|
||||
reply: DynamicConnectSuccess { ips }.into(),
|
||||
},
|
||||
}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user