Commit e7229916 authored by Joanne Hugé's avatar Joanne Hugé

Add getCountry RPC

parent 0f97c026
......@@ -59,6 +59,9 @@ class RegistryServer(object):
peers = 0, ()
cert_duration = 365 * 86400
def _geoiplookup(self, ip):
raise HTTPError(httplib.BAD_REQUEST)
def __init__(self, config):
self.config = config
self.lock = threading.Lock()
......@@ -103,6 +106,20 @@ class RegistryServer(object):
self.ctl = ctl.Babel(os.path.join(, 'babeld.sock'),
db = os.getenv('GEOIP2_MMDB')
if db:
from geoip2 import database, errors
country = database.Reader(db).country
def geoiplookup(ip):
return country(ip).country.iso_code.encode()
except errors.AddressNotFoundError:
self._geoiplookup = geoiplookup
elif self.config.same_country:
sys.exit("Can not respect 'same_country' network configuration"
" (GEOIP2_MMDB not set)")
if self.prefix:
with self.db:
......@@ -504,6 +521,10 @@ class RegistryServer(object):"Timeout while querying address for %s/%s",
int(peer, 2), len(peer))
def getCountry(self, cn, address):
return self._geoiplookup(address)
def getBootstrapPeer(self, cn):
with self.peers_lock:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment