Library for data group management. More...
Enumerations | |
enum | GNUNET_BLOCK_ReplyEvaluationResult { GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED = -1 , GNUNET_BLOCK_REPLY_OK_DUPLICATE = 0 , GNUNET_BLOCK_REPLY_IRRELEVANT = 1 , GNUNET_BLOCK_REPLY_OK_MORE = 2 , GNUNET_BLOCK_REPLY_OK_LAST = 3 } |
Possible ways for how a block may relate to a query. More... | |
Functions | |
size_t | GNUNET_BLOCK_GROUP_compute_bloomfilter_size (unsigned int entry_count, unsigned int k) |
How many bytes should a bloomfilter be if we have already seen entry_count responses? Sized so that do not have to re-size the filter too often (to keep it cheap). More... | |
struct GNUNET_BLOCK_Group * | GNUNET_BLOCK_GROUP_bf_create (void *cls, size_t bf_size, unsigned int bf_k, enum GNUNET_BLOCK_Type type, const void *raw_data, size_t raw_data_size) |
Create a new block group that filters duplicates using a Bloom filter. More... | |
enum GNUNET_GenericReturnValue | GNUNET_BLOCK_GROUP_bf_test_and_set (struct GNUNET_BLOCK_Group *bg, const struct GNUNET_HashCode *hc) |
Test if hc is contained in the Bloom filter of bg. More... | |
void | GNUNET_BLOCK_mingle_hash (const struct GNUNET_HashCode *in, uint32_t mingle_number, struct GNUNET_HashCode *hc) |
Mingle hash with the mingle_number to produce different bits. More... | |
struct GNUNET_BLOCK_Context * | GNUNET_BLOCK_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg) |
Create a block context. More... | |
void | GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx) |
Destroy the block context. More... | |
struct GNUNET_BLOCK_Group * | GNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type, const void *raw_data, size_t raw_data_size,...) |
Create a new block group. More... | |
enum GNUNET_GenericReturnValue | GNUNET_BLOCK_group_serialize (struct GNUNET_BLOCK_Group *bg, void **raw_data, size_t *raw_data_size) |
Serialize state of a block group. More... | |
void | GNUNET_BLOCK_group_destroy (struct GNUNET_BLOCK_Group *bg) |
Destroy resources used by a block group. More... | |
enum GNUNET_BLOCK_ReplyEvaluationResult | GNUNET_BLOCK_check_reply (struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type, struct GNUNET_BLOCK_Group *group, const struct GNUNET_HashCode *query, const void *xquery, size_t xquery_size, const void *reply_block, size_t reply_block_size) |
Function called to validate if a reply is good for a particular query. More... | |
enum GNUNET_GenericReturnValue | GNUNET_BLOCK_check_query (struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type, const struct GNUNET_HashCode *query, const void *xquery, size_t xquery_size) |
Function called to validate a request. More... | |
enum GNUNET_GenericReturnValue | GNUNET_BLOCK_check_block (struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type, const void *block, size_t block_size) |
Function called to validate a block. More... | |
enum GNUNET_GenericReturnValue | GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type, const void *block, size_t block_size, struct GNUNET_HashCode *key) |
Function called to obtain the key for a block. More... | |
enum GNUNET_GenericReturnValue | GNUNET_BLOCK_group_set_seen (struct GNUNET_BLOCK_Group *bg, const struct GNUNET_HashCode *seen_results, unsigned int seen_results_count) |
Update block group to filter out the given results. More... | |
enum GNUNET_GenericReturnValue | GNUNET_BLOCK_group_merge (struct GNUNET_BLOCK_Group *bg1, struct GNUNET_BLOCK_Group *bg2) |
Try merging two block groups. More... | |
Library for data group management.
Library for data block manipulation.
Possible ways for how a block may relate to a query.
Definition at line 53 of file gnunet_block_lib.h.
size_t GNUNET_BLOCK_GROUP_compute_bloomfilter_size | ( | unsigned int | entry_count, |
unsigned int | k | ||
) |
How many bytes should a bloomfilter be if we have already seen entry_count responses? Sized so that do not have to re-size the filter too often (to keep it cheap).
Since other peers will also add entries but not resize the filter, we should generally pick a slightly larger size than what the strict math would suggest.
entry_count | expected number of entries in the Bloom filter |
k | number of bits set per entry |
Definition at line 268 of file bg_bf.c.
Referenced by block_plugin_dht_create_group(), block_plugin_dns_create_group(), block_plugin_fs_create_group(), block_plugin_gns_create_group(), block_plugin_regex_create_group(), block_plugin_template_create_group(), and block_plugin_test_create_group().
struct GNUNET_BLOCK_Group * GNUNET_BLOCK_GROUP_bf_create | ( | void * | cls, |
size_t | bf_size, | ||
unsigned int | bf_k, | ||
enum GNUNET_BLOCK_Type | type, | ||
const void * | raw_data, | ||
size_t | raw_data_size | ||
) |
Create a new block group that filters duplicates using a Bloom filter.
ctx | block context in which the block group is created |
bf_size | size of the Bloom filter |
bf_k | K-value for the Bloom filter |
type | block type |
raw_data | optional serialized prior state of the group, NULL if unavailable/fresh |
raw_data_size | number of bytes in raw_data, 0 if unavailable/fresh |
Definition at line 173 of file bg_bf.c.
References BfGroupInternals::bf, bf_group_destroy_cb(), bf_group_mark_seen_cb(), bf_group_merge_cb(), bf_group_serialize_cb(), BfGroupInternals::bf_mutator, BfGroupInternals::bf_size, GNUNET_BLOCK_Group::destroy_cb, GNUNET_break_op, GNUNET_CONTAINER_bloomfilter_init(), GNUNET_CRYPTO_QUALITY_NONCE, GNUNET_CRYPTO_random_u32(), GNUNET_new, GNUNET_BLOCK_Group::internal_cls, GNUNET_BLOCK_Group::mark_seen_cb, GNUNET_BLOCK_Group::merge_cb, GNUNET_BLOCK_Group::serialize_cb, type, and GNUNET_BLOCK_Group::type.
Referenced by block_plugin_dht_create_group(), block_plugin_dns_create_group(), block_plugin_fs_create_group(), block_plugin_gns_create_group(), block_plugin_regex_create_group(), block_plugin_template_create_group(), and block_plugin_test_create_group().
enum GNUNET_GenericReturnValue GNUNET_BLOCK_GROUP_bf_test_and_set | ( | struct GNUNET_BLOCK_Group * | bg, |
const struct GNUNET_HashCode * | hc | ||
) |
Test if hc is contained in the Bloom filter of bg.
If so, return GNUNET_YES. If not, add hc to the Bloom filter and return GNUNET_NO.
bg | block group to use for testing |
hc | hash of element to evaluate |
Definition at line 232 of file bg_bf.c.
References BfGroupInternals::bf, BfGroupInternals::bf_mutator, GNUNET_BLOCK_mingle_hash(), GNUNET_CONTAINER_bloomfilter_add(), GNUNET_CONTAINER_bloomfilter_test(), GNUNET_NO, GNUNET_YES, and GNUNET_BLOCK_Group::internal_cls.
Referenced by block_plugin_dht_check_reply(), block_plugin_dns_check_reply(), block_plugin_fs_check_reply(), block_plugin_gns_check_reply(), block_plugin_regex_check_reply(), block_plugin_test_check_reply(), and process().
void GNUNET_BLOCK_mingle_hash | ( | const struct GNUNET_HashCode * | in, |
uint32_t | mingle_number, | ||
struct GNUNET_HashCode * | hc | ||
) |
Mingle hash with the mingle_number to produce different bits.
in | original hash code |
mingle_number | number for hash permutation |
hc | where to store the result. |
Definition at line 96 of file block.c.
References GNUNET_CRYPTO_hash(), and MinglePacker::in.
Referenced by bf_group_mark_seen_cb(), filtered_map_initialization(), GNUNET_BLOCK_GROUP_bf_test_and_set(), iterator_bf_create(), and iterator_bf_reduce().
struct GNUNET_BLOCK_Context * GNUNET_BLOCK_context_create | ( | const struct GNUNET_CONFIGURATION_Handle * | cfg | ) |
Create a block context.
Loads the block plugins.
cfg | configuration to use |
Definition at line 140 of file block.c.
References add_plugin(), cfg, GNUNET_FS_Handle::cfg, ctx, GNUNET_CONFIGURATION_get_project_data(), GNUNET_new, and GNUNET_PLUGIN_load_all().
Referenced by block_plugin_consensus_check_block(), block_plugin_consensus_check_reply(), and run().
void GNUNET_BLOCK_context_destroy | ( | struct GNUNET_BLOCK_Context * | ctx | ) |
Destroy the block context.
ctx | context to destroy |
Definition at line 158 of file block.c.
References ctx, GNUNET_break, GNUNET_free, GNUNET_PLUGIN_unload(), and plugin.
Referenced by libgnunet_plugin_block_consensus_done(), and shutdown_task().
struct GNUNET_BLOCK_Group * GNUNET_BLOCK_group_create | ( | struct GNUNET_BLOCK_Context * | ctx, |
enum GNUNET_BLOCK_Type | type, | ||
const void * | raw_data, | ||
size_t | raw_data_size, | ||
... | |||
) |
Create a new block group.
ctx | block context in which the block group is created |
type | type of the block for which we are creating the group |
raw_data | optional serialized prior state of the group, NULL if unavailable/fresh |
raw_data_size | number of bytes in raw_data, 0 if unavailable/fresh |
... | type-specific additional data, can be empty |
Definition at line 249 of file block.c.
References GNUNET_TESTING_PluginFunctions::cls, ctx, find_plugin(), plugin, and type.
Referenced by GSF_pending_request_create_(), handle_dht_p2p_get(), refresh_bloomfilter(), send_find_peer_message(), and transmit_request().
enum GNUNET_GenericReturnValue GNUNET_BLOCK_group_serialize | ( | struct GNUNET_BLOCK_Group * | bg, |
void ** | raw_data, | ||
size_t * | raw_data_size | ||
) |
Serialize state of a block group.
bg | group to serialize | |
[out] | raw_data | set to the serialized state |
[out] | raw_data_size | set to the number of bytes in raw_data |
Definition at line 177 of file block.c.
References GNUNET_NO, and GNUNET_BLOCK_Group::serialize_cb.
Referenced by GDS_NEIGHBOURS_handle_get(), and GSF_pending_request_get_message_().
void GNUNET_BLOCK_group_destroy | ( | struct GNUNET_BLOCK_Group * | bg | ) |
Destroy resources used by a block group.
bg | group to destroy, NULL is allowed |
Definition at line 194 of file block.c.
References GNUNET_BLOCK_Group::destroy_cb.
Referenced by clean_request(), expire_oldest_entry(), refresh_bloomfilter(), send_find_peer_message(), and transmit_request().
enum GNUNET_BLOCK_ReplyEvaluationResult GNUNET_BLOCK_check_reply | ( | struct GNUNET_BLOCK_Context * | ctx, |
enum GNUNET_BLOCK_Type | type, | ||
struct GNUNET_BLOCK_Group * | group, | ||
const struct GNUNET_HashCode * | query, | ||
const void * | xquery, | ||
size_t | xquery_size, | ||
const void * | reply_block, | ||
size_t | reply_block_size | ||
) |
Function called to validate if a reply is good for a particular query.
ctx | block contxt | |
type | block type | |
[in,out] | group | block group to use for evaluation |
query | original query (hash) | |
xquery | extrended query data (can be NULL, depending on type) | |
xquery_size | number of bytes in xquery | |
reply_block | response to validate | |
reply_block_size | number of bytes in reply_block |
Definition at line 339 of file block.c.
References GNUNET_TESTING_PluginFunctions::cls, ctx, find_plugin(), GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED, plugin, and type.
Referenced by block_plugin_consensus_check_reply(), datacache_get_iterator(), forward_reply(), handle_find_local_hello(), handle_find_my_hello(), process(), and process_reply().
enum GNUNET_GenericReturnValue GNUNET_BLOCK_check_query | ( | struct GNUNET_BLOCK_Context * | ctx, |
enum GNUNET_BLOCK_Type | type, | ||
const struct GNUNET_HashCode * | query, | ||
const void * | xquery, | ||
size_t | xquery_size | ||
) |
Function called to validate a request.
ctx | block contxt |
type | block type |
query | original query (hash) |
xquery | extrended query data (can be NULL, depending on type) |
xquery_size | number of bytes in xquery |
Definition at line 298 of file block.c.
References GNUNET_TESTING_PluginFunctions::cls, ctx, find_plugin(), GNUNET_BLOCK_TYPE_ANY, GNUNET_SYSERR, plugin, and type.
Referenced by handle_dht_p2p_get().
enum GNUNET_GenericReturnValue GNUNET_BLOCK_check_block | ( | struct GNUNET_BLOCK_Context * | ctx, |
enum GNUNET_BLOCK_Type | type, | ||
const void * | block, | ||
size_t | block_size | ||
) |
Function called to validate a block.
ctx | block contxt |
type | block type |
block | payload to put |
block_size | number of bytes in block |
Definition at line 321 of file block.c.
References GNUNET_TESTING_PluginFunctions::cls, ctx, find_plugin(), GNUNET_SYSERR, plugin, and type.
Referenced by block_plugin_consensus_check_block(), cadet_reply_proc(), handle_dht_local_put(), handle_dht_p2p_put(), handle_dht_p2p_result(), and handle_p2p_put().
enum GNUNET_GenericReturnValue GNUNET_BLOCK_get_key | ( | struct GNUNET_BLOCK_Context * | ctx, |
enum GNUNET_BLOCK_Type | type, | ||
const void * | block, | ||
size_t | block_size, | ||
struct GNUNET_HashCode * | key | ||
) |
Function called to obtain the key for a block.
If the block is malformed, the function should zero-out key and return GNUNET_OK.
ctx | block context |
type | block type |
block | block to get the key for |
block_size | number of bytes in block |
key | set to the key (query) for the given block |
Definition at line 278 of file block.c.
References GNUNET_TESTING_PluginFunctions::cls, ctx, find_plugin(), GNUNET_SYSERR, key, plugin, and type.
Referenced by cadet_reply_proc(), handle_dht_p2p_put(), handle_dht_p2p_result(), handle_p2p_put(), handle_reply(), and process_local_reply().
enum GNUNET_GenericReturnValue GNUNET_BLOCK_group_set_seen | ( | struct GNUNET_BLOCK_Group * | bg, |
const struct GNUNET_HashCode * | seen_results, | ||
unsigned int | seen_results_count | ||
) |
Update block group to filter out the given results.
Note that the use of a hash for seen results implies that the caller magically knows how the specific block engine hashes for filtering duplicates, so this API may not always apply.
bf_mutator | mutation value to use |
seen_results | results already seen |
seen_results_count | number of entries in seen_results |
Definition at line 365 of file block.c.
References GNUNET_OK, GNUNET_SYSERR, and GNUNET_BLOCK_Group::mark_seen_cb.
Referenced by add_known_to_bloom(), GSF_pending_request_update_(), refresh_bloomfilter(), and transmit_request().
enum GNUNET_GenericReturnValue GNUNET_BLOCK_group_merge | ( | struct GNUNET_BLOCK_Group * | bg1, |
struct GNUNET_BLOCK_Group * | bg2 | ||
) |
Try merging two block groups.
Afterwards, bg1 should remain valid and contain the rules from both bg1 and bg2, and bg2 should be destroyed (as part of this call). The latter should happen even if merging is not supported.
[in,out] | bg1 | first group to merge, is updated |
bg2 | second group to merge, is destroyed |
Definition at line 203 of file block.c.
References GNUNET_BLOCK_Group::destroy_cb, GNUNET_assert, GNUNET_OK, GNUNET_SYSERR, GNUNET_BLOCK_Group::merge_cb, and ret.
Referenced by try_combine_recent().