aboutsummaryrefslogtreecommitdiff
path: root/src/util/resolver_api.c
diff options
context:
space:
mode:
authorlurchi <lurchi@strangeplace.net>2018-06-24 23:31:07 +0200
committerlurchi <lurchi@strangeplace.net>2018-06-24 23:31:07 +0200
commitc38455c65f9968ccf7e870c3cce30fa19f319376 (patch)
tree523075af0d81a9f460d60b90b51557ad83bd5b42 /src/util/resolver_api.c
parent92e03f9117f5dc29909d73707897d28d8e27e048 (diff)
downloadgnunet-c38455c65f9968ccf7e870c3cce30fa19f319376.tar.gz
gnunet-c38455c65f9968ccf7e870c3cce30fa19f319376.zip
use the asynchronous DNS resolution API (getaddrinfo_a) in the resolver module
Diffstat (limited to 'src/util/resolver_api.c')
-rw-r--r--src/util/resolver_api.c37
1 files changed, 29 insertions, 8 deletions
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c
index afebabf08..b94819f06 100644
--- a/src/util/resolver_api.c
+++ b/src/util/resolver_api.c
@@ -69,6 +69,11 @@ static struct GNUNET_RESOLVER_RequestHandle *req_head;
69static struct GNUNET_RESOLVER_RequestHandle *req_tail; 69static struct GNUNET_RESOLVER_RequestHandle *req_tail;
70 70
71/** 71/**
72 * ID of the last request we sent to the service
73 */
74static uint32_t last_request_id;
75
76/**
72 * How long should we wait to reconnect? 77 * How long should we wait to reconnect?
73 */ 78 */
74static struct GNUNET_TIME_Relative backoff; 79static struct GNUNET_TIME_Relative backoff;
@@ -137,6 +142,11 @@ struct GNUNET_RESOLVER_RequestHandle
137 int af; 142 int af;
138 143
139 /** 144 /**
145 * Identifies the request. The response will contain this id.
146 */
147 uint32_t id;
148
149 /**
140 * Has this request been transmitted to the service? 150 * Has this request been transmitted to the service?
141 * #GNUNET_YES if transmitted 151 * #GNUNET_YES if transmitted
142 * #GNUNET_YES if not transmitted 152 * #GNUNET_YES if not transmitted
@@ -435,11 +445,13 @@ process_requests ()
435 GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST); 445 GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST);
436 msg->direction = htonl (rh->direction); 446 msg->direction = htonl (rh->direction);
437 msg->af = htonl (rh->af); 447 msg->af = htonl (rh->af);
448 msg->id = htonl (rh->id);
438 GNUNET_memcpy (&msg[1], 449 GNUNET_memcpy (&msg[1],
439 &rh[1], 450 &rh[1],
440 rh->data_len); 451 rh->data_len);
441 LOG (GNUNET_ERROR_TYPE_DEBUG, 452 LOG (GNUNET_ERROR_TYPE_DEBUG,
442 "Transmitting DNS resolution request to DNS service\n"); 453 "Transmitting DNS resolution request (ID %u) to DNS service\n",
454 rh->id);
443 GNUNET_MQ_send (mq, 455 GNUNET_MQ_send (mq,
444 env); 456 env);
445 rh->was_transmitted = GNUNET_YES; 457 rh->was_transmitted = GNUNET_YES;
@@ -454,7 +466,7 @@ process_requests ()
454 */ 466 */
455static int 467static int
456check_response (void *cls, 468check_response (void *cls,
457 const struct GNUNET_MessageHeader *msg) 469 const struct GNUNET_RESOLVER_ResponseMessage *msg)
458{ 470{
459 (void) cls; 471 (void) cls;
460 (void) msg; 472 (void) msg;
@@ -474,11 +486,18 @@ check_response (void *cls,
474 */ 486 */
475static void 487static void
476handle_response (void *cls, 488handle_response (void *cls,
477 const struct GNUNET_MessageHeader *msg) 489 const struct GNUNET_RESOLVER_ResponseMessage *msg)
478{ 490{
479 struct GNUNET_RESOLVER_RequestHandle *rh = req_head; 491 struct GNUNET_RESOLVER_RequestHandle *rh = req_head;
480 uint16_t size; 492 uint16_t size;
481 char *nret; 493 char *nret;
494 uint32_t request_id = msg->id;
495
496 for (; rh != NULL; rh = rh->next)
497 {
498 if (rh->id == request_id)
499 break;
500 }
482 501
483 (void) cls; 502 (void) cls;
484 if (NULL == rh) 503 if (NULL == rh)
@@ -490,8 +509,8 @@ handle_response (void *cls,
490 reconnect (); 509 reconnect ();
491 return; 510 return;
492 } 511 }
493 size = ntohs (msg->size); 512 size = ntohs (msg->header.size);
494 if (size == sizeof (struct GNUNET_MessageHeader)) 513 if (size == sizeof (struct GNUNET_RESOLVER_ResponseMessage))
495 { 514 {
496 LOG (GNUNET_ERROR_TYPE_DEBUG, 515 LOG (GNUNET_ERROR_TYPE_DEBUG,
497 "Received empty response from DNS service\n"); 516 "Received empty response from DNS service\n");
@@ -532,7 +551,7 @@ handle_response (void *cls,
532 const char *hostname; 551 const char *hostname;
533 552
534 hostname = (const char *) &msg[1]; 553 hostname = (const char *) &msg[1];
535 if (hostname[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0') 554 if (hostname[size - sizeof (struct GNUNET_RESOLVER_ResponseMessage) - 1] != '\0')
536 { 555 {
537 GNUNET_break (0); 556 GNUNET_break (0);
538 if (GNUNET_SYSERR != rh->was_transmitted) 557 if (GNUNET_SYSERR != rh->was_transmitted)
@@ -566,7 +585,7 @@ handle_response (void *cls,
566 size_t ip_len; 585 size_t ip_len;
567 586
568 ip = &msg[1]; 587 ip = &msg[1];
569 ip_len = size - sizeof (struct GNUNET_MessageHeader); 588 ip_len = size - sizeof (struct GNUNET_RESOLVER_ResponseMessage);
570 if (ip_len == sizeof (struct in_addr)) 589 if (ip_len == sizeof (struct in_addr))
571 { 590 {
572 memset (&v4, 0, sizeof (v4)); 591 memset (&v4, 0, sizeof (v4));
@@ -763,7 +782,7 @@ reconnect_task (void *cls)
763 struct GNUNET_MQ_MessageHandler handlers[] = { 782 struct GNUNET_MQ_MessageHandler handlers[] = {
764 GNUNET_MQ_hd_var_size (response, 783 GNUNET_MQ_hd_var_size (response,
765 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE, 784 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE,
766 struct GNUNET_MessageHeader, 785 struct GNUNET_RESOLVER_ResponseMessage,
767 NULL), 786 NULL),
768 GNUNET_MQ_handler_end () 787 GNUNET_MQ_handler_end ()
769 }; 788 };
@@ -926,6 +945,7 @@ GNUNET_RESOLVER_ip_get (const char *hostname,
926 hostname); 945 hostname);
927 rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + slen); 946 rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + slen);
928 rh->af = af; 947 rh->af = af;
948 rh->id = ++last_request_id;
929 rh->addr_callback = callback; 949 rh->addr_callback = callback;
930 rh->cls = callback_cls; 950 rh->cls = callback_cls;
931 GNUNET_memcpy (&rh[1], 951 GNUNET_memcpy (&rh[1],
@@ -1072,6 +1092,7 @@ GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa,
1072 rh->name_callback = callback; 1092 rh->name_callback = callback;
1073 rh->cls = cls; 1093 rh->cls = cls;
1074 rh->af = sa->sa_family; 1094 rh->af = sa->sa_family;
1095 rh->id = ++last_request_id;
1075 rh->timeout = GNUNET_TIME_relative_to_absolute (timeout); 1096 rh->timeout = GNUNET_TIME_relative_to_absolute (timeout);
1076 GNUNET_memcpy (&rh[1], 1097 GNUNET_memcpy (&rh[1],
1077 ip, 1098 ip,