summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2010-02-22 13:59:34 -0500
committerNick Mathewson <nickm@torproject.org>2010-09-27 14:22:18 -0400
commitffd5070b04b3db4409d8e3dc933ffc7d12b5219d (patch)
treef1fcfa7d71f88f9b005637aa6df804d61f1f3085 /src/common
parent98ec959c9c1d2b0a872926a3cafe42742520397a (diff)
downloadtor-ffd5070b04b3db4409d8e3dc933ffc7d12b5219d.tar.gz
tor-ffd5070b04b3db4409d8e3dc933ffc7d12b5219d.zip
Convert bufferevents to use rate-limiting.
This requires the latest Git version of Libevent as of 24 March 2010. In the future, we'll just say it requires Libevent 2.0.5-alpha or later. Since Libevent doesn't yet support hierarchical rate limit groups, there isn't yet support for tracking relayed-bytes separately when using the bufferevent system. If a future version does add support for hierarchical buckets, we can add that back in.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/compat_libevent.c24
-rw-r--r--src/common/compat_libevent.h5
-rw-r--r--src/common/tortls.c3
3 files changed, 30 insertions, 2 deletions
diff --git a/src/common/compat_libevent.c b/src/common/compat_libevent.c
index 250fa2bdb7..2ae280e669 100644
--- a/src/common/compat_libevent.c
+++ b/src/common/compat_libevent.c
@@ -551,3 +551,27 @@ periodic_timer_free(periodic_timer_t *timer)
tor_free(timer);
}
+#ifdef USE_BUFFEREVENTS
+static const struct timeval *one_tick = NULL;
+/**
+ DOCDOC
+*/
+const struct timeval *tor_libevent_get_one_tick_timeout(void)
+{
+
+ if (PREDICT_UNLIKELY(one_tick == NULL)) {
+ struct event_base *base = tor_libevent_get_base();
+ struct timeval tv;
+ if (TOR_LIBEVENT_TICKS_PER_SECOND == 1) {
+ tv.tv_sec = 1;
+ tv.tv_usec = 0;
+ } else {
+ tv.tv_sec = 0;
+ tv.tv_usec = 1000000 / TOR_LIBEVENT_TICKS_PER_SECOND;
+ }
+ one_tick = event_base_init_common_timeout(base, &tv);
+ }
+ return one_tick;
+}
+#endif
+
diff --git a/src/common/compat_libevent.h b/src/common/compat_libevent.h
index a4011e37af..f483d6ee6d 100644
--- a/src/common/compat_libevent.h
+++ b/src/common/compat_libevent.h
@@ -64,5 +64,10 @@ void tor_check_libevent_version(const char *m, int server,
void tor_check_libevent_header_compatibility(void);
const char *tor_libevent_get_version_str(void);
+#ifdef USE_BUFFEREVENTS
+#define TOR_LIBEVENT_TICKS_PER_SECOND 3
+const struct timeval *tor_libevent_get_one_tick_timeout(void);
+#endif
+
#endif
diff --git a/src/common/tortls.c b/src/common/tortls.c
index 06533ca43b..3ae3ef8835 100644
--- a/src/common/tortls.c
+++ b/src/common/tortls.c
@@ -1699,7 +1699,6 @@ tor_tls_init_bufferevent(tor_tls_t *tls, struct bufferevent *bufev_in,
state,
BEV_OPT_DEFER_CALLBACKS);
#else
- /* Disabled: just use filter for now. */
if (bufev_in) {
evutil_socket_t s = bufferevent_getfd(bufev_in);
tor_assert(s == -1 || s == socket);
@@ -1715,7 +1714,7 @@ tor_tls_init_bufferevent(tor_tls_t *tls, struct bufferevent *bufev_in,
tls->ssl,
state,
0);
- //BEV_OPT_DEFER_CALLBACKS);
+ //BEV_OPT_DEFER_CALLBACKS);
#endif
return out;
}