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): @@ -45,19 +45,19 @@ def isdatabase(db_path):
time timestamp default (strftime('%s', 'now')))''')
conn.commit()
except Error as e:
print e
print(e)
finally:
conn.close()
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):
try:
conn = sqlite3.connect(db_path + "yggindex.db")
c = conn.cursor()
c.execute('''INSERT OR REPLACE INTO yggindex(ipv6, coords) VALUES(?, ?)''',\
(ipv6, coords))
c.execute('''INSERT OR REPLACE INTO yggindex(ipv6, coords, utimestamp) VALUES(?, ?, ?)''',\
(ipv6, coords, utimestamp))
conn.commit()
conn.close()
except Error as e:
@ -78,22 +78,26 @@ def error_check_insert_into_db(dht, switchpeers): @@ -78,22 +78,26 @@ def error_check_insert_into_db(dht, switchpeers):
except:
print"error in json file, aborting"
def proccess_incoming_data(datty, addr):
print addr
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"])
except:
print "ignoring, data was not json"
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.listen(30)
while True:
try:
dataraw, addr = conn.recvfrom(1024 * 20)
dataraw, addr = conn.accept()
thread.start_new_thread(proccess_incoming_data, (dataraw, addr))
except:
print "bloop"

Loading…
Cancel
Save