Commit 356e1468 authored by Guillaume Bury's avatar Guillaume Bury

Added time-out for peers in registry

parent 03e3061a
...@@ -107,7 +107,10 @@ OPTIONS : VIFIBNET.PY ...@@ -107,7 +107,10 @@ OPTIONS : VIFIBNET.PY
-s, --state directory -s, --state directory
Path to the directory used for state files. State files include : Path to the directory used for state files. State files include :
- peers.db : the peers db used to establish connection - peers.db : the peers db used to establish connection
- vifibnet.babeld.state : babeld state file - vifibnet.babeld.state : babeld state file ( created if does not
exists, overriden if exists )
There must be a valid peers db file ( named peers.db ) in the
directory. A valid peers db file can be created with setup.py
Default : /var/lib/vifibnet Default : /var/lib/vifibnet
-v, --verbose level -v, --verbose level
......
...@@ -3,6 +3,7 @@ import argparse, math, random, select, smtplib, sqlite3, string, socket, time, t ...@@ -3,6 +3,7 @@ import argparse, math, random, select, smtplib, sqlite3, string, socket, time, t
from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler
from email.mime.text import MIMEText from email.mime.text import MIMEText
from OpenSSL import crypto from OpenSSL import crypto
from time import time
import utils import utils
# 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
...@@ -32,6 +33,9 @@ class main(object): ...@@ -32,6 +33,9 @@ class main(object):
def __init__(self): def __init__(self):
self.cert_duration = 365 * 86400 self.cert_duration = 365 * 86400
self.time_out = 86400
self.refresh_interval = 600
self.last_refresh = time()
# Command line parsing # Command line parsing
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
...@@ -54,6 +58,7 @@ class main(object): ...@@ -54,6 +58,7 @@ class main(object):
prefix text primary key not null, prefix text primary key not null,
address text not null, address text not null,
date integer default (strftime('%s','now')))""") date integer default (strftime('%s','now')))""")
self.db.execute("CREATE INDEX IF NOT EXISTS peers_ping ON peers(date)")
self.db.execute("""CREATE TABLE IF NOT EXISTS tokens ( self.db.execute("""CREATE TABLE IF NOT EXISTS tokens (
token text primary key not null, token text primary key not null,
email text not null, email text not null,
...@@ -193,6 +198,10 @@ class main(object): ...@@ -193,6 +198,10 @@ class main(object):
assert 0 < n < 1000 assert 0 < n < 1000
client_ip = utils.binFromIp(client_address) client_ip = utils.binFromIp(client_address)
if client_ip.startswith(self.network): if client_ip.startswith(self.network):
if time() > self.last_refresh + self.refresh_interval:
print "refreshing peers for dead ones"
self.db.execute("DELETE FROM peers WHERE ( date + ? ) <= CAST (strftime('%s', 'now') AS INTEGER)", (self.time_out,))
self.last_refesh = time()
print "sending peers" print "sending peers"
return self.db.execute("SELECT prefix, address FROM peers ORDER BY random() LIMIT ?", (n,)).fetchall() return self.db.execute("SELECT prefix, address FROM peers ORDER BY random() LIMIT ?", (n,)).fetchall()
else: else:
......
...@@ -34,7 +34,7 @@ def getConfig(): ...@@ -34,7 +34,7 @@ def getConfig():
help='Port on the machine to listen on for incomming connections') help='Port on the machine to listen on for incomming connections')
_('--peers-db-refresh', default=3600, type=int, _('--peers-db-refresh', default=3600, type=int,
help='the time (seconds) to wait before refreshing the peers db') help='the time (seconds) to wait before refreshing the peers db')
_('-l', '-log', default='/var/log', _('-l', '--log', default='/var/log',
help='Path to vifibnet logs directory') help='Path to vifibnet logs directory')
_('-s', '--state', default='/var/lib/vifibnet', _('-s', '--state', default='/var/lib/vifibnet',
help='Path to VPN state directory') help='Path to VPN state directory')
......
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