Subject: recursive MX lookup <-> libc-ares <-> libev

recursive MX lookup <-> libc-ares <-> libev

From: Wilfried Goesgens <dothebart_at_citadel.org>
Date: Sat, 08 Jan 2011 10:00:37 -0500

Hy everyone;

I'm trying to evolve citadel.orgs smtp client to become async.

My toolchain of choice became c-ares and libev.

My current workstate can be found here:
http://code.citadel.org/cgit.cgi/git.citadel.org/log/?h=libevent

For finding out the host needed to connect I need to do two DNS-calls in
sequence; first the MX record, then the IP of that host.

I've managed to implement the MX lookup by inspecting the nodejs.org
implementation; i'm successfully retrieving names here.

My journey starts like this:

modules/c-ares/serv_c-ares.c:*QueueQuery()*

its setting* ares_init_options() *with a *SockStateCb()* and then sends out
the *ares_query(Channel, "citadel.org', ns_c_in, ns_t_mx, QueryCb, IO) ;*

ngrep shows, my query goes out, *SockStateCb() *is called, it registers the
given Socket with libev for read & write operations.

My query-cb *DNS_io_callback()* gets invoked by libev, and calls
ares_process_fd(). My callback *QueryCb*() is invoked, parses the MX-record
using ares_parse_mx_reply()

It then calls my application code, which then should resolve the IP of that
first MX-Record. It does so by calling

*ares_gethostbyname(Channel*/*(same as the last query)*/*,
"uncensored.citadel.org", xxx)*

I can then see the first a-query go out from within ares_gethostbyname(), the
SockStateCB() isn't called.

when stepping out of it, back through my application call, back into c-ares,
I can see it sending that query out again; my SockStateCB() isn't called all
the time; the IO-Callback also isn't called.

If I don't step through it, the query for the IP just goes out once, but I
also don't get neither of my my callback called by *ares_gethostbyname()*, no
SockStateCb, nor my DNS_io_callback().

I'm also a little bit puzzled, that my IO-callback isn't called for sending
the mx-query.

 

Any hints what I'm doing wrong here? Where should I look at?

 

TIA, Wilfried Goesgens
Received on 2011-01-08