diff options
author | Nick Mathewson <nickm@torproject.org> | 2011-08-24 17:09:56 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2011-08-24 17:31:32 -0400 |
commit | 59d0f750c972011372febefbee958b37a17a0569 (patch) | |
tree | bb8da76fc73ba427afd23f54f7465a469cd3ba11 /src/common/compat_libevent.c | |
parent | ede9cd4f99e4cd1c0c4bcf1a3ac994e87054cc2d (diff) | |
download | tor-59d0f750c972011372febefbee958b37a17a0569.tar.gz tor-59d0f750c972011372febefbee958b37a17a0569.zip |
Apply rate-limiting to the lowest bufferevent in the stack.
When we're doing filtering ssl bufferevents, we want the rate-limits
to apply to the lowest level of the bufferevent stack, so that we're
actually limiting bytes sent on the network. Otherwise, we'll read
from the network aggressively, and only limit stuff as we process it.
Diffstat (limited to 'src/common/compat_libevent.c')
-rw-r--r-- | src/common/compat_libevent.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/common/compat_libevent.c b/src/common/compat_libevent.c index 595742f961..beae9502da 100644 --- a/src/common/compat_libevent.c +++ b/src/common/compat_libevent.c @@ -20,6 +20,9 @@ #ifdef HAVE_EVENT2_EVENT_H #include <event2/event.h> #include <event2/thread.h> +#ifdef USE_BUFFEREVENTS +#include <event2/bufferevent.h> +#endif #else #include <event.h> #endif @@ -614,5 +617,28 @@ tor_libevent_get_one_tick_timeout(void) } return one_tick; } + +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 |