329 Commits

Author SHA1 Message Date
Nick Mathewson
ca46d25b01 Merge branch 'arc4random' 2010-02-17 23:02:28 -05:00
Nick Mathewson
3fe60fdf47 Use off_t for the length parameter of evbuffer_add_file 2010-02-12 23:40:13 -05:00
Nick Mathewson
d4de062efc Add an arc4random implementation for use by evdns
Previously, evdns was at the mercy of the user for providing a good
entropy source; without one, it would be vulnerable to various
active attacks.

This patch adds a port of OpenBSD's arc4random() calls to Libevent
[port by Chris Davis], and wraps it up a little bit so we can use it
more safely.
2010-02-11 12:53:32 -05:00
Nick Mathewson
1dd7e6dc3a Remove the 'flags' argument from evdns_base_set_option()
The 'flags' argument made sense when passed to
evdns_(base_)?parse_resolv_conf when it said which parts of the
resolv.conf file to obey.  But for evdns_set_option(), it was really
silly, since you wouldn't be calling evdns_set_option() unless you
actually wanted to set the option.  Its meaning was basically, "set
this to DNS_OPTIONS_ALL unless you want a funny surprise."

evdns_base_set_option was new in 2.0.1-alpha, so we aren't committed
to keeping it source-compatible.
2010-02-05 13:55:12 -05:00
Nick Mathewson
cfe7a9ff4c Merge remote branch 'niels/http_chunk' 2010-02-04 10:15:39 -05:00
Niels Provos
397818011b make evhttp_send() safe against terminated connections, too 2010-02-03 16:54:18 -08:00
Nick Mathewson
e2d15d81c3 Merge remote branch 'niels/http_chunk' 2010-02-03 17:52:55 -05:00
Niels Provos
93d7369106 do not fail while sending on http connections the client closed.
when sending chunked requests via multiple calls to evhttp_send_reply_chunk,
the client may close the connection before the server is done sending. this
used to cause a crash.

we introduce a new function evhttp_request_get_connection() that allows the
server to determine if the request is still associated with a connection.
If it's not, evhttp_request_free() needs to be called explicitly or the user
can call evhttp_send_reply_end() which just frees the request, too.
2010-02-03 14:34:56 -08:00
Nick Mathewson
60742d581b Add the rest of the integer limits, and add a test for them. 2010-02-03 17:01:45 -05:00
Nick Mathewson
85047a6983 Functions to view and manipulate rate-limiting buckets.
We need these for Tor, and other projects probably need them too.  Uses
include:
    - Checking whether bandwidth is mostly-used, and only taking some
      actions when there's plenty of bandwidth.
    - Deducting some non-bufferevent activities from a rate-limit group.
2010-02-03 15:12:04 -05:00
Nick Mathewson
aba1fff33a Add EV_*_MAX macros to event2/util.h to expose limits for ev_* types. 2010-02-03 14:37:42 -05:00
Nick Mathewson
da6135e356 Reduce windows header includes in our own headers.
It turns out that absolutely everything that was including
windows.h was doing so needlessly; our headers don't need it,
so we should just include winsock2.h (since that's where
struct timeval is defined).

Pre-2.0 code will use the old headers, which include windows.h
for them, so we aren't breaking source compatibility with 1.4.

This solves the bug where we were leaving WIN32_LEAN_AND_MEAN
defined, in roughly the same way that buying an automobile
solves the question of what to give your coachman for boxing
day.
2010-02-03 02:09:19 -05:00
Nick Mathewson
27c9a40f15 Fix a dumb typo in ev_intptr_t definitions.
We said "#define ev_uintptr_t" twice instead of ever saying
"#define ev_intptr_t".
2010-02-03 02:08:08 -05:00
Nick Mathewson
6c21c895d9 Remove EVUTIL_CHECK_FMT.
This was never supposed to be an exposed API, so its name should have been
more like _EVUTIL_CHECK_FMT.  But it was only used in one place, so let's
just eliminate it.
2010-02-03 01:22:44 -05:00
Nick Mathewson
f6b269498a Deprecate EVENT_FD and EVENT_SIGNAL.
These are old aliases for event_get_fd and event_get_signal, and they
haven't been the preferred way of doing things since 2.0.1-alpha.

