Commit f85a3905 authored by Ulysse Beaugnon's avatar Ulysse Beaugnon

Prepare the peer db to separate the server advertisment and the getPeersLists

parent 35b9ec40
...@@ -8,12 +8,11 @@ Bugs : ...@@ -8,12 +8,11 @@ Bugs :
To be done : To be done :
Replace comments at the beginning of functions with docstrings & give all fn docstrings Replace comments at the beginning of functions with docstrings & give all fn docstrings
Do a clean-up in the import
Remove the parameters to choose the number of clients
Use the server events ( client connection/deconnection ) to do something usefull Use the server events ( client connection/deconnection ) to do something usefull
In peers DB, remove some peers when they are too many of them In peers DB, remove some peers when they are too many of them
Contact the server using vifibnet and not the underlying network when possible Contact the server using vifibnet and not the underlying network when possible
Use a timeout for the peersDB Use a timeout for the peersDB
The peer DB size should depend on the number of connection and the refresh time
To be discuss: To be discuss:
U : Remove the --no-boot option since we know when no node is avalaible U : Remove the --no-boot option since we know when no node is avalaible
...@@ -21,16 +20,10 @@ To be discuss: ...@@ -21,16 +20,10 @@ To be discuss:
irl it should never happen, no-boot is a debug option irl it should never happen, no-boot is a debug option
U : Ok, but the server knows when no peers is avalaible, doesn't he ? U : Ok, but the server knows when no peers is avalaible, doesn't he ?
How we choose which protocol we use :
IMO, we should use UDP. I've read many times than TCP other TCP can be catastrophic in terme of performance
Every time a packet is lost, it is resend 2 times, one for each TCP tunnel
And many GW allow UDP port forwarding (for bittorent, Xbox, ...) but not TCP port forwarding
Use peers_db.populate(100) every once in a while ?
G : yes but be warry of the refresh time ( populate the db once every 20s is bad.. )
U : I agree. Once evry hours should be sufficient, and when their too few peers avalaible.
G : don't reconnect to server each time we repopulate in peers_db ? G : don't reconnect to server each time we repopulate in peers_db ?
U : we might recontact the server evry 1H or even less. So i think it is a good thing not to keep the connection alive U : From what I've read on the internet, when you create a server object, you don't connect to the server,
You only connect to the server once you send a request for a methode and then you can automatically use the same connection for 15sec
Is the bootstrap node used ?
Why --ping-exit had been removed form openvpn args ? without this we can have zombie connections We should separate the getNodesList and advertise options
\ No newline at end of file
...@@ -4,35 +4,44 @@ import utils ...@@ -4,35 +4,44 @@ import utils
class PeerManager: class PeerManager:
def __init__(self, dbPath, server, port, refresh_time, external_ip): def __init__(self, dbPath, server, server_port, refresh_time, external_ip, internal_ip, port, proto, db_size):
self._server_port = server_port
self._refresh_time = refresh_time
self._external_ip = external_ip
self._internal_ip = internal_ip
self._external_port = port
self._proto = proto
self._db_size = db_size
utils.log('Connectiong to peers database', 4) utils.log('Connectiong to peers database', 4)
self._db = sqlite3.connect(dbPath, isolation_level=None) self._db = sqlite3.connect(dbPath, isolation_level=None)
self._server = server self._server = server
self._server_port = port
self._refresh_time = refresh_time
self._external_ip = external_ip
utils.log('Preparing peers database', 4) utils.log('Preparing peers database', 4)
try: try:
self._db.execute("UPDATE peers SET used = 0") self._db.execute("UPDATE peers SET used = 0")
except sqlite3.OperationalError, e: except sqlite3.OperationalError, e:
if e.args[0] == 'no such table: peers': if e.args[0] == 'no such table: peers':
raise RuntimeError raise RuntimeError
self.next_refresh = time.time() self.next_refresh = time.time()
def populate(self, n, internal_ip, port, proto): def refresh(self):
self._populate()
self.next_refresh = time.time() + self._refresh_time
def _populate(self):
if self._external_ip != None: if self._external_ip != None:
address = (internal_ip, self._external_ip, port, proto) address = (self._internal_ip, self._external_ip, self._external_port, self._proto)
else: else:
address = 0 address = 0
utils.log('Connecting to remote server', 3) utils.log('Connecting to remote server', 3)
self._proxy = xmlrpclib.ServerProxy('http://%s:%u' % (self._server, self._server_port)) self._proxy = xmlrpclib.ServerProxy('http://%s:%u' % (self._server, self._server_port))
utils.log('Updating peers database : populating', 2) utils.log('Updating peers database : populating', 2)
new_peer_list = self._proxy.getPeerList(n, address) new_peer_list = self._proxy.getPeerList(self._db_size, address)
utils.log('New peers recieved from %s' % self._server, 5) utils.log('New peers recieved from %s' % self._server, 5)
self._db.executemany("INSERT OR IGNORE INTO peers (ip, port, proto, used) VALUES (?,?,?,0)", new_peer_list) self._db.executemany("INSERT OR IGNORE INTO peers (ip, port, proto, used) VALUES (?,?,?,0)", new_peer_list)
if self._external_ip != None: if self._external_ip != None:
self._db.execute("DELETE FROM peers WHERE ip = ?", (self._external_ip,)) self._db.execute("DELETE FROM peers WHERE ip = ?", (self._external_ip,))
self.next_refresh = time.time() + self._refresh_time
utils.log('New peers : %s' % ', '.join(map(str, new_peer_list)), 5) utils.log('New peers : %s' % ', '.join(map(str, new_peer_list)), 5)
def getUnusedPeers(self, nPeers): def getUnusedPeers(self, nPeers):
......
...@@ -65,7 +65,8 @@ def main(): ...@@ -65,7 +65,8 @@ def main():
read_pipe = os.fdopen(r_pipe) read_pipe = os.fdopen(r_pipe)
# Init db and tunnels # Init db and tunnels
peer_db = db.PeerManager(config.db, config.server, config.server_port, config.peers_db_refresh, config.external_ip) peer_db = db.PeerManager(config.db, config.server, config.server_port, config.peers_db_refresh,
config.external_ip, internal_ip, config.external_port, config.proto, 200)
tunnel_manager = tunnel.TunnelManager(write_pipe, peer_db, openvpn_args, config.tunnel_refresh, config.connection_count, config.refresh_rate) tunnel_manager = tunnel.TunnelManager(write_pipe, peer_db, openvpn_args, config.tunnel_refresh, config.connection_count, config.refresh_rate)
# Launch babel on all interfaces. WARNING : you have to be root to start babeld # Launch babel on all interfaces. WARNING : you have to be root to start babeld
...@@ -87,7 +88,7 @@ def main(): ...@@ -87,7 +88,7 @@ def main():
if ready: if ready:
peer_db.handle_message(read_pipe.readline()) peer_db.handle_message(read_pipe.readline())
if time.time() >= peer_db.next_refresh: if time.time() >= peer_db.next_refresh:
peer_db.populate(200, internal_ip, config.external_port, config.proto) peer_db.refresh()
if time.time() >= tunnel_manager.next_refresh: if time.time() >= tunnel_manager.next_refresh:
tunnel_manager.refresh() tunnel_manager.refresh()
except KeyboardInterrupt: except KeyboardInterrupt:
......
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