diff options
author | Phil <phil.buschmann@tum.de> | 2018-06-25 00:17:34 +0200 |
---|---|---|
committer | Phil <phil.buschmann@tum.de> | 2018-06-25 00:17:34 +0200 |
commit | db8c5cd31a92cd18450bf9d2d595a8fd314583e0 (patch) | |
tree | 01fd1779157a215346618ff0a575ef150051d154 /src/util/resolver_api.c | |
parent | 4e6cb01843318385cfad41aec4cde5791f51cde2 (diff) | |
parent | d87371054ac03be953cb8b2d216e735d99515ca4 (diff) | |
download | gnunet-db8c5cd31a92cd18450bf9d2d595a8fd314583e0.tar.gz gnunet-db8c5cd31a92cd18450bf9d2d595a8fd314583e0.zip |
-Merge branch 'master' of ssh://gnunet.org/gnunet into gsoc2018/rest_api
Diffstat (limited to 'src/util/resolver_api.c')
-rw-r--r-- | src/util/resolver_api.c | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c index b2e6a4986..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; | |||
69 | static struct GNUNET_RESOLVER_RequestHandle *req_tail; | 69 | static struct GNUNET_RESOLVER_RequestHandle *req_tail; |
70 | 70 | ||
71 | /** | 71 | /** |
72 | * ID of the last request we sent to the service | ||
73 | */ | ||
74 | static 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 | */ |
74 | static struct GNUNET_TIME_Relative backoff; | 79 | static 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 |
@@ -180,6 +190,11 @@ check_config () | |||
180 | struct sockaddr_in v4; | 190 | struct sockaddr_in v4; |
181 | struct sockaddr_in6 v6; | 191 | struct sockaddr_in6 v6; |
182 | 192 | ||
193 | if (GNUNET_OK == | ||
194 | GNUNET_CONFIGURATION_have_value (resolver_cfg, | ||
195 | "resolver", | ||
196 | "UNIXPATH")) | ||
197 | return GNUNET_OK; | ||
183 | memset (&v4, 0, sizeof (v4)); | 198 | memset (&v4, 0, sizeof (v4)); |
184 | v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK); | 199 | v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK); |
185 | v4.sin_family = AF_INET; | 200 | v4.sin_family = AF_INET; |
@@ -430,11 +445,13 @@ process_requests () | |||
430 | GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST); | 445 | GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST); |
431 | msg->direction = htonl (rh->direction); | 446 | msg->direction = htonl (rh->direction); |
432 | msg->af = htonl (rh->af); | 447 | msg->af = htonl (rh->af); |
448 | msg->id = htonl (rh->id); | ||
433 | GNUNET_memcpy (&msg[1], | 449 | GNUNET_memcpy (&msg[1], |
434 | &rh[1], | 450 | &rh[1], |
435 | rh->data_len); | 451 | rh->data_len); |
436 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 452 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
437 | "Transmitting DNS resolution request to DNS service\n"); | 453 | "Transmitting DNS resolution request (ID %u) to DNS service\n", |
454 | rh->id); | ||
438 | GNUNET_MQ_send (mq, | 455 | GNUNET_MQ_send (mq, |
439 | env); | 456 | env); |
440 | rh->was_transmitted = GNUNET_YES; | 457 | rh->was_transmitted = GNUNET_YES; |
@@ -449,7 +466,7 @@ process_requests () | |||
449 | */ | 466 | */ |
450 | static int | 467 | static int |
451 | check_response (void *cls, | 468 | check_response (void *cls, |
452 | const struct GNUNET_MessageHeader *msg) | 469 | const struct GNUNET_RESOLVER_ResponseMessage *msg) |
453 | { | 470 | { |
454 | (void) cls; | 471 | (void) cls; |
455 | (void) msg; | 472 | (void) msg; |
@@ -469,11 +486,18 @@ check_response (void *cls, | |||
469 | */ | 486 | */ |
470 | static void | 487 | static void |
471 | handle_response (void *cls, | 488 | handle_response (void *cls, |
472 | const struct GNUNET_MessageHeader *msg) | 489 | const struct GNUNET_RESOLVER_ResponseMessage *msg) |
473 | { | 490 | { |
474 | struct GNUNET_RESOLVER_RequestHandle *rh = req_head; | 491 | struct GNUNET_RESOLVER_RequestHandle *rh = req_head; |
475 | uint16_t size; | 492 | uint16_t size; |
476 | 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 | } | ||
477 | 501 | ||
478 | (void) cls; | 502 | (void) cls; |
479 | if (NULL == rh) | 503 | if (NULL == rh) |
@@ -485,8 +509,8 @@ handle_response (void *cls, | |||
485 | reconnect (); | 509 | reconnect (); |
486 | return; | 510 | return; |
487 | } | 511 | } |
488 | size = ntohs (msg->size); | 512 | size = ntohs (msg->header.size); |
489 | if (size == sizeof (struct GNUNET_MessageHeader)) | 513 | if (size == sizeof (struct GNUNET_RESOLVER_ResponseMessage)) |
490 | { | 514 | { |
491 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 515 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
492 | "Received empty response from DNS service\n"); | 516 | "Received empty response from DNS service\n"); |
@@ -527,7 +551,7 @@ handle_response (void *cls, | |||
527 | const char *hostname; | 551 | const char *hostname; |
528 | 552 | ||
529 | hostname = (const char *) &msg[1]; | 553 | hostname = (const char *) &msg[1]; |
530 | if (hostname[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0') | 554 | if (hostname[size - sizeof (struct GNUNET_RESOLVER_ResponseMessage) - 1] != '\0') |
531 | { | 555 | { |
532 | GNUNET_break (0); | 556 | GNUNET_break (0); |
533 | if (GNUNET_SYSERR != rh->was_transmitted) | 557 | if (GNUNET_SYSERR != rh->was_transmitted) |
@@ -561,7 +585,7 @@ handle_response (void *cls, | |||
561 | size_t ip_len; | 585 | size_t ip_len; |
562 | 586 | ||
563 | ip = &msg[1]; | 587 | ip = &msg[1]; |
564 | ip_len = size - sizeof (struct GNUNET_MessageHeader); | 588 | ip_len = size - sizeof (struct GNUNET_RESOLVER_ResponseMessage); |
565 | if (ip_len == sizeof (struct in_addr)) | 589 | if (ip_len == sizeof (struct in_addr)) |
566 | { | 590 | { |
567 | memset (&v4, 0, sizeof (v4)); | 591 | memset (&v4, 0, sizeof (v4)); |
@@ -758,7 +782,7 @@ reconnect_task (void *cls) | |||
758 | struct GNUNET_MQ_MessageHandler handlers[] = { | 782 | struct GNUNET_MQ_MessageHandler handlers[] = { |
759 | GNUNET_MQ_hd_var_size (response, | 783 | GNUNET_MQ_hd_var_size (response, |
760 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE, | 784 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE, |
761 | struct GNUNET_MessageHeader, | 785 | struct GNUNET_RESOLVER_ResponseMessage, |
762 | NULL), | 786 | NULL), |
763 | GNUNET_MQ_handler_end () | 787 | GNUNET_MQ_handler_end () |
764 | }; | 788 | }; |
@@ -921,6 +945,7 @@ GNUNET_RESOLVER_ip_get (const char *hostname, | |||
921 | hostname); | 945 | hostname); |
922 | rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + slen); | 946 | rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + slen); |
923 | rh->af = af; | 947 | rh->af = af; |
948 | rh->id = ++last_request_id; | ||
924 | rh->addr_callback = callback; | 949 | rh->addr_callback = callback; |
925 | rh->cls = callback_cls; | 950 | rh->cls = callback_cls; |
926 | GNUNET_memcpy (&rh[1], | 951 | GNUNET_memcpy (&rh[1], |
@@ -1067,6 +1092,7 @@ GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa, | |||
1067 | rh->name_callback = callback; | 1092 | rh->name_callback = callback; |
1068 | rh->cls = cls; | 1093 | rh->cls = cls; |
1069 | rh->af = sa->sa_family; | 1094 | rh->af = sa->sa_family; |
1095 | rh->id = ++last_request_id; | ||
1070 | rh->timeout = GNUNET_TIME_relative_to_absolute (timeout); | 1096 | rh->timeout = GNUNET_TIME_relative_to_absolute (timeout); |
1071 | GNUNET_memcpy (&rh[1], | 1097 | GNUNET_memcpy (&rh[1], |
1072 | ip, | 1098 | ip, |