Commit f6e96b71 authored by Ulysse Beaugnon's avatar Ulysse Beaugnon

Put all annexes python files into a subfolder

parent 7072b80f
import socket, uuid
import log
# create an upd socket
# listen on it for incoming messages and forward them
# manage the forwarding routing table
# the peudo-code can be found here http://en.wikipedia.org/wiki/Chord_%28peer-to-peer%29
class RingMember:
def __init__(self, id, ip, port):
self.port = port
self.ip = ip
self.id = id
def toString(self):
return str(self.id) + ' ' + self.ip + ' ' + str(self.port)
class Ring:
def __init__(self, entry_point):
# initialize the connection
self.sock = socket.socket( socket.AF_INET6, socket.SOCK_DGRAM )
self.sock.bind(('', 0))
self.me = RingMember(uuid.uuid1().int ,'', self.sock.getsockname()[1]) # TODO : get the address
# to enter the ring
self.predecessor = None
if entry_point == None:
self.successor = self.me
else:
self.send('FIND_SUCCESSOR ' + str(self.me.id) + ' ' + self.me.toString(), entry_point)
log.log('Init the ring with me = ' + self.me.toString(), 3)
# TODO :
def handleMessages(self):
# TODO : switch to log
log.log('Handling messages ...', 3)
pass
def send(self, message, target):
# TODO : switch to log
log.log('Sending : ' + message + ' to ' + target.toString(), 5)
self.sock.sendto(message, (target.ip, target.port))
def findSuccessor(self, id, sender):
if self.id < id and id <= self.successor:
self.send('SUCCESSOR_IS ' + self.successor.toString(), sender)
else:
self.send('FIND_SUCCESSOR ' + str(id) + ' ' + sender.toString(), successor) # TODO : use the fingers
# Just copying the pseudocode from wikipedia, I will make it work later
# Possible messages (just for the creation of the ring) :
#
# find_successor $id $sender : $sender whants the IP of the successor of $id
# successor_is $ip $successor
# get_predecessor
# notify $sender_ip $sender_id
# PING
# called periodically
# pb : how to fix successor
# def stabilize(self):
# x = SEND get_predecessor TO self.successor
# if n < x && x < self.successor:
# self.successor = x
# SEND notify self.ip, self.id TO self.successor
# def notify(self, n2)
# if self.predecessor == None || (predecessor < n2 && n2 < n):
# self.predecessor = n2
# to be called periodically
# def fixFingers(self)
# # XXX: naming - should be finger_count
# next = (next + 1) mod (nFingers) # Or Random, cf google
# finger[next] = find_successor(n+2^{next-1});
# to be called periodically
# def checkPredecessor(self)
# if NO PING from self.predecessor:
# self.predecessor = None
......@@ -4,7 +4,7 @@ import subprocess, time, threading, traceback, errno, logging, os, xmlrpclib
from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler
from email.mime.text import MIMEText
from OpenSSL import crypto
import utils
from re6st import utils
# To generate server ca and key with serial for 2001:db8:42::/48
# openssl req -nodes -new -x509 -key ca.key -set_serial 0x120010db80042 -days 365 -out ca.crt
......
......@@ -3,6 +3,7 @@ import utils
verbose = 0
def openvpn(hello_interval, *args, **kw):
args = ['openvpn',
'--dev-type', 'tap',
......@@ -16,6 +17,7 @@ def openvpn(hello_interval, *args, **kw):
logging.trace('%s' % (args,))
return subprocess.Popen(args, **kw)
def server(server_ip, ip_length, max_clients, dh_path, pipe_fd, port, proto, hello_interval, *args, **kw):
logging.debug('Starting server...')
return openvpn(hello_interval,
......@@ -30,12 +32,13 @@ def server(server_ip, ip_length, max_clients, dh_path, pipe_fd, port, proto, hel
'--proto', proto,
*args, **kw)
def client(server_address, pipe_fd, hello_interval, *args, **kw):
logging.debug('Starting client...')
remote = ['--nobind',
'--client',
'--up', 'ovpn-client',
'--route-up', 'ovpn-client ' + str(pipe_fd) ]
'--route-up', 'ovpn-client ' + str(pipe_fd)]
try:
for ip, port, proto in utils.address_list(server_address):
remote += '--remote', ip, port, proto
......@@ -45,6 +48,7 @@ def client(server_address, pipe_fd, hello_interval, *args, **kw):
remote += args
return openvpn(hello_interval, *remote, **kw)
def router(network, internal_ip, interface_list,
wireless, hello_interval, state_path, **kw):
logging.info('Starting babel...')
......@@ -70,4 +74,3 @@ def router(network, internal_ip, interface_list,
args = args + interface_list
logging.trace('%s' % args)
return subprocess.Popen(args, **kw)
import os, random, traceback, time, struct, subprocess, operator, math, logging
import plib, utils, db
import os, traceback, time, subprocess, math, logging
import plib
smooth = 0.3 # this is used to smooth the traffic sampling. Lower value
# mean more smooth
......
#!/usr/bin/env python
import argparse, errno, os, select, subprocess, sqlite3, time, logging
from argparse import ArgumentParser
import db, plib, upnpigd, utils, tunnel
from re6st import plib, utils, db, upnpigd, tunnel
class ArgParser(ArgumentParser):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment