diff options
Diffstat (limited to 'src/service/peerstore/peerstore_api.c')
-rw-r--r-- | src/service/peerstore/peerstore_api.c | 128 |
1 files changed, 49 insertions, 79 deletions
diff --git a/src/service/peerstore/peerstore_api.c b/src/service/peerstore/peerstore_api.c index 9014193c7..3dec7e01b 100644 --- a/src/service/peerstore/peerstore_api.c +++ b/src/service/peerstore/peerstore_api.c | |||
@@ -86,10 +86,6 @@ struct GNUNET_PEERSTORE_Handle | |||
86 | */ | 86 | */ |
87 | struct GNUNET_TIME_Relative reconnect_delay; | 87 | struct GNUNET_TIME_Relative reconnect_delay; |
88 | 88 | ||
89 | /** | ||
90 | * Are we in the process of disconnecting but need to sync first? | ||
91 | */ | ||
92 | int disconnecting; | ||
93 | }; | 89 | }; |
94 | 90 | ||
95 | /** | 91 | /** |
@@ -465,25 +461,6 @@ destroy_watch (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
465 | 461 | ||
466 | 462 | ||
467 | /** | 463 | /** |
468 | * Kill the connection to the service. This can be delayed in case of pending | ||
469 | * STORE requests and the user explicitly asked to sync first. Otherwise it is | ||
470 | * performed instantly. | ||
471 | * | ||
472 | * @param h Handle to the service. | ||
473 | */ | ||
474 | static void | ||
475 | final_disconnect (struct GNUNET_PEERSTORE_Handle *h) | ||
476 | { | ||
477 | if (NULL != h->mq) | ||
478 | { | ||
479 | GNUNET_MQ_destroy (h->mq); | ||
480 | h->mq = NULL; | ||
481 | } | ||
482 | GNUNET_free (h); | ||
483 | } | ||
484 | |||
485 | |||
486 | /** | ||
487 | * Connect to the PEERSTORE service. | 464 | * Connect to the PEERSTORE service. |
488 | * | 465 | * |
489 | * @param cfg configuration to use | 466 | * @param cfg configuration to use |
@@ -496,7 +473,6 @@ GNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
496 | 473 | ||
497 | h = GNUNET_new (struct GNUNET_PEERSTORE_Handle); | 474 | h = GNUNET_new (struct GNUNET_PEERSTORE_Handle); |
498 | h->cfg = cfg; | 475 | h->cfg = cfg; |
499 | h->disconnecting = GNUNET_NO; | ||
500 | reconnect (h); | 476 | reconnect (h); |
501 | if (NULL == h->mq) | 477 | if (NULL == h->mq) |
502 | { | 478 | { |
@@ -513,10 +489,9 @@ GNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
513 | * Any pending STORE requests will depend on @e snyc_first flag. | 489 | * Any pending STORE requests will depend on @e snyc_first flag. |
514 | * | 490 | * |
515 | * @param h handle to disconnect | 491 | * @param h handle to disconnect |
516 | * @param sync_first send any pending STORE requests before disconnecting | ||
517 | */ | 492 | */ |
518 | void | 493 | void |
519 | GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h, int sync_first) | 494 | GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h) |
520 | { | 495 | { |
521 | struct GNUNET_PEERSTORE_IterateContext *ic; | 496 | struct GNUNET_PEERSTORE_IterateContext *ic; |
522 | struct GNUNET_PEERSTORE_StoreContext *sc; | 497 | struct GNUNET_PEERSTORE_StoreContext *sc; |
@@ -533,19 +508,12 @@ GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h, int sync_first) | |||
533 | GNUNET_break (0); | 508 | GNUNET_break (0); |
534 | GNUNET_PEERSTORE_iterate_cancel (ic); | 509 | GNUNET_PEERSTORE_iterate_cancel (ic); |
535 | } | 510 | } |
536 | if (NULL != h->store_head) | 511 | while (NULL != (sc = h->store_head)) |
537 | { | 512 | { |
538 | if (GNUNET_YES == sync_first) | 513 | GNUNET_break (0); |
539 | { | 514 | GNUNET_PEERSTORE_store_cancel (sc); |
540 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
541 | "Delaying disconnection due to pending store requests.\n"); | ||
542 | h->disconnecting = GNUNET_YES; | ||
543 | return; | ||
544 | } | ||
545 | while (NULL != (sc = h->store_head)) | ||
546 | GNUNET_PEERSTORE_store_cancel (sc); | ||
547 | } | 515 | } |
548 | final_disconnect (h); | 516 | disconnect (h); |
549 | } | 517 | } |
550 | 518 | ||
551 | 519 | ||
@@ -562,8 +530,6 @@ GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h, int sync_first) | |||
562 | void | 530 | void |
563 | GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc) | 531 | GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc) |
564 | { | 532 | { |
565 | struct GNUNET_PEERSTORE_Handle *h = sc->h; | ||
566 | |||
567 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 533 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
568 | "store cancel with sc %p \n", | 534 | "store cancel with sc %p \n", |
569 | sc); | 535 | sc); |
@@ -575,8 +541,6 @@ GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc) | |||
575 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 541 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
576 | "store cancel with sc %p is null\n", | 542 | "store cancel with sc %p is null\n", |
577 | sc); | 543 | sc); |
578 | if ((GNUNET_YES == h->disconnecting) && (NULL == h->store_head)) | ||
579 | final_disconnect (h); | ||
580 | } | 544 | } |
581 | 545 | ||
582 | 546 | ||
@@ -751,15 +715,15 @@ handle_iterate_result (void *cls, const struct StoreRecordMessage *msg) | |||
751 | void | 715 | void |
752 | GNUNET_PEERSTORE_iterate_cancel (struct GNUNET_PEERSTORE_IterateContext *ic) | 716 | GNUNET_PEERSTORE_iterate_cancel (struct GNUNET_PEERSTORE_IterateContext *ic) |
753 | { | 717 | { |
754 | if (GNUNET_NO == ic->iterating) | 718 | if (GNUNET_YES == ic->iterating) |
755 | { | 719 | { |
756 | GNUNET_CONTAINER_DLL_remove (ic->h->iterate_head, ic->h->iterate_tail, ic); | 720 | if (NULL != ic->callback) |
757 | GNUNET_free (ic->sub_system); | 721 | ic->callback (ic->callback_cls, NULL, "Iteration canceled due to reconnection"); |
758 | GNUNET_free (ic->key); | ||
759 | GNUNET_free (ic); | ||
760 | } | 722 | } |
761 | else | 723 | GNUNET_CONTAINER_DLL_remove (ic->h->iterate_head, ic->h->iterate_tail, ic); |
762 | ic->callback = NULL; | 724 | GNUNET_free (ic->sub_system); |
725 | GNUNET_free (ic->key); | ||
726 | GNUNET_free (ic); | ||
763 | } | 727 | } |
764 | 728 | ||
765 | 729 | ||
@@ -965,8 +929,8 @@ GNUNET_PEERSTORE_watch_cancel (struct GNUNET_PEERSTORE_WatchContext *wc) | |||
965 | 929 | ||
966 | static void | 930 | static void |
967 | watch_iterate (void *cls, | 931 | watch_iterate (void *cls, |
968 | const struct GNUNET_PEERSTORE_Record *record, | 932 | const struct GNUNET_PEERSTORE_Record *record, |
969 | const char *emsg) | 933 | const char *emsg) |
970 | { | 934 | { |
971 | struct GNUNET_PEERSTORE_WatchContext *wc = cls; | 935 | struct GNUNET_PEERSTORE_WatchContext *wc = cls; |
972 | struct GNUNET_PEERSTORE_Handle *h = wc->h; | 936 | struct GNUNET_PEERSTORE_Handle *h = wc->h; |
@@ -1053,11 +1017,11 @@ GNUNET_PEERSTORE_watch (struct GNUNET_PEERSTORE_Handle *h, | |||
1053 | wc->sub_system = sub_system; | 1017 | wc->sub_system = sub_system; |
1054 | 1018 | ||
1055 | wc->ic = GNUNET_PEERSTORE_iterate (h, | 1019 | wc->ic = GNUNET_PEERSTORE_iterate (h, |
1056 | sub_system, | 1020 | sub_system, |
1057 | peer, | 1021 | peer, |
1058 | key, | 1022 | key, |
1059 | &watch_iterate, | 1023 | &watch_iterate, |
1060 | wc); | 1024 | wc); |
1061 | 1025 | ||
1062 | return wc; | 1026 | return wc; |
1063 | } | 1027 | } |
@@ -1091,7 +1055,8 @@ hello_updated (void *cls, | |||
1091 | hello = record->value; | 1055 | hello = record->value; |
1092 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1056 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1093 | "hello_updated with expired %s and size %u for peer %s\n", | 1057 | "hello_updated with expired %s and size %u for peer %s\n", |
1094 | GNUNET_STRINGS_absolute_time_to_string (GNUNET_HELLO_builder_get_expiration_time (hello)), | 1058 | GNUNET_STRINGS_absolute_time_to_string ( |
1059 | GNUNET_HELLO_builder_get_expiration_time (hello)), | ||
1095 | ntohs (hello->size), | 1060 | ntohs (hello->size), |
1096 | GNUNET_i2s (&record->peer)); | 1061 | GNUNET_i2s (&record->peer)); |
1097 | if ((0 == record->value_size)) | 1062 | if ((0 == record->value_size)) |
@@ -1119,11 +1084,11 @@ GNUNET_PEERSTORE_hello_changed_notify (struct GNUNET_PEERSTORE_Handle *h, | |||
1119 | nc->h = h; | 1084 | nc->h = h; |
1120 | 1085 | ||
1121 | nc->wc = GNUNET_PEERSTORE_watch (h, | 1086 | nc->wc = GNUNET_PEERSTORE_watch (h, |
1122 | "peerstore", | 1087 | "peerstore", |
1123 | NULL, | 1088 | NULL, |
1124 | GNUNET_PEERSTORE_HELLO_KEY, | 1089 | GNUNET_PEERSTORE_HELLO_KEY, |
1125 | &hello_updated, | 1090 | &hello_updated, |
1126 | nc); | 1091 | nc); |
1127 | 1092 | ||
1128 | return nc; | 1093 | return nc; |
1129 | } | 1094 | } |
@@ -1152,7 +1117,8 @@ merge_success (void *cls, int success) | |||
1152 | struct StoreHelloCls *shu_cls = cls; | 1117 | struct StoreHelloCls *shu_cls = cls; |
1153 | struct GNUNET_PEERSTORE_StoreHelloContext *huc = shu_cls->huc; | 1118 | struct GNUNET_PEERSTORE_StoreHelloContext *huc = shu_cls->huc; |
1154 | 1119 | ||
1155 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_remove (huc->store_context_map, huc->pid, shu_cls->sc)) | 1120 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_remove (huc->store_context_map, |
1121 | huc->pid, shu_cls->sc)) | ||
1156 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1122 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1157 | "There was no store context to be removed after storing hello for peer %s\n", | 1123 | "There was no store context to be removed after storing hello for peer %s\n", |
1158 | GNUNET_i2s (huc->pid)); | 1124 | GNUNET_i2s (huc->pid)); |
@@ -1213,14 +1179,16 @@ store_hello (struct GNUNET_PEERSTORE_StoreHelloContext *huc, | |||
1213 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1179 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1214 | "store_hello with expiration %s\n", | 1180 | "store_hello with expiration %s\n", |
1215 | GNUNET_STRINGS_absolute_time_to_string (hello_exp)); | 1181 | GNUNET_STRINGS_absolute_time_to_string (hello_exp)); |
1216 | GNUNET_assert (GNUNET_SYSERR != GNUNET_CONTAINER_multipeermap_put (huc->store_context_map, | 1182 | GNUNET_assert (GNUNET_SYSERR != GNUNET_CONTAINER_multipeermap_put ( |
1217 | huc->pid, | 1183 | huc->store_context_map, |
1218 | sc, | 1184 | huc->pid, |
1219 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 1185 | sc, |
1186 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | ||
1220 | shu_cls->sc = sc; | 1187 | shu_cls->sc = sc; |
1221 | } | 1188 | } |
1222 | 1189 | ||
1223 | //TODO Find a better name for the function. We do not merge, but replace, if there is a storing process | 1190 | |
1191 | // TODO Find a better name for the function. We do not merge, but replace, if there is a storing process | ||
1224 | // during another store process with a newer hello. | 1192 | // during another store process with a newer hello. |
1225 | static void | 1193 | static void |
1226 | merge_uri (void *cls, | 1194 | merge_uri (void *cls, |
@@ -1249,11 +1217,12 @@ merge_uri (void *cls, | |||
1249 | GNUNET_STRINGS_absolute_time_to_string (huc_hello_exp_time)); | 1217 | GNUNET_STRINGS_absolute_time_to_string (huc_hello_exp_time)); |
1250 | store_hello (huc, huc->hello); | 1218 | store_hello (huc, huc->hello); |
1251 | } | 1219 | } |
1252 | else if (GNUNET_NO == huc->success && 0 == GNUNET_memcmp (huc->pid, &record->peer)) | 1220 | else if (GNUNET_NO == huc->success && 0 == GNUNET_memcmp (huc->pid, |
1221 | &record->peer)) | ||
1253 | { | 1222 | { |
1254 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1223 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1255 | "merge_uri record for peer %s\n", | 1224 | "merge_uri record for peer %s\n", |
1256 | GNUNET_i2s (&record->peer)); | 1225 | GNUNET_i2s (&record->peer)); |
1257 | hello = record->value; | 1226 | hello = record->value; |
1258 | if ((0 == record->value_size)) | 1227 | if ((0 == record->value_size)) |
1259 | { | 1228 | { |
@@ -1310,11 +1279,11 @@ GNUNET_PEERSTORE_hello_add (struct GNUNET_PEERSTORE_Handle *h, | |||
1310 | GNUNET_STRINGS_absolute_time_to_string (huc_exp), | 1279 | GNUNET_STRINGS_absolute_time_to_string (huc_exp), |
1311 | size_msg); | 1280 | size_msg); |
1312 | huc->wc = GNUNET_PEERSTORE_watch (h, | 1281 | huc->wc = GNUNET_PEERSTORE_watch (h, |
1313 | "peerstore", | 1282 | "peerstore", |
1314 | NULL, | 1283 | NULL, |
1315 | GNUNET_PEERSTORE_HELLO_KEY, | 1284 | GNUNET_PEERSTORE_HELLO_KEY, |
1316 | &merge_uri, | 1285 | &merge_uri, |
1317 | huc); | 1286 | huc); |
1318 | GNUNET_HELLO_builder_free (builder); | 1287 | GNUNET_HELLO_builder_free (builder); |
1319 | 1288 | ||
1320 | return huc; | 1289 | return huc; |
@@ -1322,13 +1291,14 @@ GNUNET_PEERSTORE_hello_add (struct GNUNET_PEERSTORE_Handle *h, | |||
1322 | 1291 | ||
1323 | 1292 | ||
1324 | static enum GNUNET_GenericReturnValue | 1293 | static enum GNUNET_GenericReturnValue |
1325 | free_store_context(void *cls, | 1294 | free_store_context (void *cls, |
1326 | const struct GNUNET_PeerIdentity *key, | 1295 | const struct GNUNET_PeerIdentity *key, |
1327 | void *value) | 1296 | void *value) |
1328 | { | 1297 | { |
1329 | (void) cls; | 1298 | (void) cls; |
1330 | 1299 | ||
1331 | GNUNET_PEERSTORE_store_cancel ((struct GNUNET_PEERSTORE_StoreContext *) value); | 1300 | GNUNET_PEERSTORE_store_cancel ((struct |
1301 | GNUNET_PEERSTORE_StoreContext *) value); | ||
1332 | return GNUNET_YES; // FIXME why is this a map anyway | 1302 | return GNUNET_YES; // FIXME why is this a map anyway |
1333 | } | 1303 | } |
1334 | 1304 | ||