diff options
Diffstat (limited to 'src/psycstore/psycstore_api.c')
-rw-r--r-- | src/psycstore/psycstore_api.c | 309 |
1 files changed, 227 insertions, 82 deletions
diff --git a/src/psycstore/psycstore_api.c b/src/psycstore/psycstore_api.c index 9df55888d..9ef1fb61a 100644 --- a/src/psycstore/psycstore_api.c +++ b/src/psycstore/psycstore_api.c | |||
@@ -25,6 +25,8 @@ | |||
25 | * @author Christian Grothoff | 25 | * @author Christian Grothoff |
26 | */ | 26 | */ |
27 | 27 | ||
28 | #include <inttypes.h> | ||
29 | |||
28 | #include "platform.h" | 30 | #include "platform.h" |
29 | #include "gnunet_util_lib.h" | 31 | #include "gnunet_util_lib.h" |
30 | #include "gnunet_constants.h" | 32 | #include "gnunet_constants.h" |
@@ -76,7 +78,7 @@ struct GNUNET_PSYCSTORE_OperationHandle | |||
76 | /** | 78 | /** |
77 | * Operation ID. | 79 | * Operation ID. |
78 | */ | 80 | */ |
79 | uint32_t op_id; | 81 | uint64_t op_id; |
80 | 82 | ||
81 | /** | 83 | /** |
82 | * Message to send to the PSYCstore service. | 84 | * Message to send to the PSYCstore service. |
@@ -137,15 +139,14 @@ struct GNUNET_PSYCSTORE_Handle | |||
137 | struct GNUNET_TIME_Relative reconnect_delay; | 139 | struct GNUNET_TIME_Relative reconnect_delay; |
138 | 140 | ||
139 | /** | 141 | /** |
140 | * Are we polling for incoming messages right now? | 142 | * Last operation ID used. |
141 | */ | 143 | */ |
142 | int in_receive; | 144 | uint64_t last_op_id; |
143 | 145 | ||
144 | /** | 146 | /** |
145 | * The last operation id used for a PSYCstore operation. | 147 | * Are we polling for incoming messages right now? |
146 | */ | 148 | */ |
147 | uint32_t last_op_id_used; | 149 | uint8_t in_receive; |
148 | |||
149 | }; | 150 | }; |
150 | 151 | ||
151 | 152 | ||
@@ -155,10 +156,10 @@ struct GNUNET_PSYCSTORE_Handle | |||
155 | * @param h Handle to the PSYCstore service. | 156 | * @param h Handle to the PSYCstore service. |
156 | * @return next operation id to use | 157 | * @return next operation id to use |
157 | */ | 158 | */ |
158 | static uint32_t | 159 | static uint64_t |
159 | get_next_op_id (struct GNUNET_PSYCSTORE_Handle *h) | 160 | get_next_op_id (struct GNUNET_PSYCSTORE_Handle *h) |
160 | { | 161 | { |
161 | return h->last_op_id_used++; | 162 | return h->last_op_id++; |
162 | } | 163 | } |
163 | 164 | ||
164 | 165 | ||
@@ -168,7 +169,7 @@ get_next_op_id (struct GNUNET_PSYCSTORE_Handle *h) | |||
168 | * @return OperationHandle if found, or NULL otherwise. | 169 | * @return OperationHandle if found, or NULL otherwise. |
169 | */ | 170 | */ |
170 | static struct GNUNET_PSYCSTORE_OperationHandle * | 171 | static struct GNUNET_PSYCSTORE_OperationHandle * |
171 | find_op_by_id (struct GNUNET_PSYCSTORE_Handle *h, uint32_t op_id) | 172 | find_op_by_id (struct GNUNET_PSYCSTORE_Handle *h, uint64_t op_id) |
172 | { | 173 | { |
173 | struct GNUNET_PSYCSTORE_OperationHandle *op = h->op_head; | 174 | struct GNUNET_PSYCSTORE_OperationHandle *op = h->op_head; |
174 | while (NULL != op) | 175 | while (NULL != op) |
@@ -284,19 +285,20 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
284 | if (size == sizeof (struct OperationResult)) | 285 | if (size == sizeof (struct OperationResult)) |
285 | str = NULL; | 286 | str = NULL; |
286 | 287 | ||
287 | op = find_op_by_id (h, ntohl (opres->op_id)); | 288 | op = find_op_by_id (h, GNUNET_ntohll (opres->op_id)); |
288 | if (NULL == op) | 289 | if (NULL == op) |
289 | { | 290 | { |
290 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 291 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
291 | "No callback registered for operation with ID %ld.\n", | 292 | "No callback registered for operation with ID %" PRIu64 ".\n", |
292 | type, ntohl (opres->op_id)); | 293 | type, GNUNET_ntohll (opres->op_id)); |
293 | } | 294 | } |
294 | else | 295 | else |
295 | { | 296 | { |
296 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 297 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
297 | "Received result message (type %d) with operation ID: %ld\n", | 298 | "Received result message (type %d) with operation ID: %" PRIu64 "\n", |
298 | type, op->op_id); | 299 | type, op->op_id); |
299 | 300 | ||
301 | int64_t result_code = GNUNET_ntohll (opres->result_code) + INT64_MIN; | ||
300 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); | 302 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); |
301 | if (NULL != op->res_cb) | 303 | if (NULL != op->res_cb) |
302 | { | 304 | { |
@@ -307,19 +309,19 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
307 | case GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_MODIFY: | 309 | case GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_MODIFY: |
308 | smreq = (const struct StateModifyRequest *) op->msg; | 310 | smreq = (const struct StateModifyRequest *) op->msg; |
309 | if (!(smreq->flags & STATE_OP_LAST | 311 | if (!(smreq->flags & STATE_OP_LAST |
310 | || GNUNET_OK != ntohl (opres->result_code))) | 312 | || GNUNET_OK != result_code)) |
311 | op->res_cb = NULL; | 313 | op->res_cb = NULL; |
312 | break; | 314 | break; |
313 | case GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_SYNC: | 315 | case GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_SYNC: |
314 | ssreq = (const struct StateSyncRequest *) op->msg; | 316 | ssreq = (const struct StateSyncRequest *) op->msg; |
315 | if (!(ssreq->flags & STATE_OP_LAST | 317 | if (!(ssreq->flags & STATE_OP_LAST |
316 | || GNUNET_OK != ntohl (opres->result_code))) | 318 | || GNUNET_OK != result_code)) |
317 | op->res_cb = NULL; | 319 | op->res_cb = NULL; |
318 | break; | 320 | break; |
319 | } | 321 | } |
320 | } | 322 | } |
321 | if (NULL != op->res_cb) | 323 | if (NULL != op->res_cb) |
322 | op->res_cb (op->cls, ntohl (opres->result_code), str); | 324 | op->res_cb (op->cls, result_code, str); |
323 | GNUNET_free (op); | 325 | GNUNET_free (op); |
324 | } | 326 | } |
325 | break; | 327 | break; |
@@ -338,19 +340,20 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
338 | 340 | ||
339 | cres = (const struct CountersResult *) msg; | 341 | cres = (const struct CountersResult *) msg; |
340 | 342 | ||
341 | op = find_op_by_id (h, ntohl (cres->op_id)); | 343 | op = find_op_by_id (h, GNUNET_ntohll (cres->op_id)); |
342 | if (NULL == op) | 344 | if (NULL == op) |
343 | { | 345 | { |
344 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 346 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
345 | "No callback registered for operation with ID %ld.\n", | 347 | "No callback registered for operation with ID %" PRIu64 ".\n", |
346 | type, ntohl (cres->op_id)); | 348 | type, GNUNET_ntohll (cres->op_id)); |
347 | } | 349 | } |
348 | else | 350 | else |
349 | { | 351 | { |
350 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); | 352 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); |
351 | if (NULL != op->data_cb) | 353 | if (NULL != op->data_cb) |
352 | ((GNUNET_PSYCSTORE_CountersCallback) | 354 | ((GNUNET_PSYCSTORE_CountersCallback) |
353 | op->data_cb) (op->cls, ntohl (cres->result_code), | 355 | op->data_cb) (op->cls, |
356 | ntohl (cres->result_code) + INT32_MIN, | ||
354 | GNUNET_ntohll (cres->max_fragment_id), | 357 | GNUNET_ntohll (cres->max_fragment_id), |
355 | GNUNET_ntohll (cres->max_message_id), | 358 | GNUNET_ntohll (cres->max_message_id), |
356 | GNUNET_ntohll (cres->max_group_generation), | 359 | GNUNET_ntohll (cres->max_group_generation), |
@@ -386,12 +389,12 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
386 | return; | 389 | return; |
387 | } | 390 | } |
388 | 391 | ||
389 | op = find_op_by_id (h, ntohl (fres->op_id)); | 392 | op = find_op_by_id (h, GNUNET_ntohll (fres->op_id)); |
390 | if (NULL == op) | 393 | if (NULL == op) |
391 | { | 394 | { |
392 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 395 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
393 | "No callback registered for operation with ID %ld.\n", | 396 | "No callback registered for operation with ID %" PRIu64 ".\n", |
394 | type, ntohl (fres->op_id)); | 397 | type, GNUNET_ntohll (fres->op_id)); |
395 | } | 398 | } |
396 | else | 399 | else |
397 | { | 400 | { |
@@ -427,12 +430,12 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
427 | return; | 430 | return; |
428 | } | 431 | } |
429 | 432 | ||
430 | op = find_op_by_id (h, ntohl (sres->op_id)); | 433 | op = find_op_by_id (h, GNUNET_ntohll (sres->op_id)); |
431 | if (NULL == op) | 434 | if (NULL == op) |
432 | { | 435 | { |
433 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 436 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
434 | "No callback registered for operation with ID %ld.\n", | 437 | "No callback registered for operation with ID %" PRIu64 ".\n", |
435 | type, ntohl (sres->op_id)); | 438 | type, GNUNET_ntohll (sres->op_id)); |
436 | } | 439 | } |
437 | else | 440 | else |
438 | { | 441 | { |
@@ -479,7 +482,7 @@ send_next_message (void *cls, size_t size, void *buf) | |||
479 | return 0; | 482 | return 0; |
480 | } | 483 | } |
481 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 484 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
482 | "Sending message of type %d to PSYCstore service. ID: %u\n", | 485 | "Sending message of type %d to PSYCstore service. ID: %" PRIu64 "\n", |
483 | ntohs (op->msg->type), op->op_id); | 486 | ntohs (op->msg->type), op->op_id); |
484 | memcpy (buf, op->msg, ret); | 487 | memcpy (buf, op->msg, ret); |
485 | 488 | ||
@@ -682,8 +685,8 @@ GNUNET_PSYCSTORE_membership_store (struct GNUNET_PSYCSTORE_Handle *h, | |||
682 | : effective_since == 0); | 685 | : effective_since == 0); |
683 | 686 | ||
684 | struct MembershipStoreRequest *req; | 687 | struct MembershipStoreRequest *req; |
685 | struct GNUNET_PSYCSTORE_OperationHandle *op | 688 | struct GNUNET_PSYCSTORE_OperationHandle * |
686 | = GNUNET_malloc (sizeof (*op) + sizeof (*req)); | 689 | op = GNUNET_malloc (sizeof (*op) + sizeof (*req)); |
687 | op->h = h; | 690 | op->h = h; |
688 | op->res_cb = rcb; | 691 | op->res_cb = rcb; |
689 | op->cls = rcb_cls; | 692 | op->cls = rcb_cls; |
@@ -700,7 +703,7 @@ GNUNET_PSYCSTORE_membership_store (struct GNUNET_PSYCSTORE_Handle *h, | |||
700 | req->group_generation = GNUNET_htonll (group_generation); | 703 | req->group_generation = GNUNET_htonll (group_generation); |
701 | 704 | ||
702 | op->op_id = get_next_op_id (h); | 705 | op->op_id = get_next_op_id (h); |
703 | req->op_id = htonl (op->op_id); | 706 | req->op_id = GNUNET_htonll (op->op_id); |
704 | 707 | ||
705 | GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op); | 708 | GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op); |
706 | transmit_next (h); | 709 | transmit_next (h); |
@@ -746,8 +749,8 @@ GNUNET_PSYCSTORE_membership_test (struct GNUNET_PSYCSTORE_Handle *h, | |||
746 | void *rcb_cls) | 749 | void *rcb_cls) |
747 | { | 750 | { |
748 | struct MembershipTestRequest *req; | 751 | struct MembershipTestRequest *req; |
749 | struct GNUNET_PSYCSTORE_OperationHandle *op | 752 | struct GNUNET_PSYCSTORE_OperationHandle * |
750 | = GNUNET_malloc (sizeof (*op) + sizeof (*req)); | 753 | op = GNUNET_malloc (sizeof (*op) + sizeof (*req)); |
751 | op->h = h; | 754 | op->h = h; |
752 | op->res_cb = rcb; | 755 | op->res_cb = rcb; |
753 | op->cls = rcb_cls; | 756 | op->cls = rcb_cls; |
@@ -762,7 +765,7 @@ GNUNET_PSYCSTORE_membership_test (struct GNUNET_PSYCSTORE_Handle *h, | |||
762 | req->group_generation = GNUNET_htonll (group_generation); | 765 | req->group_generation = GNUNET_htonll (group_generation); |
763 | 766 | ||
764 | op->op_id = get_next_op_id (h); | 767 | op->op_id = get_next_op_id (h); |
765 | req->op_id = htonl (op->op_id); | 768 | req->op_id = GNUNET_htonll (op->op_id); |
766 | 769 | ||
767 | GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op); | 770 | GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op); |
768 | transmit_next (h); | 771 | transmit_next (h); |
@@ -794,8 +797,8 @@ GNUNET_PSYCSTORE_fragment_store (struct GNUNET_PSYCSTORE_Handle *h, | |||
794 | { | 797 | { |
795 | uint16_t size = ntohs (msg->header.size); | 798 | uint16_t size = ntohs (msg->header.size); |
796 | struct FragmentStoreRequest *req; | 799 | struct FragmentStoreRequest *req; |
797 | struct GNUNET_PSYCSTORE_OperationHandle *op | 800 | struct GNUNET_PSYCSTORE_OperationHandle * |
798 | = GNUNET_malloc (sizeof (*op) + sizeof (*req) + size); | 801 | op = GNUNET_malloc (sizeof (*op) + sizeof (*req) + size); |
799 | op->h = h; | 802 | op->h = h; |
800 | op->res_cb = rcb; | 803 | op->res_cb = rcb; |
801 | op->cls = rcb_cls; | 804 | op->cls = rcb_cls; |
@@ -809,7 +812,7 @@ GNUNET_PSYCSTORE_fragment_store (struct GNUNET_PSYCSTORE_Handle *h, | |||
809 | memcpy (&req[1], msg, size); | 812 | memcpy (&req[1], msg, size); |
810 | 813 | ||
811 | op->op_id = get_next_op_id (h); | 814 | op->op_id = get_next_op_id (h); |
812 | req->op_id = htonl (op->op_id); | 815 | req->op_id = GNUNET_htonll (op->op_id); |
813 | 816 | ||
814 | GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op); | 817 | GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op); |
815 | transmit_next (h); | 818 | transmit_next (h); |
@@ -819,7 +822,7 @@ GNUNET_PSYCSTORE_fragment_store (struct GNUNET_PSYCSTORE_Handle *h, | |||
819 | 822 | ||
820 | 823 | ||
821 | /** | 824 | /** |
822 | * Retrieve a message fragment by fragment ID. | 825 | * Retrieve message fragments by fragment ID range. |
823 | * | 826 | * |
824 | * @param h | 827 | * @param h |
825 | * Handle for the PSYCstore. | 828 | * Handle for the PSYCstore. |
@@ -829,9 +832,15 @@ GNUNET_PSYCSTORE_fragment_store (struct GNUNET_PSYCSTORE_Handle *h, | |||
829 | * The slave requesting the fragment. If not NULL, a membership test is | 832 | * The slave requesting the fragment. If not NULL, a membership test is |
830 | * performed first and the fragment is only returned if the slave has | 833 | * performed first and the fragment is only returned if the slave has |
831 | * access to it. | 834 | * access to it. |
832 | * @param fragment_id | 835 | * @param first_fragment_id |
833 | * Fragment ID to retrieve. Use 0 to get the latest message fragment. | 836 | * First fragment ID to retrieve. |
834 | * @param fcb | 837 | * Use 0 to get the latest message fragment. |
838 | * @param last_fragment_id | ||
839 | * Last consecutive fragment ID to retrieve. | ||
840 | * Use 0 to get the latest message fragment. | ||
841 | * @param fragment_limit | ||
842 | * Maximum number of fragments to retrieve. | ||
843 | * @param fragment_cb | ||
835 | * Callback to call with the retrieved fragments. | 844 | * Callback to call with the retrieved fragments. |
836 | * @param rcb | 845 | * @param rcb |
837 | * Callback to call with the result of the operation. | 846 | * Callback to call with the result of the operation. |
@@ -844,16 +853,85 @@ struct GNUNET_PSYCSTORE_OperationHandle * | |||
844 | GNUNET_PSYCSTORE_fragment_get (struct GNUNET_PSYCSTORE_Handle *h, | 853 | GNUNET_PSYCSTORE_fragment_get (struct GNUNET_PSYCSTORE_Handle *h, |
845 | const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key, | 854 | const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key, |
846 | const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key, | 855 | const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key, |
847 | uint64_t fragment_id, | 856 | uint64_t first_fragment_id, |
848 | GNUNET_PSYCSTORE_FragmentCallback fcb, | 857 | uint64_t last_fragment_id, |
858 | GNUNET_PSYCSTORE_FragmentCallback fragment_cb, | ||
849 | GNUNET_PSYCSTORE_ResultCallback rcb, | 859 | GNUNET_PSYCSTORE_ResultCallback rcb, |
850 | void *cls) | 860 | void *cls) |
851 | { | 861 | { |
852 | struct FragmentGetRequest *req; | 862 | struct FragmentGetRequest *req; |
853 | struct GNUNET_PSYCSTORE_OperationHandle *op | 863 | struct GNUNET_PSYCSTORE_OperationHandle * |
854 | = GNUNET_malloc (sizeof (*op) + sizeof (*req)); | 864 | op = GNUNET_malloc (sizeof (*op) + sizeof (*req)); |
865 | op->h = h; | ||
866 | op->data_cb = (DataCallback) fragment_cb; | ||
867 | op->res_cb = rcb; | ||
868 | op->cls = cls; | ||
869 | |||
870 | req = (struct FragmentGetRequest *) &op[1]; | ||
871 | op->msg = (struct GNUNET_MessageHeader *) req; | ||
872 | req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_FRAGMENT_GET); | ||
873 | req->header.size = htons (sizeof (*req)); | ||
874 | req->channel_key = *channel_key; | ||
875 | req->first_fragment_id = GNUNET_htonll (first_fragment_id); | ||
876 | req->last_fragment_id = GNUNET_htonll (last_fragment_id); | ||
877 | if (NULL != slave_key) | ||
878 | { | ||
879 | req->slave_key = *slave_key; | ||
880 | req->do_membership_test = GNUNET_YES; | ||
881 | } | ||
882 | |||
883 | op->op_id = get_next_op_id (h); | ||
884 | req->op_id = GNUNET_htonll (op->op_id); | ||
885 | |||
886 | GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op); | ||
887 | transmit_next (h); | ||
888 | |||
889 | return op; | ||
890 | } | ||
891 | |||
892 | |||
893 | /** | ||
894 | * Retrieve latest message fragments. | ||
895 | * | ||
896 | * @param h | ||
897 | * Handle for the PSYCstore. | ||
898 | * @param channel_key | ||
899 | * The channel we are interested in. | ||
900 | * @param slave_key | ||
901 | * The slave requesting the fragment. If not NULL, a membership test is | ||
902 | * performed first and the fragment is only returned if the slave has | ||
903 | * access to it. | ||
904 | * @param first_fragment_id | ||
905 | * First fragment ID to retrieve. | ||
906 | * Use 0 to get the latest message fragment. | ||
907 | * @param last_fragment_id | ||
908 | * Last consecutive fragment ID to retrieve. | ||
909 | * Use 0 to get the latest message fragment. | ||
910 | * @param fragment_limit | ||
911 | * Maximum number of fragments to retrieve. | ||
912 | * @param fragment_cb | ||
913 | * Callback to call with the retrieved fragments. | ||
914 | * @param rcb | ||
915 | * Callback to call with the result of the operation. | ||
916 | * @param cls | ||
917 | * Closure for the callbacks. | ||
918 | * | ||
919 | * @return Handle that can be used to cancel the operation. | ||
920 | */ | ||
921 | struct GNUNET_PSYCSTORE_OperationHandle * | ||
922 | GNUNET_PSYCSTORE_fragment_get_latest (struct GNUNET_PSYCSTORE_Handle *h, | ||
923 | const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key, | ||
924 | const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key, | ||
925 | uint64_t fragment_limit, | ||
926 | GNUNET_PSYCSTORE_FragmentCallback fragment_cb, | ||
927 | GNUNET_PSYCSTORE_ResultCallback rcb, | ||
928 | void *cls) | ||
929 | { | ||
930 | struct FragmentGetRequest *req; | ||
931 | struct GNUNET_PSYCSTORE_OperationHandle * | ||
932 | op = GNUNET_malloc (sizeof (*op) + sizeof (*req)); | ||
855 | op->h = h; | 933 | op->h = h; |
856 | op->data_cb = (DataCallback) fcb; | 934 | op->data_cb = (DataCallback) fragment_cb; |
857 | op->res_cb = rcb; | 935 | op->res_cb = rcb; |
858 | op->cls = cls; | 936 | op->cls = cls; |
859 | 937 | ||
@@ -862,7 +940,7 @@ GNUNET_PSYCSTORE_fragment_get (struct GNUNET_PSYCSTORE_Handle *h, | |||
862 | req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_FRAGMENT_GET); | 940 | req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_FRAGMENT_GET); |
863 | req->header.size = htons (sizeof (*req)); | 941 | req->header.size = htons (sizeof (*req)); |
864 | req->channel_key = *channel_key; | 942 | req->channel_key = *channel_key; |
865 | req->fragment_id = GNUNET_htonll (fragment_id); | 943 | req->fragment_limit = GNUNET_ntohll (fragment_limit); |
866 | if (NULL != slave_key) | 944 | if (NULL != slave_key) |
867 | { | 945 | { |
868 | req->slave_key = *slave_key; | 946 | req->slave_key = *slave_key; |
@@ -870,7 +948,7 @@ GNUNET_PSYCSTORE_fragment_get (struct GNUNET_PSYCSTORE_Handle *h, | |||
870 | } | 948 | } |
871 | 949 | ||
872 | op->op_id = get_next_op_id (h); | 950 | op->op_id = get_next_op_id (h); |
873 | req->op_id = htonl (op->op_id); | 951 | req->op_id = GNUNET_htonll (op->op_id); |
874 | 952 | ||
875 | GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op); | 953 | GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op); |
876 | transmit_next (h); | 954 | transmit_next (h); |
@@ -880,7 +958,7 @@ GNUNET_PSYCSTORE_fragment_get (struct GNUNET_PSYCSTORE_Handle *h, | |||
880 | 958 | ||
881 | 959 | ||
882 | /** | 960 | /** |
883 | * Retrieve all fragments of a message. | 961 | * Retrieve all fragments of messages in a message ID range. |
884 | * | 962 | * |
885 | * @param h | 963 | * @param h |
886 | * Handle for the PSYCstore. | 964 | * Handle for the PSYCstore. |
@@ -890,9 +968,13 @@ GNUNET_PSYCSTORE_fragment_get (struct GNUNET_PSYCSTORE_Handle *h, | |||
890 | * The slave requesting the message. If not NULL, a membership test is | 968 | * The slave requesting the message. If not NULL, a membership test is |
891 | * performed first and the message is only returned if the slave has | 969 | * performed first and the message is only returned if the slave has |
892 | * access to it. | 970 | * access to it. |
893 | * @param message_id | 971 | * @param first_message_id |
894 | * Message ID to retrieve. Use 0 to get the latest message. | 972 | * First message ID to retrieve. |
895 | * @param fcb | 973 | * Use 0 to get the latest message. |
974 | * @param last_message_id | ||
975 | * Last consecutive message ID to retrieve. | ||
976 | * Use 0 to get the latest message. | ||
977 | * @param fragment_cb | ||
896 | * Callback to call with the retrieved fragments. | 978 | * Callback to call with the retrieved fragments. |
897 | * @param rcb | 979 | * @param rcb |
898 | * Callback to call with the result of the operation. | 980 | * Callback to call with the result of the operation. |
@@ -905,16 +987,17 @@ struct GNUNET_PSYCSTORE_OperationHandle * | |||
905 | GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h, | 987 | GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h, |
906 | const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key, | 988 | const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key, |
907 | const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key, | 989 | const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key, |
908 | uint64_t message_id, | 990 | uint64_t first_message_id, |
909 | GNUNET_PSYCSTORE_FragmentCallback fcb, | 991 | uint64_t last_message_id, |
992 | GNUNET_PSYCSTORE_FragmentCallback fragment_cb, | ||
910 | GNUNET_PSYCSTORE_ResultCallback rcb, | 993 | GNUNET_PSYCSTORE_ResultCallback rcb, |
911 | void *cls) | 994 | void *cls) |
912 | { | 995 | { |
913 | struct MessageGetRequest *req; | 996 | struct MessageGetRequest *req; |
914 | struct GNUNET_PSYCSTORE_OperationHandle *op | 997 | struct GNUNET_PSYCSTORE_OperationHandle * |
915 | = GNUNET_malloc (sizeof (*op) + sizeof (*req)); | 998 | op = GNUNET_malloc (sizeof (*op) + sizeof (*req)); |
916 | op->h = h; | 999 | op->h = h; |
917 | op->data_cb = (DataCallback) fcb; | 1000 | op->data_cb = (DataCallback) fragment_cb; |
918 | op->res_cb = rcb; | 1001 | op->res_cb = rcb; |
919 | op->cls = cls; | 1002 | op->cls = cls; |
920 | 1003 | ||
@@ -923,7 +1006,8 @@ GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h, | |||
923 | req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_MESSAGE_GET); | 1006 | req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_MESSAGE_GET); |
924 | req->header.size = htons (sizeof (*req)); | 1007 | req->header.size = htons (sizeof (*req)); |
925 | req->channel_key = *channel_key; | 1008 | req->channel_key = *channel_key; |
926 | req->message_id = GNUNET_htonll (message_id); | 1009 | req->first_message_id = GNUNET_htonll (first_message_id); |
1010 | req->last_message_id = GNUNET_htonll (last_message_id); | ||
927 | if (NULL != slave_key) | 1011 | if (NULL != slave_key) |
928 | { | 1012 | { |
929 | req->slave_key = *slave_key; | 1013 | req->slave_key = *slave_key; |
@@ -931,7 +1015,68 @@ GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h, | |||
931 | } | 1015 | } |
932 | 1016 | ||
933 | op->op_id = get_next_op_id (h); | 1017 | op->op_id = get_next_op_id (h); |
934 | req->op_id = htonl (op->op_id); | 1018 | req->op_id = GNUNET_htonll (op->op_id); |
1019 | |||
1020 | GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op); | ||
1021 | transmit_next (h); | ||
1022 | |||
1023 | return op; | ||
1024 | } | ||
1025 | |||
1026 | |||
1027 | /** | ||
1028 | * Retrieve all fragments of the latest messages. | ||
1029 | * | ||
1030 | * @param h | ||
1031 | * Handle for the PSYCstore. | ||
1032 | * @param channel_key | ||
1033 | * The channel we are interested in. | ||
1034 | * @param slave_key | ||
1035 | * The slave requesting the message. If not NULL, a membership test is | ||
1036 | * performed first and the message is only returned if the slave has | ||
1037 | * access to it. | ||
1038 | * @param message_limit | ||
1039 | * Maximum number of messages to retrieve. | ||
1040 | * @param fragment_cb | ||
1041 | * Callback to call with the retrieved fragments. | ||
1042 | * @param rcb | ||
1043 | * Callback to call with the result of the operation. | ||
1044 | * @param cls | ||
1045 | * Closure for the callbacks. | ||
1046 | * | ||
1047 | * @return Handle that can be used to cancel the operation. | ||
1048 | */ | ||
1049 | struct GNUNET_PSYCSTORE_OperationHandle * | ||
1050 | GNUNET_PSYCSTORE_message_get_latest (struct GNUNET_PSYCSTORE_Handle *h, | ||
1051 | const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key, | ||
1052 | const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key, | ||
1053 | uint64_t message_limit, | ||
1054 | GNUNET_PSYCSTORE_FragmentCallback fragment_cb, | ||
1055 | GNUNET_PSYCSTORE_ResultCallback rcb, | ||
1056 | void *cls) | ||
1057 | { | ||
1058 | struct MessageGetRequest *req; | ||
1059 | struct GNUNET_PSYCSTORE_OperationHandle * | ||
1060 | op = GNUNET_malloc (sizeof (*op) + sizeof (*req)); | ||
1061 | op->h = h; | ||
1062 | op->data_cb = (DataCallback) fragment_cb; | ||
1063 | op->res_cb = rcb; | ||
1064 | op->cls = cls; | ||
1065 | |||
1066 | req = (struct MessageGetRequest *) &op[1]; | ||
1067 | op->msg = (struct GNUNET_MessageHeader *) req; | ||
1068 | req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_MESSAGE_GET); | ||
1069 | req->header.size = htons (sizeof (*req)); | ||
1070 | req->channel_key = *channel_key; | ||
1071 | req->message_limit = GNUNET_ntohll (message_limit); | ||
1072 | if (NULL != slave_key) | ||
1073 | { | ||
1074 | req->slave_key = *slave_key; | ||
1075 | req->do_membership_test = GNUNET_YES; | ||
1076 | } | ||
1077 | |||
1078 | op->op_id = get_next_op_id (h); | ||
1079 | req->op_id = GNUNET_htonll (op->op_id); | ||
935 | 1080 | ||
936 | GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op); | 1081 | GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op); |
937 | transmit_next (h); | 1082 | transmit_next (h); |
@@ -956,9 +1101,9 @@ GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h, | |||
956 | * Message ID to retrieve. Use 0 to get the latest message. | 1101 | * Message ID to retrieve. Use 0 to get the latest message. |
957 | * @param fragment_offset | 1102 | * @param fragment_offset |
958 | * Offset of the fragment to retrieve. | 1103 | * Offset of the fragment to retrieve. |
959 | * @param fcb | 1104 | * @param fragment_cb |
960 | * Callback to call with the retrieved fragments. | 1105 | * Callback to call with the retrieved fragments. |
961 | * @param rcb | 1106 | * @param result_cb |
962 | * Callback to call with the result of the operation. | 1107 | * Callback to call with the result of the operation. |
963 | * @param cls | 1108 | * @param cls |
964 | * Closure for the callbacks. | 1109 | * Closure for the callbacks. |
@@ -971,15 +1116,15 @@ GNUNET_PSYCSTORE_message_get_fragment (struct GNUNET_PSYCSTORE_Handle *h, | |||
971 | const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key, | 1116 | const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key, |
972 | uint64_t message_id, | 1117 | uint64_t message_id, |
973 | uint64_t fragment_offset, | 1118 | uint64_t fragment_offset, |
974 | GNUNET_PSYCSTORE_FragmentCallback fcb, | 1119 | GNUNET_PSYCSTORE_FragmentCallback fragment_cb, |
975 | GNUNET_PSYCSTORE_ResultCallback rcb, | 1120 | GNUNET_PSYCSTORE_ResultCallback rcb, |
976 | void *cls) | 1121 | void *cls) |
977 | { | 1122 | { |
978 | struct MessageGetFragmentRequest *req; | 1123 | struct MessageGetFragmentRequest *req; |
979 | struct GNUNET_PSYCSTORE_OperationHandle *op | 1124 | struct GNUNET_PSYCSTORE_OperationHandle * |
980 | = GNUNET_malloc (sizeof (*op) + sizeof (*req)); | 1125 | op = GNUNET_malloc (sizeof (*op) + sizeof (*req)); |
981 | op->h = h; | 1126 | op->h = h; |
982 | op->data_cb = (DataCallback) fcb; | 1127 | op->data_cb = (DataCallback) fragment_cb; |
983 | op->res_cb = rcb; | 1128 | op->res_cb = rcb; |
984 | op->cls = cls; | 1129 | op->cls = cls; |
985 | 1130 | ||
@@ -997,7 +1142,7 @@ GNUNET_PSYCSTORE_message_get_fragment (struct GNUNET_PSYCSTORE_Handle *h, | |||
997 | } | 1142 | } |
998 | 1143 | ||
999 | op->op_id = get_next_op_id (h); | 1144 | op->op_id = get_next_op_id (h); |
1000 | req->op_id = htonl (op->op_id); | 1145 | req->op_id = GNUNET_htonll (op->op_id); |
1001 | 1146 | ||
1002 | GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op); | 1147 | GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op); |
1003 | transmit_next (h); | 1148 | transmit_next (h); |
@@ -1026,8 +1171,8 @@ GNUNET_PSYCSTORE_counters_get (struct GNUNET_PSYCSTORE_Handle *h, | |||
1026 | void *ccb_cls) | 1171 | void *ccb_cls) |
1027 | { | 1172 | { |
1028 | struct OperationRequest *req; | 1173 | struct OperationRequest *req; |
1029 | struct GNUNET_PSYCSTORE_OperationHandle *op | 1174 | struct GNUNET_PSYCSTORE_OperationHandle * |
1030 | = GNUNET_malloc (sizeof (*op) + sizeof (*req)); | 1175 | op = GNUNET_malloc (sizeof (*op) + sizeof (*req)); |
1031 | op->h = h; | 1176 | op->h = h; |
1032 | op->data_cb = ccb; | 1177 | op->data_cb = ccb; |
1033 | op->cls = ccb_cls; | 1178 | op->cls = ccb_cls; |
@@ -1039,7 +1184,7 @@ GNUNET_PSYCSTORE_counters_get (struct GNUNET_PSYCSTORE_Handle *h, | |||
1039 | req->channel_key = *channel_key; | 1184 | req->channel_key = *channel_key; |
1040 | 1185 | ||
1041 | op->op_id = get_next_op_id (h); | 1186 | op->op_id = get_next_op_id (h); |
1042 | req->op_id = htonl (op->op_id); | 1187 | req->op_id = GNUNET_htonll (op->op_id); |
1043 | 1188 | ||
1044 | GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op); | 1189 | GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op); |
1045 | transmit_next (h); | 1190 | transmit_next (h); |
@@ -1109,7 +1254,7 @@ GNUNET_PSYCSTORE_state_modify (struct GNUNET_PSYCSTORE_Handle *h, | |||
1109 | memcpy ((char *) &req[1] + name_size, modifiers[i].value, modifiers[i].value_size); | 1254 | memcpy ((char *) &req[1] + name_size, modifiers[i].value, modifiers[i].value_size); |
1110 | 1255 | ||
1111 | op->op_id = get_next_op_id (h); | 1256 | op->op_id = get_next_op_id (h); |
1112 | req->op_id = htonl (op->op_id); | 1257 | req->op_id = GNUNET_htonll (op->op_id); |
1113 | 1258 | ||
1114 | GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op); | 1259 | GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op); |
1115 | transmit_next (h); | 1260 | transmit_next (h); |
@@ -1175,7 +1320,7 @@ GNUNET_PSYCSTORE_state_sync (struct GNUNET_PSYCSTORE_Handle *h, | |||
1175 | memcpy ((char *) &req[1] + name_size, modifiers[i].value, modifiers[i].value_size); | 1320 | memcpy ((char *) &req[1] + name_size, modifiers[i].value, modifiers[i].value_size); |
1176 | 1321 | ||
1177 | op->op_id = get_next_op_id (h); | 1322 | op->op_id = get_next_op_id (h); |
1178 | req->op_id = htonl (op->op_id); | 1323 | req->op_id = GNUNET_htonll (op->op_id); |
1179 | 1324 | ||
1180 | GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op); | 1325 | GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op); |
1181 | transmit_next (h); | 1326 | transmit_next (h); |
@@ -1204,8 +1349,8 @@ GNUNET_PSYCSTORE_state_reset (struct GNUNET_PSYCSTORE_Handle *h, | |||
1204 | void *rcb_cls) | 1349 | void *rcb_cls) |
1205 | { | 1350 | { |
1206 | struct OperationRequest *req; | 1351 | struct OperationRequest *req; |
1207 | struct GNUNET_PSYCSTORE_OperationHandle *op | 1352 | struct GNUNET_PSYCSTORE_OperationHandle * |
1208 | = GNUNET_malloc (sizeof (*op) + sizeof (*req)); | 1353 | op = GNUNET_malloc (sizeof (*op) + sizeof (*req)); |
1209 | op->h = h; | 1354 | op->h = h; |
1210 | op->res_cb = rcb; | 1355 | op->res_cb = rcb; |
1211 | op->cls = rcb_cls; | 1356 | op->cls = rcb_cls; |
@@ -1217,7 +1362,7 @@ GNUNET_PSYCSTORE_state_reset (struct GNUNET_PSYCSTORE_Handle *h, | |||
1217 | req->channel_key = *channel_key; | 1362 | req->channel_key = *channel_key; |
1218 | 1363 | ||
1219 | op->op_id = get_next_op_id (h); | 1364 | op->op_id = get_next_op_id (h); |
1220 | req->op_id = htonl (op->op_id); | 1365 | req->op_id = GNUNET_htonll (op->op_id); |
1221 | 1366 | ||
1222 | GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op); | 1367 | GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op); |
1223 | transmit_next (h); | 1368 | transmit_next (h); |
@@ -1247,8 +1392,8 @@ GNUNET_PSYCSTORE_state_hash_update (struct GNUNET_PSYCSTORE_Handle *h, | |||
1247 | void *rcb_cls) | 1392 | void *rcb_cls) |
1248 | { | 1393 | { |
1249 | struct StateHashUpdateRequest *req; | 1394 | struct StateHashUpdateRequest *req; |
1250 | struct GNUNET_PSYCSTORE_OperationHandle *op | 1395 | struct GNUNET_PSYCSTORE_OperationHandle * |
1251 | = GNUNET_malloc (sizeof (*op) + sizeof (*req)); | 1396 | op = GNUNET_malloc (sizeof (*op) + sizeof (*req)); |
1252 | op->h = h; | 1397 | op->h = h; |
1253 | op->res_cb = rcb; | 1398 | op->res_cb = rcb; |
1254 | op->cls = rcb_cls; | 1399 | op->cls = rcb_cls; |
@@ -1261,7 +1406,7 @@ GNUNET_PSYCSTORE_state_hash_update (struct GNUNET_PSYCSTORE_Handle *h, | |||
1261 | req->hash = *hash; | 1406 | req->hash = *hash; |
1262 | 1407 | ||
1263 | op->op_id = get_next_op_id (h); | 1408 | op->op_id = get_next_op_id (h); |
1264 | req->op_id = htonl (op->op_id); | 1409 | req->op_id = GNUNET_htonll (op->op_id); |
1265 | 1410 | ||
1266 | GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op); | 1411 | GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op); |
1267 | transmit_next (h); | 1412 | transmit_next (h); |
@@ -1292,8 +1437,8 @@ GNUNET_PSYCSTORE_state_get (struct GNUNET_PSYCSTORE_Handle *h, | |||
1292 | { | 1437 | { |
1293 | size_t name_size = strlen (name) + 1; | 1438 | size_t name_size = strlen (name) + 1; |
1294 | struct OperationRequest *req; | 1439 | struct OperationRequest *req; |
1295 | struct GNUNET_PSYCSTORE_OperationHandle *op | 1440 | struct GNUNET_PSYCSTORE_OperationHandle * |
1296 | = GNUNET_malloc (sizeof (*op) + sizeof (*req) + name_size); | 1441 | op = GNUNET_malloc (sizeof (*op) + sizeof (*req) + name_size); |
1297 | op->h = h; | 1442 | op->h = h; |
1298 | op->data_cb = (DataCallback) scb; | 1443 | op->data_cb = (DataCallback) scb; |
1299 | op->res_cb = rcb; | 1444 | op->res_cb = rcb; |
@@ -1307,7 +1452,7 @@ GNUNET_PSYCSTORE_state_get (struct GNUNET_PSYCSTORE_Handle *h, | |||
1307 | memcpy (&req[1], name, name_size); | 1452 | memcpy (&req[1], name, name_size); |
1308 | 1453 | ||
1309 | op->op_id = get_next_op_id (h); | 1454 | op->op_id = get_next_op_id (h); |
1310 | req->op_id = htonl (op->op_id); | 1455 | req->op_id = GNUNET_htonll (op->op_id); |
1311 | 1456 | ||
1312 | GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op); | 1457 | GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op); |
1313 | transmit_next (h); | 1458 | transmit_next (h); |
@@ -1339,8 +1484,8 @@ GNUNET_PSYCSTORE_state_get_prefix (struct GNUNET_PSYCSTORE_Handle *h, | |||
1339 | { | 1484 | { |
1340 | size_t name_size = strlen (name_prefix) + 1; | 1485 | size_t name_size = strlen (name_prefix) + 1; |
1341 | struct OperationRequest *req; | 1486 | struct OperationRequest *req; |
1342 | struct GNUNET_PSYCSTORE_OperationHandle *op | 1487 | struct GNUNET_PSYCSTORE_OperationHandle * |
1343 | = GNUNET_malloc (sizeof (*op) + sizeof (*req) + name_size); | 1488 | op = GNUNET_malloc (sizeof (*op) + sizeof (*req) + name_size); |
1344 | op->h = h; | 1489 | op->h = h; |
1345 | op->data_cb = (DataCallback) scb; | 1490 | op->data_cb = (DataCallback) scb; |
1346 | op->res_cb = rcb; | 1491 | op->res_cb = rcb; |
@@ -1354,7 +1499,7 @@ GNUNET_PSYCSTORE_state_get_prefix (struct GNUNET_PSYCSTORE_Handle *h, | |||
1354 | memcpy (&req[1], name_prefix, name_size); | 1499 | memcpy (&req[1], name_prefix, name_size); |
1355 | 1500 | ||
1356 | op->op_id = get_next_op_id (h); | 1501 | op->op_id = get_next_op_id (h); |
1357 | req->op_id = htonl (op->op_id); | 1502 | req->op_id = GNUNET_htonll (op->op_id); |
1358 | 1503 | ||
1359 | GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op); | 1504 | GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op); |
1360 | transmit_next (h); | 1505 | transmit_next (h); |