diff --git a/kademlia/routing.py b/kademlia/routing.py index 0f9aa4c..c047025 100644 --- a/kademlia/routing.py +++ b/kademlia/routing.py @@ -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): diff --git a/kademlia/utils.py b/kademlia/utils.py index 7528703..45d646e 100644 --- a/kademlia/utils.py +++ b/kademlia/utils.py @@ -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)