tor  master
Data Structures | Macros | Functions
address_set.c File Reference

Implementation for a set of addresses. More...

#include "orconfig.h"
#include "address_set.h"
#include "address.h"
#include "compat.h"
#include "container.h"
#include "crypto_rand.h"
#include "util.h"
#include "siphash.h"
Include dependency graph for address_set.c:

Data Structures

struct  address_set_t
 

Macros

#define N_HASHES   2
 
#define N_BITS_PER_ITEM   (N_HASHES * 2)
 
#define BIT(set, val)   ((val) & (set)->mask)
 

Functions

address_set_taddress_set_new (int max_addresses_guess)
 
void address_set_free (address_set_t *set)
 
void address_set_add (address_set_t *set, const struct tor_addr_t *addr)
 
void address_set_add_ipv4h (address_set_t *set, uint32_t addr)
 
int address_set_probably_contains (address_set_t *set, const struct tor_addr_t *addr)
 

Detailed Description

Implementation for a set of addresses.

This module was first written on a semi-emergency basis to improve the robustness of the anti-DoS module. As such, it's written in a pretty conservative way, and should be susceptible to improvement later on.

Macro Definition Documentation

◆ BIT

#define BIT (   set,
  val 
)    ((val) & (set)->mask)

Yield the bit index corresponding to 'val' for set.

◆ N_BITS_PER_ITEM

#define N_BITS_PER_ITEM   (N_HASHES * 2)

How many bloom-filter bits we set per address. This is twice the N_HASHES value, since we split the siphash output into two 32-bit values.

◆ N_HASHES

#define N_HASHES   2

How many 64-bit siphash values to extract per address

Function Documentation

◆ address_set_add()

void address_set_add ( address_set_t set,
const struct tor_addr_t addr 
)

Add addr to set.

All future queries for addr in set will return true. Removing items is not possible.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ address_set_add_ipv4h()

void address_set_add_ipv4h ( address_set_t set,
uint32_t  addr 
)

As address_set_add(), but take an ipv4 address in host order.

Here is the call graph for this function:

◆ address_set_free()

void address_set_free ( address_set_t set)

Release all storage associated with set.

◆ address_set_new()

address_set_t* address_set_new ( int  max_addresses_guess)

Allocate and return an address_set, suitable for holding up to max_address_guess distinct values.

Here is the call graph for this function:

◆ address_set_probably_contains()

int address_set_probably_contains ( address_set_t set,
const struct tor_addr_t addr 
)

Return true if addr is a member of set. (And probably, return false if addr is not a member of set.)

Here is the call graph for this function: