GNUnet  0.20.0
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
 

Functions

static enum GNUNET_GenericReturnValue block_plugin_revocation_check_query (void *cls, enum GNUNET_BLOCK_Type type, const struct GNUNET_HashCode *query, const void *xquery, size_t xquery_size)
 Function called to validate a query. More...
 
static enum GNUNET_GenericReturnValue block_plugin_revocation_check_block (void *cls, enum GNUNET_BLOCK_Type type, const void *block, size_t block_size)
 Function called to validate a block for storage. More...
 
static enum GNUNET_BLOCK_ReplyEvaluationResult block_plugin_revocation_check_reply (void *cls, 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 a reply to a request. More...
 
static enum GNUNET_GenericReturnValue 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.

Function Documentation

◆ block_plugin_revocation_check_query()

static enum GNUNET_GenericReturnValue block_plugin_revocation_check_query ( void *  cls,
enum GNUNET_BLOCK_Type  type,
const struct GNUNET_HashCode query,
const void *  xquery,
size_t  xquery_size 
)
static

Function called to validate a query.

Parameters
clsclosure
ctxblock context
typeblock type
queryoriginal query (hash)
xqueryextrended query data (can be NULL, depending on type)
xquery_sizenumber of bytes in xquery
Returns
GNUNET_OK if the query is fine, GNUNET_NO if not

Definition at line 1 of file plugin_block_revocation.c.

63 {
64  (void) cls;
65  (void) query;
66  (void) xquery;
68  {
69  GNUNET_break (0);
70  return GNUNET_SYSERR;
71  }
72  if (0 != xquery_size)
73  return GNUNET_NO;
74  return GNUNET_OK;
75 }
@ GNUNET_BLOCK_TYPE_REVOCATION
Block type for a revocation message by which a key is revoked.
@ GNUNET_OK
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model

Referenced by libgnunet_plugin_block_revocation_init().

Here is the caller graph for this function:

◆ block_plugin_revocation_check_block()

static enum GNUNET_GenericReturnValue block_plugin_revocation_check_block ( void *  cls,
enum GNUNET_BLOCK_Type  type,
const void *  block,
size_t  block_size 
)
static

Function called to validate a block for storage.

Parameters
clsclosure
typeblock type
blockblock data to validate
block_sizenumber of bytes in block
Returns
GNUNET_OK if the block is fine, GNUNET_NO if not

Definition at line 1 of file plugin_block_revocation.c.

92 {
93  struct InternalContext *ic = cls;
94  const struct RevokeMessage *rm = block;
95  const struct GNUNET_REVOCATION_PowP *pow
96  = (const struct GNUNET_REVOCATION_PowP *) &rm[1];
98  size_t pklen;
99  size_t left;
100 
102  {
103  GNUNET_break (0);
104  return GNUNET_SYSERR;
105  }
106  if (block_size < sizeof(*rm) + sizeof(*pow))
107  {
108  GNUNET_break_op (0);
109  return GNUNET_NO;
110  }
111  if (block_size != sizeof(*rm) + ntohl (rm->pow_size))
112  {
113  GNUNET_break_op (0);
114  return GNUNET_NO;
115  }
116  left = block_size - sizeof (*rm) - sizeof (*pow);
117  if (GNUNET_SYSERR ==
119  left,
120  &pk,
121  &pklen))
122  {
123  GNUNET_break_op (0);
124  return GNUNET_NO;
125  }
126  if (0 == pklen)
127  {
128  GNUNET_break_op (0);
129  return GNUNET_NO;
130  }
131  if (GNUNET_YES !=
133  ic->matching_bits,
134  ic->epoch_duration))
135  {
136  GNUNET_break_op (0);
137  return GNUNET_NO;
138  }
139  return GNUNET_OK;
140 }
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
enum GNUNET_GenericReturnValue GNUNET_IDENTITY_read_public_key_from_buffer(const void *buffer, size_t len, struct GNUNET_IDENTITY_PublicKey *key, size_t *kb_read)
Reads a GNUNET_IDENTITY_PublicKey from a compact buffer.
Definition: identity_api.c:865
@ GNUNET_YES
#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.
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:80
uint32_t pow_size
Length of PoW with signature.
Definition: revocation.h:89

Referenced by libgnunet_plugin_block_revocation_init().

Here is the caller graph for this function:

◆ block_plugin_revocation_check_reply()

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

Function called to validate a reply to a request.

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 GetKeyFunction and the BlockEvaluationFunction.

Parameters
clsclosure
typeblock type
groupwhich block group to use for 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

Definition at line 1 of file plugin_block_revocation.c.

