Commit e661f4d5 authored by Ulysse Beaugnon's avatar Ulysse Beaugnon

The trafic is now taken into account to choose the tunnel to delete

openvpns and babeld should now exit correctly
parent ea9d24b8
...@@ -11,11 +11,6 @@ To be done : ...@@ -11,11 +11,6 @@ To be done :
To be discussed: To be discussed:
G : There is a blacklist system now ( blacklisted prefixes are deleted from
the peers database ). Since all nodes whose packets are routed through
the local network are blacklisted, I think we should reset the blacklist
from time to time....
U : Babel seems to be very long to establish the routes : maybe we should U : Babel seems to be very long to establish the routes : maybe we should
tell him thant we are not on a wired network but on a mobile network ? tell him thant we are not on a wired network but on a mobile network ?
G : babel establish routes quickly enough i'd say. There are two new G : babel establish routes quickly enough i'd say. There are two new
......
...@@ -5,6 +5,20 @@ from email.mime.text import MIMEText ...@@ -5,6 +5,20 @@ from email.mime.text import MIMEText
from OpenSSL import crypto from OpenSSL import crypto
import utils import utils
# Fix for librpcxml to avoid doing reverse dns on each request
# it was causing a 10s delay on each request when no reverse DNS was avalaible
# for tis IP
import BaseHTTPServer
def not_insane_address_string(self):
host, port = self.client_address[:2]
return '%s (reverse DNS disabled)' % host # used to call: socket.getfqdn(host)
BaseHTTPServer.BaseHTTPRequestHandler.address_string = not_insane_address_string
# To generate server ca and key with serial for 2001:db8:42::/48 # 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 # openssl req -nodes -new -x509 -key ca.key -set_serial 0x120010db80042 -days 365 -out ca.crt
......
...@@ -4,6 +4,8 @@ import plib, utils, db ...@@ -4,6 +4,8 @@ import plib, utils, db
log = None log = None
smooth = 0.3 # this is used to smooth the traffic sampling. Lower value smooth = 0.3 # this is used to smooth the traffic sampling. Lower value
# mean more smooth # mean more smooth
protected = 0.2 # ratio of the tunnels protected against kill because they are
# used a lot
# Be carfull the refresh interval should let the routes be established # Be carfull the refresh interval should let the routes be established
...@@ -22,7 +24,7 @@ class Connection: ...@@ -22,7 +24,7 @@ class Connection:
self.iface = iface self.iface = iface
self.routes = 0 self.routes = 0
self._prefix = prefix self._prefix = prefix
self._bandwidth = None self.bandwidth = None
self._last_trafic = None self._last_trafic = None
# TODO : update the stats # TODO : update the stats
...@@ -49,14 +51,14 @@ class Connection: ...@@ -49,14 +51,14 @@ class Connection:
if bool(self._last_trafic): if bool(self._last_trafic):
bw = (trafic - self._last_trafic) / (t - bw = (trafic - self._last_trafic) / (t -
self._last_trafic_update) self._last_trafic_update)
if bool(self._bandwidth): if bool(self.bandwidth):
self._bandwidth = ((1 - smooth) * self._bandwidth self.bandwidth = ((1 - smooth) * self.bandwidth
+ smooth * bw) + smooth * bw)
else: else:
self._bandwidth = bw self.bandwidth = bw
utils.log('New bandwidth calculated on iface %s : %s' % utils.log('New bandwidth calculated on iface %s : %s' %
(self.iface, self._bandwidth), 4) (self.iface, self.bandwidth), 4)
self._last_trafic_update = t self._last_trafic_update = t
self._last_trafic = trafic self._last_trafic = trafic
...@@ -107,9 +109,10 @@ class TunnelManager: ...@@ -107,9 +109,10 @@ class TunnelManager:
def _removeSomeTunnels(self): def _removeSomeTunnels(self):
# Get the candidates to killing # Get the candidates to killing
candidates = sorted(self._connection_dict, key=lambda p: candidates = sorted(self._connection_dict, key=lambda p:
self._connection_dict[p].bandwidth)
candidates = sorted(candidates[0: int(math.ceil((1 - protected)
* len(candidates)))], key=lambda p:
self._connection_dict[p].routes) self._connection_dict[p].routes)
print max(0, len(self._connection_dict) - self._client_count + self._refresh_count) # DEBUG
print self._client_count
for prefix in candidates[0: max(0, len(self._connection_dict) - for prefix in candidates[0: max(0, len(self._connection_dict) -
self._client_count + self._refresh_count)]: self._client_count + self._refresh_count)]:
self._kill(prefix) self._kill(prefix)
......
...@@ -174,6 +174,20 @@ def main(): ...@@ -174,6 +174,20 @@ def main():
pass pass
tunnel_manager.killAll() tunnel_manager.killAll()
return 0 return 0
except:
try:
router.kill()
except:
pass
try:
server_process.kill()
except:
pass
try:
tunnel_manager.killAll()
except:
pass
raise
if __name__ == "__main__": if __name__ == "__main__":
main() main()
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