1
0
mirror of https://github.com/r4sas/Niflheim-api synced 2025-01-27 07:04:44 +00:00

Update vserv.py

This commit is contained in:
yakamok 2018-07-01 02:15:34 +02:00 committed by GitHub
parent 0a688f49eb
commit 9188280a7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,4 @@
#server for collecting views of the network #server for collecting DHT info
import json import json
import time import time
@ -17,7 +17,7 @@ DB_PATH = "vservdb/"
def check_coords(coords): def check_coords(coords):
coord_len = coords.replace(' ', '').replace('[', '').replace(']', '') coord_len = coords.replace(' ', '').replace('[', '').replace(']', '')
digits_found = [x for x in coord_len if x.isdigit()] digits_found = [x for x in coord_len if x.isdigit()]
if len(digits_found) == len(coord_len): if len(digits_found) == len(coord_len):
crus = True crus = True
else: else:
@ -26,7 +26,6 @@ def check_coords(coords):
def valid_ipv6_check(ipv6add): def valid_ipv6_check(ipv6add):
import ipaddress
try: try:
if ipaddress.IPv6Address(unicode(ipv6add)): if ipaddress.IPv6Address(unicode(ipv6add)):
addr = True addr = True
@ -47,11 +46,11 @@ def isdatabase(db_path):
conn.commit() conn.commit()
# c.commit() # c.commit()
except Error as e: except Error as e:
print(e) print e
finally: finally:
conn.close() conn.close()
else: else:
print("found database will not create a new one") print"found database will not create a new one"
def insert_new_entry(db_path, ipv6, coords, utimestamp): def insert_new_entry(db_path, ipv6, coords, utimestamp):
@ -59,26 +58,26 @@ def insert_new_entry(db_path, ipv6, coords, utimestamp):
conn = sqlite3.connect(db_path + "yggindex.db") conn = sqlite3.connect(db_path + "yggindex.db")
c = conn.cursor() c = conn.cursor()
c.execute('''INSERT OR REPLACE INTO yggindex(ipv6, coords, utimestamp) VALUES(?, ?, ?)''',\ c.execute('''INSERT OR REPLACE INTO yggindex(ipv6, coords, utimestamp) VALUES(?, ?, ?)''',\
(ipv6, coords, utimestamp)) (ipv6, coords, utimestamp))
conn.commit() conn.commit()
conn.close() conn.close()
except Error as e: except Error as e:
print(e) print e
def error_check_insert_into_db(dht, switchpeers): def error_check_insert_into_db(dht, switchpeers):
try: try:
if "success" == dht.get("status"): if dht.get("status") == "success":
for x,y in dht["response"]["dht"].iteritems(): for x, y in dht["response"]["dht"].iteritems():
if valid_ipv6_check(x) and check_coords(y["coords"]): if valid_ipv6_check(x) and check_coords(y["coords"]):
insert_new_entry(DB_PATH, x, y["coords"], int(time.time())) insert_new_entry(DB_PATH, x, y["coords"], int(time.time()))
if "success" == dht.get("status"): if dht.get("status") == "success":
for x in switchpeers["response"]["switchpeers"].iteritems(): for x in switchpeers["response"]["switchpeers"].iteritems():
if valid_ipv6_check(x[1]["ip"]) and check_coords(x[1]["coords"]): if valid_ipv6_check(x[1]["ip"]) and check_coords(x[1]["coords"]):
insert_new_entry(DB_PATH, x[1]["ip"], x[1]["coords"], int(time.time())) insert_new_entry(DB_PATH, x[1]["ip"], x[1]["coords"], int(time.time()))
except: except:
print("error in json file, aborting") print"error in json file, aborting"
def proccess_incoming_data(datty, addr): def proccess_incoming_data(datty, addr):
print addr print addr