diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..3a8e4be --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,7 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + * Fixed #77 - Unexpected type conversion in buckets diff --git a/kademlia/routing.py b/kademlia/routing.py index 2db2185..8bb5b8c 100644 --- a/kademlia/routing.py +++ b/kademlia/routing.py @@ -23,7 +23,7 @@ class KBucket: return list(self.nodes.values()) def split(self): - midpoint = (self.range[0] + self.range[1]) / 2 + midpoint = (self.range[0] + self.range[1]) // 2 one = KBucket(self.range[0], midpoint, self.ksize) two = KBucket(midpoint + 1, self.range[1], self.ksize) nodes = chain(self.nodes.values(), self.replacement_nodes.values()) diff --git a/kademlia/tests/test_routing.py b/kademlia/tests/test_routing.py index 266b712..212a95f 100644 --- a/kademlia/tests/test_routing.py +++ b/kademlia/tests/test_routing.py @@ -13,6 +13,10 @@ class TestKBucket: assert len(two) == 1 assert two.range == (6, 10) + def test_split_no_overlap(self): # pylint: disable=no-self-use + left, right = KBucket(0, 2 ** 160, 20).split() + assert (right.range[0] - left.range[1]) == 1 + def test_add_node(self, mknode): # pylint: disable=no-self-use # when full, return false bucket = KBucket(0, 10, 2)