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 Vifibnet is a daemon setting up a resilient virtual private network over the
internet 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 certificates. Then you should run setup.py on each clients tu prepare the
clients and then run vifibnet.py on each client clients and then run vifibnet.py on each client
...@@ -13,4 +13,3 @@ The organisation of the code ...@@ -13,4 +13,3 @@ The organisation of the code
tunnel.py To choose wich connection delete/keep/... tunnel.py To choose wich connection delete/keep/...
upnpigd.py To open a port upnpigd.py To open a port
import sqlite3, xmlrpclib, time import sqlite3, socket, xmlrpclib, time
import utils import utils
class PeerManager: class PeerManager:
...@@ -29,9 +29,14 @@ class PeerManager: ...@@ -29,9 +29,14 @@ class PeerManager:
def refresh(self): def refresh(self):
utils.log('Refreshing the peers DB', 2) utils.log('Refreshing the peers DB', 2)
self._declare() try:
self._populate() self._declare()
self.next_refresh = time.time() + self._refresh_time 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): def _declare(self):
if self._address != None: if self._address != None:
......
...@@ -42,9 +42,6 @@ def main(): ...@@ -42,9 +42,6 @@ def main():
used INTEGER NOT NULL DEFAULT 0, used INTEGER NOT NULL DEFAULT 0,
date INTEGER DEFAULT (strftime('%s', 'now')))""") date INTEGER DEFAULT (strftime('%s', 'now')))""")
db.execute("CREATE INDEX _peers_used ON peers(used)") 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: except sqlite3.OperationalError, e:
if e.args[0] == 'table peers already exists': if e.args[0] == 'table peers already exists':
print "Table peers already exists, leaving it as it is" print "Table peers already exists, leaving it as it is"
...@@ -52,6 +49,10 @@ def main(): ...@@ -52,6 +49,10 @@ def main():
print "sqlite3.OperationalError :" + e.args[0] print "sqlite3.OperationalError :" + e.args[0]
sys.exit(1) 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: if config.db_only:
sys.exit(0) sys.exit(0)
......
...@@ -116,6 +116,7 @@ def main(): ...@@ -116,6 +116,7 @@ def main():
server_process = plib.server(internal_ip, network, config.connection_count, config.dh, write_pipe, 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, 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)) 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 # main loop
try: 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