go2p
go2p copied to clipboard
[QUESTION] Peers address
Hello,
How are generated peers address?
For example, with https://github.com/v-braun/go2p/blob/master/example_test.go If I run a server at 127.0.0.1:7071 and another one at 127.0.0.1:7072 for example and I connect it to the first one, the peer address change to something like 127.0.0.1:30002
Probably a stupid question, but I'm a Junior (especially in P2P ... ) Thanks :)
Hi! This is a common assumption but it is not correct 😃
TCP Communication has alway a Server and a Client part. The Server that u are starting "listening" to an endpoint and the client "dials" to this endpoint. In this Lib (basically in all P2P scenarios) each node in the Network us min. one Server (wich is used to listen to inbound connections) and multiple clients (to connect to other nodes).
Wich means: 1.: You start a (Application-1) Server with the address 127.0.0.1:7071 2.: Than you start another (Application-2) Server with the address 127.0.0.1:7072
Run the netstat command and you should see two applications running and LISTENING to the above ports.
3.: You create a connection from Application-1 to Application-2, wich means that Application-1 use a client and dials to the Server of Application-2. During the Dial procedure the "client" of Application-1 will open a new port (30002) wich is assigned by the operating system.
Run the netstat command and you should see still the two LISTENING ports and you should see that there is an ESTABLISHED connection between 127.0.0.1:300002 to 127.0.0.1:7072
I hope I could answer ur question?