Sfoglia il codice sorgente

[Project] Rdns: Add more functions for TCP based requests

tags/3.2
Vsevolod Stakhov 2 anni fa
parent
commit
be5153fa1b

+ 3
- 1
contrib/librdns/dns_private.h Vedi File



static const int dns_port = 53; static const int dns_port = 53;
static const int default_io_cnt = 8; static const int default_io_cnt = 8;
static const int default_tcp_io_cnt = 2;
static const int default_tcp_io_cnt = 1;


#define UDP_PACKET_SIZE (4096 * 2) #define UDP_PACKET_SIZE (4096 * 2)


}; };


KHASH_DECLARE(rdns_requests_hash, int, struct rdns_request *); KHASH_DECLARE(rdns_requests_hash, int, struct rdns_request *);
#define RDNS_IO_CHANNEL_TAG UINT64_C(0xe190a5ba12f094c8)
/** /**
* IO channel for a specific DNS server * IO channel for a specific DNS server
*/ */
struct rdns_io_channel { struct rdns_io_channel {
uint64_t struct_magic; /**< tag for this structure */
struct rdns_server *srv; struct rdns_server *srv;
struct rdns_resolver *resolver; struct rdns_resolver *resolver;
struct sockaddr *saddr; struct sockaddr *saddr;

+ 1
- 1
contrib/librdns/rdns.h Vedi File



void rdns_process_read (int fd, void *arg); void rdns_process_read (int fd, void *arg);
void rdns_process_timer (void *arg); void rdns_process_timer (void *arg);
void rdns_process_retransmit (int fd, void *arg);
void rdns_process_write (int fd, void *arg);


#ifdef __cplusplus #ifdef __cplusplus
} }

+ 1
- 1
contrib/librdns/rdns_ev.h Vedi File

static void static void
rdns_libev_write_event (struct ev_loop *loop, ev_io *ev, int revents) rdns_libev_write_event (struct ev_loop *loop, ev_io *ev, int revents)
{ {
rdns_process_retransmit (ev->fd, ev->data);
rdns_process_write(ev->fd, ev->data);
} }


static void static void

+ 1
- 1
contrib/librdns/rdns_event.h Vedi File

static void static void
rdns_libevent_write_event (int fd, short what, void *ud) rdns_libevent_write_event (int fd, short what, void *ud)
{ {
rdns_process_retransmit (fd, ud);
rdns_process_write (fd, ud);
} }


static void static void

+ 44
- 5
contrib/librdns/resolver.c Vedi File

} }
} }


void
rdns_process_retransmit (int fd, void *arg)
static void
rdns_process_udp_retransmit (int fd, struct rdns_request *req)
{ {
struct rdns_request *req = (struct rdns_request *)arg;
struct rdns_resolver *resolver; struct rdns_resolver *resolver;
struct rdns_reply *rep; struct rdns_reply *rep;
int r; int r;
if (r == 0) { if (r == 0) {
/* Retransmit one more time */ /* Retransmit one more time */
req->async_event = req->async->add_write (req->async->data, req->async_event = req->async->add_write (req->async->data,
fd, req);
fd, req);
req->state = RDNS_REQUEST_WAIT_SEND; req->state = RDNS_REQUEST_WAIT_SEND;
} }
else if (r == -1) { else if (r == -1) {
} }
else { else {
req->async_event = req->async->add_timer (req->async->data, req->async_event = req->async->add_timer (req->async->data,
req->timeout, req);
req->timeout, req);
req->state = RDNS_REQUEST_WAIT_REPLY; req->state = RDNS_REQUEST_WAIT_REPLY;
} }
} }


static void
rdns_process_tcp_write (int fd, struct rdns_io_channel *ioc)
{

}

void
rdns_process_write (int fd, void *arg)
{
/*
* We first need to dispatch *arg to understand what has caused the write
* readiness event.
* The one possibility is that it was a UDP retransmit request, so our
* arg will be struct rdns_request *
* Another possibility is that write event was triggered by some TCP related
* stuff. In this case the only possibility is that our arg is struct rdns_io_channel *
* To distinguish these two cases (due to flaws in the rdns architecture in the first
* place) we compare the first 8 bytes with RDNS_IO_CHANNEL_TAG
*/
uint64_t tag;

memcpy (&tag, arg, sizeof(tag));

if (tag == RDNS_IO_CHANNEL_TAG) {
struct rdns_io_channel *ioc = (struct rdns_io_channel *) arg;

if (IS_CHANNEL_CONNECTED(ioc)) {
rdns_process_tcp_write(fd, ioc);
}
else {
rdns_process_tcp_connect(fd, ioc);
}
}
else {
struct rdns_request *req = (struct rdns_request *) arg;
rdns_process_udp_retransmit(fd, req);
}
}

struct rdns_server * struct rdns_server *
rdns_select_request_upstream (struct rdns_resolver *resolver, rdns_select_request_upstream (struct rdns_resolver *resolver,
struct rdns_request *req, struct rdns_request *req,
} }
UPSTREAM_DEL (resolver->servers, serv); UPSTREAM_DEL (resolver->servers, serv);
free (serv->io_channels); free (serv->io_channels);
free (serv->tcp_io_channels);
free (serv->name); free (serv->name);
free (serv); free (serv);
} }

+ 1
- 0
contrib/librdns/util.c Vedi File

return NULL; return NULL;
} }


nioc->struct_magic = RDNS_IO_CHANNEL_TAG;
nioc->sock = rdns_make_client_socket (serv->name, serv->port, nioc->sock = rdns_make_client_socket (serv->name, serv->port,
is_tcp ? SOCK_STREAM : SOCK_DGRAM, &nioc->saddr, &nioc->slen); is_tcp ? SOCK_STREAM : SOCK_DGRAM, &nioc->saddr, &nioc->slen);
if (nioc->sock == -1) { if (nioc->sock == -1) {

Loading…
Annulla
Salva