169 {
170  (void) cls;
171  (void) group;
172  (void) query;
173  (void) xquery;
174  (void) xquery_size;
175  (void) reply_block;
176  (void) reply_block_size;
178  {
179  GNUNET_break (0);
181  }
183 }
@ GNUNET_BLOCK_REPLY_OK_LAST
Last possible valid result.
@ GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED
Specified block type not supported by any plugin.

Referenced by libgnunet_plugin_block_revocation_init().

Here is the caller graph for this function:

◆ block_plugin_revocation_get_key()

static enum GNUNET_GenericReturnValue 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 1 of file plugin_block_revocation.c.

203 {
204  const struct RevokeMessage *rm = block;
205  const struct GNUNET_REVOCATION_PowP *pow
206  = (const struct GNUNET_REVOCATION_PowP *) &rm[1];
208  size_t pklen;
209  size_t left;
210 
212  {
213  GNUNET_break (0);
214  return GNUNET_SYSERR;
215  }
216  if (block_size < sizeof(*rm) + sizeof(*pow))
217  {
218  GNUNET_break_op (0);
219  return GNUNET_NO;
220  }
221  if (block_size != sizeof(*rm) + ntohl (rm->pow_size))
222  {
223  GNUNET_break_op (0);
224  return GNUNET_NO;
225  }
226  left = block_size - sizeof (*rm) - sizeof (*pow);
228  left,
229  &pk,
230  &pklen))
231  {
232  GNUNET_break_op (0);
233  return GNUNET_NO;
234  }
235  if (0 == pklen)
236  {
237  GNUNET_break_op (0);
238  return GNUNET_NO;
239  }
240  GNUNET_CRYPTO_hash (&pow[1],
241  pklen,
242  key);
243  return GNUNET_OK;
244 }
struct GNUNET_HashCode key
The key used in the DHT.
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

Referenced by libgnunet_plugin_block_revocation_init().

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 253 of file plugin_block_revocation.c.

254 {
255  static const enum GNUNET_BLOCK_Type types[] = {
257  GNUNET_BLOCK_TYPE_ANY /* end of list */
258  };
259  const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
260  struct GNUNET_BLOCK_PluginFunctions *api;
261  struct InternalContext *ic;
262  unsigned long long matching_bits;
264 
265  if (GNUNET_OK !=
267  "REVOCATION",
268  "WORKBITS",
269  &matching_bits))
270  return NULL;
271  if (GNUNET_OK !=
273  "REVOCATION",
274  "EPOCH_DURATION",
275  &epoch_duration))
276  return NULL;
277 
283  api->create_group = NULL;
284  api->types = types;
285  ic = GNUNET_new (struct InternalContext);
286  ic->matching_bits = (unsigned int) matching_bits;
288  api->cls = ic;
289  return api;
290 }
GNUNET_BLOCK_Type
WARNING: This header is generated! In order to add DHT block types, you must register them in GANA,...
@ GNUNET_BLOCK_TYPE_ANY
Identifier for any block.
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.
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_GenericReturnValue block_plugin_revocation_check_query(void *cls, enum GNUNET_BLOCK_Type type, const struct GNUNET_HashCode *query, const void *xquery, size_t xquery_size)
Function called to validate a query.
static enum GNUNET_BLOCK_ReplyEvaluationResult block_plugin_revocation_check_reply(void *cls, 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 a reply to a request.
static enum GNUNET_GenericReturnValue 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.
static enum GNUNET_GenericReturnValue block_plugin_revocation_check_block(void *cls, enum GNUNET_BLOCK_Type type, const void *block, size_t block_size)
Function called to validate a block for storage.
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_QueryEvaluationFunction check_query
Check that a query is well-formed.
GNUNET_BLOCK_BlockEvaluationFunction check_block
Check that a block is well-formed.
GNUNET_BLOCK_GetKeyFunction get_key
Obtain the key for a given block (if possible).
GNUNET_BLOCK_ReplyEvaluationFunction check_reply
Check that a reply block matches a query.
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.
Time for relative time used by GNUnet, in microseconds.

References block_plugin_revocation_check_block(), block_plugin_revocation_check_query(), block_plugin_revocation_check_reply(), block_plugin_revocation_get_key(), cfg, GNUNET_BLOCK_PluginFunctions::check_block, GNUNET_BLOCK_PluginFunctions::check_query, GNUNET_BLOCK_PluginFunctions::check_reply, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_BLOCK_PluginFunctions::create_group, epoch_duration, InternalContext::epoch_duration, 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 297 of file plugin_block_revocation.c.

298 {
299  struct GNUNET_BLOCK_PluginFunctions *api = cls;
300  struct InternalContext *ic = api->cls;
301 
302  GNUNET_free (ic);
303  GNUNET_free (api);
304  return NULL;
305 }
#define GNUNET_free(ptr)
Wrapper around free.

References GNUNET_BLOCK_PluginFunctions::cls, and GNUNET_free.