Skip to content

Commit

Permalink
Merge bitcoin#18937: refactor: s/command/msg_type/ in CNetMsgMaker an…
Browse files Browse the repository at this point in the history
…d CSerializedNetMsg

51e9393 refactor: s/command/msg_type/ in CNetMsgMaker and CSerializedNetMsg (Sebastian Falbesoner)

Pull request description:

  Follow-up PR for bitcoin#18533 -- another small step towards getting rid of the confusing "command" terminology. Also see PR bitcoin#18610 which tackled the functional tests.

ACKs for top commit:
  MarcoFalke:
    ACK 51e9393

Tree-SHA512: bb6f05a7be6823d5c4eab1d05b31fee944e700946827ad9425d59a3957fd879776c88c606319cbe9832d9451b275baedf913b71429ea3e01e4e82bf2d419e819
  • Loading branch information
MarcoFalke committed Jun 19, 2020
2 parents c940c1a + 51e9393 commit 62948ca
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ void V1TransportSerializer::prepareForTransport(CSerializedNetMsg& msg, std::vec
uint256 hash = Hash(msg.data.begin(), msg.data.end());

// create header
CMessageHeader hdr(Params().MessageStart(), msg.command.c_str(), msg.data.size());
CMessageHeader hdr(Params().MessageStart(), msg.m_type.c_str(), msg.data.size());
memcpy(hdr.pchChecksum, hash.begin(), CMessageHeader::CHECKSUM_SIZE);

// serialize header
Expand Down Expand Up @@ -2794,7 +2794,7 @@ bool CConnman::NodeFullyConnected(const CNode* pnode)
void CConnman::PushMessage(CNode* pnode, CSerializedNetMsg&& msg)
{
size_t nMessageSize = msg.data.size();
LogPrint(BCLog::NET, "sending %s (%d bytes) peer=%d\n", SanitizeString(msg.command), nMessageSize, pnode->GetId());
LogPrint(BCLog::NET, "sending %s (%d bytes) peer=%d\n", SanitizeString(msg.m_type), nMessageSize, pnode->GetId());

// make sure we use the appropriate network transport format
std::vector<unsigned char> serializedHeader;
Expand All @@ -2806,8 +2806,8 @@ void CConnman::PushMessage(CNode* pnode, CSerializedNetMsg&& msg)
LOCK(pnode->cs_vSend);
bool optimisticSend(pnode->vSendMsg.empty());

//log total amount of bytes per command
pnode->mapSendBytesPerMsgCmd[msg.command] += nTotalSize;
//log total amount of bytes per message type
pnode->mapSendBytesPerMsgCmd[msg.m_type] += nTotalSize;
pnode->nSendSize += nTotalSize;

if (pnode->nSendSize > nSendBufferMaxSize)
Expand Down
2 changes: 1 addition & 1 deletion src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ struct CSerializedNetMsg
CSerializedNetMsg& operator=(const CSerializedNetMsg&) = delete;

std::vector<unsigned char> data;
std::string command;
std::string m_type;
};


Expand Down
8 changes: 4 additions & 4 deletions src/netmessagemaker.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ class CNetMsgMaker
explicit CNetMsgMaker(int nVersionIn) : nVersion(nVersionIn){}

template <typename... Args>
CSerializedNetMsg Make(int nFlags, std::string sCommand, Args&&... args) const
CSerializedNetMsg Make(int nFlags, std::string msg_type, Args&&... args) const
{
CSerializedNetMsg msg;
msg.command = std::move(sCommand);
msg.m_type = std::move(msg_type);
CVectorWriter{ SER_NETWORK, nFlags | nVersion, msg.data, 0, std::forward<Args>(args)... };
return msg;
}

template <typename... Args>
CSerializedNetMsg Make(std::string sCommand, Args&&... args) const
CSerializedNetMsg Make(std::string msg_type, Args&&... args) const
{
return Make(0, std::move(sCommand), std::forward<Args>(args)...);
return Make(0, std::move(msg_type), std::forward<Args>(args)...);
}

private:
Expand Down
2 changes: 1 addition & 1 deletion src/test/fuzz/process_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void test_one_input(const std::vector<uint8_t>& buffer)
const std::string random_message_type{fuzzed_data_provider.ConsumeBytesAsString(CMessageHeader::COMMAND_SIZE).c_str()};

CSerializedNetMsg net_msg;
net_msg.command = random_message_type;
net_msg.m_type = random_message_type;
net_msg.data = ConsumeRandomLengthByteVector(fuzzed_data_provider);

CNode& random_node = *peers.at(fuzzed_data_provider.ConsumeIntegralInRange<int>(0, peers.size() - 1));
Expand Down

0 comments on commit 62948ca

Please sign in to comment.