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: ...@@ -71,3 +71,10 @@ To be discussed:
enought DB to ensure we can still choose a peer as if it was choosen 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 directly from the server. The requiered db size can be calculated from
the number of connections and the refresh time. 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: ...@@ -57,7 +57,7 @@ class PeerManager:
def unusePeer(self, prefix): def unusePeer(self, prefix):
utils.log('Updating peers database : unusing peer ' + str(prefix), 5) 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): def handle_message(self, msg):
script_type, arg = msg.split() script_type, arg = msg.split()
...@@ -72,7 +72,7 @@ class PeerManager: ...@@ -72,7 +72,7 @@ class PeerManager:
[external_ip, external_port, 'tcp-client']] [external_ip, external_port, 'tcp-client']]
if self._address != new_address: if self._address != new_address:
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() self._declare()
else: else:
utils.log('Unknow message recieved from the openvpn pipe : ' + msg, 1) utils.log('Unknow message recieved from the openvpn pipe : ' + msg, 1)
...@@ -7,8 +7,7 @@ smooth = 0.3 ...@@ -7,8 +7,7 @@ smooth = 0.3
class Connection: class Connection:
def __init__(self, address, write_pipe, hello, iface, prefix, def __init__(self, address, write_pipe, hello, iface, prefix,
ovpn_args): ovpn_args):
self.process = plib.client(address, write_pipe, hello, self.process = plib.client(address, write_pipe, hello, '--dev', iface,
'--dev', iface, '--proto', proto, '--rport', str(port),
*ovpn_args, stdout=os.open(os.path.join(log, *ovpn_args, stdout=os.open(os.path.join(log,
'vifibnet.client.%s.log' % (prefix,)), 'vifibnet.client.%s.log' % (prefix,)),
os.O_WRONLY|os.O_CREAT|os.O_TRUNC) ) os.O_WRONLY|os.O_CREAT|os.O_TRUNC) )
...@@ -16,13 +15,14 @@ class Connection: ...@@ -16,13 +15,14 @@ class Connection:
self.iface = iface self.iface = iface
self._lastTrafic = self._getTrafic() self._lastTrafic = self._getTrafic()
self._bandwidth = None self._bandwidth = None
self._prefix = prefix
# TODO : update the stats # TODO : update the stats
def refresh(self): def refresh(self):
# Check that the connection is alive # Check that the connection is alive
if self.process.poll() != None: if self.process.poll() != None:
utils.log('Connection with %s has failed with return code %s' utils.log('Connection with %s has failed with return code %s'
% (prefix, self.process.returncode), 3) % (self._prefix, self.process.returncode), 3)
return False return False
trafic = self._getTrafic() trafic = self._getTrafic()
...@@ -40,7 +40,7 @@ class Connection: ...@@ -40,7 +40,7 @@ class Connection:
f_rx = open('/sys/class/net/%s/statistics/rx_bytes' % self.iface, 'r') 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') f_tx = open('/sys/class/net/%s/statistics/tx_bytes' % self.iface, 'r')
return int(f_rx.read()) + int(f_tx.read()) return int(f_rx.read()) + int(f_tx.read())
except Exception: # TODO : change this except Exception:
return 0 return 0
class TunnelManager: class TunnelManager:
...@@ -97,7 +97,7 @@ class TunnelManager: ...@@ -97,7 +97,7 @@ class TunnelManager:
try: try:
for prefix, address in self._peer_db.getUnusedPeers( for prefix, address in self._peer_db.getUnusedPeers(
self._client_count - len(self._connection_dict)): 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() iface = self.free_interface_set.pop()
self._connection_dict[prefix] = Connection(address, self._connection_dict[prefix] = Connection(address,
self._write_pipe, self._hello, iface, self._write_pipe, self._hello, iface,
......
...@@ -97,8 +97,8 @@ def main(): ...@@ -97,8 +97,8 @@ def main():
config.address = [[external_ip, external_port, 'udp'], config.address = [[external_ip, external_port, 'udp'],
[external_ip, external_port, 'tcp-client']] [external_ip, external_port, 'tcp-client']]
except Exception: except Exception:
utils.log('An atempt to forward a port via UPnP failed', 3) utils.log('An atempt to forward a port via UPnP failed', 4)
raise RuntimeError #raise RuntimeError => this shouldn't raise an error since upnp is not mandatory
peer_db = db.PeerManager(config.db, config.server, config.server_port, peer_db = db.PeerManager(config.db, config.server, config.server_port,
config.peers_db_refresh, config.address, internal_ip, prefix, manual, 200) 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