This is more of a technical/programming question.

I am referring to this line of code: https://github.com/bitcoin/bitcoin/blob/be992701b018f256db6d64786624be4cb60d8975/src/net_processing.cpp#L1699

I understand the logic behind not sending a version packet to a newly accepted connection unless they send one first, but the code I linked to does not quite do that, or does it?

At that point we are already inside an if block which verifies that the command received is "version", so the peer has already sent us a version packet, irrespective of who initiated the connection. Am I missing something?

up vote 1 down vote accepted
  • First the peer who chooses to connect shares their version.
  • Each of the peers can only send one version message.

PushNodeVersion is used to send the version message. It is called by two functions

1) PeerLogicValidation::InitializeNode when the connection is outbound.

2) ProcessMessage when a message is received. It looks like this:

bool static ProcessMessage(...) {
    if (strCommand == NetMsgType::VERSION) {
        if (pfrom->fInbound)
            PushNodeVersion(pfrom, connman, GetAdjustedTime());
    }
}

If it was

    if (strCommand == NetMsgType::VERSION) {
        // If this if clause didn't exist: if (pfrom->fInbound)
            PushNodeVersion(pfrom, connman, GetAdjustedTime());
    }

Consider the following case:

1) Client A connects to Client B

2) Client A sends its version to Client B

3) Client B, as an answer, shares its version

Now, if that if caluse didn't exist, Client A would send the version message once again.

The comment // Be shy and don't send version until we hear is actually irrelevant.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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