diff --git a/main.py b/main.py index 9f4f236..5a8e984 100755 --- a/main.py +++ b/main.py @@ -1,7 +1,6 @@ #!/usr/bin/python import socket, os, time, select, urllib, sys, threading -from multiprocessing import Process class Meshenger: devices = {} #the dictionary of all the nodes this this node has seen @@ -31,7 +30,7 @@ class Meshenger: a.daemon = True a.start() - n = Process(target=self.nodeserve) + n = threading.Thread(target=self.nodeserve) n.daemon = True n.start() @@ -61,7 +60,6 @@ class Meshenger: print 'found', len(self.devices),'device(s)' for device in self.devices.keys(): - nodepath = self.ip_to_hash_path(device) #make a folder for the node (nodes/'hash'/) nodeupdatepath = os.path.join(self.ip_to_hash_path(device), 'lastupdate') @@ -81,7 +79,7 @@ class Meshenger: self.get_index(device, nodepath) print 'downloading messages' self.get_messages(device, nodepath) - self.node_timestamp(device) + self.node_timestamp(device) time.sleep(5) #free process or ctrl+c @@ -114,17 +112,14 @@ Discover other devices by listening to the Meshenger announce port bufferSize = 1024 # whatever you need? s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM, socket.IPPROTO_UDP) - s.bind(('::', self.announce_port)) s.setblocking(0) while not self.exitapp: result = select.select([s],[],[])[0][0].recvfrom(bufferSize) - ip = result[1][0] print ip, "*"*45 node_path = os.path.join(os.path.abspath('nodes'), self.hasj(ip)) - if not os.path.exists(node_path) and ip != self.own_ip: #loop for first time self.ip_to_hash_path(ip) #make a folder /nodes/hash @@ -136,6 +131,7 @@ Discover other devices by listening to the Meshenger announce port print 'Known node', ip self.devices[ip] = result[0] + time.sleep(1) def nodeserve(self): @@ -203,7 +199,6 @@ Get new messages from other node based on it's index file with open(os.path.join(path,'index')) as index: index = index.read().split('\n') for message in index: - messagepath = os.path.join(os.path.abspath(self.msg_dir), message) if not os.path.exists(messagepath): print 'downloading', message, 'to', messagepath @@ -238,8 +233,7 @@ Convert a node's ip into a hash and make a directory to store it's files Hack to adhoc0's inet6 adress """ if not os.path.isfile('interfaceip6adress'): -#changed to wlan for unexplainable reasons (god) - os.system('ifconfig -a wlan0 | grep inet6 > /root/meshenger/interfaceip6adress') + os.system('ifconfig -a adhoc0 | grep inet6 > /root/meshenger/interfaceip6adress') with open('interfaceip6adress', 'r') as a: return a.read().split()[2].split('/')[0] diff --git a/webapp.html b/webapp.html index 39f2462..70f7a0d 100644 --- a/webapp.html +++ b/webapp.html @@ -114,7 +114,7 @@ function doStuffForEach( entriesString, stuffFunction ) { * INBOX STUFF */ function updateInboxView() { - +localStorage.clear(); var contentString = ''; for(var i in localStorage) { @@ -133,6 +133,20 @@ function onMessageDownload( msg, filename ) { updateInboxView(); } function onIndex( index ) { + +/* NON WORKING MOD + for(var k in localStorage){ + var l = 1; + for ( var i in lines ) { + if (i == k){ l = 0; } + } + if (l == 1){ + localStorage.removeItem(k); + } + } +updateInboxView(); +*/ + var lines = index.split( /\n/ ); for ( var i in lines ) { var fname = lines[i]; @@ -140,7 +154,9 @@ function onIndex( index ) { //localStorage.setItem( ts, lines[i].substr(lines[i].indexOf(' ')) ); downloadMessage( fname ); } + } + } function downloadMessage(filename) { var xhr = new XMLHttpRequest(); @@ -173,7 +189,7 @@ updateOutboxView(); window.setInterval( function(){ checkInbox(); checkOutbox(); -}, 10000 ); +}, 3000 );