GNUnet  0.11.x
Data Structures | Functions | Variables
gnunet-service-revocation.c File Reference

key revocation service More...

#include "platform.h"
#include <math.h>
#include "gnunet_util_lib.h"
#include "gnunet_block_lib.h"
#include "gnunet_constants.h"
#include "gnunet_protocols.h"
#include "gnunet_signatures.h"
#include "gnunet_statistics_service.h"
#include "gnunet_core_service.h"
#include "gnunet_revocation_service.h"
#include "gnunet_setu_service.h"
#include "revocation.h"
#include <gcrypt.h>
Include dependency graph for gnunet-service-revocation.c:

Go to the source code of this file.

Data Structures

struct  PeerEntry
 Per-peer information. More...
 

Functions

static struct PeerEntrynew_peer_entry (const struct GNUNET_PeerIdentity *peer)
 Create a new PeerEntry and add it to the peers multipeermap. More...
 
static int verify_revoke_message (const struct RevokeMessage *rm)
 An revoke message has been received, check that it is well-formed. More...
 
static void * client_connect_cb (void *cls, struct GNUNET_SERVICE_Client *client, struct GNUNET_MQ_Handle *mq)
 Handle client connecting to the service. More...
 
static void client_disconnect_cb (void *cls, struct GNUNET_SERVICE_Client *client, void *app_cls)
 Handle client connecting to the service. More...
 
static void handle_query_message (void *cls, const struct QueryMessage *qm)
 Handle QUERY message from client. More...
 
static int do_flood (void *cls, const struct GNUNET_PeerIdentity *target, void *value)
 Flood the given revocation message to all neighbours. More...
 
static int publicize_rm (const struct RevokeMessage *rm)
 Publicize revocation message. More...
 
static int check_revoke_message (void *cls, const struct RevokeMessage *rm)
 
static void handle_revoke_message (void *cls, const struct RevokeMessage *rm)
 Handle REVOKE message from client. More...
 
static int check_p2p_revoke (void *cls, const struct RevokeMessage *rm)
 
static void handle_p2p_revoke (void *cls, const struct RevokeMessage *rm)
 Core handler for flooded revocation messages. More...
 
static void add_revocation (void *cls, const struct GNUNET_SETU_Element *element, uint64_t current_size, enum GNUNET_SETU_Status status)
 Callback for set operation results. More...
 
static void transmit_task_cb (void *cls)
 The timeout for performing the set union has expired, run the set operation on the revocation certificates. More...
 
static void * handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
 Method called whenever a peer connects. More...
 
static void handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer, void *internal_cls)
 Method called whenever a peer disconnects. More...
 
static int free_entry (void *cls, const struct GNUNET_HashCode *key, void *value)
 Free all values in a hash map. More...
 
static void shutdown_task (void *cls)
 Task run during shutdown. More...
 
static void core_init (void *cls, const struct GNUNET_PeerIdentity *identity)
 Called on core init/fail. More...
 
static void handle_revocation_union_request (void *cls, const struct GNUNET_PeerIdentity *other_peer, const struct GNUNET_MessageHeader *context_msg, struct GNUNET_SETU_Request *request)
 Called when another peer wants to do a set operation with the local peer. More...
 
static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *service)
 Handle network size estimate clients. More...
 
 GNUNET_SERVICE_MAIN ("revocation", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, &client_disconnect_cb, NULL, GNUNET_MQ_hd_fixed_size(query_message, GNUNET_MESSAGE_TYPE_REVOCATION_QUERY, struct QueryMessage, NULL), GNUNET_MQ_hd_var_size(revoke_message, GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE, struct RevokeMessage, NULL), GNUNET_MQ_handler_end())
 Define "main" method using service macro. More...
 

Variables

static struct GNUNET_SETU_Handlerevocation_set
 Set from all revocations known to us. More...
 
static struct GNUNET_CONTAINER_MultiHashMaprevocation_map
 Hash map with all revoked keys, maps the hash of the public key to the respective struct RevokeMessage. More...
 
static const struct GNUNET_CONFIGURATION_Handlecfg
 Handle to our current configuration. More...
 
static struct GNUNET_STATISTICS_Handlestats
 Handle to the statistics service. More...
 
static struct GNUNET_CORE_Handlecore_api
 Handle to the core service (for flooding) More...
 
static struct GNUNET_CONTAINER_MultiPeerMappeers
 Map of all connected peers. More...
 
static struct GNUNET_PeerIdentity my_identity
 The peer identity of this peer. More...
 
static struct GNUNET_DISK_FileHandlerevocation_db
 File handle for the revocation database. More...
 
static struct GNUNET_SETU_ListenHandlerevocation_union_listen_handle
 Handle for us listening to incoming revocation set union requests. More...
 
static unsigned long long revocation_work_required
 Amount of work required (W-bit collisions) for REVOCATION proofs, in collision-bits. More...
 
static struct GNUNET_TIME_Relative epoch_duration
 Length of an expiration expoch. More...
 
static struct GNUNET_HashCode revocation_set_union_app_id
 Our application ID for set union operations. More...
 

Detailed Description

key revocation service

Author
Christian Grothoff

The purpose of this service is to allow users to permanently revoke (compromised) keys. This is done by flooding the network with the revocation requests. To reduce the attack potential offered by such flooding, revocations must include a proof of work. We use the set service for efficiently computing the union of revocations of peers that connect.

TODO:

Definition in file gnunet-service-revocation.c.

Function Documentation

◆ new_peer_entry()

static struct PeerEntry* new_peer_entry ( const struct GNUNET_PeerIdentity peer)
static

Create a new PeerEntry and add it to the peers multipeermap.

Parameters
peerthe peer identity
Returns
a pointer to the new PeerEntry

Definition at line 150 of file gnunet-service-revocation.c.

References GNUNET_assert, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multipeermap_put(), GNUNET_new, GNUNET_OK, PeerEntry::id, and peer.

Referenced by handle_core_connect(), and handle_revocation_union_request().

151 {
152  struct PeerEntry *peer_entry;
153 
154  peer_entry = GNUNET_new (struct PeerEntry);
155  peer_entry->id = *peer;
158  &peer_entry->id,
159  peer_entry,
161  return peer_entry;
162 }
Per-peer information.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_CONTAINER_MultiPeerMap * peers
Map of all connected peers.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
There must only be one value per key; storing a value should fail if a value under the same key alrea...
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
struct GNUNET_PeerIdentity id
What is the identity of the peer?
Here is the call graph for this function:
Here is the caller graph for this function:

◆ verify_revoke_message()

static int verify_revoke_message ( const struct RevokeMessage rm)
static

An revoke message has been received, check that it is well-formed.

Parameters
rmthe message to verify
Returns
GNUNET_YES if the message is verified GNUNET_NO if the key/signature don't verify

Definition at line 173 of file gnunet-service-revocation.c.

References epoch_duration, GNUNET_break_op, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NO, GNUNET_REVOCATION_check_pow(), GNUNET_YES, GNUNET_REVOCATION_PowP::pow, and revocation_work_required.

Referenced by publicize_rm().

174 {
175  struct GNUNET_REVOCATION_PowP *pow = (struct GNUNET_REVOCATION_PowP *) &rm[1];
177  (unsigned
180  {
182  "Proof of work invalid!\n");
183  GNUNET_break_op (0);
184  return GNUNET_NO;
185  }
186  return GNUNET_YES;
187 }
Struct for a proof of work as part of the revocation.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
uint64_t pow[32]
The PoWs.
static unsigned long long revocation_work_required
Amount of work required (W-bit collisions) for REVOCATION proofs, in collision-bits.
static struct GNUNET_TIME_Relative epoch_duration
Length of an expiration expoch.
#define GNUNET_log(kind,...)
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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ client_connect_cb()

static void* client_connect_cb ( void *  cls,
struct GNUNET_SERVICE_Client client,
struct GNUNET_MQ_Handle mq 
)
static

Handle client connecting to the service.

Parameters
clsNULL
clientthe new client
mqthe message queue of client
Returns
client

Definition at line 199 of file gnunet-service-revocation.c.

Referenced by run().

202 {
203  return client;
204 }
Here is the caller graph for this function:

◆ client_disconnect_cb()

static void client_disconnect_cb ( void *  cls,
struct GNUNET_SERVICE_Client client,
void *  app_cls 
)
static

Handle client connecting to the service.

Parameters
clsNULL
clientthe new client
app_clsmust alias client

Definition at line 215 of file gnunet-service-revocation.c.

References GNUNET_assert.

Referenced by run().

218 {
219  GNUNET_assert (client == app_cls);
220 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Here is the caller graph for this function:

◆ handle_query_message()

static void handle_query_message ( void *  cls,
const struct QueryMessage qm 
)
static

Handle QUERY message from client.

Parameters
clsclient who sent the message
qmthe message received

Definition at line 230 of file gnunet-service-revocation.c.

References env, GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_MESSAGE_TYPE_REVOCATION_QUERY_RESPONSE, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_NO, GNUNET_SERVICE_client_continue(), GNUNET_SERVICE_client_get_mq(), GNUNET_YES, QueryResponseMessage::is_valid, QueryMessage::key, and res.

232 {
233  struct GNUNET_SERVICE_Client *client = cls;
234  struct GNUNET_MQ_Envelope *env;
235  struct QueryResponseMessage *qrm;
236  struct GNUNET_HashCode hc;
237  int res;
238 
239  GNUNET_CRYPTO_hash (&qm->key,
240  sizeof(struct GNUNET_IDENTITY_PublicKey),
241  &hc);
243  &hc);
245  (GNUNET_NO == res)
246  ? "Received revocation check for valid key `%s' from client\n"
247  : "Received revocation check for revoked key `%s' from client\n",
248  GNUNET_h2s (&hc));
249  env = GNUNET_MQ_msg (qrm,
251  qrm->is_valid = htonl ((GNUNET_YES == res) ? GNUNET_NO : GNUNET_YES);
253  env);
255 }
struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq(struct GNUNET_SERVICE_Client *c)
Obtain the message queue of c.
Definition: service.c:2438
static struct GNUNET_CONTAINER_MultiHashMap * revocation_map
Hash map with all revoked keys, maps the hash of the public key to the respective struct RevokeMessag...
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
int GNUNET_CONTAINER_multihashmap_contains(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Check if the map contains any value under the given key (including values that are NULL)...
struct GNUNET_IDENTITY_PublicKey key
Key to check.
Definition: revocation.h:52
Handle to a client that is connected to a service.
Definition: service.c:250
#define GNUNET_MESSAGE_TYPE_REVOCATION_QUERY_RESPONSE
Service to client: answer if key was revoked!
Key revocation response.
Definition: revocation.h:59
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
A 512-bit hashcode.
static int res
uint32_t is_valid
GNUNET_NO if revoked, GNUNET_YES if valid.
Definition: revocation.h:69
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
An identity key as per LSD0001.
#define GNUNET_log(kind,...)
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:355
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2244
Here is the call graph for this function:

◆ do_flood()

static int do_flood ( void *  cls,
const struct GNUNET_PeerIdentity target,
void *  value 
)
static

Flood the given revocation message to all neighbours.

Parameters
clsthe struct RevokeMessage to flood
targeta neighbour
valueour struct PeerEntry for the neighbour
Returns
GNUNET_OK (continue to iterate)

Definition at line 267 of file gnunet-service-revocation.c.

References e, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_OK, PeerEntry::mq, RevokeMessage::pow_size, and value.

Referenced by publicize_rm().

270 {
271  const struct RevokeMessage *rm = cls;
272  struct PeerEntry *pe = value;
273  struct GNUNET_MQ_Envelope *e;
274  struct RevokeMessage *cp;
275 
276  if (NULL == pe->mq)
277  return GNUNET_OK; /* peer connected to us via SET,
278  but we have no direct CORE
279  connection for flooding */
280  e = GNUNET_MQ_msg_extra (cp,
281  htonl (rm->pow_size),
283  *cp = *rm;
284  memcpy (&cp[1], &rm[1], htonl (rm->pow_size));
286  "Flooding revocation to `%s'\n",
287  GNUNET_i2s (target));
288  GNUNET_MQ_send (pe->mq,
289  e);
290  return GNUNET_OK;
291 }
Per-peer information.
static struct Experiment * e
uint32_t pow_size
Length of PoW with signature.
Definition: revocation.h:90
#define GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE
Client to service OR peer-to-peer: revoke this key!
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
Revoke key.
Definition: revocation.h:80
static char * value
Value of the record to add/remove.
struct GNUNET_MQ_Handle * mq
Queue for sending messages to this peer.
#define GNUNET_log(kind,...)
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:355
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ publicize_rm()

static int publicize_rm ( const struct RevokeMessage rm)
static

Publicize revocation message.

Stores the message locally in the database and passes it to all connected neighbours (and adds it to the set for future connections).

Parameters
rmmessage to publicize
Returns
GNUNET_OK on success, GNUNET_NO if we encountered an error, GNUNET_SYSERR if the message was malformed

Definition at line 304 of file gnunet-service-revocation.c.

References GNUNET_SETU_Element::data, do_flood(), GNUNET_SETU_Element::element_type, GNUNET_BLOCK_TYPE_REVOCATION, GNUNET_break, GNUNET_break_op, GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_copy_message(), GNUNET_CRYPTO_hash(), GNUNET_DISK_file_sync(), GNUNET_DISK_file_write(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_IDENTITY_key_get_length(), GNUNET_log, GNUNET_log_strerror, GNUNET_NO, GNUNET_OK, GNUNET_SETU_add_element(), GNUNET_SYSERR, GNUNET_YES, RevokeMessage::header, pk, GNUNET_REVOCATION_PowP::pow, GNUNET_SETU_Element::size, GNUNET_MessageHeader::size, and verify_revoke_message().

Referenced by handle_p2p_revoke(), and handle_revoke_message().

305 {
306  struct RevokeMessage *cp;
307  struct GNUNET_HashCode hc;
308  struct GNUNET_SETU_Element e;
309  ssize_t pklen;
310  const struct GNUNET_IDENTITY_PublicKey *pk;
311 
312  struct GNUNET_REVOCATION_PowP *pow = (struct GNUNET_REVOCATION_PowP *) &rm[1];
313  pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1];
314  pklen = GNUNET_IDENTITY_key_get_length (pk);
315  if (0 > pklen)
316  {
317  GNUNET_break_op (0);
318  return GNUNET_SYSERR;
319  }
320  GNUNET_CRYPTO_hash (pk,
321  pklen,
322  &hc);
323  if (GNUNET_YES ==
325  &hc))
326  {
328  "Duplicate revocation received from peer. Ignored.\n");
329  return GNUNET_OK;
330  }
331  if (GNUNET_OK !=
333  {
334  GNUNET_break_op (0);
335  return GNUNET_SYSERR;
336  }
337  /* write to disk */
338  if (sizeof(struct RevokeMessage) !=
340  rm,
341  sizeof(struct RevokeMessage)))
342  {
344  "write");
345  return GNUNET_NO;
346  }
347  if (GNUNET_OK !=
349  {
351  "sync");
352  return GNUNET_NO;
353  }
354  /* keep copy in memory */
355  cp = (struct RevokeMessage *) GNUNET_copy_message (&rm->header);
358  &hc,
359  cp,
361  /* add to set for future connections */
362  e.size = htons (rm->header.size);
363  e.element_type = GNUNET_BLOCK_TYPE_REVOCATION;
364  e.data = rm;
365  if (GNUNET_OK !=
367  &e,
368  NULL,
369  NULL))
370  {
371  GNUNET_break (0);
372  return GNUNET_OK;
373  }
374  else
375  {
377  "Added revocation info to SET\n");
378  }
379  /* flood to neighbours */
381  &do_flood,
382  cp);
383  return GNUNET_OK;
384 }
static int do_flood(void *cls, const struct GNUNET_PeerIdentity *target, void *value)
Flood the given revocation message to all neighbours.
static int verify_revoke_message(const struct RevokeMessage *rm)
An revoke message has been received, check that it is well-formed.
Block type for a revocation message by which a key is revoked.
Struct for a proof of work as part of the revocation.
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
static struct GNUNET_CONTAINER_MultiHashMap * revocation_map
Hash map with all revoked keys, maps the hash of the public key to the respective struct RevokeMessag...
static struct GNUNET_CONTAINER_MultiPeerMap * peers
Map of all connected peers.
static struct Experiment * e
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
int GNUNET_CONTAINER_multihashmap_contains(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Check if the map contains any value under the given key (including values that are NULL)...
static struct GNUNET_DISK_FileHandle * revocation_db
File handle for the revocation database.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
Revoke key.
Definition: revocation.h:80
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
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_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:686
A 512-bit hashcode.
uint64_t pow[32]
The PoWs.
There must only be one value per key; storing a value should fail if a value under the same key alrea...
int GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE.
Definition: revocation.h:85
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
An identity key as per LSD0001.
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_sync(const struct GNUNET_DISK_FileHandle *h)
Write file changes to disk.
Definition: disk.c:1402
#define GNUNET_log(kind,...)
int GNUNET_SETU_add_element(struct GNUNET_SETU_Handle *set, const struct GNUNET_SETU_Element *element, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Add an element to the given set.
Definition: setu_api.c:428
static struct GNUNET_SETU_Handle * revocation_set
Set from all revocations known to us.
struct GNUNET_MessageHeader * GNUNET_copy_message(const struct GNUNET_MessageHeader *msg)
Create a copy of the given message.
Element stored in a set.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_revoke_message()

static int check_revoke_message ( void *  cls,
const struct RevokeMessage rm 
)
static

Definition at line 388 of file gnunet-service-revocation.c.

References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, RevokeMessage::header, size, and GNUNET_MessageHeader::size.

390 {
391  uint16_t size;
392 
393  size = ntohs (rm->header.size);
394  if (size <= sizeof(struct RevokeMessage) ||
395  (size > UINT16_MAX))
396  {
397  GNUNET_break (0);
398  return GNUNET_SYSERR;
399  }
400  return GNUNET_OK;
401 
402 }
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Revoke key.
Definition: revocation.h:80
static unsigned int size
Size of the "table".
Definition: peer.c:67
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE.
Definition: revocation.h:85

◆ handle_revoke_message()

static void handle_revoke_message ( void *  cls,
const struct RevokeMessage rm 
)
static

Handle REVOKE message from client.

Parameters
clsclient who sent the message
rmthe message received

Definition at line 412 of file gnunet-service-revocation.c.

References env, GNUNET_break_op, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_NO, GNUNET_OK, GNUNET_SERVICE_client_continue(), GNUNET_SERVICE_client_drop(), GNUNET_SERVICE_client_get_mq(), GNUNET_SYSERR, GNUNET_YES, RevocationResponseMessage::is_valid, publicize_rm(), and ret.

414 {
415  struct GNUNET_SERVICE_Client *client = cls;
416  struct GNUNET_MQ_Envelope *env;
417  struct RevocationResponseMessage *rrm;
418  int ret;
419 
421  "Received REVOKE message from client\n");
422  if (GNUNET_SYSERR == (ret = publicize_rm (rm)))
423  {
424  GNUNET_break_op (0);
426  return;
427  }
428  env = GNUNET_MQ_msg (rrm,
430  rrm->is_valid = htonl ((GNUNET_OK == ret) ? GNUNET_NO : GNUNET_YES);
432  env);
434 }
struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq(struct GNUNET_SERVICE_Client *c)
Obtain the message queue of c.
Definition: service.c:2438
static int publicize_rm(const struct RevokeMessage *rm)
Publicize revocation message.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
Handle to a client that is connected to a service.
Definition: service.c:250
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE
Service to client: revocation confirmed.
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition: service.c:2325
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
Key revocation response.
Definition: revocation.h:99
#define GNUNET_log(kind,...)
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:355
uint32_t is_valid
GNUNET_NO if revocation failed for internal reasons (e.g.
Definition: revocation.h:110
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2244
Here is the call graph for this function:

◆ check_p2p_revoke()

static int check_p2p_revoke ( void *  cls,
const struct RevokeMessage rm 
)
static

Definition at line 438 of file gnunet-service-revocation.c.

References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, RevokeMessage::header, size, and GNUNET_MessageHeader::size.

440 {
441  uint16_t size;
442 
443  size = ntohs (rm->header.size);
444  if (size <= sizeof(struct RevokeMessage))
445  {
446  GNUNET_break (0);
447  return GNUNET_SYSERR;
448  }
449  return GNUNET_OK;
450 
451 }
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Revoke key.
Definition: revocation.h:80
static unsigned int size
Size of the "table".
Definition: peer.c:67
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE.
Definition: revocation.h:85

◆ handle_p2p_revoke()

static void handle_p2p_revoke ( void *  cls,
const struct RevokeMessage rm 
)
static

Core handler for flooded revocation messages.

Parameters
clsclosure unused
rmrevocation message

Definition at line 461 of file gnunet-service-revocation.c.

References GNUNET_break_op, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_SYSERR, and publicize_rm().

Referenced by add_revocation().

463 {
465  "Received REVOKE message\n");
467  publicize_rm (rm));
468 }
static int publicize_rm(const struct RevokeMessage *rm)
Publicize revocation message.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_log(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_revocation()

static void add_revocation ( void *  cls,
const struct GNUNET_SETU_Element element,
uint64_t  current_size,
enum GNUNET_SETU_Status  status 
)
static

Callback for set operation results.

Called for each element in the result set. Each element contains a revocation, which we should validate and then add to our revocation list (and set).

Parameters
clsclosure
elementa result element, only valid if status is #GNUNET_SETU_STATUS_OK
current_sizecurrent set size
statussee enum GNUNET_SETU_Status

Definition at line 482 of file gnunet-service-revocation.c.

References _, GNUNET_SETU_Element::data, GNUNET_SETU_Element::element_type, gettext_noop, GNUNET_BLOCK_TYPE_REVOCATION, GNUNET_break, GNUNET_break_op, GNUNET_ERROR_TYPE_WARNING, GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_SETU_STATUS_ADD_LOCAL, GNUNET_SETU_STATUS_DONE, GNUNET_SETU_STATUS_FAILURE, GNUNET_STATISTICS_update(), handle_p2p_revoke(), PeerEntry::id, GNUNET_SETU_Element::size, and PeerEntry::so.

Referenced by handle_revocation_union_request().

486 {
487  struct PeerEntry *peer_entry = cls;
488  const struct RevokeMessage *rm;
489 
490  switch (status)
491  {
493  if (element->size != sizeof(struct RevokeMessage))
494  {
495  GNUNET_break_op (0);
496  return;
497  }
499  {
501  gettext_noop (
502  "# unsupported revocations received via set union"),
503  1,
504  GNUNET_NO);
505  return;
506  }
507  rm = element->data;
508  (void) handle_p2p_revoke (NULL,
509  rm);
511  gettext_noop (
512  "# revocation messages received via set union"),
513  1, GNUNET_NO);
514  break;
517  _ ("Error computing revocation set union with %s\n"),
518  GNUNET_i2s (&peer_entry->id));
519  peer_entry->so = NULL;
521  gettext_noop ("# revocation set unions failed"),
522  1,
523  GNUNET_NO);
524  break;
526  peer_entry->so = NULL;
528  gettext_noop (
529  "# revocation set unions completed"),
530  1,
531  GNUNET_NO);
532  break;
533  default:
534  GNUNET_break (0);
535  break;
536  }
537 }
static void handle_p2p_revoke(void *cls, const struct RevokeMessage *rm)
Core handler for flooded revocation messages.
Per-peer information.
const void * data
Actual data of the element.
struct GNUNET_SETU_OperationHandle * so
Handle to active set union operation (over revocation sets).
Block type for a revocation message by which a key is revoked.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
The other peer refused to do the operation with us, or something went wrong.
Revoke key.
Definition: revocation.h:80
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
Success, all elements have been sent (and received).
uint16_t element_type
Application-specific element type.
Element should be added to the result set of the local peer, i.e.
uint16_t status
See PRISM_STATUS_*-constants.
#define GNUNET_log(kind,...)
struct GNUNET_PeerIdentity id
What is the identity of the peer?
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
uint16_t size
Number of bytes in the buffer pointed to by data.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ transmit_task_cb()

