GNUnet  0.11.x
Data Structures | Typedefs | Functions
gnunet-service-messenger_ego_store.h File Reference

GNUnet MESSENGER service. More...

#include "platform.h"
#include "gnunet_container_lib.h"
#include "messenger_api_ego.h"
Include dependency graph for gnunet-service-messenger_ego_store.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  GNUNET_MESSENGER_EgoLookup
 
struct  GNUNET_MESSENGER_EgoOperation
 
struct  GNUNET_MESSENGER_EgoStore
 

Typedefs

typedef void(* GNUNET_MESSENGER_EgoLookupCallback) (void *cls, const char *identifier, const struct GNUNET_MESSENGER_Ego *ego)
 

Functions

void init_ego_store (struct GNUNET_MESSENGER_EgoStore *store, const struct GNUNET_CONFIGURATION_Handle *config)
 Initializes an EGO-store as fully empty. More...
 
void clear_ego_store (struct GNUNET_MESSENGER_EgoStore *store)
 Clears an EGO-store, wipes its content and deallocates its memory. More...
 
void create_store_ego (struct GNUNET_MESSENGER_EgoStore *store, const char *identifier, void *handle)
 Creates a new EGO which will be registered to a store under a specific identifier. More...
 
void lookup_store_ego (struct GNUNET_MESSENGER_EgoStore *store, const char *identifier, GNUNET_MESSENGER_EgoLookupCallback lookup, void *cls)
 Lookups an EGO which was registered to a store under a specific identifier. More...
 
struct GNUNET_MESSENGER_Egoupdate_store_ego (struct GNUNET_MESSENGER_EgoStore *store, const char *identifier, const struct GNUNET_IDENTITY_PrivateKey *key)
 Updates the registration of an EGO to a store under a specific identifier with a new key. More...
 
void rename_store_ego (struct GNUNET_MESSENGER_EgoStore *store, const char *old_identifier, const char *new_identifier)
 Updates the location of a registered EGO in a store to a different one under a specific new_identifier replacing its old one. More...
 

Detailed Description

GNUnet MESSENGER service.

Author
Tobias Frisch

Definition in file gnunet-service-messenger_ego_store.h.

Typedef Documentation

◆ GNUNET_MESSENGER_EgoLookupCallback

typedef void(* GNUNET_MESSENGER_EgoLookupCallback) (void *cls, const char *identifier, const struct GNUNET_MESSENGER_Ego *ego)

Definition at line 38 of file gnunet-service-messenger_ego_store.h.

Function Documentation

◆ init_ego_store()

void init_ego_store ( struct GNUNET_MESSENGER_EgoStore store,
const struct GNUNET_CONFIGURATION_Handle config 
)

Initializes an EGO-store as fully empty.

Parameters
[out]storeEGO-store
[in]configConfiguration handle

Definition at line 44 of file gnunet-service-messenger_ego_store.c.

References callback_update_ego(), GNUNET_MESSENGER_EgoStore::cfg, config, GNUNET_MESSENGER_EgoStore::egos, GNUNET_assert, GNUNET_CONTAINER_multihashmap_create(), GNUNET_IDENTITY_connect(), GNUNET_NO, GNUNET_MESSENGER_EgoStore::identity, GNUNET_MESSENGER_EgoStore::lu_end, GNUNET_MESSENGER_EgoStore::lu_start, GNUNET_MESSENGER_EgoStore::op_end, and GNUNET_MESSENGER_EgoStore::op_start.

Referenced by create_service().

45 {
46  GNUNET_assert ((store) && (config));
47 
48  store->cfg = config;
49  store->identity = GNUNET_IDENTITY_connect (config, &callback_update_ego, store);
51 
52  store->lu_start = NULL;
53  store->lu_end = NULL;
54 
55  store->op_start = NULL;
56  store->op_end = NULL;
57 }
struct GNUNET_IDENTITY_Handle * GNUNET_IDENTITY_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_IDENTITY_Callback cb, void *cb_cls)
Connect to the identity service.
Definition: identity_api.c:610
const struct GNUNET_CONFIGURATION_Handle * cfg
static void callback_update_ego(void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *identifier)
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MESSENGER_EgoOperation * op_start
struct GNUNET_IDENTITY_Handle * identity
static const struct GNUNET_CONFIGURATION_Handle * config
struct GNUNET_CONTAINER_MultiHashMap * egos
struct GNUNET_MESSENGER_EgoLookup * lu_end
struct GNUNET_MESSENGER_EgoLookup * lu_start
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
struct GNUNET_MESSENGER_EgoOperation * op_end
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear_ego_store()

void clear_ego_store ( struct GNUNET_MESSENGER_EgoStore store)

Clears an EGO-store, wipes its content and deallocates its memory.

Parameters

Definition at line 69 of file gnunet-service-messenger_ego_store.c.

References GNUNET_MESSENGER_EgoStore::egos, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_free, GNUNET_IDENTITY_cancel(), GNUNET_IDENTITY_disconnect(), GNUNET_IDENTITY_ego_lookup_cancel(), GNUNET_MESSENGER_EgoLookup::identifier, GNUNET_MESSENGER_EgoOperation::identifier, GNUNET_MESSENGER_EgoStore::identity, iterate_destroy_egos(), GNUNET_MESSENGER_EgoLookup::lookup, GNUNET_MESSENGER_EgoStore::lu_end, GNUNET_MESSENGER_EgoStore::lu_start, op, GNUNET_MESSENGER_EgoStore::op_end, GNUNET_MESSENGER_EgoStore::op_start, and GNUNET_MESSENGER_EgoOperation::operation.

Referenced by destroy_service().

70 {
71  GNUNET_assert (store);
72 
74 
75  while (store->op_start)
76  {
77  op = store->op_start;
78 
80  GNUNET_CONTAINER_DLL_remove (store->op_start, store->op_end, op);
81 
82  if (op->identifier)
83  GNUNET_free (op->identifier);
84 
85  GNUNET_free (op);
86  }
87 
88  struct GNUNET_MESSENGER_EgoLookup *lu;
89 
90  while (store->lu_start)
91  {
92  lu = store->lu_start;
93 
95  GNUNET_CONTAINER_DLL_remove (store->lu_start, store->lu_end, lu);
96 
97  if (lu->identifier)
99 
100  GNUNET_free (lu);
101  }
102 
105 
106  if (store->identity)
107  {
109 
110  store->identity = NULL;
111  }
112 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
void GNUNET_IDENTITY_cancel(struct GNUNET_IDENTITY_Operation *op)
Cancel an identity operation.
Definition: identity_api.c:904
void GNUNET_IDENTITY_ego_lookup_cancel(struct GNUNET_IDENTITY_EgoLookup *el)
Abort ego lookup attempt.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MESSENGER_EgoOperation * op_start
struct GNUNET_IDENTITY_Handle * identity
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
void GNUNET_IDENTITY_disconnect(struct GNUNET_IDENTITY_Handle *h)
Disconnect from identity service.
Definition: identity_api.c:921
struct GNUNET_CONTAINER_MultiHashMap * egos
static int iterate_destroy_egos(void *cls, const struct GNUNET_HashCode *key, void *value)
struct GNUNET_MESSENGER_EgoLookup * lu_end
struct GNUNET_IDENTITY_Operation * operation
struct GNUNET_IDENTITY_EgoLookup * lookup
struct GNUNET_MESSENGER_EgoLookup * lu_start
struct GNUNET_MESSENGER_EgoOperation * op_end
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:144
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_store_ego()

void create_store_ego ( struct GNUNET_MESSENGER_EgoStore store,
const char *  identifier,
void *  handle 
)

Creates a new EGO which will be registered to a store under a specific identifier.

A given handle will be informed about the creation and changes its EGO accordingly.

Parameters

Definition at line 142 of file gnunet-service-messenger_ego_store.c.

References callback_ego_create(), GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_IDENTITY_create(), GNUNET_IDENTITY_TYPE_ECDSA, GNUNET_new, GNUNET_strdup, handle, GNUNET_MESSENGER_EgoOperation::handle, GNUNET_MESSENGER_EgoOperation::identifier, GNUNET_MESSENGER_EgoStore::identity, GNUNET_MESSENGER_EgoStore::op_end, GNUNET_MESSENGER_EgoStore::op_start, GNUNET_MESSENGER_EgoOperation::operation, and GNUNET_MESSENGER_EgoOperation::store.

Referenced by callback_update_handle().

144 {
145  GNUNET_assert ((store) && (identifier));
146 
148 
149  element->store = store;
150  element->handle = handle;
151 
152  element->identifier = GNUNET_strdup (identifier);
153 
154  element->operation = GNUNET_IDENTITY_create (store->identity, identifier, NULL,
156 
157  GNUNET_CONTAINER_DLL_insert (store->op_start, store->op_end, element);
158 }
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MESSENGER_EgoOperation * op_start
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static void callback_ego_create(void *cls, const struct GNUNET_IDENTITY_PrivateKey *key, const char *emsg)
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
struct GNUNET_IDENTITY_Handle * identity
struct GNUNET_IDENTITY_Operation * GNUNET_IDENTITY_create(struct GNUNET_IDENTITY_Handle *h, const char *name, const struct GNUNET_IDENTITY_PrivateKey *privkey, enum GNUNET_IDENTITY_KeyType ktype, GNUNET_IDENTITY_CreateContinuation cont, void *cont_cls)
Create a new ego with the given name.
Definition: identity_api.c:757
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct GNUNET_MESSENGER_EgoStore * store
struct GNUNET_IDENTITY_Operation * operation
struct GNUNET_MESSENGER_EgoOperation * op_end
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lookup_store_ego()

void lookup_store_ego ( struct GNUNET_MESSENGER_EgoStore store,
const char *  identifier,
GNUNET_MESSENGER_EgoLookupCallback  lookup,
void *  cls 
)

Lookups an EGO which was registered to a store under a specific identifier.

Parameters

Definition at line 186 of file gnunet-service-messenger_ego_store.c.

References callback_ego_lookup(), GNUNET_MESSENGER_EgoLookup::cb, GNUNET_MESSENGER_EgoStore::cfg, GNUNET_MESSENGER_EgoLookup::cls, GNUNET_MESSENGER_EgoStore::egos, GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_multihashmap_get(), GNUNET_CRYPTO_hash(), GNUNET_IDENTITY_ego_lookup(), GNUNET_new, GNUNET_strdup, GNUNET_MESSENGER_EgoLookup::identifier, GNUNET_MESSENGER_EgoLookup::lookup, GNUNET_MESSENGER_EgoStore::lu_end, GNUNET_MESSENGER_EgoStore::lu_start, and GNUNET_MESSENGER_EgoLookup::store.

Referenced by set_handle_name(), setup_handle_name(), and update_handle().

188 {
189  GNUNET_assert (store);
190 
191  if (!identifier)
192  {
193  lookup(cls, identifier, NULL);
194  return;
195  }
196 
197  struct GNUNET_HashCode hash;
198  GNUNET_CRYPTO_hash (identifier, strlen (identifier), &hash);
199 
200  struct GNUNET_MESSENGER_Ego *ego = GNUNET_CONTAINER_multihashmap_get (store->egos, &hash);
201 
202  if (ego)
203  lookup(cls, identifier, ego);
204  else
205  {
207 
208  element->store = store;
209 
210  element->cb = lookup;
211  element->cls = cls;
212 
213  element->identifier = GNUNET_strdup (identifier);
214 
216 
217  GNUNET_CONTAINER_DLL_insert (store->lu_start, store->lu_end, element);
218  }
219 }
const struct GNUNET_CONFIGURATION_Handle * cfg
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
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
GNUNET_MESSENGER_EgoLookupCallback cb
A 512-bit hashcode.
struct GNUNET_CONTAINER_MultiHashMap * egos
struct GNUNET_MESSENGER_EgoLookup * lu_end
struct GNUNET_IDENTITY_EgoLookup * GNUNET_IDENTITY_ego_lookup(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *name, GNUNET_IDENTITY_EgoCallback cb, void *cb_cls)
Lookup an ego by name.
struct GNUNET_MESSENGER_EgoStore * store
static void callback_ego_lookup(void *cls, struct GNUNET_IDENTITY_Ego *ego)
struct GNUNET_IDENTITY_EgoLookup * lookup
struct GNUNET_MESSENGER_EgoLookup * lu_start
Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_store_ego()

struct GNUNET_MESSENGER_Ego* update_store_ego ( struct GNUNET_MESSENGER_EgoStore store,
const char *  identifier,
const struct GNUNET_IDENTITY_PrivateKey key 
)

Updates the registration of an EGO to a store under a specific identifier with a new key.

Parameters

Definition at line 222 of file gnunet-service-messenger_ego_store.c.

References GNUNET_MESSENGER_EgoStore::egos, GNUNET_assert, GNUNET_CONTAINER_multihashmap_get(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_WARNING, GNUNET_IDENTITY_key_get_public(), GNUNET_log, GNUNET_memcpy, GNUNET_new, GNUNET_OK, GNUNET_MESSENGER_Ego::priv, and GNUNET_MESSENGER_Ego::pub.

Referenced by callback_ego_create(), callback_ego_lookup(), and callback_update_ego().

224 {
225  GNUNET_assert ((store) && (identifier) && (key));
226 
227  struct GNUNET_HashCode hash;
228  GNUNET_CRYPTO_hash (identifier, strlen (identifier), &hash);
229 
230  struct GNUNET_MESSENGER_Ego *ego = GNUNET_CONTAINER_multihashmap_get (store->egos, &hash);
231 
232  if (!ego)
233  {
234  ego = GNUNET_new(struct GNUNET_MESSENGER_Ego);
236  }
237 
238  GNUNET_memcpy(&(ego->priv), key, sizeof(*key));
239 
240  if (GNUNET_OK != GNUNET_IDENTITY_key_get_public (key, &(ego->pub)))
241  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Updating invalid ego key failed!\n");
242 
243  return ego;
244 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
struct GNUNET_IDENTITY_PublicKey pub
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
enum GNUNET_GenericReturnValue GNUNET_IDENTITY_key_get_public(const struct GNUNET_IDENTITY_PrivateKey *privkey, struct GNUNET_IDENTITY_PublicKey *key)
Retrieves the public key representation of a private key.
Definition: identity_api.c:175
A 512-bit hashcode.
struct GNUNET_CONTAINER_MultiHashMap * egos
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.
#define GNUNET_log(kind,...)
struct GNUNET_IDENTITY_PrivateKey priv
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rename_store_ego()

void rename_store_ego ( struct GNUNET_MESSENGER_EgoStore store,
const char *  old_identifier,
const char *  new_identifier 
)

Updates the location of a registered EGO in a store to a different one under a specific new_identifier replacing its old one.

Parameters

Definition at line 280 of file gnunet-service-messenger_ego_store.c.

References callback_ego_rename(), GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_IDENTITY_rename(), GNUNET_new, GNUNET_strdup, GNUNET_MESSENGER_EgoOperation::handle, GNUNET_MESSENGER_EgoOperation::identifier, GNUNET_MESSENGER_EgoStore::identity, GNUNET_MESSENGER_EgoStore::op_end, GNUNET_MESSENGER_EgoStore::op_start, GNUNET_MESSENGER_EgoOperation::operation, and GNUNET_MESSENGER_EgoOperation::store.

Referenced by callback_set_handle_name().

282 {
283  GNUNET_assert ((store) && (old_identifier) && (new_identifier));
284 
286 
287  element->store = store;
288  element->handle = GNUNET_strdup (new_identifier);
289 
290  element->identifier = GNUNET_strdup (old_identifier);
291 
292  element->operation = GNUNET_IDENTITY_rename (store->identity, old_identifier, new_identifier, callback_ego_rename, element);
293 
294  GNUNET_CONTAINER_DLL_insert (store->op_start, store->op_end, element);
295 }
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MESSENGER_EgoOperation * op_start
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
struct GNUNET_IDENTITY_Handle * identity
struct GNUNET_MESSENGER_EgoStore * store
struct GNUNET_IDENTITY_Operation * operation
struct GNUNET_IDENTITY_Operation * GNUNET_IDENTITY_rename(struct GNUNET_IDENTITY_Handle *h, const char *old_name, const char *new_name, GNUNET_IDENTITY_Continuation cb, void *cb_cls)
Renames an existing identity.
Definition: identity_api.c:810
struct GNUNET_MESSENGER_EgoOperation * op_end
static void callback_ego_rename(void *cls, const char *emsg)
Here is the call graph for this function:
Here is the caller graph for this function: