Bitcoin Forum
May 10, 2024, 11:43:36 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: why is alert message being sent before handshake completes?  (Read 178 times)
pooya87 (OP)
Legendary
*
Offline Offline

Activity: 3444
Merit: 10558



View Profile
December 13, 2019, 03:29:10 PM
 #1

all i have to do is to send the "version" message and the other node (v. 0.19.0.1) sends 3 messages: version+verack (as expected) alongside an alert message which seems strange because i have not yet sent any verack messages back to complete the handshake.
is alert a special case or does it happen with other messages too?

i am also wondering why bitcoin core nodes can't recognize a message if it has preceding garbage bytes (random bytes before the magic) but they are fine if it is after it. what's the point of magic then if it isn't used as the message start marker?

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
1715341416
Hero Member
*
Offline Offline

Posts: 1715341416

View Profile Personal Message (Offline)

Ignore
1715341416
Reply with quote  #2

1715341416
Report to moderator
1715341416
Hero Member
*
Offline Offline

Posts: 1715341416

View Profile Personal Message (Offline)

Ignore
1715341416
Reply with quote  #2

1715341416
Report to moderator
"Your bitcoin is secured in a way that is physically impossible for others to access, no matter for what reason, no matter how good the excuse, no matter a majority of miners, no matter what." -- Greg Maxwell
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3388
Merit: 6635


Just writing some code


View Profile WWW
December 13, 2019, 04:44:44 PM
Last edit: December 14, 2019, 05:40:12 AM by achow101
Merited by Foxpup (3), darosior (2), pooya87 (1), ABCbits (1), hugeblack (1), Heisenberg_Hunter (1)
 #2

It's because of TCP guaranteeing order.

The verack is sent first, so the other node will receive that first. If they like the version and verack, then they can send their own verack indicating readiness to receive further messages. If not, they will just kill the connection. The protocol is not violated by sending the alert immediately after the verack and nothing bad happens.

The alert message in this instance is a special message. It is part of the old P2P alert system that has since been deprecated and removed. The alert message is only sent to old nodes that indicate that they still have the alert system. It is being sent immediately after connecting because that alert message will cause the "Alert Key Compromised" message to be displayed on nodes that still have the alert system.

However sending messages immediately after verack before receiving the other node's verack is a common thing to do. There are a couple of other messages that are not responses to anything and can just be sent immediately after verack. You should see this same behavior with the sendheaders message.

i am also wondering why bitcoin core nodes can't recognize a message if it has preceding garbage bytes (random bytes before the magic) but they are fine if it is after it. what's the point of magic then if it isn't used as the message start marker?
Because it is expecting only messages in discrete chunks. TCP generally gives it the messages in a single recv(). It is expecting the magic bytes at the beginning. If someone is sending garbage, then it wants to just disconnect as fast as possible because that could be a DoS attack. However garbage at the end of the message is fine because the message itself is self descriptive in size and garbage after the message can be discarded.

The magic bytes are not a start marker. They are an unique identifier.

odolvlobo
Legendary
*
Offline Offline

Activity: 4312
Merit: 3214



View Profile
December 13, 2019, 05:52:58 PM
 #3

i am also wondering why bitcoin core nodes can't recognize a message if it has preceding garbage bytes (random bytes before the magic) but they are fine if it is after it. what's the point of magic then if it isn't used as the message start marker?
Because it is expecting only messages in discrete chunks. TCP generally gives it the messages in a single recv(). It is expecting the magic bytes at the beginning. If someone is sending garbage, then it wants to just disconnect as fast as possible because that could be a DoS attack. However garbage at the end of the message is fine because the message itself is self descriptive in size and garbage after the message can be discarded.
The magic bytes are not a start marker. They are an unique identifier.
As Andrew stated, a message is a discrete chunk of data, but this is not determined by TCP or recv(). Bitcoin divides the TCP stream into distinct messages, each containing a header and a payload. Garbage cannot precede or follow a message, but the payload can contain extra data at the end that will be ignored.

Join an anti-signature campaign: Click ignore on the members of signature campaigns.
PGP Fingerprint: 6B6BC26599EC24EF7E29A405EAF050539D0B2925 Signing address: 13GAVJo8YaAuenj6keiEykwxWUZ7jMoSLt
pooya87 (OP)
Legendary
*
Offline Offline

Activity: 3444
Merit: 10558



View Profile
December 14, 2019, 04:21:39 AM
 #4

The protocol is not violated by sending the alert immediately after the verack and nothing bad happens.
it is a little odd because i was expecting the "handshake" to be more strict like how TCP handshake (SYN, ACK packets exchange before any data is exchanged) is strict.

Quote
You should see this same behavior with the sendheaders message.
interesting. i have not encountered this yet, they all seem to be waiting for my verack after sending the 3 messages.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
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!