Commit 4fc87945 authored by Ulysse Beaugnon's avatar Ulysse Beaugnon

Populate has been removed

parent ab232120
......@@ -2,14 +2,12 @@ Bug :
possible bug in the upnp refresh, when refreshing after a too long time
To be done :
Choose peer DB size.
Choose the number of peer we ask to the server
Choose the db size and who peers are deleted
find out who to have an automatic recovery without declare
Test the package
remove some peers if their is too much in addpeer
check the ips attributed
remove populate
remove unused methodes from the registry
remove decalre
how do we make sure that none inject some false packets ?
how do we make sur that noone is declaring too much false nodes ?
......
......@@ -234,21 +234,5 @@ class main(object):
% (utils.ipFromBin(client_ip), utils.ipFromBin(self.network.ljust(128, '0'))))
return False
def getPeerList(self, handler, n):
assert 0 < n < 1000
client_address, _, _, _ = handler.client_address
client_ip = utils.binFromIp(client_address)
if client_ip.startswith(self.network):
if time.time() > self.last_refresh + self.refresh_interval:
print "refreshing peers for dead ones"
self.db.execute("DELETE FROM peers WHERE ( date + ? ) <= CAST (strftime('%s', 'now') AS INTEGER)", (self.time_out,))
self.last_refesh = time.time()
print "sending peers"
return self.db.execute("SELECT prefix, address FROM peers ORDER BY random() LIMIT ?", (n,)).fetchall()
else:
logging.warning("Unauthorized connection from %s which does not start with %s"
% (utils.ipFromBin(client_ip), utils.ipFromBin(self.network.ljust(128, '0'))))
raise RuntimeError
if __name__ == "__main__":
main()
......@@ -74,10 +74,12 @@ class PeerManager:
logging.info('Refreshing the peers DB...')
try:
self._declare()
self._populate()
logging.info('DB refreshed')
self.next_refresh = time.time() + self._refresh_time
return True
except socket.error, e:
logging.info('Connection to server failed, re-bootstraping')
try:
self._bootstrap()
except socket.error, e:
logging.debug('socket.error : %s' % e)
logging.info('Connection to server failed, retrying in 30s')
......@@ -92,23 +94,8 @@ class PeerManager:
else:
logging.warning("Warning : couldn't send ip, unknown external config")
def _populate(self):
logging.info('Populating the peers DB...')
new_peer_list = self._proxy.getPeerList(self._db_size)
with self._db:
self._db.execute("""DELETE FROM peers WHERE used <= 0 ORDER BY used,
RANDOM() LIMIT MAX(0, ? + (SELECT COUNT(*)
FROM peers WHERE used <= 0))""",
(str(len(new_peer_list) - self._db_size),))
self._db.executemany("""INSERT OR IGNORE INTO peers (prefix, address)
VALUES (?,?)""", new_peer_list)
self._db.execute("""DELETE FROM peers WHERE prefix IN
(SELECT prefix FROM blacklist.flag)""")
logging.info('DB populated')
logging.trace('New peers : %s' % (', '.join(map(str, new_peer_list)),))
def getUnusedPeers(self, peer_count):
for populate in self.refresh, self._bootstrap, bool:
for populate in self._bootstrap, bool:
peer_list = self._db.execute("""SELECT prefix, address FROM peers WHERE used
<= 0 ORDER BY used DESC,RANDOM() LIMIT ?""",
(peer_count,)).fetchall()
......@@ -196,6 +183,9 @@ class PeerManager:
if int(self._db.execute("""SELECT COUNT(*) FROM blacklist.flag WHERE prefix = ?""", (peer[0],)).next()[0]) > 0:
logging.info('Peer is blacklisted')
return False
self._db.execute("""DELETE FROM peers WHERE used <= 0 ORDER BY used,
RANDOM() LIMIT MAX(0, (SELECT COUNT(*) FROM peers
WHERE used <= 0) - ?)""", str(self._db_size))
self._db.execute("INSERT INTO peers (prefix, address) VALUES (?,?)", peer)
logging.debug('Peer added')
return True
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