Skip to content

Commit 5948398

Browse files
author
MarcoFalke
committed
Merge #17474: Bugfix: GUI: Recognise NETWORK_LIMITED in formatServicesStr
4341bff GUI: Refactor formatServicesStr to warn when a ServicesFlag is missing (Luke Dashjr) df77de8 Bugfix: GUI: Recognise NETWORK_LIMITED in formatServicesStr (Luke Dashjr) Pull request description: Currently, only the bottom 8 service bits are shown in the GUI peer details view. `NODE_NETWORK_LIMITED` is the 11th bit (2^10). The first commit expands the range to cover the full 64 bits, and properly label `"NETWORK_LIMITED"`. The second commit refactors the code so that any future omitted service bits will trigger a compile warning. ACKs for top commit: jonasschnelli: utACK 4341bff jonasschnelli: Tested ACK 4341bff hebasto: Concept ACK 4341bff Tree-SHA512: 8338737d03fbcd92024159aabd7e632d46e13c72436d935b504d2bf7ee92b7d124e89a5917bf64d51c87f12a64de703270c2d7b4c6711fa8ed08ea7887d817c7
2 parents 7da9e3a + 4341bff commit 5948398

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

src/protocol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ const std::vector<std::string> &getAllNetMessageTypes();
237237

238238
/** nServices flags */
239239
enum ServiceFlags : uint64_t {
240+
// NOTE: When adding here, be sure to update qt/guiutil.cpp's formatServicesStr too
240241
// Nothing
241242
NODE_NONE = 0,
242243
// NODE_NETWORK means that the node is capable of serving the complete block chain. It is currently

src/qt/guiutil.cpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -731,32 +731,33 @@ QString formatDurationStr(int secs)
731731
return strList.join(" ");
732732
}
733733

734+
QString serviceFlagToStr(const quint64 mask, const int bit)
735+
{
736+
switch (ServiceFlags(mask)) {
737+
case NODE_NONE: abort(); // impossible
738+
case NODE_NETWORK: return "NETWORK";
739+
case NODE_GETUTXO: return "GETUTXO";
740+
case NODE_BLOOM: return "BLOOM";
741+
case NODE_WITNESS: return "WITNESS";
742+
case NODE_NETWORK_LIMITED: return "NETWORK_LIMITED";
743+
// Not using default, so we get warned when a case is missing
744+
}
745+
if (bit < 8) {
746+
return QString("%1[%2]").arg("UNKNOWN").arg(mask);
747+
} else {
748+
return QString("%1[2^%2]").arg("UNKNOWN").arg(bit);
749+
}
750+
}
751+
734752
QString formatServicesStr(quint64 mask)
735753
{
736754
QStringList strList;
737755

738-
// Just scan the last 8 bits for now.
739-
for (int i = 0; i < 8; i++) {
740-
uint64_t check = 1 << i;
756+
for (int i = 0; i < 64; i++) {
757+
uint64_t check = 1LL << i;
741758
if (mask & check)
742759
{
743-
switch (check)
744-
{
745-
case NODE_NETWORK:
746-
strList.append("NETWORK");
747-
break;
748-
case NODE_GETUTXO:
749-
strList.append("GETUTXO");
750-
break;
751-
case NODE_BLOOM:
752-
strList.append("BLOOM");
753-
break;
754-
case NODE_WITNESS:
755-
strList.append("WITNESS");
756-
break;
757-
default:
758-
strList.append(QString("%1[%2]").arg("UNKNOWN").arg(check));
759-
}
760+
strList.append(serviceFlagToStr(check, i));
760761
}
761762
}
762763

0 commit comments

Comments
 (0)