bmuller / kademlia

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

Remove nodes with same ip/port #35

Closed vdrg closed 7 years ago

vdrg commented 7 years ago

If a node is added to the heap, shouldn't a existing node with the same ip/port be deleted? Now, when a node reconnects it gets stored again.

bmuller commented 7 years ago

Don't think so - see here

vdrg commented 7 years ago

but the id is computed randomly, right? what I mean is that not only it should delete nodes with the same id, but also nodes with the same ip/port.

bmuller commented 7 years ago

Why?

On Oct 11, 2017, at 19:05, Vicente Dragicevic notifications@github.com wrote:

but the id is computed randomly, right? what I mean is that not only it should delete nodes with the same id, but also nodes with the same ip/port.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

vdrg commented 7 years ago

For example, if you start a server for bootstrapping and 2 nodes, if one of the nodes reconnects and then goes offline again, the remaining node will try to send two messages to the offline node:

Type a command(get/set):
set hello byebye
Did not received reply for msg id b'dyK00zT4pkYKRX3uZJ+pWIJ5TH0=' within 5 seconds
Did not received reply for msg id b'jQMY0ZiKXqz9UxC66BuYPOBVqWQ=' within 5 seconds
no response from 127.0.0.1:1235, removing from router
no response from 127.0.0.1:1235, removing from router
Value set.

BTW, I'm using the python3.5 branch

bmuller commented 7 years ago

Why would anyone ever run more than one node on the same port on the same machine?

On Oct 11, 2017, at 19:31, Vicente Dragicevic notifications@github.com wrote:

For example, if you start a server for bootstrapping and 2 nodes, if one of the nodes reconnects and then goes offline again, the remaining node will try to send two messages to the offline node:

Type a command(get/set): set hello byebye Did not received reply for msg id b'dyK00zT4pkYKRX3uZJ+pWIJ5TH0=' within 5 seconds Did not received reply for msg id b'jQMY0ZiKXqz9UxC66BuYPOBVqWQ=' within 5 seconds no response from 127.0.0.1:1235, removing from router no response from 127.0.0.1:1235, removing from router Value set. — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

vdrg commented 7 years ago

I think I didn't explain it well enough:

That happens when one of the nodes connects, disconnects, connects again and finally disconnects. I'm not talking about two nodes running at the same time on the same machine, what I mean is that a new node will be created and stored in the table even if it has already been stored before (which happens when the same node connects to the network multiple times, as a different id is created each time).

bmuller commented 7 years ago

I'm not sure why the node id would change on disconnect. If you mean in the case that someone destroys the existing Server object and then instantiates another, then I suppose this would happen - but I'm not sure that this would be a common occurrence. If there's a risk that your python process may die - then use the saveState and loadState methods on Server and your new instance will have the same node id and list of bootstrappable neighbors.

vdrg commented 7 years ago

Perfect, I will try that. Thanks!