Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: GlowingGypsie on October 20, 2019, 01:23:20 PM



Title: How do nodes connect to each other?
Post by: GlowingGypsie on October 20, 2019, 01:23:20 PM
Clients connect to SeedDNS and connect to nodes but how do nodes connect to each other?


Title: Re: How do nodes connect to each other?
Post by: jackg on October 20, 2019, 01:29:59 PM
Bitcoin node software comes with a predetermined list of nodes that should be avaliable when the software is run.

After the initial run, the software asks those nodes for a list of recommended nodes (which has to be less than 1000) it adds these modes to peers.dat and picks the fastest few to connect to (normally 8 or so) it wants the one with the longest chain too so that it knows its up to date. So if a node has a lower speed but a longer chain it may download the next block from it and connect to it rather than the fastest node in order to stay up to date...

When the node is turned on again, it scans its peers.dat and checks the connections that are still active from it.


Title: Re: How do nodes connect to each other?
Post by: GlowingGypsie on October 20, 2019, 02:58:15 PM
I have two clients on the same wifi network and they connect to each other via IPv4 and IPv6 how the hell is that possible?


Title: Re: How do nodes connect to each other?
Post by: jackg on October 20, 2019, 03:12:09 PM
I have two clients on the same wifi network and they connect to each other via IPv4 and IPv6 how the hell is that possible?

If they both have the longest chain or one has a chain longer than the other then they are the fastest for a connection. Every so often other nodes they are connected to might get pinged too.

Generally if you have a fast switch/modem the lung speed should be less than 1ms and the rate data can be transferred at between them should obviously be higher.

I'm not sure if there's something bitcoin core uses that scans the home network for anything that it can connect to (it'd normally just have to ping 192.168.0.255 for a response from anything that can accept a connection and understand the packet sent to it).


Title: Re: How do nodes connect to each other?
Post by: BrewMaster on October 20, 2019, 03:14:55 PM
I have two clients on the same wifi network and they connect to each other via IPv4 and IPv6 how the hell is that possible?

if they are actually connected over the internet (not through any other way) then it is not surprising really. every client has an IP address that it broadcasts to others as it connects to any other node through a version message. then others send its IP to other nodes and that way it propagates. so your other client eventually finds out about that IP, most likely right away if both are connected to same node(s) and attempts connecting to that IP.


Title: Re: How do nodes connect to each other?
Post by: GlowingGypsie on October 20, 2019, 03:28:42 PM
Just weirded me out that Client A has an IPv4 and IPV6 and so does Client B. In client A i can see two IPs one v4 and v6 and both belong to client B and the same at client B I can see clients A v4 and v6 IPs. Why using both v4 and v6?


Title: Re: How do nodes connect to each other?
Post by: BrewMaster on October 20, 2019, 03:51:51 PM
Why using both v4 and v6?

it is a networking thing, not everyone has adopted IPV6 yet (in fact according to google (https://www.google.com/intl/en/ipv6/statistics.html) only 26% of the world is using it right now) but it is recommended to move to V6 because of V4 exhaustion, so if you have it you must advertise that but to let those who don't have it you must also advertise V4.
i believe what bitcoin does is that it mapps all IP addresses to V6 so it can show you both at the same time.