Commit 8e011be5 authored by Ulysse Beaugnon's avatar Ulysse Beaugnon

Solving all the bugs that were their when I arrived this morning.

parent aefcb9de
......@@ -71,3 +71,10 @@ To be discussed:
enought DB to ensure we can still choose a peer as if it was choosen
directly from the server. The requiered db size can be calculated from
the number of connections and the refresh time.
U : Why are --ip and internal-port mutually exclusive ?
Currently upnp only forward via UDP. Should he also forward via TCP ?
Why dont we only use UDP ?
No error should be raised when no upnp is detected : we should allow
machines having public IP to do an automatic configuration using the
discovery by an other peer
......@@ -57,7 +57,7 @@ class PeerManager:
def unusePeer(self, prefix):
utils.log('Updating peers database : unusing peer ' + str(prefix), 5)
self._db.execute("UPDATE peers SET used = 0 WHERE id = ?", (prefix,))
self._db.execute("UPDATE peers SET used = 0 WHERE prefix = ?", (prefix,))
def handle_message(self, msg):
script_type, arg = msg.split()
......@@ -72,7 +72,7 @@ class PeerManager:
[external_ip, external_port, 'tcp-client']]
if self._address != new_address:
self._address = new_address
utils.log('Received new external configuration : %:%s' % (external_ip, external_port), 3)
utils.log('Received new external configuration : %s:%s' % (external_ip, external_port), 3)
self._declare()
else:
utils.log('Unknow message recieved from the openvpn pipe : ' + msg, 1)
......@@ -7,8 +7,7 @@ smooth = 0.3
class Connection:
def __init__(self, address, write_pipe, hello, iface, prefix,
ovpn_args):
self.process = plib.client(address, write_pipe, hello,
'--dev', iface, '--proto', proto, '--rport', str(port),
self.process = plib.client(address, write_pipe, hello, '--dev', iface,
*ovpn_args, stdout=os.open(os.path.join(log,
'vifibnet.client.%s.log' % (prefix,)),
os.O_WRONLY|os.O_CREAT|os.O_TRUNC) )
......@@ -16,13 +15,14 @@ class Connection:
self.iface = iface
self._lastTrafic = self._getTrafic()
self._bandwidth = None
self._prefix = prefix
# TODO : update the stats
def refresh(self):
# Check that the connection is alive
if self.process.poll() != None:
utils.log('Connection with %s has failed with return code %s'
% (prefix, self.process.returncode), 3)
% (self._prefix, self.process.returncode), 3)
return False
trafic = self._getTrafic()
......@@ -40,7 +40,7 @@ class Connection:
f_rx = open('/sys/class/net/%s/statistics/rx_bytes' % self.iface, 'r')
f_tx = open('/sys/class/net/%s/statistics/tx_bytes' % self.iface, 'r')
return int(f_rx.read()) + int(f_tx.read())
except Exception: # TODO : change this
except Exception:
return 0
class TunnelManager:
......@@ -97,7 +97,7 @@ class TunnelManager:
try:
for prefix, address in self._peer_db.getUnusedPeers(
self._client_count - len(self._connection_dict)):
utils.log('Establishing a connection with %s (%s:%s)' % prefix, 2)
utils.log('Establishing a connection with %s' % prefix, 2)
iface = self.free_interface_set.pop()
self._connection_dict[prefix] = Connection(address,
self._write_pipe, self._hello, iface,
......@@ -105,6 +105,6 @@ class TunnelManager:
self._peer_db.usePeer(prefix)
except KeyError:
utils.log("""Can't establish connection with %s
: no available interface""" % prefix, 2)
: no available interface""" % prefix, 2)
except Exception:
traceback.print_exc()
......@@ -97,8 +97,8 @@ def main():
config.address = [[external_ip, external_port, 'udp'],
[external_ip, external_port, 'tcp-client']]
except Exception:
utils.log('An atempt to forward a port via UPnP failed', 3)
raise RuntimeError
utils.log('An atempt to forward a port via UPnP failed', 4)
#raise RuntimeError => this shouldn't raise an error since upnp is not mandatory
peer_db = db.PeerManager(config.db, config.server, config.server_port,
config.peers_db_refresh, config.address, internal_ip, prefix, manual, 200)
......
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