diff options
author | Gabor X Toth <*@tg-x.net> | 2015-08-28 13:33:43 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2015-08-28 13:33:43 +0000 |
commit | 38963d1e81332032e0ac774f4f2c6b804c38802a (patch) | |
tree | ce33b979e47fe332c7c744744d60077a7e1fefee | |
parent | b4fa14499c64140273850569247abda687803053 (diff) | |
download | gnunet-38963d1e81332032e0ac774f4f2c6b804c38802a.tar.gz gnunet-38963d1e81332032e0ac774f4f2c6b804c38802a.zip |
psyc/social: get state from psycstore
-rw-r--r-- | src/include/gnunet_psyc_service.h | 28 | ||||
-rw-r--r-- | src/include/gnunet_psyc_util_lib.h | 17 | ||||
-rw-r--r-- | src/include/gnunet_psycstore_service.h | 2 | ||||
-rw-r--r-- | src/psyc/gnunet-service-psyc.c | 156 | ||||
-rw-r--r-- | src/psyc/psyc_api.c | 22 | ||||
-rw-r--r-- | src/psyc/test_psyc.c | 20 | ||||
-rw-r--r-- | src/psycstore/gnunet-service-psycstore.c | 78 | ||||
-rw-r--r-- | src/psycstore/plugin_psycstore_sqlite.c | 38 | ||||
-rw-r--r-- | src/psycstore/psyc_util_lib.c | 40 | ||||
-rw-r--r-- | src/psycstore/test_plugin_psycstore.c | 2 | ||||
-rw-r--r-- | src/psycstore/test_psycstore.c | 2 | ||||
-rw-r--r-- | src/social/gnunet-service-social.c | 133 | ||||
-rw-r--r-- | src/social/social_api.c | 68 | ||||
-rw-r--r-- | src/social/test_social.c | 125 |
14 files changed, 556 insertions, 175 deletions
diff --git a/src/include/gnunet_psyc_service.h b/src/include/gnunet_psyc_service.h index 92397ec2e..1346e77c7 100644 --- a/src/include/gnunet_psyc_service.h +++ b/src/include/gnunet_psyc_service.h | |||
@@ -220,7 +220,8 @@ struct GNUNET_PSYC_Message | |||
220 | /** | 220 | /** |
221 | * Header of a PSYC message. | 221 | * Header of a PSYC message. |
222 | * | 222 | * |
223 | * Only present when receiving a message. | 223 | * The PSYC service adds this when delivering the message to local clients, |
224 | * not present on the multicast layer. | ||
224 | */ | 225 | */ |
225 | struct GNUNET_PSYC_MessageHeader | 226 | struct GNUNET_PSYC_MessageHeader |
226 | { | 227 | { |
@@ -1193,17 +1194,30 @@ GNUNET_PSYC_channel_history_replay_cancel (struct GNUNET_PSYC_Channel *channel, | |||
1193 | /** | 1194 | /** |
1194 | * Function called to inform a member about stored state values for a channel. | 1195 | * Function called to inform a member about stored state values for a channel. |
1195 | * | 1196 | * |
1196 | * @param cls Closure. | 1197 | * If @a full_value_size > value_size then this function is called multiple |
1197 | * @param name Name of the state variable. A NULL value indicates that there | 1198 | * times until the whole value arrived. |
1198 | * are no more state variables to be returned. | 1199 | * |
1199 | * @param value Value of the state variable. | 1200 | * @param cls |
1200 | * @param value_size Number of bytes in @a value. | 1201 | * Closure. |
1202 | * @param name | ||
1203 | * Name of the state variable. | ||
1204 | * NULL if there are no more state variables to be returned. | ||
1205 | * @param value | ||
1206 | * Value of the state variable. | ||
1207 | * @param value_size | ||
1208 | * Number of bytes in @a value. | ||
1209 | * @param full_value_size | ||
1210 | * Number of bytes in the full value, including continuations. | ||
1211 | * Only set for the first part of a variable, | ||
1212 | * in case of a continuation it is 0. | ||
1201 | */ | 1213 | */ |
1202 | typedef void | 1214 | typedef void |
1203 | (*GNUNET_PSYC_StateVarCallback) (void *cls, | 1215 | (*GNUNET_PSYC_StateVarCallback) (void *cls, |
1216 | const struct GNUNET_MessageHeader *mod, | ||
1204 | const char *name, | 1217 | const char *name, |
1205 | const void *value, | 1218 | const void *value, |
1206 | size_t value_size); | 1219 | uint32_t value_size, |
1220 | uint32_t full_value_size); | ||
1207 | 1221 | ||
1208 | 1222 | ||
1209 | /** | 1223 | /** |
diff --git a/src/include/gnunet_psyc_util_lib.h b/src/include/gnunet_psyc_util_lib.h index c5dae975f..504476573 100644 --- a/src/include/gnunet_psyc_util_lib.h +++ b/src/include/gnunet_psyc_util_lib.h | |||
@@ -230,6 +230,23 @@ GNUNET_PSYC_receive_check_parts (uint16_t data_size, const char *data, | |||
230 | uint16_t *first_ptype, uint16_t *last_ptype); | 230 | uint16_t *first_ptype, uint16_t *last_ptype); |
231 | 231 | ||
232 | 232 | ||
233 | /** | ||
234 | * Initialize PSYC message header. | ||
235 | */ | ||
236 | void | ||
237 | GNUNET_PSYC_message_header_init (struct GNUNET_PSYC_MessageHeader *pmsg, | ||
238 | const struct GNUNET_MULTICAST_MessageHeader *mmsg, | ||
239 | uint32_t flags); | ||
240 | |||
241 | |||
242 | /** | ||
243 | * Create a new PSYC message header from a multicast message for sending it to clients. | ||
244 | */ | ||
245 | struct GNUNET_PSYC_MessageHeader * | ||
246 | GNUNET_PSYC_message_header_create (const struct GNUNET_MULTICAST_MessageHeader *mmsg, | ||
247 | uint32_t flags); | ||
248 | |||
249 | |||
233 | #if 0 /* keep Emacsens' auto-indent happy */ | 250 | #if 0 /* keep Emacsens' auto-indent happy */ |
234 | { | 251 | { |
235 | #endif | 252 | #endif |
diff --git a/src/include/gnunet_psycstore_service.h b/src/include/gnunet_psycstore_service.h index 8f3866bdb..17d53b34d 100644 --- a/src/include/gnunet_psycstore_service.h +++ b/src/include/gnunet_psycstore_service.h | |||
@@ -612,7 +612,7 @@ GNUNET_PSYCSTORE_state_hash_update (struct GNUNET_PSYCSTORE_Handle *h, | |||
612 | */; | 612 | */; |
613 | typedef int | 613 | typedef int |
614 | (*GNUNET_PSYCSTORE_StateCallback) (void *cls, const char *name, | 614 | (*GNUNET_PSYCSTORE_StateCallback) (void *cls, const char *name, |
615 | const void *value, size_t value_size); | 615 | const void *value, uint32_t value_size); |
616 | 616 | ||
617 | 617 | ||
618 | /** | 618 | /** |
diff --git a/src/psyc/gnunet-service-psyc.c b/src/psyc/gnunet-service-psyc.c index 4c34f6108..2afc98040 100644 --- a/src/psyc/gnunet-service-psyc.c +++ b/src/psyc/gnunet-service-psyc.c | |||
@@ -1,3 +1,4 @@ | |||
1 | |||
1 | /* | 2 | /* |
2 | * This file is part of GNUnet | 3 | * This file is part of GNUnet |
3 | * Copyright (C) 2013 Christian Grothoff (and other contributing authors) | 4 | * Copyright (C) 2013 Christian Grothoff (and other contributing authors) |
@@ -171,6 +172,11 @@ struct FragmentQueue | |||
171 | uint8_t state; | 172 | uint8_t state; |
172 | 173 | ||
173 | /** | 174 | /** |
175 | * Whether the state is already modified in PSYCstore. | ||
176 | */ | ||
177 | uint8_t state_is_modified; | ||
178 | |||
179 | /** | ||
174 | * Is the message queued for delivery to the client? | 180 | * Is the message queued for delivery to the client? |
175 | * i.e. added to the recv_msgs queue | 181 | * i.e. added to the recv_msgs queue |
176 | */ | 182 | */ |
@@ -460,9 +466,9 @@ op_add (struct Channel *chn, struct GNUNET_SERVER_Client *client, | |||
460 | 466 | ||
461 | 467 | ||
462 | static void | 468 | static void |
463 | op_remove (struct Channel *chn, struct Operation *op) | 469 | op_remove (struct Operation *op) |
464 | { | 470 | { |
465 | GNUNET_CONTAINER_DLL_remove (chn->op_head, chn->op_tail, op); | 471 | GNUNET_CONTAINER_DLL_remove (op->chn->op_head, op->chn->op_tail, op); |
466 | GNUNET_free (op); | 472 | GNUNET_free (op); |
467 | } | 473 | } |
468 | 474 | ||
@@ -1008,7 +1014,8 @@ client_send_mcast_msg (struct Channel *chn, | |||
1008 | chn, GNUNET_ntohll (mmsg->fragment_id), | 1014 | chn, GNUNET_ntohll (mmsg->fragment_id), |
1009 | GNUNET_ntohll (mmsg->message_id)); | 1015 | GNUNET_ntohll (mmsg->message_id)); |
1010 | 1016 | ||
1011 | struct GNUNET_PSYC_MessageHeader *pmsg = psyc_msg_new (mmsg, flags); | 1017 | struct GNUNET_PSYC_MessageHeader * |
1018 | pmsg = GNUNET_PSYC_message_header_create (mmsg, flags); | ||
1012 | client_send_msg (chn, &pmsg->header); | 1019 | client_send_msg (chn, &pmsg->header); |
1013 | GNUNET_free (pmsg); | 1020 | GNUNET_free (pmsg); |
1014 | } | 1021 | } |
@@ -1049,7 +1056,7 @@ client_send_mcast_req (struct Master *mst, | |||
1049 | /** | 1056 | /** |
1050 | * Insert a multicast message fragment into the queue belonging to the message. | 1057 | * Insert a multicast message fragment into the queue belonging to the message. |
1051 | * | 1058 | * |
1052 | * @param chn Channel. | 1059 | * @param chn Channel. |
1053 | * @param mmsg Multicast message fragment. | 1060 | * @param mmsg Multicast message fragment. |
1054 | * @param msg_id_hash Message ID of @a mmsg in a struct GNUNET_HashCode. | 1061 | * @param msg_id_hash Message ID of @a mmsg in a struct GNUNET_HashCode. |
1055 | * @param first_ptype First PSYC message part type in @a mmsg. | 1062 | * @param first_ptype First PSYC message part type in @a mmsg. |
@@ -1222,7 +1229,7 @@ fragment_queue_run (struct Channel *chn, uint64_t msg_id, | |||
1222 | struct GNUNET_CONTAINER_MultiHashMap | 1229 | struct GNUNET_CONTAINER_MultiHashMap |
1223 | *chan_msgs = GNUNET_CONTAINER_multihashmap_get (recv_cache, | 1230 | *chan_msgs = GNUNET_CONTAINER_multihashmap_get (recv_cache, |
1224 | &chn->pub_key_hash); | 1231 | &chn->pub_key_hash); |
1225 | GNUNET_assert (NULL != chan_msgs); | 1232 | GNUNET_assert (NULL != chan_msgs); // FIXME |
1226 | uint64_t frag_id; | 1233 | uint64_t frag_id; |
1227 | 1234 | ||
1228 | while (GNUNET_YES == GNUNET_CONTAINER_heap_peek2 (fragq->fragments, NULL, | 1235 | while (GNUNET_YES == GNUNET_CONTAINER_heap_peek2 (fragq->fragments, NULL, |
@@ -1279,8 +1286,8 @@ fragment_queue_run (struct Channel *chn, uint64_t msg_id, | |||
1279 | struct StateModifyClosure | 1286 | struct StateModifyClosure |
1280 | { | 1287 | { |
1281 | struct Channel *chn; | 1288 | struct Channel *chn; |
1282 | struct FragmentQueue *fragq; | 1289 | uint64_t msg_id; |
1283 | uint64_t message_id; | 1290 | struct GNUNET_HashCode msg_id_hash; |
1284 | }; | 1291 | }; |
1285 | 1292 | ||
1286 | 1293 | ||
@@ -1290,21 +1297,37 @@ store_recv_state_modify_result (void *cls, int64_t result, | |||
1290 | { | 1297 | { |
1291 | struct StateModifyClosure *mcls = cls; | 1298 | struct StateModifyClosure *mcls = cls; |
1292 | struct Channel *chn = mcls->chn; | 1299 | struct Channel *chn = mcls->chn; |
1293 | struct FragmentQueue *fragq = mcls->fragq; | 1300 | uint64_t msg_id = mcls->msg_id; |
1294 | uint64_t msg_id = mcls->message_id; | 1301 | |
1302 | struct FragmentQueue * | ||
1303 | fragq = GNUNET_CONTAINER_multihashmap_get (chn->recv_frags, &mcls->msg_id_hash); | ||
1295 | 1304 | ||
1296 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1305 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1297 | "%p GNUNET_PSYCSTORE_state_modify() returned %" PRId64 " (%.*s)\n", | 1306 | "%p GNUNET_PSYCSTORE_state_modify() returned %" PRId64 " (%.*s)\n", |
1298 | chn, result, err_msg_size, err_msg); | 1307 | chn, result, err_msg_size, err_msg); |
1299 | 1308 | ||
1300 | if (GNUNET_OK == result) | 1309 | switch (result) |
1301 | { | 1310 | { |
1302 | chn->max_state_message_id = msg_id; | 1311 | case GNUNET_OK: |
1303 | chn->max_message_id = msg_id; | 1312 | case GNUNET_NO: |
1313 | if (NULL != fragq) | ||
1314 | fragq->state_is_modified = GNUNET_YES; | ||
1315 | if (chn->max_state_message_id < msg_id) | ||
1316 | chn->max_state_message_id = msg_id; | ||
1317 | if (chn->max_message_id < msg_id) | ||
1318 | chn->max_message_id = msg_id; | ||
1304 | 1319 | ||
1305 | fragment_queue_run (chn, msg_id, fragq, MSG_FRAG_STATE_DROP == fragq->state); | 1320 | if (NULL != fragq) |
1321 | fragment_queue_run (chn, msg_id, fragq, MSG_FRAG_STATE_DROP == fragq->state); | ||
1306 | GNUNET_CONTAINER_heap_remove_root (chn->recv_msgs); | 1322 | GNUNET_CONTAINER_heap_remove_root (chn->recv_msgs); |
1307 | message_queue_run (chn); | 1323 | message_queue_run (chn); |
1324 | break; | ||
1325 | |||
1326 | default: | ||
1327 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1328 | "%p GNUNET_PSYCSTORE_state_modify() failed with error %" PRId64 " (%.*s)\n", | ||
1329 | chn, result, err_msg_size, err_msg); | ||
1330 | /** @todo FIXME: handle state_modify error */ | ||
1308 | } | 1331 | } |
1309 | } | 1332 | } |
1310 | 1333 | ||
@@ -1349,42 +1372,58 @@ message_queue_run (struct Channel *chn) | |||
1349 | break; | 1372 | break; |
1350 | } | 1373 | } |
1351 | 1374 | ||
1352 | if (MSG_FRAG_STATE_HEADER == fragq->state) | 1375 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1376 | "%p Fragment queue entry: state: %u, state delta: " | ||
1377 | "%" PRIu64 " - %" PRIu64 " ?= %" PRIu64 "\n", | ||
1378 | chn, fragq->state, msg_id, fragq->state_delta, chn->max_state_message_id); | ||
1379 | |||
1380 | if (MSG_FRAG_STATE_DATA <= fragq->state) | ||
1353 | { | 1381 | { |
1354 | /* Check if there's a missing message before the current one */ | 1382 | /* Check if there's a missing message before the current one */ |
1355 | if (GNUNET_PSYC_STATE_NOT_MODIFIED == fragq->state_delta) | 1383 | if (GNUNET_PSYC_STATE_NOT_MODIFIED == fragq->state_delta) |
1356 | { | 1384 | { |
1385 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%p state NOT modified\n"); | ||
1386 | |||
1357 | if (!(fragq->flags & GNUNET_PSYC_MESSAGE_ORDER_ANY) | 1387 | if (!(fragq->flags & GNUNET_PSYC_MESSAGE_ORDER_ANY) |
1358 | && msg_id - 1 != chn->max_message_id) | 1388 | && (chn->max_message_id != msg_id - 1 |
1389 | && chn->max_message_id != msg_id)) | ||
1359 | { | 1390 | { |
1360 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1391 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1361 | "%p Out of order message. " | 1392 | "%p Out of order message. " |
1362 | "(%" PRIu64 " - 1 != %" PRIu64 ")\n", | 1393 | "(%" PRIu64 " != %" PRIu64 " - 1)\n", |
1363 | chn, msg_id, chn->max_message_id); | 1394 | chn, chn->max_message_id, msg_id); |
1364 | continue; | 1395 | break; |
1396 | // FIXME: keep track of messages processed in this queue run, | ||
1397 | // and only stop after reaching the end | ||
1365 | } | 1398 | } |
1366 | } | 1399 | } |
1367 | else | 1400 | else |
1368 | { | 1401 | { |
1369 | if (msg_id - fragq->state_delta != chn->max_state_message_id) | 1402 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%p state modified\n"); |
1403 | if (GNUNET_YES != fragq->state_is_modified) | ||
1370 | { | 1404 | { |
1371 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1405 | if (msg_id - fragq->state_delta != chn->max_state_message_id) |
1372 | "%p Out of order stateful message. " | 1406 | { |
1373 | "(%" PRIu64 " - %" PRIu64 " != %" PRIu64 ")\n", | 1407 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1374 | chn, msg_id, fragq->state_delta, chn->max_state_message_id); | 1408 | "%p Out of order stateful message. " |
1375 | continue; | 1409 | "(%" PRIu64 " - %" PRIu64 " != %" PRIu64 ")\n", |
1410 | chn, msg_id, fragq->state_delta, chn->max_state_message_id); | ||
1411 | break; | ||
1412 | // FIXME: keep track of messages processed in this queue run, | ||
1413 | // and only stop after reaching the end | ||
1414 | } | ||
1415 | |||
1416 | struct StateModifyClosure *mcls = GNUNET_malloc (sizeof (*mcls)); | ||
1417 | mcls->chn = chn; | ||
1418 | mcls->msg_id = msg_id; | ||
1419 | mcls->msg_id_hash = msg_id_hash; | ||
1420 | |||
1421 | /* Apply modifiers to state in PSYCstore */ | ||
1422 | GNUNET_PSYCSTORE_state_modify (store, &chn->pub_key, msg_id, | ||
1423 | fragq->state_delta, | ||
1424 | store_recv_state_modify_result, mcls); | ||
1425 | break; // continue after asynchronous state modify result | ||
1376 | } | 1426 | } |
1377 | |||
1378 | struct StateModifyClosure *mcls = GNUNET_malloc (sizeof (*mcls)); | ||
1379 | mcls->chn = chn; | ||
1380 | mcls->fragq = fragq; | ||
1381 | mcls->message_id = msg_id; | ||
1382 | |||
1383 | /* Apply modifiers to state in PSYCstore */ | ||
1384 | GNUNET_PSYCSTORE_state_modify (store, &chn->pub_key, msg_id, | ||
1385 | fragq->state_delta, | ||
1386 | store_recv_state_modify_result, mcls); | ||
1387 | break; | ||
1388 | } | 1427 | } |
1389 | chn->max_message_id = msg_id; | 1428 | chn->max_message_id = msg_id; |
1390 | } | 1429 | } |
@@ -2060,7 +2099,7 @@ static void | |||
2060 | master_queue_message (struct Master *mst, struct TransmitMessage *tmit_msg, | 2099 | master_queue_message (struct Master *mst, struct TransmitMessage *tmit_msg, |
2061 | uint16_t first_ptype, uint16_t last_ptype) | 2100 | uint16_t first_ptype, uint16_t last_ptype) |
2062 | { | 2101 | { |
2063 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%p master_queue_message()\n", mst); | 2102 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%p master_queue_message()\n", mst); |
2064 | 2103 | ||
2065 | if (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD == first_ptype) | 2104 | if (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD == first_ptype) |
2066 | { | 2105 | { |
@@ -2074,11 +2113,13 @@ master_queue_message (struct Master *mst, struct TransmitMessage *tmit_msg, | |||
2074 | } | 2113 | } |
2075 | else if (pmeth->flags & GNUNET_PSYC_MASTER_TRANSMIT_STATE_MODIFY) | 2114 | else if (pmeth->flags & GNUNET_PSYC_MASTER_TRANSMIT_STATE_MODIFY) |
2076 | { | 2115 | { |
2116 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%p master_queue_message: setting state_modify flag\n", mst); | ||
2077 | pmeth->state_delta = GNUNET_htonll (tmit_msg->id | 2117 | pmeth->state_delta = GNUNET_htonll (tmit_msg->id |
2078 | - mst->max_state_message_id); | 2118 | - mst->max_state_message_id); |
2079 | } | 2119 | } |
2080 | else | 2120 | else |
2081 | { | 2121 | { |
2122 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%p master_queue_message: setting state_not_modified flag\n", mst); | ||
2082 | pmeth->state_delta = GNUNET_htonll (GNUNET_PSYC_STATE_NOT_MODIFIED); | 2123 | pmeth->state_delta = GNUNET_htonll (GNUNET_PSYC_STATE_NOT_MODIFIED); |
2083 | } | 2124 | } |
2084 | 2125 | ||
@@ -2226,14 +2267,6 @@ client_recv_psyc_message (void *cls, struct GNUNET_SERVER_Client *client, | |||
2226 | }; | 2267 | }; |
2227 | 2268 | ||
2228 | 2269 | ||
2229 | struct MembershipStoreClosure | ||
2230 | { | ||
2231 | struct GNUNET_SERVER_Client *client; | ||
2232 | struct Channel *chn; | ||
2233 | uint64_t op_id; | ||
2234 | }; | ||
2235 | |||
2236 | |||
2237 | /** | 2270 | /** |
2238 | * Received result of GNUNET_PSYCSTORE_membership_store() | 2271 | * Received result of GNUNET_PSYCSTORE_membership_store() |
2239 | */ | 2272 | */ |
@@ -2241,12 +2274,13 @@ static void | |||
2241 | store_recv_membership_store_result (void *cls, int64_t result, | 2274 | store_recv_membership_store_result (void *cls, int64_t result, |
2242 | const char *err_msg, uint16_t err_msg_size) | 2275 | const char *err_msg, uint16_t err_msg_size) |
2243 | { | 2276 | { |
2244 | struct MembershipStoreClosure *mcls = cls; | 2277 | struct Operation *op = cls; |
2245 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2278 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2246 | "%p GNUNET_PSYCSTORE_membership_store() returned %" PRId64 " (%.s)\n", | 2279 | "%p GNUNET_PSYCSTORE_membership_store() returned %" PRId64 " (%.s)\n", |
2247 | mcls->chn, result, err_msg_size, err_msg); | 2280 | op->chn, result, err_msg_size, err_msg); |
2248 | 2281 | ||
2249 | client_send_result (mcls->client, mcls->op_id, result, err_msg, err_msg_size); | 2282 | client_send_result (op->client, op->op_id, result, err_msg, err_msg_size); |
2283 | op_remove (op); | ||
2250 | } | 2284 | } |
2251 | 2285 | ||
2252 | 2286 | ||
@@ -2264,10 +2298,7 @@ client_recv_membership_store (void *cls, struct GNUNET_SERVER_Client *client, | |||
2264 | const struct ChannelMembershipStoreRequest * | 2298 | const struct ChannelMembershipStoreRequest * |
2265 | req = (const struct ChannelMembershipStoreRequest *) msg; | 2299 | req = (const struct ChannelMembershipStoreRequest *) msg; |
2266 | 2300 | ||
2267 | struct MembershipStoreClosure *mcls = GNUNET_malloc (sizeof (*mcls)); | 2301 | struct Operation *op = op_add (chn, client, req->op_id, 0); |
2268 | mcls->client = client; | ||
2269 | mcls->chn = chn; | ||
2270 | mcls->op_id = req->op_id; | ||
2271 | 2302 | ||
2272 | uint64_t announced_at = GNUNET_ntohll (req->announced_at); | 2303 | uint64_t announced_at = GNUNET_ntohll (req->announced_at); |
2273 | uint64_t effective_since = GNUNET_ntohll (req->effective_since); | 2304 | uint64_t effective_since = GNUNET_ntohll (req->effective_since); |
@@ -2280,7 +2311,7 @@ client_recv_membership_store (void *cls, struct GNUNET_SERVER_Client *client, | |||
2280 | GNUNET_PSYCSTORE_membership_store (store, &chn->pub_key, &req->slave_key, | 2311 | GNUNET_PSYCSTORE_membership_store (store, &chn->pub_key, &req->slave_key, |
2281 | req->did_join, announced_at, effective_since, | 2312 | req->did_join, announced_at, effective_since, |
2282 | 0, /* FIXME: group_generation */ | 2313 | 0, /* FIXME: group_generation */ |
2283 | &store_recv_membership_store_result, mcls); | 2314 | &store_recv_membership_store_result, op); |
2284 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 2315 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2285 | } | 2316 | } |
2286 | 2317 | ||
@@ -2313,7 +2344,7 @@ store_recv_fragment_history (void *cls, | |||
2313 | res->result_code = GNUNET_htonll (GNUNET_OK); | 2344 | res->result_code = GNUNET_htonll (GNUNET_OK); |
2314 | 2345 | ||
2315 | pmsg = (struct GNUNET_PSYC_MessageHeader *) &res[1]; | 2346 | pmsg = (struct GNUNET_PSYC_MessageHeader *) &res[1]; |
2316 | psyc_msg_init (pmsg, mmsg, flags | GNUNET_PSYC_MESSAGE_HISTORIC); | 2347 | GNUNET_PSYC_message_header_init (pmsg, mmsg, flags | GNUNET_PSYC_MESSAGE_HISTORIC); |
2317 | memcpy (&res[1], pmsg, psize); | 2348 | memcpy (&res[1], pmsg, psize); |
2318 | 2349 | ||
2319 | /** @todo FIXME: send only to requesting client */ | 2350 | /** @todo FIXME: send only to requesting client */ |
@@ -2339,7 +2370,7 @@ store_recv_fragment_history_result (void *cls, int64_t result, | |||
2339 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2370 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2340 | "%p History replay #%" PRIu64 ": " | 2371 | "%p History replay #%" PRIu64 ": " |
2341 | "PSYCSTORE returned %" PRId64 " (%.*s)\n", | 2372 | "PSYCSTORE returned %" PRId64 " (%.*s)\n", |
2342 | op->chn, op->op_id, result, err_msg_size, err_msg); | 2373 | op->chn, GNUNET_ntohll (op->op_id), result, err_msg_size, err_msg); |
2343 | 2374 | ||
2344 | if (op->flags & GNUNET_PSYC_HISTORY_REPLAY_REMOTE) | 2375 | if (op->flags & GNUNET_PSYC_HISTORY_REPLAY_REMOTE) |
2345 | { | 2376 | { |
@@ -2347,6 +2378,7 @@ store_recv_fragment_history_result (void *cls, int64_t result, | |||
2347 | } | 2378 | } |
2348 | 2379 | ||
2349 | client_send_result (op->client, op->op_id, result, err_msg, err_msg_size); | 2380 | client_send_result (op->client, op->op_id, result, err_msg, err_msg_size); |
2381 | op_remove (op); | ||
2350 | } | 2382 | } |
2351 | 2383 | ||
2352 | 2384 | ||
@@ -2404,12 +2436,16 @@ client_recv_history_replay (void *cls, struct GNUNET_SERVER_Client *client, | |||
2404 | */ | 2436 | */ |
2405 | static int | 2437 | static int |
2406 | store_recv_state_var (void *cls, const char *name, | 2438 | store_recv_state_var (void *cls, const char *name, |
2407 | const void *value, size_t value_size) | 2439 | const void *value, uint32_t value_size) |
2408 | { | 2440 | { |
2409 | struct Operation *op = cls; | 2441 | struct Operation *op = cls; |
2410 | struct GNUNET_OperationResultMessage *res; | 2442 | struct GNUNET_OperationResultMessage *res; |
2411 | 2443 | ||
2412 | if (NULL != name) | 2444 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2445 | "%p state_get #%" PRIu64 " - received var from PSYCstore: %s\n", | ||
2446 | op->chn, GNUNET_ntohll (op->op_id), name); | ||
2447 | |||
2448 | if (NULL != name) /* First part */ | ||
2413 | { | 2449 | { |
2414 | uint16_t name_size = strnlen (name, GNUNET_PSYC_MODIFIER_MAX_PAYLOAD) + 1; | 2450 | uint16_t name_size = strnlen (name, GNUNET_PSYC_MODIFIER_MAX_PAYLOAD) + 1; |
2415 | struct GNUNET_PSYC_MessageModifier *mod; | 2451 | struct GNUNET_PSYC_MessageModifier *mod; |
@@ -2427,7 +2463,7 @@ store_recv_state_var (void *cls, const char *name, | |||
2427 | memcpy (&mod[1], name, name_size); | 2463 | memcpy (&mod[1], name, name_size); |
2428 | memcpy (((char *) &mod[1]) + name_size, value, value_size); | 2464 | memcpy (((char *) &mod[1]) + name_size, value, value_size); |
2429 | } | 2465 | } |
2430 | else | 2466 | else /* Continuation */ |
2431 | { | 2467 | { |
2432 | struct GNUNET_MessageHeader *mod; | 2468 | struct GNUNET_MessageHeader *mod; |
2433 | res = GNUNET_malloc (sizeof (*res) + sizeof (*mod) + value_size); | 2469 | res = GNUNET_malloc (sizeof (*res) + sizeof (*mod) + value_size); |
@@ -2445,7 +2481,6 @@ store_recv_state_var (void *cls, const char *name, | |||
2445 | GNUNET_SERVER_notification_context_add (nc, op->client); | 2481 | GNUNET_SERVER_notification_context_add (nc, op->client); |
2446 | GNUNET_SERVER_notification_context_unicast (nc, op->client, &res->header, | 2482 | GNUNET_SERVER_notification_context_unicast (nc, op->client, &res->header, |
2447 | GNUNET_NO); | 2483 | GNUNET_NO); |
2448 | GNUNET_free (op); | ||
2449 | return GNUNET_YES; | 2484 | return GNUNET_YES; |
2450 | } | 2485 | } |
2451 | 2486 | ||
@@ -2460,12 +2495,13 @@ store_recv_state_result (void *cls, int64_t result, | |||
2460 | { | 2495 | { |
2461 | struct Operation *op = cls; | 2496 | struct Operation *op = cls; |
2462 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2497 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2463 | "%p History replay #%" PRIu64 ": " | 2498 | "%p state_get #%" PRIu64 ": " |
2464 | "PSYCSTORE returned %" PRId64 " (%.*s)\n", | 2499 | "PSYCSTORE returned %" PRId64 " (%.*s)\n", |
2465 | op->chn, op->op_id, result, err_msg_size, err_msg); | 2500 | op->chn, GNUNET_ntohll (op->op_id), result, err_msg_size, err_msg); |
2466 | 2501 | ||
2467 | // FIXME: client might have been disconnected | 2502 | // FIXME: client might have been disconnected |
2468 | client_send_result (op->client, op->op_id, result, err_msg, err_msg_size); | 2503 | client_send_result (op->client, op->op_id, result, err_msg, err_msg_size); |
2504 | op_remove (op); | ||
2469 | } | 2505 | } |
2470 | 2506 | ||
2471 | 2507 | ||
diff --git a/src/psyc/psyc_api.c b/src/psyc/psyc_api.c index 5fc5391a0..b862eee9c 100644 --- a/src/psyc/psyc_api.c +++ b/src/psyc/psyc_api.c | |||
@@ -366,34 +366,36 @@ channel_recv_state_result (void *cls, | |||
366 | } | 366 | } |
367 | 367 | ||
368 | const struct GNUNET_MessageHeader * | 368 | const struct GNUNET_MessageHeader * |
369 | modc = (struct GNUNET_MessageHeader *) &res[1]; | 369 | mod = (struct GNUNET_MessageHeader *) &res[1]; |
370 | uint16_t modc_size = ntohs (modc->size); | 370 | uint16_t mod_size = ntohs (mod->size); |
371 | if (ntohs (msg->size) - sizeof (*msg) != modc_size) | 371 | if (ntohs (msg->size) - sizeof (*res) != mod_size) |
372 | { | 372 | { |
373 | GNUNET_break (0); | 373 | GNUNET_break (0); |
374 | return; | 374 | return; |
375 | } | 375 | } |
376 | switch (ntohs (modc->type)) | 376 | switch (ntohs (mod->type)) |
377 | { | 377 | { |
378 | case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MODIFIER: | 378 | case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MODIFIER: |
379 | { | 379 | { |
380 | const struct GNUNET_PSYC_MessageModifier * | 380 | const struct GNUNET_PSYC_MessageModifier * |
381 | mod = (const struct GNUNET_PSYC_MessageModifier *) modc; | 381 | pmod = (const struct GNUNET_PSYC_MessageModifier *) mod; |
382 | 382 | ||
383 | const char *name = (const char *) &mod[1]; | 383 | const char *name = (const char *) &pmod[1]; |
384 | uint16_t name_size = ntohs (mod->name_size); | 384 | uint16_t name_size = ntohs (pmod->name_size); |
385 | if ('\0' != name[name_size - 1]) | 385 | if ('\0' != name[name_size - 1]) |
386 | { | 386 | { |
387 | GNUNET_break (0); | 387 | GNUNET_break (0); |
388 | return; | 388 | return; |
389 | } | 389 | } |
390 | sr->var_cb (sr->cls, name, name + name_size, ntohs (mod->value_size)); | 390 | sr->var_cb (sr->cls, mod, name, name + name_size, |
391 | ntohs (pmod->header.size) - sizeof (*pmod), | ||
392 | ntohs (pmod->value_size)); | ||
391 | break; | 393 | break; |
392 | } | 394 | } |
393 | 395 | ||
394 | case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MOD_CONT: | 396 | case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MOD_CONT: |
395 | sr->var_cb (sr->cls, NULL, (const char *) &modc[1], | 397 | sr->var_cb (sr->cls, mod, NULL, (const char *) &mod[1], |
396 | modc_size - sizeof (*modc)); | 398 | mod_size - sizeof (*mod), 0); |
397 | break; | 399 | break; |
398 | } | 400 | } |
399 | } | 401 | } |
diff --git a/src/psyc/test_psyc.c b/src/psyc/test_psyc.c index d62474afb..4e7979a4d 100644 --- a/src/psyc/test_psyc.c +++ b/src/psyc/test_psyc.c | |||
@@ -329,7 +329,9 @@ slave_message_part_cb (void *cls, uint64_t message_id, | |||
329 | 329 | ||
330 | 330 | ||
331 | void | 331 | void |
332 | state_get_var (void *cls, const char *name, const void *value, size_t value_size) | 332 | state_get_var (void *cls, const struct GNUNET_MessageHeader *mod, |
333 | const char *name, const void *value, | ||
334 | uint32_t value_size, uint32_t full_value_size) | ||
333 | { | 335 | { |
334 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 336 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
335 | "Got state var: %s\n%.*s\n", name, value_size, value); | 337 | "Got state var: %s\n%.*s\n", name, value_size, value); |
@@ -354,8 +356,8 @@ void | |||
354 | slave_state_get_prefix () | 356 | slave_state_get_prefix () |
355 | { | 357 | { |
356 | test = TEST_SLAVE_STATE_GET_PREFIX; | 358 | test = TEST_SLAVE_STATE_GET_PREFIX; |
357 | GNUNET_PSYC_channel_state_get_prefix (slv_chn, "_foo", &state_get_var, | 359 | GNUNET_PSYC_channel_state_get_prefix (slv_chn, "_foo", state_get_var, |
358 | &slave_state_get_prefix_result, NULL); | 360 | slave_state_get_prefix_result, NULL); |
359 | } | 361 | } |
360 | 362 | ||
361 | 363 | ||
@@ -377,8 +379,8 @@ void | |||
377 | master_state_get_prefix () | 379 | master_state_get_prefix () |
378 | { | 380 | { |
379 | test = TEST_MASTER_STATE_GET_PREFIX; | 381 | test = TEST_MASTER_STATE_GET_PREFIX; |
380 | GNUNET_PSYC_channel_state_get_prefix (mst_chn, "_foo", &state_get_var, | 382 | GNUNET_PSYC_channel_state_get_prefix (mst_chn, "_foo", state_get_var, |
381 | &master_state_get_prefix_result, NULL); | 383 | master_state_get_prefix_result, NULL); |
382 | } | 384 | } |
383 | 385 | ||
384 | 386 | ||
@@ -401,8 +403,8 @@ void | |||
401 | slave_state_get () | 403 | slave_state_get () |
402 | { | 404 | { |
403 | test = TEST_SLAVE_STATE_GET; | 405 | test = TEST_SLAVE_STATE_GET; |
404 | GNUNET_PSYC_channel_state_get (slv_chn, "_foo_bar_baz", &state_get_var, | 406 | GNUNET_PSYC_channel_state_get (slv_chn, "_foo_bar_baz", state_get_var, |
405 | &slave_state_get_result, NULL); | 407 | slave_state_get_result, NULL); |
406 | } | 408 | } |
407 | 409 | ||
408 | 410 | ||
@@ -425,8 +427,8 @@ void | |||
425 | master_state_get () | 427 | master_state_get () |
426 | { | 428 | { |
427 | test = TEST_MASTER_STATE_GET; | 429 | test = TEST_MASTER_STATE_GET; |
428 | GNUNET_PSYC_channel_state_get (mst_chn, "_foo_bar_baz", &state_get_var, | 430 | GNUNET_PSYC_channel_state_get (mst_chn, "_foo_bar_baz", state_get_var, |
429 | &master_state_get_result, NULL); | 431 | master_state_get_result, NULL); |
430 | } | 432 | } |
431 | 433 | ||
432 | 434 | ||
diff --git a/src/psycstore/gnunet-service-psycstore.c b/src/psycstore/gnunet-service-psycstore.c index 6e40e7849..1f9de54f8 100644 --- a/src/psycstore/gnunet-service-psycstore.c +++ b/src/psycstore/gnunet-service-psycstore.c | |||
@@ -217,7 +217,7 @@ send_fragment (void *cls, struct GNUNET_MULTICAST_MessageHeader *msg, | |||
217 | 217 | ||
218 | static int | 218 | static int |
219 | send_state_var (void *cls, const char *name, | 219 | send_state_var (void *cls, const char *name, |
220 | const void *value, size_t value_size) | 220 | const void *value, uint32_t value_size) |
221 | { | 221 | { |
222 | struct SendClosure *sc = cls; | 222 | struct SendClosure *sc = cls; |
223 | struct StateResult *res; | 223 | struct StateResult *res; |
@@ -496,14 +496,14 @@ handle_counters_get (void *cls, | |||
496 | 496 | ||
497 | struct StateModifyClosure | 497 | struct StateModifyClosure |
498 | { | 498 | { |
499 | const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key; | 499 | const struct GNUNET_CRYPTO_EddsaPublicKey channel_key; |
500 | struct GNUNET_PSYC_ReceiveHandle *recv; | 500 | struct GNUNET_PSYC_ReceiveHandle *recv; |
501 | enum GNUNET_PSYC_MessageState msg_state; | 501 | enum GNUNET_PSYC_MessageState msg_state; |
502 | char mod_oper; | 502 | char mod_oper; |
503 | char *mod_name; | 503 | char *mod_name; |
504 | char *mod_value; | 504 | char *mod_value; |
505 | uint64_t mod_value_size; | 505 | uint32_t mod_value_size; |
506 | uint64_t mod_value_remaining; | 506 | uint32_t mod_value_remaining; |
507 | }; | 507 | }; |
508 | 508 | ||
509 | 509 | ||
@@ -513,6 +513,12 @@ recv_state_message_part (void *cls, uint64_t message_id, uint64_t data_offset, | |||
513 | { | 513 | { |
514 | struct StateModifyClosure *scls = cls; | 514 | struct StateModifyClosure *scls = cls; |
515 | uint16_t psize; | 515 | uint16_t psize; |
516 | |||
517 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
518 | "recv_state_message_part() message_id: %" PRIu64 | ||
519 | ", data_offset: %" PRIu64 ", flags: %u\n", | ||
520 | message_id, data_offset, flags); | ||
521 | |||
516 | if (NULL == msg) | 522 | if (NULL == msg) |
517 | { | 523 | { |
518 | scls->msg_state = GNUNET_PSYC_MESSAGE_STATE_ERROR; | 524 | scls->msg_state = GNUNET_PSYC_MESSAGE_STATE_ERROR; |
@@ -533,7 +539,7 @@ recv_state_message_part (void *cls, uint64_t message_id, uint64_t data_offset, | |||
533 | pmod = (struct GNUNET_PSYC_MessageModifier *) msg; | 539 | pmod = (struct GNUNET_PSYC_MessageModifier *) msg; |
534 | psize = ntohs (pmod->header.size); | 540 | psize = ntohs (pmod->header.size); |
535 | uint16_t name_size = ntohs (pmod->name_size); | 541 | uint16_t name_size = ntohs (pmod->name_size); |
536 | uint16_t value_size = ntohs (pmod->value_size); | 542 | uint32_t value_size = ntohl (pmod->value_size); |
537 | 543 | ||
538 | const char *name = (const char *) &pmod[1]; | 544 | const char *name = (const char *) &pmod[1]; |
539 | const void *value = name + name_size; | 545 | const void *value = name + name_size; |
@@ -542,7 +548,7 @@ recv_state_message_part (void *cls, uint64_t message_id, uint64_t data_offset, | |||
542 | { // Apply non-transient operation. | 548 | { // Apply non-transient operation. |
543 | if (psize == sizeof (*pmod) + name_size + value_size) | 549 | if (psize == sizeof (*pmod) + name_size + value_size) |
544 | { | 550 | { |
545 | db->state_modify_op (db->cls, scls->channel_key, | 551 | db->state_modify_op (db->cls, &scls->channel_key, |
546 | pmod->oper, name, value, value_size); | 552 | pmod->oper, name, value, value_size); |
547 | } | 553 | } |
548 | else | 554 | else |
@@ -576,7 +582,7 @@ recv_state_message_part (void *cls, uint64_t message_id, uint64_t data_offset, | |||
576 | scls->mod_value_remaining -= psize - sizeof (*msg); | 582 | scls->mod_value_remaining -= psize - sizeof (*msg); |
577 | if (0 == scls->mod_value_remaining) | 583 | if (0 == scls->mod_value_remaining) |
578 | { | 584 | { |
579 | db->state_modify_op (db->cls, scls->channel_key, | 585 | db->state_modify_op (db->cls, &scls->channel_key, |
580 | scls->mod_oper, scls->mod_name, | 586 | scls->mod_oper, scls->mod_name, |
581 | scls->mod_value, scls->mod_value_size); | 587 | scls->mod_value, scls->mod_value_size); |
582 | GNUNET_free (scls->mod_name); | 588 | GNUNET_free (scls->mod_name); |
@@ -616,9 +622,13 @@ recv_state_fragment (void *cls, struct GNUNET_MULTICAST_MessageHeader *msg, | |||
616 | scls); | 622 | scls); |
617 | } | 623 | } |
618 | 624 | ||
619 | const struct GNUNET_PSYC_MessageHeader * | 625 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
620 | pmsg = (const struct GNUNET_PSYC_MessageHeader *) &msg[1]; | 626 | "recv_state_fragment: %" PRIu64 "\n", GNUNET_ntohll (msg->fragment_id)); |
627 | |||
628 | struct GNUNET_PSYC_MessageHeader * | ||
629 | pmsg = GNUNET_PSYC_message_header_create (msg, flags); | ||
621 | GNUNET_PSYC_receive_message (scls->recv, pmsg); | 630 | GNUNET_PSYC_receive_message (scls->recv, pmsg); |
631 | GNUNET_free (pmsg); | ||
622 | 632 | ||
623 | return GNUNET_YES; | 633 | return GNUNET_YES; |
624 | } | 634 | } |
@@ -635,31 +645,41 @@ handle_state_modify (void *cls, | |||
635 | uint64_t message_id = GNUNET_ntohll (req->message_id); | 645 | uint64_t message_id = GNUNET_ntohll (req->message_id); |
636 | uint64_t state_delta = GNUNET_ntohll (req->state_delta); | 646 | uint64_t state_delta = GNUNET_ntohll (req->state_delta); |
637 | uint64_t ret_frags = 0; | 647 | uint64_t ret_frags = 0; |
648 | struct StateModifyClosure | ||
649 | scls = { .channel_key = req->channel_key }; | ||
638 | 650 | ||
639 | struct StateModifyClosure scls = { 0 }; | 651 | int ret = db->state_modify_begin (db->cls, &req->channel_key, |
640 | 652 | message_id, state_delta); | |
641 | if (GNUNET_OK != db->state_modify_begin (db->cls, &req->channel_key, | ||
642 | message_id, state_delta)) | ||
643 | { | ||
644 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
645 | _("Failed to begin modifying state!\n")); | ||
646 | GNUNET_break (0); | ||
647 | } | ||
648 | |||
649 | int ret = db->message_get (db->cls, &req->channel_key, | ||
650 | message_id, message_id, | ||
651 | &ret_frags, &recv_state_fragment, &scls); | ||
652 | 653 | ||
653 | if (GNUNET_OK != db->state_modify_end (db->cls, &req->channel_key, message_id)) | 654 | if (GNUNET_OK != ret) |
654 | { | 655 | { |
655 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 656 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
656 | _("Failed to end modifying state!\n")); | 657 | _("Failed to begin modifying state: %d\n"), ret); |
657 | GNUNET_break (0); | ||
658 | } | 658 | } |
659 | 659 | else | |
660 | if (NULL != scls.recv) | ||
661 | { | 660 | { |
662 | GNUNET_PSYC_receive_destroy (scls.recv); | 661 | ret = db->message_get (db->cls, &req->channel_key, |
662 | message_id, message_id, | ||
663 | &ret_frags, &recv_state_fragment, &scls); | ||
664 | if (GNUNET_OK != ret) | ||
665 | { | ||
666 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
667 | _("Failed to modify state: %d\n"), ret); | ||
668 | GNUNET_break (0); | ||
669 | } | ||
670 | else | ||
671 | { | ||
672 | if (GNUNET_OK != db->state_modify_end (db->cls, &req->channel_key, message_id)) | ||
673 | { | ||
674 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
675 | _("Failed to end modifying state!\n")); | ||
676 | GNUNET_break (0); | ||
677 | } | ||
678 | } | ||
679 | if (NULL != scls.recv) | ||
680 | { | ||
681 | GNUNET_PSYC_receive_destroy (scls.recv); | ||
682 | } | ||
663 | } | 683 | } |
664 | 684 | ||
665 | send_result_code (client, req->op_id, ret, NULL); | 685 | send_result_code (client, req->op_id, ret, NULL); |
diff --git a/src/psycstore/plugin_psycstore_sqlite.c b/src/psycstore/plugin_psycstore_sqlite.c index 1abc479d2..1bf14644b 100644 --- a/src/psycstore/plugin_psycstore_sqlite.c +++ b/src/psycstore/plugin_psycstore_sqlite.c | |||
@@ -64,7 +64,8 @@ | |||
64 | 64 | ||
65 | enum Transactions { | 65 | enum Transactions { |
66 | TRANSACTION_NONE = 0, | 66 | TRANSACTION_NONE = 0, |
67 | TRANSACTION_STATE_MODIFY | 67 | TRANSACTION_STATE_MODIFY, |
68 | TRANSACTION_STATE_SYNC, | ||
68 | }; | 69 | }; |
69 | 70 | ||
70 | /** | 71 | /** |
@@ -1522,18 +1523,27 @@ state_modify_begin (void *cls, | |||
1522 | 1523 | ||
1523 | uint64_t max_state_message_id = 0; | 1524 | uint64_t max_state_message_id = 0; |
1524 | int ret = counters_state_get (plugin, channel_key, &max_state_message_id); | 1525 | int ret = counters_state_get (plugin, channel_key, &max_state_message_id); |
1525 | if (GNUNET_OK != ret) | 1526 | switch (ret) |
1527 | { | ||
1528 | case GNUNET_OK: | ||
1529 | case GNUNET_NO: // no state yet | ||
1530 | ret = GNUNET_OK; | ||
1531 | break; | ||
1532 | default: | ||
1526 | return ret; | 1533 | return ret; |
1534 | } | ||
1527 | 1535 | ||
1528 | if (message_id - state_delta != max_state_message_id) | 1536 | if (max_state_message_id < message_id - state_delta) |
1529 | return GNUNET_NO; | 1537 | return GNUNET_NO; /* some stateful messages not yet applied */ |
1538 | else if (message_id - state_delta < max_state_message_id) | ||
1539 | return GNUNET_NO; /* changes already applied */ | ||
1530 | } | 1540 | } |
1531 | 1541 | ||
1532 | // Make sure no other transaction is going on. | ||
1533 | if (TRANSACTION_NONE != plugin->transaction) | 1542 | if (TRANSACTION_NONE != plugin->transaction) |
1534 | if (GNUNET_OK != transaction_rollback (plugin)) | 1543 | { |
1535 | return GNUNET_SYSERR; | 1544 | /** @todo FIXME: wait for other transaction to finish */ |
1536 | 1545 | return GNUNET_SYSERR; | |
1546 | } | ||
1537 | return transaction_begin (plugin, TRANSACTION_STATE_MODIFY); | 1547 | return transaction_begin (plugin, TRANSACTION_STATE_MODIFY); |
1538 | } | 1548 | } |
1539 | 1549 | ||
@@ -1560,8 +1570,8 @@ state_modify_op (void *cls, | |||
1560 | return state_assign (plugin, plugin->insert_state_current, channel_key, | 1570 | return state_assign (plugin, plugin->insert_state_current, channel_key, |
1561 | name, value, value_size); | 1571 | name, value, value_size); |
1562 | 1572 | ||
1563 | /// @todo implement more state operations | 1573 | default: /** @todo implement more state operations */ |
1564 | default: | 1574 | GNUNET_break (0); |
1565 | return GNUNET_SYSERR; | 1575 | return GNUNET_SYSERR; |
1566 | } | 1576 | } |
1567 | } | 1577 | } |
@@ -1630,7 +1640,13 @@ state_sync_end (void *cls, | |||
1630 | struct Plugin *plugin = cls; | 1640 | struct Plugin *plugin = cls; |
1631 | int ret = GNUNET_SYSERR; | 1641 | int ret = GNUNET_SYSERR; |
1632 | 1642 | ||
1633 | GNUNET_OK == transaction_begin (plugin, TRANSACTION_NONE) | 1643 | if (TRANSACTION_NONE != plugin->transaction) |
1644 | { | ||
1645 | /** @todo FIXME: wait for other transaction to finish */ | ||
1646 | return GNUNET_SYSERR; | ||
1647 | } | ||
1648 | |||
1649 | GNUNET_OK == transaction_begin (plugin, TRANSACTION_STATE_SYNC) | ||
1634 | && GNUNET_OK == exec_channel (plugin, plugin->delete_state, channel_key) | 1650 | && GNUNET_OK == exec_channel (plugin, plugin->delete_state, channel_key) |
1635 | && GNUNET_OK == exec_channel (plugin, plugin->insert_state_from_sync, | 1651 | && GNUNET_OK == exec_channel (plugin, plugin->insert_state_from_sync, |
1636 | channel_key) | 1652 | channel_key) |
diff --git a/src/psycstore/psyc_util_lib.c b/src/psycstore/psyc_util_lib.c index 75f97aad0..f6dd4e593 100644 --- a/src/psycstore/psyc_util_lib.c +++ b/src/psycstore/psyc_util_lib.c | |||
@@ -570,7 +570,7 @@ transmit_notify_env (void *cls, uint16_t *data_size, void *data, uint8_t *oper, | |||
570 | { | 570 | { |
571 | struct GNUNET_PSYC_TransmitHandle *tmit = cls; | 571 | struct GNUNET_PSYC_TransmitHandle *tmit = cls; |
572 | uint16_t name_size = 0; | 572 | uint16_t name_size = 0; |
573 | size_t value_size = 0; | 573 | uint32_t value_size = 0; |
574 | const char *value = NULL; | 574 | const char *value = NULL; |
575 | 575 | ||
576 | if (NULL != oper) | 576 | if (NULL != oper) |
@@ -1231,3 +1231,41 @@ GNUNET_PSYC_message_parse (const struct GNUNET_PSYC_Message *msg, | |||
1231 | ? GNUNET_OK | 1231 | ? GNUNET_OK |
1232 | : GNUNET_SYSERR; | 1232 | : GNUNET_SYSERR; |
1233 | } | 1233 | } |
1234 | |||
1235 | |||
1236 | /** | ||
1237 | * Initialize PSYC message header. | ||
1238 | */ | ||
1239 | void | ||
1240 | GNUNET_PSYC_message_header_init (struct GNUNET_PSYC_MessageHeader *pmsg, | ||
1241 | const struct GNUNET_MULTICAST_MessageHeader *mmsg, | ||
1242 | uint32_t flags) | ||
1243 | { | ||
1244 | uint16_t size = ntohs (mmsg->header.size); | ||
1245 | uint16_t psize = sizeof (*pmsg) + size - sizeof (*mmsg); | ||
1246 | |||
1247 | pmsg->header.size = htons (psize); | ||
1248 | pmsg->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE); | ||
1249 | pmsg->message_id = mmsg->message_id; | ||
1250 | pmsg->fragment_offset = mmsg->fragment_offset; | ||
1251 | pmsg->flags = htonl (flags); | ||
1252 | |||
1253 | memcpy (&pmsg[1], &mmsg[1], size - sizeof (*mmsg)); | ||
1254 | } | ||
1255 | |||
1256 | |||
1257 | /** | ||
1258 | * Create a new PSYC message header from a multicast message for sending it to clients. | ||
1259 | */ | ||
1260 | struct GNUNET_PSYC_MessageHeader * | ||
1261 | GNUNET_PSYC_message_header_create (const struct GNUNET_MULTICAST_MessageHeader *mmsg, | ||
1262 | uint32_t flags) | ||
1263 | { | ||
1264 | struct GNUNET_PSYC_MessageHeader *pmsg; | ||
1265 | uint16_t size = ntohs (mmsg->header.size); | ||
1266 | uint16_t psize = sizeof (*pmsg) + size - sizeof (*mmsg); | ||
1267 | |||
1268 | pmsg = GNUNET_malloc (psize); | ||
1269 | GNUNET_PSYC_message_header_init (pmsg, mmsg, flags); | ||
1270 | return pmsg; | ||
1271 | } | ||
diff --git a/src/psycstore/test_plugin_psycstore.c b/src/psycstore/test_plugin_psycstore.c index 0a7824929..5a5f970b9 100644 --- a/src/psycstore/test_plugin_psycstore.c +++ b/src/psycstore/test_plugin_psycstore.c | |||
@@ -141,7 +141,7 @@ struct StateClosure { | |||
141 | }; | 141 | }; |
142 | 142 | ||
143 | static int | 143 | static int |
144 | state_cb (void *cls, const char *name, const void *value, size_t value_size) | 144 | state_cb (void *cls, const char *name, const void *value, uint32_t value_size) |
145 | { | 145 | { |
146 | struct StateClosure *scls = cls; | 146 | struct StateClosure *scls = cls; |
147 | const void *val = scls->value[scls->n]; | 147 | const void *val = scls->value[scls->n]; |
diff --git a/src/psycstore/test_psycstore.c b/src/psycstore/test_psycstore.c index c869a862f..58e6243b7 100644 --- a/src/psycstore/test_psycstore.c +++ b/src/psycstore/test_psycstore.c | |||
@@ -170,7 +170,7 @@ state_reset_result (void *cls, int64_t result, | |||
170 | 170 | ||
171 | 171 | ||
172 | static int | 172 | static int |
173 | state_result (void *cls, const char *name, const void *value, size_t value_size) | 173 | state_result (void *cls, const char *name, const void *value, uint32_t value_size) |
174 | { | 174 | { |
175 | struct StateClosure *scls = cls; | 175 | struct StateClosure *scls = cls; |
176 | const char *nam = scls->name[scls->n]; | 176 | const char *nam = scls->name[scls->n]; |
diff --git a/src/social/gnunet-service-social.c b/src/social/gnunet-service-social.c index 4211772f1..56612b488 100644 --- a/src/social/gnunet-service-social.c +++ b/src/social/gnunet-service-social.c | |||
@@ -350,7 +350,7 @@ cleanup_guest (struct Guest *gst) | |||
350 | struct GNUNET_CONTAINER_MultiHashMap * | 350 | struct GNUNET_CONTAINER_MultiHashMap * |
351 | plc_gst = GNUNET_CONTAINER_multihashmap_get (place_guests, | 351 | plc_gst = GNUNET_CONTAINER_multihashmap_get (place_guests, |
352 | &plc->pub_key_hash); | 352 | &plc->pub_key_hash); |
353 | GNUNET_assert (NULL != plc_gst); | 353 | GNUNET_assert (NULL != plc_gst); // FIXME |
354 | GNUNET_CONTAINER_multihashmap_remove (plc_gst, &gst->pub_key_hash, gst); | 354 | GNUNET_CONTAINER_multihashmap_remove (plc_gst, &gst->pub_key_hash, gst); |
355 | 355 | ||
356 | if (0 == GNUNET_CONTAINER_multihashmap_size (plc_gst)) | 356 | if (0 == GNUNET_CONTAINER_multihashmap_size (plc_gst)) |
@@ -1302,7 +1302,7 @@ psyc_transmit_queue_next_method (struct Place *plc, | |||
1302 | { | 1302 | { |
1303 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1303 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1304 | "%p psyc_transmit_queue_next_method: unexpected message part of type %u.\n", | 1304 | "%p psyc_transmit_queue_next_method: unexpected message part of type %u.\n", |
1305 | plc, ntohs (pmsg->type)); | 1305 | plc, NULL != pmsg ? ntohs (pmsg->type) : 0); |
1306 | GNUNET_break (0); | 1306 | GNUNET_break (0); |
1307 | return GNUNET_SYSERR; | 1307 | return GNUNET_SYSERR; |
1308 | } | 1308 | } |
@@ -1536,12 +1536,10 @@ client_recv_psyc_message (void *cls, struct GNUNET_SERVER_Client *client, | |||
1536 | 1536 | ||
1537 | 1537 | ||
1538 | /** | 1538 | /** |
1539 | * A historic message result arrived from PSYC. | 1539 | * A historic message arrived from PSYC. |
1540 | */ | 1540 | */ |
1541 | static void | 1541 | static void |
1542 | psyc_recv_history_message (void *cls, | 1542 | psyc_recv_history_message (void *cls, uint64_t message_id, uint32_t flags, |
1543 | uint64_t message_id, | ||
1544 | uint32_t flags, | ||
1545 | const struct GNUNET_PSYC_MessageHeader *msg) | 1543 | const struct GNUNET_PSYC_MessageHeader *msg) |
1546 | { | 1544 | { |
1547 | struct OperationClosure *opcls = cls; | 1545 | struct OperationClosure *opcls = cls; |
@@ -1567,6 +1565,9 @@ psyc_recv_history_message (void *cls, | |||
1567 | } | 1565 | } |
1568 | 1566 | ||
1569 | 1567 | ||
1568 | /** | ||
1569 | * Result of message history replay from PSYC. | ||
1570 | */ | ||
1570 | static void | 1571 | static void |
1571 | psyc_recv_history_result (void *cls, int64_t result, | 1572 | psyc_recv_history_result (void *cls, int64_t result, |
1572 | const void *err_msg, uint16_t err_msg_size) | 1573 | const void *err_msg, uint16_t err_msg_size) |
@@ -1574,7 +1575,7 @@ psyc_recv_history_result (void *cls, int64_t result, | |||
1574 | struct OperationClosure *opcls = cls; | 1575 | struct OperationClosure *opcls = cls; |
1575 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1576 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1576 | "%p History replay #%" PRIu64 ": " | 1577 | "%p History replay #%" PRIu64 ": " |
1577 | "PSYCSTORE returned %" PRId64 " (%.*s)\n", | 1578 | "PSYCstore returned %" PRId64 " (%.*s)\n", |
1578 | opcls->plc, GNUNET_ntohll (opcls->op_id), result, err_msg_size, err_msg); | 1579 | opcls->plc, GNUNET_ntohll (opcls->op_id), result, err_msg_size, err_msg); |
1579 | 1580 | ||
1580 | // FIXME: place might have been destroyed | 1581 | // FIXME: place might have been destroyed |
@@ -1635,6 +1636,118 @@ client_recv_history_replay (void *cls, struct GNUNET_SERVER_Client *client, | |||
1635 | } | 1636 | } |
1636 | 1637 | ||
1637 | 1638 | ||
1639 | /** | ||
1640 | * A state variable part arrived from PSYC. | ||
1641 | */ | ||
1642 | void | ||
1643 | psyc_recv_state_var (void *cls, | ||
1644 | const struct GNUNET_MessageHeader *mod, | ||
1645 | const char *name, | ||
1646 | const void *value, | ||
1647 | uint32_t value_size, | ||
1648 | uint32_t full_value_size) | ||
1649 | { | ||
1650 | struct OperationClosure *opcls = cls; | ||
1651 | struct Place *plc = opcls->plc; | ||
1652 | |||
1653 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1654 | "%p Received state variable %s from PSYC\n", | ||
1655 | plc, name); | ||
1656 | |||
1657 | uint16_t size = ntohs (mod->size); | ||
1658 | |||
1659 | struct GNUNET_OperationResultMessage * | ||
1660 | res = GNUNET_malloc (sizeof (*res) + size); | ||
1661 | res->header.size = htons (sizeof (*res) + size); | ||
1662 | res->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_STATE_RESULT); | ||
1663 | res->op_id = opcls->op_id; | ||
1664 | res->result_code = GNUNET_htonll (GNUNET_OK); | ||
1665 | |||
1666 | memcpy (&res[1], mod, size); | ||
1667 | |||
1668 | /** @todo FIXME: send only to requesting client */ | ||
1669 | client_send_msg (plc, &res->header); | ||
1670 | } | ||
1671 | |||
1672 | |||
1673 | /** | ||
1674 | * Result of retrieving state variable from PSYC. | ||
1675 | */ | ||
1676 | static void | ||
1677 | psyc_recv_state_result (void *cls, int64_t result, | ||
1678 | const void *err_msg, uint16_t err_msg_size) | ||
1679 | { | ||
1680 | struct OperationClosure *opcls = cls; | ||
1681 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1682 | "%p State get #%" PRIu64 ": " | ||
1683 | "PSYCstore returned %" PRId64 " (%.*s)\n", | ||
1684 | opcls->plc, GNUNET_ntohll (opcls->op_id), result, err_msg_size, err_msg); | ||
1685 | |||
1686 | // FIXME: place might have been destroyed | ||
1687 | client_send_result (opcls->client, opcls->op_id, result, err_msg, err_msg_size); | ||
1688 | } | ||
1689 | |||
1690 | |||
1691 | /** | ||
1692 | * Client requests channel history. | ||
1693 | */ | ||
1694 | static void | ||
1695 | client_recv_state_get (void *cls, struct GNUNET_SERVER_Client *client, | ||
1696 | const struct GNUNET_MessageHeader *msg) | ||
1697 | { | ||
1698 | struct Client * | ||
1699 | ctx = GNUNET_SERVER_client_get_user_context (client, struct Client); | ||
1700 | GNUNET_assert (NULL != ctx); | ||
1701 | struct Place *plc = ctx->plc; | ||
1702 | |||
1703 | const struct GNUNET_PSYC_StateRequestMessage * | ||
1704 | req = (const struct GNUNET_PSYC_StateRequestMessage *) msg; | ||
1705 | uint16_t size = ntohs (msg->size); | ||
1706 | const char *name = (const char *) &req[1]; | ||
1707 | |||
1708 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1709 | "%p State get #%" PRIu64 ": %s\n", | ||
1710 | plc, GNUNET_ntohll (req->op_id), name); | ||
1711 | |||
1712 | if (size < sizeof (*req) + 1 | ||
1713 | || '\0' != name[size - sizeof (*req) - 1]) | ||
1714 | { | ||
1715 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1716 | "%p State get #%" PRIu64 ": " | ||
1717 | "invalid name. size: %u < %u?\n", | ||
1718 | plc, GNUNET_ntohll (req->op_id), size, sizeof (*req) + 1); | ||
1719 | GNUNET_break (0); | ||
1720 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
1721 | return; | ||
1722 | } | ||
1723 | |||
1724 | struct OperationClosure *opcls = GNUNET_malloc (sizeof (*opcls)); | ||
1725 | opcls->client = client; | ||
1726 | opcls->plc = plc; | ||
1727 | opcls->op_id = req->op_id; | ||
1728 | |||
1729 | switch (ntohs (msg->type)) | ||
1730 | { | ||
1731 | case GNUNET_MESSAGE_TYPE_PSYC_STATE_GET: | ||
1732 | GNUNET_PSYC_channel_state_get (plc->channel, name, | ||
1733 | psyc_recv_state_var, | ||
1734 | psyc_recv_state_result, opcls); | ||
1735 | break; | ||
1736 | |||
1737 | case GNUNET_MESSAGE_TYPE_PSYC_STATE_GET_PREFIX: | ||
1738 | GNUNET_PSYC_channel_state_get_prefix (plc->channel, name, | ||
1739 | psyc_recv_state_var, | ||
1740 | psyc_recv_state_result, opcls); | ||
1741 | break; | ||
1742 | |||
1743 | default: | ||
1744 | GNUNET_assert (0); | ||
1745 | } | ||
1746 | |||
1747 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
1748 | } | ||
1749 | |||
1750 | |||
1638 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | 1751 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { |
1639 | { &client_recv_host_enter, NULL, | 1752 | { &client_recv_host_enter, NULL, |
1640 | GNUNET_MESSAGE_TYPE_SOCIAL_HOST_ENTER, 0 }, | 1753 | GNUNET_MESSAGE_TYPE_SOCIAL_HOST_ENTER, 0 }, |
@@ -1650,13 +1763,13 @@ static const struct GNUNET_SERVER_MessageHandler handlers[] = { | |||
1650 | 1763 | ||
1651 | { &client_recv_history_replay, NULL, | 1764 | { &client_recv_history_replay, NULL, |
1652 | GNUNET_MESSAGE_TYPE_PSYC_HISTORY_REPLAY, 0 }, | 1765 | GNUNET_MESSAGE_TYPE_PSYC_HISTORY_REPLAY, 0 }, |
1653 | #if FIXME | 1766 | |
1654 | { &client_recv_state_get, NULL, | 1767 | { &client_recv_state_get, NULL, |
1655 | GNUNET_MESSAGE_TYPE_PSYC_STATE_GET, 0 }, | 1768 | GNUNET_MESSAGE_TYPE_PSYC_STATE_GET, 0 }, |
1656 | 1769 | ||
1657 | { &client_recv_state_get_prefix, NULL, | 1770 | { &client_recv_state_get, NULL, |
1658 | GNUNET_MESSAGE_TYPE_PSYC_STATE_GET_PREFIX, 0 }, | 1771 | GNUNET_MESSAGE_TYPE_PSYC_STATE_GET_PREFIX, 0 }, |
1659 | #endif | 1772 | |
1660 | { NULL, NULL, 0, 0 } | 1773 | { NULL, NULL, 0, 0 } |
1661 | }; | 1774 | }; |
1662 | 1775 | ||
diff --git a/src/social/social_api.c b/src/social/social_api.c index 74a13cc35..20d0dc8b8 100644 --- a/src/social/social_api.c +++ b/src/social/social_api.c | |||
@@ -310,6 +310,21 @@ struct GNUNET_SOCIAL_LookHandle | |||
310 | GNUNET_ResultCallback result_cb; | 310 | GNUNET_ResultCallback result_cb; |
311 | 311 | ||
312 | /** | 312 | /** |
313 | * Name of current modifier being received. | ||
314 | */ | ||
315 | char *mod_name; | ||
316 | |||
317 | /** | ||
318 | * Size of current modifier value being received. | ||
319 | */ | ||
320 | size_t mod_value_size; | ||
321 | |||
322 | /** | ||
323 | * Remaining size of current modifier value still to be received. | ||
324 | */ | ||
325 | size_t mod_value_remaining; | ||
326 | |||
327 | /** | ||
313 | * Closure for @a result_cb. | 328 | * Closure for @a result_cb. |
314 | */ | 329 | */ |
315 | void *cls; | 330 | void *cls; |
@@ -753,49 +768,66 @@ place_recv_state_result (void *cls, | |||
753 | const struct GNUNET_OperationResultMessage * | 768 | const struct GNUNET_OperationResultMessage * |
754 | res = (const struct GNUNET_OperationResultMessage *) msg; | 769 | res = (const struct GNUNET_OperationResultMessage *) msg; |
755 | 770 | ||
756 | #if FIXME | ||
757 | GNUNET_ResultCallback result_cb = NULL; | 771 | GNUNET_ResultCallback result_cb = NULL; |
758 | struct GNUNET_PSYC_StateRequest *sr = NULL; | 772 | struct GNUNET_SOCIAL_LookHandle *look = NULL; |
759 | 773 | ||
760 | if (GNUNET_YES != GNUNET_CLIENT_MANAGER_op_find (plc->client, | 774 | if (GNUNET_YES != GNUNET_CLIENT_MANAGER_op_find (plc->client, |
761 | GNUNET_ntohll (res->op_id), | 775 | GNUNET_ntohll (res->op_id), |
762 | &result_cb, (void *) &sr)) | 776 | &result_cb, (void *) &look)) |
763 | { /* Operation not found. */ | 777 | { /* Operation not found. */ |
764 | return; | 778 | return; |
765 | } | 779 | } |
766 | 780 | ||
767 | const struct GNUNET_MessageHeader * | 781 | const struct GNUNET_MessageHeader * |
768 | modc = (struct GNUNET_MessageHeader *) &res[1]; | 782 | mod = (struct GNUNET_MessageHeader *) &res[1]; |
769 | uint16_t modc_size = ntohs (modc->size); | 783 | uint16_t mod_size = ntohs (mod->size); |
770 | if (ntohs (msg->size) - sizeof (*msg) != modc_size) | 784 | if (ntohs (msg->size) - sizeof (*res) != mod_size) |
771 | { | 785 | { |
772 | GNUNET_break (0); | 786 | GNUNET_break_op (0); |
787 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
788 | "Invalid modifier size in state result: %u - %u != %u\n", | ||
789 | ntohs (msg->size), sizeof (*res), mod_size); | ||
773 | return; | 790 | return; |
774 | } | 791 | } |
775 | switch (ntohs (modc->type)) | 792 | switch (ntohs (mod->type)) |
776 | { | 793 | { |
777 | case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MODIFIER: | 794 | case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MODIFIER: |
778 | { | 795 | { |
779 | const struct GNUNET_PSYC_MessageModifier * | 796 | const struct GNUNET_PSYC_MessageModifier * |
780 | mod = (const struct GNUNET_PSYC_MessageModifier *) modc; | 797 | pmod = (const struct GNUNET_PSYC_MessageModifier *) mod; |
781 | 798 | ||
782 | const char *name = (const char *) &mod[1]; | 799 | const char *name = (const char *) &pmod[1]; |
783 | uint16_t name_size = ntohs (mod->name_size); | 800 | uint16_t name_size = ntohs (pmod->name_size); |
784 | if ('\0' != name[name_size - 1]) | 801 | if ('\0' != name[name_size - 1]) |
785 | { | 802 | { |
786 | GNUNET_break (0); | 803 | GNUNET_break_op (0); |
804 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
805 | "Invalid modifier name in state result\n"); | ||
787 | return; | 806 | return; |
788 | } | 807 | } |
789 | sr->var_cb (sr->cls, name, name + name_size, ntohs (mod->value_size)); | 808 | look->mod_value_size = ntohs (pmod->value_size); |
809 | look->var_cb (look->cls, mod, name, name + name_size, | ||
810 | mod_size - sizeof (*mod) - name_size, | ||
811 | look->mod_value_size); | ||
812 | if (look->mod_value_size > mod_size - sizeof (*mod) - name_size) | ||
813 | { | ||
814 | look->mod_value_remaining = look->mod_value_size; | ||
815 | look->mod_name = GNUNET_malloc (name_size); | ||
816 | memcpy (look->mod_name, name, name_size); | ||
817 | } | ||
790 | break; | 818 | break; |
791 | } | 819 | } |
792 | 820 | ||
793 | case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MOD_CONT: | 821 | case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MOD_CONT: |
794 | sr->var_cb (sr->cls, NULL, (const char *) &modc[1], | 822 | look->var_cb (look->cls, mod, look->mod_name, (const char *) &mod[1], |
795 | modc_size - sizeof (*modc)); | 823 | mod_size - sizeof (*mod), look->mod_value_size); |
824 | look->mod_value_remaining -= mod_size - sizeof (*mod); | ||
825 | if (0 == look->mod_value_remaining) | ||
826 | { | ||
827 | GNUNET_free (look->mod_name); | ||
828 | } | ||
796 | break; | 829 | break; |
797 | } | 830 | } |
798 | #endif | ||
799 | } | 831 | } |
800 | 832 | ||
801 | 833 | ||
@@ -1980,7 +2012,7 @@ place_state_get (struct GNUNET_SOCIAL_Place *plc, | |||
1980 | * what was requested). | 2012 | * what was requested). |
1981 | * | 2013 | * |
1982 | * @param place | 2014 | * @param place |
1983 | * The place to look the object at. | 2015 | * The place where to look. |
1984 | * @param full_name | 2016 | * @param full_name |
1985 | * Full name of the object. | 2017 | * Full name of the object. |
1986 | * @param value_size | 2018 | * @param value_size |
@@ -2004,7 +2036,7 @@ GNUNET_SOCIAL_place_look_at (struct GNUNET_SOCIAL_Place *plc, | |||
2004 | * Look for objects in the place with a matching name prefix. | 2036 | * Look for objects in the place with a matching name prefix. |
2005 | * | 2037 | * |
2006 | * @param place | 2038 | * @param place |
2007 | * The place to look its objects at. | 2039 | * The place where to look. |
2008 | * @param name_prefix | 2040 | * @param name_prefix |
2009 | * Look at objects with names beginning with this value. | 2041 | * Look at objects with names beginning with this value. |
2010 | * @param var_cb | 2042 | * @param var_cb |
diff --git a/src/social/test_social.c b/src/social/test_social.c index 19a81f43d..dbcf822f8 100644 --- a/src/social/test_social.c +++ b/src/social/test_social.c | |||
@@ -36,7 +36,7 @@ | |||
36 | #include "gnunet_core_service.h" | 36 | #include "gnunet_core_service.h" |
37 | #include "gnunet_identity_service.h" | 37 | #include "gnunet_identity_service.h" |
38 | 38 | ||
39 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | 39 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) |
40 | 40 | ||
41 | #define DATA2ARG(data) data, sizeof (data) | 41 | #define DATA2ARG(data) data, sizeof (data) |
42 | 42 | ||
@@ -99,6 +99,10 @@ struct TransmitClosure | |||
99 | uint8_t n; | 99 | uint8_t n; |
100 | } tmit; | 100 | } tmit; |
101 | 101 | ||
102 | struct ResultClosure { | ||
103 | uint32_t n; | ||
104 | }; | ||
105 | |||
102 | uint8_t join_req_count; | 106 | uint8_t join_req_count; |
103 | struct GNUNET_PSYC_Message *join_resp; | 107 | struct GNUNET_PSYC_Message *join_resp; |
104 | 108 | ||
@@ -107,19 +111,21 @@ uint32_t counter; | |||
107 | enum | 111 | enum |
108 | { | 112 | { |
109 | TEST_NONE = 0, | 113 | TEST_NONE = 0, |
110 | TEST_HOST_ANSWER_DOOR_REFUSE = 1, | 114 | TEST_HOST_ANSWER_DOOR_REFUSE = 1, |
111 | TEST_GUEST_RECV_ENTRY_DCSN_REFUSE = 2, | 115 | TEST_GUEST_RECV_ENTRY_DCSN_REFUSE = 2, |
112 | TEST_HOST_ANSWER_DOOR_ADMIT = 3, | 116 | TEST_HOST_ANSWER_DOOR_ADMIT = 3, |
113 | TEST_GUEST_RECV_ENTRY_DCSN_ADMIT = 4, | 117 | TEST_GUEST_RECV_ENTRY_DCSN_ADMIT = 4, |
114 | TEST_HOST_ANNOUNCE = 5, | 118 | TEST_HOST_ANNOUNCE = 5, |
115 | TEST_HOST_ANNOUNCE_END = 6, | 119 | TEST_HOST_ANNOUNCE_END = 6, |
116 | TEST_HOST_ANNOUNCE2 = 7, | 120 | TEST_HOST_ANNOUNCE2 = 7, |
117 | TEST_HOST_ANNOUNCE2_END = 8, | 121 | TEST_HOST_ANNOUNCE2_END = 8, |
118 | TEST_GUEST_TALK = 9, | 122 | TEST_GUEST_TALK = 9, |
119 | TEST_GUEST_HISTORY_REPLAY = 10, | 123 | TEST_GUEST_HISTORY_REPLAY = 10, |
120 | TEST_GUEST_HISTORY_REPLAY_LATEST = 11, | 124 | TEST_GUEST_HISTORY_REPLAY_LATEST = 11, |
121 | TEST_GUEST_LEAVE = 12, | 125 | TEST_GUEST_LOOK_AT = 12, |
122 | TEST_HOST_LEAVE = 13, | 126 | TEST_GUEST_LOOK_FOR = 13, |
127 | TEST_GUEST_LEAVE = 14, | ||
128 | TEST_HOST_LEAVE = 15, | ||
123 | } test; | 129 | } test; |
124 | 130 | ||
125 | 131 | ||
@@ -351,6 +357,86 @@ schedule_guest_leave (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
351 | 357 | ||
352 | 358 | ||
353 | static void | 359 | static void |
360 | guest_look_for_result (void *cls, int64_t result_code, | ||
361 | const void *data, uint16_t data_size) | ||
362 | { | ||
363 | struct ResultClosure *rcls = cls; | ||
364 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
365 | "guest_look_for_result: %d\n", result_code); | ||
366 | GNUNET_assert (GNUNET_OK == result_code); | ||
367 | GNUNET_assert (3 == rcls->n); | ||
368 | GNUNET_free (rcls); | ||
369 | GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL); | ||
370 | } | ||
371 | |||
372 | |||
373 | static void | ||
374 | guest_look_for_var (void *cls, | ||
375 | const struct GNUNET_MessageHeader *mod, | ||
376 | const char *name, | ||
377 | const void *value, | ||
378 | uint32_t value_size, | ||
379 | uint32_t full_value_size) | ||
380 | { | ||
381 | struct ResultClosure *rcls = cls; | ||
382 | rcls->n++; | ||
383 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
384 | "guest_look_for_var: %s\n%.*s\n", | ||
385 | name, value_size, value); | ||
386 | } | ||
387 | |||
388 | |||
389 | static void | ||
390 | guest_look_for () | ||
391 | { | ||
392 | test = TEST_GUEST_LOOK_FOR; | ||
393 | struct ResultClosure *rcls = GNUNET_malloc (sizeof (*rcls)); | ||
394 | GNUNET_SOCIAL_place_look_for (gst_plc, "_foo", guest_look_for_var, guest_look_for_result, rcls); | ||
395 | } | ||
396 | |||
397 | |||
398 | static void | ||
399 | guest_look_at_result (void *cls, int64_t result_code, | ||
400 | const void *data, uint16_t data_size) | ||
401 | { | ||
402 | struct ResultClosure *rcls = cls; | ||
403 | |||
404 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
405 | "guest_look_at_result: %d\n", result_code); | ||
406 | GNUNET_assert (GNUNET_OK == result_code); | ||
407 | GNUNET_assert (1 == rcls->n); | ||
408 | GNUNET_free (rcls); | ||
409 | guest_look_for (); | ||
410 | } | ||
411 | |||
412 | |||
413 | static void | ||
414 | guest_look_at_var (void *cls, | ||
415 | const struct GNUNET_MessageHeader *mod, | ||
416 | const char *name, | ||
417 | const void *value, | ||
418 | uint32_t value_size, | ||
419 | uint32_t full_value_size) | ||
420 | { | ||
421 | struct ResultClosure *rcls = cls; | ||
422 | rcls->n++; | ||
423 | |||
424 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
425 | "guest_look_at_var: %s\n%.*s\n", | ||
426 | name, value_size, value); | ||
427 | } | ||
428 | |||
429 | |||
430 | static void | ||
431 | guest_look_at () | ||
432 | { | ||
433 | test = TEST_GUEST_LOOK_AT; | ||
434 | struct ResultClosure *rcls = GNUNET_malloc (sizeof (*rcls)); | ||
435 | GNUNET_SOCIAL_place_look_at (gst_plc, "_foo_bar", guest_look_at_var, guest_look_at_result, rcls); | ||
436 | } | ||
437 | |||
438 | |||
439 | static void | ||
354 | guest_recv_history_replay_latest_result (void *cls, int64_t result, | 440 | guest_recv_history_replay_latest_result (void *cls, int64_t result, |
355 | const void *data, uint16_t data_size) | 441 | const void *data, uint16_t data_size) |
356 | { | 442 | { |
@@ -361,7 +447,7 @@ guest_recv_history_replay_latest_result (void *cls, int64_t result, | |||
361 | GNUNET_assert (2 == counter); /* message count */ | 447 | GNUNET_assert (2 == counter); /* message count */ |
362 | GNUNET_assert (7 == result); /* fragment count */ | 448 | GNUNET_assert (7 == result); /* fragment count */ |
363 | 449 | ||
364 | GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL); | 450 | guest_look_at (); |
365 | } | 451 | } |
366 | 452 | ||
367 | 453 | ||
@@ -488,6 +574,7 @@ guest_recv_eom (void *cls, | |||
488 | break; | 574 | break; |
489 | 575 | ||
490 | default: | 576 | default: |
577 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test); | ||
491 | GNUNET_assert (0); | 578 | GNUNET_assert (0); |
492 | } | 579 | } |
493 | } | 580 | } |
@@ -570,10 +657,11 @@ host_recv_eom (void *cls, | |||
570 | break; | 657 | break; |
571 | 658 | ||
572 | case TEST_GUEST_TALK: | 659 | case TEST_GUEST_TALK: |
573 | guest_history_replay (); | 660 | guest_history_replay (); |
574 | break; | 661 | break; |
575 | 662 | ||
576 | default: | 663 | default: |
664 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test); | ||
577 | GNUNET_assert (0); | 665 | GNUNET_assert (0); |
578 | } | 666 | } |
579 | } | 667 | } |
@@ -624,7 +712,8 @@ host_announce () | |||
624 | tmit.host_ann | 712 | tmit.host_ann |
625 | = GNUNET_SOCIAL_host_announce (hst, "_message_host", tmit.env, | 713 | = GNUNET_SOCIAL_host_announce (hst, "_message_host", tmit.env, |
626 | ¬ify_data, &tmit, | 714 | ¬ify_data, &tmit, |
627 | GNUNET_SOCIAL_ANNOUNCE_NONE); | 715 | GNUNET_SOCIAL_ANNOUNCE_NONE |
716 | | GNUNET_PSYC_MASTER_TRANSMIT_STATE_MODIFY); | ||
628 | } | 717 | } |
629 | 718 | ||
630 | 719 | ||
@@ -689,6 +778,7 @@ guest_recv_entry_decision (void *cls, | |||
689 | break; | 778 | break; |
690 | 779 | ||
691 | default: | 780 | default: |
781 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test); | ||
692 | GNUNET_assert (0); | 782 | GNUNET_assert (0); |
693 | } | 783 | } |
694 | } | 784 | } |
@@ -728,6 +818,7 @@ host_answer_door (void *cls, | |||
728 | break; | 818 | break; |
729 | 819 | ||
730 | default: | 820 | default: |
821 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test); | ||
731 | GNUNET_assert (0); | 822 | GNUNET_assert (0); |
732 | } | 823 | } |
733 | } | 824 | } |