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
|
||||
|
||||
from collections import OrderedDict
|
||||
from kademlia.utils import OrderedSet, sharedPrefix
|
||||
from kademlia.utils import OrderedSet, sharedPrefix, bytesToBitString
|
||||
|
||||
|
||||
class KBucket(object):
|
||||
@ -65,7 +65,7 @@ class KBucket(object):
|
||||
return True
|
||||
|
||||
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)
|
||||
|
||||
def head(self):
|
||||
|
@ -49,3 +49,8 @@ def sharedPrefix(args):
|
||||
break
|
||||
i += 1
|
||||
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