diff options
author | Gabor X Toth <*@tg-x.net> | 2015-05-07 12:15:58 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2015-05-07 12:15:58 +0000 |
commit | 4725d59b468f1f30ba2910992333ca157682ce29 (patch) | |
tree | 23715ee20879c94a3363e28ea184370a4a71e44d /src/psycstore/psycstore_api.c | |
parent | a5edf8ac9f03a368c87ea6163994d4ac3d62af06 (diff) | |
download | gnunet-4725d59b468f1f30ba2910992333ca157682ce29.tar.gz gnunet-4725d59b468f1f30ba2910992333ca157682ce29.zip |
psyc/social: request history & state from psycstore; more documentation, tests, cleanup
Diffstat (limited to 'src/psycstore/psycstore_api.c')
-rw-r--r-- | src/psycstore/psycstore_api.c | 53 |
1 files changed, 38 insertions, 15 deletions
diff --git a/src/psycstore/psycstore_api.c b/src/psycstore/psycstore_api.c index 0178e9ce6..c319b2e1b 100644 --- a/src/psycstore/psycstore_api.c +++ b/src/psycstore/psycstore_api.c | |||
@@ -283,7 +283,7 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
283 | return; | 283 | return; |
284 | } | 284 | } |
285 | if (size == sizeof (struct OperationResult)) | 285 | if (size == sizeof (struct OperationResult)) |
286 | str = NULL; | 286 | str = ""; |
287 | 287 | ||
288 | op = find_op_by_id (h, GNUNET_ntohll (opres->op_id)); | 288 | op = find_op_by_id (h, GNUNET_ntohll (opres->op_id)); |
289 | if (NULL == op) | 289 | if (NULL == op) |
@@ -321,7 +321,7 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
321 | } | 321 | } |
322 | } | 322 | } |
323 | if (NULL != op->res_cb) | 323 | if (NULL != op->res_cb) |
324 | op->res_cb (op->cls, result_code, str); | 324 | op->res_cb (op->cls, result_code, str, size - sizeof (*opres)); |
325 | GNUNET_free (op); | 325 | GNUNET_free (op); |
326 | } | 326 | } |
327 | break; | 327 | break; |
@@ -965,18 +965,19 @@ GNUNET_PSYCSTORE_fragment_get_latest (struct GNUNET_PSYCSTORE_Handle *h, | |||
965 | * @param channel_key | 965 | * @param channel_key |
966 | * The channel we are interested in. | 966 | * The channel we are interested in. |
967 | * @param slave_key | 967 | * @param slave_key |
968 | * The slave requesting the message. If not NULL, a membership test is | 968 | * The slave requesting the message. |
969 | * performed first and the message is only returned if the slave has | 969 | * If not NULL, a membership test is performed first |
970 | * access to it. | 970 | * and the message is only returned if the slave has access to it. |
971 | * @param first_message_id | 971 | * @param first_message_id |
972 | * First message ID to retrieve. | 972 | * First message ID to retrieve. |
973 | * Use 0 to get the latest message. | ||
974 | * @param last_message_id | 973 | * @param last_message_id |
975 | * Last consecutive message ID to retrieve. | 974 | * Last consecutive message ID to retrieve. |
976 | * Use 0 to get the latest message. | 975 | * @param method_prefix |
976 | * Retrieve only messages with a matching method prefix. | ||
977 | * @todo Implement method_prefix query. | ||
977 | * @param fragment_cb | 978 | * @param fragment_cb |
978 | * Callback to call with the retrieved fragments. | 979 | * Callback to call with the retrieved fragments. |
979 | * @param rcb | 980 | * @param result_cb |
980 | * Callback to call with the result of the operation. | 981 | * Callback to call with the result of the operation. |
981 | * @param cls | 982 | * @param cls |
982 | * Closure for the callbacks. | 983 | * Closure for the callbacks. |
@@ -989,11 +990,18 @@ GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h, | |||
989 | const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key, | 990 | const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key, |
990 | uint64_t first_message_id, | 991 | uint64_t first_message_id, |
991 | uint64_t last_message_id, | 992 | uint64_t last_message_id, |
993 | const char *method_prefix, | ||
992 | GNUNET_PSYCSTORE_FragmentCallback fragment_cb, | 994 | GNUNET_PSYCSTORE_FragmentCallback fragment_cb, |
993 | GNUNET_PSYCSTORE_ResultCallback rcb, | 995 | GNUNET_PSYCSTORE_ResultCallback rcb, |
994 | void *cls) | 996 | void *cls) |
995 | { | 997 | { |
996 | struct MessageGetRequest *req; | 998 | struct MessageGetRequest *req; |
999 | if (NULL == method_prefix) | ||
1000 | method_prefix = ""; | ||
1001 | uint16_t method_size = strnlen (method_prefix, | ||
1002 | GNUNET_SERVER_MAX_MESSAGE_SIZE | ||
1003 | - sizeof (*req)) + 1; | ||
1004 | |||
997 | struct GNUNET_PSYCSTORE_OperationHandle * | 1005 | struct GNUNET_PSYCSTORE_OperationHandle * |
998 | op = GNUNET_malloc (sizeof (*op) + sizeof (*req)); | 1006 | op = GNUNET_malloc (sizeof (*op) + sizeof (*req)); |
999 | op->h = h; | 1007 | op->h = h; |
@@ -1004,7 +1012,7 @@ GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h, | |||
1004 | req = (struct MessageGetRequest *) &op[1]; | 1012 | req = (struct MessageGetRequest *) &op[1]; |
1005 | op->msg = (struct GNUNET_MessageHeader *) req; | 1013 | op->msg = (struct GNUNET_MessageHeader *) req; |
1006 | req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_MESSAGE_GET); | 1014 | req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_MESSAGE_GET); |
1007 | req->header.size = htons (sizeof (*req)); | 1015 | req->header.size = htons (sizeof (*req) + method_size); |
1008 | req->channel_key = *channel_key; | 1016 | req->channel_key = *channel_key; |
1009 | req->first_message_id = GNUNET_htonll (first_message_id); | 1017 | req->first_message_id = GNUNET_htonll (first_message_id); |
1010 | req->last_message_id = GNUNET_htonll (last_message_id); | 1018 | req->last_message_id = GNUNET_htonll (last_message_id); |
@@ -1013,6 +1021,8 @@ GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h, | |||
1013 | req->slave_key = *slave_key; | 1021 | req->slave_key = *slave_key; |
1014 | req->do_membership_test = GNUNET_YES; | 1022 | req->do_membership_test = GNUNET_YES; |
1015 | } | 1023 | } |
1024 | memcpy (&req[1], method_prefix, method_size); | ||
1025 | ((char *) &req[1])[method_size - 1] = '\0'; | ||
1016 | 1026 | ||
1017 | op->op_id = get_next_op_id (h); | 1027 | op->op_id = get_next_op_id (h); |
1018 | req->op_id = GNUNET_htonll (op->op_id); | 1028 | req->op_id = GNUNET_htonll (op->op_id); |
@@ -1032,14 +1042,17 @@ GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h, | |||
1032 | * @param channel_key | 1042 | * @param channel_key |
1033 | * The channel we are interested in. | 1043 | * The channel we are interested in. |
1034 | * @param slave_key | 1044 | * @param slave_key |
1035 | * The slave requesting the message. If not NULL, a membership test is | 1045 | * The slave requesting the message. |
1036 | * performed first and the message is only returned if the slave has | 1046 | * If not NULL, a membership test is performed first |
1037 | * access to it. | 1047 | * and the message is only returned if the slave has access to it. |
1038 | * @param message_limit | 1048 | * @param message_limit |
1039 | * Maximum number of messages to retrieve. | 1049 | * Maximum number of messages to retrieve. |
1050 | * @param method_prefix | ||
1051 | * Retrieve only messages with a matching method prefix. | ||
1052 | * @todo Implement method_prefix query. | ||
1040 | * @param fragment_cb | 1053 | * @param fragment_cb |
1041 | * Callback to call with the retrieved fragments. | 1054 | * Callback to call with the retrieved fragments. |
1042 | * @param rcb | 1055 | * @param result_cb |
1043 | * Callback to call with the result of the operation. | 1056 | * Callback to call with the result of the operation. |
1044 | * @param cls | 1057 | * @param cls |
1045 | * Closure for the callbacks. | 1058 | * Closure for the callbacks. |
@@ -1051,13 +1064,22 @@ GNUNET_PSYCSTORE_message_get_latest (struct GNUNET_PSYCSTORE_Handle *h, | |||
1051 | const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key, | 1064 | const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key, |
1052 | const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key, | 1065 | const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key, |
1053 | uint64_t message_limit, | 1066 | uint64_t message_limit, |
1067 | const char *method_prefix, | ||
1054 | GNUNET_PSYCSTORE_FragmentCallback fragment_cb, | 1068 | GNUNET_PSYCSTORE_FragmentCallback fragment_cb, |
1055 | GNUNET_PSYCSTORE_ResultCallback rcb, | 1069 | GNUNET_PSYCSTORE_ResultCallback rcb, |
1056 | void *cls) | 1070 | void *cls) |
1057 | { | 1071 | { |
1058 | struct MessageGetRequest *req; | 1072 | struct MessageGetRequest *req; |
1073 | |||
1074 | if (NULL == method_prefix) | ||
1075 | method_prefix = ""; | ||
1076 | uint16_t method_size = strnlen (method_prefix, | ||
1077 | GNUNET_SERVER_MAX_MESSAGE_SIZE | ||
1078 | - sizeof (*req)) + 1; | ||
1079 | GNUNET_assert ('\0' == method_prefix[method_size - 1]); | ||
1080 | |||
1059 | struct GNUNET_PSYCSTORE_OperationHandle * | 1081 | struct GNUNET_PSYCSTORE_OperationHandle * |
1060 | op = GNUNET_malloc (sizeof (*op) + sizeof (*req)); | 1082 | op = GNUNET_malloc (sizeof (*op) + sizeof (*req) + method_size); |
1061 | op->h = h; | 1083 | op->h = h; |
1062 | op->data_cb = (DataCallback) fragment_cb; | 1084 | op->data_cb = (DataCallback) fragment_cb; |
1063 | op->res_cb = rcb; | 1085 | op->res_cb = rcb; |
@@ -1066,7 +1088,7 @@ GNUNET_PSYCSTORE_message_get_latest (struct GNUNET_PSYCSTORE_Handle *h, | |||
1066 | req = (struct MessageGetRequest *) &op[1]; | 1088 | req = (struct MessageGetRequest *) &op[1]; |
1067 | op->msg = (struct GNUNET_MessageHeader *) req; | 1089 | op->msg = (struct GNUNET_MessageHeader *) req; |
1068 | req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_MESSAGE_GET); | 1090 | req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_MESSAGE_GET); |
1069 | req->header.size = htons (sizeof (*req)); | 1091 | req->header.size = htons (sizeof (*req) + method_size); |
1070 | req->channel_key = *channel_key; | 1092 | req->channel_key = *channel_key; |
1071 | req->message_limit = GNUNET_ntohll (message_limit); | 1093 | req->message_limit = GNUNET_ntohll (message_limit); |
1072 | if (NULL != slave_key) | 1094 | if (NULL != slave_key) |
@@ -1077,6 +1099,7 @@ GNUNET_PSYCSTORE_message_get_latest (struct GNUNET_PSYCSTORE_Handle *h, | |||
1077 | 1099 | ||
1078 | op->op_id = get_next_op_id (h); | 1100 | op->op_id = get_next_op_id (h); |
1079 | req->op_id = GNUNET_htonll (op->op_id); | 1101 | req->op_id = GNUNET_htonll (op->op_id); |
1102 | memcpy (&req[1], method_prefix, method_size); | ||
1080 | 1103 | ||
1081 | GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op); | 1104 | GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op); |
1082 | transmit_next (h); | 1105 | transmit_next (h); |