aboutsummaryrefslogtreecommitdiff
path: root/src/protocol.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2015-11-06 01:32:04 +0100
committerPieter Wuille <pieter.wuille@gmail.com>2016-06-22 15:42:59 +0200
commit7030d9eb47254499bba14f1c00abc6bf493efd91 (patch)
tree95055978907c7418c1b96728ff09413781b9c0b7 /src/protocol.cpp
parentecacfd98e657c5819a1bcb1da93b25d3ad4e5045 (diff)
downloadbitcoin-7030d9eb47254499bba14f1c00abc6bf493efd91.tar.xz
BIP144: Serialization, hashes, relay (sender side)
Contains refactorings by Eric Lombrozo. Contains fixup by Nicolas Dorier. Contains cleanup of CInv::GetCommand by Alex Morcos
Diffstat (limited to 'src/protocol.cpp')
-rw-r--r--src/protocol.cpp46
1 files changed, 13 insertions, 33 deletions
diff --git a/src/protocol.cpp b/src/protocol.cpp
index 2f90fb764c..247c6c2120 100644
--- a/src/protocol.cpp
+++ b/src/protocol.cpp
@@ -41,15 +41,6 @@ const char *GETBLOCKTXN="getblocktxn";
const char *BLOCKTXN="blocktxn";
};
-static const char* ppszTypeName[] =
-{
- "ERROR", // Should never occur
- NetMsgType::TX,
- NetMsgType::BLOCK,
- "filtered block", // Should never occur
- "compact block" // Should never occur
-};
-
/** All known message types. Keep this in the same order as the list of
* messages above and in protocol.h.
*/
@@ -166,37 +157,26 @@ CInv::CInv(int typeIn, const uint256& hashIn)
hash = hashIn;
}
-CInv::CInv(const std::string& strType, const uint256& hashIn)
-{
- unsigned int i;
- for (i = 1; i < ARRAYLEN(ppszTypeName); i++)
- {
- if (strType == ppszTypeName[i])
- {
- type = i;
- break;
- }
- }
- if (i == ARRAYLEN(ppszTypeName))
- throw std::out_of_range(strprintf("CInv::CInv(string, uint256): unknown type '%s'", strType));
- hash = hashIn;
-}
-
bool operator<(const CInv& a, const CInv& b)
{
return (a.type < b.type || (a.type == b.type && a.hash < b.hash));
}
-bool CInv::IsKnownType() const
+std::string CInv::GetCommand() const
{
- return (type >= 1 && type < (int)ARRAYLEN(ppszTypeName));
-}
-
-const char* CInv::GetCommand() const
-{
- if (!IsKnownType())
+ std::string cmd;
+ if (type & MSG_WITNESS_FLAG)
+ cmd.append("witness-");
+ int masked = type & MSG_TYPE_MASK;
+ switch (masked)
+ {
+ case MSG_TX: return cmd.append(NetMsgType::TX);
+ case MSG_BLOCK: return cmd.append(NetMsgType::BLOCK);
+ case MSG_FILTERED_BLOCK: return cmd.append(NetMsgType::MERKLEBLOCK);
+ case MSG_CMPCT_BLOCK: return cmd.append(NetMsgType::CMPCTBLOCK);
+ default:
throw std::out_of_range(strprintf("CInv::GetCommand(): type=%d unknown type", type));
- return ppszTypeName[type];
+ }
}
std::string CInv::ToString() const