aboutsummaryrefslogtreecommitdiff
path: root/src/fs
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-02-28 21:12:03 +0000
committerChristian Grothoff <christian@grothoff.org>2015-02-28 21:12:03 +0000
commit3a2737d76679c68331fad0be0b89d8efdcde5079 (patch)
tree5bd4ef163438954cdcb75558e6368a297629b56d /src/fs
parent9c46ed792caae948fd99cca44deaf5a265af7614 (diff)
downloadgnunet-3a2737d76679c68331fad0be0b89d8efdcde5079.tar.gz
gnunet-3a2737d76679c68331fad0be0b89d8efdcde5079.zip
-extend block API to allow specifying flags, use this to allow reducing checks for replies from local DB
Diffstat (limited to 'src/fs')
-rw-r--r--src/fs/gnunet-service-fs_pr.c89
-rw-r--r--src/fs/plugin_block_fs.c51
-rw-r--r--src/fs/test_plugin_block_fs.c27
3 files changed, 117 insertions, 50 deletions
diff --git a/src/fs/gnunet-service-fs_pr.c b/src/fs/gnunet-service-fs_pr.c
index 545c7c657..709874f75 100644
--- a/src/fs/gnunet-service-fs_pr.c
+++ b/src/fs/gnunet-service-fs_pr.c
@@ -748,6 +748,11 @@ struct ProcessReplyClosure
748 enum GNUNET_BLOCK_Type type; 748 enum GNUNET_BLOCK_Type type;
749 749
750 /** 750 /**
751 * Control flags for evaluation.
752 */
753 enum GNUNET_BLOCK_EvaluationOptions eo;
754
755 /**
751 * How much was this reply worth to us? 756 * How much was this reply worth to us?
752 */ 757 */
753 uint32_t priority; 758 uint32_t priority;
@@ -790,7 +795,7 @@ update_request_performance_data (struct ProcessReplyClosure *prq,
790/** 795/**
791 * We have received a reply; handle it! 796 * We have received a reply; handle it!
792 * 797 *
793 * @param cls response (struct ProcessReplyClosure) 798 * @param cls response (a `struct ProcessReplyClosure`)
794 * @param key our query 799 * @param key our query
795 * @param value value in the hash map (info about the query) 800 * @param value value in the hash map (info about the query)
796 * @return #GNUNET_YES (we should continue to iterate) 801 * @return #GNUNET_YES (we should continue to iterate)
@@ -809,13 +814,21 @@ process_reply (void *cls,
809 return GNUNET_YES; 814 return GNUNET_YES;
810 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 815 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
811 "Matched result (type %u) for query `%s' with pending request\n", 816 "Matched result (type %u) for query `%s' with pending request\n",
812 (unsigned int) prq->type, GNUNET_h2s (key)); 817 (unsigned int) prq->type,
818 GNUNET_h2s (key));
813 GNUNET_STATISTICS_update (GSF_stats, 819 GNUNET_STATISTICS_update (GSF_stats,
814 gettext_noop ("# replies received and matched"), 1, 820 gettext_noop ("# replies received and matched"), 1,
815 GNUNET_NO); 821 GNUNET_NO);
816 prq->eval = 822 prq->eval =
817 GNUNET_BLOCK_evaluate (GSF_block_ctx, prq->type, key, &pr->bf, pr->mingle, 823 GNUNET_BLOCK_evaluate (GSF_block_ctx,
818 NULL, 0, prq->data, 824 prq->type,
825 prq->eo,
826 key,
827 &pr->bf,
828 pr->mingle,
829 NULL,
830 0,
831 prq->data,
819 prq->size); 832 prq->size);
820 switch (prq->eval) 833 switch (prq->eval)
821 { 834 {
@@ -864,20 +877,26 @@ process_reply (void *cls,
864 GNUNET_break (0); 877 GNUNET_break (0);
865 return GNUNET_YES; 878 return GNUNET_YES;
866 case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: 879 case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED:
867 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Unsupported block type %u\n"), 880 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
881 _("Unsupported block type %u\n"),
868 prq->type); 882 prq->type);
869 return GNUNET_NO; 883 return GNUNET_NO;
870 } 884 }
871 /* update bloomfilter */ 885 /* update bloomfilter */
872 GNUNET_CRYPTO_hash (prq->data, prq->size, &chash); 886 GNUNET_CRYPTO_hash (prq->data,
873 GSF_pending_request_update_ (pr, &chash, 1); 887 prq->size,
888 &chash);
889 GSF_pending_request_update_ (pr,
890 &chash,
891 1);
874 if (NULL == prq->sender) 892 if (NULL == prq->sender)
875 { 893 {
876 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 894 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
877 "Found result for query `%s' in local datastore\n", 895 "Found result for query `%s' in local datastore\n",
878 GNUNET_h2s (key)); 896 GNUNET_h2s (key));
879 GNUNET_STATISTICS_update (GSF_stats, 897 GNUNET_STATISTICS_update (GSF_stats,
880 gettext_noop ("# results found locally"), 1, 898 gettext_noop ("# results found locally"),
899 1,
881 GNUNET_NO); 900 GNUNET_NO);
882 } 901 }
883 else 902 else
@@ -894,9 +913,15 @@ process_reply (void *cls,
894 prq->sender, 913 prq->sender,
895 &last_transmission)) 914 &last_transmission))
896 last_transmission.abs_value_us = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; 915 last_transmission.abs_value_us = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
897 pr->rh (pr->rh_cls, prq->eval, pr, 916 pr->rh (pr->rh_cls,
898 prq->anonymity_level, prq->expiration, 917 prq->eval,
899 last_transmission, prq->type, prq->data, prq->size); 918 pr,
919 prq->anonymity_level,
920 prq->expiration,
921 last_transmission,
922 prq->type,
923 prq->data,
924 prq->size);
900 return GNUNET_YES; 925 return GNUNET_YES;
901} 926}
902 927
@@ -1076,6 +1101,7 @@ handle_dht_reply (void *cls,
1076 prq.expiration); 1101 prq.expiration);
1077 prq.size = size; 1102 prq.size = size;
1078 prq.type = type; 1103 prq.type = type;
1104 prq.eo = GNUNET_BLOCK_EO_NONE;
1079 process_reply (&prq, key, pr); 1105 process_reply (&prq, key, pr);
1080 if ((GNUNET_YES == active_to_migration) && 1106 if ((GNUNET_YES == active_to_migration) &&
1081 (GNUNET_NO == test_put_load_too_high (prq.priority))) 1107 (GNUNET_NO == test_put_load_too_high (prq.priority)))
@@ -1207,6 +1233,7 @@ cadet_reply_proc (void *cls,
1207 prq.expiration); 1233 prq.expiration);
1208 prq.size = data_size; 1234 prq.size = data_size;
1209 prq.type = type; 1235 prq.type = type;
1236 prq.eo = GNUNET_BLOCK_EO_NONE;
1210 process_reply (&prq, &query, pr); 1237 process_reply (&prq, &query, pr);
1211} 1238}
1212 1239
@@ -1283,9 +1310,9 @@ odc_warn_delay_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1283 * peer and if we are done either clean up (operation 1310 * peer and if we are done either clean up (operation
1284 * complete) or forward to other peers (more results possible). 1311 * complete) or forward to other peers (more results possible).
1285 * 1312 *
1286 * @param cls our closure (struct PendingRequest) 1313 * @param cls our closure (`struct GSF_PendingRequest *`)
1287 * @param key key for the content 1314 * @param key key for the content
1288 * @param size number of bytes in data 1315 * @param size number of bytes in @a data
1289 * @param data content stored 1316 * @param data content stored
1290 * @param type type of the content 1317 * @param type type of the content
1291 * @param priority priority of the content 1318 * @param priority priority of the content
@@ -1295,10 +1322,15 @@ odc_warn_delay_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1295 * maybe 0 if no unique identifier is available 1322 * maybe 0 if no unique identifier is available
1296 */ 1323 */
1297static void 1324static void
1298process_local_reply (void *cls, const struct GNUNET_HashCode * key, size_t size, 1325process_local_reply (void *cls,
1299 const void *data, enum GNUNET_BLOCK_Type type, 1326 const struct GNUNET_HashCode *key,
1300 uint32_t priority, uint32_t anonymity, 1327 size_t size,
1301 struct GNUNET_TIME_Absolute expiration, uint64_t uid) 1328 const void *data,
1329 enum GNUNET_BLOCK_Type type,
1330 uint32_t priority,
1331 uint32_t anonymity,
1332 struct GNUNET_TIME_Absolute expiration,
1333 uint64_t uid)
1302{ 1334{
1303 struct GSF_PendingRequest *pr = cls; 1335 struct GSF_PendingRequest *pr = cls;
1304 GSF_LocalLookupContinuation cont; 1336 GSF_LocalLookupContinuation cont;
@@ -1464,8 +1496,9 @@ process_local_reply (void *cls, const struct GNUNET_HashCode * key, size_t size,
1464 prq.priority = priority; 1496 prq.priority = priority;
1465 prq.request_found = GNUNET_NO; 1497 prq.request_found = GNUNET_NO;
1466 prq.anonymity_level = anonymity; 1498 prq.anonymity_level = anonymity;
1467 if ((old_rf == 0) && (pr->public_data.results_found == 0)) 1499 if ((0 == old_rf) && (0 == pr->public_data.results_found))
1468 GSF_update_datastore_delay_ (pr->public_data.start_time); 1500 GSF_update_datastore_delay_ (pr->public_data.start_time);
1501 prq.eo = GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO;
1469 process_reply (&prq, key, pr); 1502 process_reply (&prq, key, pr);
1470 pr->local_result = prq.eval; 1503 pr->local_result = prq.eval;
1471 if (prq.eval == GNUNET_BLOCK_EVALUATION_OK_LAST) 1504 if (prq.eval == GNUNET_BLOCK_EVALUATION_OK_LAST)
@@ -1473,7 +1506,8 @@ process_local_reply (void *cls, const struct GNUNET_HashCode * key, size_t size,
1473 GNUNET_STATISTICS_update (GSF_stats, 1506 GNUNET_STATISTICS_update (GSF_stats,
1474 gettext_noop 1507 gettext_noop
1475 ("# Datastore lookups concluded (found last result)"), 1508 ("# Datastore lookups concluded (found last result)"),
1476 1, GNUNET_NO); 1509 1,
1510 GNUNET_NO);
1477 goto check_error_and_continue; 1511 goto check_error_and_continue;
1478 } 1512 }
1479 if ((0 == (GSF_PRO_PRIORITY_UNLIMITED & pr->public_data.options)) && 1513 if ((0 == (GSF_PRO_PRIORITY_UNLIMITED & pr->public_data.options)) &&
@@ -1484,12 +1518,14 @@ process_local_reply (void *cls, const struct GNUNET_HashCode * key, size_t size,
1484 GNUNET_STATISTICS_update (GSF_stats, 1518 GNUNET_STATISTICS_update (GSF_stats,
1485 gettext_noop 1519 gettext_noop
1486 ("# Datastore lookups concluded (load too high)"), 1520 ("# Datastore lookups concluded (load too high)"),
1487 1, GNUNET_NO); 1521 1,
1522 GNUNET_NO);
1488 goto check_error_and_continue; 1523 goto check_error_and_continue;
1489 } 1524 }
1490 pr->qe_start = GNUNET_TIME_absolute_get (); 1525 pr->qe_start = GNUNET_TIME_absolute_get ();
1491 pr->warn_task = 1526 pr->warn_task =
1492 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &warn_delay_task, 1527 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
1528 &warn_delay_task,
1493 pr); 1529 pr);
1494 pr->qe = 1530 pr->qe =
1495 GNUNET_DATASTORE_get_key (GSF_dsh, pr->local_result_offset++, 1531 GNUNET_DATASTORE_get_key (GSF_dsh, pr->local_result_offset++,
@@ -1553,7 +1589,7 @@ check_error_and_continue:
1553 * 1589 *
1554 * @param pr request 1590 * @param pr request
1555 * @param target 1591 * @param target
1556 * @return GNUNET_YES if this request could be forwarded to the given peer 1592 * @return #GNUNET_YES if this request could be forwarded to the given peer
1557 */ 1593 */
1558int 1594int
1559GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr, 1595GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr,
@@ -1576,11 +1612,12 @@ GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr,
1576 * 1612 *
1577 * @param pr the pending request to process 1613 * @param pr the pending request to process
1578 * @param cont function to call at the end 1614 * @param cont function to call at the end
1579 * @param cont_cls closure for cont 1615 * @param cont_cls closure for @a cont
1580 */ 1616 */
1581void 1617void
1582GSF_local_lookup_ (struct GSF_PendingRequest *pr, 1618GSF_local_lookup_ (struct GSF_PendingRequest *pr,
1583 GSF_LocalLookupContinuation cont, void *cont_cls) 1619 GSF_LocalLookupContinuation cont,
1620 void *cont_cls)
1584{ 1621{
1585 GNUNET_assert (NULL == pr->gh); 1622 GNUNET_assert (NULL == pr->gh);
1586 GNUNET_assert (NULL == pr->cadet_request); 1623 GNUNET_assert (NULL == pr->cadet_request);
@@ -1682,7 +1719,8 @@ GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp,
1682 return GNUNET_SYSERR; 1719 return GNUNET_SYSERR;
1683 } 1720 }
1684 GNUNET_STATISTICS_update (GSF_stats, 1721 GNUNET_STATISTICS_update (GSF_stats,
1685 gettext_noop ("# GAP PUT messages received"), 1, 1722 gettext_noop ("# GAP PUT messages received"),
1723 1,
1686 GNUNET_NO); 1724 GNUNET_NO);
1687 /* now, lookup 'query' */ 1725 /* now, lookup 'query' */
1688 prq.data = (const void *) &put[1]; 1726 prq.data = (const void *) &put[1];
@@ -1693,6 +1731,7 @@ GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp,
1693 prq.priority = 0; 1731 prq.priority = 0;
1694 prq.anonymity_level = UINT32_MAX; 1732 prq.anonymity_level = UINT32_MAX;
1695 prq.request_found = GNUNET_NO; 1733 prq.request_found = GNUNET_NO;
1734 prq.eo = GNUNET_BLOCK_EO_NONE;
1696 GNUNET_CONTAINER_multihashmap_get_multiple (pr_map, 1735 GNUNET_CONTAINER_multihashmap_get_multiple (pr_map,
1697 &query, 1736 &query,
1698 &process_reply, 1737 &process_reply,
diff --git a/src/fs/plugin_block_fs.c b/src/fs/plugin_block_fs.c
index bc2e2d507..c032899c5 100644
--- a/src/fs/plugin_block_fs.c
+++ b/src/fs/plugin_block_fs.c
@@ -42,25 +42,30 @@
42 * request evaluation, simply pass "NULL" for the reply_block. 42 * request evaluation, simply pass "NULL" for the reply_block.
43 * Note that it is assumed that the reply has already been 43 * Note that it is assumed that the reply has already been
44 * matched to the key (and signatures checked) as it would 44 * matched to the key (and signatures checked) as it would
45 * be done with the "get_key" function. 45 * be done with the #GNUNET_BLOCK_get_key() function.
46 * 46 *
47 * @param cls closure 47 * @param cls closure
48 * @param type block type 48 * @param type block type
49 * @param eo control flags
49 * @param query original query (hash) 50 * @param query original query (hash)
50 * @param bf pointer to bloom filter associated with query; possibly updated (!) 51 * @param bf pointer to bloom filter associated with query; possibly updated (!)
51 * @param bf_mutator mutation value for bf 52 * @param bf_mutator mutation value for @a bf
52 * @param xquery extrended query data (can be NULL, depending on type) 53 * @param xquery extrended query data (can be NULL, depending on type)
53 * @param xquery_size number of bytes in xquery 54 * @param xquery_size number of bytes in @a xquery
54 * @param reply_block response to validate 55 * @param reply_block response to validate
55 * @param reply_block_size number of bytes in reply block 56 * @param reply_block_size number of bytes in @a reply_block
56 * @return characterization of result 57 * @return characterization of result
57 */ 58 */
58static enum GNUNET_BLOCK_EvaluationResult 59static enum GNUNET_BLOCK_EvaluationResult
59block_plugin_fs_evaluate (void *cls, enum GNUNET_BLOCK_Type type, 60block_plugin_fs_evaluate (void *cls,
61 enum GNUNET_BLOCK_Type type,
62 enum GNUNET_BLOCK_EvaluationOptions eo,
60 const struct GNUNET_HashCode *query, 63 const struct GNUNET_HashCode *query,
61 struct GNUNET_CONTAINER_BloomFilter **bf, 64 struct GNUNET_CONTAINER_BloomFilter **bf,
62 int32_t bf_mutator, const void *xquery, 65 int32_t bf_mutator,
63 size_t xquery_size, const void *reply_block, 66 const void *xquery,
67 size_t xquery_size,
68 const void *reply_block,
64 size_t reply_block_size) 69 size_t reply_block_size)
65{ 70{
66 const struct UBlock *ub; 71 const struct UBlock *ub;
@@ -110,22 +115,28 @@ block_plugin_fs_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
110 GNUNET_break_op (0); 115 GNUNET_break_op (0);
111 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 116 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
112 } 117 }
113 if (GNUNET_OK != 118 if ( (0 == (eo & GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO)) &&
114 GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK, 119 (GNUNET_OK !=
115 &ub->purpose, 120 GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK,
116 &ub->signature, 121 &ub->purpose,
117 &ub->verification_key)) 122 &ub->signature,
123 &ub->verification_key)) )
118 { 124 {
119 GNUNET_break_op (0); 125 GNUNET_break_op (0);
120 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 126 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
121 } 127 }
122 if (NULL != bf) 128 if (NULL != bf)
123 { 129 {
124 GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash); 130 GNUNET_CRYPTO_hash (reply_block,
125 GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash); 131 reply_block_size,
132 &chash);
133 GNUNET_BLOCK_mingle_hash (&chash,
134 bf_mutator,
135 &mhash);
126 if (NULL != *bf) 136 if (NULL != *bf)
127 { 137 {
128 if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash)) 138 if (GNUNET_YES ==
139 GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash))
129 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; 140 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
130 } 141 }
131 else 142 else
@@ -147,14 +158,16 @@ block_plugin_fs_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
147 * @param cls closure 158 * @param cls closure
148 * @param type block type 159 * @param type block type
149 * @param block block to get the key for 160 * @param block block to get the key for
150 * @param block_size number of bytes in block 161 * @param block_size number of bytes in @a block
151 * @param key set to the key (query) for the given block 162 * @param key set to the key (query) for the given block
152 * @return GNUNET_OK on success, GNUNET_SYSERR if type not supported 163 * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported
153 * (or if extracting a key from a block of this type does not work) 164 * (or if extracting a key from a block of this type does not work)
154 */ 165 */
155static int 166static int
156block_plugin_fs_get_key (void *cls, enum GNUNET_BLOCK_Type type, 167block_plugin_fs_get_key (void *cls,
157 const void *block, size_t block_size, 168 enum GNUNET_BLOCK_Type type,
169 const void *block,
170 size_t block_size,
158 struct GNUNET_HashCode *key) 171 struct GNUNET_HashCode *key)
159{ 172{
160 const struct UBlock *ub; 173 const struct UBlock *ub;
diff --git a/src/fs/test_plugin_block_fs.c b/src/fs/test_plugin_block_fs.c
index 208f4ce78..9e1246f72 100644
--- a/src/fs/test_plugin_block_fs.c
+++ b/src/fs/test_plugin_block_fs.c
@@ -38,17 +38,32 @@ test_fs (struct GNUNET_BLOCK_Context *ctx)
38 sizeof (block), &key)) 38 sizeof (block), &key))
39 return 1; 39 return 1;
40 if (GNUNET_BLOCK_EVALUATION_OK_LAST != 40 if (GNUNET_BLOCK_EVALUATION_OK_LAST !=
41 GNUNET_BLOCK_evaluate (ctx, GNUNET_BLOCK_TYPE_FS_DBLOCK, &key, NULL, 0, 41 GNUNET_BLOCK_evaluate (ctx,
42 NULL, 0, block, sizeof (block))) 42 GNUNET_BLOCK_TYPE_FS_DBLOCK,
43 GNUNET_BLOCK_EO_NONE,
44 &key,
45 NULL, 0,
46 NULL, 0,
47 block, sizeof (block)))
43 return 2; 48 return 2;
44 if (GNUNET_BLOCK_EVALUATION_REQUEST_VALID != 49 if (GNUNET_BLOCK_EVALUATION_REQUEST_VALID !=
45 GNUNET_BLOCK_evaluate (ctx, GNUNET_BLOCK_TYPE_FS_DBLOCK, &key, NULL, 0, 50 GNUNET_BLOCK_evaluate (ctx,
46 NULL, 0, NULL, 0)) 51 GNUNET_BLOCK_TYPE_FS_DBLOCK,
52 GNUNET_BLOCK_EO_NONE,
53 &key,
54 NULL, 0,
55 NULL, 0,
56 NULL, 0))
47 return 4; 57 return 4;
48 GNUNET_log_skip (1, GNUNET_NO); 58 GNUNET_log_skip (1, GNUNET_NO);
49 if (GNUNET_BLOCK_EVALUATION_REQUEST_INVALID != 59 if (GNUNET_BLOCK_EVALUATION_REQUEST_INVALID !=
50 GNUNET_BLOCK_evaluate (ctx, GNUNET_BLOCK_TYPE_FS_DBLOCK, &key, NULL, 0, 60 GNUNET_BLOCK_evaluate (ctx,
51 "bogus", 5, NULL, 0)) 61 GNUNET_BLOCK_TYPE_FS_DBLOCK,
62 GNUNET_BLOCK_EO_NONE,
63 &key,
64 NULL, 0,
65 "bogus", 5,
66 NULL, 0))
52 return 8; 67 return 8;
53 GNUNET_log_skip (0, GNUNET_YES); 68 GNUNET_log_skip (0, GNUNET_YES);
54 return 0; 69 return 0;