forked from LBRYCommunity/lbry-sdk
port dht.distance ~> py3
This commit is contained in:
parent
9967857a57
commit
5b35c4e8f0
2 changed files with 8 additions and 3 deletions
|
@ -1,4 +1,9 @@
|
|||
from binascii import hexlify
|
||||
|
||||
from lbrynet.dht import constants
|
||||
import sys
|
||||
if sys.version_info > (3,):
|
||||
long = int
|
||||
|
||||
|
||||
class Distance(object):
|
||||
|
@ -12,10 +17,10 @@ class Distance(object):
|
|||
if len(key) != constants.key_bits / 8:
|
||||
raise ValueError("invalid key length: %i" % len(key))
|
||||
self.key = key
|
||||
self.val_key_one = long(key.encode('hex'), 16)
|
||||
self.val_key_one = long(hexlify(key), 16)
|
||||
|
||||
def __call__(self, key_two):
|
||||
val_key_two = long(key_two.encode('hex'), 16)
|
||||
val_key_two = long(hexlify(key_two), 16)
|
||||
return self.val_key_one ^ val_key_two
|
||||
|
||||
def is_closer(self, a, b):
|
||||
|
|
|
@ -14,7 +14,7 @@ from lbrynet.dht import constants
|
|||
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue