Skip to content

Commit 475b1c6

Browse files
theunifurszy
authored andcommitted
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 8a6c72b commit 475b1c6

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/net_processing.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,14 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
12901290
(fLogIPs ? strprintf(", peeraddr=%s", pfrom->addr.ToString()) : ""));
12911291
}
12921292

1293+
else if (!pfrom->fSuccessfullyConnected)
1294+
{
1295+
// Must have a verack message before anything else
1296+
LOCK(cs_main);
1297+
Misbehaving(pfrom->GetId(), 1);
1298+
return false;
1299+
}
1300+
12931301

12941302
else if (strCommand == NetMsgType::ADDR || strCommand == NetMsgType::ADDRV2) {
12951303
int stream_version = vRecv.GetVersion();

0 commit comments

Comments
 (0)