fix issue with bit prefix finding in sharedPrefix
This commit is contained in:
parent
de78bd9b5d
commit
125abe7415
@ -4,7 +4,7 @@ import operator
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from kademlia.utils import OrderedSet, sharedPrefix
|
from kademlia.utils import OrderedSet, sharedPrefix, bytesToBitString
|
||||||
|
|
||||||
|
|
||||||
class KBucket(object):
|
class KBucket(object):
|
||||||
@ -65,7 +65,7 @@ class KBucket(object):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def depth(self):
|
def depth(self):
|
||||||
sp = sharedPrefix([n.id for n in self.nodes.values()])
|
sp = sharedPrefix([bytesToBitString(n.id) for n in self.nodes.values()])
|
||||||
return len(sp)
|
return len(sp)
|
||||||
|
|
||||||
def head(self):
|
def head(self):
|
||||||
|
@ -49,3 +49,8 @@ def sharedPrefix(args):
|
|||||||
break
|
break
|
||||||
i += 1
|
i += 1
|
||||||
return args[0][:i]
|
return args[0][:i]
|
||||||
|
|
||||||
|
|
||||||
|
def bytesToBitString(bytes):
|
||||||
|
bits = [bin(byte)[2:].rjust(8, '0') for byte in bytes]
|
||||||
|
return "".join(bits)
|
||||||
|
Loading…
Reference in New Issue
Block a user