diff options
Diffstat (limited to 'src/protocol.cpp')
-rw-r--r-- | src/protocol.cpp | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/src/protocol.cpp b/src/protocol.cpp index 737baff36b..83a24b9d95 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -40,6 +40,8 @@ const char *SENDCMPCT="sendcmpct"; const char *CMPCTBLOCK="cmpctblock"; const char *GETBLOCKTXN="getblocktxn"; const char *BLOCKTXN="blocktxn"; +const char *GETCFILTERS="getcfilters"; +const char *CFILTER="cfilter"; const char *GETCFHEADERS="getcfheaders"; const char *CFHEADERS="cfheaders"; const char *GETCFCHECKPT="getcfcheckpt"; @@ -75,6 +77,8 @@ const static std::string allNetMessageTypes[] = { NetMsgType::CMPCTBLOCK, NetMsgType::GETBLOCKTXN, NetMsgType::BLOCKTXN, + NetMsgType::GETCFILTERS, + NetMsgType::CFILTER, NetMsgType::GETCFHEADERS, NetMsgType::CFHEADERS, NetMsgType::GETCFCHECKPT, @@ -195,9 +199,15 @@ const std::vector<std::string> &getAllNetMessageTypes() return allNetMessageTypesVec; } -std::string serviceFlagToStr(const uint64_t mask, const int bit) +/** + * Convert a service flag (NODE_*) to a human readable string. + * It supports unknown service flags which will be returned as "UNKNOWN[...]". + * @param[in] bit the service flag is calculated as (1 << bit) + */ +static std::string serviceFlagToStr(size_t bit) { - switch (ServiceFlags(mask)) { + const uint64_t service_flag = 1ULL << bit; + switch ((ServiceFlags)service_flag) { case NODE_NONE: abort(); // impossible case NODE_NETWORK: return "NETWORK"; case NODE_GETUTXO: return "GETUTXO"; @@ -211,10 +221,23 @@ std::string serviceFlagToStr(const uint64_t mask, const int bit) stream.imbue(std::locale::classic()); stream << "UNKNOWN["; if (bit < 8) { - stream << mask; + stream << service_flag; } else { stream << "2^" << bit; } stream << "]"; return stream.str(); } + +std::vector<std::string> serviceFlagsToStr(uint64_t flags) +{ + std::vector<std::string> str_flags; + + for (size_t i = 0; i < sizeof(flags) * 8; ++i) { + if (flags & (1ULL << i)) { + str_flags.emplace_back(serviceFlagToStr(i)); + } + } + + return str_flags; +} |