Skip to content

Commit

Permalink
Merge branch 'master' into sync-hw-firmware
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-yarmosh committed Jan 23, 2025
2 parents 8631e78 + 5049b89 commit 47f379b
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/lib/alt-ips.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,40 +144,42 @@ export class AltIps {
/**
* @returns was alt IP added.
*/
private async addAltIp (localSocket: ServerSocket, ip: string): Promise<boolean> {
if (localSocket.data.probe.altIpAddresses.includes(ip)) {
logger.info('Alt IP already in the list.', { ip });
private async addAltIp (localSocket: ServerSocket, altIp: string): Promise<boolean> {
const probeInfo = { probeIp: localSocket.data.probe.ipAddress, probeLocation: localSocket.data.probe.location };

if (localSocket.data.probe.altIpAddresses.includes(altIp)) {
logger.info('Alt IP already in the list.', { altIp });
return true;
}

if (isIpPrivate(ip)) {
logger.warn('Alt IP is private.', { ip });
if (isIpPrivate(altIp)) {
logger.warn('Alt IP is private.', { altIp });
return false;
}

try {
const altIpInfo = await this.geoIpClient.lookup(ip);
const altIpInfo = await this.geoIpClient.lookup(altIp);

if (altIpInfo.country !== localSocket.data.probe.location.country) {
logger.warn('Alt IP country doesn\'t match the probe country.', { ip, altIpInfo, probeLocation: localSocket.data.probe.location });
logger.warn('Alt IP country doesn\'t match the probe country.', { altIp, altIpInfo, ...probeInfo });
return false;
}

if (altIpInfo.isAnycast) {
logger.warn('Alt IP is anycast.', { ip, altIpInfo });
logger.warn('Alt IP is anycast.', { altIp, altIpInfo, ...probeInfo });
return false;
}
} catch (e) {
if (e instanceof ProbeError) {
logger.warn('Failed to add an alt IP.', e, { ip });
logger.warn('Failed to add an alt IP.', e, { altIp, ...probeInfo });
} else {
logger.error('Failed to add an alt IP.', e, { ip });
logger.error('Failed to add an alt IP.', e, { altIp, ...probeInfo });
}

return false;
}

localSocket.data.probe.altIpAddresses.push(ip);
localSocket.data.probe.altIpAddresses.push(altIp);
return true;
}

Expand Down

0 comments on commit 47f379b

Please sign in to comment.