Skip to content

Commit

Permalink
fix: error.
Browse files Browse the repository at this point in the history
  • Loading branch information
BruceWind committed Sep 8, 2024
1 parent 7b84552 commit 20bec45
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,12 @@ async function main() {
for (const ipRnage of arrOfIPRanges) {
let netmask = new Netmask(ipRnage);

let ip = netmask.first;

netmask.forEach(async (ip) => {
ips.push(ip);
const ipstr = ip + '';
if (parseInt(ipstr.split('.')[3]) < 100) {
ips.push(ip);
// console.log('jump ' + ipstr);
}
})

}
Expand Down Expand Up @@ -184,7 +186,7 @@ async function queryLatency(ip) {
return result.alive ? Math.round(result.avg) : 1000;
}
catch (e) {
console.log(`${ip} is not reachable.`, e.message);
// console.log(`${ip} is not reachable.`, e.message);
}
return 1000;
}
Expand Down Expand Up @@ -221,7 +223,7 @@ async function queryTCPLatency(ip) {

return elapsed;
} catch (err) {
console.log(`TCP connection failed for ${ip}: ${err.message}`);
// console.log(`TCP connection failed for ${ip}: ${err.message}`);
return 1000;
}
}
Expand All @@ -231,16 +233,16 @@ async function queryAvgLatency(ip) {
try {
await queryTCPLatency(ip); // this line looks like useless, but In my opinion, this can make connection reliable.
const pingLatency = await queryLatency(ip);
if (pingLatency > THRESHOLD + 50) return latency1;
if (pingLatency > THRESHOLD + 50) return pingLatency;
const latency1 = await queryTCPLatency(ip);
if (latency1 > THRESHOLD + 50) return latency1;
const latency2 = await queryTCPLatency(ip);
if (latency2 > THRESHOLD + 50) return latency2;
if(latency1=== undefined || latency2 === undefined) throw new Error('latencies are undefined');
if (latency1 === undefined || latency2 === undefined) throw new Error('latencies are undefined');
const latency3 = await queryTCPLatency(ip);

const result = Math.round((latency1 + latency2) / 2);

return result;
}
catch (e) {
Expand Down

0 comments on commit 20bec45

Please sign in to comment.