diff options
Diffstat (limited to 'src/dht/dht_api.c')
-rw-r--r-- | src/dht/dht_api.c | 51 |
1 files changed, 22 insertions, 29 deletions
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c index 7a0771de0..af0dafbf3 100644 --- a/src/dht/dht_api.c +++ b/src/dht/dht_api.c | |||
@@ -55,7 +55,7 @@ struct GNUNET_DHT_PutHandle | |||
55 | /** | 55 | /** |
56 | * Continuation to call when done. | 56 | * Continuation to call when done. |
57 | */ | 57 | */ |
58 | GNUNET_DHT_PutContinuation cont; | 58 | GNUNET_SCHEDULER_TaskCallback cont; |
59 | 59 | ||
60 | /** | 60 | /** |
61 | * Main handle to this DHT api | 61 | * Main handle to this DHT api |
@@ -68,9 +68,9 @@ struct GNUNET_DHT_PutHandle | |||
68 | void *cont_cls; | 68 | void *cont_cls; |
69 | 69 | ||
70 | /** | 70 | /** |
71 | * Unique ID for the PUT operation. | 71 | * Envelope from the PUT operation. |
72 | */ | 72 | */ |
73 | uint64_t unique_id; | 73 | struct GNUNET_MQ_Envelope *env; |
74 | 74 | ||
75 | }; | 75 | }; |
76 | 76 | ||
@@ -440,7 +440,7 @@ static void | |||
440 | do_disconnect (struct GNUNET_DHT_Handle *h) | 440 | do_disconnect (struct GNUNET_DHT_Handle *h) |
441 | { | 441 | { |
442 | struct GNUNET_DHT_PutHandle *ph; | 442 | struct GNUNET_DHT_PutHandle *ph; |
443 | GNUNET_DHT_PutContinuation cont; | 443 | GNUNET_SCHEDULER_TaskCallback cont; |
444 | void *cont_cls; | 444 | void *cont_cls; |
445 | 445 | ||
446 | if (NULL == h->mq) | 446 | if (NULL == h->mq) |
@@ -456,10 +456,10 @@ do_disconnect (struct GNUNET_DHT_Handle *h) | |||
456 | { | 456 | { |
457 | cont = ph->cont; | 457 | cont = ph->cont; |
458 | cont_cls = ph->cont_cls; | 458 | cont_cls = ph->cont_cls; |
459 | ph->env = NULL; | ||
459 | GNUNET_DHT_put_cancel (ph); | 460 | GNUNET_DHT_put_cancel (ph); |
460 | if (NULL != cont) | 461 | if (NULL != cont) |
461 | cont (cont_cls, | 462 | cont (cont_cls); |
462 | GNUNET_SYSERR); | ||
463 | } | 463 | } |
464 | GNUNET_assert (NULL == h->reconnect_task); | 464 | GNUNET_assert (NULL == h->reconnect_task); |
465 | h->reconnect_task | 465 | h->reconnect_task |
@@ -818,31 +818,23 @@ handle_client_result (void *cls, | |||
818 | 818 | ||
819 | 819 | ||
820 | /** | 820 | /** |
821 | * Process a put confirmation message from the service. | 821 | * Process a MQ PUT transmission notification. |
822 | * | 822 | * |
823 | * @param cls The DHT handle. | 823 | * @param cls The DHT handle. |
824 | * @param msg confirmation message from the service. | ||
825 | */ | 824 | */ |
826 | static void | 825 | static void |
827 | handle_put_confirmation (void *cls, | 826 | handle_put_cont (void *cls) |
828 | const struct GNUNET_DHT_ClientPutConfirmationMessage *msg) | ||
829 | { | 827 | { |
830 | struct GNUNET_DHT_Handle *handle = cls; | 828 | struct GNUNET_DHT_PutHandle *ph = cls; |
831 | struct GNUNET_DHT_PutHandle *ph; | 829 | GNUNET_SCHEDULER_TaskCallback cont; |
832 | GNUNET_DHT_PutContinuation cont; | ||
833 | void *cont_cls; | 830 | void *cont_cls; |
834 | 831 | ||
835 | for (ph = handle->put_head; NULL != ph; ph = ph->next) | ||
836 | if (ph->unique_id == msg->unique_id) | ||
837 | break; | ||
838 | if (NULL == ph) | ||
839 | return; | ||
840 | cont = ph->cont; | 832 | cont = ph->cont; |
841 | cont_cls = ph->cont_cls; | 833 | cont_cls = ph->cont_cls; |
834 | ph->env = NULL; | ||
842 | GNUNET_DHT_put_cancel (ph); | 835 | GNUNET_DHT_put_cancel (ph); |
843 | if (NULL != cont) | 836 | if (NULL != cont) |
844 | cont (cont_cls, | 837 | cont (cont_cls); |
845 | GNUNET_OK); | ||
846 | } | 838 | } |
847 | 839 | ||
848 | 840 | ||
@@ -872,10 +864,6 @@ try_connect (struct GNUNET_DHT_Handle *h) | |||
872 | GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT, | 864 | GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT, |
873 | struct GNUNET_DHT_ClientResultMessage, | 865 | struct GNUNET_DHT_ClientResultMessage, |
874 | h), | 866 | h), |
875 | GNUNET_MQ_hd_fixed_size (put_confirmation, | ||
876 | GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT_OK, | ||
877 | struct GNUNET_DHT_ClientPutConfirmationMessage, | ||
878 | h), | ||
879 | GNUNET_MQ_handler_end () | 867 | GNUNET_MQ_handler_end () |
880 | }; | 868 | }; |
881 | if (NULL != h->mq) | 869 | if (NULL != h->mq) |
@@ -941,8 +929,7 @@ GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle) | |||
941 | while (NULL != (ph = handle->put_head)) | 929 | while (NULL != (ph = handle->put_head)) |
942 | { | 930 | { |
943 | if (NULL != ph->cont) | 931 | if (NULL != ph->cont) |
944 | ph->cont (ph->cont_cls, | 932 | ph->cont (ph->cont_cls); |
945 | GNUNET_SYSERR); | ||
946 | GNUNET_DHT_put_cancel (ph); | 933 | GNUNET_DHT_put_cancel (ph); |
947 | } | 934 | } |
948 | if (NULL != handle->mq) | 935 | if (NULL != handle->mq) |
@@ -989,7 +976,7 @@ GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, | |||
989 | size_t size, | 976 | size_t size, |
990 | const void *data, | 977 | const void *data, |
991 | struct GNUNET_TIME_Absolute exp, | 978 | struct GNUNET_TIME_Absolute exp, |
992 | GNUNET_DHT_PutContinuation cont, | 979 | GNUNET_SCHEDULER_TaskCallback cont, |
993 | void *cont_cls) | 980 | void *cont_cls) |
994 | { | 981 | { |
995 | struct GNUNET_MQ_Envelope *env; | 982 | struct GNUNET_MQ_Envelope *env; |
@@ -1014,17 +1001,19 @@ GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, | |||
1014 | ph->dht_handle = handle; | 1001 | ph->dht_handle = handle; |
1015 | ph->cont = cont; | 1002 | ph->cont = cont; |
1016 | ph->cont_cls = cont_cls; | 1003 | ph->cont_cls = cont_cls; |
1017 | ph->unique_id = ++handle->uid_gen; | ||
1018 | GNUNET_CONTAINER_DLL_insert_tail (handle->put_head, | 1004 | GNUNET_CONTAINER_DLL_insert_tail (handle->put_head, |
1019 | handle->put_tail, | 1005 | handle->put_tail, |
1020 | ph); | 1006 | ph); |
1021 | env = GNUNET_MQ_msg_extra (put_msg, | 1007 | env = GNUNET_MQ_msg_extra (put_msg, |
1022 | size, | 1008 | size, |
1023 | GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT); | 1009 | GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT); |
1010 | GNUNET_MQ_notify_sent (env, | ||
1011 | &handle_put_cont, | ||
1012 | ph); | ||
1013 | ph->env = env; | ||
1024 | put_msg->type = htonl ((uint32_t) type); | 1014 | put_msg->type = htonl ((uint32_t) type); |
1025 | put_msg->options = htonl ((uint32_t) options); | 1015 | put_msg->options = htonl ((uint32_t) options); |
1026 | put_msg->desired_replication_level = htonl (desired_replication_level); | 1016 | put_msg->desired_replication_level = htonl (desired_replication_level); |
1027 | put_msg->unique_id = ph->unique_id; | ||
1028 | put_msg->expiration = GNUNET_TIME_absolute_hton (exp); | 1017 | put_msg->expiration = GNUNET_TIME_absolute_hton (exp); |
1029 | put_msg->key = *key; | 1018 | put_msg->key = *key; |
1030 | GNUNET_memcpy (&put_msg[1], | 1019 | GNUNET_memcpy (&put_msg[1], |
@@ -1052,6 +1041,10 @@ GNUNET_DHT_put_cancel (struct GNUNET_DHT_PutHandle *ph) | |||
1052 | { | 1041 | { |
1053 | struct GNUNET_DHT_Handle *handle = ph->dht_handle; | 1042 | struct GNUNET_DHT_Handle *handle = ph->dht_handle; |
1054 | 1043 | ||
1044 | if (NULL != ph->env) | ||
1045 | GNUNET_MQ_notify_sent (ph->env, | ||
1046 | NULL, | ||
1047 | NULL); | ||
1055 | GNUNET_CONTAINER_DLL_remove (handle->put_head, | 1048 | GNUNET_CONTAINER_DLL_remove (handle->put_head, |
1056 | handle->put_tail, | 1049 | handle->put_tail, |
1057 | ph); | 1050 | ph); |