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 37 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 47 of file gnunet-service-messenger_ego_store.c.

49 {
50  GNUNET_assert ((store) && (config));
51 
52  store->cfg = config;
55 
56  store->lu_start = NULL;
57  store->lu_end = NULL;
58 
59  store->op_start = NULL;
60  store->op_end = NULL;
61 }
static void callback_update_ego(void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *identifier)
static const struct GNUNET_CONFIGURATION_Handle * config
@ GNUNET_NO
Definition: gnunet_common.h:94
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
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
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MESSENGER_EgoLookup * lu_end
const struct GNUNET_CONFIGURATION_Handle * cfg
struct GNUNET_MESSENGER_EgoLookup * lu_start
struct GNUNET_IDENTITY_Handle * identity
struct GNUNET_CONTAINER_MultiHashMap * egos
struct GNUNET_MESSENGER_EgoOperation * op_end
struct GNUNET_MESSENGER_EgoOperation * op_start

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().

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
[in/out]store EGO-store

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

76 {
77  GNUNET_assert (store);
78 
80 
81  while (store->op_start)
82  {
83  op = store->op_start;
84 
85  GNUNET_IDENTITY_cancel (op->operation);
87 
88  if (op->identifier)
89  GNUNET_free (op->identifier);
90 
91  GNUNET_free (op);
92  }
93 
94  struct GNUNET_MESSENGER_EgoLookup *lu;
95 
96  while (store->lu_start)
97  {
98  lu = store->lu_start;
99 
102 
103  if (lu->identifier)
104  GNUNET_free(lu->identifier);
105 
106  GNUNET_free (lu);
107  }
108 
111 
112  if (store->identity)
113  {
115 
116  store->identity = NULL;
117  }
118 }
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:144
static int iterate_destroy_egos(void *cls, const struct GNUNET_HashCode *key, void *value)
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
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.
void GNUNET_IDENTITY_disconnect(struct GNUNET_IDENTITY_Handle *h)
Disconnect from identity service.
Definition: identity_api.c:921
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_IDENTITY_EgoLookup * lookup
struct GNUNET_MESSENGER_EgoStore * store
struct GNUNET_MESSENGER_EgoStore * store

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_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, GNUNET_MESSENGER_EgoLookup::store, and GNUNET_MESSENGER_EgoOperation::store.

Referenced by destroy_service().

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
[in/out]store EGO-store
[in]identifierIdentifier string
[in/out]handle Handle or NULL

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

153 {
154  GNUNET_assert ((store) && (identifier));
155 
157 
158  element->store = store;
159  element->handle = handle;
160 
161  element->identifier = GNUNET_strdup (identifier);
162 
165 
167 }
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static void callback_ego_create(void *cls, const struct GNUNET_IDENTITY_PrivateKey *key, const char *emsg)
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
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
@ GNUNET_IDENTITY_TYPE_ECDSA
The identity type.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_IDENTITY_Operation * operation

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().

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
[in/out]store EGO-store
[in]identifierIdentifier string
[in]lookupLookup callback (non-NULL)
[in]clsClosure

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

200 {
201  GNUNET_assert (store);
202 
203  if (!identifier)
204  {
205  lookup(cls, identifier, NULL);
206  return;
207  }
208 
209  struct GNUNET_HashCode hash;
210  GNUNET_CRYPTO_hash (identifier, strlen (identifier), &hash);
211 
212  struct GNUNET_MESSENGER_Ego *ego = GNUNET_CONTAINER_multihashmap_get (store->egos, &hash);
213 
214  if (ego)
215  lookup(cls, identifier, ego);
216  else
217  {
219 
220  element->store = store;
221 
222  element->cb = lookup;
223  element->cls = cls;
224 
225  element->identifier = GNUNET_strdup (identifier);
226 
228 
230  }
231 }
static void callback_ego_lookup(void *cls, struct GNUNET_IDENTITY_Ego *ego)
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
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.
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.
A 512-bit hashcode.
GNUNET_MESSENGER_EgoLookupCallback cb

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().

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
[in/out]store EGO-store
[in]identifierIdentifier string
[in]keyPrivate EGO key
Returns
Updated EGO

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

237 {
238  GNUNET_assert ((store) && (identifier) && (key));
239 
240  struct GNUNET_HashCode hash;
241  GNUNET_CRYPTO_hash (identifier, strlen (identifier), &hash);
242 
243  struct GNUNET_MESSENGER_Ego *ego = GNUNET_CONTAINER_multihashmap_get (store->egos, &hash);
244 
245  if (!ego)
246  {
247  ego = GNUNET_new(struct GNUNET_MESSENGER_Ego);
249  }
250 
251  GNUNET_memcpy(&(ego->priv), key, sizeof(*key));
252 
254  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Updating invalid ego key failed!\n");
255 
256  return ego;
257 }
struct GNUNET_HashCode key
The key used in the DHT.
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
Definition: gnunet_common.h:95
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.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE...
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
@ GNUNET_ERROR_TYPE_WARNING
struct GNUNET_IDENTITY_PublicKey pub
struct GNUNET_IDENTITY_PrivateKey priv

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, key, GNUNET_MESSENGER_Ego::priv, and GNUNET_MESSENGER_Ego::pub.

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

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
[in/out]store EGO-store
[in]old_identifierOld identifier string
[in]new_identifierNew identifier string

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

297 {
298  GNUNET_assert ((store) && (old_identifier) && (new_identifier));
299 
301 
302  element->store = store;
303  element->handle = GNUNET_strdup (new_identifier);
304 
305  element->identifier = GNUNET_strdup (old_identifier);
306 
307  element->operation = GNUNET_IDENTITY_rename (store->identity, old_identifier, new_identifier, callback_ego_rename, element);
308 
310 }
static void callback_ego_rename(void *cls, const char *emsg)
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

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().

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