Commit e79bb78e authored by Julien Muchembled's avatar Julien Muchembled

Fix bug preventing the registry to send its own address for bootstrap

parent b6d43ac1
...@@ -69,14 +69,16 @@ class PeerDB(object): ...@@ -69,14 +69,16 @@ class PeerDB(object):
(prefix,)).fetchone() (prefix,)).fetchone()
return r and r[0] return r and r[0]
def getPeerList(self, failed=0):
# Exclude our own address from results in case it is there, which may # Exclude our own address from results in case it is there, which may
# happen if a node change its certificate without clearing the cache. # happen if a node change its certificate without clearing the cache.
# IOW, one should probably always put our own address there. # IOW, one should probably always put our own address there.
return self._db.execute( _get_peer_sql = "SELECT %s FROM peer, volatile.stat" \
"SELECT prefix, address FROM peer, volatile.stat" " WHERE prefix=peer AND prefix!=? AND try=?"
" WHERE prefix=peer AND prefix!=? AND try=? ORDER BY RANDOM()", def getPeerList(self, failed=0, __sql=_get_peer_sql % "prefix, address"
(self._prefix, failed)) + " ORDER BY RANDOM()"):
return self._db.execute(__sql, (self._prefix, failed))
def getPeerCount(self, failed=0, __sql=_get_peer_sql % "COUNT(*)"):
return self._db.execute(__sql, (self._prefix, failed)).next()[0]
def getBootstrapPeer(self): def getBootstrapPeer(self):
logging.info('Getting Boot peer...') logging.info('Getting Boot peer...')
......
...@@ -327,9 +327,8 @@ class TunnelManager(object): ...@@ -327,9 +327,8 @@ class TunnelManager(object):
else: # I don't know my IP yet! else: # I don't know my IP yet!
msg = [] msg = []
# Add an extra random peer, mainly for the registry. # Add an extra random peer, mainly for the registry.
for peer in self._peer_db.getPeerList(): if random.randint(0, self._peer_db.getPeerCount()):
msg.append(encode(peer)) msg.append(encode(self._peer_db.getPeerList().next()))
break
if msg: if msg:
try: try:
self.sock.sendto('\1' + ''.join(msg), address) self.sock.sendto('\1' + ''.join(msg), address)
......
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