general cleanup of randomness
This commit is contained in:
parent
f12bd4dcec
commit
87ed307ac5
12
main.py
12
main.py
@ -1,7 +1,6 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
import socket, os, time, select, urllib, sys, threading
|
import socket, os, time, select, urllib, sys, threading
|
||||||
from multiprocessing import Process
|
|
||||||
|
|
||||||
class Meshenger:
|
class Meshenger:
|
||||||
devices = {} #the dictionary of all the nodes this this node has seen
|
devices = {} #the dictionary of all the nodes this this node has seen
|
||||||
@ -31,7 +30,7 @@ class Meshenger:
|
|||||||
a.daemon = True
|
a.daemon = True
|
||||||
a.start()
|
a.start()
|
||||||
|
|
||||||
n = Process(target=self.nodeserve)
|
n = threading.Thread(target=self.nodeserve)
|
||||||
n.daemon = True
|
n.daemon = True
|
||||||
n.start()
|
n.start()
|
||||||
|
|
||||||
@ -61,7 +60,6 @@ class Meshenger:
|
|||||||
print 'found', len(self.devices),'device(s)'
|
print 'found', len(self.devices),'device(s)'
|
||||||
|
|
||||||
for device in self.devices.keys():
|
for device in self.devices.keys():
|
||||||
|
|
||||||
nodepath = self.ip_to_hash_path(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_path(device), 'lastupdate')
|
nodeupdatepath = os.path.join(self.ip_to_hash_path(device), 'lastupdate')
|
||||||
|
|
||||||
@ -114,17 +112,14 @@ Discover other devices by listening to the Meshenger announce port
|
|||||||
bufferSize = 1024 # whatever you need?
|
bufferSize = 1024 # whatever you need?
|
||||||
|
|
||||||
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
|
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
|
||||||
|
|
||||||
s.bind(('::', self.announce_port))
|
s.bind(('::', self.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]
|
ip = result[1][0]
|
||||||
print ip, "*"*45
|
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 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) #make a folder /nodes/hash
|
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
|
print 'Known node', ip
|
||||||
self.devices[ip] = result[0]
|
self.devices[ip] = result[0]
|
||||||
|
|
||||||
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
def nodeserve(self):
|
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:
|
with open(os.path.join(path,'index')) as index:
|
||||||
index = index.read().split('\n')
|
index = index.read().split('\n')
|
||||||
for message in index:
|
for message in index:
|
||||||
|
|
||||||
messagepath = os.path.join(os.path.abspath(self.msg_dir), message)
|
messagepath = os.path.join(os.path.abspath(self.msg_dir), message)
|
||||||
if not os.path.exists(messagepath):
|
if not os.path.exists(messagepath):
|
||||||
print 'downloading', message, 'to', 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
|
Hack to adhoc0's inet6 adress
|
||||||
"""
|
"""
|
||||||
if not os.path.isfile('interfaceip6adress'):
|
if not os.path.isfile('interfaceip6adress'):
|
||||||
#changed to wlan for unexplainable reasons (god)
|
os.system('ifconfig -a adhoc0 | grep inet6 > /root/meshenger/interfaceip6adress')
|
||||||
os.system('ifconfig -a wlan0 | grep inet6 > /root/meshenger/interfaceip6adress')
|
|
||||||
with open('interfaceip6adress', 'r') as a:
|
with open('interfaceip6adress', 'r') as a:
|
||||||
return a.read().split()[2].split('/')[0]
|
return a.read().split()[2].split('/')[0]
|
||||||
|
|
||||||
|
20
webapp.html
20
webapp.html
@ -114,7 +114,7 @@ function doStuffForEach( entriesString, stuffFunction ) {
|
|||||||
* INBOX STUFF
|
* INBOX STUFF
|
||||||
*/
|
*/
|
||||||
function updateInboxView() {
|
function updateInboxView() {
|
||||||
|
localStorage.clear();
|
||||||
var contentString = '';
|
var contentString = '';
|
||||||
for(var i in localStorage)
|
for(var i in localStorage)
|
||||||
{
|
{
|
||||||
@ -133,6 +133,20 @@ function onMessageDownload( msg, filename ) {
|
|||||||
updateInboxView();
|
updateInboxView();
|
||||||
}
|
}
|
||||||
function onIndex( index ) {
|
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/ );
|
var lines = index.split( /\n/ );
|
||||||
for ( var i in lines ) {
|
for ( var i in lines ) {
|
||||||
var fname = lines[i];
|
var fname = lines[i];
|
||||||
@ -140,7 +154,9 @@ function onIndex( index ) {
|
|||||||
//localStorage.setItem( ts, lines[i].substr(lines[i].indexOf(' ')) );
|
//localStorage.setItem( ts, lines[i].substr(lines[i].indexOf(' ')) );
|
||||||
downloadMessage( fname );
|
downloadMessage( fname );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
function downloadMessage(filename) {
|
function downloadMessage(filename) {
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
@ -173,7 +189,7 @@ updateOutboxView();
|
|||||||
window.setInterval( function(){
|
window.setInterval( function(){
|
||||||
checkInbox();
|
checkInbox();
|
||||||
checkOutbox();
|
checkOutbox();
|
||||||
}, 10000 );
|
}, 3000 );
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user