perlin-network / noise

A decentralized P2P networking stack written in Go.
https://godoc.org/github.com/perlin-network/noise
MIT License
1.79k stars 211 forks source link

OnPeerEvicted happens immediately after connection, disregarding timeout #299

Open delp opened 3 years ago

delp commented 3 years ago

If I run the chat example multiple times on the same machine, the chat clients are able to find one another.

If I run the chat client on two different machines on my network, the client connects and then immediately fails out. I tried to change the timeout from 3 seconds to much larger, but the evicted event is immediate and not related to the timeout.

From the machine trying to connect:

Your ID is :46097(e60bd758). Type '/discover' to attempt to discover new peers, or '/peers' to list out all peers you are connected to.
Learned about a new peer :38469(ea91a207).
Forgotten a peer :38469(ea91a207).
Did not discover any peers.```

The machine receiving the connection retains memory of the new peer however:

Learned about a new peer :46097(e60bd758).
/peers
You know 1 peer(s): [:46097(e60bd758)]
delp commented 3 years ago

Was able to turn logging on in order to provide more detail:

Your ID is :39471(7c8a053e). Type '/discover' to attempt to discover new peers, or '/peers' to list out all peers you are connected to.                                                                             
Running bootstrap, there are currently these addresses:
[192.168.1.67:42465]
{"level":"info","msg":"Listening for incoming peers.","bind_addr":"[::]:39471","id_addr":":39471","public_key":"7c8a053e2969f7db46b53c660fe10df0c6c3cb4df0b6758b9a1ffe839952165d","private_key":"3e8473e3dc137d669d4ff67bb1eb07b85c3c1f8a04eda49759eae9292f3d6fdc7c8a053e2969f7db46b53c660fe10df0c6c3cb4df0b6758b9a1ffe839952165d"}                                                                                                      
{"level":"debug","msg":"Peer connection opened.","peer_id":"5cb3670bfd21807cd827d27db7516809707bd784283829e61777200262001aa5","peer_addr":":42465","remote_addr":"192.168.1.67:42465","session_key":"1e7c1613c05ca546806dc9fc7c9f45d432635f2f3bab62dc4cefaad2d3e8c413"}
{"level":"debug","msg":"Peer was inserted into routing table.","peer_id":"{\"public_key\": \"5cb3670bfd21807cd827d27db7516809707bd784283829e61777200262001aa5\", \"address\": \":42465\"}","peer_addr":":42465"}    
Learned about a new peer :42465(5cb3670b).
Trying to discover peers from nodes
{"level":"debug","msg":"Peer was evicted from routing table by failing to be dialed.","error":"attempted to dial :42465 several times but failed: dial tcp :42465: connect: connection refused"}                    
Forgotten a peer :42465(5cb3670b).
Did not discover any peers.

Operative line being:

{"level":"debug","msg":"Peer was evicted from routing table by failing to be dialed.","error":"attempted to dial :42465 several times but failed: dial tcp :42465: connect: connection refused"}                    

However, there is no reason for this connection to be refused. I can connect to it via netcat. Does the client have issues accepting connections from remote hosts?

delp commented 3 years ago

Have added a bunch of debugs.

Somewhere between the first call to the peer, and subsequent communication, the Address is being stripped of the hostname and only being saved as the port. (:12345) So subsequent network requests fail. Not clear if this is a bug in the kademlia implementation or in the chat example.

delp commented 3 years ago

@iwasaki-kenta Any chance you're still looking at this project? : 3

lithdew commented 3 years ago

@delp Hello! Sorry to tell you, though the project was meant to be archived 2 years ago - for an FYI, @iwasaki-kenta is my old account.

This project has been abandoned since my departure from the Perlin project, and I would take the measures to close it down though I no longer have access to this repository or the other repositories in the organization.

Nowadays I am mostly working with and contributing to the Zig programming language, and actually just started working again on some performant p2p and networking stuff in Go. If you'd like to salvage any of the code of Noise, or would just like to reach out in general, feel free to reach me on my Discord: lithdew#6092

delp commented 3 years ago

thanks, sent you a friend request!