Skip to content

Commit cbfc5a6

Browse files
committed
net: require a verack before responding to anything else
7a8c251 made this logic hard to follow. After that change, messages would not be sent to a peer via SendMessages() before the handshake was complete, but messages could still be sent as a response to an incoming message. For example, if a peer had not yet sent a verack, we wouldn't notify it about new blocks, but we would respond to a PING with a PONG. This change makes the behavior straightforward: until we've received a verack, never send any message other than version/verack/reject. The behavior until a VERACK is received has always been undefined, this change just tightens our policy. This also makes testing much easier, because we can now connect but not send version/verack, and anything sent to us is an error.
1 parent 8502e7a commit cbfc5a6

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/net_processing.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,13 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
14201420
pfrom->fSuccessfullyConnected = true;
14211421
}
14221422

1423+
else if (!pfrom->fSuccessfullyConnected)
1424+
{
1425+
// Must have a verack message before anything else
1426+
LOCK(cs_main);
1427+
Misbehaving(pfrom->GetId(), 1);
1428+
return false;
1429+
}
14231430

14241431
else if (strCommand == NetMsgType::ADDR)
14251432
{

0 commit comments

Comments
 (0)