fix issue with bit prefix finding in sharedPrefix

This commit is contained in:
Brian Muller 2016-08-06 11:15:53 -04:00
parent de78bd9b5d
commit 125abe7415
2 changed files with 7 additions and 2 deletions

View File

@ -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):

View File

@ -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)