GNUnet  0.11.x
Functions
gnunet-service-messenger_ego_store.c File Reference

GNUnet MESSENGER service. More...

#include "gnunet-service-messenger_ego_store.h"
#include "gnunet-service-messenger_handle.h"
Include dependency graph for gnunet-service-messenger_ego_store.c:

Go to the source code of this file.

Functions

static void callback_update_ego (void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *identifier)
 
void init_ego_store (struct GNUNET_MESSENGER_EgoStore *store, const struct GNUNET_CONFIGURATION_Handle *config)
 Initializes an EGO-store as fully empty. More...
 
static int iterate_destroy_egos (void *cls, const struct GNUNET_HashCode *key, void *value)
 
void clear_ego_store (struct GNUNET_MESSENGER_EgoStore *store)
 Clears an EGO-store, wipes its content and deallocates its memory. More...
 
static void callback_ego_create (void *cls, const struct GNUNET_IDENTITY_PrivateKey *key, const char *emsg)
 
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...
 
static void callback_ego_lookup (void *cls, struct GNUNET_IDENTITY_Ego *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. 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...
 
static void callback_ego_rename (void *cls, const char *emsg)
 
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.c.

Function Documentation

◆ callback_update_ego()

static void callback_update_ego ( void *  cls,
struct GNUNET_IDENTITY_Ego ego,
void **  ctx,
const char *  identifier 
)
static

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

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_IDENTITY_ego_get_private_key(), GNUNET_log, and update_store_ego().

Referenced by init_ego_store().

32 {
33  if ((!ego) || (!identifier))
34  return;
35 
36  struct GNUNET_MESSENGER_EgoStore *store = cls;
37 
38  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "New ego in use: '%s'\n", identifier);
39 
40  update_store_ego (store, identifier, GNUNET_IDENTITY_ego_get_private_key (ego));
41 }
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...
const struct GNUNET_IDENTITY_PrivateKey * GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego)
Obtain the ECC key associated with a ego.
Definition: identity_api.c:639
#define GNUNET_log(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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:

◆ iterate_destroy_egos()

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

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

References GNUNET_free, GNUNET_YES, and value.

Referenced by clear_ego_store().

62 {
63  struct GNUNET_MESSENGER_Ego *ego = value;
64  GNUNET_free(ego);
65  return GNUNET_YES;
66 }
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:

◆ 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:

◆ callback_ego_create()

static void callback_ego_create ( void *  cls,
const struct GNUNET_IDENTITY_PrivateKey key,
const char *  emsg 
)
static

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

References GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, handle, GNUNET_MESSENGER_EgoOperation::handle, GNUNET_MESSENGER_EgoOperation::identifier, GNUNET_MESSENGER_EgoStore::op_end, GNUNET_MESSENGER_EgoStore::op_start, set_handle_ego(), GNUNET_MESSENGER_EgoOperation::store, and update_store_ego().

Referenced by create_store_ego().

