diff --git a/lbrynet/core/Session.py b/lbrynet/core/Session.py index edf4e425f..d85b7aca2 100644 --- a/lbrynet/core/Session.py +++ b/lbrynet/core/Session.py @@ -274,7 +274,8 @@ class Session(object): self.dht_node = self.dht_node_class( udpPort=self.dht_node_port, node_id=self.node_id, - externalIP=self.external_ip + externalIP=self.external_ip, + peerPort=self.peer_port ) self.peer_finder = DHTPeerFinder(self.dht_node, self.peer_manager) if self.hash_announcer is None: diff --git a/lbrynet/core/server/DHTHashAnnouncer.py b/lbrynet/core/server/DHTHashAnnouncer.py index aaa16bc74..ba7bede7d 100644 --- a/lbrynet/core/server/DHTHashAnnouncer.py +++ b/lbrynet/core/server/DHTHashAnnouncer.py @@ -76,7 +76,7 @@ class DHTHashAnnouncer(object): if len(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) + d = self.dht_node.announceHaveBlob(binascii.unhexlify(h)) d.chainDeferred(announce_deferred) d.addBoth(lambda _: utils.call_later(0, announce)) else: diff --git a/lbrynet/dht/node.py b/lbrynet/dht/node.py index c2245e749..40e5ef7ad 100644 --- a/lbrynet/dht/node.py +++ b/lbrynet/dht/node.py @@ -51,7 +51,7 @@ class Node(object): def __init__(self, node_id=None, udpPort=4000, dataStore=None, routingTableClass=None, networkProtocol=None, - externalIP=None): + externalIP=None, peerPort=None): """ @param dataStore: The data store to use. This must be class inheriting from the C{DataStore} interface (or providing the @@ -73,6 +73,8 @@ class Node(object): change the format of the physical RPC messages being transmitted. @type networkProtocol: entangled.kademlia.protocol.KademliaProtocol + @param externalIP: the IP at which this node can be contacted + @param peerPort: the port at which this node announces it has a blob for """ self.node_id = node_id or self._generateID() self.port = udpPort @@ -112,6 +114,7 @@ class Node(object): contactTriple[0], contactTriple[1], contactTriple[2], self._protocol) self._routingTable.addContact(contact) self.externalIP = externalIP + self.peerPort = peerPort self.hash_watcher = HashWatcher() def __del__(self): @@ -206,8 +209,8 @@ class Node(object): return 0 return num_in_data_store * self.getApproximateTotalDHTNodes() / 8 - def announceHaveBlob(self, key, port): - return self.iterativeAnnounceHaveBlob(key, {'port': port, 'lbryid': self.node_id}) + def announceHaveBlob(self, key): + return self.iterativeAnnounceHaveBlob(key, {'port': self.peerPort, 'lbryid': self.node_id}) @defer.inlineCallbacks def getPeersForBlob(self, blob_hash): diff --git a/lbrynet/tests/mocks.py b/lbrynet/tests/mocks.py index 4359aadb5..74c516931 100644 --- a/lbrynet/tests/mocks.py +++ b/lbrynet/tests/mocks.py @@ -132,7 +132,7 @@ class PeerFinder(object): self.num_peers = num_peers self.count = 0 - def find_peers_for_blob(self, *args): + def find_peers_for_blob(self, h, filter_self=False): peer_port = self.start_port + self.count self.count += 1 if self.count >= self.num_peers: diff --git a/lbrynet/tests/unit/core/server/test_DHTHashAnnouncer.py b/lbrynet/tests/unit/core/server/test_DHTHashAnnouncer.py index 927dff723..60021ffc9 100644 --- a/lbrynet/tests/unit/core/server/test_DHTHashAnnouncer.py +++ b/lbrynet/tests/unit/core/server/test_DHTHashAnnouncer.py @@ -8,7 +8,7 @@ class MocDHTNode(object): def __init__(self): self.blobs_announced = 0 - def announceHaveBlob(self, blob, port): + def announceHaveBlob(self, blob): self.blobs_announced += 1 return defer.succeed(True)