For a while, we made them use struct event if it was included, but call
event_get_(fd|signal) if it wasn't.  This was entirely too cute.
2010-02-03 01:16:47 -05:00
Nick Mathewson
d38a7a1931 const-ify a few more functions in event.h 2010-02-02 15:44:10 -05:00
Nick Mathewson
1fa4c81c71 Add ev_[u]intptr_t to include/event2/util.h
We already emulate most of the other useful bits of stdint.h, and
we seem to have started to use uintptr_t in a few places throughout
the code.  Let's make sure we can continue to do so even on backwards
platforms that don't do C99.
2010-01-26 12:06:41 -05:00
Nick Mathewson
361da8f202 Note a missing ratelim function 2010-01-25 13:54:14 -05:00
Nick Mathewson
cd17c3acd5 Add support for a "debug mode" to try to catch common errors.
Right now it only catches cases where we aren't initializing events,
or where we are re-initializing events without deleting them first.
These are however shockingly common.
2010-01-25 13:53:13 -05:00
Nick Mathewson
70a4a3ef14 Remove a needless include of rpc_compat.h
Nothing in evrpc.c was using rpc_compat.h, so it's best to take it
out, especially since it polluted our build process with GCC variadic
macros.

While we're at it, this patch puts an extra restriction on when the
variadic macros in rpc_compat.h are defined.  Not only must GCC be the
compiler, but GCC must not be running in -ansi mode.
2010-01-23 23:12:29 -05:00
Nick Mathewson
918e9c5e72 Fix a number of warnings from gcc -pedantic 2010-01-23 16:38:36 -05:00
Nick Mathewson
ff3f6cd42b Check more internal event_add() calls for failure
Most of these should be unable to fail, since adding a timeout
generally always works.  Still, it's better not to try to be "too
smart for our own good here."

There are some remaining event_add() calls that I didn't add checks
for; I've marked those with "XXXX" comments.
2010-01-22 16:14:49 -05:00
Nick Mathewson
0683950384 Functions to access more fields of struct event.
Once event_assign() or event_new() had been called, there was no way
to get at a copy of the event's callback, callback argument, or
configured events.  This patch adds an accessor function for each, and
an all-fields accessor for code that wants to re-assign one field of
an event.

This patch also adds a function to return sizeof(struct event), so
that code with intense RAM needs can still retain ABI compatibility
between versions of Libevent without having to heap-allocate every
struct event individually.

The code here was first proposed by Pavel Pisa.
2010-01-19 14:01:36 -05:00
Niels Provos
5032e52680 do not use a function to assign the evdns base; instead assign it via evhttp_connection_base_new() which is a new function introduced in 2.0 2010-01-14 15:42:07 -08:00
Nick Mathewson
c698b77d19 Allow http connections to use evdns for hostname looksups.
This was as simple as using bufferevent_connect_hostname instead of
calling connect() ourself, which already knows how to use an
evdns_base if it gets one.

Untangling the bind code might be a little trickier.
2010-01-14 15:18:25 -05:00
Nick Mathewson
b9f43b231f Add a comment on evthread_enable_lock_debuging. 2010-01-11 20:47:45 -05:00
Nick Mathewson
72dd666777 evdns_getaddrinfo() now supports the /etc/hosts file.
The regular blocking evutil_getaddrinfo() already supported /etc/hosts
by falling back to getaddrinfo() or gethostbyname().  But
evdns_getaddrinfo() had no such facility.  Now it does.

The data structure here isn't very clever.  I guess people with huge
/etc/hosts files will either need to get out of the 1980s, or submit a
patch to this code so that it uses a hashtable instead of a linked
list.

Includes basic unit tests.
2010-01-08 19:36:37 -05:00
Nick Mathewson
ba2945f931 Merge branch 'ratelimit'
Conflicts:
	bufferevent_async.c
2010-01-06 17:59:44 -05:00
Nick Mathewson
1e56a32d08 Make the initial nameserver probe timeout configurable.
When we decide that a nameserver is down, we stop sending queries to
it, except to periodically probe it to see if it has come back up.
Our previous probe sechedule was an ad-hoc and hard-wired "10 seconds,
one minute, 5 minues, 15 minutes, 1 hour, 1 hour, 1 hour...".  There
was nothing wrong with having it be ad-hoc, but making it hard-wired
served no good purpose.

Now the user can set the initial timeout via a new
"initial-probe-timeout:" option; future timeouts back off by a factor
of 3 on every failure to a maximum of 1 hour.

