dirvote: Handling adding vote and signature if module is disabled
[tor.git] / src / or / dns_structs.h
blobe22f23ac15f101f7b13eb3ea3fc0a1b7ac454c63
1 /* Copyright (c) 2003-2004, Roger Dingledine.
2 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3 * Copyright (c) 2007-2017, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
6 /**
7 * \file dns_structs.h
9 * \brief Structures used in dns.c. Exposed to dns.c, and to the unit tests
10 * that declare DNS_PRIVATE.
13 #ifndef TOR_DNS_STRUCTS_H
14 #define TOR_DNS_STRUCTS_H
16 /** Longest hostname we're willing to resolve. */
17 #define MAX_ADDRESSLEN 256
19 /** Linked list of connections waiting for a DNS answer. */
20 typedef struct pending_connection_t {
21 edge_connection_t *conn;
22 struct pending_connection_t *next;
23 } pending_connection_t;
25 /** Value of 'magic' field for cached_resolve_t. Used to try to catch bad
26 * pointers and memory stomping. */
27 #define CACHED_RESOLVE_MAGIC 0x1234F00D
29 /* Possible states for a cached resolve_t */
30 /** We are waiting for the resolver system to tell us an answer here.
31 * When we get one, or when we time out, the state of this cached_resolve_t
32 * will become "DONE" and we'll possibly add a CACHED
33 * entry. This cached_resolve_t will be in the hash table so that we will
34 * know not to launch more requests for this addr, but rather to add more
35 * connections to the pending list for the addr. */
36 #define CACHE_STATE_PENDING 0
37 /** This used to be a pending cached_resolve_t, and we got an answer for it.
38 * Now we're waiting for this cached_resolve_t to expire. This should
39 * have no pending connections, and should not appear in the hash table. */
40 #define CACHE_STATE_DONE 1
41 /** We are caching an answer for this address. This should have no pending
42 * connections, and should appear in the hash table. */
43 #define CACHE_STATE_CACHED 2
45 /** @name status values for a single DNS request.
47 * @{ */
48 /** The DNS request is in progress. */
49 #define RES_STATUS_INFLIGHT 1
50 /** The DNS request finished and gave an answer */
51 #define RES_STATUS_DONE_OK 2
52 /** The DNS request finished and gave an error */
53 #define RES_STATUS_DONE_ERR 3
54 /**@}*/
56 /** A DNS request: possibly completed, possibly pending; cached_resolve
57 * structs are stored at the OR side in a hash table, and as a linked
58 * list from oldest to newest.
60 typedef struct cached_resolve_t {
61 HT_ENTRY(cached_resolve_t) node;
62 uint32_t magic; /**< Must be CACHED_RESOLVE_MAGIC */
63 char address[MAX_ADDRESSLEN]; /**< The hostname to be resolved. */
65 union {
66 uint32_t addr_ipv4; /**< IPv4 addr for <b>address</b>, if successful.
67 * (In host order.) */
68 int err_ipv4; /**< One of DNS_ERR_*, if IPv4 lookup failed. */
69 } result_ipv4; /**< Outcome of IPv4 lookup */
70 union {
71 struct in6_addr addr_ipv6; /**< IPv6 addr for <b>address</b>, if
72 * successful */
73 int err_ipv6; /**< One of DNS_ERR_*, if IPv6 lookup failed. */
74 } result_ipv6; /**< Outcome of IPv6 lookup, if any */
75 union {
76 char *hostname; /** A hostname, if PTR lookup happened successfully*/
77 int err_hostname; /** One of DNS_ERR_*, if PTR lookup failed. */
78 } result_ptr;
79 /** @name Status fields
81 * These take one of the RES_STATUS_* values, depending on the state
82 * of the corresponding lookup.
84 * @{ */
85 unsigned int res_status_ipv4 : 2;
86 unsigned int res_status_ipv6 : 2;
87 unsigned int res_status_hostname : 2;
88 /**@}*/
89 uint8_t state; /**< Is this cached entry pending/done/informative? */
91 time_t expire; /**< Remove items from cache after this time. */
92 uint32_t ttl_ipv4; /**< What TTL did the nameserver tell us? */
93 uint32_t ttl_ipv6; /**< What TTL did the nameserver tell us? */
94 uint32_t ttl_hostname; /**< What TTL did the nameserver tell us? */
95 /** Connections that want to know when we get an answer for this resolve. */
96 pending_connection_t *pending_connections;
97 /** Position of this element in the heap*/
98 int minheap_idx;
99 } cached_resolve_t;
101 #endif /* !defined(TOR_DNS_STRUCTS_H) */