Commit 4e4830ea authored by Guillaume Bury's avatar Guillaume Bury

You can flag peers ( in vifibnet ) so that they are chosen last when looking...

You can flag peers ( in vifibnet ) so that they are chosen last when looking for a peer to connect to.
parent 50003a3d
...@@ -56,8 +56,8 @@ class PeerManager: ...@@ -56,8 +56,8 @@ class PeerManager:
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, peer_count): def getUnusedPeers(self, peer_count):
return self._db.execute("""SELECT prefix, address FROM peers WHERE used = 0 return self._db.execute("""SELECT prefix, address FROM peers WHERE used <= 0
ORDER BY RANDOM() LIMIT ?""", (peer_count,)) ORDER BY used DESC,RANDOM() LIMIT ?""", (peer_count,))
def usePeer(self, prefix): def usePeer(self, prefix):
utils.log('Updating peers database : using peer ' + str(prefix), 5) utils.log('Updating peers database : using peer ' + str(prefix), 5)
...@@ -67,6 +67,10 @@ class PeerManager: ...@@ -67,6 +67,10 @@ class PeerManager:
utils.log('Updating peers database : unusing peer ' + str(prefix), 5) utils.log('Updating peers database : unusing peer ' + str(prefix), 5)
self._db.execute("UPDATE peers SET used = 0 WHERE prefix = ?", (prefix,)) self._db.execute("UPDATE peers SET used = 0 WHERE prefix = ?", (prefix,))
def flagPeer(self, prefix):
utils.log('Updating peers database : flagging peer ' + str(prefix), 5)
self._db.execute("UPDATE peers SET used = -1 WHERE prefix = ?", (prefix,))
def handle_message(self, msg): def handle_message(self, msg):
script_type, arg = msg.split() script_type, arg = msg.split()
if script_type == 'client-connect': if script_type == 'client-connect':
......
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