diff --git a/src/protocol.h b/src/protocol.h --- a/src/protocol.h +++ b/src/protocol.h @@ -61,7 +61,6 @@ std::string GetCommand() const; bool IsCommandValid() const; - bool IsValidWithoutConfig(const MessageMagic &magic) const; bool IsOversized(const Config &config) const; SERIALIZE_METHODS(CMessageHeader, obj) { diff --git a/src/protocol.cpp b/src/protocol.cpp --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -118,13 +118,13 @@ strnlen(pchCommand.data(), COMMAND_SIZE)); } -static bool CheckHeaderMagicAndCommand(const CMessageHeader &header) { +bool CMessageHeader::IsCommandValid() const { // Check the command string for errors - for (const char *p1 = header.pchCommand.data(); - p1 < header.pchCommand.data() + CMessageHeader::COMMAND_SIZE; p1++) { + for (const char *p1 = pchCommand.data(); + p1 < pchCommand.data() + CMessageHeader::COMMAND_SIZE; p1++) { if (*p1 == 0) { // Must be all zeros after the first zero - for (; p1 < header.pchCommand.data() + CMessageHeader::COMMAND_SIZE; + for (; p1 < pchCommand.data() + CMessageHeader::COMMAND_SIZE; p1++) { if (*p1 != 0) { return false; @@ -138,31 +138,6 @@ return true; } -bool CMessageHeader::IsCommandValid() const { - // Check start string - if (!CheckHeaderMagicAndCommand(*this)) { - return false; - } - - return true; -} - -/** - * This is a transition method in order to stay compatible with older code that - * do not use the config. It assumes message will not get too large. This cannot - * be used for any piece of code that will download blocks as blocks may be - * bigger than the permitted size. Idealy, code that uses this function should - * be migrated toward using the config. - */ -bool CMessageHeader::IsValidWithoutConfig(const MessageMagic &magic) const { - // Check start string - if (!CheckHeaderMagicAndCommand(*this)) { - return false; - } - - return true; -} - bool CMessageHeader::IsOversized(const Config &config) const { // If the message doesn't not contain a block content, check against // MAX_PROTOCOL_MESSAGE_LENGTH. diff --git a/src/seeder/bitcoin.cpp b/src/seeder/bitcoin.cpp --- a/src/seeder/bitcoin.cpp +++ b/src/seeder/bitcoin.cpp @@ -135,7 +135,7 @@ vRecv.begin() + nHeaderSize); CMessageHeader hdr; vRecv >> hdr; - if (!hdr.IsValidWithoutConfig(netMagic)) { + if (!hdr.IsCommandValid()) { // tfm::format(std::cout, "%s: BAD (invalid header)\n", // ToString(you)); ban = 100000; diff --git a/src/seeder/test/p2p_messaging_tests.cpp b/src/seeder/test/p2p_messaging_tests.cpp --- a/src/seeder/test/p2p_messaging_tests.cpp +++ b/src/seeder/test/p2p_messaging_tests.cpp @@ -98,16 +98,15 @@ PeerMessagingState::AwaitingMessages); // Seeder should respond with an ADDR message - const CMessageHeader::MessageMagic netMagic = Params().NetMagic(); CMessageHeader header; CDataStream sendBuffer = testNode->getSendBuffer(); sendBuffer >> header; - BOOST_CHECK(header.IsValidWithoutConfig(netMagic)); + BOOST_CHECK(header.IsCommandValid()); BOOST_CHECK_EQUAL(header.GetCommand(), NetMsgType::GETADDR); // Next message should be GETHEADERS sendBuffer >> header; - BOOST_CHECK(header.IsValidWithoutConfig(netMagic)); + BOOST_CHECK(header.IsCommandValid()); BOOST_CHECK_EQUAL(header.GetCommand(), NetMsgType::GETHEADERS); CBlockLocator locator;