diff options
author | Gabor X Toth <*@tg-x.net> | 2015-09-26 17:09:48 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2015-09-26 17:09:48 +0000 |
commit | 0c5cea1c26efb8b53f643a6ce6b162d9c9fe2b8f (patch) | |
tree | da1f58068d54688c560c2cb464dc8ce4053874a1 /src/psycstore | |
parent | 68e2709a38f9c481f96024138a6f9ae57a280a57 (diff) | |
download | gnunet-0c5cea1c26efb8b53f643a6ce6b162d9c9fe2b8f.tar.gz gnunet-0c5cea1c26efb8b53f643a6ce6b162d9c9fe2b8f.zip |
psycstore: add fragment_limit arg for message_get
Diffstat (limited to 'src/psycstore')
-rw-r--r-- | src/psycstore/gnunet-service-psycstore.c | 31 | ||||
-rw-r--r-- | src/psycstore/plugin_psycstore_sqlite.c | 10 | ||||
-rw-r--r-- | src/psycstore/psycstore.h | 5 | ||||
-rw-r--r-- | src/psycstore/psycstore_api.c | 4 | ||||
-rw-r--r-- | src/psycstore/test_plugin_psycstore.c | 2 | ||||
-rw-r--r-- | src/psycstore/test_psycstore.c | 2 |
6 files changed, 37 insertions, 17 deletions
diff --git a/src/psycstore/gnunet-service-psycstore.c b/src/psycstore/gnunet-service-psycstore.c index 44103c6a0..53e593455 100644 --- a/src/psycstore/gnunet-service-psycstore.c +++ b/src/psycstore/gnunet-service-psycstore.c | |||
@@ -319,8 +319,10 @@ handle_fragment_get (void *cls, | |||
319 | const struct FragmentGetRequest * | 319 | const struct FragmentGetRequest * |
320 | req = (const struct FragmentGetRequest *) msg; | 320 | req = (const struct FragmentGetRequest *) msg; |
321 | struct SendClosure | 321 | struct SendClosure |
322 | sc = { .op_id = req->op_id, .client = client, | 322 | sc = { .op_id = req->op_id, |
323 | .channel_key = req->channel_key, .slave_key = req->slave_key, | 323 | .client = client, |
324 | .channel_key = req->channel_key, | ||
325 | .slave_key = req->slave_key, | ||
324 | .membership_test = req->do_membership_test }; | 326 | .membership_test = req->do_membership_test }; |
325 | 327 | ||
326 | int64_t ret; | 328 | int64_t ret; |
@@ -332,10 +334,10 @@ handle_fragment_get (void *cls, | |||
332 | if (0 == limit) | 334 | if (0 == limit) |
333 | ret = db->fragment_get (db->cls, &req->channel_key, | 335 | ret = db->fragment_get (db->cls, &req->channel_key, |
334 | first_fragment_id, last_fragment_id, | 336 | first_fragment_id, last_fragment_id, |
335 | &ret_frags, &send_fragment, &sc); | 337 | &ret_frags, send_fragment, &sc); |
336 | else | 338 | else |
337 | ret = db->fragment_get_latest (db->cls, &req->channel_key, limit, | 339 | ret = db->fragment_get_latest (db->cls, &req->channel_key, limit, |
338 | &ret_frags, &send_fragment, &sc); | 340 | &ret_frags, send_fragment, &sc); |
339 | 341 | ||
340 | switch (ret) | 342 | switch (ret) |
341 | { | 343 | { |
@@ -389,24 +391,27 @@ handle_message_get (void *cls, | |||
389 | } | 391 | } |
390 | 392 | ||
391 | struct SendClosure | 393 | struct SendClosure |
392 | sc = { .op_id = req->op_id, .client = client, | 394 | sc = { .op_id = req->op_id, |
393 | .channel_key = req->channel_key, .slave_key = req->slave_key, | 395 | .client = client, |
396 | .channel_key = req->channel_key, | ||
397 | .slave_key = req->slave_key, | ||
394 | .membership_test = req->do_membership_test }; | 398 | .membership_test = req->do_membership_test }; |
395 | 399 | ||
396 | int64_t ret; | 400 | int64_t ret; |
397 | uint64_t ret_frags = 0; | 401 | uint64_t ret_frags = 0; |
398 | uint64_t first_message_id = GNUNET_ntohll (req->first_message_id); | 402 | uint64_t first_message_id = GNUNET_ntohll (req->first_message_id); |
399 | uint64_t last_message_id = GNUNET_ntohll (req->last_message_id); | 403 | uint64_t last_message_id = GNUNET_ntohll (req->last_message_id); |
400 | uint64_t limit = GNUNET_ntohll (req->message_limit); | 404 | uint64_t msg_limit = GNUNET_ntohll (req->message_limit); |
405 | uint64_t frag_limit = GNUNET_ntohll (req->fragment_limit); | ||
401 | 406 | ||
402 | /** @todo method_prefix */ | 407 | /** @todo method_prefix */ |
403 | if (0 == limit) | 408 | if (0 == msg_limit) |
404 | ret = db->message_get (db->cls, &req->channel_key, | 409 | ret = db->message_get (db->cls, &req->channel_key, |
405 | first_message_id, last_message_id, | 410 | first_message_id, last_message_id, frag_limit, |
406 | &ret_frags, &send_fragment, &sc); | 411 | &ret_frags, send_fragment, &sc); |
407 | else | 412 | else |
408 | ret = db->message_get_latest (db->cls, &req->channel_key, limit, | 413 | ret = db->message_get_latest (db->cls, &req->channel_key, msg_limit, |
409 | &ret_frags, &send_fragment, &sc); | 414 | &ret_frags, send_fragment, &sc); |
410 | 415 | ||
411 | switch (ret) | 416 | switch (ret) |
412 | { | 417 | { |
@@ -661,7 +666,7 @@ handle_state_modify (void *cls, | |||
661 | else | 666 | else |
662 | { | 667 | { |
663 | ret = db->message_get (db->cls, &req->channel_key, | 668 | ret = db->message_get (db->cls, &req->channel_key, |
664 | message_id, message_id, | 669 | message_id, message_id, 0, |
665 | &ret_frags, recv_state_fragment, &scls); | 670 | &ret_frags, recv_state_fragment, &scls); |
666 | if (GNUNET_OK != ret) | 671 | if (GNUNET_OK != ret) |
667 | { | 672 | { |
diff --git a/src/psycstore/plugin_psycstore_sqlite.c b/src/psycstore/plugin_psycstore_sqlite.c index 8f9a3ef63..4ad3b1517 100644 --- a/src/psycstore/plugin_psycstore_sqlite.c +++ b/src/psycstore/plugin_psycstore_sqlite.c | |||
@@ -472,7 +472,8 @@ database_setup (struct Plugin *plugin) | |||
472 | " multicast_flags, psycstore_flags, data\n" | 472 | " multicast_flags, psycstore_flags, data\n" |
473 | "FROM messages\n" | 473 | "FROM messages\n" |
474 | "WHERE channel_id = (SELECT id FROM channels WHERE pub_key = ?)\n" | 474 | "WHERE channel_id = (SELECT id FROM channels WHERE pub_key = ?)\n" |
475 | " AND ? <= message_id AND message_id <= ?;", | 475 | " AND ? <= message_id AND message_id <= ?" |
476 | "LIMIT ?;", | ||
476 | &plugin->select_messages); | 477 | &plugin->select_messages); |
477 | 478 | ||
478 | sql_prepare (plugin->dbh, | 479 | sql_prepare (plugin->dbh, |
@@ -1195,6 +1196,7 @@ message_get (void *cls, | |||
1195 | const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key, | 1196 | const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key, |
1196 | uint64_t first_message_id, | 1197 | uint64_t first_message_id, |
1197 | uint64_t last_message_id, | 1198 | uint64_t last_message_id, |
1199 | uint64_t fragment_limit, | ||
1198 | uint64_t *returned_fragments, | 1200 | uint64_t *returned_fragments, |
1199 | GNUNET_PSYCSTORE_FragmentCallback cb, | 1201 | GNUNET_PSYCSTORE_FragmentCallback cb, |
1200 | void *cb_cls) | 1202 | void *cb_cls) |
@@ -1208,7 +1210,11 @@ message_get (void *cls, | |||
1208 | sizeof (*channel_key), | 1210 | sizeof (*channel_key), |
1209 | SQLITE_STATIC) | 1211 | SQLITE_STATIC) |
1210 | || SQLITE_OK != sqlite3_bind_int64 (stmt, 2, first_message_id) | 1212 | || SQLITE_OK != sqlite3_bind_int64 (stmt, 2, first_message_id) |
1211 | || SQLITE_OK != sqlite3_bind_int64 (stmt, 3, last_message_id)) | 1213 | || SQLITE_OK != sqlite3_bind_int64 (stmt, 3, last_message_id) |
1214 | || SQLITE_OK != sqlite3_bind_int64 (stmt, 4, | ||
1215 | (0 != fragment_limit) | ||
1216 | ? fragment_limit | ||
1217 | : -1)) | ||
1212 | { | 1218 | { |
1213 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 1219 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
1214 | "sqlite3_bind"); | 1220 | "sqlite3_bind"); |
diff --git a/src/psycstore/psycstore.h b/src/psycstore/psycstore.h index 67104e8ad..831b5c550 100644 --- a/src/psycstore/psycstore.h +++ b/src/psycstore/psycstore.h | |||
@@ -345,6 +345,11 @@ struct MessageGetRequest | |||
345 | uint64_t message_limit GNUNET_PACKED; | 345 | uint64_t message_limit GNUNET_PACKED; |
346 | 346 | ||
347 | /** | 347 | /** |
348 | * Maximum number of fragments to retrieve. | ||
349 | */ | ||
350 | uint64_t fragment_limit GNUNET_PACKED; | ||
351 | |||
352 | /** | ||
348 | * Do membership test with @a slave_key before returning fragment? | 353 | * Do membership test with @a slave_key before returning fragment? |
349 | * #GNUNET_YES or #GNUNET_NO | 354 | * #GNUNET_YES or #GNUNET_NO |
350 | */ | 355 | */ |
diff --git a/src/psycstore/psycstore_api.c b/src/psycstore/psycstore_api.c index f378be210..8f067b452 100644 --- a/src/psycstore/psycstore_api.c +++ b/src/psycstore/psycstore_api.c | |||
@@ -965,6 +965,8 @@ GNUNET_PSYCSTORE_fragment_get_latest (struct GNUNET_PSYCSTORE_Handle *h, | |||
965 | * First message ID to retrieve. | 965 | * First message ID to retrieve. |
966 | * @param last_message_id | 966 | * @param last_message_id |
967 | * Last consecutive message ID to retrieve. | 967 | * Last consecutive message ID to retrieve. |
968 | * @param fragment_limit | ||
969 | * Maximum number of fragments to retrieve. | ||
968 | * @param method_prefix | 970 | * @param method_prefix |
969 | * Retrieve only messages with a matching method prefix. | 971 | * Retrieve only messages with a matching method prefix. |
970 | * @todo Implement method_prefix query. | 972 | * @todo Implement method_prefix query. |
@@ -983,6 +985,7 @@ GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h, | |||
983 | const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key, | 985 | const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key, |
984 | uint64_t first_message_id, | 986 | uint64_t first_message_id, |
985 | uint64_t last_message_id, | 987 | uint64_t last_message_id, |
988 | uint64_t fragment_limit, | ||
986 | const char *method_prefix, | 989 | const char *method_prefix, |
987 | GNUNET_PSYCSTORE_FragmentCallback fragment_cb, | 990 | GNUNET_PSYCSTORE_FragmentCallback fragment_cb, |
988 | GNUNET_PSYCSTORE_ResultCallback rcb, | 991 | GNUNET_PSYCSTORE_ResultCallback rcb, |
@@ -1009,6 +1012,7 @@ GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h, | |||
1009 | req->channel_key = *channel_key; | 1012 | req->channel_key = *channel_key; |
1010 | req->first_message_id = GNUNET_htonll (first_message_id); | 1013 | req->first_message_id = GNUNET_htonll (first_message_id); |
1011 | req->last_message_id = GNUNET_htonll (last_message_id); | 1014 | req->last_message_id = GNUNET_htonll (last_message_id); |
1015 | req->fragment_limit = GNUNET_htonll (fragment_limit); | ||
1012 | if (NULL != slave_key) | 1016 | if (NULL != slave_key) |
1013 | { | 1017 | { |
1014 | req->slave_key = *slave_key; | 1018 | req->slave_key = *slave_key; |
diff --git a/src/psycstore/test_plugin_psycstore.c b/src/psycstore/test_plugin_psycstore.c index 5a5f970b9..3a022ec52 100644 --- a/src/psycstore/test_plugin_psycstore.c +++ b/src/psycstore/test_plugin_psycstore.c | |||
@@ -285,7 +285,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
285 | 285 | ||
286 | GNUNET_assert ( | 286 | GNUNET_assert ( |
287 | GNUNET_OK == db->message_get (db->cls, &channel_pub_key, | 287 | GNUNET_OK == db->message_get (db->cls, &channel_pub_key, |
288 | message_id, message_id, | 288 | message_id, message_id, 0, |
289 | &ret_frags, fragment_cb, &fcls)); | 289 | &ret_frags, fragment_cb, &fcls)); |
290 | GNUNET_assert (fcls.n == 2 && ret_frags == 2); | 290 | GNUNET_assert (fcls.n == 2 && ret_frags == 2); |
291 | 291 | ||
diff --git a/src/psycstore/test_psycstore.c b/src/psycstore/test_psycstore.c index 58e6243b7..1e7004021 100644 --- a/src/psycstore/test_psycstore.c +++ b/src/psycstore/test_psycstore.c | |||
@@ -378,7 +378,7 @@ message_get_fragment_result (void *cls, int64_t result, | |||
378 | fcls->n_expected = 3; | 378 | fcls->n_expected = 3; |
379 | uint64_t message_id = GNUNET_ntohll (fcls->msg[0]->message_id); | 379 | uint64_t message_id = GNUNET_ntohll (fcls->msg[0]->message_id); |
380 | op = GNUNET_PSYCSTORE_message_get (h, &channel_pub_key, &slave_pub_key, | 380 | op = GNUNET_PSYCSTORE_message_get (h, &channel_pub_key, &slave_pub_key, |
381 | message_id, message_id, "", | 381 | message_id, message_id, 0, "", |
382 | &fragment_result, | 382 | &fragment_result, |
383 | &message_get_result, fcls); | 383 | &message_get_result, fcls); |
384 | } | 384 | } |