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