264 Commits

Author SHA1 Message Date
Nick Mathewson
5fa30d2bf4 Fix evdns build with -DUNICODE
It turns out that GetProcAddress always takes its second argument as
a C string, regardless of whether unicode is on or not.
2010-08-06 17:13:27 -04:00
Nick Mathewson
cc2379d264 Constify a couple of arguments to evdns_server_request_add_*_reply 2010-07-26 14:48:32 -04:00
Nick Mathewson
e1c1167cbe Replace (unused,always 0) is_tcp argument to evdns_add_server_port*() with flags
Since we weren't using it for anything, and we always failed if it was
set, we're allowed to change the future semantics of setting it.
2010-07-22 14:44:24 +02:00
Nick Mathewson
7e87a599bb Stop asserting when asked for a (unsupported) TCP dns port. Just return NULL. 2010-07-21 14:33:42 +02:00
Nick Mathewson
899b0a39ab Use generic win32 interfaces, not ASCII-only ones, where possible. 2010-05-24 15:24:03 -04:00
Nick Mathewson
b14f151b42 If no evdns request can be launched, return NULL, not a handle
Some of our evdns code was willing to return an evdns_request with
handle->current_req set to NULL.  Really, those cases should just
return NULL.
2010-05-18 17:27:06 -04:00
Nick Mathewson
b1c795007f Make evdns logging threadsafe
The old logging code was littered with places where we stored messages in
static char[] fields.  This is fine in a single-threaded program, but if you
ever tried to log evdns messages from two threads at once, you'd hit a race.

This patch also refactors evdns's debug_ntop function into a more useful
evutil_sockaddr_port_format() function, with unit tests.
2010-04-23 14:42:25 -04:00
Nick Mathewson
ceefbe8730 Add a comment to explain why evdns_request is now separte from request 2010-04-23 14:04:03 -04:00
Christopher Davis
67072f3c3b Assert for valid requests as necessary.
A valid request has an associated handle, and the handle must point
to the request.
2010-04-22 21:46:05 -07:00
Christopher Davis
a62584000a Free search state when finished searching to avoid an infinite loop. 2010-04-21 22:20:10 -07:00
Christopher Davis
beaa14a46f Move domain search state to evdns_request.
It doesn't seem to make sense to copy the state to each new request
in the search.
2010-04-21 22:01:59 -07:00
Christopher Davis
15bb82d690 Ensure that evdns_request is a persistent handle.
When searching is enabled, evdns may make multiple requests before
calling the user callback with the result. This is a problem because
the same evdns_request handle is not retained for each search request,
so the user cannot reliably cancel the request.

This patch attempts to ensure that evdns_request persists accross
search requests.
2010-04-21 21:21:21 -07:00
Sebastian Sjöberg
899c1dcc98 Replace EVUTIL_CLOSESOCKET macro with a function
The EVUTIL_CLOSESOCKET() macro required you to include unistd.h in your
source for POSIX.  We might as well turn it into a function: an extra
function call is going to be cheap in comparison with the system call.

We retain the EVUTIL_CLOSESOCKET() macro as an alias for the new
evutil_closesocket() function.

(commit message from email by Nick and Sebastian)
2010-04-14 15:42:57 -04:00
Nick Mathewson
859af6772c Free evdns_base->req_heads on evdns_base_free
It looks like when we moved from one big inflight-requests list to an
n-heads structure, we didn't make evdns_base_free() free the array of
heads.  This patch should fix that.

Found with valgrind
2010-03-13 00:53:54 -05:00
Nick Mathewson
b2f2be6edc Make evdns use the regular logging system by default
Once, for reasons that made sense at the time, we had evdns.c use its
own logging subsystem with two levels, "warn" and "debug".  This leads
to problems, since setting a log handler for Libevent wouldn't actually
trap these messages, since they weren't on by default, and since some of
the warns should really be msgs.

This patch changes the default behavior of evdns.c to log to
event_(debugx,warnx,msgx) by default, and adds a new (internal-use-only)
log level of EVDNS_LOG_MSG.  Programs that set a evdns logging
function will see no change.  Programs that don't will now see evdns
warnings reported like other warnings.
2010-03-10 16:25:16 -05:00
Nick Mathewson
2c2618d858 more whitespace normalization 2010-03-05 13:00:15 -05:00
Nick Mathewson
4faeaea90e Clean up formatting: function/keyword spacing consistency.
- Keywords always have a space before a paren.  Functions never do.

- No more than 3 blank lines in a row.
2010-02-19 03:39:50 -05:00
Nick Mathewson
e5bbd40ad7 Clean up formatting: use tabs, not 8-spaces, to indent. 2010-02-18 17:44:09 -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
a7a943106c Fix some additional -DUNICODE issues on win32.
Brodie's patch didn't catch the ones that were new since 1.4.
2010-02-03 23:49:22 -05:00
Brodie Thiesfield
000a33ec83 Make Libevent 1.4.12 build on win32 with Unicode enabled.
This patch fixes calls to the win32 api to explicitly call the char* versions
of the functions. This fixes build failures when libevent is built with the
UNICODE define.
2010-02-03 23:31:44 -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
439aea0d07 Try to untangle the logic in server_port_flush().
The logic that prevented the first loop in this function from being
infinite was rather confusing and hard to follow.  It seems to confuse
some automatic analysis tools as well as me.  Let's try to replace it
with something more comprehensible.
2010-01-25 14:07:01 -05:00
Nick Mathewson
a19b4a05e6 Call event_debug_unassign on internal events
I don't expect that many users will be so religious about calling
unassign, but we need to be so that it's at least possible to use
debug mode without eating memory.
2010-01-25 13:53:17 -05:00
Nick Mathewson
e2ca403fae Make it compile under gcc --std=c89. 2010-01-23 16:23:45 -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
8d4aaf9086 Don't use a bind address for nameservers on loopback
If the user sets a bind address to use for nameservers, and a
nameserver happens to be on 127.0.0.1, the nameserver will generally
fail.  This patch alters this behavior so that the bind address is
only applied when the nameserver is on a non-loopback address.
2010-01-20 12:56:54 -05:00
Nick Mathewson
66c02c7826 Look at the proper /etc/hosts file on windows.
This is harder than it might initially seem, since the proper filename
depends on what the admin has decided to call the windows system directory,
which for all we know might be Q:\tralfamidore\slartibartfast.  And of course,
this being windows, there are twelve ways to do it, where you can pick a
nice one or a portable one, but not a really nice portable one.
2010-01-08 19:36:38 -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
Jardel Weyrich
0546ce11e8 Eradicated the last free() call. Let mm_free() take care of deallocation. 2009-12-30 17:28:05 -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
Nick Mathewson
ee4953f89e Fix the code that allowed DNS options to not end with :
We tried to fix this in 0.2.0.3-alpha, but our fix was buggy.
2009-12-29 16:03:30 -05:00
unknown
c51bb3c342 Fix a few locking issues on windows. 2009-12-21 16:36:40 -05:00
Nick Mathewson
2b7abf038f Merge commit 'niels/dnscrash' 2009-12-04 13:49:27 -05:00
Yasuoka Masahiko
6c7c5799a4 Fix a crash when reading badly formatted resolve.conf; from Yasuoka Masahiko 2009-12-04 10:44:46 -08:00
Nick Mathewson
0cd3bb9f3a Improved optional lock debugging.
There were a couple of places in the code where we manually kept lock
counts to make sure we never accessed resources without holding a
lock, and that we never released a lock we didn't have.  The
lock-debugging code already puts counts on _every_ lock when lock
debugging is enabled, so there is no need to keep these counts around
otherwise.  This patch rewrites the ASSERT_FOO_LOCKED macros to all
use a common EVLOCK_ASSERT_LOCKED().

We also teach the lock debugging code to keep track of who exactly
holds each lock, so that EVLOCK_ASSERT_LOCKED() means "locked by this
thread."
2009-11-27 17:36:51 -05:00
Zhuang Yuyao
2df1f82bfa Fix an evdns lock violation.
Original message:

   evdns contains a bug related to thread lock.

   enable thread lock by evthread_use_pthreads() will cause successive
   evdns_base_resolve_ipv4() (and other resolve functions i think) to
   hang on EVDNS_LOCK(base) after one or several successful call to
   evdns_base_resolve_ipv4().
2009-11-27 17:36:51 -05:00
Nick Mathewson
76cd2b70bb Stop passing EVTHREAD_READ and EVTHREAD_WRITE to non-rw locks.
Previously, our default lock model kind of assumed that every lock was
potentially a read-write lock.  This was a poor choice, since
read-write locks are far more expensive than regular locks, and so the
lock API should only use them when we can actually take advantage of
them.  Neither our pthreads or win32 lock implementation provided rw
locks.

Now that we have a way (not currently used!) to	indicate that we
really want a read-write lock, we shouldn't actually say "lock this
for reading" or "lock this for writing" unless we mean it.
2009-11-27 17:36:51 -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
91fe23fc08 Tolerate code that returns from a fatal_cb.
Also, replace more abort() calls with EVUTIL_ASSERT() or event_errx.
2009-11-20 15:46:04 -05:00
Nick Mathewson
767eb70f50 Fix compilation with threading disabled.
svn:r1546
2009-11-18 21:16:33 +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
18a8cfac39 Prefer calloc(a,b) to malloc(a*b). via openbsd.
svn:r1531
2009-11-15 19:00:12 +00:00
Nick Mathewson
e2b2de79bf Use arc4random() for dns transaction ids where available. Patch taken from OpenBSD
svn:r1528
2009-11-15 18:59:48 +00:00
Nick Mathewson
784b8773a4 We do not work any more without an event-config.h; stop pretending that it is meaningful to check for HAVE_CONFIG_H
svn:r1516
2009-11-06 21:46:57 +00:00
Nick Mathewson
d2e7e65d21 Move the evdns sample code into the sample directory and fix it not to use any deprecated APIs.
svn:r1511
2009-11-05 22:19:09 +00:00
Nick Mathewson
25a5e6819d Build fixes for MSVC
svn:r1506
2009-11-05 20:37:19 +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