Rev3223, Fix error when using ip wihout city entry
This commit is contained in:
parent
f5b4936197
commit
342f9f6096
2 changed files with 34 additions and 35 deletions
|
@ -517,6 +517,34 @@ class UiWebsocketPlugin(object):
|
||||||
-100
|
-100
|
||||||
])
|
])
|
||||||
|
|
||||||
|
def getLoc(self, geodb, ip):
|
||||||
|
global loc_cache
|
||||||
|
|
||||||
|
if ip in loc_cache:
|
||||||
|
return loc_cache[ip]
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
loc_data = geodb.get(ip)
|
||||||
|
except:
|
||||||
|
loc_data = None
|
||||||
|
|
||||||
|
if not loc_data or "location" not in loc_data:
|
||||||
|
loc_cache[ip] = None
|
||||||
|
return None
|
||||||
|
|
||||||
|
loc = {
|
||||||
|
"lat": loc_data["location"]["latitude"],
|
||||||
|
"lon": loc_data["location"]["longitude"],
|
||||||
|
}
|
||||||
|
if "city" in loc_data:
|
||||||
|
loc["city"] = loc_data["city"]["names"]["en"]
|
||||||
|
|
||||||
|
if "country" in loc_data:
|
||||||
|
loc["country"] = loc_data["country"]["names"]["en"]
|
||||||
|
|
||||||
|
loc_cache[ip] = loc
|
||||||
|
return loc
|
||||||
|
|
||||||
def getPeerLocations(self, peers):
|
def getPeerLocations(self, peers):
|
||||||
import maxminddb
|
import maxminddb
|
||||||
db_path = config.data_dir + '/GeoLite2-City.mmdb'
|
db_path = config.data_dir + '/GeoLite2-City.mmdb'
|
||||||
|
@ -535,28 +563,8 @@ class UiWebsocketPlugin(object):
|
||||||
ping = round(peer.connection.last_ping_delay * 1000)
|
ping = round(peer.connection.last_ping_delay * 1000)
|
||||||
else:
|
else:
|
||||||
ping = None
|
ping = None
|
||||||
|
loc = self.getLoc(geodb, peer.ip)
|
||||||
|
|
||||||
# Query and cache location
|
|
||||||
if peer.ip in loc_cache:
|
|
||||||
loc = loc_cache[peer.ip]
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
loc_data = geodb.get(peer.ip)
|
|
||||||
except:
|
|
||||||
loc_data = None
|
|
||||||
if not loc_data or "location" not in loc_data:
|
|
||||||
loc_cache[peer.ip] = None
|
|
||||||
continue
|
|
||||||
|
|
||||||
loc = {
|
|
||||||
"lat": loc_data["location"]["latitude"],
|
|
||||||
"lon": loc_data["location"]["longitude"],
|
|
||||||
}
|
|
||||||
if "city" in loc_data:
|
|
||||||
loc["city"] = loc_data["city"]["names"]["en"]
|
|
||||||
if "country" in loc_data:
|
|
||||||
loc["country"] = loc_data["country"]["names"]["en"]
|
|
||||||
loc_cache[peer.ip] = loc
|
|
||||||
if not loc:
|
if not loc:
|
||||||
continue
|
continue
|
||||||
# Create position array
|
# Create position array
|
||||||
|
@ -576,19 +584,10 @@ class UiWebsocketPlugin(object):
|
||||||
peer_locations.append(peer_location)
|
peer_locations.append(peer_location)
|
||||||
|
|
||||||
# Append myself
|
# Append myself
|
||||||
try:
|
my_loc = self.getLoc(geodb, config.ip_external)
|
||||||
loc_data = geodb.get(config.ip_external)
|
if my_loc:
|
||||||
except:
|
my_loc["ping"] = 0
|
||||||
loc_data = None
|
peer_locations.append(my_loc)
|
||||||
if loc_data and loc_data.get("location"):
|
|
||||||
peer_location = {
|
|
||||||
"lat": loc_data["location"]["latitude"],
|
|
||||||
"lon": loc_data["location"]["longitude"],
|
|
||||||
"country": loc_data["country"]["names"]["en"],
|
|
||||||
"city": loc_data["city"]["names"]["en"],
|
|
||||||
"ping": 0
|
|
||||||
}
|
|
||||||
peer_locations.append(peer_location)
|
|
||||||
|
|
||||||
return peer_locations
|
return peer_locations
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ class Config(object):
|
||||||
|
|
||||||
def __init__(self, argv):
|
def __init__(self, argv):
|
||||||
self.version = "0.6.1"
|
self.version = "0.6.1"
|
||||||
self.rev = 3222
|
self.rev = 3223
|
||||||
self.argv = argv
|
self.argv = argv
|
||||||
self.action = None
|
self.action = None
|
||||||
self.config_file = "zeronet.conf"
|
self.config_file = "zeronet.conf"
|
||||||
|
|
Loading…
Reference in a new issue