bmuller / kademlia

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

Fails to bootstrap node in example #82

Closed dax-dot-gay closed 4 years ago

dax-dot-gay commented 4 years ago

Describe the bug I am attempting to run the first_node and set examples in tandem, and it fails to bootstrap the node after 5 seconds.

To Reproduce Steps to reproduce the behavior:

  1. Run first_node.py and set.py using a batch file similar to the one below:
    start python first_node.py
    python set.py 192.168.86.38 8468 test_k test_v
    pause

    After running, the set.py instance outputs the following error, while first_node continues running:

    2020-07-18 14:21:01,051 - kademlia.network - INFO - Node 108995474039131676481680986686925546654942811706 listening on 192.168.86.38:8469
    2020-07-18 14:21:01,052 - kademlia.network - DEBUG - Refreshing routing table
    2020-07-18 14:21:01,052 - kademlia.network - DEBUG - Attempting to bootstrap node with 1 initial contacts
    Did not receive reply for msg id b'PtLAsQuhaK4GIujIPLtqplhOv14=' within 5 seconds
    2020-07-18 14:21:06,053 - kademlia.crawling - INFO - creating spider with peers: []
    2020-07-18 14:21:06,053 - kademlia.crawling - INFO - crawling network with nearest: ()
    2020-07-18 14:21:06,053 - kademlia.network - INFO - setting 'test_k' = 'test_v' on network
    2020-07-18 14:21:06,053 - kademlia.network - WARNING - There are no known neighbors to set key 8488291004d33c55edef2966ff7bc3867068b968

Expected behavior The Set node should bootstrap and find the neighbor.

Screenshots image

Desktop (please complete the following information):

bmuller commented 4 years ago

@iTecAI please disable all firewall rules and also try using 127.0.0.1 as the host if you're running on the same machine (it's possible that your operating system doesn't resolve your IP as the same host).

This library is not officially supported in windows, but it should work.

dax-dot-gay commented 4 years ago

I have applied those changes and the issue is the same as before. My firewall is completely off as I am on a private network, and changing the IP to localhost/127.0.0.1 does not resolve the issue.

bmuller commented 4 years ago

@iTecAI can you send the output from running the following in two different console windows (don't use start, or any other windows specific stuff, just run these specific commands in 2 separate console windows):

Console Window One

> python first_node.py

Console Window Two

> python set.py 127.0.0.1 8468 key value

If you can put the output from both windows here, that might help diagnose.

dax-dot-gay commented 4 years ago

first_node.py

D:\Downloads\kademlia-master\kademlia-master\examples>python first_node.py
2020-07-18 15:15:51,039 - kademlia.network - INFO - Node 81011206440633377725205859190027940965572046235 listening on 127.0.0.1:8468
2020-07-18 15:15:51,041 - kademlia.network - DEBUG - Refreshing routing table

< I pressed Ctrl+C after a bit here, just to see what would happen >

2020-07-18 15:16:28,178 - kademlia.protocol - INFO - never seen 127.0.0.1:8469 before, adding to router
Executing <Task finished name='Task-4' coro=<RPCProtocol._accept_request() done, defined at C:\Python38\lib\site-packages\rpcudp\protocol.py:71> result=None created at C:\Python38\lib\site-packages\rpcudp\protocol.py:51> took 16.063 seconds

set.py

D:\Downloads\kademlia-master\kademlia-master\examples>python set.py 127.0.0.1 8468 test_k test_v
2020-07-18 15:16:28,176 - kademlia.network - INFO - Node 144244605408982251315605458964589358728155001363 listening on 127.0.0.1:8469
2020-07-18 15:16:28,176 - kademlia.network - DEBUG - Refreshing routing table
2020-07-18 15:16:28,177 - kademlia.network - DEBUG - Attempting to bootstrap node with 1 initial contacts
Did not receive reply for msg id b'5l0v/qyC/WFLzcEIS2RsgUBuK3M=' within 5 seconds
2020-07-18 15:16:33,178 - kademlia.crawling - INFO - creating spider with peers: []
2020-07-18 15:16:33,178 - kademlia.crawling - INFO - crawling network with nearest: ()
2020-07-18 15:16:33,178 - kademlia.network - INFO - setting 'test_k' = 'test_v' on network
2020-07-18 15:16:33,178 - kademlia.network - WARNING - There are no known neighbors to set key 8488291004d33c55edef2966ff7bc3867068b968

Based on what happened in first_node.py, it looks like it might be hanging for some reason?

bmuller commented 4 years ago

@iTecAI Don't hit Ctrl+C - leave it running - it's a server. If you stop it, it can't respond. Please try again and make sure to not stop the first node, then copy the full output again.

dax-dot-gay commented 4 years ago

Looks like it worked - Although when I pressed Ctrl+C on the last one the set.py code had already completed, I gave the server more time to initialize this time. Thanks for your help!