Bitcoin Forum
May 09, 2024, 06:12:19 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How is bitcoind “shy” when exchanging `version` packets?  (Read 169 times)
pgmforever (OP)
Newbie
*
Offline Offline

Activity: 16
Merit: 12


View Profile
October 10, 2018, 03:46:15 PM
Merited by AdolfinWolf (1)
 #1

Hello,

I posted this question on bitcoin.SE so I'll just leave the link here if anyone wants to answer that, but paste the full question here as well.

Link: https://bitcoin.stackexchange.com/questions/79991/how-is-bitcoind-shy-when-exchanging-version-packets

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?

1715235139
Hero Member
*
Offline Offline

Posts: 1715235139

View Profile Personal Message (Offline)

Ignore
1715235139
Reply with quote  #2

1715235139
Report to moderator
1715235139
Hero Member
*
Offline Offline

Posts: 1715235139

View Profile Personal Message (Offline)

Ignore
1715235139
Reply with quote  #2

1715235139
Report to moderator
TalkImg was created especially for hosting images on bitcointalk.org: try it next time you want to post an image
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715235139
Hero Member
*
Offline Offline

Posts: 1715235139

View Profile Personal Message (Offline)

Ignore
1715235139
Reply with quote  #2

1715235139
Report to moderator
theymos
Administrator
Legendary
*
Offline Offline

Activity: 5194
Merit: 12976


View Profile
October 10, 2018, 11:26:43 PM
Last edit: October 11, 2018, 12:09:26 AM by theymos
Merited by Foxpup (4)
 #2

If you initiate the connection, then you send a version right away, and so when you receive a version in return, you don't want to send another one. If the peer initiates the connection, then you ignore them until you receive a version, and when you do, you then need to respond with a version of your own. That's what that if statement is about.

Very old versions would immediately send a version as soon as the TCP connection was opened, regardless of whether it was incoming or outgoing. The comment is maybe a little confusing because it's sort-of talking about changing this ancient behavior.

1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
pgmforever (OP)
Newbie
*
Offline Offline

Activity: 16
Merit: 12


View Profile
October 11, 2018, 07:31:15 AM
 #3

If you initiate the connection, then you send a version right away, and so when you receive a version in return, you don't want to send another one. If the peer initiates the connection, then you ignore them until you receive a version, and when you do, you then need to respond with a version of your own. That's what that if statement is about.

Very old versions would immediately send a version as soon as the TCP connection was opened, regardless of whether it was incoming or outgoing. The comment is maybe a little confusing because it's sort-of talking about changing this ancient behavior.

So basically at that point I know that I received a version, the question is whether I should send one back or not and that depends on who opened the connection (because if I did then I already sent one). Makes sense and is compliant with the code, but got nothing to do with shyness (letting the other peer send one first). So yeah I guess the comment is just kinda confusing Smiley Thanks a lot
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!