diff --git a/docs/packet_filter_reference.md b/docs/packet_filter_reference.md index 71dc1fc1d3e..7ff86d5362a 100644 --- a/docs/packet_filter_reference.md +++ b/docs/packet_filter_reference.md @@ -688,19 +688,19 @@ Display per-packet-type statistics: ```text filter count -[TYPE: HOPS,RATE] -00: 0,0 -01: 0,0 -02: 0,0 -03: 0,0 -04: 0,0 -05: 2,10 -06: 0,0 -07: 0,0 -08: 0,0 -09: 0,0 -10: 0,0 -11: 0,0 +[TYPE: HOPS, RATE] +00: 0, 0 +01: 0, 0 +02: 0, 0 +03: 0, 0 +04: 0, 0 +05: 2, 10 +06: 0, 0 +07: 0, 0 +08: 0, 0 +09: 0, 0 +10: 0, 0 +11: 0, 0 ``` Meaning: @@ -778,7 +778,7 @@ rather than abuse — nodes flood with 1-byte path hashes by default. ```text filter stats channel -#bot (a3): 412,#test (5c): 0 +#bot (a3): 412, #test (5c): 0 ``` ### malformed @@ -833,7 +833,7 @@ the line ends in `(clock not set, inactive)`. ```text filter stats path -A1B2: 412,C3: 0 +A1B2: 412, C3: 0 ``` Drops per blocked prefix, so you can tell which entry is doing the work. @@ -845,7 +845,7 @@ filter sender list Bob throttle 60s,Bot* block 50%,SpamBot block filter stats sender -Bob: 12 (pass 3),Bot*: 40,SpamBot: 5 +Bob: 12 (pass 3), Bot*: 40, SpamBot: 5 ``` The setting view shows each rule's mode; the stats view shows the drops it diff --git a/examples/simple_repeater/Filter.cpp b/examples/simple_repeater/Filter.cpp index 07f8637250a..d3160ea40e8 100644 --- a/examples/simple_repeater/Filter.cpp +++ b/examples/simple_repeater/Filter.cpp @@ -729,7 +729,7 @@ void Filter::listChannelNames(char *out_buf, size_t out_size, bool with_counts) mesh::Utils::toHex(channel_hex, _prefs.filter_channels[i].channel.hash, 1); const char *mode = _prefs.channel_hash_only[i] ? " hash" : ""; if (with_counts) { - b.add(listed > 0 ? ",%s (%s%s): %lu" : "%s (%s%s): %lu", + b.add(listed > 0 ? ", %s (%s%s): %lu" : "%s (%s%s): %lu", name, channel_hex, mode, (unsigned long)_cnt.channel_slot[i]); } else { b.add(listed > 0 ? ",%s (%s%s)" : "%s (%s%s)", name, channel_hex, mode); diff --git a/examples/simple_repeater/FilterStats.h b/examples/simple_repeater/FilterStats.h index 8db19678f55..d2065f5eb0f 100644 --- a/examples/simple_repeater/FilterStats.h +++ b/examples/simple_repeater/FilterStats.h @@ -261,7 +261,11 @@ namespace FilterStat { return (a > 0xFFFFFFFFu - b) ? 0xFFFFFFFFu : a + b; } - // ---- `filter` and `filter count`: unchanged shapes, now bounded ------------ + // ---- `filter` and `filter count`: bounded ----------------------------------- + // + // Statistics replies separate entries with ", " so they read easily. The setting + // views (`filter rate`, `filter ... list`) keep a bare ",": clients parse those + // back, and the reply size caps how many entries they can show. inline void formatSummary(char* out, size_t cap, const Counters& c, bool enabled, bool dryrun = false) { uint32_t hops_total = 0; @@ -284,9 +288,9 @@ namespace FilterStat { inline void formatCount(char* out, size_t cap, const Counters& c) { Buf b(out, cap); - b.add("[TYPE: HOPS,RATE]"); + b.add("[TYPE: HOPS, RATE]"); for (uint8_t i = 0; i < PAYLOAD_TYPE_COUNT; i++) { - b.add("\n%02u: %lu,%lu", (unsigned)i, (unsigned long)c.hops[i], (unsigned long)c.rate[i]); + b.add("\n%02u: %lu, %lu", (unsigned)i, (unsigned long)c.hops[i], (unsigned long)c.rate[i]); } b.markTruncated(".."); } @@ -434,7 +438,7 @@ namespace FilterStat { if (list[i].len == 0) continue; FilterPath::format(hex, sizeof(hex), list[i]); if (counts != nullptr) { - b.add(listed > 0 ? ",%s: %lu" : "%s: %lu", hex, (unsigned long)counts->path_slot[i]); + b.add(listed > 0 ? ", %s: %lu" : "%s: %lu", hex, (unsigned long)counts->path_slot[i]); } else { b.add(listed > 0 ? ",%s" : "%s", hex); } @@ -483,7 +487,7 @@ namespace FilterStat { for (int i = 0; i < count; i++) { const char* pat = FilterRules::patternOf(rules[i]); if (pat[0] == '\0') continue; - if (listed > 0) b.add(","); + if (listed > 0) b.add(drops != nullptr ? ", " : ","); if (drops != nullptr) { b.add("%s: %lu", pat, (unsigned long)drops[i]); if (passes != nullptr && passes[i] > 0) b.add(" (pass %lu)", (unsigned long)passes[i]); diff --git a/test/test_filter_channel/test_filter_channel.cpp b/test/test_filter_channel/test_filter_channel.cpp index 0109e836965..5f779a3b814 100644 --- a/test/test_filter_channel/test_filter_channel.cpp +++ b/test/test_filter_channel/test_filter_channel.cpp @@ -120,6 +120,22 @@ TEST_F(ChannelFilterTest, ChannelNamedHashIsStillAKeyEntry) { EXPECT_EQ(nullptr, strstr(reply, " hash)")) << reply; } +TEST_F(ChannelFilterTest, StatsSeparatesEntriesWithCommaAndSpace) { + command(filter, fs, "filter channel add #nl", reply); + command(filter, fs, "filter channel add hash #bot", reply); + command(filter, fs, "filter stats channel", reply); + EXPECT_STREQ("#nl (23): 0, #bot (23 hash): 0", reply); +} + +// The toolbox reads this list back, so it keeps the compact form: every byte +// spent on a separator is one less for a channel name. +TEST_F(ChannelFilterTest, ListStaysCompact) { + command(filter, fs, "filter channel add #nl", reply); + command(filter, fs, "filter channel add hash #bot", reply); + command(filter, fs, "filter channel list", reply); + EXPECT_STREQ("#nl (23),#bot (23 hash)", reply); +} + int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/test/test_filterstats/test_filterstats.cpp b/test/test_filterstats/test_filterstats.cpp index 27260e38b43..1fad704e4ab 100644 --- a/test/test_filterstats/test_filterstats.cpp +++ b/test/test_filterstats/test_filterstats.cpp @@ -385,7 +385,7 @@ TEST(FilterStatsCount, KeepsListingEveryPayloadType) { FilterStat::formatCount(out, sizeof(out), c); - EXPECT_EQ(0u, strncmp(out, "[TYPE: HOPS,RATE]\n00: 0,0\n01: 0,0\n02: 0,4\n03: 0,0\n04: 300,0", 59)) << "got: " << out; + EXPECT_EQ(0u, strncmp(out, "[TYPE: HOPS, RATE]\n00: 0, 0\n01: 0, 0\n02: 0, 4\n03: 0, 0\n04: 300, 0", 65)) << "got: " << out; } TEST(FilterStatsCount, MarksClippedOutputInsteadOfDroppingRowsSilently) { @@ -701,7 +701,7 @@ TEST(FilterStatsPath, ListsEveryPrefixWithItsDrops) { FilterStat::formatPathList(out, sizeof(out), list, &c); - EXPECT_STREQ("A1: 5,B2C3: 0", out); + EXPECT_STREQ("A1: 5, B2C3: 0", out); } TEST(FilterStatsPath, ListsPrefixesWithoutCountsForTheSettingView) { @@ -800,7 +800,7 @@ TEST(FilterStatsRules, ListsDropsAndPassesForTheStatsView) { FilterStat::formatRuleList(out, sizeof(out), rules, FILTER_RULE_COUNT, drops, passes); - EXPECT_STREQ("Bot*: 12 (pass 3),Spam: 5", out); + EXPECT_STREQ("Bot*: 12 (pass 3), Spam: 5", out); } TEST(FilterStatsRules, SaysNoneWhenNoRuleIsSet) {