Skip to content

Commit

Permalink
Add lightweight ipaddr lookup API
Browse files Browse the repository at this point in the history
  • Loading branch information
FedericoCeratto committed Aug 31, 2023
1 parent 6b7b4fc commit ec057f5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
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.67) unstable; urgency=medium

* Add lightweight ipaddr lookup API

-- Federico Ceratto <federico@debian.org> Thu, 31 Aug 2023 15:45:06 +0200

ooni-api (1.0.66) unstable; urgency=medium

* Add short description to incidents
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 @@ -116,6 +116,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

0 comments on commit ec057f5

Please sign in to comment.