Skip to content

Commit 0ce44e8

Browse files
committed
protocol: add FILTER_DURATION_LONGER
1 parent bcc88e7 commit 0ce44e8

File tree

7 files changed

+51
-1
lines changed

7 files changed

+51
-1
lines changed

debian/changelog

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
cm4all-pond (0.34) unstable; urgency=low
22

33
* zeroconf: append the host name to the service name
4+
* protocol: add FILTER_DURATION_LONGER
45
* protocol: add attribute CONTENT_TYPE
56

67
--

src/Connection.cxx

+16
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,22 @@ try {
484484
throw SimplePondError{"Duplicate FILTER_GENERATOR"};
485485

486486
return BufferedResult::AGAIN;
487+
488+
case PondRequestCommand::FILTER_DURATION_LONGER:
489+
if (!current.MatchId(id) ||
490+
current.command != PondRequestCommand::QUERY)
491+
throw SimplePondError{"Misplaced FILTER_DURATION_LONGER"};
492+
493+
if (current.filter.duration.HasLonger())
494+
throw SimplePondError{"Duplicate FILTER_DURATION_LONGER"};
495+
496+
if (payload.size() != sizeof(uint64_t))
497+
throw SimplePondError{"Malformed FILTER_DURATION_LONGER"};
498+
499+
current.filter.duration.longer = Net::Log::Duration{FromBE64(*(const uint64_t *)(const void *)payload.data())};
500+
if (!current.filter.duration.HasLonger())
501+
throw SimplePondError{"Malformed FILTER_DURATION_LONGER"};
502+
return BufferedResult::AGAIN;
487503
}
488504

489505
throw SimplePondError{"Command not implemented"};

src/Filter.cxx

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ inline bool
3535
Filter::MatchMore(const Net::Log::Datagram &d) const noexcept
3636
{
3737
return http_status(static_cast<uint16_t>(d.http_status)) &&
38+
duration(d) &&
3839
MatchFilter(d.host, hosts) &&
3940
MatchFilter(d.generator, generators) &&
4041
MatchHttpUriStartsWith(d.http_uri, http_uri_starts_with);

src/Filter.hxx

+19
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@ struct Filter {
4545
}
4646
} timestamp;
4747

48+
struct {
49+
Net::Log::Duration longer = Net::Log::Duration::zero();
50+
51+
constexpr bool HasLonger() const noexcept {
52+
return longer != Net::Log::Duration::zero();
53+
}
54+
55+
constexpr operator bool() const noexcept {
56+
return HasLonger();
57+
}
58+
59+
constexpr bool operator()(const auto &d) const noexcept {
60+
return !*this ||
61+
(d.valid_duration && d.duration >= longer);
62+
63+
}
64+
} duration;
65+
4866
Net::Log::Type type = Net::Log::Type::UNSPECIFIED;
4967

5068
struct {
@@ -74,6 +92,7 @@ private:
7492
[[gnu::pure]]
7593
bool NeedMore() const noexcept {
7694
return http_status || !hosts.empty() ||
95+
duration ||
7796
!generators.empty() ||
7897
!http_uri_starts_with.empty();
7998
}

src/Protocol.hxx

+6
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ enum class PondRequestCommand : uint16_t {
121121
* the exact string to compare with.
122122
*/
123123
FILTER_GENERATOR = 18,
124+
125+
/**
126+
* Specify a filter on the "duration" attribute. Payload is
127+
* a 64 bit unsigned integer [microseconds].
128+
*/
129+
FILTER_DURATION_LONGER = 19,
124130
};
125131

126132
enum class PondResponseCommand : uint16_t {

src/client/Main.cxx

+7
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ ParseFilterItem(Filter &filter, PondGroupSitePayload &group_site,
164164
PrecedingMidnightLocal(std::chrono::system_clock::now());
165165
filter.timestamp.since = Net::Log::FromSystem(midnight);
166166
filter.timestamp.until = Net::Log::FromSystem(midnight + std::chrono::hours(24));
167+
} else if (auto duration_longer = IsFilter(p, "duration_longer")) {
168+
auto d = ParseDuration(duration_longer);
169+
filter.duration.longer = std::chrono::duration_cast<Net::Log::Duration>(d.first);
167170
} else if (auto type_string = IsFilter(p, "type")) {
168171
filter.type = Net::Log::ParseType(type_string);
169172
if (filter.type == Net::Log::Type::UNSPECIFIED)
@@ -338,6 +341,10 @@ Query(const PondServerSpecification &server, ConstBuffer<const char *> args)
338341
if (filter.timestamp.HasUntil())
339342
client.Send(id, PondRequestCommand::FILTER_UNTIL, filter.timestamp.until);
340343

344+
if (filter.duration.HasLonger())
345+
client.Send(id, PondRequestCommand::FILTER_DURATION_LONGER,
346+
filter.duration.longer);
347+
341348
if (filter.http_status) {
342349
PondFilterHttpStatusPayload status;
343350
status.begin = ToBE16(filter.http_status.begin);

0 commit comments

Comments
 (0)