aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-02-12 20:35:50 +0000
committerChristian Grothoff <christian@grothoff.org>2015-02-12 20:35:50 +0000
commit69b02446b5e358d37a6863d8fc45d5f90bbdea67 (patch)
tree1ac52c44b0f577899a30dc2240be058c647f38ca
parent2ca8668b12b792ad9ffbffa17088b22d008c709b (diff)
downloadgnunet-69b02446b5e358d37a6863d8fc45d5f90bbdea67.tar.gz
gnunet-69b02446b5e358d37a6863d8fc45d5f90bbdea67.zip
-fix callback after cancellation issue
-rw-r--r--src/util/resolver_api.c118
1 files changed, 74 insertions, 44 deletions
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c
index d1ec4e5c9..103634bbb 100644
--- a/src/util/resolver_api.c
+++ b/src/util/resolver_api.c
@@ -375,15 +375,16 @@ handle_response (void *cls,
375 GNUNET_free (nret); 375 GNUNET_free (nret);
376 } 376 }
377 /* finally, make termination call */ 377 /* finally, make termination call */
378 rh->name_callback (rh->cls, NULL); 378 rh->name_callback (rh->cls,
379 NULL);
379 } 380 }
380 if (NULL != rh->addr_callback) 381 if (NULL != rh->addr_callback)
381 rh->addr_callback (rh->cls, NULL, 0); 382 rh->addr_callback (rh->cls,
383 NULL,
384 0);
382 } 385 }
383 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh); 386 rh->was_transmitted = GNUNET_NO;
384 if (NULL != rh->task) 387 GNUNET_RESOLVER_request_cancel (rh);
385 GNUNET_SCHEDULER_cancel (rh->task);
386 GNUNET_free (rh);
387 GNUNET_CLIENT_disconnect (client); 388 GNUNET_CLIENT_disconnect (client);
388 client = NULL; 389 client = NULL;
389 reconnect (); 390 reconnect ();
@@ -405,14 +406,15 @@ handle_response (void *cls,
405 if (GNUNET_SYSERR != rh->was_transmitted) 406 if (GNUNET_SYSERR != rh->was_transmitted)
406 { 407 {
407 if (NULL != rh->name_callback) 408 if (NULL != rh->name_callback)
408 rh->name_callback (rh->cls, NULL); 409 rh->name_callback (rh->cls,
410 NULL);
409 if (NULL != rh->addr_callback) 411 if (NULL != rh->addr_callback)
410 rh->addr_callback (rh->cls, NULL, 0); 412 rh->addr_callback (rh->cls,
413 NULL,
414 0);
411 } 415 }
412 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh); 416 rh->was_transmitted = GNUNET_NO;
413 if (NULL != rh->task) 417 GNUNET_RESOLVER_request_cancel (rh);
414 GNUNET_SCHEDULER_cancel (rh->task);
415 GNUNET_free (rh);
416 process_requests (); 418 process_requests ();
417 return; 419 return;
418 } 420 }
@@ -426,11 +428,10 @@ handle_response (void *cls,
426 { 428 {
427 GNUNET_break (0); 429 GNUNET_break (0);
428 if (GNUNET_SYSERR != rh->was_transmitted) 430 if (GNUNET_SYSERR != rh->was_transmitted)
429 rh->name_callback (rh->cls, NULL); 431 rh->name_callback (rh->cls,
430 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh); 432 NULL);
431 if (NULL != rh->task) 433 rh->was_transmitted = GNUNET_NO;
432 GNUNET_SCHEDULER_cancel (rh->task); 434 GNUNET_RESOLVER_request_cancel (rh);
433 GNUNET_free (rh);
434 GNUNET_CLIENT_disconnect (client); 435 GNUNET_CLIENT_disconnect (client);
435 client = NULL; 436 client = NULL;
436 reconnect (); 437 reconnect ();
@@ -442,7 +443,8 @@ handle_response (void *cls,
442 GNUNET_a2s ((const void *) &rh[1], 443 GNUNET_a2s ((const void *) &rh[1],
443 rh->data_len)); 444 rh->data_len));
444 if (rh->was_transmitted != GNUNET_SYSERR) 445 if (rh->was_transmitted != GNUNET_SYSERR)
445 rh->name_callback (rh->cls, hostname); 446 rh->name_callback (rh->cls,
447 hostname);
446 rh->received_response = GNUNET_YES; 448 rh->received_response = GNUNET_YES;
447 } 449 }
448 /* return lookup results to caller */ 450 /* return lookup results to caller */
@@ -483,17 +485,20 @@ handle_response (void *cls,
483 { 485 {
484 GNUNET_break (0); 486 GNUNET_break (0);
485 if (GNUNET_SYSERR != rh->was_transmitted) 487 if (GNUNET_SYSERR != rh->was_transmitted)
486 rh->addr_callback (rh->cls, NULL, 0); 488 rh->addr_callback (rh->cls,
487 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh); 489 NULL,
488 if (NULL != rh->task) 490 0);
489 GNUNET_SCHEDULER_cancel (rh->task); 491 rh->was_transmitted = GNUNET_NO;
490 GNUNET_free (rh); 492 GNUNET_RESOLVER_request_cancel (rh);
491 GNUNET_CLIENT_disconnect (client); 493 GNUNET_CLIENT_disconnect (client);
492 client = NULL; 494 client = NULL;
493 reconnect (); 495 reconnect ();
494 return; 496 return;
495 } 497 }
496 rh->addr_callback (rh->cls, sa, salen); 498 if (GNUNET_SYSERR != rh->was_transmitted)
499 rh->addr_callback (rh->cls,
500 sa,
501 salen);
497 } 502 }
498 GNUNET_CLIENT_receive (client, 503 GNUNET_CLIENT_receive (client,
499 &handle_response, 504 &handle_response,
@@ -545,7 +550,9 @@ numeric_resolution (void *cls,
545 (const struct sockaddr *) &v6, 550 (const struct sockaddr *) &v6,
546 sizeof (v6)); 551 sizeof (v6));
547 } 552 }
548 rh->addr_callback (rh->cls, NULL, 0); 553 rh->addr_callback (rh->cls,
554 NULL,
555 0);
549 GNUNET_free (rh); 556 GNUNET_free (rh);
550 return; 557 return;
551 } 558 }
@@ -556,7 +563,9 @@ numeric_resolution (void *cls,
556 rh->addr_callback (rh->cls, 563 rh->addr_callback (rh->cls,
557 (const struct sockaddr *) &v6, 564 (const struct sockaddr *) &v6,
558 sizeof (v6)); 565 sizeof (v6));
559 rh->addr_callback (rh->cls, NULL, 0); 566 rh->addr_callback (rh->cls,
567 NULL,
568 0);
560 GNUNET_free (rh); 569 GNUNET_free (rh);
561 return; 570 return;
562 } 571 }
@@ -598,14 +607,22 @@ loopback_resolution (void *cls,
598 switch (rh->af) 607 switch (rh->af)
599 { 608 {
600 case AF_INET: 609 case AF_INET:
601 rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4)); 610 rh->addr_callback (rh->cls,
611 (const struct sockaddr *) &v4,
612 sizeof (v4));
602 break; 613 break;
603 case AF_INET6: 614 case AF_INET6:
604 rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6)); 615 rh->addr_callback (rh->cls,
616 (const struct sockaddr *) &v6,
617 sizeof (v6));
605 break; 618 break;
606 case AF_UNSPEC: 619 case AF_UNSPEC:
607 rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6)); 620 rh->addr_callback (rh->cls,
608 rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4)); 621 (const struct sockaddr *) &v6,
622 sizeof (v6));
623 rh->addr_callback (rh->cls,
624 (const struct sockaddr *) &v4,
625 sizeof (v4));
609 break; 626 break;
610 default: 627 default:
611 GNUNET_break (0); 628 GNUNET_break (0);
@@ -653,7 +670,8 @@ process_requests ()
653 * else happening... */ 670 * else happening... */
654 s_task = 671 s_task =
655 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, 672 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
656 &shutdown_task, NULL); 673 &shutdown_task,
674 NULL);
657 return; 675 return;
658 } 676 }
659 if (GNUNET_YES == rh->was_transmitted) 677 if (GNUNET_YES == rh->was_transmitted)
@@ -664,7 +682,9 @@ process_requests ()
664 msg->header.type = htons (GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST); 682 msg->header.type = htons (GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST);
665 msg->direction = htonl (rh->direction); 683 msg->direction = htonl (rh->direction);
666 msg->af = htonl (rh->af); 684 msg->af = htonl (rh->af);
667 memcpy (&msg[1], &rh[1], rh->data_len); 685 memcpy (&msg[1],
686 &rh[1],
687 rh->data_len);
668 LOG (GNUNET_ERROR_TYPE_DEBUG, 688 LOG (GNUNET_ERROR_TYPE_DEBUG,
669 "Transmitting DNS resolution request to DNS service\n"); 689 "Transmitting DNS resolution request to DNS service\n");
670 if (GNUNET_OK != 690 if (GNUNET_OK !=
@@ -672,7 +692,8 @@ process_requests ()
672 &msg->header, 692 &msg->header,
673 GNUNET_TIME_absolute_get_remaining (rh->timeout), 693 GNUNET_TIME_absolute_get_remaining (rh->timeout),
674 GNUNET_YES, 694 GNUNET_YES,
675 &handle_response, rh)) 695 &handle_response,
696 rh))
676 { 697 {
677 GNUNET_CLIENT_disconnect (client); 698 GNUNET_CLIENT_disconnect (client);
678 client = NULL; 699 client = NULL;
@@ -701,7 +722,8 @@ reconnect_task (void *cls,
701 return; 722 return;
702 LOG (GNUNET_ERROR_TYPE_DEBUG, 723 LOG (GNUNET_ERROR_TYPE_DEBUG,
703 "Trying to connect to DNS service\n"); 724 "Trying to connect to DNS service\n");
704 client = GNUNET_CLIENT_connect ("resolver", resolver_cfg); 725 client = GNUNET_CLIENT_connect ("resolver",
726 resolver_cfg);
705 if (NULL == client) 727 if (NULL == client)
706 { 728 {
707 LOG (GNUNET_ERROR_TYPE_DEBUG, 729 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -747,9 +769,12 @@ reconnect ()
747 } 769 }
748 LOG (GNUNET_ERROR_TYPE_DEBUG, 770 LOG (GNUNET_ERROR_TYPE_DEBUG,
749 "Will try to connect to DNS service in %s\n", 771 "Will try to connect to DNS service in %s\n",
750 GNUNET_STRINGS_relative_time_to_string (backoff, GNUNET_YES)); 772 GNUNET_STRINGS_relative_time_to_string (backoff,
773 GNUNET_YES));
751 GNUNET_assert (NULL != resolver_cfg); 774 GNUNET_assert (NULL != resolver_cfg);
752 r_task = GNUNET_SCHEDULER_add_delayed (backoff, &reconnect_task, NULL); 775 r_task = GNUNET_SCHEDULER_add_delayed (backoff,
776 &reconnect_task,
777 NULL);
753 backoff = GNUNET_TIME_STD_BACKOFF (backoff); 778 backoff = GNUNET_TIME_STD_BACKOFF (backoff);
754} 779}
755 780
@@ -826,7 +851,8 @@ GNUNET_RESOLVER_ip_get (const char *hostname, int af,
826 /* then, check if this is a loopback address */ 851 /* then, check if this is a loopback address */
827 i = 0; 852 i = 0;
828 while (NULL != loopback[i]) 853 while (NULL != loopback[i])
829 if (0 == strcasecmp (loopback[i++], hostname)) 854 if (0 == strcasecmp (loopback[i++],
855 hostname))
830 { 856 {
831 rh->task = GNUNET_SCHEDULER_add_now (&loopback_resolution, 857 rh->task = GNUNET_SCHEDULER_add_now (&loopback_resolution,
832 rh); 858 rh);
@@ -835,9 +861,11 @@ GNUNET_RESOLVER_ip_get (const char *hostname, int af,
835 rh->task = GNUNET_SCHEDULER_add_delayed (timeout, 861 rh->task = GNUNET_SCHEDULER_add_delayed (timeout,
836 &handle_lookup_timeout, 862 &handle_lookup_timeout,
837 rh); 863 rh);
838 GNUNET_CONTAINER_DLL_insert_tail (req_head, req_tail, rh); 864 GNUNET_CONTAINER_DLL_insert_tail (req_head,
865 req_tail,
866 rh);
839 rh->was_queued = GNUNET_YES; 867 rh->was_queued = GNUNET_YES;
840 if (s_task != NULL) 868 if (NULL != s_task)
841 { 869 {
842 GNUNET_SCHEDULER_cancel (s_task); 870 GNUNET_SCHEDULER_cancel (s_task);
843 s_task = NULL; 871 s_task = NULL;
@@ -872,10 +900,12 @@ numeric_reverse (void *cls,
872 result); 900 result);
873 if (NULL != result) 901 if (NULL != result)
874 { 902 {
875 rh->name_callback (rh->cls, result); 903 rh->name_callback (rh->cls,
904 result);
876 GNUNET_free (result); 905 GNUNET_free (result);
877 } 906 }
878 rh->name_callback (rh->cls, NULL); 907 rh->name_callback (rh->cls,
908 NULL);
879 GNUNET_free (rh); 909 GNUNET_free (rh);
880} 910}
881 911
@@ -937,7 +967,7 @@ GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa,
937 req_tail, 967 req_tail,
938 rh); 968 rh);
939 rh->was_queued = GNUNET_YES; 969 rh->was_queued = GNUNET_YES;
940 if (s_task != NULL) 970 if (NULL != s_task)
941 { 971 {
942 GNUNET_SCHEDULER_cancel (s_task); 972 GNUNET_SCHEDULER_cancel (s_task);
943 s_task = NULL; 973 s_task = NULL;
@@ -1024,14 +1054,14 @@ GNUNET_RESOLVER_hostname_resolve (int af,
1024void 1054void
1025GNUNET_RESOLVER_request_cancel (struct GNUNET_RESOLVER_RequestHandle *rh) 1055GNUNET_RESOLVER_request_cancel (struct GNUNET_RESOLVER_RequestHandle *rh)
1026{ 1056{
1027 if (rh->task != NULL) 1057 if (NULL != rh->task)
1028 { 1058 {
1029 GNUNET_SCHEDULER_cancel (rh->task); 1059 GNUNET_SCHEDULER_cancel (rh->task);
1030 rh->task = NULL; 1060 rh->task = NULL;
1031 } 1061 }
1032 if (GNUNET_NO == rh->was_transmitted) 1062 if (GNUNET_NO == rh->was_transmitted)
1033 { 1063 {
1034 if (rh->was_queued == GNUNET_YES) 1064 if (GNUNET_YES == rh->was_queued)
1035 GNUNET_CONTAINER_DLL_remove (req_head, 1065 GNUNET_CONTAINER_DLL_remove (req_head,
1036 req_tail, 1066 req_tail,
1037 rh); 1067 rh);