Skip to content

Commit

Permalink
Do not enqueue hashes that are already enqueued to be announced
Browse files Browse the repository at this point in the history
  • Loading branch information
jobevers committed Jan 23, 2017
1 parent 9b84b70 commit 0936b5c
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions lbrynet/core/server/DHTHashAnnouncer.py
Expand Up @@ -9,14 +9,37 @@
log = logging.getLogger(__name__)


class DequeSet(object):
def __init__(self):
self._queue = collections.deque()
self._items = set()

def append(self, item):
if item in self._items:
return
self._queue.append(item)
self._items.add(item)

def popleft(self):
item = self._queue.popleft()
self._items.remove(item)
return item

def __len__(self):
return len(self._queue)

def __nonzero__(self):
return self._queue.__nonzero__()


class DHTHashAnnouncer(object):
"""This class announces to the DHT that this peer has certain blobs"""
def __init__(self, dht_node, peer_port):
self.dht_node = dht_node
self.peer_port = peer_port
self.suppliers = []
self.next_manage_call = None
self.hash_queue = collections.deque()
self.hash_queue = DequeSet()
self._concurrent_announcers = 0

def run_manage_loop(self):
Expand Down Expand Up @@ -67,7 +90,7 @@ def _announce_hashes(self, hashes, supplier):
log.debug('There are now %s hashes remaining to be announced', len(self.hash_queue))

def announce():
if len(self.hash_queue):
if self.hash_queue:
h, announce_deferred = self.hash_queue.popleft()
log.debug('Announcing blob %s to dht', h)
d = self.dht_node.announceHaveBlob(binascii.unhexlify(h), self.peer_port)
Expand Down

0 comments on commit 0936b5c

Please sign in to comment.