forked from LBRYCommunity/lbry-sdk
partial dht functional tests porting to py3
This commit is contained in:
parent
19211d4417
commit
cea3b7630c
7 changed files with 24 additions and 14 deletions
|
@ -113,6 +113,9 @@ class _Contact(object):
|
|||
else:
|
||||
return True
|
||||
|
||||
def __hash__(self):
|
||||
return self.id.__hash__()
|
||||
|
||||
def compact_ip(self):
|
||||
compact_ip = reduce(
|
||||
lambda buff, x: buff + bytearray([int(x)]), self.address.split('.'), bytearray())
|
||||
|
|
|
@ -454,7 +454,7 @@ class KademliaProtocol(protocol.DatagramProtocol):
|
|||
log.error("deferred timed out, but is not present in sent messages list!")
|
||||
return
|
||||
remoteContact, df, timeout_call, timeout_canceller, method, args = self._sentMessages[messageID]
|
||||
if self._partialMessages.has_key(messageID):
|
||||
if messageID in self._partialMessages:
|
||||
# We are still receiving this message
|
||||
self._msgTimeoutInProgress(messageID, timeout_canceller, remoteContact, df, method, args)
|
||||
return
|
||||
|
@ -480,7 +480,7 @@ class KademliaProtocol(protocol.DatagramProtocol):
|
|||
|
||||
def _hasProgressBeenMade(self, messageID):
|
||||
return (
|
||||
self._partialMessagesProgress.has_key(messageID) and
|
||||
messageID in self._partialMessagesProgress and
|
||||
(
|
||||
len(self._partialMessagesProgress[messageID]) !=
|
||||
len(self._partialMessages[messageID])
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import logging
|
||||
from binascii import hexlify
|
||||
|
||||
from twisted.trial import unittest
|
||||
from twisted.internet import defer, task
|
||||
from lbrynet.dht import constants
|
||||
from lbrynet.dht.node import Node
|
||||
from mock_transport import resolve, listenUDP, MOCK_DHT_SEED_DNS, mock_node_generator
|
||||
from .mock_transport import resolve, listenUDP, MOCK_DHT_SEED_DNS, mock_node_generator
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -16,8 +18,8 @@ class TestKademliaBase(unittest.TestCase):
|
|||
seed_dns = MOCK_DHT_SEED_DNS
|
||||
|
||||
def _add_next_node(self):
|
||||
node_id, node_ip = self.mock_node_generator.next()
|
||||
node = Node(node_id=node_id.decode('hex'), udpPort=4444, peerPort=3333, externalIP=node_ip,
|
||||
node_id, node_ip = next(self.mock_node_generator)
|
||||
node = Node(node_id=node_id, udpPort=4444, peerPort=3333, externalIP=node_ip,
|
||||
resolve=resolve, listenUDP=listenUDP, callLater=self.clock.callLater, clock=self.clock)
|
||||
self.nodes.append(node)
|
||||
return node
|
||||
|
@ -141,6 +143,7 @@ class TestKademliaBase(unittest.TestCase):
|
|||
for node in self.nodes:
|
||||
contact_addresses = {contact.address for contact in node.contacts}
|
||||
routable.update(contact_addresses)
|
||||
print(routable, node_addresses)
|
||||
self.assertSetEqual(routable, node_addresses)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
|
|
|
@ -6,6 +6,9 @@ from lbrynet.dht.encoding import Bencode
|
|||
from lbrynet.dht.error import DecodeError
|
||||
from lbrynet.dht.msgformat import DefaultFormat
|
||||
from lbrynet.dht.msgtypes import ResponseMessage, RequestMessage, ErrorMessage
|
||||
import sys
|
||||
if sys.version_info > (3,):
|
||||
unicode = str
|
||||
|
||||
_encode = Bencode()
|
||||
_datagram_formatter = DefaultFormat()
|
||||
|
@ -13,9 +16,9 @@ _datagram_formatter = DefaultFormat()
|
|||
log = logging.getLogger()
|
||||
|
||||
MOCK_DHT_NODES = [
|
||||
"cc8db9d0dd9b65b103594b5f992adf09f18b310958fa451d61ce8d06f3ee97a91461777c2b7dea1a89d02d2f23eb0e4f",
|
||||
"83a3a398eead3f162fbbe1afb3d63482bb5b6d3cdd8f9b0825c1dfa58dffd3f6f6026d6e64d6d4ae4c3dfe2262e734ba",
|
||||
"b6928ff25778a7bbb5d258d3b3a06e26db1654f3d2efce8c26681d43f7237cdf2e359a4d309c4473d5d89ec99fb4f573",
|
||||
b"cc8db9d0dd9b65b103594b5f992adf09f18b310958fa451d61ce8d06f3ee97a91461777c2b7dea1a89d02d2f23eb0e4f",
|
||||
b"83a3a398eead3f162fbbe1afb3d63482bb5b6d3cdd8f9b0825c1dfa58dffd3f6f6026d6e64d6d4ae4c3dfe2262e734ba",
|
||||
b"b6928ff25778a7bbb5d258d3b3a06e26db1654f3d2efce8c26681d43f7237cdf2e359a4d309c4473d5d89ec99fb4f573",
|
||||
]
|
||||
|
||||
MOCK_DHT_SEED_DNS = { # these map to mock nodes 0, 1, and 2
|
||||
|
@ -100,7 +103,7 @@ def listenUDP(port, protocol, interface='', maxPacketSize=8192):
|
|||
|
||||
def address_generator(address=(10, 42, 42, 1)):
|
||||
def increment(addr):
|
||||
value = struct.unpack("I", "".join([chr(x) for x in list(addr)[::-1]]))[0] + 1
|
||||
value = struct.unpack("I", "".join([chr(x) for x in list(addr)[::-1]]).encode())[0] + 1
|
||||
new_addr = []
|
||||
for i in range(4):
|
||||
new_addr.append(value % 256)
|
||||
|
@ -122,8 +125,8 @@ def mock_node_generator(count=None, mock_node_ids=MOCK_DHT_NODES):
|
|||
break
|
||||
if num >= len(mock_node_ids):
|
||||
h = hashlib.sha384()
|
||||
h.update("node %i" % num)
|
||||
node_id = h.hexdigest()
|
||||
h.update(b"node %i" % num)
|
||||
node_id = h.digest()
|
||||
else:
|
||||
node_id = mock_node_ids[num]
|
||||
yield (node_id, node_ip)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from twisted.trial import unittest
|
||||
from dht_test_environment import TestKademliaBase
|
||||
|
||||
from tests.functional.dht.dht_test_environment import TestKademliaBase
|
||||
|
||||
|
||||
class TestKademliaBootstrap(TestKademliaBase):
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import logging
|
||||
from twisted.internet import defer
|
||||
from lbrynet.dht import constants
|
||||
from dht_test_environment import TestKademliaBase
|
||||
from .dht_test_environment import TestKademliaBase
|
||||
|
||||
log = logging.getLogger()
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import lbrynet.dht.protocol
|
|||
import lbrynet.dht.contact
|
||||
from lbrynet.dht.error import TimeoutError
|
||||
from lbrynet.dht.node import Node, rpcmethod
|
||||
from mock_transport import listenUDP, resolve
|
||||
from .mock_transport import listenUDP, resolve
|
||||
|
||||
log = logging.getLogger()
|
||||
|
||||
|
|
Loading…
Reference in a new issue