diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/peerstore/peerstore_api.c | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/peerstore/peerstore_api.c')
-rw-r--r-- | src/peerstore/peerstore_api.c | 541 |
1 files changed, 268 insertions, 273 deletions
diff --git a/src/peerstore/peerstore_api.c b/src/peerstore/peerstore_api.c index 64bc3ae72..3ce2c5533 100644 --- a/src/peerstore/peerstore_api.c +++ b/src/peerstore/peerstore_api.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file peerstore/peerstore_api.c | 21 | * @file peerstore/peerstore_api.c |
22 | * @brief API for peerstore | 22 | * @brief API for peerstore |
@@ -28,7 +28,7 @@ | |||
28 | #include "peerstore.h" | 28 | #include "peerstore.h" |
29 | #include "peerstore_common.h" | 29 | #include "peerstore_common.h" |
30 | 30 | ||
31 | #define LOG(kind, ...) GNUNET_log_from (kind, "peerstore-api", __VA_ARGS__) | 31 | #define LOG(kind, ...) GNUNET_log_from(kind, "peerstore-api", __VA_ARGS__) |
32 | 32 | ||
33 | /******************************************************************************/ | 33 | /******************************************************************************/ |
34 | /************************ DATA STRUCTURES ****************************/ | 34 | /************************ DATA STRUCTURES ****************************/ |
@@ -37,9 +37,7 @@ | |||
37 | /** | 37 | /** |
38 | * Handle to the PEERSTORE service. | 38 | * Handle to the PEERSTORE service. |
39 | */ | 39 | */ |
40 | struct GNUNET_PEERSTORE_Handle | 40 | struct GNUNET_PEERSTORE_Handle { |
41 | { | ||
42 | |||
43 | /** | 41 | /** |
44 | * Our configuration. | 42 | * Our configuration. |
45 | */ | 43 | */ |
@@ -94,8 +92,7 @@ struct GNUNET_PEERSTORE_Handle | |||
94 | /** | 92 | /** |
95 | * Context for a store request | 93 | * Context for a store request |
96 | */ | 94 | */ |
97 | struct GNUNET_PEERSTORE_StoreContext | 95 | struct GNUNET_PEERSTORE_StoreContext { |
98 | { | ||
99 | /** | 96 | /** |
100 | * Kept in a DLL. | 97 | * Kept in a DLL. |
101 | */ | 98 | */ |
@@ -160,8 +157,7 @@ struct GNUNET_PEERSTORE_StoreContext | |||
160 | /** | 157 | /** |
161 | * Context for a iterate request | 158 | * Context for a iterate request |
162 | */ | 159 | */ |
163 | struct GNUNET_PEERSTORE_IterateContext | 160 | struct GNUNET_PEERSTORE_IterateContext { |
164 | { | ||
165 | /** | 161 | /** |
166 | * Kept in a DLL. | 162 | * Kept in a DLL. |
167 | */ | 163 | */ |
@@ -211,8 +207,7 @@ struct GNUNET_PEERSTORE_IterateContext | |||
211 | /** | 207 | /** |
212 | * Context for a watch request | 208 | * Context for a watch request |
213 | */ | 209 | */ |
214 | struct GNUNET_PEERSTORE_WatchContext | 210 | struct GNUNET_PEERSTORE_WatchContext { |
215 | { | ||
216 | /** | 211 | /** |
217 | * Kept in a DLL. | 212 | * Kept in a DLL. |
218 | */ | 213 | */ |
@@ -254,7 +249,7 @@ struct GNUNET_PEERSTORE_WatchContext | |||
254 | * @param cls a `struct GNUNET_PEERSTORE_Handle *h` | 249 | * @param cls a `struct GNUNET_PEERSTORE_Handle *h` |
255 | */ | 250 | */ |
256 | static void | 251 | static void |
257 | reconnect (void *cls); | 252 | reconnect(void *cls); |
258 | 253 | ||
259 | 254 | ||
260 | /** | 255 | /** |
@@ -263,32 +258,32 @@ reconnect (void *cls); | |||
263 | * @param h peerstore handle to disconnect | 258 | * @param h peerstore handle to disconnect |
264 | */ | 259 | */ |
265 | static void | 260 | static void |
266 | disconnect (struct GNUNET_PEERSTORE_Handle *h) | 261 | disconnect(struct GNUNET_PEERSTORE_Handle *h) |
267 | { | 262 | { |
268 | struct GNUNET_PEERSTORE_IterateContext *next; | 263 | struct GNUNET_PEERSTORE_IterateContext *next; |
269 | 264 | ||
270 | for (struct GNUNET_PEERSTORE_IterateContext *ic = h->iterate_head; NULL != ic; | 265 | for (struct GNUNET_PEERSTORE_IterateContext *ic = h->iterate_head; NULL != ic; |
271 | ic = next) | 266 | ic = next) |
272 | { | ||
273 | next = ic->next; | ||
274 | if (GNUNET_YES == ic->iterating) | ||
275 | { | 267 | { |
276 | GNUNET_PEERSTORE_Processor icb; | 268 | next = ic->next; |
277 | void *icb_cls; | 269 | if (GNUNET_YES == ic->iterating) |
278 | 270 | { | |
279 | icb = ic->callback; | 271 | GNUNET_PEERSTORE_Processor icb; |
280 | icb_cls = ic->callback_cls; | 272 | void *icb_cls; |
281 | GNUNET_PEERSTORE_iterate_cancel (ic); | 273 | |
282 | if (NULL != icb) | 274 | icb = ic->callback; |
283 | icb (icb_cls, NULL, "Iteration canceled due to reconnection"); | 275 | icb_cls = ic->callback_cls; |
276 | GNUNET_PEERSTORE_iterate_cancel(ic); | ||
277 | if (NULL != icb) | ||
278 | icb(icb_cls, NULL, "Iteration canceled due to reconnection"); | ||
279 | } | ||
284 | } | 280 | } |
285 | } | ||
286 | 281 | ||
287 | if (NULL != h->mq) | 282 | if (NULL != h->mq) |
288 | { | 283 | { |
289 | GNUNET_MQ_destroy (h->mq); | 284 | GNUNET_MQ_destroy(h->mq); |
290 | h->mq = NULL; | 285 | h->mq = NULL; |
291 | } | 286 | } |
292 | } | 287 | } |
293 | 288 | ||
294 | 289 | ||
@@ -299,16 +294,16 @@ disconnect (struct GNUNET_PEERSTORE_Handle *h) | |||
299 | * @param h peerstore to reconnect | 294 | * @param h peerstore to reconnect |
300 | */ | 295 | */ |
301 | static void | 296 | static void |
302 | disconnect_and_schedule_reconnect (struct GNUNET_PEERSTORE_Handle *h) | 297 | disconnect_and_schedule_reconnect(struct GNUNET_PEERSTORE_Handle *h) |
303 | { | 298 | { |
304 | GNUNET_assert (NULL == h->reconnect_task); | 299 | GNUNET_assert(NULL == h->reconnect_task); |
305 | disconnect (h); | 300 | disconnect(h); |
306 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 301 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
307 | "Scheduling task to reconnect to PEERSTORE service in %s.\n", | 302 | "Scheduling task to reconnect to PEERSTORE service in %s.\n", |
308 | GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, GNUNET_YES)); | 303 | GNUNET_STRINGS_relative_time_to_string(h->reconnect_delay, GNUNET_YES)); |
309 | h->reconnect_task = | 304 | h->reconnect_task = |
310 | GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h); | 305 | GNUNET_SCHEDULER_add_delayed(h->reconnect_delay, &reconnect, h); |
311 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); | 306 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF(h->reconnect_delay); |
312 | } | 307 | } |
313 | 308 | ||
314 | 309 | ||
@@ -318,7 +313,7 @@ disconnect_and_schedule_reconnect (struct GNUNET_PEERSTORE_Handle *h) | |||
318 | * @param cls a `struct GNUNET_PEERSTORE_StoreContext *` | 313 | * @param cls a `struct GNUNET_PEERSTORE_StoreContext *` |
319 | */ | 314 | */ |
320 | static void | 315 | static void |
321 | store_request_sent (void *cls) | 316 | store_request_sent(void *cls) |
322 | { | 317 | { |
323 | struct GNUNET_PEERSTORE_StoreContext *sc = cls; | 318 | struct GNUNET_PEERSTORE_StoreContext *sc = cls; |
324 | GNUNET_PEERSTORE_Continuation cont; | 319 | GNUNET_PEERSTORE_Continuation cont; |
@@ -326,9 +321,9 @@ store_request_sent (void *cls) | |||
326 | 321 | ||
327 | cont = sc->cont; | 322 | cont = sc->cont; |
328 | cont_cls = sc->cont_cls; | 323 | cont_cls = sc->cont_cls; |
329 | GNUNET_PEERSTORE_store_cancel (sc); | 324 | GNUNET_PEERSTORE_store_cancel(sc); |
330 | if (NULL != cont) | 325 | if (NULL != cont) |
331 | cont (cont_cls, GNUNET_OK); | 326 | cont(cont_cls, GNUNET_OK); |
332 | } | 327 | } |
333 | 328 | ||
334 | 329 | ||
@@ -341,14 +336,14 @@ store_request_sent (void *cls) | |||
341 | * Function called when we had trouble talking to the service. | 336 | * Function called when we had trouble talking to the service. |
342 | */ | 337 | */ |
343 | static void | 338 | static void |
344 | handle_client_error (void *cls, enum GNUNET_MQ_Error error) | 339 | handle_client_error(void *cls, enum GNUNET_MQ_Error error) |
345 | { | 340 | { |
346 | struct GNUNET_PEERSTORE_Handle *h = cls; | 341 | struct GNUNET_PEERSTORE_Handle *h = cls; |
347 | 342 | ||
348 | LOG (GNUNET_ERROR_TYPE_ERROR, | 343 | LOG(GNUNET_ERROR_TYPE_ERROR, |
349 | "Received an error notification from MQ of type: %d\n", | 344 | "Received an error notification from MQ of type: %d\n", |
350 | error); | 345 | error); |
351 | disconnect_and_schedule_reconnect (h); | 346 | disconnect_and_schedule_reconnect(h); |
352 | } | 347 | } |
353 | 348 | ||
354 | 349 | ||
@@ -361,16 +356,16 @@ handle_client_error (void *cls, enum GNUNET_MQ_Error error) | |||
361 | * @return #GNUNET_YES (continue to iterate) | 356 | * @return #GNUNET_YES (continue to iterate) |
362 | */ | 357 | */ |
363 | static int | 358 | static int |
364 | rewatch_it (void *cls, const struct GNUNET_HashCode *key, void *value) | 359 | rewatch_it(void *cls, const struct GNUNET_HashCode *key, void *value) |
365 | { | 360 | { |
366 | struct GNUNET_PEERSTORE_Handle *h = cls; | 361 | struct GNUNET_PEERSTORE_Handle *h = cls; |
367 | struct GNUNET_PEERSTORE_WatchContext *wc = value; | 362 | struct GNUNET_PEERSTORE_WatchContext *wc = value; |
368 | struct StoreKeyHashMessage *hm; | 363 | struct StoreKeyHashMessage *hm; |
369 | struct GNUNET_MQ_Envelope *ev; | 364 | struct GNUNET_MQ_Envelope *ev; |
370 | 365 | ||
371 | ev = GNUNET_MQ_msg (hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH); | 366 | ev = GNUNET_MQ_msg(hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH); |
372 | hm->keyhash = wc->keyhash; | 367 | hm->keyhash = wc->keyhash; |
373 | GNUNET_MQ_send (h->mq, ev); | 368 | GNUNET_MQ_send(h->mq, ev); |
374 | return GNUNET_YES; | 369 | return GNUNET_YES; |
375 | } | 370 | } |
376 | 371 | ||
@@ -384,11 +379,11 @@ rewatch_it (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
384 | * @return #GNUNET_YES to continue iteration | 379 | * @return #GNUNET_YES to continue iteration |
385 | */ | 380 | */ |
386 | static int | 381 | static int |
387 | destroy_watch (void *cls, const struct GNUNET_HashCode *key, void *value) | 382 | destroy_watch(void *cls, const struct GNUNET_HashCode *key, void *value) |
388 | { | 383 | { |
389 | struct GNUNET_PEERSTORE_WatchContext *wc = value; | 384 | struct GNUNET_PEERSTORE_WatchContext *wc = value; |
390 | 385 | ||
391 | GNUNET_PEERSTORE_watch_cancel (wc); | 386 | GNUNET_PEERSTORE_watch_cancel(wc); |
392 | return GNUNET_YES; | 387 | return GNUNET_YES; |
393 | } | 388 | } |
394 | 389 | ||
@@ -401,14 +396,14 @@ destroy_watch (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
401 | * @param h Handle to the service. | 396 | * @param h Handle to the service. |
402 | */ | 397 | */ |
403 | static void | 398 | static void |
404 | final_disconnect (struct GNUNET_PEERSTORE_Handle *h) | 399 | final_disconnect(struct GNUNET_PEERSTORE_Handle *h) |
405 | { | 400 | { |
406 | if (NULL != h->mq) | 401 | if (NULL != h->mq) |
407 | { | 402 | { |
408 | GNUNET_MQ_destroy (h->mq); | 403 | GNUNET_MQ_destroy(h->mq); |
409 | h->mq = NULL; | 404 | h->mq = NULL; |
410 | } | 405 | } |
411 | GNUNET_free (h); | 406 | GNUNET_free(h); |
412 | } | 407 | } |
413 | 408 | ||
414 | 409 | ||
@@ -419,19 +414,19 @@ final_disconnect (struct GNUNET_PEERSTORE_Handle *h) | |||
419 | * @return NULL on error | 414 | * @return NULL on error |
420 | */ | 415 | */ |
421 | struct GNUNET_PEERSTORE_Handle * | 416 | struct GNUNET_PEERSTORE_Handle * |
422 | GNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | 417 | GNUNET_PEERSTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg) |
423 | { | 418 | { |
424 | struct GNUNET_PEERSTORE_Handle *h; | 419 | struct GNUNET_PEERSTORE_Handle *h; |
425 | 420 | ||
426 | h = GNUNET_new (struct GNUNET_PEERSTORE_Handle); | 421 | h = GNUNET_new(struct GNUNET_PEERSTORE_Handle); |
427 | h->cfg = cfg; | 422 | h->cfg = cfg; |
428 | h->disconnecting = GNUNET_NO; | 423 | h->disconnecting = GNUNET_NO; |
429 | reconnect (h); | 424 | reconnect(h); |
430 | if (NULL == h->mq) | 425 | if (NULL == h->mq) |
431 | { | 426 | { |
432 | GNUNET_free (h); | 427 | GNUNET_free(h); |
433 | return NULL; | 428 | return NULL; |
434 | } | 429 | } |
435 | return h; | 430 | return h; |
436 | } | 431 | } |
437 | 432 | ||
@@ -445,36 +440,36 @@ GNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
445 | * @param sync_first send any pending STORE requests before disconnecting | 440 | * @param sync_first send any pending STORE requests before disconnecting |
446 | */ | 441 | */ |
447 | void | 442 | void |
448 | GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h, int sync_first) | 443 | GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h, int sync_first) |
449 | { | 444 | { |
450 | struct GNUNET_PEERSTORE_IterateContext *ic; | 445 | struct GNUNET_PEERSTORE_IterateContext *ic; |
451 | struct GNUNET_PEERSTORE_StoreContext *sc; | 446 | struct GNUNET_PEERSTORE_StoreContext *sc; |
452 | 447 | ||
453 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting.\n"); | 448 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting.\n"); |
454 | if (NULL != h->watches) | 449 | if (NULL != h->watches) |
455 | { | 450 | { |
456 | GNUNET_CONTAINER_multihashmap_iterate (h->watches, &destroy_watch, NULL); | 451 | GNUNET_CONTAINER_multihashmap_iterate(h->watches, &destroy_watch, NULL); |
457 | GNUNET_CONTAINER_multihashmap_destroy (h->watches); | 452 | GNUNET_CONTAINER_multihashmap_destroy(h->watches); |
458 | h->watches = NULL; | 453 | h->watches = NULL; |
459 | } | 454 | } |
460 | while (NULL != (ic = h->iterate_head)) | 455 | while (NULL != (ic = h->iterate_head)) |
461 | { | 456 | { |
462 | GNUNET_break (0); | 457 | GNUNET_break(0); |
463 | GNUNET_PEERSTORE_iterate_cancel (ic); | 458 | GNUNET_PEERSTORE_iterate_cancel(ic); |
464 | } | 459 | } |
465 | if (NULL != h->store_head) | 460 | if (NULL != h->store_head) |
466 | { | ||
467 | if (GNUNET_YES == sync_first) | ||
468 | { | 461 | { |
469 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 462 | if (GNUNET_YES == sync_first) |
470 | "Delaying disconnection due to pending store requests.\n"); | 463 | { |
471 | h->disconnecting = GNUNET_YES; | 464 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
472 | return; | 465 | "Delaying disconnection due to pending store requests.\n"); |
466 | h->disconnecting = GNUNET_YES; | ||
467 | return; | ||
468 | } | ||
469 | while (NULL != (sc = h->store_head)) | ||
470 | GNUNET_PEERSTORE_store_cancel(sc); | ||
473 | } | 471 | } |
474 | while (NULL != (sc = h->store_head)) | 472 | final_disconnect(h); |
475 | GNUNET_PEERSTORE_store_cancel (sc); | ||
476 | } | ||
477 | final_disconnect (h); | ||
478 | } | 473 | } |
479 | 474 | ||
480 | 475 | ||
@@ -489,17 +484,17 @@ GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h, int sync_first) | |||
489 | * @param sc Store request context | 484 | * @param sc Store request context |
490 | */ | 485 | */ |
491 | void | 486 | void |
492 | GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc) | 487 | GNUNET_PEERSTORE_store_cancel(struct GNUNET_PEERSTORE_StoreContext *sc) |
493 | { | 488 | { |
494 | struct GNUNET_PEERSTORE_Handle *h = sc->h; | 489 | struct GNUNET_PEERSTORE_Handle *h = sc->h; |
495 | 490 | ||
496 | GNUNET_CONTAINER_DLL_remove (sc->h->store_head, sc->h->store_tail, sc); | 491 | GNUNET_CONTAINER_DLL_remove(sc->h->store_head, sc->h->store_tail, sc); |
497 | GNUNET_free (sc->sub_system); | 492 | GNUNET_free(sc->sub_system); |
498 | GNUNET_free (sc->value); | 493 | GNUNET_free(sc->value); |
499 | GNUNET_free (sc->key); | 494 | GNUNET_free(sc->key); |
500 | GNUNET_free (sc); | 495 | GNUNET_free(sc); |
501 | if ((GNUNET_YES == h->disconnecting) && (NULL == h->store_head)) | 496 | if ((GNUNET_YES == h->disconnecting) && (NULL == h->store_head)) |
502 | final_disconnect (h); | 497 | final_disconnect(h); |
503 | } | 498 | } |
504 | 499 | ||
505 | 500 | ||
@@ -520,41 +515,41 @@ GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc) | |||
520 | * @param cont_cls Closure for @a cont | 515 | * @param cont_cls Closure for @a cont |
521 | */ | 516 | */ |
522 | struct GNUNET_PEERSTORE_StoreContext * | 517 | struct GNUNET_PEERSTORE_StoreContext * |
523 | GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h, | 518 | GNUNET_PEERSTORE_store(struct GNUNET_PEERSTORE_Handle *h, |
524 | const char *sub_system, | 519 | const char *sub_system, |
525 | const struct GNUNET_PeerIdentity *peer, | 520 | const struct GNUNET_PeerIdentity *peer, |
526 | const char *key, | 521 | const char *key, |
527 | const void *value, | 522 | const void *value, |
528 | size_t size, | 523 | size_t size, |
529 | struct GNUNET_TIME_Absolute expiry, | 524 | struct GNUNET_TIME_Absolute expiry, |
530 | enum GNUNET_PEERSTORE_StoreOption options, | 525 | enum GNUNET_PEERSTORE_StoreOption options, |
531 | GNUNET_PEERSTORE_Continuation cont, | 526 | GNUNET_PEERSTORE_Continuation cont, |
532 | void *cont_cls) | 527 | void *cont_cls) |
533 | { | 528 | { |
534 | struct GNUNET_MQ_Envelope *ev; | 529 | struct GNUNET_MQ_Envelope *ev; |
535 | struct GNUNET_PEERSTORE_StoreContext *sc; | 530 | struct GNUNET_PEERSTORE_StoreContext *sc; |
536 | 531 | ||
537 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 532 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
538 | "Storing value (size: %lu) for subsytem `%s', peer `%s', key `%s'\n", | 533 | "Storing value (size: %lu) for subsytem `%s', peer `%s', key `%s'\n", |
539 | size, | 534 | size, |
540 | sub_system, | 535 | sub_system, |
541 | GNUNET_i2s (peer), | 536 | GNUNET_i2s(peer), |
542 | key); | 537 | key); |
543 | ev = | 538 | ev = |
544 | PEERSTORE_create_record_mq_envelope (sub_system, | 539 | PEERSTORE_create_record_mq_envelope(sub_system, |
545 | peer, | 540 | peer, |
546 | key, | 541 | key, |
547 | value, | 542 | value, |
548 | size, | 543 | size, |
549 | expiry, | 544 | expiry, |
550 | options, | 545 | options, |
551 | GNUNET_MESSAGE_TYPE_PEERSTORE_STORE); | 546 | GNUNET_MESSAGE_TYPE_PEERSTORE_STORE); |
552 | sc = GNUNET_new (struct GNUNET_PEERSTORE_StoreContext); | 547 | sc = GNUNET_new(struct GNUNET_PEERSTORE_StoreContext); |
553 | 548 | ||
554 | sc->sub_system = GNUNET_strdup (sub_system); | 549 | sc->sub_system = GNUNET_strdup(sub_system); |
555 | sc->peer = *peer; | 550 | sc->peer = *peer; |
556 | sc->key = GNUNET_strdup (key); | 551 | sc->key = GNUNET_strdup(key); |
557 | sc->value = GNUNET_memdup (value, size); | 552 | sc->value = GNUNET_memdup(value, size); |
558 | sc->size = size; | 553 | sc->size = size; |
559 | sc->expiry = expiry; | 554 | sc->expiry = expiry; |
560 | sc->options = options; | 555 | sc->options = options; |
@@ -562,9 +557,9 @@ GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h, | |||
562 | sc->cont_cls = cont_cls; | 557 | sc->cont_cls = cont_cls; |
563 | sc->h = h; | 558 | sc->h = h; |
564 | 559 | ||
565 | GNUNET_CONTAINER_DLL_insert_tail (h->store_head, h->store_tail, sc); | 560 | GNUNET_CONTAINER_DLL_insert_tail(h->store_head, h->store_tail, sc); |
566 | GNUNET_MQ_notify_sent (ev, &store_request_sent, sc); | 561 | GNUNET_MQ_notify_sent(ev, &store_request_sent, sc); |
567 | GNUNET_MQ_send (h->mq, ev); | 562 | GNUNET_MQ_send(h->mq, ev); |
568 | return sc; | 563 | return sc; |
569 | } | 564 | } |
570 | 565 | ||
@@ -581,7 +576,7 @@ GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h, | |||
581 | * @param msg message received | 576 | * @param msg message received |
582 | */ | 577 | */ |
583 | static void | 578 | static void |
584 | handle_iterate_end (void *cls, const struct GNUNET_MessageHeader *msg) | 579 | handle_iterate_end(void *cls, const struct GNUNET_MessageHeader *msg) |
585 | { | 580 | { |
586 | struct GNUNET_PEERSTORE_Handle *h = cls; | 581 | struct GNUNET_PEERSTORE_Handle *h = cls; |
587 | struct GNUNET_PEERSTORE_IterateContext *ic; | 582 | struct GNUNET_PEERSTORE_IterateContext *ic; |
@@ -590,18 +585,18 @@ handle_iterate_end (void *cls, const struct GNUNET_MessageHeader *msg) | |||
590 | 585 | ||
591 | ic = h->iterate_head; | 586 | ic = h->iterate_head; |
592 | if (NULL == ic) | 587 | if (NULL == ic) |
593 | { | 588 | { |
594 | LOG (GNUNET_ERROR_TYPE_ERROR, | 589 | LOG(GNUNET_ERROR_TYPE_ERROR, |
595 | _ ("Unexpected iteration response, this should not happen.\n")); | 590 | _("Unexpected iteration response, this should not happen.\n")); |
596 | disconnect_and_schedule_reconnect (h); | 591 | disconnect_and_schedule_reconnect(h); |
597 | return; | 592 | return; |
598 | } | 593 | } |
599 | callback = ic->callback; | 594 | callback = ic->callback; |
600 | callback_cls = ic->callback_cls; | 595 | callback_cls = ic->callback_cls; |
601 | ic->iterating = GNUNET_NO; | 596 | ic->iterating = GNUNET_NO; |
602 | GNUNET_PEERSTORE_iterate_cancel (ic); | 597 | GNUNET_PEERSTORE_iterate_cancel(ic); |
603 | if (NULL != callback) | 598 | if (NULL != callback) |
604 | callback (callback_cls, NULL, NULL); | 599 | callback(callback_cls, NULL, NULL); |
605 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; | 600 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; |
606 | } | 601 | } |
607 | 602 | ||
@@ -614,7 +609,7 @@ handle_iterate_end (void *cls, const struct GNUNET_MessageHeader *msg) | |||
614 | * @param msg message received | 609 | * @param msg message received |
615 | */ | 610 | */ |
616 | static int | 611 | static int |
617 | check_iterate_result (void *cls, const struct StoreRecordMessage *msg) | 612 | check_iterate_result(void *cls, const struct StoreRecordMessage *msg) |
618 | { | 613 | { |
619 | /* we defer validation to #handle_iterate_result */ | 614 | /* we defer validation to #handle_iterate_result */ |
620 | return GNUNET_OK; | 615 | return GNUNET_OK; |
@@ -628,7 +623,7 @@ check_iterate_result (void *cls, const struct StoreRecordMessage *msg) | |||
628 | * @param msg message received | 623 | * @param msg message received |
629 | */ | 624 | */ |
630 | static void | 625 | static void |
631 | handle_iterate_result (void *cls, const struct StoreRecordMessage *msg) | 626 | handle_iterate_result(void *cls, const struct StoreRecordMessage *msg) |
632 | { | 627 | { |
633 | struct GNUNET_PEERSTORE_Handle *h = cls; | 628 | struct GNUNET_PEERSTORE_Handle *h = cls; |
634 | struct GNUNET_PEERSTORE_IterateContext *ic; | 629 | struct GNUNET_PEERSTORE_IterateContext *ic; |
@@ -638,29 +633,29 @@ handle_iterate_result (void *cls, const struct StoreRecordMessage *msg) | |||
638 | 633 | ||
639 | ic = h->iterate_head; | 634 | ic = h->iterate_head; |
640 | if (NULL == ic) | 635 | if (NULL == ic) |
641 | { | 636 | { |
642 | LOG (GNUNET_ERROR_TYPE_ERROR, | 637 | LOG(GNUNET_ERROR_TYPE_ERROR, |
643 | _ ("Unexpected iteration response, this should not happen.\n")); | 638 | _("Unexpected iteration response, this should not happen.\n")); |
644 | disconnect_and_schedule_reconnect (h); | 639 | disconnect_and_schedule_reconnect(h); |
645 | return; | 640 | return; |
646 | } | 641 | } |
647 | ic->iterating = GNUNET_YES; | 642 | ic->iterating = GNUNET_YES; |
648 | callback = ic->callback; | 643 | callback = ic->callback; |
649 | callback_cls = ic->callback_cls; | 644 | callback_cls = ic->callback_cls; |
650 | if (NULL == callback) | 645 | if (NULL == callback) |
651 | return; | 646 | return; |
652 | record = PEERSTORE_parse_record_message (msg); | 647 | record = PEERSTORE_parse_record_message(msg); |
653 | if (NULL == record) | 648 | if (NULL == record) |
654 | { | 649 | { |
655 | callback (callback_cls, | 650 | callback(callback_cls, |
656 | NULL, | 651 | NULL, |
657 | _ ("Received a malformed response from service.")); | 652 | _("Received a malformed response from service.")); |
658 | } | 653 | } |
659 | else | 654 | else |
660 | { | 655 | { |
661 | callback (callback_cls, record, NULL); | 656 | callback(callback_cls, record, NULL); |
662 | PEERSTORE_destroy_record (record); | 657 | PEERSTORE_destroy_record(record); |
663 | } | 658 | } |
664 | } | 659 | } |
665 | 660 | ||
666 | 661 | ||
@@ -671,15 +666,15 @@ handle_iterate_result (void *cls, const struct StoreRecordMessage *msg) | |||
671 | * @param ic Iterate request context as returned by GNUNET_PEERSTORE_iterate() | 666 | * @param ic Iterate request context as returned by GNUNET_PEERSTORE_iterate() |
672 | */ | 667 | */ |
673 | void | 668 | void |
674 | GNUNET_PEERSTORE_iterate_cancel (struct GNUNET_PEERSTORE_IterateContext *ic) | 669 | GNUNET_PEERSTORE_iterate_cancel(struct GNUNET_PEERSTORE_IterateContext *ic) |
675 | { | 670 | { |
676 | if (GNUNET_NO == ic->iterating) | 671 | if (GNUNET_NO == ic->iterating) |
677 | { | 672 | { |
678 | GNUNET_CONTAINER_DLL_remove (ic->h->iterate_head, ic->h->iterate_tail, ic); | 673 | GNUNET_CONTAINER_DLL_remove(ic->h->iterate_head, ic->h->iterate_tail, ic); |
679 | GNUNET_free (ic->sub_system); | 674 | GNUNET_free(ic->sub_system); |
680 | GNUNET_free_non_null (ic->key); | 675 | GNUNET_free_non_null(ic->key); |
681 | GNUNET_free (ic); | 676 | GNUNET_free(ic); |
682 | } | 677 | } |
683 | else | 678 | else |
684 | ic->callback = NULL; | 679 | ic->callback = NULL; |
685 | } | 680 | } |
@@ -697,39 +692,39 @@ GNUNET_PEERSTORE_iterate_cancel (struct GNUNET_PEERSTORE_IterateContext *ic) | |||
697 | * @return Handle to iteration request | 692 | * @return Handle to iteration request |
698 | */ | 693 | */ |
699 | struct GNUNET_PEERSTORE_IterateContext * | 694 | struct GNUNET_PEERSTORE_IterateContext * |
700 | GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h, | 695 | GNUNET_PEERSTORE_iterate(struct GNUNET_PEERSTORE_Handle *h, |
701 | const char *sub_system, | 696 | const char *sub_system, |
702 | const struct GNUNET_PeerIdentity *peer, | 697 | const struct GNUNET_PeerIdentity *peer, |
703 | const char *key, | 698 | const char *key, |
704 | GNUNET_PEERSTORE_Processor callback, | 699 | GNUNET_PEERSTORE_Processor callback, |
705 | void *callback_cls) | 700 | void *callback_cls) |
706 | { | 701 | { |
707 | struct GNUNET_MQ_Envelope *ev; | 702 | struct GNUNET_MQ_Envelope *ev; |
708 | struct GNUNET_PEERSTORE_IterateContext *ic; | 703 | struct GNUNET_PEERSTORE_IterateContext *ic; |
709 | 704 | ||
710 | ev = | 705 | ev = |
711 | PEERSTORE_create_record_mq_envelope (sub_system, | 706 | PEERSTORE_create_record_mq_envelope(sub_system, |
712 | peer, | 707 | peer, |
713 | key, | 708 | key, |
714 | NULL, | 709 | NULL, |
715 | 0, | 710 | 0, |
716 | GNUNET_TIME_UNIT_FOREVER_ABS, | 711 | GNUNET_TIME_UNIT_FOREVER_ABS, |
717 | 0, | 712 | 0, |
718 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE); | 713 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE); |
719 | ic = GNUNET_new (struct GNUNET_PEERSTORE_IterateContext); | 714 | ic = GNUNET_new(struct GNUNET_PEERSTORE_IterateContext); |
720 | ic->callback = callback; | 715 | ic->callback = callback; |
721 | ic->callback_cls = callback_cls; | 716 | ic->callback_cls = callback_cls; |
722 | ic->h = h; | 717 | ic->h = h; |
723 | ic->sub_system = GNUNET_strdup (sub_system); | 718 | ic->sub_system = GNUNET_strdup(sub_system); |
724 | if (NULL != peer) | 719 | if (NULL != peer) |
725 | ic->peer = *peer; | 720 | ic->peer = *peer; |
726 | if (NULL != key) | 721 | if (NULL != key) |
727 | ic->key = GNUNET_strdup (key); | 722 | ic->key = GNUNET_strdup(key); |
728 | GNUNET_CONTAINER_DLL_insert_tail (h->iterate_head, h->iterate_tail, ic); | 723 | GNUNET_CONTAINER_DLL_insert_tail(h->iterate_head, h->iterate_tail, ic); |
729 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 724 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
730 | "Sending an iterate request for sub system `%s'\n", | 725 | "Sending an iterate request for sub system `%s'\n", |
731 | sub_system); | 726 | sub_system); |
732 | GNUNET_MQ_send (h->mq, ev); | 727 | GNUNET_MQ_send(h->mq, ev); |
733 | return ic; | 728 | return ic; |
734 | } | 729 | } |
735 | 730 | ||
@@ -745,7 +740,7 @@ GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h, | |||
745 | * @param msg message received | 740 | * @param msg message received |
746 | */ | 741 | */ |
747 | static int | 742 | static int |
748 | check_watch_record (void *cls, const struct StoreRecordMessage *msg) | 743 | check_watch_record(void *cls, const struct StoreRecordMessage *msg) |
749 | { | 744 | { |
750 | /* we defer validation to #handle_watch_result */ | 745 | /* we defer validation to #handle_watch_result */ |
751 | return GNUNET_OK; | 746 | return GNUNET_OK; |
@@ -759,35 +754,35 @@ check_watch_record (void *cls, const struct StoreRecordMessage *msg) | |||
759 | * @param msg message received | 754 | * @param msg message received |
760 | */ | 755 | */ |
761 | static void | 756 | static void |
762 | handle_watch_record (void *cls, const struct StoreRecordMessage *msg) | 757 | handle_watch_record(void *cls, const struct StoreRecordMessage *msg) |
763 | { | 758 | { |
764 | struct GNUNET_PEERSTORE_Handle *h = cls; | 759 | struct GNUNET_PEERSTORE_Handle *h = cls; |
765 | struct GNUNET_PEERSTORE_Record *record; | 760 | struct GNUNET_PEERSTORE_Record *record; |
766 | struct GNUNET_HashCode keyhash; | 761 | struct GNUNET_HashCode keyhash; |
767 | struct GNUNET_PEERSTORE_WatchContext *wc; | 762 | struct GNUNET_PEERSTORE_WatchContext *wc; |
768 | 763 | ||
769 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received a watch record from service.\n"); | 764 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Received a watch record from service.\n"); |
770 | record = PEERSTORE_parse_record_message (msg); | 765 | record = PEERSTORE_parse_record_message(msg); |
771 | if (NULL == record) | 766 | if (NULL == record) |
772 | { | 767 | { |
773 | disconnect_and_schedule_reconnect (h); | 768 | disconnect_and_schedule_reconnect(h); |
774 | return; | 769 | return; |
775 | } | 770 | } |
776 | PEERSTORE_hash_key (record->sub_system, &record->peer, record->key, &keyhash); | 771 | PEERSTORE_hash_key(record->sub_system, &record->peer, record->key, &keyhash); |
777 | // FIXME: what if there are multiple watches for the same key? | 772 | // FIXME: what if there are multiple watches for the same key? |
778 | wc = GNUNET_CONTAINER_multihashmap_get (h->watches, &keyhash); | 773 | wc = GNUNET_CONTAINER_multihashmap_get(h->watches, &keyhash); |
779 | if (NULL == wc) | 774 | if (NULL == wc) |
780 | { | 775 | { |
781 | LOG (GNUNET_ERROR_TYPE_ERROR, | 776 | LOG(GNUNET_ERROR_TYPE_ERROR, |
782 | _ ("Received a watch result for a non existing watch.\n")); | 777 | _("Received a watch result for a non existing watch.\n")); |
783 | PEERSTORE_destroy_record (record); | 778 | PEERSTORE_destroy_record(record); |
784 | disconnect_and_schedule_reconnect (h); | 779 | disconnect_and_schedule_reconnect(h); |
785 | return; | 780 | return; |
786 | } | 781 | } |
787 | if (NULL != wc->callback) | 782 | if (NULL != wc->callback) |
788 | wc->callback (wc->callback_cls, record, NULL); | 783 | wc->callback(wc->callback_cls, record, NULL); |
789 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; | 784 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; |
790 | PEERSTORE_destroy_record (record); | 785 | PEERSTORE_destroy_record(record); |
791 | } | 786 | } |
792 | 787 | ||
793 | 788 | ||
@@ -797,67 +792,67 @@ handle_watch_record (void *cls, const struct StoreRecordMessage *msg) | |||
797 | * @param cls a `struct GNUNET_PEERSTORE_Handle *` | 792 | * @param cls a `struct GNUNET_PEERSTORE_Handle *` |
798 | */ | 793 | */ |
799 | static void | 794 | static void |
800 | reconnect (void *cls) | 795 | reconnect(void *cls) |
801 | { | 796 | { |
802 | struct GNUNET_PEERSTORE_Handle *h = cls; | 797 | struct GNUNET_PEERSTORE_Handle *h = cls; |
803 | struct GNUNET_MQ_MessageHandler mq_handlers[] = | 798 | struct GNUNET_MQ_MessageHandler mq_handlers[] = |
804 | {GNUNET_MQ_hd_fixed_size (iterate_end, | 799 | { GNUNET_MQ_hd_fixed_size(iterate_end, |
805 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END, | 800 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END, |
806 | struct GNUNET_MessageHeader, | 801 | struct GNUNET_MessageHeader, |
807 | h), | ||
808 | GNUNET_MQ_hd_var_size (iterate_result, | ||
809 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD, | ||
810 | struct StoreRecordMessage, | ||
811 | h), | 802 | h), |
812 | GNUNET_MQ_hd_var_size (watch_record, | 803 | GNUNET_MQ_hd_var_size(iterate_result, |
813 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD, | 804 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD, |
814 | struct StoreRecordMessage, | 805 | struct StoreRecordMessage, |
815 | h), | 806 | h), |
816 | GNUNET_MQ_handler_end ()}; | 807 | GNUNET_MQ_hd_var_size(watch_record, |
808 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD, | ||
809 | struct StoreRecordMessage, | ||
810 | h), | ||
811 | GNUNET_MQ_handler_end() }; | ||
817 | struct GNUNET_MQ_Envelope *ev; | 812 | struct GNUNET_MQ_Envelope *ev; |
818 | 813 | ||
819 | h->reconnect_task = NULL; | 814 | h->reconnect_task = NULL; |
820 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting...\n"); | 815 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Reconnecting...\n"); |
821 | h->mq = GNUNET_CLIENT_connect (h->cfg, | 816 | h->mq = GNUNET_CLIENT_connect(h->cfg, |
822 | "peerstore", | 817 | "peerstore", |
823 | mq_handlers, | 818 | mq_handlers, |
824 | &handle_client_error, | 819 | &handle_client_error, |
825 | h); | 820 | h); |
826 | if (NULL == h->mq) | 821 | if (NULL == h->mq) |
827 | return; | 822 | return; |
828 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 823 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
829 | "Resending pending requests after reconnect.\n"); | 824 | "Resending pending requests after reconnect.\n"); |
830 | if (NULL != h->watches) | 825 | if (NULL != h->watches) |
831 | GNUNET_CONTAINER_multihashmap_iterate (h->watches, &rewatch_it, h); | 826 | GNUNET_CONTAINER_multihashmap_iterate(h->watches, &rewatch_it, h); |
832 | for (struct GNUNET_PEERSTORE_IterateContext *ic = h->iterate_head; NULL != ic; | 827 | for (struct GNUNET_PEERSTORE_IterateContext *ic = h->iterate_head; NULL != ic; |
833 | ic = ic->next) | 828 | ic = ic->next) |
834 | { | 829 | { |
835 | ev = | 830 | ev = |
836 | PEERSTORE_create_record_mq_envelope (ic->sub_system, | 831 | PEERSTORE_create_record_mq_envelope(ic->sub_system, |
837 | &ic->peer, | 832 | &ic->peer, |
838 | ic->key, | 833 | ic->key, |
839 | NULL, | 834 | NULL, |
840 | 0, | 835 | 0, |
841 | GNUNET_TIME_UNIT_FOREVER_ABS, | 836 | GNUNET_TIME_UNIT_FOREVER_ABS, |
842 | 0, | 837 | 0, |
843 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE); | 838 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE); |
844 | GNUNET_MQ_send (h->mq, ev); | 839 | GNUNET_MQ_send(h->mq, ev); |
845 | } | 840 | } |
846 | for (struct GNUNET_PEERSTORE_StoreContext *sc = h->store_head; NULL != sc; | 841 | for (struct GNUNET_PEERSTORE_StoreContext *sc = h->store_head; NULL != sc; |
847 | sc = sc->next) | 842 | sc = sc->next) |
848 | { | 843 | { |
849 | ev = | 844 | ev = |
850 | PEERSTORE_create_record_mq_envelope (sc->sub_system, | 845 | PEERSTORE_create_record_mq_envelope(sc->sub_system, |
851 | &sc->peer, | 846 | &sc->peer, |
852 | sc->key, | 847 | sc->key, |
853 | sc->value, | 848 | sc->value, |
854 | sc->size, | 849 | sc->size, |
855 | sc->expiry, | 850 | sc->expiry, |
856 | sc->options, | 851 | sc->options, |
857 | GNUNET_MESSAGE_TYPE_PEERSTORE_STORE); | 852 | GNUNET_MESSAGE_TYPE_PEERSTORE_STORE); |
858 | GNUNET_MQ_notify_sent (ev, &store_request_sent, sc); | 853 | GNUNET_MQ_notify_sent(ev, &store_request_sent, sc); |
859 | GNUNET_MQ_send (h->mq, ev); | 854 | GNUNET_MQ_send(h->mq, ev); |
860 | } | 855 | } |
861 | } | 856 | } |
862 | 857 | ||
863 | 858 | ||
@@ -867,20 +862,20 @@ reconnect (void *cls) | |||
867 | * @param wc handle to the watch request | 862 | * @param wc handle to the watch request |
868 | */ | 863 | */ |
869 | void | 864 | void |
870 | GNUNET_PEERSTORE_watch_cancel (struct GNUNET_PEERSTORE_WatchContext *wc) | 865 | GNUNET_PEERSTORE_watch_cancel(struct GNUNET_PEERSTORE_WatchContext *wc) |
871 | { | 866 | { |
872 | struct GNUNET_PEERSTORE_Handle *h = wc->h; | 867 | struct GNUNET_PEERSTORE_Handle *h = wc->h; |
873 | struct GNUNET_MQ_Envelope *ev; | 868 | struct GNUNET_MQ_Envelope *ev; |
874 | struct StoreKeyHashMessage *hm; | 869 | struct StoreKeyHashMessage *hm; |
875 | 870 | ||
876 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Canceling watch.\n"); | 871 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Canceling watch.\n"); |
877 | ev = GNUNET_MQ_msg (hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL); | 872 | ev = GNUNET_MQ_msg(hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL); |
878 | hm->keyhash = wc->keyhash; | 873 | hm->keyhash = wc->keyhash; |
879 | GNUNET_MQ_send (h->mq, ev); | 874 | GNUNET_MQ_send(h->mq, ev); |
880 | GNUNET_assert ( | 875 | GNUNET_assert( |
881 | GNUNET_YES == | 876 | GNUNET_YES == |
882 | GNUNET_CONTAINER_multihashmap_remove (h->watches, &wc->keyhash, wc)); | 877 | GNUNET_CONTAINER_multihashmap_remove(h->watches, &wc->keyhash, wc)); |
883 | GNUNET_free (wc); | 878 | GNUNET_free(wc); |
884 | } | 879 | } |
885 | 880 | ||
886 | 881 | ||
@@ -897,37 +892,37 @@ GNUNET_PEERSTORE_watch_cancel (struct GNUNET_PEERSTORE_WatchContext *wc) | |||
897 | * @return Handle to watch request | 892 | * @return Handle to watch request |
898 | */ | 893 | */ |
899 | struct GNUNET_PEERSTORE_WatchContext * | 894 | struct GNUNET_PEERSTORE_WatchContext * |
900 | GNUNET_PEERSTORE_watch (struct GNUNET_PEERSTORE_Handle *h, | 895 | GNUNET_PEERSTORE_watch(struct GNUNET_PEERSTORE_Handle *h, |
901 | const char *sub_system, | 896 | const char *sub_system, |
902 | const struct GNUNET_PeerIdentity *peer, | 897 | const struct GNUNET_PeerIdentity *peer, |
903 | const char *key, | 898 | const char *key, |
904 | GNUNET_PEERSTORE_Processor callback, | 899 | GNUNET_PEERSTORE_Processor callback, |
905 | void *callback_cls) | 900 | void *callback_cls) |
906 | { | 901 | { |
907 | struct GNUNET_MQ_Envelope *ev; | 902 | struct GNUNET_MQ_Envelope *ev; |
908 | struct StoreKeyHashMessage *hm; | 903 | struct StoreKeyHashMessage *hm; |
909 | struct GNUNET_PEERSTORE_WatchContext *wc; | 904 | struct GNUNET_PEERSTORE_WatchContext *wc; |
910 | 905 | ||
911 | ev = GNUNET_MQ_msg (hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH); | 906 | ev = GNUNET_MQ_msg(hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH); |
912 | PEERSTORE_hash_key (sub_system, peer, key, &hm->keyhash); | 907 | PEERSTORE_hash_key(sub_system, peer, key, &hm->keyhash); |
913 | wc = GNUNET_new (struct GNUNET_PEERSTORE_WatchContext); | 908 | wc = GNUNET_new(struct GNUNET_PEERSTORE_WatchContext); |
914 | wc->callback = callback; | 909 | wc->callback = callback; |
915 | wc->callback_cls = callback_cls; | 910 | wc->callback_cls = callback_cls; |
916 | wc->h = h; | 911 | wc->h = h; |
917 | wc->keyhash = hm->keyhash; | 912 | wc->keyhash = hm->keyhash; |
918 | if (NULL == h->watches) | 913 | if (NULL == h->watches) |
919 | h->watches = GNUNET_CONTAINER_multihashmap_create (5, GNUNET_NO); | 914 | h->watches = GNUNET_CONTAINER_multihashmap_create(5, GNUNET_NO); |
920 | GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put ( | 915 | GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multihashmap_put( |
921 | h->watches, | 916 | h->watches, |
922 | &wc->keyhash, | 917 | &wc->keyhash, |
923 | wc, | 918 | wc, |
924 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 919 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
925 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 920 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
926 | "Sending a watch request for subsystem `%s', peer `%s', key `%s'.\n", | 921 | "Sending a watch request for subsystem `%s', peer `%s', key `%s'.\n", |
927 | sub_system, | 922 | sub_system, |
928 | GNUNET_i2s (peer), | 923 | GNUNET_i2s(peer), |
929 | key); | 924 | key); |
930 | GNUNET_MQ_send (h->mq, ev); | 925 | GNUNET_MQ_send(h->mq, ev); |
931 | return wc; | 926 | return wc; |
932 | } | 927 | } |
933 | 928 | ||