Browse Source

changed to TCP

develop
yakamok 6 years ago committed by GitHub
parent
commit
e8f47f2c3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      vserv.py

18
vserv.py

@ -45,19 +45,19 @@ def isdatabase(db_path):
time timestamp default (strftime('%s', 'now')))''') time timestamp default (strftime('%s', 'now')))''')
conn.commit() conn.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):
try: try:
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) VALUES(?, ?)''',\ c.execute('''INSERT OR REPLACE INTO yggindex(ipv6, coords, utimestamp) VALUES(?, ?, ?)''',\
(ipv6, coords)) (ipv6, coords, utimestamp))
conn.commit() conn.commit()
conn.close() conn.close()
except Error as e: except Error as e:
@ -78,22 +78,26 @@ def error_check_insert_into_db(dht, switchpeers):
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
try: try:
data = json.loads(datty.decode()) ddata = datty.recv(1024 * 20)
data = json.loads(ddata.decode())
error_check_insert_into_db(data["dhtpack"], data["switchpack"]) error_check_insert_into_db(data["dhtpack"], data["switchpack"])
except: except:
print "ignoring, data was not json" print "ignoring, data was not json"
isdatabase(DB_PATH) isdatabase(DB_PATH)
conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) conn = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
conn.bind((SERVER, 45671)) conn.bind((SERVER, 45671))
conn.listen(30)
while True: while True:
try: try:
dataraw, addr = conn.recvfrom(1024 * 20) dataraw, addr = conn.accept()
thread.start_new_thread(proccess_incoming_data, (dataraw, addr)) thread.start_new_thread(proccess_incoming_data, (dataraw, addr))
except: except:
print "bloop" print "bloop"

Loading…
Cancel
Save