tor  0.4.0.0-alpha-dev
address_set.c
Go to the documentation of this file.
1 /* Copyright (c) 2018-2018, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
3 
13 #include "orconfig.h"
14 #include "core/or/address_set.h"
15 #include "lib/net/address.h"
18 #include "siphash.h"
19 
20 /* Wrap our hash function to have the signature that the bloom filter
21  * needs. */
22 static uint64_t
23 bloomfilt_addr_hash(const struct sipkey *key,
24  const void *item)
25 {
26  return tor_addr_keyed_hash(key, item);
27 }
28 
34 address_set_new(int max_addresses_guess)
35 {
36  uint8_t k[BLOOMFILT_KEY_LEN];
37  crypto_rand((void*)k, sizeof(k));
38  return bloomfilt_new(max_addresses_guess, bloomfilt_addr_hash, k);
39 }
40 
47 void
48 address_set_add(address_set_t *set, const struct tor_addr_t *addr)
49 {
50  bloomfilt_add(set, addr);
51 }
52 
54 void
56 {
57  tor_addr_t a;
58  tor_addr_from_ipv4h(&a, addr);
59  address_set_add(set, &a);
60 }
61 
66 int
68  const struct tor_addr_t *addr)
69 {
70  return bloomfilt_probably_contains(set, addr);
71 }
Common functions for using (pseudo-)random number generators.
Types to handle sets of addresses.
void bloomfilt_add(bloomfilt_t *set, const void *item)
Definition: bloomfilt.c:38
bloomfilt_t * bloomfilt_new(int max_elements, bloomfilt_hash_fn hashfn, const uint8_t *random_key)
Definition: bloomfilt.c:78
int address_set_probably_contains(const address_set_t *set, const struct tor_addr_t *addr)
Definition: address_set.c:67
#define tor_addr_from_ipv4h(dest, v4addr)
Definition: address.h:287
void address_set_add(address_set_t *set, const struct tor_addr_t *addr)
Definition: address_set.c:48
#define BLOOMFILT_KEY_LEN
Definition: bloomfilt.h:26
Headers for address.h.
Header for bloomfilt.c.
uint64_t tor_addr_keyed_hash(const struct sipkey *key, const tor_addr_t *addr)
Definition: address.c:1100
int bloomfilt_probably_contains(const bloomfilt_t *set, const void *item)
Definition: bloomfilt.c:54
address_set_t * address_set_new(int max_addresses_guess)
Definition: address_set.c:34
void address_set_add_ipv4h(address_set_t *set, uint32_t addr)
Definition: address_set.c:55