GNUnet  0.11.x
Data Structures | Macros | Functions
plugin_block_revocation.c File Reference
#include "platform.h"
#include "gnunet_signatures.h"
#include "gnunet_block_plugin.h"
#include "gnunet_block_group_lib.h"
#include "revocation.h"
#include "gnunet_revocation_service.h"
Include dependency graph for plugin_block_revocation.c:

Go to the source code of this file.

Data Structures

struct  InternalContext
 Context used inside the plugin. More...
 

Macros

#define DEBUG_REVOCATION   GNUNET_EXTRA_LOGGING
 
#define BLOOMFILTER_K   16
 Number of bits we set per entry in the bloomfilter. More...
 
#define REVOCATION_BF_SIZE   8
 How big is the BF we use for DHT blocks? More...
 

Functions

static struct GNUNET_BLOCK_Groupblock_plugin_revocation_create_group (void *cls, enum GNUNET_BLOCK_Type type, uint32_t nonce, const void *raw_data, size_t raw_data_size, va_list va)
 Create a new block group. More...
 
static enum GNUNET_BLOCK_EvaluationResult block_plugin_revocation_evaluate (void *cls, 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...
 
static int block_plugin_revocation_get_key (void *cls, 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...
 
void * libgnunet_plugin_block_revocation_init (void *cls)
 Entry point for the plugin. More...
 
void * libgnunet_plugin_block_revocation_done (void *cls)
 Exit point from the plugin. More...
 

Macro Definition Documentation

◆ DEBUG_REVOCATION

#define DEBUG_REVOCATION   GNUNET_EXTRA_LOGGING

Definition at line 34 of file plugin_block_revocation.c.

◆ BLOOMFILTER_K

#define BLOOMFILTER_K   16

Number of bits we set per entry in the bloomfilter.

Do not change!

Definition at line 40 of file plugin_block_revocation.c.

◆ REVOCATION_BF_SIZE

#define REVOCATION_BF_SIZE   8

How big is the BF we use for DHT blocks?

Definition at line 46 of file plugin_block_revocation.c.

Function Documentation

◆ block_plugin_revocation_create_group()

static struct GNUNET_BLOCK_Group* block_plugin_revocation_create_group ( void *  cls,
enum GNUNET_BLOCK_Type  type,
uint32_t  nonce,
const void *  raw_data,
size_t  raw_data_size,
va_list  va 
)
static

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
vavariable arguments specific to type
Returns
block group handle, NULL if block groups are not supported by this type of block (this is not an error)

Definition at line 72 of file plugin_block_revocation.c.

78 {
79  unsigned int bf_size;
80  const char *guard;
81 
82  guard = va_arg (va, const char *);
83  if (0 == strcmp (guard,
84  "seen-set-size"))
85  bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned
86  int),
88  else if (0 == strcmp (guard,
89  "filter-size"))
90  bf_size = va_arg (va, unsigned int);
91  else
92  {
93  GNUNET_break (0);
94  bf_size = REVOCATION_BF_SIZE;
95  }
96  GNUNET_break (NULL == va_arg (va, const char *));
97  return GNUNET_BLOCK_GROUP_bf_create (cls,
98  bf_size,
100  type,
101  nonce,
102  raw_data,
103  raw_data_size);
104 }
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?...
Definition: bg_bf.c:250
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.
Definition: bg_bf.c:174
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define BLOOMFILTER_K
Number of bits we set per entry in the bloomfilter.
#define REVOCATION_BF_SIZE
How big is the BF we use for DHT blocks?
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model

References BLOOMFILTER_K, GNUNET_BLOCK_GROUP_bf_create(), GNUNET_BLOCK_GROUP_compute_bloomfilter_size(), GNUNET_break, REVOCATION_BF_SIZE, and type.

Referenced by libgnunet_plugin_block_revocation_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ block_plugin_revocation_evaluate()

static enum GNUNET_BLOCK_EvaluationResult block_plugin_revocation_evaluate ( void *  cls,
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 
)
static

Function called to validate a reply or a request.

For request evaluation, simply pass "NULL" for the reply_block.

Parameters
clsour struct InternalContext
ctxcontext
typeblock type
groupblock group to use
eocontrol flags
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

Definition at line 72 of file plugin_block_revocation.c.

134 {
135  struct InternalContext *ic = cls;
136  struct GNUNET_HashCode chash;
137  ssize_t pklen;
138  const struct RevokeMessage *rm = reply_block;
139 
140  if (NULL == reply_block)
142  if (reply_block_size != sizeof(*rm))
143  {
144  GNUNET_break_op (0);
146  }
147  struct GNUNET_REVOCATION_PowP *pow = (struct GNUNET_REVOCATION_PowP *) &rm[1];
148  const struct GNUNET_IDENTITY_PublicKey *pk;
149  pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1];
151  ic->matching_bits,
152  ic->epoch_duration))
153  {
154  GNUNET_break_op (0);
156  }
158  if (0 > pklen)
159  {
160  GNUNET_break_op (0);
162  }
164  pklen,
165  &chash);
166  if (GNUNET_YES ==
168  &chash))
171 }
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
@ GNUNET_YES
Definition: gnunet_common.h:97
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.
Definition: bg_bf.c:214
@ GNUNET_BLOCK_EVALUATION_RESULT_INVALID
Block does not match query (invalid result)
@ GNUNET_BLOCK_EVALUATION_OK_DUPLICATE
Valid result, but suppressed because it is a duplicate.
@ GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED
Specified block type not supported by this plugin.
@ GNUNET_BLOCK_EVALUATION_REQUEST_VALID
Query is valid, no reply given.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
ssize_t GNUNET_IDENTITY_key_get_length(const struct GNUNET_IDENTITY_PublicKey *key)
Get the compacted length of a GNUNET_IDENTITY_PublicKey.
Definition: identity_api.c:976
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
enum GNUNET_GenericReturnValue GNUNET_REVOCATION_check_pow(const struct GNUNET_REVOCATION_PowP *pow, unsigned int matching_bits, struct GNUNET_TIME_Relative epoch_duration)
Check if the given proof-of-work is valid.
A 512-bit hashcode.
An identity key as per LSD0001.
Struct for a proof of work as part of the revocation.
Context used inside the plugin.
struct GNUNET_TIME_Relative epoch_duration
Revoke key.
Definition: revocation.h:81

Referenced by libgnunet_plugin_block_revocation_init().

Here is the caller graph for this function:

◆ block_plugin_revocation_get_key()

static int block_plugin_revocation_get_key ( void *  cls,
enum GNUNET_BLOCK_Type  type,
const void *  block,
size_t  block_size,
struct GNUNET_HashCode key 
)
static

Function called to obtain the key for a block.

Parameters
clsclosure
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 186 of file plugin_block_revocation.c.

191 {
192  const struct RevokeMessage *rm = block;
193  ssize_t ksize;
194 
195  if (block_size <= sizeof(*rm))
196  {
197  GNUNET_break_op (0);
198  return GNUNET_SYSERR;
199  }
200  struct GNUNET_REVOCATION_PowP *pow = (struct GNUNET_REVOCATION_PowP *) &rm[1];
201  const struct GNUNET_IDENTITY_PublicKey *pk;
202  pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1];
204  if (0 > ksize)
205  {
206  GNUNET_break_op (0);
207  return GNUNET_SYSERR;
208  }
210  ksize,
211  key);
212  return GNUNET_OK;
213 }
struct GNUNET_HashCode key
The key used in the DHT.
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_SYSERR
Definition: gnunet_common.h:93

References GNUNET_break_op, GNUNET_CRYPTO_hash(), GNUNET_IDENTITY_key_get_length(), GNUNET_OK, GNUNET_SYSERR, key, pk, and GNUNET_REVOCATION_PowP::pow.

Referenced by libgnunet_plugin_block_revocation_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ libgnunet_plugin_block_revocation_init()

void* libgnunet_plugin_block_revocation_init ( void *  cls)

Entry point for the plugin.

Parameters
clsthe configuration to use

Definition at line 222 of file plugin_block_revocation.c.

223 {
224  static enum GNUNET_BLOCK_Type types[] = {
226  GNUNET_BLOCK_TYPE_ANY /* end of list */
227  };
228  const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
229  struct GNUNET_BLOCK_PluginFunctions *api;
230  struct InternalContext *ic;
231  unsigned long long matching_bits;
233 
234  if (GNUNET_OK !=
236  "REVOCATION",
237  "WORKBITS",
238  &matching_bits))
239  return NULL;
240  if (GNUNET_OK !=
242  "REVOCATION",
243  "EPOCH_DURATION",
244  &epoch_duration))
245  return NULL;
246 
251  api->types = types;
252  ic = GNUNET_new (struct InternalContext);
253  ic->matching_bits = (unsigned int) matching_bits;
255  api->cls = ic;
256  return api;
257 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static struct GNUNET_TIME_Relative epoch_duration
Epoch length.
static unsigned long long matching_bits
Number of matching bits required for revocation.
GNUNET_BLOCK_Type
Blocks in the datastore and the datacache must have a unique type.
@ GNUNET_BLOCK_TYPE_REVOCATION
Block type for a revocation message by which a key is revoked.
@ GNUNET_BLOCK_TYPE_ANY
Any type of block, used as a wildcard when searching.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_time(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, struct GNUNET_TIME_Relative *time)
Get a configuration value that should be a relative time.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static enum GNUNET_BLOCK_EvaluationResult block_plugin_revocation_evaluate(void *cls, 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.
static struct GNUNET_BLOCK_Group * block_plugin_revocation_create_group(void *cls, enum GNUNET_BLOCK_Type type, uint32_t nonce, const void *raw_data, size_t raw_data_size, va_list va)
Create a new block group.
static int block_plugin_revocation_get_key(void *cls, 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.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
enum GNUNET_BLOCK_Type * types
0-terminated array of block types supported by this plugin.
GNUNET_BLOCK_GetKeyFunction get_key
Obtain the key for a given block (if possible).
GNUNET_BLOCK_GroupCreateFunction create_group
Create a block group to process a bunch of blocks in a shared context (i.e.
void * cls
Closure for all of the callbacks.
GNUNET_BLOCK_EvaluationFunction evaluate
Main function of a block plugin.
Time for relative time used by GNUnet, in microseconds.

References block_plugin_revocation_create_group(), block_plugin_revocation_evaluate(), block_plugin_revocation_get_key(), cfg, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_BLOCK_PluginFunctions::create_group, epoch_duration, InternalContext::epoch_duration, GNUNET_BLOCK_PluginFunctions::evaluate, GNUNET_BLOCK_PluginFunctions::get_key, GNUNET_BLOCK_TYPE_ANY, GNUNET_BLOCK_TYPE_REVOCATION, GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_time(), GNUNET_new, GNUNET_OK, consensus-simulation::int, matching_bits, InternalContext::matching_bits, and GNUNET_BLOCK_PluginFunctions::types.

Here is the call graph for this function:

◆ libgnunet_plugin_block_revocation_done()

void* libgnunet_plugin_block_revocation_done ( void *  cls)

Exit point from the plugin.

Definition at line 264 of file plugin_block_revocation.c.

265 {
266  struct GNUNET_BLOCK_PluginFunctions *api = cls;
267  struct InternalContext *ic = api->cls;
268 
269  GNUNET_free (ic);
270  GNUNET_free (api);
271  return NULL;
272 }
#define GNUNET_free(ptr)
Wrapper around free.

References GNUNET_BLOCK_PluginFunctions::cls, and GNUNET_free.