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
-s, --state directory
Path to the directory used for state files. State files include :
- 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
-v, --verbose level
......
......@@ -3,6 +3,7 @@ import argparse, math, random, select, smtplib, sqlite3, string, socket, time, t
from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler
from email.mime.text import MIMEText
from OpenSSL import crypto
from time import time
import utils
# To generate server ca and key with serial for 2001:db8:42::/48
......@@ -32,6 +33,9 @@ class main(object):
def __init__(self):
self.cert_duration = 365 * 86400
self.time_out = 86400
self.refresh_interval = 600
self.last_refresh = time()
# Command line parsing
parser = argparse.ArgumentParser(
......@@ -54,6 +58,7 @@ class main(object):
prefix text primary key not null,
address text not null,
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 (
token text primary key not null,
email text not null,
......@@ -193,6 +198,10 @@ class main(object):
assert 0 < n < 1000
client_ip = utils.binFromIp(client_address)
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"
return self.db.execute("SELECT prefix, address FROM peers ORDER BY random() LIMIT ?", (n,)).fetchall()
else:
......
......@@ -34,7 +34,7 @@ def getConfig():
help='Port on the machine to listen on for incomming connections')
_('--peers-db-refresh', default=3600, type=int,
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')
_('-s', '--state', default='/var/lib/vifibnet',
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