Merge branch 'master' of https://github.com/jngrt/meshenger
This commit is contained in:
commit
a3fe513094
45
main.py
45
main.py
@ -60,8 +60,8 @@ class Meshenger:
|
|||||||
print 'found', len(self.devices),'device(s)'
|
print 'found', len(self.devices),'device(s)'
|
||||||
|
|
||||||
for device in self.devices:
|
for device in self.devices:
|
||||||
nodepath = self.ip_to_hash(device) #make a folder for the node (nodes/'hash'/)
|
nodepath = self.ip_to_hash_path(device) #make a folder for the node (nodes/'hash'/)
|
||||||
nodeupdatepath = os.path.join(self.ip_to_hash(device), 'lastupdate')
|
nodeupdatepath = os.path.join(self.ip_to_hash_path(device), 'lastupdate')
|
||||||
|
|
||||||
|
|
||||||
print 'Checking age of foreign node index'
|
print 'Checking age of foreign node index'
|
||||||
@ -81,7 +81,7 @@ class Meshenger:
|
|||||||
|
|
||||||
def node_timestamp(self, ip):
|
def node_timestamp(self, ip):
|
||||||
|
|
||||||
updatepath = os.path.join(self.ip_to_hash(ip), 'lastupdate')
|
updatepath = os.path.join(self.ip_to_hash_path(ip), '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
|
||||||
@ -112,17 +112,20 @@ Discover other devices by listening to the Meshenger announce port
|
|||||||
s.setblocking(0)
|
s.setblocking(0)
|
||||||
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]
|
||||||
|
|
||||||
if result[1][0] in self.devices and result[1][0] != self.own_ip:
|
if os.path.exists(self.ip_to_hash_path(ip)) and ip != self.own_ip:
|
||||||
print 'Known node', result[1][0]
|
print 'Known node', ip
|
||||||
self.devices[result[1][0]] = result[0]
|
self.devices[ip] = result[0]
|
||||||
#self.devices.append(result[1][0])
|
self.node_timestamp(ip) #klopt dit?
|
||||||
|
#self.devices.append(ip)
|
||||||
|
|
||||||
elif result[1][0] not in self.devices and result[1][0] != self.own_ip:
|
elif not os.path.exists(self.ip_to_hash_path(ip)) and ip != self.own_ip:
|
||||||
#loop for first time
|
#loop for first time
|
||||||
self.devices[result[1][0]] = result[0]
|
self.ip_to_hash_path(ip)
|
||||||
self.node_timestamp(result[1][0])
|
self.devices[ip] = result[0]
|
||||||
print 'New node', result[1][0]
|
self.node_timestamp(ip)
|
||||||
|
print 'New node', ip
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -156,8 +159,9 @@ Save the time of the last update.
|
|||||||
if not os.path.exists('index'):
|
if not os.path.exists('index'):
|
||||||
with open('index','wb') as index:
|
with open('index','wb') as index:
|
||||||
index.write('')
|
index.write('')
|
||||||
|
|
||||||
previous_index = []
|
previous_index = []
|
||||||
|
else:
|
||||||
|
previous_index = open('index').readlines()
|
||||||
|
|
||||||
while not self.exitapp:
|
while not self.exitapp:
|
||||||
current_index = os.listdir(self.msg_dir)
|
current_index = os.listdir(self.msg_dir)
|
||||||
@ -170,8 +174,8 @@ Save the time of the last update.
|
|||||||
|
|
||||||
print 'Index updated:', current_index
|
print 'Index updated:', current_index
|
||||||
|
|
||||||
with open('index_last_update', 'wb') as indexupdate: ### misschien is dit overbodig
|
with open('index_last_update', 'wb') as indexupdate:
|
||||||
indexupdate.write(str(int(time.time())))
|
indexupdate.write(self.index_last_update) ### misschien moet dit index_last_update zijn
|
||||||
|
|
||||||
previous_index = current_index
|
previous_index = current_index
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
@ -199,21 +203,26 @@ Get new messages from other node based on it's index file
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def ip_to_hash(self, ip):
|
def ip_to_hash_path(self, ip):
|
||||||
"""
|
"""
|
||||||
Convert a node's ip into a hash and make a directory to store it's files
|
Convert a node's ip into a hash and make a directory to store it's files
|
||||||
"""
|
"""
|
||||||
if not os.path.exists('nodes'):
|
if not os.path.exists('nodes'):
|
||||||
os.mkdir('nodes')
|
os.mkdir('nodes')
|
||||||
|
|
||||||
import hashlib
|
nodepath = os.path.join(os.path.abspath('nodes'), self.hasj(ip))
|
||||||
hasj = hashlib.md5(ip).hexdigest()
|
|
||||||
nodepath = os.path.join(os.path.abspath('nodes'), hasj)
|
|
||||||
if not os.path.exists(nodepath):
|
if not os.path.exists(nodepath):
|
||||||
os.mkdir(nodepath)
|
os.mkdir(nodepath)
|
||||||
|
|
||||||
return nodepath
|
return nodepath
|
||||||
|
|
||||||
|
def hasj(self, ip):
|
||||||
|
"""
|
||||||
|
Convert a node's ip into a hash
|
||||||
|
"""
|
||||||
|
import hashlib
|
||||||
|
hasj = hashlib.md5(ip).hexdigest()
|
||||||
|
return hasj
|
||||||
|
|
||||||
def clientsite(self):
|
def clientsite(self):
|
||||||
a = ''
|
a = ''
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
-find a way to prioritize the index/message download threads. Perhaps these threads could tell other threads to pause?
|
-find a way to prioritize the index/message download threads. Perhaps these threads could tell other threads to pause?
|
||||||
|
|
||||||
-nodes that are new to the network don't immediately download indices from the other nodes
|
SOLVED -nodes that are new to the network don't immediately download indices from the other nodes
|
||||||
|
|
||||||
-nodes that disconnect from the network should be removed from lists of known devices
|
-nodes that disconnect from the network should be removed from lists of known devices
|
||||||
|
|
||||||
-file deletion or time to live (client side?)
|
-file deletion or time to live (client side?)
|
||||||
|
|
||||||
|
-prevent WebSheet (ios) and etc captive portal to hijack the client connection ;)
|
||||||
|
|
||||||
# Cryptoshit
|
# Cryptoshit
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user