Remove USE_BUFFEREVENTS code outside src/or

This commit is contained in:
Nick Mathewson
2016-08-02 13:20:59 -04:00
parent c68a23a135
commit 8fd6b0fc46
6 changed files with 3 additions and 218 deletions
+3 -110
View File
@@ -18,9 +18,6 @@
#include <event2/event.h>
#include <event2/thread.h>
#ifdef USE_BUFFEREVENTS
#include <event2/bufferevent.h>
#endif
/** A string which, if it appears in a libevent log, should be ignored. */
static const char *suppress_msg = NULL;
@@ -94,17 +91,6 @@ static struct event_base *the_event_base = NULL;
#endif
#endif
#ifdef USE_BUFFEREVENTS
static int using_iocp_bufferevents = 0;
static void tor_libevent_set_tick_timeout(int msec_per_tick);
int
tor_libevent_using_iocp_bufferevents(void)
{
return using_iocp_bufferevents;
}
#endif
/** Initialize the Libevent library and set up the event base. */
void
tor_libevent_initialize(tor_libevent_cfg *torcfg)
@@ -115,34 +101,15 @@ tor_libevent_initialize(tor_libevent_cfg *torcfg)
{
int attempts = 0;
int using_threads;
struct event_config *cfg;
retry:
++attempts;
using_threads = 0;
cfg = event_config_new();
tor_assert(cfg);
#if defined(_WIN32) && defined(USE_BUFFEREVENTS)
if (! torcfg->disable_iocp) {
evthread_use_windows_threads();
event_config_set_flag(cfg, EVENT_BASE_FLAG_STARTUP_IOCP);
using_iocp_bufferevents = 1;
using_threads = 1;
} else {
using_iocp_bufferevents = 0;
}
#elif defined(__COVERITY__)
/* Avoid a 'dead code' warning below. */
using_threads = ! torcfg->disable_iocp;
#endif
if (!using_threads) {
/* Telling Libevent not to try to turn locking on can avoid a needless
* socketpair() attempt. */
event_config_set_flag(cfg, EVENT_BASE_FLAG_NOLOCK);
}
/* Telling Libevent not to try to turn locking on can avoid a needless
* socketpair() attempt. */
event_config_set_flag(cfg, EVENT_BASE_FLAG_NOLOCK);
if (torcfg->num_cpus > 0)
event_config_set_num_cpus_hint(cfg, torcfg->num_cpus);
@@ -154,24 +121,6 @@ tor_libevent_initialize(tor_libevent_cfg *torcfg)
the_event_base = event_base_new_with_config(cfg);
event_config_free(cfg);
if (using_threads && the_event_base == NULL && attempts < 2) {
/* This could be a socketpair() failure, which can happen sometimes on
* windows boxes with obnoxious firewall rules. Downgrade and try
* again. */
#if defined(_WIN32) && defined(USE_BUFFEREVENTS)
if (torcfg->disable_iocp == 0) {
log_warn(LD_GENERAL, "Unable to initialize Libevent. Trying again "
"with IOCP disabled.");
} else
#endif
{
log_warn(LD_GENERAL, "Unable to initialize Libevent. Trying again.");
}
torcfg->disable_iocp = 1;
goto retry;
}
}
if (!the_event_base) {
@@ -184,10 +133,6 @@ tor_libevent_initialize(tor_libevent_cfg *torcfg)
log_info(LD_GENERAL,
"Initialized libevent version %s using method %s. Good.",
event_get_version(), tor_libevent_get_method());
#ifdef USE_BUFFEREVENTS
tor_libevent_set_tick_timeout(torcfg->msec_per_tick);
#endif
}
/** Return the current Libevent event base that we're set up to use. */
@@ -276,58 +221,6 @@ periodic_timer_free(periodic_timer_t *timer)
tor_free(timer);
}
#ifdef USE_BUFFEREVENTS
static const struct timeval *one_tick = NULL;
/**
* Return a special timeout to be passed whenever libevent's O(1) timeout
* implementation should be used. Only use this when the timer is supposed
* to fire after msec_per_tick ticks have elapsed.
*/
const struct timeval *
tor_libevent_get_one_tick_timeout(void)
{
tor_assert(one_tick);
return one_tick;
}
/** Initialize the common timeout that we'll use to refill the buckets every
* time a tick elapses. */
static void
tor_libevent_set_tick_timeout(int msec_per_tick)
{
struct event_base *base = tor_libevent_get_base();
struct timeval tv;
tor_assert(! one_tick);
tv.tv_sec = msec_per_tick / 1000;
tv.tv_usec = (msec_per_tick % 1000) * 1000;
one_tick = event_base_init_common_timeout(base, &tv);
}
static struct bufferevent *
tor_get_root_bufferevent(struct bufferevent *bev)
{
struct bufferevent *u;
while ((u = bufferevent_get_underlying(bev)) != NULL)
bev = u;
return bev;
}
int
tor_set_bufferevent_rate_limit(struct bufferevent *bev,
struct ev_token_bucket_cfg *cfg)
{
return bufferevent_set_rate_limit(tor_get_root_bufferevent(bev), cfg);
}
int
tor_add_bufferevent_to_rate_limit_group(struct bufferevent *bev,
struct bufferevent_rate_limit_group *g)
{
return bufferevent_add_to_rate_limit_group(tor_get_root_bufferevent(bev), g);
}
#endif
int
tor_init_libevent_rng(void)
{
-13
View File
@@ -9,10 +9,6 @@
#include <event2/event.h>
#ifdef USE_BUFFEREVENTS
#include <event2/bufferevent.h>
#endif
void configure_libevent_logging(void);
void suppress_libevent_log_msg(const char *msg);
@@ -54,15 +50,6 @@ void tor_check_libevent_header_compatibility(void);
const char *tor_libevent_get_version_str(void);
const char *tor_libevent_get_header_version_str(void);
#ifdef USE_BUFFEREVENTS
const struct timeval *tor_libevent_get_one_tick_timeout(void);
int tor_libevent_using_iocp_bufferevents(void);
int tor_set_bufferevent_rate_limit(struct bufferevent *bev,
struct ev_token_bucket_cfg *cfg);
int tor_add_bufferevent_to_rate_limit_group(struct bufferevent *bev,
struct bufferevent_rate_limit_group *g);
#endif
int tor_init_libevent_rng(void);
void tor_gettimeofday_cached(struct timeval *tv);
-79
View File
@@ -48,13 +48,6 @@ DISABLE_GCC_WARNING(redundant-decls)
ENABLE_GCC_WARNING(redundant-decls)
#ifdef USE_BUFFEREVENTS
#include <event2/bufferevent_ssl.h>
#include <event2/buffer.h>
#include <event2/event.h>
#include "compat_libevent.h"
#endif
#define TORTLS_PRIVATE
#include "tortls.h"
#include "util.h"
@@ -2486,78 +2479,6 @@ tor_tls_get_buffer_sizes(tor_tls_t *tls,
#endif
}
#ifdef USE_BUFFEREVENTS
/** Construct and return an TLS-encrypting bufferevent to send data over
* <b>socket</b>, which must match the socket of the underlying bufferevent
* <b>bufev_in</b>. The TLS object <b>tls</b> is used for encryption.
*
* This function will either create a filtering bufferevent that wraps around
* <b>bufev_in</b>, or it will free bufev_in and return a new bufferevent that
* uses the <b>tls</b> to talk to the network directly. Do not use
* <b>bufev_in</b> after calling this function.
*
* The connection will start out doing a server handshake if <b>receiving</b>
* is strue, and a client handshake otherwise.
*
* Returns NULL on failure.
*/
struct bufferevent *
tor_tls_init_bufferevent(tor_tls_t *tls, struct bufferevent *bufev_in,
evutil_socket_t socket, int receiving,
int filter)
{
struct bufferevent *out;
const enum bufferevent_ssl_state state = receiving ?
BUFFEREVENT_SSL_ACCEPTING : BUFFEREVENT_SSL_CONNECTING;
if (filter || tor_libevent_using_iocp_bufferevents()) {
/* Grab an extra reference to the SSL, since BEV_OPT_CLOSE_ON_FREE
means that the SSL will get freed too.
This increment makes our SSL usage not-threadsafe, BTW. We should
see if we're allowed to use CRYPTO_add from outside openssl. */
tls->ssl->references += 1;
out = bufferevent_openssl_filter_new(tor_libevent_get_base(),
bufev_in,
tls->ssl,
state,
BEV_OPT_DEFER_CALLBACKS|
BEV_OPT_CLOSE_ON_FREE);
/* Tell the underlying bufferevent when to accept more data from the SSL
filter (only when it's got less than 32K to write), and when to notify
the SSL filter that it could write more (when it drops under 24K). */
bufferevent_setwatermark(bufev_in, EV_WRITE, 24*1024, 32*1024);
} else {
if (bufev_in) {
evutil_socket_t s = bufferevent_getfd(bufev_in);
tor_assert(s == -1 || s == socket);
tor_assert(evbuffer_get_length(bufferevent_get_input(bufev_in)) == 0);
tor_assert(evbuffer_get_length(bufferevent_get_output(bufev_in)) == 0);
tor_assert(BIO_number_read(SSL_get_rbio(tls->ssl)) == 0);
tor_assert(BIO_number_written(SSL_get_rbio(tls->ssl)) == 0);
bufferevent_free(bufev_in);
}
/* Current versions (as of 2.0.x) of Libevent need to defer
* bufferevent_openssl callbacks, or else our callback functions will
* get called reentrantly, which is bad for us.
*/
out = bufferevent_openssl_socket_new(tor_libevent_get_base(),
socket,
tls->ssl,
state,
BEV_OPT_DEFER_CALLBACKS);
}
tls->state = TOR_TLS_ST_BUFFEREVENT;
/* Unblock _after_ creating the bufferevent, since accept/connect tend to
* clear flags. */
tor_tls_unblock_renegotiation(tls);
return out;
}
#endif
/** Check whether the ECC group requested is supported by the current OpenSSL
* library instance. Return 1 if the group is supported, and 0 if not.
*/
-8
View File
@@ -235,14 +235,6 @@ void check_no_tls_errors_(const char *fname, int line);
void tor_tls_log_one_error(tor_tls_t *tls, unsigned long err,
int severity, int domain, const char *doing);
#ifdef USE_BUFFEREVENTS
int tor_tls_start_renegotiating(tor_tls_t *tls);
struct bufferevent *tor_tls_init_bufferevent(tor_tls_t *tls,
struct bufferevent *bufev_in,
evutil_socket_t socket, int receiving,
int filter);
#endif
void tor_x509_cert_free(tor_x509_cert_t *cert);
tor_x509_cert_t *tor_x509_cert_decode(const uint8_t *certificate,
size_t certificate_len);
-3
View File
@@ -11,9 +11,6 @@
#include <event2/event.h>
#include <event2/thread.h>
#ifdef USE_BUFFEREVENTS
#include <event2/bufferevent.h>
#endif
#include "log_test_helpers.h"
-5
View File
@@ -101,13 +101,8 @@ dummy_edge_conn_new(circuit_t *circ,
else
conn = ENTRY_TO_EDGE_CONN(entry_connection_new(type, AF_INET));
#ifdef USE_BUFFEREVENTS
inbuf = bufferevent_get_input(TO_CONN(conn)->bufev);
outbuf = bufferevent_get_output(TO_CONN(conn)->bufev);
#else
inbuf = TO_CONN(conn)->inbuf;
outbuf = TO_CONN(conn)->outbuf;
#endif
/* We add these bytes directly to the buffers, to avoid all the
* edge connection read/write machinery. */