diff options
Diffstat (limited to 'src/util/resolver_api.c')
-rw-r--r-- | src/util/resolver_api.c | 74 |
1 files changed, 54 insertions, 20 deletions
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c index 68f02587a..8a054327b 100644 --- a/src/util/resolver_api.c +++ b/src/util/resolver_api.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009-2018 GNUnet e.V. | 3 | Copyright (C) 2009-2018 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | 18 | ||
21 | /** | 19 | /** |
@@ -70,6 +68,11 @@ static struct GNUNET_RESOLVER_RequestHandle *req_head; | |||
70 | */ | 68 | */ |
71 | static struct GNUNET_RESOLVER_RequestHandle *req_tail; | 69 | static struct GNUNET_RESOLVER_RequestHandle *req_tail; |
72 | 70 | ||
71 | ///** | ||
72 | // * ID of the last request we sent to the service | ||
73 | // */ | ||
74 | //static uint16_t last_request_id; | ||
75 | |||
73 | /** | 76 | /** |
74 | * How long should we wait to reconnect? | 77 | * How long should we wait to reconnect? |
75 | */ | 78 | */ |
@@ -139,6 +142,11 @@ struct GNUNET_RESOLVER_RequestHandle | |||
139 | int af; | 142 | int af; |
140 | 143 | ||
141 | /** | 144 | /** |
145 | * Identifies the request. The response will contain this id. | ||
146 | */ | ||
147 | uint32_t id; | ||
148 | |||
149 | /** | ||
142 | * Has this request been transmitted to the service? | 150 | * Has this request been transmitted to the service? |
143 | * #GNUNET_YES if transmitted | 151 | * #GNUNET_YES if transmitted |
144 | * #GNUNET_YES if not transmitted | 152 | * #GNUNET_YES if not transmitted |
@@ -182,6 +190,11 @@ check_config () | |||
182 | struct sockaddr_in v4; | 190 | struct sockaddr_in v4; |
183 | struct sockaddr_in6 v6; | 191 | struct sockaddr_in6 v6; |
184 | 192 | ||
193 | if (GNUNET_OK == | ||
194 | GNUNET_CONFIGURATION_have_value (resolver_cfg, | ||
195 | "resolver", | ||
196 | "UNIXPATH")) | ||
197 | return GNUNET_OK; | ||
185 | memset (&v4, 0, sizeof (v4)); | 198 | memset (&v4, 0, sizeof (v4)); |
186 | v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK); | 199 | v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK); |
187 | v4.sin_family = AF_INET; | 200 | v4.sin_family = AF_INET; |
@@ -432,11 +445,13 @@ process_requests () | |||
432 | GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST); | 445 | GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST); |
433 | msg->direction = htonl (rh->direction); | 446 | msg->direction = htonl (rh->direction); |
434 | msg->af = htonl (rh->af); | 447 | msg->af = htonl (rh->af); |
448 | msg->id = htons (rh->id); | ||
435 | GNUNET_memcpy (&msg[1], | 449 | GNUNET_memcpy (&msg[1], |
436 | &rh[1], | 450 | &rh[1], |
437 | rh->data_len); | 451 | rh->data_len); |
438 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 452 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
439 | "Transmitting DNS resolution request to DNS service\n"); | 453 | "Transmitting DNS resolution request (ID %u) to DNS service\n", |
454 | rh->id); | ||
440 | GNUNET_MQ_send (mq, | 455 | GNUNET_MQ_send (mq, |
441 | env); | 456 | env); |
442 | rh->was_transmitted = GNUNET_YES; | 457 | rh->was_transmitted = GNUNET_YES; |
@@ -451,7 +466,7 @@ process_requests () | |||
451 | */ | 466 | */ |
452 | static int | 467 | static int |
453 | check_response (void *cls, | 468 | check_response (void *cls, |
454 | const struct GNUNET_MessageHeader *msg) | 469 | const struct GNUNET_RESOLVER_ResponseMessage *msg) |
455 | { | 470 | { |
456 | (void) cls; | 471 | (void) cls; |
457 | (void) msg; | 472 | (void) msg; |
@@ -471,11 +486,18 @@ check_response (void *cls, | |||
471 | */ | 486 | */ |
472 | static void | 487 | static void |
473 | handle_response (void *cls, | 488 | handle_response (void *cls, |
474 | const struct GNUNET_MessageHeader *msg) | 489 | const struct GNUNET_RESOLVER_ResponseMessage *msg) |
475 | { | 490 | { |
476 | struct GNUNET_RESOLVER_RequestHandle *rh = req_head; | 491 | struct GNUNET_RESOLVER_RequestHandle *rh = req_head; |
477 | uint16_t size; | 492 | uint16_t size; |
478 | char *nret; | 493 | char *nret; |
494 | uint16_t request_id = msg->id; | ||
495 | |||
496 | for (; rh != NULL; rh = rh->next) | ||
497 | { | ||
498 | if (rh->id == request_id) | ||
499 | break; | ||
500 | } | ||
479 | 501 | ||
480 | (void) cls; | 502 | (void) cls; |
481 | if (NULL == rh) | 503 | if (NULL == rh) |
@@ -487,8 +509,8 @@ handle_response (void *cls, | |||
487 | reconnect (); | 509 | reconnect (); |
488 | return; | 510 | return; |
489 | } | 511 | } |
490 | size = ntohs (msg->size); | 512 | size = ntohs (msg->header.size); |
491 | if (size == sizeof (struct GNUNET_MessageHeader)) | 513 | if (size == sizeof (struct GNUNET_RESOLVER_ResponseMessage)) |
492 | { | 514 | { |
493 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 515 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
494 | "Received empty response from DNS service\n"); | 516 | "Received empty response from DNS service\n"); |
@@ -515,8 +537,8 @@ handle_response (void *cls, | |||
515 | if ( (NULL != rh->addr_callback) && | 537 | if ( (NULL != rh->addr_callback) && |
516 | (GNUNET_SYSERR != rh->was_transmitted) ) | 538 | (GNUNET_SYSERR != rh->was_transmitted) ) |
517 | rh->addr_callback (rh->cls, | 539 | rh->addr_callback (rh->cls, |
518 | NULL, | 540 | NULL, |
519 | 0); | 541 | 0); |
520 | } | 542 | } |
521 | rh->was_transmitted = GNUNET_NO; | 543 | rh->was_transmitted = GNUNET_NO; |
522 | GNUNET_RESOLVER_request_cancel (rh); | 544 | GNUNET_RESOLVER_request_cancel (rh); |
@@ -529,7 +551,7 @@ handle_response (void *cls, | |||
529 | const char *hostname; | 551 | const char *hostname; |
530 | 552 | ||
531 | hostname = (const char *) &msg[1]; | 553 | hostname = (const char *) &msg[1]; |
532 | if (hostname[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0') | 554 | if (hostname[size - sizeof (struct GNUNET_RESOLVER_ResponseMessage) - 1] != '\0') |
533 | { | 555 | { |
534 | GNUNET_break (0); | 556 | GNUNET_break (0); |
535 | if (GNUNET_SYSERR != rh->was_transmitted) | 557 | if (GNUNET_SYSERR != rh->was_transmitted) |
@@ -563,7 +585,7 @@ handle_response (void *cls, | |||
563 | size_t ip_len; | 585 | size_t ip_len; |
564 | 586 | ||
565 | ip = &msg[1]; | 587 | ip = &msg[1]; |
566 | ip_len = size - sizeof (struct GNUNET_MessageHeader); | 588 | ip_len = size - sizeof (struct GNUNET_RESOLVER_ResponseMessage); |
567 | if (ip_len == sizeof (struct in_addr)) | 589 | if (ip_len == sizeof (struct in_addr)) |
568 | { | 590 | { |
569 | memset (&v4, 0, sizeof (v4)); | 591 | memset (&v4, 0, sizeof (v4)); |
@@ -760,7 +782,7 @@ reconnect_task (void *cls) | |||
760 | struct GNUNET_MQ_MessageHandler handlers[] = { | 782 | struct GNUNET_MQ_MessageHandler handlers[] = { |
761 | GNUNET_MQ_hd_var_size (response, | 783 | GNUNET_MQ_hd_var_size (response, |
762 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE, | 784 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE, |
763 | struct GNUNET_MessageHeader, | 785 | struct GNUNET_RESOLVER_ResponseMessage, |
764 | NULL), | 786 | NULL), |
765 | GNUNET_MQ_handler_end () | 787 | GNUNET_MQ_handler_end () |
766 | }; | 788 | }; |
@@ -889,6 +911,14 @@ handle_lookup_timeout (void *cls) | |||
889 | } | 911 | } |
890 | 912 | ||
891 | 913 | ||
914 | static uint16_t | ||
915 | get_request_id () | ||
916 | { | ||
917 | return (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, | ||
918 | UINT16_MAX); | ||
919 | } | ||
920 | |||
921 | |||
892 | /** | 922 | /** |
893 | * Convert a string to one or more IP addresses. | 923 | * Convert a string to one or more IP addresses. |
894 | * | 924 | * |
@@ -923,6 +953,8 @@ GNUNET_RESOLVER_ip_get (const char *hostname, | |||
923 | hostname); | 953 | hostname); |
924 | rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + slen); | 954 | rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + slen); |
925 | rh->af = af; | 955 | rh->af = af; |
956 | //rh->id = ++last_request_id; | ||
957 | rh->id = get_request_id (); | ||
926 | rh->addr_callback = callback; | 958 | rh->addr_callback = callback; |
927 | rh->cls = callback_cls; | 959 | rh->cls = callback_cls; |
928 | GNUNET_memcpy (&rh[1], | 960 | GNUNET_memcpy (&rh[1], |
@@ -1069,6 +1101,8 @@ GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa, | |||
1069 | rh->name_callback = callback; | 1101 | rh->name_callback = callback; |
1070 | rh->cls = cls; | 1102 | rh->cls = cls; |
1071 | rh->af = sa->sa_family; | 1103 | rh->af = sa->sa_family; |
1104 | //rh->id = ++last_request_id; | ||
1105 | rh->id = get_request_id (); | ||
1072 | rh->timeout = GNUNET_TIME_relative_to_absolute (timeout); | 1106 | rh->timeout = GNUNET_TIME_relative_to_absolute (timeout); |
1073 | GNUNET_memcpy (&rh[1], | 1107 | GNUNET_memcpy (&rh[1], |
1074 | ip, | 1108 | ip, |