static void transmit_task_cb ( void *  cls)
static

The timeout for performing the set union has expired, run the set operation on the revocation certificates.

Parameters
clsNULL

Definition at line 547 of file gnunet-service-revocation.c.

References GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_SETU_prepare(), PeerEntry::id, revocation_set_union_app_id, PeerEntry::so, and PeerEntry::transmit_task.

Referenced by handle_core_connect().

548 {
549  struct PeerEntry *peer_entry = cls;
550 
552  "Starting set exchange with peer `%s'\n",
553  GNUNET_i2s (&peer_entry->id));
554  peer_entry->transmit_task = NULL;
555  GNUNET_assert (NULL == peer_entry->so);
556  peer_entry->so = GNUNET_SETU_prepare (&peer_entry->id,
558  NULL,
559  (struct GNUNET_SETU_Option[]) { { 0 } },
561  peer_entry);
562  if (GNUNET_OK !=
563  GNUNET_SETU_commit (peer_entry->so,
565  {
567  _ ("SET service crashed, terminating revocation service\n"));
569  return;
570  }
571 }
struct GNUNET_SETU_OperationHandle * GNUNET_SETU_prepare(const struct GNUNET_PeerIdentity *other_peer, const struct GNUNET_HashCode *app_id, const struct GNUNET_MessageHeader *context_msg, const struct GNUNET_SETU_Option options[], GNUNET_SETU_ResultIterator result_cb, void *result_cls)
Prepare a set operation to be evaluated with another peer.
Definition: setu_api.c:508
int GNUNET_SETU_commit(struct GNUNET_SETU_OperationHandle *oh, struct GNUNET_SETU_Handle *set)
Commit a set to be used with a set operation.
Definition: setu_api.c:837
Per-peer information.
struct GNUNET_SETU_OperationHandle * so
Handle to active set union operation (over revocation sets).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Option for set operations.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
static struct GNUNET_HashCode revocation_set_union_app_id
Our application ID for set union operations.
struct GNUNET_SCHEDULER_Task * transmit_task
Tasked used to trigger the set union operation.
static void add_revocation(void *cls, const struct GNUNET_SETU_Element *element, uint64_t current_size, enum GNUNET_SETU_Status status)
Callback for set operation results.
#define GNUNET_log(kind,...)
static struct GNUNET_SETU_Handle * revocation_set
Set from all revocations known to us.
struct GNUNET_PeerIdentity id
What is the identity of the peer?
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_core_connect()

