Browse Source

indentation

develop
Generic Username 11 years ago
parent
commit
7e9e68ed93
  1. 20
      main.py

20
main.py

@ -6,14 +6,15 @@ class Meshenger:
devices = [] #the list of all the nodes this this node has seen
serve_port = 13338
announce_port = 13337
own_ip = "0.0.0.0"
#own_ip = "0.0.0.0"
msg_dir = os.path.relpath('msg/')
def __init__(self):
os.system("echo 1 >> /proc/sys/net/ipv6/conf/br-lan/disable_ipv6")
#self.own_ip = self.get_ip_adress()
self.own_ip = "192.168.2.196"
self.own_ip = self.get_ip_adress()
#self.own_ip = "192.168.2.196"
while True:
@ -31,9 +32,10 @@ class Meshenger:
self.get_messages(device, nodepath)
print 'updating own index'
self.build_index()
#voeg toe aan eigen index --> build_index()
time.sleep(5)
def announce(self):
#announces it's existance to other nodes
@ -49,8 +51,6 @@ class Meshenger:
def discover(self):
# discovers other nodes by listening to the Meshenger announce port
#own_ip = get_ip_adress()
#port = 13337 # where do you expect to get a msg?
bufferSize = 1024 # whatever you need
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
@ -75,13 +75,15 @@ class Meshenger:
def build_index(self):
previous_index = []
current_index = os.listdir('msg/')
current_index = os.listdir(msg_dir)
if current_index != previous_index:
with open('index', 'wb') as index:
for message in os.listdir('msg/'):
for message in os.listdir(msg_dir):
index.write(message)
index.write('\n')
with open('index_last_update', 'wb') as indexupdate:
indexupdate.write(str(int(time.time())))
current_index = previous_index
def get_index(self,ip, path):
@ -95,7 +97,7 @@ class Meshenger:
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('msg/'), message)
messagepath = os.path.join(os.path.abspath(msg_dir), message)
if not os.path.exists(messagepath):
print 'downloading', message, 'to', messagepath
os.system('wget http://['+ip+'%adhoc0]:13338/msg/'+message+' -O '+messagepath)

Loading…
Cancel
Save