|
@ -11,7 +11,6 @@ class Meshenger: |
|
|
exitapp = False #to kill all threads on |
|
|
exitapp = False #to kill all threads on |
|
|
index_last_update = str(time.time()) |
|
|
index_last_update = str(time.time()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self): |
|
|
def __init__(self): |
|
|
|
|
|
|
|
|
os.system("echo 1 >> /proc/sys/net/ipv6/conf/br-lan/disable_ipv6") |
|
|
os.system("echo 1 >> /proc/sys/net/ipv6/conf/br-lan/disable_ipv6") |
|
@ -31,20 +30,27 @@ class Meshenger: |
|
|
a.daemon = True |
|
|
a.daemon = True |
|
|
a.start() |
|
|
a.start() |
|
|
|
|
|
|
|
|
s = threading.Thread(target=self.serve) |
|
|
n = threading.Thread(target=self.nodeserve) |
|
|
s.daemon = True |
|
|
n.daemon = True |
|
|
s.start() |
|
|
n.start() |
|
|
|
|
|
|
|
|
|
|
|
c = threading.Thread(target=self.clientserve) |
|
|
|
|
|
c.daemon = True |
|
|
|
|
|
c.start() |
|
|
|
|
|
|
|
|
b = threading.Thread(target=self.build_index) |
|
|
b = threading.Thread(target=self.build_index) |
|
|
b.daemon = True |
|
|
b.daemon = True |
|
|
b.start() |
|
|
b.start() |
|
|
|
|
|
|
|
|
|
|
|
#os.system("python meshenger_clientserve.py") |
|
|
|
|
|
|
|
|
except (KeyboardInterrupt, SystemExit): |
|
|
except (KeyboardInterrupt, SystemExit): |
|
|
print 'exiting discovery thread' |
|
|
print 'exiting discovery thread' |
|
|
d.join() |
|
|
d.join() |
|
|
a.join() |
|
|
a.join() |
|
|
b.join() |
|
|
b.join() |
|
|
s.join() |
|
|
n.join() |
|
|
|
|
|
c.join() |
|
|
sys.exit() |
|
|
sys.exit() |
|
|
|
|
|
|
|
|
while True: |
|
|
while True: |
|
@ -57,7 +63,7 @@ class Meshenger: |
|
|
nodepath = self.ip_to_hash(device) #make a folder for the node (nodes/'hash'/) |
|
|
nodepath = self.ip_to_hash(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(device), 'lastupdate') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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' |
|
|
foreign_node_update = open(nodeupdatepath).read() |
|
|
foreign_node_update = open(nodeupdatepath).read() |
|
@ -70,9 +76,9 @@ class Meshenger: |
|
|
self.node_timestamp(device) |
|
|
self.node_timestamp(device) |
|
|
print 'downloading messages' |
|
|
print 'downloading messages' |
|
|
self.get_messages(device, nodepath) |
|
|
self.get_messages(device, nodepath) |
|
|
|
|
|
|
|
|
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): |
|
|
|
|
|
|
|
|
updatepath = os.path.join(self.ip_to_hash(ip), 'lastupdate') |
|
|
updatepath = os.path.join(self.ip_to_hash(ip), 'lastupdate') |
|
@ -111,7 +117,7 @@ Discover other devices by listening to the Meshenger announce port |
|
|
print 'Known node', result[1][0] |
|
|
print 'Known node', result[1][0] |
|
|
self.devices[result[1][0]] = result[0] |
|
|
self.devices[result[1][0]] = result[0] |
|
|
#self.devices.append(result[1][0]) |
|
|
#self.devices.append(result[1][0]) |
|
|
|
|
|
|
|
|
elif result[1][0] not in self.devices and result[1][0] != self.own_ip: |
|
|
elif result[1][0] not in self.devices and result[1][0] != self.own_ip: |
|
|
#loop for first time |
|
|
#loop for first time |
|
|
self.devices[result[1][0]] = result[0] |
|
|
self.devices[result[1][0]] = result[0] |
|
@ -122,13 +128,22 @@ Discover other devices by listening to the Meshenger announce port |
|
|
|
|
|
|
|
|
time.sleep(1) |
|
|
time.sleep(1) |
|
|
|
|
|
|
|
|
def serve(self): |
|
|
def nodeserve(self): |
|
|
""" |
|
|
""" |
|
|
Initialize the server |
|
|
Initialize the nodeserver |
|
|
""" |
|
|
""" |
|
|
print 'Serving' |
|
|
print 'Serving to nodes' |
|
|
import meshenger_serve |
|
|
import meshenger_nodeserve |
|
|
meshenger_serve.main() |
|
|
meshenger_nodeserve.main() |
|
|
|
|
|
|
|
|
|
|
|
def clientserve(self): |
|
|
|
|
|
""" |
|
|
|
|
|
Initialize the clientserver |
|
|
|
|
|
""" |
|
|
|
|
|
print 'Serving to client' |
|
|
|
|
|
import meshenger_clientserve |
|
|
|
|
|
meshenger_clientserve.main() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def build_index(self): |
|
|
def build_index(self): |
|
|
""" |
|
|
""" |
|
@ -152,7 +167,7 @@ Save the time of the last update. |
|
|
index.write(message) |
|
|
index.write(message) |
|
|
index.write('\n') |
|
|
index.write('\n') |
|
|
self.index_last_update = str(int(time.time())) |
|
|
self.index_last_update = str(int(time.time())) |
|
|
|
|
|
|
|
|
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: ### misschien is dit overbodig |
|
@ -223,4 +238,3 @@ if __name__ == "__main__": |
|
|
except (KeyboardInterrupt, SystemExit): |
|
|
except (KeyboardInterrupt, SystemExit): |
|
|
exitapp = True |
|
|
exitapp = True |
|
|
raise |
|
|
raise |
|
|
|
|
|
|
|
|