devices should now properly download stuff on joining network, added verbosity to the daemon threads
This commit is contained in:
parent
cebc2ebf71
commit
7982530fb8
29
main.py
29
main.py
@ -9,7 +9,7 @@ class Meshenger:
|
|||||||
#own_ip = "0.0.0.0"
|
#own_ip = "0.0.0.0"
|
||||||
msg_dir = os.path.relpath('msg/')
|
msg_dir = os.path.relpath('msg/')
|
||||||
exitapp = False #to kill all threads on
|
exitapp = False #to kill all threads on
|
||||||
index_last_update = str(time.time())
|
index_last_update = str(int(time.time()))
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
@ -70,21 +70,21 @@ class Meshenger:
|
|||||||
foreign_node_update = open(nodeupdatepath).read()
|
foreign_node_update = open(nodeupdatepath).read()
|
||||||
except:
|
except:
|
||||||
foreign_node_update = 0 #means it was never seen before
|
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'
|
||||||
|
|
||||||
|
|
||||||
if self.devices[device] > foreign_node_update:
|
if self.devices[device] > foreign_node_update:
|
||||||
print 'Foreign node"s index is newer, proceed to download index'
|
print 'Foreign node"s index is newer, proceed to download index'
|
||||||
self.get_index(device, nodepath)
|
self.get_index(device, nodepath)
|
||||||
self.node_timestamp(device)
|
|
||||||
print 'downloading messages'
|
print 'downloading messages'
|
||||||
self.get_messages(device, nodepath)
|
self.get_messages(device, nodepath)
|
||||||
|
self.node_timestamp(device)
|
||||||
|
|
||||||
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))
|
nodepath = os.path.abspath(os.path.join('nodes', self.hasj(ip)))
|
||||||
updatepath = os.path.join(nodepath, '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])
|
||||||
@ -117,20 +117,19 @@ 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]
|
||||||
|
print ip, "*"*45
|
||||||
node_path = os.path.join(os.path.abspath('nodes'), self.hasj(ip))
|
node_path = os.path.join(os.path.abspath('nodes'), self.hasj(ip))
|
||||||
if os.path.exists(node_path) and ip != self.own_ip:
|
|
||||||
print 'Known node', ip
|
|
||||||
self.devices[ip] = result[0]
|
|
||||||
#self.node_timestamp(ip) #klopt dit? ##
|
|
||||||
#self.devices.append(ip)
|
|
||||||
|
|
||||||
elif not os.path.exists(node_path) and ip != self.own_ip:
|
if 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) #make a folder /nodes/hash
|
||||||
self.devices[ip] = result[0]
|
self.devices[ip] = result[0]
|
||||||
self.node_timestamp(ip)
|
#self.node_timestamp(ip) #make a local copy of the timestamp in /nodes/hash/updatetimestamp
|
||||||
print 'New node', ip
|
print 'New node', ip
|
||||||
|
|
||||||
|
elif os.path.exists(node_path) and ip != self.own_ip:
|
||||||
|
print 'Known node', ip
|
||||||
|
self.devices[ip] = result[0]
|
||||||
|
|
||||||
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
@ -205,6 +204,7 @@ Get new messages from other node based on it's index file
|
|||||||
print 'downloading', message, 'to', messagepath
|
print 'downloading', message, 'to', messagepath
|
||||||
os.system('wget http://['+ip+'%adhoc0]:'+self.serve_port+'/msg/'+message+' -O '+messagepath)
|
os.system('wget http://['+ip+'%adhoc0]:'+self.serve_port+'/msg/'+message+' -O '+messagepath)
|
||||||
except:
|
except:
|
||||||
|
print 'Failed to download messages'
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def ip_to_hash_path(self, ip):
|
def ip_to_hash_path(self, ip):
|
||||||
@ -228,11 +228,6 @@ Convert a node's ip into a hash and make a directory to store it's files
|
|||||||
hasj = hashlib.md5(ip).hexdigest()
|
hasj = hashlib.md5(ip).hexdigest()
|
||||||
return hasj
|
return hasj
|
||||||
|
|
||||||
def clientsite(self):
|
|
||||||
a = ''
|
|
||||||
|
|
||||||
#tools
|
|
||||||
|
|
||||||
def get_ip_adress(self):
|
def get_ip_adress(self):
|
||||||
"""
|
"""
|
||||||
Hack to adhoc0's inet6 adress
|
Hack to adhoc0's inet6 adress
|
||||||
|
Loading…
Reference in New Issue
Block a user