#include <inttypes.h>
#include <stddef.h>
#include <stdint.h>
+#include <string.h>
#include <sys/types.h>
struct siphash {
uint64_t siphash24_finalize(struct siphash *state);
uint64_t siphash24(const void *in, size_t inlen, const uint8_t k[16]);
+
+static inline uint64_t siphash24_string(const char *s, const uint8_t k[16]) {
+ return siphash24(s, strlen(s) + 1, k);
+}
static JournalRateLimitGroup* journal_rate_limit_group_new(JournalRateLimit *r, const char *id, usec_t ts) {
JournalRateLimitGroup *g;
- struct siphash state;
assert(r);
assert(id);
if (!g->id)
goto fail;
- siphash24_init(&state, r->hash_key);
- string_hash_func(g->id, &state);
- g->hash = siphash24_finalize(&state);
+ g->hash = siphash24_string(g->id, r->hash_key);
journal_rate_limit_vacuum(r, ts);
uint64_t h;
JournalRateLimitGroup *g;
JournalRateLimitPool *p;
- struct siphash state;
unsigned burst;
usec_t ts;
ts = now(CLOCK_MONOTONIC);
- siphash24_init(&state, r->hash_key);
- string_hash_func(id, &state);
- h = siphash24_finalize(&state);
+ h = siphash24_string(id, r->hash_key);
g = r->buckets[h % BUCKETS_MAX];
LIST_FOREACH(bucket, g, g)