diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-07-05 15:42:55 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-07-05 15:42:55 -0400 |
commit | 02ba0a2dbbe1032b56d0ba17468f2ee0d95e4f1b (patch) | |
tree | eb0ec8b0dc6c1b803033e663558cc2a7542152ac /src/or | |
parent | 3d610363eff2fe70d3775a66a97f844956480141 (diff) | |
parent | f7eff3008d33fb0c35986cbc14799b0127e8ab73 (diff) | |
download | tor-02ba0a2dbbe1032b56d0ba17468f2ee0d95e4f1b.tar.gz tor-02ba0a2dbbe1032b56d0ba17468f2ee0d95e4f1b.zip |
Merge branch 'destroy_common'
Diffstat (limited to 'src/or')
33 files changed, 194 insertions, 45 deletions
diff --git a/src/or/address_set.c b/src/or/address_set.c new file mode 100644 index 0000000000..927a5597c0 --- /dev/null +++ b/src/or/address_set.c @@ -0,0 +1,71 @@ +/* Copyright (c) 2018-2018, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/** + * \file address_set.c + * \brief 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. + **/ + +#include "orconfig.h" +#include "or/address_set.h" +#include "lib/net/address.h" +#include "lib/container/bloomfilt.h" +#include "lib/crypt_ops/crypto_rand.h" +#include "siphash.h" + +/* Wrap our hash function to have the signature that the bloom filter + * needs. */ +static uint64_t +bloomfilt_addr_hash(const struct sipkey *key, + const void *item) +{ + return tor_addr_keyed_hash(key, item); +} + +/** + * Allocate and return an address_set, suitable for holding up to + * <b>max_address_guess</b> distinct values. + */ +address_set_t * +address_set_new(int max_addresses_guess) +{ + uint8_t k[BLOOMFILT_KEY_LEN]; + crypto_rand((void*)k, sizeof(k)); + return bloomfilt_new(max_addresses_guess, bloomfilt_addr_hash, k); +} + +/** + * Add <b>addr</b> to <b>set</b>. + * + * All future queries for <b>addr</b> in set will return true. Removing + * items is not possible. + */ +void +address_set_add(address_set_t *set, const struct tor_addr_t *addr) +{ + bloomfilt_add(set, addr); +} + +/** As address_set_add(), but take an ipv4 address in host order. */ +void +address_set_add_ipv4h(address_set_t *set, uint32_t addr) +{ + tor_addr_t a; + tor_addr_from_ipv4h(&a, addr); + address_set_add(set, &a); +} + +/** + * Return true if <b>addr</b> is a member of <b>set</b>. (And probably, + * return false if <b>addr</b> is not a member of set.) + */ +int +address_set_probably_contains(const address_set_t *set, + const struct tor_addr_t *addr) +{ + return bloomfilt_probably_contains(set, addr); +} diff --git a/src/or/address_set.h b/src/or/address_set.h new file mode 100644 index 0000000000..2efa1cb03b --- /dev/null +++ b/src/or/address_set.h @@ -0,0 +1,31 @@ +/* Copyright (c) 2018-2018, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/** + * \file address_set.h + * \brief Types to handle sets of addresses. + **/ + +#ifndef TOR_ADDRESS_SET_H +#define TOR_ADDRESS_SET_H + +#include "orconfig.h" +#include "lib/cc/torint.h" +#include "lib/container/bloomfilt.h" + +/** + * An address_set_t represents a set of tor_addr_t values. The implementation + * is probabilistic: false negatives cannot occur but false positives are + * possible. + */ +typedef struct bloomfilt_t address_set_t; +struct tor_addr_t; + +address_set_t *address_set_new(int max_addresses_guess); +#define address_set_free(set) bloomfilt_free(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(const address_set_t *set, + const struct tor_addr_t *addr); + +#endif diff --git a/src/or/channel.c b/src/or/channel.c index 2dbacbde98..e6d717f111 100644 --- a/src/or/channel.c +++ b/src/or/channel.c @@ -79,7 +79,7 @@ #include "lib/time/compat_time.h" #include "or/networkstatus.h" #include "or/rendservice.h" -#include "common/timers.h" +#include "lib/evloop/timers.h" #include "or/cell_queue_st.h" diff --git a/src/or/channel.h b/src/or/channel.h index 010a8aa5bc..7f25056769 100644 --- a/src/or/channel.h +++ b/src/or/channel.h @@ -11,7 +11,7 @@ #include "or/or.h" #include "or/circuitmux.h" -#include "common/handles.h" +#include "lib/container/handles.h" #include "lib/crypt_ops/crypto_ed25519.h" #include "tor_queue.h" diff --git a/src/or/channelpadding.c b/src/or/channelpadding.c index 298fea79a9..504f6f8f83 100644 --- a/src/or/channelpadding.c +++ b/src/or/channelpadding.c @@ -22,7 +22,7 @@ #include "or/router.h" #include "lib/time/compat_time.h" #include "or/rendservice.h" -#include "common/timers.h" +#include "lib/evloop/timers.h" #include "or/cell_st.h" #include "or/or_connection_st.h" diff --git a/src/or/config.c b/src/or/config.c index 13002dd963..9b2706982a 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -99,7 +99,6 @@ #include "or/rephist.h" #include "or/router.h" #include "lib/sandbox/sandbox.h" -#include "common/util.h" #include "or/routerlist.h" #include "or/routerset.h" #include "or/scheduler.h" @@ -132,7 +131,7 @@ #include "lib/encoding/keyval.h" #include "lib/fs/conffile.h" -#include "common/procmon.h" +#include "lib/evloop/procmon.h" #include "or/dirauth/dirvote.h" #include "or/dirauth/mode.h" diff --git a/src/or/connection.c b/src/or/connection.c index 9680b08b56..6fd8fbf771 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -105,7 +105,7 @@ #include "lib/sandbox/sandbox.h" #include "lib/net/buffers_net.h" #include "lib/tls/tortls.h" -#include "common/compat_libevent.h" +#include "lib/evloop/compat_libevent.h" #include "lib/compress/compress.h" #ifdef HAVE_PWD_H diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index f3f77dbc91..13d957a937 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -106,7 +106,7 @@ #include "or/or_circuit_st.h" #include "or/origin_circuit_st.h" #include "or/socks_request_st.h" -#include "common/compat_libevent.h" +#include "lib/evloop/compat_libevent.h" #ifdef HAVE_LINUX_TYPES_H #include <linux/types.h> diff --git a/src/or/conscache.h b/src/or/conscache.h index c46b824235..c274a60393 100644 --- a/src/or/conscache.h +++ b/src/or/conscache.h @@ -4,7 +4,7 @@ #ifndef TOR_CONSCACHE_H #define TOR_CONSCACHE_H -#include "common/handles.h" +#include "lib/container/handles.h" typedef struct consensus_cache_entry_t consensus_cache_entry_t; typedef struct consensus_cache_t consensus_cache_t; diff --git a/src/or/consdiffmgr.c b/src/or/consdiffmgr.c index c75b59c1f5..6d5183f934 100644 --- a/src/or/consdiffmgr.c +++ b/src/or/consdiffmgr.c @@ -21,8 +21,8 @@ #include "or/cpuworker.h" #include "or/networkstatus.h" #include "or/routerparse.h" -#include "common/compat_libevent.h" -#include "common/workqueue.h" +#include "lib/evloop/compat_libevent.h" +#include "lib/evloop/workqueue.h" #include "lib/compress/compress.h" #include "lib/encoding/confline.h" diff --git a/src/or/control.c b/src/or/control.c index ea12448126..aa43fccff0 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -46,7 +46,7 @@ #include "or/circuitstats.h" #include "or/circuituse.h" #include "or/command.h" -#include "common/compat_libevent.h" +#include "lib/evloop/compat_libevent.h" #include "or/config.h" #include "or/confparse.h" #include "or/connection.h" @@ -113,8 +113,8 @@ #endif #include "lib/crypt_ops/crypto_s2k.h" -#include "common/procmon.h" -#include "common/compat_libevent.h" +#include "lib/evloop/procmon.h" +#include "lib/evloop/compat_libevent.h" /** Yield true iff <b>s</b> is the state of a control_connection_t that has * finished authentication and is accepting commands. */ diff --git a/src/or/cpuworker.c b/src/or/cpuworker.c index b37dfd1684..8b58e4c68c 100644 --- a/src/or/cpuworker.c +++ b/src/or/cpuworker.c @@ -30,7 +30,7 @@ #include "or/onion.h" #include "or/rephist.h" #include "or/router.h" -#include "common/workqueue.h" +#include "lib/evloop/workqueue.h" #include "or/or_circuit_st.h" #include "lib/intmath/weakrng.h" diff --git a/src/or/dirauth/shared_random.c b/src/or/dirauth/shared_random.c index 8b53c1e743..d122690129 100644 --- a/src/or/dirauth/shared_random.c +++ b/src/or/dirauth/shared_random.c @@ -99,7 +99,6 @@ #include "or/routerlist.h" #include "or/shared_random_client.h" #include "or/dirauth/shared_random_state.h" -#include "common/util.h" #include "or/voting_schedule.h" #include "or/dirauth/dirvote.h" diff --git a/src/or/dns.c b/src/or/dns.c index 45c4384eb1..4ac58552f4 100644 --- a/src/or/dns.c +++ b/src/or/dns.c @@ -64,7 +64,7 @@ #include "or/router.h" #include "ht.h" #include "lib/sandbox/sandbox.h" -#include "common/compat_libevent.h" +#include "lib/evloop/compat_libevent.h" #include "or/edge_connection_st.h" #include "or/or_circuit_st.h" diff --git a/src/or/dnsserv.c b/src/or/dnsserv.c index d2ef4a496e..6e75254239 100644 --- a/src/or/dnsserv.c +++ b/src/or/dnsserv.c @@ -34,7 +34,7 @@ #include "or/entry_connection_st.h" #include "or/listener_connection_st.h" #include "or/socks_request_st.h" -#include "common/compat_libevent.h" +#include "lib/evloop/compat_libevent.h" #include <event2/dns.h> #include <event2/dns_compat.h> diff --git a/src/or/entrynodes.h b/src/or/entrynodes.h index 56b961e9a0..5f9b5bdcba 100644 --- a/src/or/entrynodes.h +++ b/src/or/entrynodes.h @@ -12,7 +12,7 @@ #ifndef TOR_ENTRYNODES_H #define TOR_ENTRYNODES_H -#include "common/handles.h" +#include "lib/container/handles.h" /* Forward declare for guard_selection_t; entrynodes.c has the real struct */ typedef struct guard_selection_s guard_selection_t; diff --git a/src/or/ext_orport.c b/src/or/ext_orport.c index 701dc45288..7342a66e06 100644 --- a/src/or/ext_orport.c +++ b/src/or/ext_orport.c @@ -27,7 +27,6 @@ #include "or/ext_orport.h" #include "or/main.h" #include "or/proto_ext_or.h" -#include "common/util.h" #include "or/or_connection_st.h" diff --git a/src/or/hibernate.c b/src/or/hibernate.c index 1024c03546..55de64c13e 100644 --- a/src/or/hibernate.c +++ b/src/or/hibernate.c @@ -41,7 +41,7 @@ hibernating, phase 2: #include "or/main.h" #include "or/router.h" #include "or/statefile.h" -#include "common/compat_libevent.h" +#include "lib/evloop/compat_libevent.h" #include "or/or_connection_st.h" #include "or/or_state_st.h" diff --git a/src/or/hs_cell.c b/src/or/hs_cell.c index b50c87dfa3..f8b76c5133 100644 --- a/src/or/hs_cell.c +++ b/src/or/hs_cell.c @@ -11,7 +11,6 @@ #include "lib/crypt_ops/crypto_util.h" #include "or/rendservice.h" #include "or/replaycache.h" -#include "common/util.h" #include "or/hs_cell.h" #include "or/hs_ntor.h" diff --git a/src/or/include.am b/src/or/include.am index 9b5f7c1f60..ad7ee69bf5 100644 --- a/src/or/include.am +++ b/src/or/include.am @@ -19,6 +19,7 @@ EXTRA_DIST+= src/or/ntmain.c src/or/Makefile.nmake LIBTOR_APP_A_SOURCES = \ src/or/addressmap.c \ + src/or/address_set.c \ src/or/bridges.c \ src/or/channel.c \ src/or/channelpadding.c \ @@ -180,6 +181,7 @@ endif ORHEADERS = \ src/or/addressmap.h \ + src/or/address_set.h \ src/or/addr_policy_st.h \ src/or/authority_cert_st.h \ src/or/auth_dirs.inc \ diff --git a/src/or/keypin.c b/src/or/keypin.c index 34cf64f5c4..a2f3654b82 100644 --- a/src/or/keypin.c +++ b/src/or/keypin.c @@ -11,17 +11,28 @@ #define KEYPIN_PRIVATE #include "orconfig.h" + +#include "lib/cc/torint.h" #include "lib/crypt_ops/crypto_digest.h" #include "lib/crypt_ops/crypto_format.h" +#include "lib/crypt_ops/crypto_format.h" +#include "lib/ctime/di_ops.h" #include "lib/ctime/di_ops.h" +#include "lib/encoding/binascii.h" +#include "lib/encoding/time_fmt.h" +#include "lib/fdio/fdio.h" +#include "lib/fs/files.h" +#include "lib/fs/mmap.h" +#include "lib/log/torlog.h" +#include "lib/log/util_bug.h" +#include "lib/string/compat_ctype.h" +#include "lib/string/printf.h" +#include "lib/wallclock/approx_time.h" + #include "ht.h" #include "or/keypin.h" + #include "siphash.h" -#include "lib/cc/torint.h" -#include "lib/log/torlog.h" -#include "lib/fdio/fdio.h" -#include "common/util.h" -#include "lib/encoding/binascii.h" #ifdef HAVE_UNISTD_H #include <unistd.h> @@ -34,6 +45,10 @@ #include <io.h> #endif +#include <errno.h> +#include <string.h> +#include <stdlib.h> + /** * @file keypin.c * @brief Key-pinning for RSA and Ed25519 identity keys at directory diff --git a/src/or/main.c b/src/or/main.c index 408d9cf77c..7e3eb2b595 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -117,9 +117,9 @@ #include "lib/fs/lockfile.h" #include "lib/net/buffers_net.h" #include "lib/tls/tortls.h" -#include "common/compat_libevent.h" +#include "lib/evloop/compat_libevent.h" #include "lib/encoding/confline.h" -#include "common/timers.h" +#include "lib/evloop/timers.h" #include <event2/event.h> diff --git a/src/or/nodelist.c b/src/or/nodelist.c index bc04ab9526..51fd0015df 100644 --- a/src/or/nodelist.c +++ b/src/or/nodelist.c @@ -42,7 +42,7 @@ #include "or/or.h" #include "lib/net/address.h" -#include "common/address_set.h" +#include "or/address_set.h" #include "or/bridges.h" #include "or/config.h" #include "or/control.h" diff --git a/src/or/ntmain.c b/src/or/ntmain.c index 99e77a285e..f6b57753d3 100644 --- a/src/or/ntmain.c +++ b/src/or/ntmain.c @@ -25,7 +25,7 @@ #include "or/ntmain.h" #include "lib/log/win32err.h" #include "lib/fs/winlib.h" -#include "common/compat_libevent.h" +#include "lib/evloop/compat_libevent.h" #include <windows.h> #define GENSRV_SERVICENAME "tor" diff --git a/src/or/onion_ntor.c b/src/or/onion_ntor.c index 34b1112020..59c923cb97 100644 --- a/src/or/onion_ntor.c +++ b/src/or/onion_ntor.c @@ -21,14 +21,17 @@ #include "orconfig.h" #define ONION_NTOR_PRIVATE + #include "lib/crypt_ops/crypto.h" -#include "lib/crypt_ops/crypto_hkdf.h" #include "lib/crypt_ops/crypto_digest.h" +#include "lib/crypt_ops/crypto_hkdf.h" #include "lib/crypt_ops/crypto_util.h" -#include "or/onion_ntor.h" -#include "lib/log/torlog.h" #include "lib/ctime/di_ops.h" -#include "common/util.h" +#include "lib/log/torlog.h" +#include "lib/log/util_bug.h" +#include "or/onion_ntor.h" + +#include <string.h> /** Free storage held in an ntor handshake state. */ void diff --git a/src/or/or.h b/src/or/or.h index b0340ed1a0..826e81e468 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -22,14 +22,48 @@ #include <time.h> #endif -#include "common/util.h" - +#include "lib/arch/bytes.h" +#include "lib/cc/compat_compiler.h" +#include "lib/cc/torint.h" #include "lib/container/map.h" #include "lib/container/smartlist.h" #include "lib/crypt_ops/crypto.h" +#include "lib/ctime/di_ops.h" #include "lib/defs/dh_sizes.h" #include "lib/encoding/binascii.h" +#include "lib/encoding/cstring.h" +#include "lib/encoding/time_fmt.h" +#include "lib/err/torerr.h" +#include "lib/fs/dir.h" +#include "lib/fs/files.h" +#include "lib/fs/mmap.h" +#include "lib/fs/path.h" +#include "lib/fs/userdb.h" +#include "lib/intmath/addsub.h" +#include "lib/intmath/bits.h" +#include "lib/intmath/cmp.h" +#include "lib/intmath/logic.h" +#include "lib/intmath/muldiv.h" +#include "lib/log/escape.h" +#include "lib/log/ratelim.h" +#include "lib/log/util_bug.h" +#include "lib/malloc/util_malloc.h" #include "lib/net/address.h" +#include "lib/net/ipv4.h" +#include "lib/net/ipv6.h" +#include "lib/net/resolve.h" +#include "lib/net/socket.h" +#include "lib/string/compat_ctype.h" +#include "lib/string/compat_string.h" +#include "lib/string/parse_int.h" +#include "lib/string/printf.h" +#include "lib/string/scanf.h" +#include "lib/string/util_string.h" +#include "lib/testsupport/testsupport.h" +#include "lib/thread/threads.h" +#include "lib/time/compat_time.h" +#include "lib/wallclock/approx_time.h" +#include "lib/wallclock/timeval.h" #include "ht.h" diff --git a/src/or/or_connection_st.h b/src/or/or_connection_st.h index dbfe7528b0..8c2c1f89c6 100644 --- a/src/or/or_connection_st.h +++ b/src/or/or_connection_st.h @@ -8,7 +8,7 @@ #define OR_CONNECTION_ST_H #include "or/connection_st.h" -#include "common/token_bucket.h" +#include "lib/evloop/token_bucket.h" struct tor_tls_t; diff --git a/src/or/periodic.c b/src/or/periodic.c index 0cbf359b2e..041b2d287b 100644 --- a/src/or/periodic.c +++ b/src/or/periodic.c @@ -12,11 +12,11 @@ */ #include "or/or.h" -#include "common/compat_libevent.h" +#include "lib/evloop/compat_libevent.h" #include "or/config.h" #include "or/main.h" #include "or/periodic.h" -#include "common/compat_libevent.h" +#include "lib/evloop/compat_libevent.h" /** We disable any interval greater than this number of seconds, on the * grounds that it is probably an absolute time mistakenly passed in as a diff --git a/src/or/reasons.h b/src/or/reasons.h index b815463b74..837b4a0f1a 100644 --- a/src/or/reasons.h +++ b/src/or/reasons.h @@ -12,7 +12,7 @@ #ifndef TOR_REASONS_H #define TOR_REASONS_H -#include "common/socks5_status.h" +#include "lib/net/socks5_status.h" enum bandwidth_weight_rule_t; const char *stream_end_reason_to_control_string(int reason); diff --git a/src/or/scheduler.c b/src/or/scheduler.c index 7c423064c7..b8eaca3dca 100644 --- a/src/or/scheduler.c +++ b/src/or/scheduler.c @@ -4,7 +4,7 @@ #include "or/or.h" #include "or/config.h" -#include "common/compat_libevent.h" +#include "lib/evloop/compat_libevent.h" #define SCHEDULER_PRIVATE_ #define SCHEDULER_KIST_PRIVATE #include "or/scheduler.h" @@ -12,7 +12,7 @@ #include "lib/container/buffers.h" #define TOR_CHANNEL_INTERNAL_ #include "or/channeltls.h" -#include "common/compat_libevent.h" +#include "lib/evloop/compat_libevent.h" #include "or/or_connection_st.h" diff --git a/src/or/shared_random_client.c b/src/or/shared_random_client.c index 9a6c0f6644..42a5b42f60 100644 --- a/src/or/shared_random_client.c +++ b/src/or/shared_random_client.c @@ -14,7 +14,6 @@ #include "or/config.h" #include "or/voting_schedule.h" #include "or/networkstatus.h" -#include "common/util.h" #include "lib/encoding/binascii.h" #include "or/networkstatus_st.h" diff --git a/src/or/torcert.c b/src/or/torcert.c index 269fa66cea..39c6605c65 100644 --- a/src/or/torcert.c +++ b/src/or/torcert.c @@ -31,7 +31,6 @@ #include "or/torcert.h" #include "trunnel/ed25519_cert.h" #include "lib/log/torlog.h" -#include "common/util.h" #include "trunnel/link_handshake.h" #include "lib/tls/tortls.h" diff --git a/src/or/transports.c b/src/or/transports.c index ff51ff00eb..1d3cb7b951 100644 --- a/src/or/transports.c +++ b/src/or/transports.c @@ -96,7 +96,6 @@ #include "or/connection.h" #include "or/circuitbuild.h" #include "or/transports.h" -#include "common/util.h" #include "or/router.h" #include "or/statefile.h" #include "or/connection_or.h" |