116 {
117  struct GNUNET_MESSENGER_EgoOperation *element = cls;
118  struct GNUNET_MESSENGER_EgoStore *store = element->store;
119 
120  GNUNET_assert(element->identifier);
121 
122  if (emsg)
123  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s\n", emsg);
124 
125  if (key)
126  {
127  struct GNUNET_MESSENGER_SrvHandle *handle = element->handle;
128 
129  struct GNUNET_MESSENGER_Ego *msg_ego = update_store_ego (store, element->identifier, key);
130 
131  set_handle_ego (handle, msg_ego);
132  }
133  else
134  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Creating ego failed!\n");
135 
136  GNUNET_CONTAINER_DLL_remove (store->op_start, store->op_end, element);
137  GNUNET_free (element->identifier);
138  GNUNET_free (element);
139 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MESSENGER_EgoOperation * op_start
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...
void set_handle_ego(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_MESSENGER_Ego *ego)
Sets the EGO used by a given handle.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct GNUNET_MESSENGER_EgoStore * store
#define GNUNET_log(kind,...)
struct GNUNET_MESSENGER_EgoOperation * op_end
#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:

◆ callback_ego_lookup()

static void callback_ego_lookup ( void *  cls,
struct GNUNET_IDENTITY_Ego ego 
)
static

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

References GNUNET_MESSENGER_EgoLookup::cb, GNUNET_MESSENGER_EgoLookup::cls, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_IDENTITY_ego_get_private_key(), GNUNET_MESSENGER_EgoLookup::identifier, GNUNET_MESSENGER_EgoStore::lu_end, GNUNET_MESSENGER_EgoStore::lu_start, GNUNET_MESSENGER_EgoLookup::store, and update_store_ego().

Referenced by lookup_store_ego().

162 {
163  struct GNUNET_MESSENGER_EgoLookup *element = cls;
164  struct GNUNET_MESSENGER_EgoStore *store = element->store;
165 
166  GNUNET_assert(element->identifier);
167 
168  struct GNUNET_MESSENGER_Ego *msg_ego;
169 
170  if (ego)
171  msg_ego = update_store_ego (
172  store, element->identifier, GNUNET_IDENTITY_ego_get_private_key(ego)
173  );
174  else
175  msg_ego = NULL;
176 
177  if (element->cb)
178  element->cb(element->cls, element->identifier, msg_ego);
179 
180  GNUNET_CONTAINER_DLL_remove (store->lu_start, store->lu_end, element);
181  GNUNET_free (element->identifier);
182  GNUNET_free (element);
183 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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...
GNUNET_MESSENGER_EgoLookupCallback cb
struct GNUNET_MESSENGER_EgoLookup * lu_end
struct GNUNET_MESSENGER_EgoStore * store
const struct GNUNET_IDENTITY_PrivateKey * GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego)
Obtain the ECC key associated with a ego.
Definition: identity_api.c:639
struct GNUNET_MESSENGER_EgoLookup * lu_start
#define GNUNET_free(ptr)
Wrapper around free.
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:

◆ callback_ego_rename()

static void callback_ego_rename ( void *  cls,
const char *  emsg 
)
static

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

References GNUNET_MESSENGER_EgoStore::egos, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multihashmap_get(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_multihashmap_remove(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_YES, GNUNET_MESSENGER_EgoOperation::handle, GNUNET_MESSENGER_EgoOperation::identifier, GNUNET_MESSENGER_EgoStore::op_end, GNUNET_MESSENGER_EgoStore::op_start, and GNUNET_MESSENGER_EgoOperation::store.

Referenced by rename_store_ego().

248 {
249  struct GNUNET_MESSENGER_EgoOperation *element = cls;
250  struct GNUNET_MESSENGER_EgoStore *store = element->store;
251 
252  GNUNET_assert(element->identifier);
253 
254  if (emsg)
255  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s\n", emsg);
256 
257  struct GNUNET_HashCode hash;
258  GNUNET_CRYPTO_hash (element->identifier, strlen (element->identifier), &hash);
259 
260  struct GNUNET_MESSENGER_Ego *ego = GNUNET_CONTAINER_multihashmap_get (store->egos, &hash);
261 
262  if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (store->egos, &hash, ego))
263  {
264  GNUNET_CRYPTO_hash ((char*) element->handle, strlen ((char*) element->handle), &hash);
265 
266  GNUNET_CONTAINER_multihashmap_put (store->egos, &hash, ego,
268  }
269  else
270  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Renaming ego failed!\n");
271 
272  GNUNET_free (element->handle);
273 
274  GNUNET_CONTAINER_DLL_remove (store->op_start, store->op_end, element);
275  GNUNET_free (element->identifier);
276  GNUNET_free (element);
277 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MESSENGER_EgoOperation * op_start
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_...
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
int GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.
A 512-bit hashcode.
struct GNUNET_CONTAINER_MultiHashMap * egos
struct GNUNET_MESSENGER_EgoStore * store
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_MESSENGER_EgoOperation * op_end
#define GNUNET_free(ptr)
Wrapper around free.
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: