Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions docs/packet_filter_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_repeater/Filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 9 additions & 5 deletions examples/simple_repeater/FilterStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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("..");
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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]);
Expand Down
16 changes: 16 additions & 0 deletions test/test_filter_channel/test_filter_channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions test/test_filterstats/test_filterstats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
Loading