igg
This commit is contained in:
parent
6022f00690
commit
f12bd4dcec
14
main.py
14
main.py
@ -1,6 +1,7 @@
|
|||||||
#!/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
|
||||||
@ -15,7 +16,7 @@ class Meshenger:
|
|||||||
|
|
||||||
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")
|
||||||
os.system("echo 1 >> /proc/sys/net/ipv6/conf/br-hotspot/disable_ipv6")
|
os.system("echo 1 >> /proc/sys/net/ipv6/conf/br-hotspot/disable_ipv6")
|
||||||
self.own_ip = self.get_ip_adress()
|
self.own_ip = self.get_ip_adress().strip()
|
||||||
|
|
||||||
if not os.path.exists(self.msg_dir):
|
if not os.path.exists(self.msg_dir):
|
||||||
os.mkdir(self.msg_dir)
|
os.mkdir(self.msg_dir)
|
||||||
@ -30,7 +31,7 @@ class Meshenger:
|
|||||||
a.daemon = True
|
a.daemon = True
|
||||||
a.start()
|
a.start()
|
||||||
|
|
||||||
n = threading.Thread(target=self.nodeserve)
|
n = Process(target=self.nodeserve)
|
||||||
n.daemon = True
|
n.daemon = True
|
||||||
n.start()
|
n.start()
|
||||||
|
|
||||||
@ -60,6 +61,7 @@ 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')
|
||||||
|
|
||||||
@ -112,14 +114,17 @@ 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
|
||||||
@ -131,7 +136,6 @@ 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):
|
||||||
@ -199,6 +203,7 @@ 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
|
||||||
@ -233,7 +238,8 @@ 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'):
|
||||||
os.system('ifconfig -a adhoc0 | grep inet6 > /root/meshenger/interfaceip6adress')
|
#changed to wlan for unexplainable reasons (god)
|
||||||
|
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]
|
||||||
|
|
||||||
|
@ -4,10 +4,20 @@ import logging
|
|||||||
import cgi
|
import cgi
|
||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
from BaseHTTPServer import HTTPServer
|
import BaseHTTPServer
|
||||||
import SimpleHTTPServer
|
import SimpleHTTPServer
|
||||||
import urlparse
|
import urlparse
|
||||||
|
|
||||||
|
#GOTTMITTUNS
|
||||||
|
|
||||||
|
def _bare_address_string(self):
|
||||||
|
host, port = self.client_address[:2]
|
||||||
|
return '%s' % host
|
||||||
|
|
||||||
|
BaseHTTPServer.BaseHTTPRequestHandler.address_string = \
|
||||||
|
_bare_address_string
|
||||||
|
|
||||||
|
#END
|
||||||
|
|
||||||
class NodeServeHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
class NodeServeHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||||
|
|
||||||
@ -29,7 +39,7 @@ class NodeServeHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
|||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.wfile.write('404 - Not Found')
|
self.wfile.write('404 - Not Found')
|
||||||
|
|
||||||
class HTTPServerV6(HTTPServer):
|
class HTTPServerV6(BaseHTTPServer.HTTPServer):
|
||||||
address_family = socket.AF_INET6
|
address_family = socket.AF_INET6
|
||||||
|
|
||||||
class NodeServe():
|
class NodeServe():
|
||||||
|
Loading…
Reference in New Issue
Block a user