As a side-benefit, this lets us cut the runtime of the dns/retry test
from about 40 seconds to about 3 seconds.  Faster unit tests are
always a good thing.
2009-12-29 16:04:16 -05:00
Jardel Weyrich
d0939d2b97 Introduced evutil_make_socket_closeonexec() to preserve fd flags for F_SETFD.
Use this to eliminate the various macros that called F_SETFD throughout
the code.
2009-12-29 15:12:56 -05:00
Nick Mathewson
737c9cd87b Rate-limiting for bufferevents; group and individual limits are supported.
The fairness algorithms are not the best, not every bufferevent type
is supported, and some of the locking tricks here are simply absurd.
Still, this code should be a good first step.
2009-12-28 16:11:18 -05:00
Nick Mathewson
47854a802a Expose our cached gettimeofday value with a new interface
I've got a two use case that wants this for a fairly sensible purpose:
one external and on internal.
2009-12-28 16:11:18 -05:00
Nick Mathewson
390e056152 Fix up behavior of never-defered callbacks a little 2009-12-22 15:52:12 -05:00
Joachim Bauch
ea6b1df288 Only define _GNU_SOURCE if it is not already defined. 2009-12-08 15:38:34 -05:00
Nick Mathewson
438f9ed26c Add the abilitity to mark some buffer callbacks as never-deferred. 2009-12-04 14:15:17 -05:00
Roman Puls
bd6f1babf7 Fix up evthread compilation on windows 2009-12-02 01:15:15 -05:00
Nick Mathewson
347952ffe0 Revise the locking API: deprecate the old locking callbacks and add trylock.
Previously, there was no good way to request different kinds of lock
(say, read/write vs writeonly or recursive vs nonrecursive), or for a
lock function to signal failure (which would be important for a
trylock mode).

This patch revises the lock API to be a bit more useful.  The older
lock calls are still supported for now.

We also add a debugging mode to catch common errors in using the
locking APIs.
2009-11-27 17:36:24 -05:00
Nick Mathewson
07e9e9b4b1 Parenthesize macro arguments more aggressively 2009-11-20 16:50:55 -05:00
Nick Mathewson
f32b57505e Add a warning about the use of event_initialized. 2009-11-20 16:38:01 -05:00
Niels Provos
f169153956 Remove most calls to event_err() in http and deal with memory errors instead
svn:r1555
2009-11-19 23:08:50 +00:00
Nick Mathewson
201d8d0baf Clarify even more about various system-specific problems with getaddrinfo
svn:r1542
2009-11-17 18:29:44 +00:00
Nick Mathewson
86f5742015 Add two implementations of getaddrinfo: one blocking and one nonblocking.
The entry points are evutil_getaddrinfo and evdns_getaddrinfo respectively.
There are fairly extensive unit tests.

I believe this code conforms to RFC3493 pretty closely, but there are
probably more issues.  It should get tested on more platforms.

This code means we can dump the well-intentioned but weirdly-implemented
bufferevent_evdns and evutil_resolve code.

svn:r1537
2009-11-16 22:25:46 +00:00
Nick Mathewson
72bafc175a Remove the stupid brokenness where DNS option names needed to end with a
colon.

svn:r1536
2009-11-16 22:23:55 +00:00
Nick Mathewson
ab96b5f3f5 Add an option to disable the timeval cache.
svn:r1518
2009-11-09 18:30:33 +00:00
Nick Mathewson
693c24ef9d Implement queued timeouts for case where many timeouts are the same.
Libevent's current timeout code is relatively optimized for the
randomly scattered timeout case, where events are added with their
timeouts in no particular order.  We add and remove timeouts with
O(lg n) behavior.

Frequently, however, an application will want to have many timeouts
of the same value.  For example, we might have 1000 bufferevents,
each with a 2 second timeout on reading or writing.  If we knew this
were always the case, we could just put timeouts in a queue and get
O(1) add and remove behavior.  Of course, a queue would give O(n)
performance for a scattered timeout pattern, so we don't want to
just switch the implementation.

This patch gives the user the ability to explicitly tag certain
timeout values as being "very common".  These timeout values have a
cookie encoded in the high bits of their tv_usec field to indicate
which queue they belong on.  The queues themselves are each
triggered by an entry in the minheap.

See the regress_main.c code for an example use.

svn:r1517
2009-11-09 17:16:30 +00:00
Nick Mathewson
25a5e6819d Build fixes for MSVC
svn:r1506
2009-11-05 20:37:19 +00:00
Nick Mathewson
d14c3b4570 Fix another ssize_t user
svn:r1503
2009-11-05 18:25:46 +00:00
Nick Mathewson
47bad8abb7 Implement size limits on HTTP header length and body length.
Patch from Constantine Verutin, simplified a little.

svn:r1500
2009-11-04 20:17:32 +00:00
Nick Mathewson
0b9eb1bffb Add a bufferevent function to resolve a name then connect to it.
This function, bufferevent_socket_connect_hostname() can either use
evdns to do the resolve, or use a new function (evutil_resolve) that
uses getaddrinfo or gethostbyname, like http.c does now.

This function is meant to eventually replace the hostname resolution mess in
http.c.

svn:r1496
2009-11-03 20:40:48 +00:00
Nick Mathewson
e90e14fb94 Call the bufferevent_flush_mode variable "mode" more consistently in the documentation. Spotted by Alex.
svn:r1485
2009-11-02 16:31:13 +00:00