fixed logic erros
This commit is contained in:
parent
adfc560a65
commit
e1a198bea1
16
main.py
16
main.py
@ -66,7 +66,11 @@ class Meshenger:
|
|||||||
|
|
||||||
print 'Checking age of foreign node index'
|
print 'Checking age of foreign node index'
|
||||||
print self.devices[device], 'Foreign announce timestamp'
|
print self.devices[device], 'Foreign announce timestamp'
|
||||||
|
try:
|
||||||
foreign_node_update = open(nodeupdatepath).read()
|
foreign_node_update = open(nodeupdatepath).read()
|
||||||
|
except:
|
||||||
|
foreign_node_update = 0 #means it was never seen before
|
||||||
|
self.node_timestamp(device)
|
||||||
print foreign_node_update, 'Locally stored timestamp for device'
|
print foreign_node_update, 'Locally stored timestamp for device'
|
||||||
|
|
||||||
|
|
||||||
@ -80,8 +84,8 @@ class Meshenger:
|
|||||||
time.sleep(5) #free process or ctrl+c
|
time.sleep(5) #free process or ctrl+c
|
||||||
|
|
||||||
def node_timestamp(self, ip):
|
def node_timestamp(self, ip):
|
||||||
|
nodepath = os.path.abspath('nodes', self.hasj(ip))
|
||||||
updatepath = os.path.join(self.ip_to_hash_path(ip), 'lastupdate')
|
updatepath = os.path.join(nodepath, 'lastupdate')
|
||||||
with open(updatepath, 'wb') as lastupdate:
|
with open(updatepath, 'wb') as lastupdate:
|
||||||
lastupdate.write(self.devices[ip])
|
lastupdate.write(self.devices[ip])
|
||||||
#return updatepath
|
#return updatepath
|
||||||
@ -113,14 +117,14 @@ Discover other devices by listening to the Meshenger announce port
|
|||||||
while not self.exitapp:
|
while not self.exitapp:
|
||||||
result = select.select([s],[],[])[0][0].recvfrom(bufferSize)
|
result = select.select([s],[],[])[0][0].recvfrom(bufferSize)
|
||||||
ip = result[1][0]
|
ip = result[1][0]
|
||||||
|
node_path = os.path.join(os.path.abspath('nodes'), self.hasj(ip))
|
||||||
if os.path.exists(self.ip_to_hash_path(ip)) and ip != self.own_ip:
|
if os.path.exists(node_path) and ip != self.own_ip:
|
||||||
print 'Known node', ip
|
print 'Known node', ip
|
||||||
self.devices[ip] = result[0]
|
self.devices[ip] = result[0]
|
||||||
self.node_timestamp(ip) #klopt dit?
|
#self.node_timestamp(ip) #klopt dit? ##
|
||||||
#self.devices.append(ip)
|
#self.devices.append(ip)
|
||||||
|
|
||||||
elif not os.path.exists(self.ip_to_hash_path(ip)) and ip != self.own_ip:
|
elif not os.path.exists(node_path) and ip != self.own_ip:
|
||||||
#loop for first time
|
#loop for first time
|
||||||
self.ip_to_hash_path(ip)
|
self.ip_to_hash_path(ip)
|
||||||
self.devices[ip] = result[0]
|
self.devices[ip] = result[0]
|
||||||
|
Loading…
Reference in New Issue
Block a user