static void* handle_core_connect ( void *  cls,
const struct GNUNET_PeerIdentity peer,
struct GNUNET_MQ_Handle mq 
)
static

Method called whenever a peer connects.

Sets up the PeerEntry and schedules the initial revocation set exchange with this peer.

Parameters
clsclosure
peerpeer identity this notification is about

Definition at line 582 of file gnunet-service-revocation.c.

References GNUNET_CONTAINER_multipeermap_get(), GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_hash_cmp(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_memcmp, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_STATISTICS_update(), GNUNET_TIME_UNIT_SECONDS, PeerEntry::mq, my_identity, new_peer_entry(), PeerEntry::transmit_task, and transmit_task_cb().

Referenced by run().

585 {
586  struct PeerEntry *peer_entry;
587  struct GNUNET_HashCode my_hash;
588  struct GNUNET_HashCode peer_hash;
589 
590  if (0 == GNUNET_memcmp (peer,
591  &my_identity))
592  {
593  return NULL;
594  }
595 
597  "Peer `%s' connected to us\n",
598  GNUNET_i2s (peer));
600  "# peers connected",
601  1,
602  GNUNET_NO);
604  peer);
605  if (NULL != peer_entry)
606  {
607  /* This can happen if "core"'s notification is a tad late
608  and CADET+SET were faster and already produced a
609  #handle_revocation_union_request() for us to deal
610  with. This should be rare, but isn't impossible. */
611  peer_entry->mq = mq;
612  return peer_entry;
613  }
614  peer_entry = new_peer_entry (peer);
615  peer_entry->mq = mq;
617  sizeof(my_identity),
618  &my_hash);
619  GNUNET_CRYPTO_hash (peer,
620  sizeof(*peer),
621  &peer_hash);
622  if (0 < GNUNET_CRYPTO_hash_cmp (&my_hash,
623  &peer_hash))
624  {
626  "Starting SET operation with peer `%s'\n",
627  GNUNET_i2s (peer));
628  peer_entry->transmit_task =
631  peer_entry);
632  }
633  return peer_entry;
634 }
Per-peer information.
#define GNUNET_TIME_UNIT_SECONDS
One second.
static struct GNUNET_CONTAINER_MultiPeerMap * peers
Map of all connected peers.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
static void transmit_task_cb(void *cls)
The timeout for performing the set union has expired, run the set operation on the revocation certifi...
static struct GNUNET_PeerIdentity my_identity
The peer identity of this peer.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1269
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
A 512-bit hashcode.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
struct GNUNET_MQ_Handle * mq
Queue for sending messages to this peer.
struct GNUNET_SCHEDULER_Task * transmit_task
Tasked used to trigger the set union operation.
static struct PeerEntry * new_peer_entry(const struct GNUNET_PeerIdentity *peer)
Create a new PeerEntry and add it to the peers multipeermap.
int GNUNET_CRYPTO_hash_cmp(const struct GNUNET_HashCode *h1, const struct GNUNET_HashCode *h2)
Compare function for HashCodes, producing a total ordering of all hashcodes.
Definition: crypto_hash.c:201
void * GNUNET_CONTAINER_multipeermap_get(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Given a key find a value in the map matching the key.
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
#define GNUNET_log(kind,...)
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_core_disconnect()

static void handle_core_disconnect ( void *  cls,
const struct GNUNET_PeerIdentity peer,
void *  internal_cls 
)
static

Method called whenever a peer disconnects.

Deletes the PeerEntry and cancels any pending transmission requests to that peer.

Parameters
clsclosure
peerpeer identity this notification is about
internal_clsour struct PeerEntry for this peer

Definition at line 646 of file gnunet-service-revocation.c.

References GNUNET_assert, GNUNET_CONTAINER_multipeermap_remove(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_memcmp, GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_SETU_operation_cancel(), GNUNET_STATISTICS_update(), GNUNET_YES, my_identity, PeerEntry::so, and PeerEntry::transmit_task.

Referenced by run().

649 {
650  struct PeerEntry *peer_entry = internal_cls;
651 
652  if (0 == GNUNET_memcmp (peer,
653  &my_identity))
654  return;
655  GNUNET_assert (NULL != peer_entry);
657  "Peer `%s' disconnected from us\n",
658  GNUNET_i2s (peer));
661  peer,
662  peer_entry));
663  if (NULL != peer_entry->transmit_task)
664  {
666  peer_entry->transmit_task = NULL;
667  }
668  if (NULL != peer_entry->so)
669  {
670  GNUNET_SETU_operation_cancel (peer_entry->so);
671  peer_entry->so = NULL;
672  }
673  GNUNET_free (peer_entry);
675  "# peers connected",
676  -1,
677  GNUNET_NO);
678 }
Per-peer information.
struct GNUNET_SETU_OperationHandle * so
Handle to active set union operation (over revocation sets).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_CONTAINER_MultiPeerMap * peers
Map of all connected peers.
int GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
static struct GNUNET_PeerIdentity my_identity
The peer identity of this peer.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
struct GNUNET_SCHEDULER_Task * transmit_task
Tasked used to trigger the set union operation.
void GNUNET_SETU_operation_cancel(struct GNUNET_SETU_OperationHandle *oh)
Cancel the given set operation.
Definition: setu_api.c:319
#define GNUNET_log(kind,...)
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_entry()

