Skip to content

Commit

Permalink
use utils.call_later in DHTHash Announcer
Browse files Browse the repository at this point in the history
  • Loading branch information
Kay Kurokawa committed Feb 20, 2017
1 parent c27fe7a commit 3522f9a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
9 changes: 4 additions & 5 deletions lbrynet/core/server/DHTHashAnnouncer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
import logging
import time

from twisted.internet import defer, reactor

from twisted.internet import defer
from lbrynet.core import utils

log = logging.getLogger(__name__)


class DHTHashAnnouncer(object):
callLater = reactor.callLater
ANNOUNCE_CHECK_INTERVAL = 60
CONCURRENT_ANNOUNCERS = 5

Expand All @@ -26,7 +25,7 @@ def __init__(self, dht_node, peer_port):
def run_manage_loop(self):
if self.peer_port is not None:
self._announce_available_hashes()
self.next_manage_call = self.callLater(self.ANNOUNCE_CHECK_INTERVAL, self.run_manage_loop)
self.next_manage_call = utils.call_later(self.ANNOUNCE_CHECK_INTERVAL, self.run_manage_loop)

def stop(self):
log.info("Stopping %s", self)
Expand Down Expand Up @@ -79,7 +78,7 @@ def announce():
log.debug('Announcing blob %s to dht', h)
d = self.dht_node.announceHaveBlob(binascii.unhexlify(h), self.peer_port)
d.chainDeferred(announce_deferred)
d.addBoth(lambda _: self.callLater(0, announce))
d.addBoth(lambda _: utils.call_later(0, announce))
else:
self._concurrent_announcers -= 1

Expand Down
7 changes: 3 additions & 4 deletions tests/unit/core/server/test_DHTHashAnnouncer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
import binascii
from twisted.trial import unittest
from twisted.internet import defer,task
from lbrynet.core.server.DHTHashAnnouncer import DHTHashAnnouncer,DHTHashSupplier
from lbrynet.core.utils import random_string
from lbrynet.core import log_support
from lbrynet.core import log_support, utils


class MocDHTNode(object):
Expand Down Expand Up @@ -35,8 +33,9 @@ def setUp(self):
self.blobs_to_announce.append(binascii.b2a_hex(os.urandom(32)))
self.clock = task.Clock()
self.dht_node = MocDHTNode()
utils.call_later = self.clock.callLater
from lbrynet.core.server.DHTHashAnnouncer import DHTHashAnnouncer,DHTHashSupplier
self.announcer = DHTHashAnnouncer(self.dht_node, peer_port=3333)
self.announcer.callLater = self.clock.callLater
self.supplier = MocSupplier(self.blobs_to_announce)
self.announcer.add_supplier(self.supplier)

Expand Down

0 comments on commit 3522f9a

Please sign in to comment.