Commit d0f47075 authored by Guillaume Bury's avatar Guillaume Bury

Cleaner server connection

parent 49685121
Vifibnet is a daemon setting up a resilient virtual private network over the
internet
To use vifibnet, you need to launch the registry.py on a server to provide the
To use vifibnet, you need to launch the registry.py on a server to provide the
certificates. Then you should run setup.py on each clients tu prepare the
clients and then run vifibnet.py on each client
......@@ -13,4 +13,3 @@ The organisation of the code
tunnel.py To choose wich connection delete/keep/...
upnpigd.py To open a port
import sqlite3, xmlrpclib, time
import sqlite3, socket, xmlrpclib, time
import utils
class PeerManager:
......@@ -29,9 +29,14 @@ class PeerManager:
def refresh(self):
utils.log('Refreshing the peers DB', 2)
self._declare()
self._populate()
self.next_refresh = time.time() + self._refresh_time
try:
self._declare()
self._populate()
self.next_refresh = time.time() + self._refresh_time
except socket.error, e:
utils.log(str(e), 3)
utils.log('Connection to server failed, retrying in 30s', 2)
self.next_refresh = time.time() + 30
def _declare(self):
if self._address != None:
......
......@@ -42,9 +42,6 @@ def main():
used INTEGER NOT NULL DEFAULT 0,
date INTEGER DEFAULT (strftime('%s', 'now')))""")
db.execute("CREATE INDEX _peers_used ON peers(used)")
if not config.no_boot:
prefix, address = s.getBootstrapPeer()
db.execute("INSERT INTO peers (prefix, address) VALUES (?,?)", (prefix, address))
except sqlite3.OperationalError, e:
if e.args[0] == 'table peers already exists':
print "Table peers already exists, leaving it as it is"
......@@ -52,6 +49,10 @@ def main():
print "sqlite3.OperationalError :" + e.args[0]
sys.exit(1)
if not config.no_boot:
prefix, address = s.getBootstrapPeer()
db.execute("INSERT INTO peers (prefix, address) VALUES (?,?)", (prefix, address))
if config.db_only:
sys.exit(0)
......
......@@ -116,6 +116,7 @@ def main():
server_process = plib.server(internal_ip, network, config.connection_count, config.dh, write_pipe,
config.internal_port, config.proto, config.hello, '--dev', 'vifibnet', *openvpn_args,
stdout=os.open(os.path.join(config.log, 'vifibnet.server.log'), os.O_WRONLY | os.O_CREAT | os.O_TRUNC))
tunnel_manager.refresh()
# main loop
try:
......
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