Add geolocation lookup feature, fixes #902
Discussions in menshen#39 and bitmask-core#17 (closed)
Issue: #902 (closed)
Smaller changes
- Update bitmask-core
- Use NewConfigFromURL instead of NewConfig
There is a small bug in the DoGeolocationLookup function. Needs to be merged: bitmask-core!25 (merged)
New fields in provider config
- STUNServers: list of STUN servers used to get current ip address, can be self hosted, public or a combination. If STUNServers is an empty list, the geolocation lookup is skipped. Also the geolocation lookup feature is only available for v5 (implemented in bitmask-core)
- countryCodeLookupURL: url that gives us a country code for an ip. Can be empty, then OONI backend is used
New field in systray.json:
- CountryCode: if the geolocation lookup succeeds, save it. Use it if future geolocation lookups fail
New behaviour/changes
- added new fields to providers/vendor.conf (STUNServers should be seperated with a ,)
- build tooling now supports both fields to create gui/providers/providers.json
- if geolocation lookup succeeds, we save the country code in systray.json
- if geolocation lookup fails, we don't have to save it
- if geolocation lookup fails and we have specified a fallback, bitmask-core uses this fallback country code
To Test
in providers/vendor.conf, change in the riseup section:
STUNServers = relay.webwormhole.io:3478, stun.syncthing.net:3478
countryCodeLookupURL = https://api.dev.ooni.io/api/v1/geolookup (this simulates an overwrite)
ROVIDER=riseup make vendor
PROVIDER=riseup QMAKE=qmake6 make build -j $(nproc)
Run it with V5 (API_VERSION=5 and API_URL=http://localhost:443)
Tests and example:
If geolocation works:
2024-09-04T14:24:16+02:00 DBG Doing geolocataion lookup
2024-09-04T14:24:16+02:00 TRC Trying STUN server server=relay.webwormhole.io:3478
2024-09-04T14:24:16+02:00 TRC Using custom country code lookup url countryCodeLookupURL=https://api.dev.ooni.io/api/v1/geolookup
2024-09-04T14:24:16+02:00 DBG Successfully got country code countryCode=FR
2024-09-04T14:24:16+02:00 DBG Saved country code in config file in case future lookups fail
pea@peabox: cat ~/.config/leap/systray.json
{
"LastReminded": "2024-07-30T11:12:04.167090465+02:00",
"Donated": "2024-04-01T00:00:00Z",
"Obfs4": false,
"UserStoppedVPN": true,
"DisableAutostart": true,
"UDP": true,
"Snowflake": false,
"KCP": false,
"CountryCode": "FR"
}
If geolocation fails use fallback
sudo iptables -I OUTPUT -p udp --dport 3478 -j REJECT
2024-09-04T14:43:19+02:00 DBG Doing geolocataion lookup
2024-09-04T14:43:19+02:00 TRC Trying STUN server server=relay.webwormhole.io:3478
2024-09-04T14:43:19+02:00 WRN Could not get ip using STUN server error="write udp 10.42.0.112:58262->142.93.228.31:3478: write: operation not permitted" server=relay.webwormhole.io:3478
2024-09-04T14:43:19+02:00 TRC Trying STUN server server=stun.syncthing.net:3478
2024-09-04T14:43:19+02:00 WRN Could not get ip using STUN server error="write udp 10.42.0.112:36694->139.59.84.212:3478: write: operation not permitted" server=stun.syncthing.net:3478
2024-09-04T14:43:19+02:00 WRN Could not do geolocation lookup err="Could not get ip address with STUN servers. All STUN servers failed. Using fallback country code FR"
Now we only need support for it in menshen :)
Edited by Pea Nut