Skip to content
Open
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
5 changes: 5 additions & 0 deletions ooniapi/common/src/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ class Settings(BaseSettings):
"" # filename of json containing Tor bridges and DirAuth endpoints
)

geoip_metadata_active: bool = Field(
default=False,
description="Activates extra metadata collection for geoip anomalies"
)

# Used to store history of all manifests and retrieve next manifest to use
anonc_manifest_bucket: str = Field(
default="CHANGEME",
Expand Down
13 changes: 10 additions & 3 deletions ooniapi/services/ooniprobe/src/ooniprobe/routers/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ..common.metrics import timer
from ..common.routers import BaseModel
from ..common.utils import setnocacheresponse
from ..common.dependencies import ClickhouseDep
from ..common.dependencies import ClickhouseDep, Settings
from ..dependencies import SettingsDep, ASNReaderDep, CCReaderDep, S3ClientDep
from ..utils import (
error,
Expand Down Expand Up @@ -198,6 +198,7 @@ async def receive_measurement(
asn=asn,
msmt_uid=msmt_uid,
data=data,
settings=settings
)
except Exception as e:
log.error(f"Error checking for geoip anomalies: {e}")
Expand Down Expand Up @@ -228,12 +229,18 @@ def _check_and_register_geoip_anomaly(
asn: str,
msmt_uid: str,
data: bytes,
settings: Settings
) -> None:
# check for geoip anomalies

actual_cc, actual_asn = get_cc_asn(request, cc_reader, asn_reader)
if actual_cc != cc or normalize_asn(actual_asn) != normalize_asn(asn):

# expensive: parses measurement body and sends anomaly to clickhouse
platform, software_name, software_version = _parse_metadata(data)
if settings.geoip_metadata_active:
platform, software_name, software_version = _parse_metadata(data)
else:
platform, software_name, software_version = "", "", ""

register_geoip_anomaly(
cc,
actual_cc,
Expand Down
1 change: 1 addition & 0 deletions ooniapi/services/ooniprobe/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def test_settings(
anonc_manifest_file="manifest.json",
anonc_secret_key=secret_key,
tor_targets="./tests/fixtures/data/tor-targets.json",
geoip_metadata_active=True
)


Expand Down