summaryrefslogtreecommitdiffstats
path: root/src/bloombucket.h
diff options
context:
space:
mode:
authorMatt Dunwoodie <ncon@mail.noconroy.net>2019-09-22 23:29:40 +0200
committerMatt Dunwoodie <ncon@mail.noconroy.net>2019-09-22 23:29:40 +0200
commitb5ba2568f9800eacb9bc0bef1d53bf9b1efcacb8 (patch)
tree212ffdb10ef22925af143eaa036eaded05de626f /src/bloombucket.h
parentMove antireplay to it's own header (diff)
downloadwireguard-openbsd-b5ba2568f9800eacb9bc0bef1d53bf9b1efcacb8.tar.xz
wireguard-openbsd-b5ba2568f9800eacb9bc0bef1d53bf9b1efcacb8.zip
Move functions from header files into dedicated file
The header files were nice while experimenting, but they are not ideal. Currently we have all the custom data structures in kerk/kern_wg.c, which would ideally not be named after wireguard, But for the time being, at least they're organised.
Diffstat (limited to 'src/bloombucket.h')
-rw-r--r--src/bloombucket.h89
1 files changed, 0 insertions, 89 deletions
diff --git a/src/bloombucket.h b/src/bloombucket.h
index 7bcaf863cce..b69ee5eb6c6 100644
--- a/src/bloombucket.h
+++ b/src/bloombucket.h
@@ -35,93 +35,4 @@ void bb_tick(void *);
int bb_recv(struct bloom_bucket *, uint8_t *, size_t);
uint8_t bb_load(struct bloom_bucket *);
-void
-bb_init(struct bloom_bucket *bb, size_t size, size_t keys, uint8_t interval,
- uint8_t thresh, int type, int flags)
-{
- size_t i;
-
- for (bb->size = 1; bb->size < size; bb->size <<= 1);
-
- bb->type = type;
- bb->nkeys = keys;
- bb->thresh = thresh;
- bb->interval = interval;
- bb->keys = mallocarray(bb->nkeys, sizeof(*bb->keys), bb->type, flags);
- bb->bucket = mallocarray(bb->size, 1, bb->type, flags | M_ZERO);
-
- for (i = 0; i < bb->nkeys; i++)
- arc4random_buf(&bb->keys[i], sizeof(*bb->keys));
-
- timeout_set(&bb->tick, bb_tick, bb);
-}
-
-void
-bb_destroy(struct bloom_bucket *bb)
-{
- free(bb->keys, bb->type, bb->nkeys);
- free(bb->bucket, bb->type, bb->size);
-}
-
-void
-bb_tick(void *_bb)
-{
- struct bloom_bucket *bb = _bb;
- int act;
- size_t i;
-
- for (i = 0, act = 0; i < bb->size; i++) {
- /* Check to protect underflow, as well as flag
- * if action has been taken, therefore should
- * schedule again. */
- if (bb->bucket[i] > 0) {
- bb->bucket[i]--;
- act = 1;
- }
- }
-
- if (act && !timeout_pending(&bb->tick))
- timeout_add_sec(&bb->tick, bb->interval);
-}
-
-int
-bb_recv(struct bloom_bucket *bb, uint8_t *buf, size_t n)
-{
- size_t i;
- uint64_t hash;
- uint8_t *elem, min = 0xff;
-
- for (i = 0; i < bb->nkeys; i++) {
- hash = SipHash24(&bb->keys[i], buf, n);
- elem = &bb->bucket[hash & (bb->size - 1)];
- if (*elem < min)
- min = *elem;
- if (*elem < bb->thresh)
- (*elem)++;
- }
-
- if (!timeout_pending(&bb->tick))
- timeout_add_sec(&bb->tick, bb->interval);
-
- return min == bb->thresh;
-}
-
-uint8_t
-bb_load(struct bloom_bucket *bb)
-{
- size_t i;
- uint8_t log;
- uint64_t sum;
- for (i = 0, sum = 0; i < bb->size; i++)
- sum += bb->bucket[i];
-
- sum *= (0xffffffffffffffff / (bb->size * bb->thresh));
-
- log = 0;
- while (sum >>= 1)
- log++;
-
- return log;
-}
-
#endif /* __BLOOMBUCKET_H__ */