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

Lightweight ipaddr detection API #712

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions api/debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
ooni-api (1.0.70) unstable; urgency=medium

* Lightweight ipaddr detection API

-- Federico Ceratto <federico@debian.org> Fri, 22 Sep 2023 12:49:04 +0200

ooni-api (1.0.67) unstable; urgency=medium

* Support zstd compression for measurement uploads
Expand Down
41 changes: 41 additions & 0 deletions api/ooniapi/probe_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,47 @@ def probe_geoip(probe_cc: str, asn: str) -> Tuple[Dict, str, int]:
return resp, probe_cc, asn_int


@probe_services_blueprint.route("/api/_/discover_probe_ipaddr", methods=["GET"])
def discover_probe_ipaddr() -> Response:
"""Probe Services: discover probe ipaddr
---
responses:
'200':
description: Give a URL test list to a probe running web_connectivity
tests; additional data for other tests;
schema:
type: object
properties:
v:
type: integer
description: response format version
cc:
type: string
description: probe CC inferred from GeoIP or ZZ
asn:
type: string
description: probe ASN inferred from GeoIP or AS0
network_name:
type: string
description: probe network name inferred from GeoIP or None
"""
ipaddr = extract_probe_ipaddr()
cc = "ZZ"
asn = "AS0"
network_name = ""
try:
cc = lookup_probe_cc(ipaddr)
asn, network_name = lookup_probe_network(ipaddr)
metrics.incr("geoip_ipaddr_found")
except geoip2.errors.AddressNotFoundError:
metrics.incr("geoip_ipaddr_not_found")
except Exception as e:
log = current_app.logger
log.error(str(e), exc_info=True)

return nocachejson(v=1, ipaddr=ipaddr, cc=cc, asn=asn, network_name=network_name)


@probe_services_blueprint.route("/api/v1/check-in", methods=["POST"])
def check_in() -> Response:
"""Probe Services: check-in. Probes ask for tests to be run
Expand Down
Loading