Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yana/frontend fixes #5341

Merged
merged 25 commits into from
Jan 14, 2025
Merged

Yana/frontend fixes #5341

merged 25 commits into from
Jan 14, 2025

Conversation

yanok87
Copy link
Contributor

@yanok87 yanok87 commented Jan 13, 2025

This change is Reviewable

@yanok87 yanok87 requested a review from fmtabbara January 13, 2025 14:27
Comment on lines 56 to 182
const entryScore = [can_connect, can_route].filter(Boolean).length;

if (!nodeDescription) {
return null;
if (entryScore === 2) {
return 4; // 4 stars if both are true
}
if (entryScore === 1) {
return 2; // 2 stars if one is true
}
return 1; // 1 star if both are false
}

const nodeRoles = getNodeRoles(nodeDescription.declared_role);
// Check if only as_exit exists and calculate stars
if (as_exit) {
const {
can_connect,
can_route_ip_external_v4,
can_route_ip_external_v6,
can_route_ip_v4,
can_route_ip_v6,
} = as_exit;

const exitScore = [
can_connect,
can_route_ip_external_v4,
can_route_ip_external_v6,
can_route_ip_v4,
can_route_ip_v6,
].filter(Boolean).length;

if (exitScore === 5) {
return 4; // 4 stars if all 5 are true
}
if (exitScore === 4) {
return 3; // 3 stars if 4 true, 1 false
}
if (exitScore === 3) {
return 2; // 2 stars if 3 true, 2 false
}
return 1; // 1 star if 2 true or less
}

// Default case if neither as_entry nor as_exit is present
return 0; // No stars
}

function calculateWireguardPerformance(probeResult: LastProbeResult): number {
const { wg, as_exit } = probeResult.outcome;

if (!wg) {
return 1; // Default to 1 star if Wireguard information is missing
}

// Calculate average ping performance
const pingPerformance =
(wg.ping_hosts_performance_v4 +
wg.ping_hosts_performance_v6 +
wg.ping_ips_performance_v4 +
wg.ping_ips_performance_v6) /
4;

// 4 stars: Can register, complete handshakes, resolve DNS, and ping performance > 0.75
if (
wg.can_register &&
wg.can_handshake_v4 &&
wg.can_handshake_v6 &&
wg.can_resolve_dns_v4 &&
wg.can_resolve_dns_v6 &&
pingPerformance > 0.75
) {
return 4;
}

// 3 stars: Can register, complete handshakes, resolve DNS, but ping performance <= 0.75
if (
wg.can_register &&
wg.can_handshake_v4 &&
wg.can_handshake_v6 &&
wg.can_resolve_dns_v4 &&
wg.can_resolve_dns_v6 &&
pingPerformance <= 0.75
) {
return 3;
}

// 2 stars: Can register, but handshake v4 or v6 is false
if (wg.can_register && (!wg.can_handshake_v4 || !wg.can_handshake_v6)) {
return 2;
}

// 1 star: If "as_exit" exists but cannot route ipv4 or ipv6
if (as_exit && (!as_exit.can_route_ip_v4 || !as_exit.can_route_ip_v6)) {
return 1;
}

// Default case: No matching conditions
return 1;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think switch statements would make this a bit easier to follow

Copy link

vercel bot commented Jan 14, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nym-next-explorer ✅ Ready (Inspect) Visit Preview 4 resolved Jan 14, 2025 3:12pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
docs-nextra ⬜️ Ignored (Inspect) Visit Preview 💬 Add feedback Jan 14, 2025 3:12pm

@yanok87 yanok87 merged commit f4a416c into feature/explorer_v2 Jan 14, 2025
6 checks passed
@yanok87 yanok87 deleted the yana/frontend-fixes branch January 14, 2025 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants