GNUnet  0.11.x
Enumerations | Functions
Block group library

Library for data group management. More...

Enumerations

enum  GNUNET_BLOCK_Type {
  GNUNET_BLOCK_TYPE_ANY = 0, GNUNET_BLOCK_TYPE_FS_DBLOCK = 1, GNUNET_BLOCK_TYPE_FS_IBLOCK = 2, GNUNET_BLOCK_TYPE_FS_KBLOCK = 3,
  GNUNET_BLOCK_TYPE_FS_SBLOCK = 4, GNUNET_BLOCK_TYPE_FS_NBLOCK = 5, GNUNET_BLOCK_TYPE_FS_ONDEMAND = 6, GNUNET_BLOCK_TYPE_DHT_HELLO = 7,
  GNUNET_BLOCK_TYPE_TEST = 8, GNUNET_BLOCK_TYPE_FS_UBLOCK = 9, GNUNET_BLOCK_TYPE_DNS = 10, GNUNET_BLOCK_TYPE_GNS_NAMERECORD = 11,
  GNUNET_BLOCK_TYPE_REVOCATION = 12, GNUNET_BLOCK_TYPE_REGEX = 22, GNUNET_BLOCK_TYPE_REGEX_ACCEPT = 23, GNUNET_BLOCK_TYPE_SET_TEST = 24,
  GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT = 25
}
 Blocks in the datastore and the datacache must have a unique type. More...
 
enum  GNUNET_BLOCK_EvaluationOptions { GNUNET_BLOCK_EO_NONE = 0, GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO = 1 }
 Flags that can be set to control the evaluation. More...
 
enum  GNUNET_BLOCK_EvaluationResult {
  GNUNET_BLOCK_EVALUATION_OK_MORE = 0, GNUNET_BLOCK_EVALUATION_OK_LAST = 1, GNUNET_BLOCK_EVALUATION_OK_DUPLICATE = 2, GNUNET_BLOCK_EVALUATION_RESULT_INVALID = 3,
  GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT = 4, GNUNET_BLOCK_EVALUATION_REQUEST_VALID = 10, GNUNET_BLOCK_EVALUATION_REQUEST_INVALID = 11, GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED = 20
}
 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_GroupGNUNET_BLOCK_GROUP_bf_create (void *cls, size_t bf_size, unsigned int bf_k, enum GNUNET_BLOCK_Type type, uint32_t nonce, const void *raw_data, size_t raw_data_size)
 Create a new block group that filters duplicates using a Bloom filter. More...
 
int 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_ContextGNUNET_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_GroupGNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type, uint32_t nonce, const void *raw_data, size_t raw_data_size,...)
 Create a new block group. More...
 
int GNUNET_BLOCK_group_serialize (struct GNUNET_BLOCK_Group *bg, uint32_t *nonce, 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_EvaluationResult GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type, struct GNUNET_BLOCK_Group *group, enum GNUNET_BLOCK_EvaluationOptions eo, 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 a reply or a request. More...
 
int 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...
 
int 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...
 
int GNUNET_BLOCK_group_merge (struct GNUNET_BLOCK_Group *bg1, struct GNUNET_BLOCK_Group *bg2)
 Try merging two block groups. More...
 

Detailed Description

Library for data group management.

Library for data block manipulation.

Enumeration Type Documentation

◆ GNUNET_BLOCK_Type

Blocks in the datastore and the datacache must have a unique type.

Enumerator
GNUNET_BLOCK_TYPE_ANY 

Any type of block, used as a wildcard when searching.

Should never be attached to a specific block.

GNUNET_BLOCK_TYPE_FS_DBLOCK 

Data block (leaf) in the CHK tree.

GNUNET_BLOCK_TYPE_FS_IBLOCK 

Inner block in the CHK tree.

GNUNET_BLOCK_TYPE_FS_KBLOCK 

Legacy type, no longer in use.

GNUNET_BLOCK_TYPE_FS_SBLOCK 

Legacy type, no longer in use.

GNUNET_BLOCK_TYPE_FS_NBLOCK 

Legacy type, no longer in use.

GNUNET_BLOCK_TYPE_FS_ONDEMAND 

Type of a block representing a block to be encoded on demand from disk.

Should never appear on the network directly.

GNUNET_BLOCK_TYPE_DHT_HELLO 

Type of a block that contains a HELLO for a peer (for DHT and CADET find-peer operations).

GNUNET_BLOCK_TYPE_TEST 

Block for testing.

GNUNET_BLOCK_TYPE_FS_UBLOCK 

Type of a block representing any type of search result (universal).

Implemented in the context of #2564, replaces SBLOCKS, KBLOCKS and NBLOCKS.

GNUNET_BLOCK_TYPE_DNS 

Block for storing DNS exit service advertisements.

GNUNET_BLOCK_TYPE_GNS_NAMERECORD 

Block for storing record data.

GNUNET_BLOCK_TYPE_REVOCATION 

Block type for a revocation message by which a key is revoked.

GNUNET_BLOCK_TYPE_REGEX 

Block to store a cadet regex state.

GNUNET_BLOCK_TYPE_REGEX_ACCEPT 

Block to store a cadet regex accepting state.

GNUNET_BLOCK_TYPE_SET_TEST 

Block for testing set/consensus.

If first byte of the block is non-zero, the block is considered invalid.

GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT 

Block type for consensus elements.

Contains either special marker elements or a nested block.

Definition at line 47 of file gnunet_block_lib.h.

48 {
54 
59 
64 
69 
74 
79 
85 
91 
96 
103 
108 
113 
118 
123 
128 
134 
140 };
Block to store a cadet regex accepting state.
Legacy type, no longer in use.
Any type of block, used as a wildcard when searching.
Block type for a revocation message by which a key is revoked.
Type of a block representing a block to be encoded on demand from disk.
Legacy type, no longer in use.
Block for storing DNS exit service advertisements.
Inner block in the CHK tree.
Block for storing record data.
Type of a block that contains a HELLO for a peer (for DHT and CADET find-peer operations).
Type of a block representing any type of search result (universal).
Legacy type, no longer in use.
Block for testing.
Block type for consensus elements.
Data block (leaf) in the CHK tree.
Block for testing set/consensus.
Block to store a cadet regex state.

◆ GNUNET_BLOCK_EvaluationOptions

Flags that can be set to control the evaluation.

Enumerator
GNUNET_BLOCK_EO_NONE 

Default behavior.

GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO 

The block is obtained from the local database, skip cryptographic checks.

Definition at line 146 of file gnunet_block_lib.h.

147 {
152 
158 };
Default behavior.
The block is obtained from the local database, skip cryptographic checks.

◆ GNUNET_BLOCK_EvaluationResult

Possible ways for how a block may relate to a query.

Enumerator
GNUNET_BLOCK_EVALUATION_OK_MORE 

Valid result, and there may be more.

GNUNET_BLOCK_EVALUATION_OK_LAST 

Last possible valid result.

GNUNET_BLOCK_EVALUATION_OK_DUPLICATE 

Valid result, but suppressed because it is a duplicate.

GNUNET_BLOCK_EVALUATION_RESULT_INVALID 

Block does not match query (invalid result)

GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT 

Block does not match xquery (valid result, not relevant for the request)

GNUNET_BLOCK_EVALUATION_REQUEST_VALID 

Query is valid, no reply given.

GNUNET_BLOCK_EVALUATION_REQUEST_INVALID 

Query format does not match block type (invalid query).

For example, xquery not given or xquery_size not appropriate for type.

GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED 

Specified block type not supported by this plugin.

Definition at line 164 of file gnunet_block_lib.h.

165 {
170 
175 
180 
185 
190 
195 
202 
207 };
Block does not match query (invalid result)
Block does not match xquery (valid result, not relevant for the request)
Valid result, but suppressed because it is a duplicate.
Last possible valid result.
Valid result, and there may be more.
Specified block type not supported by this plugin.
Query format does not match block type (invalid query).
Query is valid, no reply given.

Function Documentation

◆ GNUNET_BLOCK_GROUP_compute_bloomfilter_size()

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.

Parameters
entry_countexpected number of entries in the Bloom filter
knumber of bits set per entry
Returns
must be a power of two and smaller or equal to 2^15.

Definition at line 250 of file bg_bf.c.

References size.

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_revocation_create_group(), block_plugin_template_create_group(), and block_plugin_test_create_group().

252 {
253  size_t size;
254  unsigned int ideal = (entry_count * k) / 4;
255  uint16_t max = 1 << 15;
256 
257  if (entry_count > max)
258  return max;
259  size = 8;
260  while ((size < max) && (size < ideal))
261  size *= 2;
262  if (size > max)
263  return max;
264  return size;
265 }
static unsigned int size
Size of the "table".
Definition: peer.c:67
Here is the caller graph for this function:

◆ GNUNET_BLOCK_GROUP_bf_create()

struct GNUNET_BLOCK_Group* GNUNET_BLOCK_GROUP_bf_create ( void *  cls,
size_t  bf_size,
unsigned int  bf_k,
enum GNUNET_BLOCK_Type  type,
uint32_t  nonce,
const void *  raw_data,
size_t  raw_data_size 
)

Create a new block group that filters duplicates using a Bloom filter.

Parameters
ctxblock context in which the block group is created
bf_sizesize of the Bloom filter
bf_kK-value for the Bloom filter
typeblock type
noncerandom value used to seed the group creation
raw_dataoptional serialized prior state of the group, NULL if unavailable/fresh
raw_data_sizenumber of bytes in raw_data, 0 if unavailable/fresh
Returns
block group handle, NULL if block groups are not supported by this type of block (this is not an error)

Definition at line 174 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_CONTAINER_bloomfilter_init(), GNUNET_new, GNUNET_BLOCK_Group::internal_cls, GNUNET_BLOCK_Group::mark_seen_cb, GNUNET_BLOCK_Group::merge_cb, GNUNET_BLOCK_Group::serialize_cb, GNUNET_BLOCK_Group::type, and 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_revocation_create_group(), block_plugin_template_create_group(), and block_plugin_test_create_group().

181 {
182  struct BfGroupInternals *gi;
183  struct GNUNET_BLOCK_Group *bg;
184 
185  gi = GNUNET_new (struct BfGroupInternals);
186  gi->bf = GNUNET_CONTAINER_bloomfilter_init ((bf_size != raw_data_size) ?
187  NULL : raw_data,
188  bf_size,
189  bf_k);
190  gi->bf_mutator = nonce;
191  gi->bf_size = bf_size;
192  bg = GNUNET_new (struct GNUNET_BLOCK_Group);
193  bg->type = type;
198  bg->internal_cls = gi;
199  return bg;
200 }
struct GNUNET_CONTAINER_BloomFilter * GNUNET_CONTAINER_bloomfilter_init(const char *data, size_t size, unsigned int k)
Create a Bloom filter from raw bits.
void * internal_cls
Internal data structure of the plugin.
GNUNET_BLOCK_GroupSerializeFunction serialize_cb
Serialize the block group data, can be NULL if not supported.
static void bf_group_mark_seen_cb(struct GNUNET_BLOCK_Group *bg, const struct GNUNET_HashCode *seen_results, unsigned int seen_results_count)
Mark elements as "seen" using a hash of the element.
Definition: bg_bf.c:99
uint32_t bf_mutator
Set from the nonce to mingle the hashes before going into the bf.
Definition: bg_bf.c:45
Internal data structure for a block group.
Definition: bg_bf.c:35
static void bf_group_destroy_cb(struct GNUNET_BLOCK_Group *bg)
Destroy resources used by a block group.
Definition: bg_bf.c:150
#define GNUNET_new(type)
Allocate a struct or union of the given type.
GNUNET_BLOCK_GroupDestroyFunction destroy_cb
Function to call to destroy the block group.
enum GNUNET_BLOCK_Type type
Type for the block group.
static int bf_group_serialize_cb(struct GNUNET_BLOCK_Group *bg, uint32_t *nonce, void **raw_data, size_t *raw_data_size)
Serialize state of a block group.
Definition: bg_bf.c:65
uint32_t bf_size
Size of bf.
Definition: bg_bf.c:50
GNUNET_BLOCK_GroupMergeFunction merge_cb
Function to call to merge two groups.
Block group data.
struct GNUNET_CONTAINER_BloomFilter * bf
A Bloom filter to weed out duplicate replies probabilistically.
Definition: bg_bf.c:40
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
static int bf_group_merge_cb(struct GNUNET_BLOCK_Group *bg1, const struct GNUNET_BLOCK_Group *bg2)
Merge two groups, if possible.
Definition: bg_bf.c:128
GNUNET_BLOCK_GroupMarkSeenFunction mark_seen_cb
Function to call to mark elements as seen in the group.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BLOCK_GROUP_bf_test_and_set()

int 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.

Parameters
bgblock group to use for testing
hchash of element to evaluate
Returns
GNUNET_YES if hc is (likely) a duplicate GNUNET_NO if hc was definitively not in (but now is)

Definition at line 214 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_evaluate(), block_plugin_dns_evaluate(), block_plugin_fs_evaluate(), block_plugin_gns_evaluate(), block_plugin_revocation_evaluate(), block_plugin_template_evaluate(), block_plugin_test_evaluate(), evaluate_block_regex(), and evaluate_block_regex_accept().

216 {
217  struct BfGroupInternals *gi;
218  struct GNUNET_HashCode mhash;
219 
220  if (NULL == bg)
221  return GNUNET_NO;
222  gi = bg->internal_cls;
224  gi->bf_mutator,
225  &mhash);
226  if (GNUNET_YES ==
228  &mhash))
229  return GNUNET_YES;
231  &mhash);
232  return GNUNET_NO;
233 }
void * internal_cls
Internal data structure of the plugin.
void GNUNET_CONTAINER_bloomfilter_add(struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Add an element to the filter.
#define GNUNET_NO
Definition: gnunet_common.h:78
uint32_t bf_mutator
Set from the nonce to mingle the hashes before going into the bf.
Definition: bg_bf.c:45
Internal data structure for a block group.
Definition: bg_bf.c:35
int GNUNET_CONTAINER_bloomfilter_test(const struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Test if an element is in the filter.
A 512-bit hashcode.
struct GNUNET_CONTAINER_BloomFilter * bf
A Bloom filter to weed out duplicate replies probabilistically.
Definition: bg_bf.c:40
#define GNUNET_YES
Definition: gnunet_common.h:77
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.
Definition: block.c:81
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BLOCK_mingle_hash()

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.

Parameters
inoriginal hash code
mingle_numbernumber for hash permutation
hcwhere to store the result.

Definition at line 81 of file block.c.

References GNUNET_CRYPTO_hash(), and GNUNET_CRYPTO_hash_xor().

Referenced by bf_group_mark_seen_cb(), filtered_map_initialization(), GNUNET_BLOCK_GROUP_bf_test_and_set(), iterator_bf_create(), and iterator_bf_reduce().

84 {
85  struct GNUNET_HashCode m;
86 
87  GNUNET_CRYPTO_hash (&mingle_number,
88  sizeof(uint32_t),
89  &m);
91  in,
92  hc);
93 }
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:48
A 512-bit hashcode.
void GNUNET_CRYPTO_hash_xor(const struct GNUNET_HashCode *a, const struct GNUNET_HashCode *b, struct GNUNET_HashCode *result)
compute result = a ^ b
Definition: crypto_hash.c:202
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BLOCK_context_create()

struct GNUNET_BLOCK_Context* GNUNET_BLOCK_context_create ( const struct GNUNET_CONFIGURATION_Handle cfg)

Create a block context.

Loads the block plugins.

Parameters
cfgconfiguration to use
Returns
NULL on error

Definition at line 131 of file block.c.

References add_plugin(), GNUNET_BLOCK_Context::cfg, Plugin::cfg, ctx, GNUNET_new, and GNUNET_PLUGIN_load_all().

Referenced by run().

132 {
133  struct GNUNET_BLOCK_Context *ctx;
134 
135  ctx = GNUNET_new (struct GNUNET_BLOCK_Context);
136  ctx->cfg = cfg;
137  GNUNET_PLUGIN_load_all ("libgnunet_plugin_block_",
138  (void *) cfg,
139  &add_plugin,
140  ctx);
141  return ctx;
142 }
Handle to an initialized block library.
Definition: block.c:54
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
#define GNUNET_new(type)
Allocate a struct or union of the given type.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: block.c:69
static void add_plugin(void *cls, const char *library_name, void *lib_ret)
Add a plugin to the list managed by the block library.
Definition: block.c:104
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
void GNUNET_PLUGIN_load_all(const char *basename, void *arg, GNUNET_PLUGIN_LoaderCallback cb, void *cb_cls)
Load all compatible plugins with the given base name.
Definition: plugin.c:372
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BLOCK_context_destroy()

void GNUNET_BLOCK_context_destroy ( struct GNUNET_BLOCK_Context ctx)

Destroy the block context.

Parameters
ctxcontext to destroy

Definition at line 151 of file block.c.

References Plugin::api, GNUNET_break, GNUNET_free, GNUNET_PLUGIN_unload(), Plugin::library_name, GNUNET_BLOCK_Context::num_plugins, plugin, and GNUNET_BLOCK_Context::plugins.

Referenced by shutdown_task().

152 {
153  struct Plugin *plugin;
154 
155  for (unsigned int i = 0; i < ctx->num_plugins; i++)
156  {
157  plugin = ctx->plugins[i];
158  GNUNET_break (NULL ==
160  plugin->api));
161  GNUNET_free (plugin->library_name);
162  GNUNET_free (plugin);
163  }
164  GNUNET_free (ctx->plugins);
165  GNUNET_free (ctx);
166 }
char * library_name
Name of the shared library.
Definition: block.c:42
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47
void * GNUNET_PLUGIN_unload(const char *library_name, void *arg)
Unload plugin (runs the "done" callback and returns whatever "done" returned).
Definition: plugin.c:256
static char * plugin
Solver plugin name as string.
unsigned int num_plugins
Size of the &#39;plugins&#39; array.
Definition: block.c:64
Handle for a plugin.
Definition: block.c:37
struct Plugin ** plugins
Array of our plugins.
Definition: block.c:59
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BLOCK_group_create()

struct GNUNET_BLOCK_Group* GNUNET_BLOCK_group_create ( struct GNUNET_BLOCK_Context ctx,
enum GNUNET_BLOCK_Type  type,
uint32_t  nonce,
const void *  raw_data,
size_t  raw_data_size,
  ... 
)

Create a new block group.

Parameters
ctxblock context in which the block group is created
typetype of the block for which we are creating the group
noncerandom value used to seed the group creation
raw_dataoptional serialized prior state of the group, NULL if unavailable/fresh
raw_data_sizenumber of bytes in raw_data, 0 if unavailable/fresh
...type-specific additional data, can be empty
Returns
block group handle, NULL if block groups are not supported by this type of block (this is not an error)
Parameters
ctxblock context in which the block group is created
typetype of the block for which we are creating the group
noncerandom value used to seed the group creation
raw_dataoptional serialized prior state of the group, NULL if unavailable/fresh
raw_data_sizenumber of bytes in raw_data, 0 if unavailable/fresh
Returns
block group handle, NULL if block groups are not supported by this type of block (this is not an error)

Definition at line 289 of file block.c.

References GNUNET_BLOCK_PluginFunctions::cls, GNUNET_BLOCK_PluginFunctions::create_group, find_plugin(), and plugin.

Referenced by GSF_pending_request_create_(), handle_dht_p2p_get(), refresh_bloomfilter(), send_find_peer_message(), and transmit_request().

295 {
297  struct GNUNET_BLOCK_Group *bg;
298  va_list ap;
299 
300  plugin = find_plugin (ctx,
301  type);
302  if (NULL == plugin)
303  return NULL;
304  if (NULL == plugin->create_group)
305  return NULL;
306  va_start (ap,
307  raw_data_size);
308  bg = plugin->create_group (plugin->cls,
309  type,
310  nonce,
311  raw_data,
312  raw_data_size,
313  ap);
314  va_end (ap);
315  return bg;
316 }
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
static struct GNUNET_BLOCK_PluginFunctions * find_plugin(struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type)
Find a plugin for the given type.
Definition: block.c:256
static char * plugin
Solver plugin name as string.
GNUNET_BLOCK_GroupCreateFunction create_group
Create a block group to process a bunch of blocks in a shared context (i.e.
Block group data.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
void * cls
Closure for all of the callbacks.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BLOCK_group_serialize()

int GNUNET_BLOCK_group_serialize ( struct GNUNET_BLOCK_Group bg,
uint32_t *  nonce,
void **  raw_data,
size_t *  raw_data_size 
)

Serialize state of a block group.

Parameters
bggroup to serialize
[out]nonceset to the nonce of the bg
[out]raw_dataset to the serialized state
[out]raw_data_sizeset to the number of bytes in raw_data
Returns
GNUNET_OK on success, GNUNET_NO if serialization is not supported, GNUNET_SYSERR on error

Definition at line 180 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_().

184 {
185  *nonce = 0;
186  *raw_data = NULL;
187  *raw_data_size = 0;
188  if (NULL == bg)
189  return GNUNET_NO;
190  if (NULL == bg->serialize_cb)
191  return GNUNET_NO;
192  return bg->serialize_cb (bg,
193  nonce,
194  raw_data,
195  raw_data_size);
196 }
GNUNET_BLOCK_GroupSerializeFunction serialize_cb
Serialize the block group data, can be NULL if not supported.
#define GNUNET_NO
Definition: gnunet_common.h:78
Here is the caller graph for this function:

◆ GNUNET_BLOCK_group_destroy()

void GNUNET_BLOCK_group_destroy ( struct GNUNET_BLOCK_Group bg)

Destroy resources used by a block group.

Parameters
bggroup to destroy, NULL is allowed

Definition at line 205 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().

206 {
207  if (NULL == bg)
208  return;
209  bg->destroy_cb (bg);
210 }
GNUNET_BLOCK_GroupDestroyFunction destroy_cb
Function to call to destroy the block group.
Here is the caller graph for this function:

◆ GNUNET_BLOCK_evaluate()

enum GNUNET_BLOCK_EvaluationResult GNUNET_BLOCK_evaluate ( struct GNUNET_BLOCK_Context ctx,
enum GNUNET_BLOCK_Type  type,
struct GNUNET_BLOCK_Group group,
enum GNUNET_BLOCK_EvaluationOptions  eo,
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 a reply or a request.

For request evaluation, simply pass "NULL" for the reply_block. Note that it is assumed that the reply has already been matched to the key (and signatures checked) as it would be done with the GNUNET_BLOCK_get_key() function.

Parameters
ctxblock contxt
typeblock type
groupblock group to use for evaluation
eoevaluation options to control evaluation
queryoriginal query (hash)
xqueryextrended query data (can be NULL, depending on type)
xquery_sizenumber of bytes in xquery
reply_blockresponse to validate
reply_block_sizenumber of bytes in reply_block
Returns
characterization of result

For request evaluation, simply pass "NULL" for the reply_block. Note that it is assumed that the reply has already been matched to the key (and signatures checked) as it would be done with the "get_key" function.

Parameters
ctxblock contxt
typeblock type
blockblock group to use
eocontrol flags
queryoriginal query (hash)
xqueryextended query data (can be NULL, depending on type)
xquery_sizenumber of bytes in xquery
reply_blockresponse to validate
reply_block_sizenumber of bytes in reply_block
Returns
characterization of result

Definition at line 338 of file block.c.

References GNUNET_BLOCK_PluginFunctions::cls, GNUNET_BLOCK_PluginFunctions::evaluate, find_plugin(), GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED, and plugin.

Referenced by block_plugin_consensus_evaluate(), datacache_get_iterator(), forward_reply(), handle_dht_p2p_get(), handle_dht_p2p_put(), handle_find_peer(), process(), and process_reply().

347 {
349  type);
350 
351  if (NULL == plugin)
353  return plugin->evaluate (plugin->cls,
354  ctx,
355  type,
356  group,
357  eo,
358  query,
359  xquery,
360  xquery_size,
361  reply_block,
362  reply_block_size);
363 }
GNUNET_BLOCK_EvaluationFunction evaluate
Main function of a block plugin.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
static struct GNUNET_BLOCK_PluginFunctions * find_plugin(struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type)
Find a plugin for the given type.
Definition: block.c:256
static char * plugin
Solver plugin name as string.
Specified block type not supported by this plugin.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
void * cls
Closure for all of the callbacks.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BLOCK_get_key()

int 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.

Parameters
ctxblock context
typeblock type
blockblock to get the key for
block_sizenumber of bytes in block
keyset to the key (query) for the given block
Returns
GNUNET_YES on success, GNUNET_NO if the block is malformed GNUNET_SYSERR if type not supported (or if extracting a key from a block of this type does not work)
Parameters
ctxblock context
typeblock type
blockblock to get the key for
block_sizenumber of bytes in block
keyset to the key (query) for the given block
Returns
GNUNET_OK on success, GNUNET_SYSERR if type not supported (or if extracting a key from a block of this type does not work)

Definition at line 378 of file block.c.

References GNUNET_BLOCK_PluginFunctions::cls, find_plugin(), GNUNET_BLOCK_PluginFunctions::get_key, GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED, and plugin.

Referenced by cadet_reply_proc(), handle_dht_p2p_put(), handle_p2p_put(), handle_reply(), process(), and process_local_reply().

383 {
385  type);
386 
387  if (plugin == NULL)
389  return plugin->get_key (plugin->cls,
390  type,
391  block,
392  block_size,
393  key);
394 }
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
static struct GNUNET_BLOCK_PluginFunctions * find_plugin(struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type)
Find a plugin for the given type.
Definition: block.c:256
static char * plugin
Solver plugin name as string.
Specified block type not supported by this plugin.
GNUNET_BLOCK_GetKeyFunction get_key
Obtain the key for a given block (if possible).
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
void * cls
Closure for all of the callbacks.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BLOCK_group_set_seen()

int 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.

Parameters
bf_mutatormutation value to use
seen_resultsresults already seen
seen_results_countnumber of entries in seen_results
Returns
GNUNET_SYSERR if not supported, GNUNET_OK on success

Definition at line 409 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().

412 {
413  if (NULL == bg)
414  return GNUNET_OK;
415  if (NULL == bg->mark_seen_cb)
416  return GNUNET_SYSERR;
417  bg->mark_seen_cb (bg,
418  seen_results,
419  seen_results_count);
420  return GNUNET_OK;
421 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
GNUNET_BLOCK_GroupMarkSeenFunction mark_seen_cb
Function to call to mark elements as seen in the group.
Here is the caller graph for this function:

◆ GNUNET_BLOCK_group_merge()

int 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 , and bg2 should be destroyed (as part of this call). The latter should happen even if merging is not supported.

Parameters
[in,out]bg1first group to merge, is updated
bg2second group to merge, is destroyed
Returns
GNUNET_OK on success, GNUNET_NO if merge failed due to different nonce GNUNET_SYSERR if merging is not supported

Definition at line 226 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().

228 {
229  int ret;
230 
231  if (NULL == bg2)
232  return GNUNET_OK;
233  if (NULL == bg1)
234  {
235  bg2->destroy_cb (bg2);
236  return GNUNET_OK;
237  }
238  if (NULL == bg1->merge_cb)
239  return GNUNET_SYSERR;
240  GNUNET_assert (bg1->merge_cb == bg1->merge_cb);
241  ret = bg1->merge_cb (bg1,
242  bg2);
243  bg2->destroy_cb (bg2);
244  return ret;
245 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
GNUNET_BLOCK_GroupDestroyFunction destroy_cb
Function to call to destroy the block group.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
GNUNET_BLOCK_GroupMergeFunction merge_cb
Function to call to merge two groups.
Here is the caller graph for this function: