Skip to content

Add ISP and approximate IP location support - #53

Open
billmcilhargey wants to merge 8 commits into
librespeed:masterfrom
blackoutsecure:billmcilhargey-ip-location-support
Open

billmcilhargey wants to merge 8 commits into
librespeed:masterfrom
blackoutsecure:billmcilhargey-ip-location-support

Conversation

@billmcilhargey

@billmcilhargey billmcilhargey commented Nov 25, 2026 •

Copy link
Copy Markdown

Summary

  • Try unauthenticated ipinfo.io lookup when no API key is configured, retaining API-key support.
  • Populate rawIspInfo and a backward-compatible structured location object.
  • Improve ASN/country MMDB fallback and optional city MMDB support.

Verification

  • cargo test --quiet passes 12 tests.
  • Verified 128.94.2.134 API-first and MMDB fallback paths.

Context

Fixes librespeed/speedtest#881 for the Rust backend.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 25, 2026 21:45
@sudodios

Copy link
Copy Markdown
Collaborator

Hi @billmcilhargey
Thank you 🙏

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Legacy IP responses can cause result-image generation to panic because missing location metadata is sent as an empty string instead of an object or omitted field.

7 open issues
What changed in this PR

This PR extends the Rust backend’s ISP lookup with approximate IP-derived location metadata, addressing the backend portion of librespeed/speedtest#881 while preserving existing response fields.

Changes:

  • Adds unauthenticated IPinfo requests alongside API-key support and improves HTTP JSON response handling.
  • Expands MMDB fallback with configurable database paths, optional city data, and structured location metadata.
  • Preserves location data in worker status and telemetry, with supporting tests and documentation.
File Description
src/​ip/​mmdb/​mmdb_record.rs Normalizes country, ASN, and city database records.
src/​ip/​mmdb/​mmdb_reader.rs Adds city lookups, safer IP parsing, and a regression test.
src/​ip/​ip_info.rs Builds and merges API/MMDB ISP and location responses.
src/​http/​response.rs Updates test configuration for MMDB paths; otherwise formatting.
src/​http/​http_client.rs Revises response reading and adds chunked JSON decoding tests.
src/​config/​mod.rs Adds database path settings, defaults, aliases, and overrides.
src/​cmd.rs Exposes country/ASN and city database path options.
README.md Documents location metadata and lookup configuration.
configs.toml Adds database paths and explains keyless API behavior.
CHANGELOG.md Records the ISP and location enhancements.
assets/​speedtest_worker.js Carries location metadata into status and telemetry.

Review effort: Balanced

Comment thread assets/speedtest_worker.js Resolved
Comment thread src/ip/ip_info.rs Resolved
Comment thread src/ip/ip_info.rs Resolved
Comment thread src/ip/ip_info.rs Resolved
Comment thread src/ip/ip_info.rs Resolved
Comment thread src/ip/ip_info.rs Resolved
Comment thread src/ip/mmdb/mmdb_record.rs Resolved
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 25, 2026 22:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment thread src/ip/ip_info.rs Resolved
Comment thread src/ip/ip_info.rs Resolved
Comment thread src/ip/ip_info.rs Resolved
Comment thread src/ip/ip_info.rs Resolved
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 25, 2026 22:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Unchecked UTF-8 slicing of ASN values can panic and abort getIP requests, while continent merges can produce locations inconsistent with the retained country.

No open issues 🎉

3 previously missed issues

In code that hasn't changed since last review

High severity Non-ASCII ASN can panic during prefix slicing

src/​ip/​ip_info.rs:804

ASN strings are accepted from API/MMDB data without an ASCII restriction, but slicing asn[..2] panics when byte 2 is inside a UTF-8 character. For example, asn_codes_match("€", "AS8075") panics, aborting the getIP request during the offline merge. Use a checked prefix lookup so malformed ASN values can be handled without panicking.

Medium severity Continent fields ignore country compatibility

src/​ip/​ip_info.rs:423

The country-code guard protects the country name, but these continent fields are still copied when the providers disagree. For example, an API result with country US and a country MMDB result with country DE produces country: "US" alongside continent: "EU". Apply the same country compatibility check to both continent fields so the structured location remains consistent.

Medium severity Offline merge can pair country with wrong continent

src/​ip/​ip_info.rs:491

The offline-only path retains the city database's country but unconditionally assigns the country/ASN database's continent. If the city database reports DE and the country/ASN database reports US, this returns Germany with continent NA/North America. Only copy these fields when the source country is compatible with the retained country.

4 resolved since last review

Review effort: Balanced

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 25, 2026 23:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The IP-info opt-out still exposes ISP/location data through getIP responses and telemetry logs, while conflicting MMDB records can produce inconsistent country and continent values.

3 open issues

Review effort: Balanced

Comment thread src/ip/ip_info.rs Resolved
Comment thread src/ip/ip_info.rs Resolved
Comment thread src/results/stats.rs Resolved
@billmcilhargey

Copy link
Copy Markdown
Author

Ready for maintainer review.

All implementation and review follow-ups are complete: safe legacy telemetry, bounded keyless API lookup, reader caching, ASN/country matching, country/coordinate validation, MMDB bounds, and city/country fallback behavior. Build, 19 tests, Clippy, live API/MMDB checks, and diff validation pass. The PR remains open and mergeable and is linked to librespeed/speedtest#881.

@billmcilhargey

Copy link
Copy Markdown
Author

Final review fixes are complete and all currently unresolved review threads are resolved or addressed.

The PR remains open and mergeable, linked to librespeed/speedtest#881. Ready for maintainer review.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 02:09
@billmcilhargey

Copy link
Copy Markdown
Author

Final review follow-ups are complete.

  • All 14 review threads are resolved.
  • The latest head is 12c3445.
  • PR is open and mergeable.
  • Validation passes: cargo fmt --check, cargo check, 22 tests, strict Clippy, and git diff --check.
  • The disable_ipinfo path now behaves as IP-only, and normal lookup preserves ISP/location behavior.

Ready for maintainer review.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human assessment is needed because an unpublished finding shows that conflicting database results can produce inconsistent country and continent metadata.

No open issues 🎉

3 resolved since last review

Review effort: Balanced

@billmcilhargey

Copy link
Copy Markdown
Author

Latest-head audit complete at 12c3445. All 14 review threads are resolved, PR 53 remains open and mergeable, and the keyless/API-first, MMDB, country/continent, coordinate, legacy telemetry, and disable_ipinfo privacy behaviors are covered by focused regressions. Validation passes: cargo fmt --check, cargo check, cargo test --quiet (22 tests), cargo clippy --all-targets --all-features -- -D warnings, live API/MMDB opt-out checks, and git diff --check.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@billmcilhargey

Copy link
Copy Markdown
Author

@sudodios Latest head d5078f5 is ready for maintainer review. The Rust provider chain now resolves public IPs through cached local MMDB first, with private-IP bypass, keyed/keyless ipinfo supplement/fallback, a 5-second timeout, failure cooldown, and disable_ipinfo IP-only behavior. The getIP wire shape preserves processedString/rawIspInfo and adds validated countryName/location metadata while guarding country/continent and coordinate conflicts. Privacy handling now removes ISP/location/log data for opt-out and historical rendering. Validation passes: cargo fmt --check, cargo check, cargo test --quiet (23 tests), cargo clippy --all-targets --all-features -- -D warnings, git diff --check, plus live public/private/disable/invalid-key checks. All 14 inline threads are resolved; PR 53 remains open and mergeable. Cross-repo work is tracked in librespeed/speedtest-go PR 96 and linked issue 881.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Address-specific misses, including successful bogon responses, trigger a global 30-second IPinfo cooldown that unnecessarily blocks lookups for unrelated public clients.

1 open issue

Review effort: Balanced

Comment thread src/ip/ip_info.rs Resolved
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 04:12
@billmcilhargey

Copy link
Copy Markdown
Author

@sudodios Latest head 3ab12db is ready for maintainer review. The latest audit finding is fixed: successful bogon/empty ipinfo responses no longer trigger the global provider cooldown; only transport/status/timeout failures do. Live 100.64.0.1 bogon checks were repeated with no cooldown side effect. Validation passes: cargo fmt --check, cargo check, cargo test --quiet (24 tests), cargo clippy --all-targets --all-features -- -D warnings, git diff --check, plus live public/private/disable/invalid-key/bogon checks. All review threads are resolved. PR 53 remains open and mergeable.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The cooldown tests share global state and can run concurrently, causing sporadic failures unless both complete test sequences are serialized with the same test-only mutex.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread src/ip/ip_info.rs Resolved
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 04:37
@billmcilhargey

Copy link
Copy Markdown
Author

@billmcilhargey Latest Rust backend head 71043d2 is ready for re-review. Global cooldown tests are serialized across setup/assertion/cleanup so they cannot interfere with each other; 24 tests plus check/strict Clippy pass. PR remains open and mergeable.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human assessment is needed because an unpublished finding indicates the offline fallback can return inconsistent country and continent metadata when its databases disagree.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@billmcilhargey

Copy link
Copy Markdown
Author

@sudodios Fresh latest-head audit complete at 71043d2. All 16 inline review threads are resolved, PR 53 remains open and mergeable, and no concrete unresolved comment or CI/status item remains. The provider policy is MMDB-first with private-IP bypass, keyed/keyless ipinfo supplement/fallback, timeout/cooldown controls, bogon handling, and disable_ipinfo IP-only behavior. The response shape preserves processedString/rawIspInfo and validated countryName/location metadata; continent/country and coordinate conflicts are guarded. Validation passes: cargo fmt --check, cargo check, cargo test --quiet (24 tests), cargo clippy --all-targets --all-features -- -D warnings, git diff --check, plus live public/private/disable/invalid-key/bogon checks. Cross-repo: linked Go PR 96 and issue 881 remain open; PR 96 inline threads are resolved, with Maddie’s formal CHANGES_REQUESTED review still pending latest-head re-review.

@billmcilhargey

Copy link
Copy Markdown
Author

@billmcilhargey Latest Rust backend head 71043d2 passed cargo fmt/check/test/Clippy with serialized cooldown tests. Remaining inline thread is resolved and the PR remains open and mergeable.

@billmcilhargey

Copy link
Copy Markdown
Author

@sudodios Latest fresh audit complete on head 71043d2. All 16 inline threads are resolved and no unresolved human/comment/CI finding remains. PR 53 remains open and mergeable. Validation passes: cargo fmt --check, cargo check, cargo test --quiet (24 tests), cargo clippy --all-targets --all-features -- -D warnings, git diff --check, plus live public/private/disable/invalid-key/bogon checks. The linked Go PR 96 currently remains CHANGES_REQUESTED and conflicting with upstream master; that follow-up PR’s inline threads are resolved but Maddie’s formal re-review and conflict resolution are still pending.

@billmcilhargey

Copy link
Copy Markdown
Author

@sudodios Fresh latest-head re-audit complete at 71043d2. No concrete unresolved Rust finding, inline thread, formal review concern, or CI/status item remains: all 16 inline threads are resolved and PR 53 remains open/mergeable. Validation passes: cargo fmt --check, cargo check, cargo test --quiet (24 tests), cargo clippy --all-targets --all-features -- -D warnings, git diff --check, plus public/private/disable/bogon/invalid-key live checks. Cross-repo linked Go PR 96 is currently CONFLICTING and Maddie’s formal CHANGES_REQUESTED remains pending latest-head re-review; issue 881 remains open.

@billmcilhargey

Copy link
Copy Markdown
Author

Latest-head status: Rust backend PR 53 is open and mergeable at 71043d2, with 0 unresolved review threads. No merge or close.

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.

Display ISP, approximate city/region/country and coordinates from IP metadata

3 participants