This document describes the integration of the Onionoo project with the Anyone-Protocol API service for geo IP data lookups.
The Onionoo project has been updated to fetch geolocation data from the Anyone-Protocol API service instead of relying solely on local geo IP files. This provides more accurate and up-to-date geolocation information for relay fingerprints.
- File:
src/main/java/org/torproject/metrics/onionoo/updater/ApiGeoLocationService.java - Purpose: Handles communication with the Anyone-Protocol API service to fetch fingerprint-based geolocation data
- Features:
- Fetches data from
/fingerprint-map/endpoint - Caches data for 1 hour to reduce API calls
- Provides statistics on cache usage
- Fetches data from
- File:
src/main/java/org/torproject/metrics/onionoo/updater/LookupService.java - Changes:
- Added constructor parameter for API service URL
- New method
lookupByFingerprint()for API-based lookups - Added
updateGeolocationData()method to refresh API cache - Enhanced statistics to include API lookup metrics
- Maintains backward compatibility with file-based lookups
- File:
src/main/java/org/torproject/metrics/onionoo/updater/StatusUpdateRunner.java - Changes:
- Reads
API_SERVICE_URLenvironment variable orapi.service.urlsystem property - Passes API URL to LookupService constructor
- Added
updateGeolocationData()method to trigger API cache refresh
- Reads
- File:
src/main/java/org/torproject/metrics/onionoo/updater/NodeDetailsStatusUpdater.java - Changes:
- Modified
lookUpCitiesAndASes()to try fingerprint-based lookups first - Falls back to IP-based lookups for fingerprints not found via API
- Improved logging to show lookup statistics
- Modified
- File:
src/main/java/org/torproject/metrics/onionoo/cron/Main.java - Changes:
- Added geolocation data update as part of the regular update cycle
- API cache is refreshed before processing descriptors
Set the API_SERVICE_URL environment variable to point to your Anyone-Protocol API service:
export API_SERVICE_URL="https://api.ec.anyone.tech"Alternatively, you can use a system property:
java -Dapi.service.url="https://api.ec.anyone.tech" -jar onionoo.jarThe deployment files have been updated to automatically discover and configure the API service URL:
- Live:
operations/deploy-live.hcl- Uses service discovery forapi-service-live - Stage:
operations/deploy-stage.hcl- Uses service discovery forapi-service-stage - Docker:
docker/docker-compose.yml- Useshost.docker.internal:3000for local development
The API service provides geolocation data in this format:
{
"relay_fingerprint": {
"hexId": "h3_hexagon_id",
"coordinates": [latitude, longitude]
}
}- API First: The system first attempts to get geolocation data for relay fingerprints using the API service
- Fallback: For fingerprints not found via the API, it falls back to traditional IP-based lookups using local geo IP files
- Caching: API data is cached for 1 hour to improve performance and reduce API load
- Statistics: Enhanced logging provides visibility into lookup success rates for both methods
- More Accurate: Fingerprint-based lookups provide more precise geolocation data
- Up-to-date: API service can provide fresher data than local files
- Hybrid Approach: Maintains compatibility with existing IP-based lookups
- Performance: Caching reduces API calls while providing fresh data
The system remains fully backward compatible:
- If
API_SERVICE_URLis not set, only file-based lookups are used - If the API service is unavailable, it falls back to IP-based lookups
- Existing geo IP files in
/srv/onionoo/geoip/are still used as fallback
The API service integration includes comprehensive monitoring capabilities:
- Cache Duration: 1 hour (considered fresh)
- Warning Threshold: 70 minutes (getting stale)
- Critical Threshold: 2 hours (service degradation)
- Cache size (number of fingerprints)
- Cache age with status (FRESH/STALE/WARNING/CRITICAL)
- Last update timestamp
- Detailed error logging for different cache states
- Onionoo Updates: Every 60 minutes (configurable)
- MaxMind Database Updates: Weekly (recommended)
- Cache Refresh: Automatic during Onionoo update cycles
Monitor the following for service health:
- Cache age and status in application logs
- API service response time and availability
- MaxMind database freshness (should be updated weekly)
For detailed monitoring setup and troubleshooting, see GEOLOCATION_MONITORING.md.
- Country Data: Enhance the API to provide country code and country name data
- ASN Data: Add ASN (Autonomous System Number) information to the API response
- Retry Logic: Implement exponential backoff for API failures
- Health Checks: Add endpoints to monitor API service health