diff options
-rw-r--r-- | src/arm/test_gnunet_service_arm.c | 14 | ||||
-rw-r--r-- | src/util/gnunet-service-resolver.c | 206 | ||||
-rw-r--r-- | src/util/resolver.h | 14 | ||||
-rw-r--r-- | src/util/resolver_api.c | 28 |
4 files changed, 185 insertions, 77 deletions
diff --git a/src/arm/test_gnunet_service_arm.c b/src/arm/test_gnunet_service_arm.c index 8b6d09bd9..fd5244ec2 100644 --- a/src/arm/test_gnunet_service_arm.c +++ b/src/arm/test_gnunet_service_arm.c | |||
@@ -112,7 +112,7 @@ hostname_resolve_cb (void *cls, | |||
112 | if (NULL == addr) | 112 | if (NULL == addr) |
113 | { | 113 | { |
114 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 114 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
115 | "Name not resolved!\n"); | 115 | "Failed to resolve our own hostname!\n"); |
116 | GNUNET_break (0); | 116 | GNUNET_break (0); |
117 | ret = 3; | 117 | ret = 3; |
118 | GNUNET_ARM_request_service_stop (arm, | 118 | GNUNET_ARM_request_service_stop (arm, |
@@ -200,7 +200,7 @@ main (int argc, char *av[]) | |||
200 | FPRINTF (stderr, | 200 | FPRINTF (stderr, |
201 | "%s", | 201 | "%s", |
202 | "Failed to determine my own hostname, testcase not run.\n"); | 202 | "Failed to determine my own hostname, testcase not run.\n"); |
203 | return 0; | 203 | return 77; |
204 | } | 204 | } |
205 | if ( (0 == strcmp (hostname, | 205 | if ( (0 == strcmp (hostname, |
206 | "localhost")) || | 206 | "localhost")) || |
@@ -210,6 +210,8 @@ main (int argc, char *av[]) | |||
210 | /* we cannot use 'localhost' as this would not trigger the | 210 | /* we cannot use 'localhost' as this would not trigger the |
211 | resolver service (see resolver_api.c); so in this case, | 211 | resolver service (see resolver_api.c); so in this case, |
212 | we fall back to (ab)using gnu.org. */ | 212 | we fall back to (ab)using gnu.org. */ |
213 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
214 | "Falling back to `www.gnu.org'\n"); | ||
213 | strcpy (hostname, | 215 | strcpy (hostname, |
214 | "www.gnu.org"); | 216 | "www.gnu.org"); |
215 | } | 217 | } |
@@ -224,7 +226,7 @@ main (int argc, char *av[]) | |||
224 | FPRINTF (stderr, | 226 | FPRINTF (stderr, |
225 | "Failed to resolve my hostname `%s', testcase not run.\n", | 227 | "Failed to resolve my hostname `%s', testcase not run.\n", |
226 | hostname); | 228 | hostname); |
227 | return 0; | 229 | return 77; |
228 | } | 230 | } |
229 | freeaddrinfo (ai); | 231 | freeaddrinfo (ai); |
230 | } | 232 | } |
@@ -240,7 +242,7 @@ main (int argc, char *av[]) | |||
240 | FPRINTF (stderr, | 242 | FPRINTF (stderr, |
241 | "Failed to resolve my hostname `%s', testcase not run.\n", | 243 | "Failed to resolve my hostname `%s', testcase not run.\n", |
242 | hostname); | 244 | hostname); |
243 | return 0; | 245 | return 77; |
244 | } | 246 | } |
245 | } | 247 | } |
246 | #elif HAVE_GETHOSTBYNAME | 248 | #elif HAVE_GETHOSTBYNAME |
@@ -253,13 +255,13 @@ main (int argc, char *av[]) | |||
253 | FPRINTF (stderr, | 255 | FPRINTF (stderr, |
254 | "Failed to resolve my hostname `%s', testcase not run.\n", | 256 | "Failed to resolve my hostname `%s', testcase not run.\n", |
255 | hostname); | 257 | hostname); |
256 | return 0; | 258 | return 77; |
257 | } | 259 | } |
258 | } | 260 | } |
259 | #else | 261 | #else |
260 | FPRINTF (stderr, | 262 | FPRINTF (stderr, |
261 | "libc fails to have resolver function, testcase not run.\n"); | 263 | "libc fails to have resolver function, testcase not run.\n"); |
262 | return 0; | 264 | return 77; |
263 | #endif | 265 | #endif |
264 | GNUNET_log_setup ("test-gnunet-service-arm", | 266 | GNUNET_log_setup ("test-gnunet-service-arm", |
265 | "WARNING", | 267 | "WARNING", |
diff --git a/src/util/gnunet-service-resolver.c b/src/util/gnunet-service-resolver.c index 90ed746b6..252408466 100644 --- a/src/util/gnunet-service-resolver.c +++ b/src/util/gnunet-service-resolver.c | |||
@@ -143,7 +143,7 @@ struct ActiveLookup | |||
143 | * Unique request ID of a client if a query for this hostname/record_type | 143 | * Unique request ID of a client if a query for this hostname/record_type |
144 | * is currently pending, undefined otherwise. | 144 | * is currently pending, undefined otherwise. |
145 | */ | 145 | */ |
146 | uint16_t request_id; | 146 | uint32_t client_request_id; |
147 | 147 | ||
148 | /** | 148 | /** |
149 | * Unique DNS request ID of a client if a query for this hostname/record_type | 149 | * Unique DNS request ID of a client if a query for this hostname/record_type |
@@ -180,10 +180,16 @@ static struct ActiveLookup *lookup_tail; | |||
180 | static struct GNUNET_DNSSTUB_Context *dnsstub_ctx; | 180 | static struct GNUNET_DNSSTUB_Context *dnsstub_ctx; |
181 | 181 | ||
182 | /** | 182 | /** |
183 | * My domain, to be appended to the hostname to get a FQDN. | ||
184 | */ | ||
185 | static char *my_domain; | ||
186 | |||
187 | /** | ||
183 | * How many entries do we have in #cache_head DLL? | 188 | * How many entries do we have in #cache_head DLL? |
184 | */ | 189 | */ |
185 | static unsigned int cache_size; | 190 | static unsigned int cache_size; |
186 | 191 | ||
192 | |||
187 | /** | 193 | /** |
188 | * Remove @a entry from cache. | 194 | * Remove @a entry from cache. |
189 | * | 195 | * |
@@ -262,6 +268,28 @@ extract_dns_server (const char* line, | |||
262 | 268 | ||
263 | 269 | ||
264 | /** | 270 | /** |
271 | * Find out if the configuration file line contains a string | ||
272 | * starting with "search ", and if so, return a copy of | ||
273 | * the machine's search domain. | ||
274 | * | ||
275 | * @param line line to parse | ||
276 | * @param line_len number of characters in @a line | ||
277 | * @return NULL if no nameserver is configured in this @a line | ||
278 | */ | ||
279 | static char * | ||
280 | extract_search_domain (const char* line, | ||
281 | size_t line_len) | ||
282 | { | ||
283 | if (0 == strncmp (line, | ||
284 | "search ", | ||
285 | strlen ("search "))) | ||
286 | return GNUNET_strndup (line + strlen ("search "), | ||
287 | line_len - strlen ("search ")); | ||
288 | return NULL; | ||
289 | } | ||
290 | |||
291 | |||
292 | /** | ||
265 | * Reads the list of nameservers from /etc/resolve.conf | 293 | * Reads the list of nameservers from /etc/resolve.conf |
266 | * | 294 | * |
267 | * @param server_addrs[out] a list of null-terminated server address strings | 295 | * @param server_addrs[out] a list of null-terminated server address strings |
@@ -306,9 +334,16 @@ lookup_dns_servers (char ***server_addrs) | |||
306 | dns_server = extract_dns_server (buf + read_offset, | 334 | dns_server = extract_dns_server (buf + read_offset, |
307 | line_len); | 335 | line_len); |
308 | if (NULL != dns_server) | 336 | if (NULL != dns_server) |
337 | { | ||
309 | GNUNET_array_append (*server_addrs, | 338 | GNUNET_array_append (*server_addrs, |
310 | num_dns_servers, | 339 | num_dns_servers, |
311 | dns_server); | 340 | dns_server); |
341 | } | ||
342 | else if (NULL == my_domain) | ||
343 | { | ||
344 | my_domain = extract_search_domain (buf + read_offset, | ||
345 | line_len); | ||
346 | } | ||
312 | read_offset += line_len + 1; | 347 | read_offset += line_len + 1; |
313 | } | 348 | } |
314 | GNUNET_DISK_file_close (fh); | 349 | GNUNET_DISK_file_close (fh); |
@@ -392,7 +427,7 @@ make_reverse_hostname (const void *ip, | |||
392 | * | 427 | * |
393 | * @param record information to transmit | 428 | * @param record information to transmit |
394 | * @param record_type requested record type from client | 429 | * @param record_type requested record type from client |
395 | * @param request_id to which request are we responding | 430 | * @param client_request_id to which request are we responding |
396 | * @param client where to send @a record | 431 | * @param client where to send @a record |
397 | * @return #GNUNET_YES if we sent a reply, | 432 | * @return #GNUNET_YES if we sent a reply, |
398 | * #GNUNET_NO if the record type is not understood or | 433 | * #GNUNET_NO if the record type is not understood or |
@@ -401,7 +436,7 @@ make_reverse_hostname (const void *ip, | |||
401 | static int | 436 | static int |
402 | send_reply (struct GNUNET_DNSPARSER_Record *record, | 437 | send_reply (struct GNUNET_DNSPARSER_Record *record, |
403 | uint16_t record_type, | 438 | uint16_t record_type, |
404 | uint16_t request_id, | 439 | uint32_t client_request_id, |
405 | struct GNUNET_SERVICE_Client *client) | 440 | struct GNUNET_SERVICE_Client *client) |
406 | { | 441 | { |
407 | struct GNUNET_RESOLVER_ResponseMessage *msg; | 442 | struct GNUNET_RESOLVER_ResponseMessage *msg; |
@@ -446,7 +481,7 @@ send_reply (struct GNUNET_DNSPARSER_Record *record, | |||
446 | env = GNUNET_MQ_msg_extra (msg, | 481 | env = GNUNET_MQ_msg_extra (msg, |
447 | payload_len, | 482 | payload_len, |
448 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); | 483 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); |
449 | msg->id = request_id; | 484 | msg->client_id = client_request_id; |
450 | GNUNET_memcpy (&msg[1], | 485 | GNUNET_memcpy (&msg[1], |
451 | payload, | 486 | payload, |
452 | payload_len); | 487 | payload_len); |
@@ -458,13 +493,13 @@ send_reply (struct GNUNET_DNSPARSER_Record *record, | |||
458 | 493 | ||
459 | /** | 494 | /** |
460 | * Send message to @a client that we transmitted all | 495 | * Send message to @a client that we transmitted all |
461 | * responses for @a request_id | 496 | * responses for @a client_request_id |
462 | * | 497 | * |
463 | * @param request_id to which request are we responding | 498 | * @param client_request_id to which request are we responding |
464 | * @param client where to send @a record | 499 | * @param client where to send @a record |
465 | */ | 500 | */ |
466 | static void | 501 | static void |
467 | send_end_msg (uint16_t request_id, | 502 | send_end_msg (uint32_t client_request_id, |
468 | struct GNUNET_SERVICE_Client *client) | 503 | struct GNUNET_SERVICE_Client *client) |
469 | { | 504 | { |
470 | struct GNUNET_RESOLVER_ResponseMessage *msg; | 505 | struct GNUNET_RESOLVER_ResponseMessage *msg; |
@@ -474,7 +509,7 @@ send_end_msg (uint16_t request_id, | |||
474 | "Sending END message\n"); | 509 | "Sending END message\n"); |
475 | env = GNUNET_MQ_msg (msg, | 510 | env = GNUNET_MQ_msg (msg, |
476 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); | 511 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); |
477 | msg->id = request_id; | 512 | msg->client_id = client_request_id; |
478 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), | 513 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), |
479 | env); | 514 | env); |
480 | } | 515 | } |
@@ -518,13 +553,13 @@ remove_expired (struct ResolveCache *rc) | |||
518 | * | 553 | * |
519 | * @param hostname DNS name to resolve | 554 | * @param hostname DNS name to resolve |
520 | * @param record_type desired record type | 555 | * @param record_type desired record type |
521 | * @param request_id client's request ID | 556 | * @param client_request_id client's request ID |
522 | * @param client who should get the result? | 557 | * @param client who should get the result? |
523 | */ | 558 | */ |
524 | static void | 559 | static void |
525 | process_get (const char *hostname, | 560 | process_get (const char *hostname, |
526 | uint16_t record_type, | 561 | uint16_t record_type, |
527 | uint16_t request_id, | 562 | uint32_t client_request_id, |
528 | struct GNUNET_SERVICE_Client *client); | 563 | struct GNUNET_SERVICE_Client *client); |
529 | 564 | ||
530 | 565 | ||
@@ -536,13 +571,13 @@ process_get (const char *hostname, | |||
536 | * | 571 | * |
537 | * @param hostname what hostname was to be resolved | 572 | * @param hostname what hostname was to be resolved |
538 | * @param record_type what type of record was requested | 573 | * @param record_type what type of record was requested |
539 | * @param request_id unique identification of the client's request | 574 | * @param client_request_id unique identification of the client's request |
540 | * @param client handle to the client making the request (for sending the reply) | 575 | * @param client handle to the client making the request (for sending the reply) |
541 | */ | 576 | */ |
542 | static int | 577 | static int |
543 | try_cache (const char *hostname, | 578 | try_cache (const char *hostname, |
544 | uint16_t record_type, | 579 | uint16_t record_type, |
545 | uint16_t request_id, | 580 | uint32_t client_request_id, |
546 | struct GNUNET_SERVICE_Client *client) | 581 | struct GNUNET_SERVICE_Client *client) |
547 | { | 582 | { |
548 | struct ResolveCache *pos; | 583 | struct ResolveCache *pos; |
@@ -595,18 +630,18 @@ try_cache (const char *hostname, | |||
595 | 630 | ||
596 | process_get (hostname, | 631 | process_get (hostname, |
597 | record_type, | 632 | record_type, |
598 | request_id, | 633 | client_request_id, |
599 | client); | 634 | client); |
600 | return GNUNET_YES; /* counts as a cache "hit" */ | 635 | return GNUNET_YES; /* counts as a cache "hit" */ |
601 | } | 636 | } |
602 | found |= send_reply (rle->record, | 637 | found |= send_reply (rle->record, |
603 | record_type, | 638 | record_type, |
604 | request_id, | 639 | client_request_id, |
605 | client); | 640 | client); |
606 | } | 641 | } |
607 | if (GNUNET_NO == found) | 642 | if (GNUNET_NO == found) |
608 | return GNUNET_NO; /* had records, but none matched! */ | 643 | return GNUNET_NO; /* had records, but none matched! */ |
609 | send_end_msg (request_id, | 644 | send_end_msg (client_request_id, |
610 | client); | 645 | client); |
611 | return GNUNET_YES; | 646 | return GNUNET_YES; |
612 | } | 647 | } |
@@ -693,14 +728,14 @@ handle_resolve_result (void *cls, | |||
693 | GNUNET_DNSPARSER_free_packet (parsed); | 728 | GNUNET_DNSPARSER_free_packet (parsed); |
694 | return; | 729 | return; |
695 | } | 730 | } |
696 | if (0 == parsed->num_answers) | 731 | if (0 == parsed->num_answers + parsed->num_authority_records + parsed->num_additional_records) |
697 | { | 732 | { |
698 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 733 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
699 | "DNS reply (hostname %s, request ID %u) contains no answers\n", | 734 | "DNS reply (hostname %s, request ID %u) contains no answers\n", |
700 | al->hostname, | 735 | al->hostname, |
701 | al->request_id); | 736 | (unsigned int) al->client_request_id); |
702 | GNUNET_DNSPARSER_free_packet (parsed); | 737 | GNUNET_DNSPARSER_free_packet (parsed); |
703 | send_end_msg (al->request_id, | 738 | send_end_msg (al->client_request_id, |
704 | al->client); | 739 | al->client); |
705 | free_active_lookup (al); | 740 | free_active_lookup (al); |
706 | return; | 741 | return; |
@@ -712,7 +747,7 @@ handle_resolve_result (void *cls, | |||
712 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 747 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
713 | "Got reply for hostname %s and request ID %u\n", | 748 | "Got reply for hostname %s and request ID %u\n", |
714 | al->hostname, | 749 | al->hostname, |
715 | al->request_id); | 750 | (unsigned int) al->client_request_id); |
716 | /* add to cache */ | 751 | /* add to cache */ |
717 | for (unsigned int i = 0; i != parsed->num_answers; i++) | 752 | for (unsigned int i = 0; i != parsed->num_answers; i++) |
718 | { | 753 | { |
@@ -740,6 +775,58 @@ handle_resolve_result (void *cls, | |||
740 | rc->records_tail, | 775 | rc->records_tail, |
741 | rle); | 776 | rle); |
742 | } | 777 | } |
778 | for (unsigned int i = 0; i != parsed->num_authority_records; i++) | ||
779 | { | ||
780 | struct GNUNET_DNSPARSER_Record *record = &parsed->authority_records[i]; | ||
781 | struct RecordListEntry *rle; | ||
782 | |||
783 | for (rc = cache_head; NULL != rc; rc = rc->next) | ||
784 | if (0 == strcasecmp (rc->hostname, | ||
785 | record->name)) | ||
786 | break; | ||
787 | if (NULL == rc) | ||
788 | { | ||
789 | rc = GNUNET_new (struct ResolveCache); | ||
790 | rc->hostname = GNUNET_strdup (record->name); | ||
791 | GNUNET_CONTAINER_DLL_insert (cache_head, | ||
792 | cache_tail, | ||
793 | rc); | ||
794 | cache_size++; | ||
795 | } | ||
796 | /* TODO: ought to check first if we have this exact record | ||
797 | already in the cache! */ | ||
798 | rle = GNUNET_new (struct RecordListEntry); | ||
799 | rle->record = GNUNET_DNSPARSER_duplicate_record (record); | ||
800 | GNUNET_CONTAINER_DLL_insert (rc->records_head, | ||
801 | rc->records_tail, | ||
802 | rle); | ||
803 | } | ||
804 | for (unsigned int i = 0; i != parsed->num_additional_records; i++) | ||
805 | { | ||
806 | struct GNUNET_DNSPARSER_Record *record = &parsed->additional_records[i]; | ||
807 | struct RecordListEntry *rle; | ||
808 | |||
809 | for (rc = cache_head; NULL != rc; rc = rc->next) | ||
810 | if (0 == strcasecmp (rc->hostname, | ||
811 | record->name)) | ||
812 | break; | ||
813 | if (NULL == rc) | ||
814 | { | ||
815 | rc = GNUNET_new (struct ResolveCache); | ||
816 | rc->hostname = GNUNET_strdup (record->name); | ||
817 | GNUNET_CONTAINER_DLL_insert (cache_head, | ||
818 | cache_tail, | ||
819 | rc); | ||
820 | cache_size++; | ||
821 | } | ||
822 | /* TODO: ought to check first if we have this exact record | ||
823 | already in the cache! */ | ||
824 | rle = GNUNET_new (struct RecordListEntry); | ||
825 | rle->record = GNUNET_DNSPARSER_duplicate_record (record); | ||
826 | GNUNET_CONTAINER_DLL_insert (rc->records_head, | ||
827 | rc->records_tail, | ||
828 | rle); | ||
829 | } | ||
743 | /* see if we need to do the 2nd request for AAAA records */ | 830 | /* see if we need to do the 2nd request for AAAA records */ |
744 | if ( (GNUNET_DNSPARSER_TYPE_ALL == al->record_type) && | 831 | if ( (GNUNET_DNSPARSER_TYPE_ALL == al->record_type) && |
745 | (GNUNET_NO == al->did_aaaa) ) | 832 | (GNUNET_NO == al->did_aaaa) ) |
@@ -774,11 +861,13 @@ handle_resolve_result (void *cls, | |||
774 | if (GNUNET_NO == | 861 | if (GNUNET_NO == |
775 | try_cache (al->hostname, | 862 | try_cache (al->hostname, |
776 | al->record_type, | 863 | al->record_type, |
777 | al->request_id, | 864 | al->client_request_id, |
778 | al->client)) | 865 | al->client)) |
779 | /* cache failed, tell client we could not get an answer */ | 866 | /* cache failed, tell client we could not get an answer */ |
780 | send_end_msg (al->request_id, | 867 | { |
868 | send_end_msg (al->client_request_id, | ||
781 | al->client); | 869 | al->client); |
870 | } | ||
782 | free_active_lookup (al); | 871 | free_active_lookup (al); |
783 | GNUNET_DNSPARSER_free_packet (parsed); | 872 | GNUNET_DNSPARSER_free_packet (parsed); |
784 | } | 873 | } |
@@ -798,7 +887,7 @@ handle_resolve_timeout (void *cls) | |||
798 | al->timeout_task = NULL; | 887 | al->timeout_task = NULL; |
799 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 888 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
800 | "DNS lookup timeout!\n"); | 889 | "DNS lookup timeout!\n"); |
801 | send_end_msg (al->request_id, | 890 | send_end_msg (al->client_request_id, |
802 | al->client); | 891 | al->client); |
803 | free_active_lookup (al); | 892 | free_active_lookup (al); |
804 | } | 893 | } |
@@ -810,14 +899,14 @@ handle_resolve_timeout (void *cls) | |||
810 | * | 899 | * |
811 | * @param hostname DNS name to resolve | 900 | * @param hostname DNS name to resolve |
812 | * @param record_type record type to locate | 901 | * @param record_type record type to locate |
813 | * @param request_id client request ID | 902 | * @param client_request_id client request ID |
814 | * @param client handle to the client | 903 | * @param client handle to the client |
815 | * @return #GNUNET_OK if the DNS query is now pending | 904 | * @return #GNUNET_OK if the DNS query is now pending |
816 | */ | 905 | */ |
817 | static int | 906 | static int |
818 | resolve_and_cache (const char* hostname, | 907 | resolve_and_cache (const char* hostname, |
819 | uint16_t record_type, | 908 | uint16_t record_type, |
820 | uint16_t request_id, | 909 | uint32_t client_request_id, |
821 | struct GNUNET_SERVICE_Client *client) | 910 | struct GNUNET_SERVICE_Client *client) |
822 | { | 911 | { |
823 | char *packet_buf; | 912 | char *packet_buf; |
@@ -827,7 +916,8 @@ resolve_and_cache (const char* hostname, | |||
827 | uint16_t type; | 916 | uint16_t type; |
828 | 917 | ||
829 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 918 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
830 | "resolve_and_cache\n"); | 919 | "resolve_and_cache `%s'\n", |
920 | hostname); | ||
831 | dns_id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, | 921 | dns_id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, |
832 | UINT16_MAX); | 922 | UINT16_MAX); |
833 | 923 | ||
@@ -851,7 +941,7 @@ resolve_and_cache (const char* hostname, | |||
851 | al = GNUNET_new (struct ActiveLookup); | 941 | al = GNUNET_new (struct ActiveLookup); |
852 | al->hostname = GNUNET_strdup (hostname); | 942 | al->hostname = GNUNET_strdup (hostname); |
853 | al->record_type = record_type; | 943 | al->record_type = record_type; |
854 | al->request_id = request_id; | 944 | al->client_request_id = client_request_id; |
855 | al->dns_id = dns_id; | 945 | al->dns_id = dns_id; |
856 | al->client = client; | 946 | al->client = client; |
857 | al->timeout_task = GNUNET_SCHEDULER_add_delayed (DNS_TIMEOUT, | 947 | al->timeout_task = GNUNET_SCHEDULER_add_delayed (DNS_TIMEOUT, |
@@ -868,42 +958,68 @@ resolve_and_cache (const char* hostname, | |||
868 | lookup_tail, | 958 | lookup_tail, |
869 | al); | 959 | al); |
870 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 960 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
871 | "Resolving %s, request_id = %u, dns_id = %u\n", | 961 | "Resolving %s, client_request_id = %u, dns_id = %u\n", |
872 | hostname, | 962 | hostname, |
873 | (unsigned int) request_id, | 963 | (unsigned int) client_request_id, |
874 | (unsigned int) dns_id); | 964 | (unsigned int) dns_id); |
875 | return GNUNET_OK; | 965 | return GNUNET_OK; |
876 | } | 966 | } |
877 | 967 | ||
878 | 968 | ||
879 | /** | 969 | /** |
880 | * Process DNS request for @a hostname with request ID @a request_id | 970 | * Process DNS request for @a hostname with request ID @a client_request_id |
881 | * from @a client demanding records of type @a record_type. | 971 | * from @a client demanding records of type @a record_type. |
882 | * | 972 | * |
883 | * @param hostname DNS name to resolve | 973 | * @param hostname DNS name to resolve |
884 | * @param record_type desired record type | 974 | * @param record_type desired record type |
885 | * @param request_id client's request ID | 975 | * @param client_request_id client's request ID |
886 | * @param client who should get the result? | 976 | * @param client who should get the result? |
887 | */ | 977 | */ |
888 | static void | 978 | static void |
889 | process_get (const char *hostname, | 979 | process_get (const char *hostname, |
890 | uint16_t record_type, | 980 | uint16_t record_type, |
891 | uint16_t request_id, | 981 | uint32_t client_request_id, |
892 | struct GNUNET_SERVICE_Client *client) | 982 | struct GNUNET_SERVICE_Client *client) |
893 | { | 983 | { |
984 | char fqdn[255]; | ||
985 | |||
986 | if ( (NULL != my_domain) && | ||
987 | (NULL == strchr (hostname, | ||
988 | (unsigned char) '.')) && | ||
989 | (strlen (hostname) + strlen (my_domain) <= 253) ) | ||
990 | { | ||
991 | GNUNET_snprintf (fqdn, | ||
992 | sizeof (fqdn), | ||
993 | "%s.%s", | ||
994 | hostname, | ||
995 | my_domain); | ||
996 | } | ||
997 | else if (strlen (hostname) < 255) | ||
998 | { | ||
999 | GNUNET_snprintf (fqdn, | ||
1000 | sizeof (fqdn), | ||
1001 | "%s", | ||
1002 | hostname); | ||
1003 | } | ||
1004 | else | ||
1005 | { | ||
1006 | GNUNET_break (0); | ||
1007 | GNUNET_SERVICE_client_drop (client); | ||
1008 | return; | ||
1009 | } | ||
894 | if (GNUNET_NO == | 1010 | if (GNUNET_NO == |
895 | try_cache (hostname, | 1011 | try_cache (fqdn, |
896 | record_type, | 1012 | record_type, |
897 | request_id, | 1013 | client_request_id, |
898 | client)) | 1014 | client)) |
899 | { | 1015 | { |
900 | if (GNUNET_OK != | 1016 | if (GNUNET_OK != |
901 | resolve_and_cache (hostname, | 1017 | resolve_and_cache (fqdn, |
902 | record_type, | 1018 | record_type, |
903 | request_id, | 1019 | client_request_id, |
904 | client)) | 1020 | client)) |
905 | { | 1021 | { |
906 | send_end_msg (request_id, | 1022 | send_end_msg (client_request_id, |
907 | client); | 1023 | client); |
908 | } | 1024 | } |
909 | } | 1025 | } |
@@ -979,12 +1095,13 @@ handle_get (void *cls, | |||
979 | struct GNUNET_SERVICE_Client *client = cls; | 1095 | struct GNUNET_SERVICE_Client *client = cls; |
980 | int direction; | 1096 | int direction; |
981 | int af; | 1097 | int af; |
982 | uint16_t request_id; | 1098 | uint32_t client_request_id; |
983 | char *hostname; | 1099 | char *hostname; |
984 | 1100 | ||
985 | direction = ntohl (msg->direction); | 1101 | direction = ntohl (msg->direction); |
986 | af = ntohl (msg->af); | 1102 | af = ntohl (msg->af); |
987 | request_id = ntohs (msg->id); | 1103 | client_request_id = msg->client_id; |
1104 | GNUNET_SERVICE_client_continue (client); | ||
988 | if (GNUNET_NO == direction) | 1105 | if (GNUNET_NO == direction) |
989 | { | 1106 | { |
990 | /* IP from hostname */ | 1107 | /* IP from hostname */ |
@@ -995,7 +1112,7 @@ handle_get (void *cls, | |||
995 | { | 1112 | { |
996 | process_get (hostname, | 1113 | process_get (hostname, |
997 | GNUNET_DNSPARSER_TYPE_ALL, | 1114 | GNUNET_DNSPARSER_TYPE_ALL, |
998 | request_id, | 1115 | client_request_id, |
999 | client); | 1116 | client); |
1000 | break; | 1117 | break; |
1001 | } | 1118 | } |
@@ -1003,7 +1120,7 @@ handle_get (void *cls, | |||
1003 | { | 1120 | { |
1004 | process_get (hostname, | 1121 | process_get (hostname, |
1005 | GNUNET_DNSPARSER_TYPE_A, | 1122 | GNUNET_DNSPARSER_TYPE_A, |
1006 | request_id, | 1123 | client_request_id, |
1007 | client); | 1124 | client); |
1008 | break; | 1125 | break; |
1009 | } | 1126 | } |
@@ -1011,15 +1128,15 @@ handle_get (void *cls, | |||
1011 | { | 1128 | { |
1012 | process_get (hostname, | 1129 | process_get (hostname, |
1013 | GNUNET_DNSPARSER_TYPE_AAAA, | 1130 | GNUNET_DNSPARSER_TYPE_AAAA, |
1014 | request_id, | 1131 | client_request_id, |
1015 | client); | 1132 | client); |
1016 | break; | 1133 | break; |
1017 | } | 1134 | } |
1018 | default: | 1135 | default: |
1019 | { | 1136 | { |
1020 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1137 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1021 | "got invalid af: %d\n", | 1138 | "got invalid af: %d\n", |
1022 | af); | 1139 | af); |
1023 | GNUNET_assert (0); | 1140 | GNUNET_assert (0); |
1024 | } | 1141 | } |
1025 | } | 1142 | } |
@@ -1031,11 +1148,10 @@ handle_get (void *cls, | |||
1031 | af); | 1148 | af); |
1032 | process_get (hostname, | 1149 | process_get (hostname, |
1033 | GNUNET_DNSPARSER_TYPE_PTR, | 1150 | GNUNET_DNSPARSER_TYPE_PTR, |
1034 | request_id, | 1151 | client_request_id, |
1035 | client); | 1152 | client); |
1036 | } | 1153 | } |
1037 | GNUNET_free_non_null (hostname); | 1154 | GNUNET_free_non_null (hostname); |
1038 | GNUNET_SERVICE_client_continue (client); | ||
1039 | } | 1155 | } |
1040 | 1156 | ||
1041 | 1157 | ||
diff --git a/src/util/resolver.h b/src/util/resolver.h index 07851d052..54a1cf5fd 100644 --- a/src/util/resolver.h +++ b/src/util/resolver.h | |||
@@ -41,7 +41,7 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
41 | struct GNUNET_RESOLVER_GetMessage | 41 | struct GNUNET_RESOLVER_GetMessage |
42 | { | 42 | { |
43 | /** | 43 | /** |
44 | * Type: GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST | 44 | * Type: #GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST |
45 | */ | 45 | */ |
46 | struct GNUNET_MessageHeader header; | 46 | struct GNUNET_MessageHeader header; |
47 | 47 | ||
@@ -60,7 +60,7 @@ struct GNUNET_RESOLVER_GetMessage | |||
60 | * identifies the request and is contained in the response message. The | 60 | * identifies the request and is contained in the response message. The |
61 | * client has to match response to request by this identifier. | 61 | * client has to match response to request by this identifier. |
62 | */ | 62 | */ |
63 | uint16_t id GNUNET_PACKED; | 63 | uint32_t client_id GNUNET_PACKED; |
64 | 64 | ||
65 | /* followed by 0-terminated string for A/AAAA-lookup or | 65 | /* followed by 0-terminated string for A/AAAA-lookup or |
66 | by 'struct in_addr' / 'struct in6_addr' for reverse lookup */ | 66 | by 'struct in_addr' / 'struct in6_addr' for reverse lookup */ |
@@ -71,15 +71,15 @@ struct GNUNET_RESOLVER_GetMessage | |||
71 | struct GNUNET_RESOLVER_ResponseMessage | 71 | struct GNUNET_RESOLVER_ResponseMessage |
72 | { | 72 | { |
73 | /** | 73 | /** |
74 | * Type: GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE | 74 | * Type: #GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE |
75 | */ | 75 | */ |
76 | struct GNUNET_MessageHeader header; | 76 | struct GNUNET_MessageHeader header; |
77 | 77 | ||
78 | /** | 78 | /** |
79 | * identifies the request this message responds to. The client | 79 | * identifies the request this message responds to. The client |
80 | * has to match response to request by this identifier. | 80 | * has to match response to request by this identifier. |
81 | */ | 81 | */ |
82 | uint16_t id GNUNET_PACKED; | 82 | uint32_t client_id GNUNET_PACKED; |
83 | 83 | ||
84 | /* followed by 0-terminated string for response to a reverse lookup | 84 | /* followed by 0-terminated string for response to a reverse lookup |
85 | * or by 'struct in_addr' / 'struct in6_addr' for response to | 85 | * or by 'struct in_addr' / 'struct in6_addr' for response to |
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c index 8a054327b..871eeb4bf 100644 --- a/src/util/resolver_api.c +++ b/src/util/resolver_api.c | |||
@@ -68,10 +68,10 @@ static struct GNUNET_RESOLVER_RequestHandle *req_head; | |||
68 | */ | 68 | */ |
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 | 72 | * ID of the last request we sent to the service |
73 | // */ | 73 | */ |
74 | //static uint16_t last_request_id; | 74 | static uint32_t last_request_id; |
75 | 75 | ||
76 | /** | 76 | /** |
77 | * How long should we wait to reconnect? | 77 | * How long should we wait to reconnect? |
@@ -445,7 +445,7 @@ process_requests () | |||
445 | GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST); | 445 | GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST); |
446 | msg->direction = htonl (rh->direction); | 446 | msg->direction = htonl (rh->direction); |
447 | msg->af = htonl (rh->af); | 447 | msg->af = htonl (rh->af); |
448 | msg->id = htons (rh->id); | 448 | msg->client_id = rh->id; |
449 | GNUNET_memcpy (&msg[1], | 449 | GNUNET_memcpy (&msg[1], |
450 | &rh[1], | 450 | &rh[1], |
451 | rh->data_len); | 451 | rh->data_len); |
@@ -491,11 +491,11 @@ handle_response (void *cls, | |||
491 | struct GNUNET_RESOLVER_RequestHandle *rh = req_head; | 491 | struct GNUNET_RESOLVER_RequestHandle *rh = req_head; |
492 | uint16_t size; | 492 | uint16_t size; |
493 | char *nret; | 493 | char *nret; |
494 | uint16_t request_id = msg->id; | 494 | uint32_t client_request_id = msg->client_id; |
495 | 495 | ||
496 | for (; rh != NULL; rh = rh->next) | 496 | for (; rh != NULL; rh = rh->next) |
497 | { | 497 | { |
498 | if (rh->id == request_id) | 498 | if (rh->id == client_request_id) |
499 | break; | 499 | break; |
500 | } | 500 | } |
501 | 501 | ||
@@ -911,14 +911,6 @@ handle_lookup_timeout (void *cls) | |||
911 | } | 911 | } |
912 | 912 | ||
913 | 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 | |||
922 | /** | 914 | /** |
923 | * Convert a string to one or more IP addresses. | 915 | * Convert a string to one or more IP addresses. |
924 | * | 916 | * |
@@ -953,8 +945,7 @@ GNUNET_RESOLVER_ip_get (const char *hostname, | |||
953 | hostname); | 945 | hostname); |
954 | rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + slen); | 946 | rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + slen); |
955 | rh->af = af; | 947 | rh->af = af; |
956 | //rh->id = ++last_request_id; | 948 | rh->id = ++last_request_id; |
957 | rh->id = get_request_id (); | ||
958 | rh->addr_callback = callback; | 949 | rh->addr_callback = callback; |
959 | rh->cls = callback_cls; | 950 | rh->cls = callback_cls; |
960 | GNUNET_memcpy (&rh[1], | 951 | GNUNET_memcpy (&rh[1], |
@@ -1101,8 +1092,7 @@ GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa, | |||
1101 | rh->name_callback = callback; | 1092 | rh->name_callback = callback; |
1102 | rh->cls = cls; | 1093 | rh->cls = cls; |
1103 | rh->af = sa->sa_family; | 1094 | rh->af = sa->sa_family; |
1104 | //rh->id = ++last_request_id; | 1095 | rh->id = ++last_request_id; |
1105 | rh->id = get_request_id (); | ||
1106 | rh->timeout = GNUNET_TIME_relative_to_absolute (timeout); | 1096 | rh->timeout = GNUNET_TIME_relative_to_absolute (timeout); |
1107 | GNUNET_memcpy (&rh[1], | 1097 | GNUNET_memcpy (&rh[1], |
1108 | ip, | 1098 | ip, |