Commit b7453ca8 authored by Julien Muchembled's avatar Julien Muchembled

Use lowercase for variables

parent ed6df9d4
...@@ -3,7 +3,7 @@ import utils ...@@ -3,7 +3,7 @@ import utils
class PeerManager: class PeerManager:
def __init__(self, dbPath, server, server_port, refresh_time, external_ip, internal_ip, port, proto, db_size): def __init__(self, db_path, server, server_port, refresh_time, external_ip, internal_ip, port, proto, db_size):
self._refresh_time = refresh_time self._refresh_time = refresh_time
self._external_ip = external_ip self._external_ip = external_ip
self._internal_ip = internal_ip self._internal_ip = internal_ip
...@@ -13,7 +13,7 @@ class PeerManager: ...@@ -13,7 +13,7 @@ class PeerManager:
self._proxy = xmlrpclib.ServerProxy('http://%s:%u' % (server, server_port)) self._proxy = xmlrpclib.ServerProxy('http://%s:%u' % (server, server_port))
utils.log('Connectiong to peers database', 4) utils.log('Connectiong to peers database', 4)
self._db = sqlite3.connect(dbPath, isolation_level=None) self._db = sqlite3.connect(db_path, isolation_level=None)
utils.log('Preparing peers database', 4) utils.log('Preparing peers database', 4)
try: try:
self._db.execute("UPDATE peers SET used = 0") self._db.execute("UPDATE peers SET used = 0")
...@@ -44,9 +44,9 @@ class PeerManager: ...@@ -44,9 +44,9 @@ class PeerManager:
self._db.execute("DELETE FROM peers WHERE ip = ?", (self._external_ip,)) self._db.execute("DELETE FROM peers WHERE ip = ?", (self._external_ip,))
utils.log('New peers : %s' % ', '.join(map(str, new_peer_list)), 5) utils.log('New peers : %s' % ', '.join(map(str, new_peer_list)), 5)
def getUnusedPeers(self, nPeers): def getUnusedPeers(self, peer_count):
return self._db.execute("SELECT id, ip, port, proto FROM peers WHERE used = 0 " return self._db.execute("SELECT id, ip, port, proto FROM peers WHERE used = 0 "
"ORDER BY RANDOM() LIMIT ?", (nPeers,)) "ORDER BY RANDOM() LIMIT ?", (peer_count,))
def usePeer(self, id): def usePeer(self, id):
utils.log('Updating peers database : using peer ' + str(id), 5) utils.log('Updating peers database : using peer ' + str(id), 5)
......
...@@ -21,12 +21,12 @@ def openvpn(*args, **kw): ...@@ -21,12 +21,12 @@ def openvpn(*args, **kw):
# TODO : set iface up when creating a server/client # TODO : set iface up when creating a server/client
# ! check working directory before launching up script ? # ! check working directory before launching up script ?
def server(serverIp, network, max_clients, dh_path, pipe_fd, port, proto, *args, **kw): def server(server_ip, network, max_clients, dh_path, pipe_fd, port, proto, *args, **kw):
utils.log('Starting server', 3) utils.log('Starting server', 3)
return openvpn( return openvpn(
'--tls-server', '--tls-server',
'--mode', 'server', '--mode', 'server',
'--up', 'ovpn-server %s/%u' % (serverIp, len(network)), '--up', 'ovpn-server %s/%u' % (server_ip, len(network)),
'--client-connect', 'ovpn-server ' + str(pipe_fd), '--client-connect', 'ovpn-server ' + str(pipe_fd),
'--client-disconnect', 'ovpn-server ' + str(pipe_fd), '--client-disconnect', 'ovpn-server ' + str(pipe_fd),
'--dh', dh_path, '--dh', dh_path,
...@@ -35,12 +35,12 @@ def server(serverIp, network, max_clients, dh_path, pipe_fd, port, proto, *args, ...@@ -35,12 +35,12 @@ def server(serverIp, network, max_clients, dh_path, pipe_fd, port, proto, *args,
'--proto', proto, '--proto', proto,
*args, **kw) *args, **kw)
def client(serverIp, pipe_fd, *args, **kw): def client(server_ip, pipe_fd, *args, **kw):
utils.log('Starting client', 5) utils.log('Starting client', 5)
return openvpn( return openvpn(
'--nobind', '--nobind',
'--client', '--client',
'--remote', serverIp, '--remote', server_ip,
'--up', 'ovpn-client', '--up', 'ovpn-client',
'--route-up', 'ovpn-client ' + str(pipe_fd), '--route-up', 'ovpn-client ' + str(pipe_fd),
*args, **kw) *args, **kw)
......
...@@ -18,17 +18,17 @@ class RingMember: ...@@ -18,17 +18,17 @@ class RingMember:
class Ring: class Ring:
def __init__(self, entryPoint): def __init__(self, entry_point):
# initialize the connection # initialize the connection
self.sock = socket.socket( socket.AF_INET6, socket.SOCK_DGRAM ) self.sock = socket.socket( socket.AF_INET6, socket.SOCK_DGRAM )
self.sock.bind(('', 0)) self.sock.bind(('', 0))
self.me = RingMember(uuid.uuid1().int ,'', self.sock.getsockname()[1]) # TODO : get the address self.me = RingMember(uuid.uuid1().int ,'', self.sock.getsockname()[1]) # TODO : get the address
# to enter the ring # to enter the ring
self.predecessor = None self.predecessor = None
if entryPoint == None: if entry_point == None:
self.successor = self.me self.successor = self.me
else: else:
self.send('FIND_SUCCESSOR ' + str(self.me.id) + ' ' + self.me.toString(), entryPoint) self.send('FIND_SUCCESSOR ' + str(self.me.id) + ' ' + self.me.toString(), entry_point)
log.log('Init the ring with me = ' + self.me.toString(), 3) log.log('Init the ring with me = ' + self.me.toString(), 3)
# TODO : # TODO :
...@@ -71,6 +71,7 @@ class Ring: ...@@ -71,6 +71,7 @@ class Ring:
# to be called periodically # to be called periodically
# def fixFingers(self) # def fixFingers(self)
# # XXX: naming - should be finger_count
# next = (next + 1) mod (nFingers) # Or Random, cf google # next = (next + 1) mod (nFingers) # Or Random, cf google
# finger[next] = find_successor(n+2^{next-1}); # finger[next] = find_successor(n+2^{next-1});
......
...@@ -2,18 +2,18 @@ import miniupnpc ...@@ -2,18 +2,18 @@ import miniupnpc
import socket import socket
# return (address, port) # return (address, port)
def ForwardViaUPnP(localPort): def ForwardViaUPnP(local_port):
u = miniupnpc.UPnP() u = miniupnpc.UPnP()
u.discoverdelay = 200 u.discoverdelay = 200
u.discover() u.discover()
u.selectigd() u.selectigd()
externalPort = 1194 external_port = 1194
while True: while True:
while u.getspecificportmapping(externalPort, 'UDP') != None: while u.getspecificportmapping(external_port, 'UDP') != None:
externalPort = max(externalPort + 1, 49152) external_port = max(externalPort + 1, 49152)
if externalPort == 65536: if external_port == 65536:
raise Exception raise Exception
if u.addportmapping(externalPort, 'UDP', u.lanaddr, localPort, 'Vifib openvpn server', ''): if u.addportmapping(external_port, 'UDP', u.lanaddr, local_port, 'Vifib openvpn server', ''):
return (u.externalipaddress(), externalPort) return (u.externalipaddress(), external_port)
# TODO : specify a lease duration # TODO : specify a lease duration
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