19 #define BTRACK_ORCONN_PRIVATE
25 static inline unsigned int
26 bto_gid_hash_(bt_orconn_t *elm)
28 return (
unsigned)siphash24g(&elm->gid,
sizeof(elm->gid));
32 bto_gid_eq_(bt_orconn_t *a, bt_orconn_t *b)
34 return a->gid == b->gid;
37 static inline unsigned int
38 bto_chan_hash_(bt_orconn_t *elm)
40 return (
unsigned)siphash24g(&elm->chan,
sizeof(elm->chan));
44 bto_chan_eq_(bt_orconn_t *a, bt_orconn_t *b)
46 return a->chan == b->chan;
49 HT_HEAD(bto_gid_ht, bt_orconn_t);
50 HT_PROTOTYPE(bto_gid_ht, bt_orconn_t, node, bto_gid_hash_, bto_gid_eq_);
51 HT_GENERATE2(bto_gid_ht, bt_orconn_t, node,
52 bto_gid_hash_, bto_gid_eq_, 0.6,
54 static struct bto_gid_ht *bto_gid_map;
56 HT_HEAD(bto_chan_ht, bt_orconn_t);
57 HT_PROTOTYPE(bto_chan_ht, bt_orconn_t, chan_node, bto_chan_hash_,
59 HT_GENERATE2(bto_chan_ht, bt_orconn_t, chan_node,
60 bto_chan_hash_, bto_chan_eq_, 0.6,
62 static struct bto_chan_ht *bto_chan_map;
69 bt_orconn_t **elt, **next, *c;
71 for (elt = HT_START(bto_gid_ht, bto_gid_map);
75 next = HT_NEXT_RMV(bto_gid_ht, bto_gid_map, elt);
82 HT_CLEAR(bto_gid_ht, bto_gid_map);
91 bt_orconn_t **elt, **next, *c;
93 for (elt = HT_START(bto_chan_ht, bto_chan_map);
97 next = HT_NEXT_RMV(bto_chan_ht, bto_chan_map, elt);
104 HT_CLEAR(bto_chan_ht, bto_chan_map);
112 bt_orconn_t key, *bto;
116 bto = HT_FIND(bto_gid_ht, bto_gid_map, &key);
119 log_debug(
LD_BTRACK,
"tried to delete unregistered ORCONN gid=%"PRIu64,
123 HT_REMOVE(bto_gid_ht, bto_gid_map, &key);
125 key.chan = bto->chan;
126 HT_REMOVE(bto_chan_ht, bto_chan_map, &key);
141 tor_assert(!bto->gid || !key->gid || bto->gid == key->gid);
142 if (!bto->gid && key->gid) {
144 log_debug(
LD_BTRACK,
"ORCONN chan=%"PRIu64
" newgid=%"PRIu64, key->chan,
147 HT_INSERT(bto_gid_ht, bto_gid_map, bto);
150 tor_assert(!bto->chan || !key->chan || bto->chan == key->chan);
151 if (!bto->chan && key->chan) {
153 log_debug(
LD_BTRACK,
"ORCONN gid=%"PRIu64
" newchan=%"PRIu64,
154 bto->gid, key->chan);
155 bto->chan = key->chan;
156 HT_INSERT(bto_chan_ht, bto_chan_map, bto);
165 struct bt_orconn_t *bto = tor_malloc(
sizeof(*bto));
168 bto->chan = key->chan;
171 bto->is_orig =
false;
172 bto->is_onehop =
true;
175 HT_INSERT(bto_gid_ht, bto_gid_map, bto);
177 HT_INSERT(bto_chan_ht, bto_chan_map, bto);
191 bt_orconn_t key, *bto = NULL;
197 bto = HT_FIND(bto_gid_ht, bto_gid_map, &key);
198 if (!bto && key.chan) {
200 bto = HT_FIND(bto_chan_ht, bto_chan_map, &key);
212 bto_gid_map = tor_malloc(
sizeof(*bto_gid_map));
213 HT_INIT(bto_gid_ht, bto_gid_map);
214 bto_chan_map = tor_malloc(
sizeof(*bto_chan_map));
215 HT_INIT(bto_chan_ht, bto_chan_map);
Header file for btrack_orconn.c.
static bt_orconn_t * bto_update(bt_orconn_t *bto, const bt_orconn_t *key)
static bt_orconn_t * bto_new(const bt_orconn_t *key)
void bto_clear_maps(void)
bt_orconn_t * bto_find_or_new(uint64_t gid, uint64_t chan)
static void bto_gid_clear_map(void)
static void bto_chan_clear_map(void)
void bto_delete(uint64_t gid)
Header file for btrack_orconn_maps.c.
HT_PROTOTYPE(hs_circuitmap_ht, circuit_t, hs_circuitmap_node, hs_circuit_hash_token, hs_circuits_have_same_token)
typedef HT_HEAD(hs_service_ht, hs_service_t) hs_service_ht
void tor_free_(void *mem)
void * tor_reallocarray_(void *ptr, size_t sz1, size_t sz2)
Master header file for Tor-specific functionality.