bmuller / kademlia

A DHT in Python using asyncio
http://kademlia.readthedocs.org
MIT License
830 stars 210 forks source link

Unexpected type conversion in buckets #77

Closed JohnDoee closed 4 years ago

JohnDoee commented 4 years ago

Describe the bug Integer seems to be converted to float at https://github.com/bmuller/kademlia/blob/master/kademlia/routing.py#L26 - floats are not precise enough to represent the correct number and therefore both buckets will have overlapping start and end range.

To Reproduce Split a bucket and check datatype.

$ python3
Python 3.7.5 (default, Nov 20 2019, 09:21:52) 
[GCC 9.2.1 20191008] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> (2**160) / 2
7.307508186654515e+47
>>> type((2**160) / 2)
<class 'float'>
>>> (2**160) // 2
730750818665451459101842416358141509827966271488
>>> type((2**160) // 2)
<class 'int'>
bmuller commented 4 years ago

Great catch - thanks @JohnDoee!