Skip to content

Commit 8502e7a

Browse files
committed
net: parse reject earlier
Prior to this change, all messages were ignored until a VERSION message was received, as well as possibly incurring a ban score. Since REJECT messages can be sent at any time (including as a response to a bad VERSION message), make sure to always parse them. Moving this parsing up keeps it from being caught in the if (pfrom->nVersion == 0) check below.
1 parent c45b9fb commit 8502e7a

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

src/net_processing.cpp

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,8 +1190,31 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
11901190
}
11911191
}
11921192

1193+
if (strCommand == NetMsgType::REJECT)
1194+
{
1195+
if (fDebug) {
1196+
try {
1197+
std::string strMsg; unsigned char ccode; std::string strReason;
1198+
vRecv >> LIMITED_STRING(strMsg, CMessageHeader::COMMAND_SIZE) >> ccode >> LIMITED_STRING(strReason, MAX_REJECT_MESSAGE_LENGTH);
1199+
1200+
std::ostringstream ss;
1201+
ss << strMsg << " code " << itostr(ccode) << ": " << strReason;
11931202

1194-
if (strCommand == NetMsgType::VERSION)
1203+
if (strMsg == NetMsgType::BLOCK || strMsg == NetMsgType::TX)
1204+
{
1205+
uint256 hash;
1206+
vRecv >> hash;
1207+
ss << ": hash " << hash.ToString();
1208+
}
1209+
LogPrint("net", "Reject %s\n", SanitizeString(ss.str()));
1210+
} catch (const std::ios_base::failure&) {
1211+
// Avoid feedback loops by preventing reject messages from triggering a new reject message.
1212+
LogPrint("net", "Unparseable reject message received\n");
1213+
}
1214+
}
1215+
}
1216+
1217+
else if (strCommand == NetMsgType::VERSION)
11951218
{
11961219
// Each connection can only send one version message
11971220
if (pfrom->nVersion != 0)
@@ -2544,31 +2567,6 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
25442567
pfrom->fRelayTxes = true;
25452568
}
25462569

2547-
2548-
else if (strCommand == NetMsgType::REJECT)
2549-
{
2550-
if (fDebug) {
2551-
try {
2552-
std::string strMsg; unsigned char ccode; std::string strReason;
2553-
vRecv >> LIMITED_STRING(strMsg, CMessageHeader::COMMAND_SIZE) >> ccode >> LIMITED_STRING(strReason, MAX_REJECT_MESSAGE_LENGTH);
2554-
2555-
std::ostringstream ss;
2556-
ss << strMsg << " code " << itostr(ccode) << ": " << strReason;
2557-
2558-
if (strMsg == NetMsgType::BLOCK || strMsg == NetMsgType::TX)
2559-
{
2560-
uint256 hash;
2561-
vRecv >> hash;
2562-
ss << ": hash " << hash.ToString();
2563-
}
2564-
LogPrint("net", "Reject %s\n", SanitizeString(ss.str()));
2565-
} catch (const std::ios_base::failure&) {
2566-
// Avoid feedback loops by preventing reject messages from triggering a new reject message.
2567-
LogPrint("net", "Unparseable reject message received\n");
2568-
}
2569-
}
2570-
}
2571-
25722570
else if (strCommand == NetMsgType::FEEFILTER) {
25732571
CAmount newFeeFilter = 0;
25742572
vRecv >> newFeeFilter;

0 commit comments

Comments
 (0)