3

I am tinkering with the bitcoin source code and trying to understand the exact working of peer discovery mechanism in the testnet mode for which I have made the following changes:

  1. Disabled the DNS seed discovery in order to force bitcoind to fallback to connect to hardcoded nodes.

  2. Changed the default hardcoded nodes to my known 4 addresses, lets say A,B,C and D, which I ensure are always online.

Now, when I run the bitcoind client (call it E), it connects to one of A,B,C or D, running the same modified version of bitcoind. It gets the peer addresses from the hardcoded node that it first connects to by exchanging getaddr and addr messages but I am not sure how it proceeds after that. I have following queries:

a. If a node falls back to connect to hardcoded nodes, is it supposed to connect to only one of the hardcoded nodes like it happends in my case or can it connect to multiple hardcoded nodes ?

b. After getting peer address via the addr message, when will the node E start connecting to those peers ?

Please point me to the relevant code files/sections if possible. Thanks

bawejakunal
  • 1,678
  • 2
  • 25
  • 54

1 Answers1

-1

A. There are no "Hardcoded nodes" there are only DNS seeds of nodes, when you run them through the DNS request you'll get new node every request.

B. If the node isn't connected to it's maximum capacity of nodes (it's 8 active nodes and 125 inactive nodes) it will try connecting to new nodes the second it'll get the addr message
you can find them here:

livenet: https://github.com/bitcoin/bitcoin/blob/master/src/chainparams.cpp#L102
testnet: https://github.com/bitcoin/bitcoin/blob/master/src/chainparams.cpp#L181

elichai2
  • 1,365
  • 3
  • 14
  • 28
  • 1
    There ARE hardcoded nodes. The hardcoded nodes is a backup mechanism if DNS fails. See https://github.com/bitcoin/bitcoin/blob/v0.13.1/src/chainparamsseeds.h – Oscar Guindzberg Nov 18 '16 at 21:25