forked from LBRYCommunity/lbry-sdk
Add to DHT Node class initialization argument peerPort where it serves blobs, instead of specifying it in announceHaveBlob
This commit is contained in:
parent
cf1b9b2aa8
commit
7e8f3254b1
5 changed files with 11 additions and 7 deletions
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue