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 :
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
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
......
......@@ -5,6 +5,20 @@ from email.mime.text import MIMEText
from OpenSSL import crypto
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
# openssl req -nodes -new -x509 -key ca.key -set_serial 0x120010db80042 -days 365 -out ca.crt
......
......@@ -2,8 +2,10 @@ import os, random, traceback, time, struct, subprocess, operator, math
import plib, utils, db
log = None
smooth = 0.3 # this is used to smooth the traffic sampling. Lower value
# mean more smooth
smooth = 0.3 # this is used to smooth the traffic sampling. Lower value
# 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
......@@ -22,7 +24,7 @@ class Connection:
self.iface = iface
self.routes = 0
self._prefix = prefix
self._bandwidth = None
self.bandwidth = None
self._last_trafic = None
# TODO : update the stats
......@@ -49,14 +51,14 @@ class Connection:
if bool(self._last_trafic):
bw = (trafic - self._last_trafic) / (t -
self._last_trafic_update)
if bool(self._bandwidth):
self._bandwidth = ((1 - smooth) * self._bandwidth
if bool(self.bandwidth):
self.bandwidth = ((1 - smooth) * self.bandwidth
+ smooth * bw)
else:
self._bandwidth = bw
self.bandwidth = bw
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 = trafic
......@@ -107,9 +109,10 @@ class TunnelManager:
def _removeSomeTunnels(self):
# Get the candidates to killing
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)
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) -
self._client_count + self._refresh_count)]:
self._kill(prefix)
......
......@@ -174,6 +174,20 @@ def main():
pass
tunnel_manager.killAll()
return 0
except:
try:
router.kill()
except:
pass
try:
server_process.kill()
except:
pass
try:
tunnel_manager.killAll()
except:
pass
raise
if __name__ == "__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