1

I connected two laptops A and B to bitcoin testnet. I then manually connected B to A using addnode of bitcoin-client.

Snippet of getpeerinfo from B:

  {
    "id": 1,
    "addr": "172.22.94.40:18333",
    "addrlocal": "137.122.81.217:53818",

  }
 { 
   "id": 10,
   "addr": "54.152.9.182:18333",
   "services": "000000000000000
 }

Some connection have an addrlocal set and its port 53818 is randomnly chosen. I searched through the codebase for this. It looks like some fInbound flag will be getting set in A. Can anyone in simple terms explain what is happening here?

I know that a socket cannot be used for listening and sending data at the same time. Is it got to do with that?

If 53818 is chosen as port to send data to A, then why is there no such random choice happening in seed node connection? (like 54.152.9.182 here in example)

1

I would guess addrlocal shows you your endpoint of the connection, that is your IP address and port number. For all incoming connections that would be the same as the IP address and port you are listening on, so that's why it's not displayed. In your case most likely: 137.122.81.217:8333

I'm not sure what would happen if the server is multihomed.

  • Why my port number is 58318 (randomnly chosen) and NOT 18333? I am still connected via the testnet right? – Guhan S Jan 6 '16 at 10:58
  • Because it's an outgoing connection and that's how TCP works: outgoing connections have a random local port (by default). When you connect to a host, you only specify that host and a port, you never specify which IP or port on your own PC you want to use, therefore it will be random. – Jannes Jan 6 '16 at 14:14
  • Yes exactly. But I have two nodes (laptop A and a seed node) connected here from laptop B. Both are outbound since they are initiated by B (one at the peer discovery and other due to my manual command). Why is no random port chosen for the connection between seed node and laptop B? Why is it using only 18333 on both sides (destination and source) for that? Should not the source also be random port (at B side) for that? I also notice that for all seed nodes the source port in B is 18333 as in this case. – Guhan S Jan 7 '16 at 2:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.