static int free_entry ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Free all values in a hash map.

Parameters
clsNULL
keythe key
valuevalue to free
Returns
GNUNET_OK (continue to iterate)

Definition at line 690 of file gnunet-service-revocation.c.

References GNUNET_free, and GNUNET_OK.

Referenced by shutdown_task().

693 {
694  GNUNET_free (value);
695  return GNUNET_OK;
696 }
static char * value
Value of the record to add/remove.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ shutdown_task()

static void shutdown_task ( void *  cls)
static

Task run during shutdown.

Parameters
clsunused

Definition at line 705 of file gnunet-service-revocation.c.

References free_entry(), GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CORE_disconnect(), GNUNET_DISK_file_close(), GNUNET_NO, GNUNET_SETU_destroy(), GNUNET_SETU_listen_cancel(), and GNUNET_STATISTICS_destroy().

Referenced by run().

706 {
707  if (NULL != revocation_set)
708  {
710  revocation_set = NULL;
711  }
712  if (NULL != revocation_union_listen_handle)
713  {
716  }
717  if (NULL != core_api)
718  {
720  core_api = NULL;
721  }
722  if (NULL != stats)
723  {
725  stats = NULL;
726  }
727  if (NULL != peers)
728  {
730  peers = NULL;
731  }
732  if (NULL != revocation_db)
733  {
735  revocation_db = NULL;
736  }
738  &free_entry,
739  NULL);
741 }
static struct GNUNET_SETU_ListenHandle * revocation_union_listen_handle
Handle for us listening to incoming revocation set union requests.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1283
static struct GNUNET_CONTAINER_MultiHashMap * revocation_map
Hash map with all revoked keys, maps the hash of the public key to the respective struct RevokeMessag...
static struct GNUNET_CONTAINER_MultiPeerMap * peers
Map of all connected peers.
static struct GNUNET_DISK_FileHandle * revocation_db
File handle for the revocation database.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
static int free_entry(void *cls, const struct GNUNET_HashCode *key, void *value)
Free all values in a hash map.
static struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
void GNUNET_CORE_disconnect(struct GNUNET_CORE_Handle *handle)
Disconnect from the core service.
Definition: core_api.c:730
void GNUNET_SETU_destroy(struct GNUNET_SETU_Handle *set)
Destroy the set handle, and free all associated resources.
Definition: setu_api.c:470
void GNUNET_SETU_listen_cancel(struct GNUNET_SETU_ListenHandle *lh)
Cancel the given listen operation.
Definition: setu_api.c:740
static struct GNUNET_CORE_Handle * core_api
Handle to the core service (for flooding)
static struct GNUNET_SETU_Handle * revocation_set
Set from all revocations known to us.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ core_init()

static void core_init ( void *  cls,
const struct GNUNET_PeerIdentity identity 
)
static

Called on core init/fail.

Parameters
clsservice closure
identitythe public identity of this peer

Definition at line 751 of file gnunet-service-revocation.c.

References GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_SCHEDULER_shutdown(), identity, and my_identity.

Referenced by run().

753 {
754  if (NULL == identity)
755  {
757  "Connection to core FAILED!\n");
759  return;
760  }
762 }
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531
static struct GNUNET_PeerIdentity my_identity
The peer identity of this peer.
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
#define GNUNET_log(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_revocation_union_request()

static void handle_revocation_union_request ( void *  cls,
const struct GNUNET_PeerIdentity other_peer,
const struct GNUNET_MessageHeader context_msg,
struct GNUNET_SETU_Request request 
)
static

Called when another peer wants to do a set operation with the local peer.

If a listen error occurs, the 'request' is NULL.

Parameters
clsclosure
other_peerthe other peer
context_msgmessage with application specific information from the other peer
requestrequest from the other peer (never NULL), use GNUNET_SETU_accept() to accept it, otherwise the request will be refused Note that we can't just return value from the listen callback, as it is also necessary to specify the set we want to do the operation with, which sometimes can be derived from the context message. It's necessary to specify the timeout.

Definition at line 781 of file gnunet-service-revocation.c.

References add_revocation(), GNUNET_break, GNUNET_break_op, GNUNET_CONTAINER_multipeermap_get(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_OK, GNUNET_SCHEDULER_shutdown(), GNUNET_SETU_accept(), GNUNET_SETU_commit(), new_peer_entry(), and PeerEntry::so.

Referenced by run().

785 {
786  struct PeerEntry *peer_entry;
787 
788  if (NULL == request)
789  {
790  GNUNET_break (0);
791  return;
792  }
794  "Received set exchange request from peer `%s'\n",
795  GNUNET_i2s (other_peer));
797  other_peer);
798  if (NULL == peer_entry)
799  {
800  peer_entry = new_peer_entry (other_peer);
801  }
802  if (NULL != peer_entry->so)
803  {
804  GNUNET_break_op (0);
805  return;
806  }
807  peer_entry->so = GNUNET_SETU_accept (request,
808  (struct GNUNET_SETU_Option[]) { { 0 } },
810  peer_entry);
811  if (GNUNET_OK !=
812  GNUNET_SETU_commit (peer_entry->so,
814  {
815  GNUNET_break (0);
817  return;
818  }
819 }
int GNUNET_SETU_commit(struct GNUNET_SETU_OperationHandle *oh, struct GNUNET_SETU_Handle *set)
Commit a set to be used with a set operation.
Definition: setu_api.c:837
Per-peer information.
struct GNUNET_SETU_OperationHandle * so
Handle to active set union operation (over revocation sets).
Option for set operations.
static struct GNUNET_CONTAINER_MultiPeerMap * peers
Map of all connected peers.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
struct GNUNET_SETU_OperationHandle * GNUNET_SETU_accept(struct GNUNET_SETU_Request *request, const struct GNUNET_SETU_Option options[], GNUNET_SETU_ResultIterator result_cb, void *result_cls)
Accept a request we got via GNUNET_SETU_listen().
Definition: setu_api.c:774
static struct PeerEntry * new_peer_entry(const struct GNUNET_PeerIdentity *peer)
Create a new PeerEntry and add it to the peers multipeermap.
static void add_revocation(void *cls, const struct GNUNET_SETU_Element *element, uint64_t current_size, enum GNUNET_SETU_Status status)
Callback for set operation results.
void * GNUNET_CONTAINER_multipeermap_get(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Given a key find a value in the map matching the key.
#define GNUNET_log(kind,...)
static struct GNUNET_SETU_Handle * revocation_set
Set from all revocations known to us.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
const struct GNUNET_CONFIGURATION_Handle c,
struct GNUNET_SERVICE_Handle service 
)
static

Handle network size estimate clients.

Parameters
clsclosure
serverthe initialized server
cconfiguration to use

Definition at line 830 of file gnunet-service-revocation.c.

References _, __attribute__, client_connect_cb(), client_disconnect_cb(), core_init(), epoch_duration, fn, GNUNET_break, GNUNET_break_op, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_time(), GNUNET_CONTAINER_multihashmap_create(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multipeermap_create(), GNUNET_CORE_connect(), GNUNET_CRYPTO_hash(), GNUNET_DISK_file_open(), GNUNET_DISK_file_read(), GNUNET_DISK_file_size(), GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_OPEN_READWRITE, GNUNET_DISK_PERM_GROUP_READ, GNUNET_DISK_PERM_OTHER_READ, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_IDENTITY_key_get_length(), GNUNET_log_config_invalid(), GNUNET_log_config_missing(), GNUNET_log_strerror_file, GNUNET_MESSAGE_TYPE_REVOCATION_QUERY, GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), GNUNET_SERVICE_MAIN(), GNUNET_SERVICE_OPTION_NONE, GNUNET_SETU_create(), GNUNET_SETU_listen(), GNUNET_STATISTICS_create(), GNUNET_YES, handle_core_connect(), handle_core_disconnect(), handle_revocation_union_request(), pk, GNUNET_REVOCATION_PowP::pow, revocation_set_union_app_id, revocation_work_required, and shutdown_task().

833 {
834  struct GNUNET_MQ_MessageHandler core_handlers[] = {
835  GNUNET_MQ_hd_var_size (p2p_revoke,
837  struct RevokeMessage,
838  NULL),
840  };
841  char *fn;
842  uint64_t left;
843  struct RevokeMessage *rm;
844  struct GNUNET_HashCode hc;
845  const struct GNUNET_IDENTITY_PublicKey *pk;
846 
847  GNUNET_CRYPTO_hash ("revocation-set-union-application-id",
848  strlen ("revocation-set-union-application-id"),
850  if (GNUNET_OK !=
852  "REVOCATION",
853  "DATABASE",
854  &fn))
855  {
857  "REVOCATION",
858  "DATABASE");
860  return;
861  }
862  cfg = c;
864  GNUNET_NO);
865  if (GNUNET_OK !=
867  "REVOCATION",
868  "WORKBITS",
870  {
872  "REVOCATION",
873  "WORKBITS");
875  GNUNET_free (fn);
876  return;
877  }
878  if (revocation_work_required >= sizeof(struct GNUNET_HashCode) * 8)
879  {
881  "REVOCATION",
882  "WORKBITS",
883  _ ("Value is too large.\n"));
885  GNUNET_free (fn);
886  return;
887  }
888  if (GNUNET_OK !=
890  "REVOCATION",
891  "EPOCH_DURATION",
892  &epoch_duration))
893  {
895  "REVOCATION",
896  "EPOCH_DURATION");
898  GNUNET_free (fn);
899  return;
900  }
901 
907  NULL);
915  if (NULL == revocation_db)
916  {
918  "REVOCATION",
919  "DATABASE",
920  _ ("Could not open revocation database file!"));
922  GNUNET_free (fn);
923  return;
924  }
925  if (GNUNET_OK !=
927  left = 0;
928  while (left > sizeof(struct RevokeMessage))
929  {
930  rm = GNUNET_new (struct RevokeMessage);
931  if (sizeof(struct RevokeMessage) !=
933  rm,
934  sizeof(struct RevokeMessage)))
935  {
937  "read",
938  fn);
939  GNUNET_free (rm);
941  GNUNET_free (fn);
942  return;
943  }
944  struct GNUNET_REVOCATION_PowP *pow = (struct
945  GNUNET_REVOCATION_PowP *) &rm[1];
946  ssize_t ksize;
947  pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1];
948  ksize = GNUNET_IDENTITY_key_get_length (pk);
949  if (0 > ksize)
950  {
951  GNUNET_break_op (0);
952  GNUNET_free (fn);
953  return;
954  }
955  GNUNET_CRYPTO_hash (pk,
956  ksize,
957  &hc);
960  &hc,
961  rm,
963  }
964  GNUNET_free (fn);
965 
967  NULL);
969  GNUNET_YES);
970  /* Connect to core service and register core handlers */
971  core_api = GNUNET_CORE_connect (cfg, /* Main configuration */
972  NULL, /* Closure passed to functions */
973  &core_init, /* Call core_init once connected */
974  &handle_core_connect, /* Handle connects */
975  &handle_core_disconnect, /* Handle disconnects */
976  core_handlers); /* Register these handlers */
977  if (NULL == core_api)
978  {
980  return;
981  }
982  stats = GNUNET_STATISTICS_create ("revocation",
983  cfg);
984 }
static void shutdown_task(void *cls)
Task run during shutdown.
static struct GNUNET_SETU_ListenHandle * revocation_union_listen_handle
Handle for us listening to incoming revocation set union requests.
Create file if it doesn&#39;t exist.
static void * handle_core_connect(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Method called whenever a peer connects.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Handle to our current configuration.
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:622
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1331
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
Struct for a proof of work as part of the revocation.
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
static struct GNUNET_CONTAINER_MultiHashMap * revocation_map
Hash map with all revoked keys, maps the hash of the public key to the respective struct RevokeMessag...
static struct GNUNET_CONTAINER_MultiPeerMap * peers
Map of all connected peers.
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.
static void core_init(void *cls, const struct GNUNET_PeerIdentity *identity)
Called on core init/fail.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
void GNUNET_log_config_invalid(enum GNUNET_ErrorType kind, const char *section, const char *option, const char *required)
Log error message about invalid configuration option value.
static struct GNUNET_DISK_FileHandle * revocation_db
File handle for the revocation database.
struct GNUNET_CONTAINER_MultiPeerMap * GNUNET_CONTAINER_multipeermap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531
struct GNUNET_SETU_Handle * GNUNET_SETU_create(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create an empty set, supporting the specified operation.
Definition: setu_api.c:383
#define GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE
Client to service OR peer-to-peer: revoke this key!
static struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
Revoke key.
Definition: revocation.h:80
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
static char * fn
Filename of the unique file.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
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
A 512-bit hashcode.
Message handler for a specific message type.
static struct GNUNET_HashCode revocation_set_union_app_id
Our application ID for set union operations.
uint64_t pow[32]
The PoWs.
There must only be one value per key; storing a value should fail if a value under the same key alrea...
struct GNUNET_SETU_ListenHandle * GNUNET_SETU_listen(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_HashCode *app_id, GNUNET_SETU_ListenCallback listen_cb, void *listen_cls)
Wait for set operation requests for the given application ID.
Definition: setu_api.c:708
struct GNUNET_CORE_Handle * GNUNET_CORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, GNUNET_CORE_StartupCallback init, GNUNET_CORE_ConnectEventHandler connects, GNUNET_CORE_DisconnectEventHandler disconnects, const struct GNUNET_MQ_MessageHandler *handlers)
Connect to the core service.
Definition: core_api.c:692
int GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_size(const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode)
Get the size of the file (or directory) of the given file (in bytes).
Definition: disk.c:222
Everybody can read.
static unsigned long long revocation_work_required
Amount of work required (W-bit collisions) for REVOCATION proofs, in collision-bits.
An identity key as per LSD0001.
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
static struct GNUNET_TIME_Relative epoch_duration
Length of an expiration expoch.
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.
Open the file for both reading and writing.
static void handle_revocation_union_request(void *cls, const struct GNUNET_PeerIdentity *other_peer, const struct GNUNET_MessageHeader *context_msg, struct GNUNET_SETU_Request *request)
Called when another peer wants to do a set operation with the local peer.
static void handle_core_disconnect(void *cls, const struct GNUNET_PeerIdentity *peer, void *internal_cls)
Method called whenever a peer disconnects.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
static struct GNUNET_CORE_Handle * core_api
Handle to the core service (for flooding)
static struct GNUNET_SETU_Handle * revocation_set
Set from all revocations known to us.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1212
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

◆ GNUNET_SERVICE_MAIN()

GNUNET_SERVICE_MAIN ( "revocation"  ,
GNUNET_SERVICE_OPTION_NONE  ,
run,
client_connect_cb,
client_disconnect_cb,
NULL  ,
GNUNET_MQ_hd_fixed_size(query_message, GNUNET_MESSAGE_TYPE_REVOCATION_QUERY, struct QueryMessage, NULL)  ,
GNUNET_MQ_hd_var_size(revoke_message, GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE, struct RevokeMessage, NULL)  ,
GNUNET_MQ_handler_end()   
)

Define "main" method using service macro.

Referenced by run().

Here is the caller graph for this function:

Variable Documentation

◆ revocation_set

struct GNUNET_SETU_Handle* revocation_set
static

Set from all revocations known to us.

Definition at line 83 of file gnunet-service-revocation.c.

◆ revocation_map

struct GNUNET_CONTAINER_MultiHashMap* revocation_map
static

Hash map with all revoked keys, maps the hash of the public key to the respective struct RevokeMessage.

Definition at line 89 of file gnunet-service-revocation.c.

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg
static

Handle to our current configuration.

Definition at line 94 of file gnunet-service-revocation.c.

◆ stats

struct GNUNET_STATISTICS_Handle* stats
static

Handle to the statistics service.

Definition at line 99 of file gnunet-service-revocation.c.

◆ core_api

struct GNUNET_CORE_Handle* core_api
static

Handle to the core service (for flooding)

Definition at line 104 of file gnunet-service-revocation.c.

◆ peers

struct GNUNET_CONTAINER_MultiPeerMap* peers
static

Map of all connected peers.

Definition at line 109 of file gnunet-service-revocation.c.

◆ my_identity

struct GNUNET_PeerIdentity my_identity
static

The peer identity of this peer.

Definition at line 114 of file gnunet-service-revocation.c.

Referenced by core_init(), handle_core_connect(), and handle_core_disconnect().

◆ revocation_db

struct GNUNET_DISK_FileHandle* revocation_db
static

File handle for the revocation database.

Definition at line 119 of file gnunet-service-revocation.c.

◆ revocation_union_listen_handle

struct GNUNET_SETU_ListenHandle* revocation_union_listen_handle
static

Handle for us listening to incoming revocation set union requests.

Definition at line 124 of file gnunet-service-revocation.c.

◆ revocation_work_required

unsigned long long revocation_work_required
static

Amount of work required (W-bit collisions) for REVOCATION proofs, in collision-bits.

Definition at line 129 of file gnunet-service-revocation.c.

Referenced by run(), and verify_revoke_message().

◆ epoch_duration

struct GNUNET_TIME_Relative epoch_duration
static

Length of an expiration expoch.

Definition at line 134 of file gnunet-service-revocation.c.

Referenced by run(), and verify_revoke_message().

◆ revocation_set_union_app_id

struct GNUNET_HashCode revocation_set_union_app_id
static

Our application ID for set union operations.

Must be the same for all (compatible) peers.

Definition at line 140 of file gnunet-service-revocation.c.

Referenced by run(), and transmit_task_cb().