connlib: refactor names (#3104)

Applying suggestions for #3096 since it was merged before I could fix
This commit is contained in:
Gabi
2024-01-03 17:09:41 -03:00
committed by GitHub
parent 1251397651
commit 23666e119b
2 changed files with 10 additions and 10 deletions

View File

@@ -642,19 +642,19 @@ impl IpProvider {
}
}
pub fn get_ip_for(&mut self, ip: &IpAddr) -> Option<IpAddr> {
let ip = match ip {
pub fn get_proxy_ip_for(&mut self, ip: &IpAddr) -> Option<IpAddr> {
let proxy_ip = match ip {
IpAddr::V4(_) => self.ipv4.next().map(Into::into),
IpAddr::V6(_) => self.ipv6.next().map(Into::into),
};
if ip.is_none() {
if proxy_ip.is_none() {
// TODO: we might want to make the iterator cyclic or another strategy to prevent ip exhaustion
// this might happen in ipv4 if tokens are too long lived.
tracing::error!("IP exhaustion: Please reset your client");
}
ip
proxy_ip
}
}

View File

@@ -199,18 +199,18 @@ pub struct PacketTransformClient {
impl PacketTransformClient {
pub fn get_or_assign_translation(
&self,
external_ip: &IpAddr,
ip: &IpAddr,
ip_provider: &mut IpProvider,
) -> Option<IpAddr> {
let mut translations = self.translations.write();
if let Some(internal_ip) = translations.get_by_right(external_ip) {
return Some(*internal_ip);
if let Some(proxy_ip) = translations.get_by_right(ip) {
return Some(*proxy_ip);
}
let internal_ip = ip_provider.get_ip_for(external_ip)?;
let proxy_ip = ip_provider.get_proxy_ip_for(ip)?;
translations.insert(internal_ip, *external_ip);
Some(internal_ip)
translations.insert(proxy_ip, *ip);
Some(proxy_ip)
}
}