This commit is contained in:
Jack Robison 2018-05-23 19:33:16 -04:00
parent 7da70cc02d
commit 760417ff3a
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
7 changed files with 11 additions and 13 deletions

View file

@ -7,7 +7,6 @@ from lbrynet.database.storage import SQLiteStorage
from lbrynet.core.RateLimiter import RateLimiter from lbrynet.core.RateLimiter import RateLimiter
from lbrynet.core.utils import generate_id from lbrynet.core.utils import generate_id
from lbrynet.core.PaymentRateManager import BasePaymentRateManager, OnlyFreePaymentsManager from lbrynet.core.PaymentRateManager import BasePaymentRateManager, OnlyFreePaymentsManager
from lbrynet.core.BlobAvailability import BlobAvailabilityTracker
log = logging.getLogger(__name__) log = logging.getLogger(__name__)

View file

@ -13,7 +13,7 @@ class _Contact(object):
self._id = id self._id = id
if id is not None: if id is not None:
if not len(id) == constants.key_bits / 8: if not len(id) == constants.key_bits / 8:
raise ValueError("invalid node id: %s", id.encode('hex')) raise ValueError("invalid node id: %s" % id.encode('hex'))
self.address = ipAddress self.address = ipAddress
self.port = udpPort self.port = udpPort
self._networkProtocol = networkProtocol self._networkProtocol = networkProtocol

View file

@ -137,7 +137,7 @@ class KademliaProtocol(protocol.DatagramProtocol):
log.debug("%s:%i SEND CALL %s(%s) TO %s:%i", self._node.externalIP, self._node.port, method, log.debug("%s:%i SEND CALL %s(%s) TO %s:%i", self._node.externalIP, self._node.port, method,
args[0].encode('hex'), contact.address, contact.port) args[0].encode('hex'), contact.address, contact.port)
else: else:
log.debug("%s:%i SEND CALL %s TO %s:%i", self._node.externalIP, self._node.port, method, log.debug("%s:%i SEND CALL %s TO %s:%i", self._node.externalIP, self._node.port, method,
contact.address, contact.port) contact.address, contact.port)
df = defer.Deferred() df = defer.Deferred()
@ -395,7 +395,7 @@ class KademliaProtocol(protocol.DatagramProtocol):
log.debug("%s:%i RECV CALL %s(%s) %s:%i", self._node.externalIP, self._node.port, method, log.debug("%s:%i RECV CALL %s(%s) %s:%i", self._node.externalIP, self._node.port, method,
args[0].encode('hex'), senderContact.address, senderContact.port) args[0].encode('hex'), senderContact.address, senderContact.port)
else: else:
log.debug("%s:%i RECV CALL %s %s:%i", self._node.externalIP, self._node.port, method, log.debug("%s:%i RECV CALL %s %s:%i", self._node.externalIP, self._node.port, method,
senderContact.address, senderContact.port) senderContact.address, senderContact.port)
try: try:
if method != 'ping': if method != 'ping':

View file

@ -124,8 +124,8 @@ class TreeRoutingTable(object):
""" """
failure.trap(TimeoutError) failure.trap(TimeoutError)
log.debug("Replacing dead contact in bucket %i: %s:%i (%s) with %s:%i (%s)", bucketIndex, log.debug("Replacing dead contact in bucket %i: %s:%i (%s) with %s:%i (%s)", bucketIndex,
deadContact.address, deadContact.port, deadContact.log_id(), contact.address, contact.port, deadContact.address, deadContact.port, deadContact.log_id(), contact.address,
contact.log_id()) contact.port, contact.log_id())
try: try:
self._buckets[bucketIndex].removeContact(deadContact) self._buckets[bucketIndex].removeContact(deadContact)
except ValueError: except ValueError:

View file

@ -40,4 +40,4 @@ class TestPeerExpiration(TestKademliaBase):
for seed_name in sorted(self.seed_dns.keys())])]) for seed_name in sorted(self.seed_dns.keys())])])
self.verify_all_nodes_are_routable() self.verify_all_nodes_are_routable()
self.verify_all_nodes_are_pingable() self.verify_all_nodes_are_pingable()

View file

@ -69,13 +69,15 @@ class KBucketTest(unittest.TestCase):
if constants.k >= 2: if constants.k >= 2:
for i in range(constants.k-2): for i in range(constants.k-2):
node_ids.append(generate_id()) node_ids.append(generate_id())
tmpContact = self.contact_manager.make_contact(node_ids[-1], next(self.address_generator), 4444, 0, None) tmpContact = self.contact_manager.make_contact(node_ids[-1], next(self.address_generator), 4444, 0,
None)
self.kbucket.addContact(tmpContact) self.kbucket.addContact(tmpContact)
else: else:
# add k contacts # add k contacts
for i in range(constants.k): for i in range(constants.k):
node_ids.append(generate_id()) node_ids.append(generate_id())
tmpContact = self.contact_manager.make_contact(node_ids[-1], next(self.address_generator), 4444, 0, None) tmpContact = self.contact_manager.make_contact(node_ids[-1], next(self.address_generator), 4444, 0,
None)
self.kbucket.addContact(tmpContact) self.kbucket.addContact(tmpContact)
# try to get too many contacts # try to get too many contacts

View file

@ -8,12 +8,9 @@ import hashlib
from twisted.trial import unittest from twisted.trial import unittest
import struct import struct
from twisted.internet import protocol, defer, selectreactor from twisted.internet import defer
from lbrynet.dht.msgtypes import ResponseMessage
from lbrynet.dht.node import Node from lbrynet.dht.node import Node
from lbrynet.dht import constants from lbrynet.dht import constants
from lbrynet.dht.datastore import DictDataStore
from lbrynet.dht.routingtable import TreeRoutingTable
class NodeIDTest(unittest.TestCase): class NodeIDTest(unittest.TestCase):