GNUnet  0.11.x
Data Structures | Functions
messenger_api_contact_store.h File Reference

messenger api: client implementation of GNUnet MESSENGER service More...

#include "platform.h"
#include "gnunet_container_lib.h"
#include "gnunet_crypto_lib.h"
#include "gnunet_identity_service.h"
Include dependency graph for messenger_api_contact_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_ContactStore
 

Functions

void init_contact_store (struct GNUNET_MESSENGER_ContactStore *store)
 Initializes a contact store as fully empty. More...
 
void clear_contact_store (struct GNUNET_MESSENGER_ContactStore *store)
 Clears a contact store, wipes its content and deallocates its memory. More...
 
struct GNUNET_MESSENGER_Contactget_store_contact_raw (struct GNUNET_MESSENGER_ContactStore *store, const struct GNUNET_HashCode *context, const struct GNUNET_HashCode *key_hash)
 Returns a contact using the hash of a specific public key. More...
 
struct GNUNET_MESSENGER_Contactget_store_contact (struct GNUNET_MESSENGER_ContactStore *store, const struct GNUNET_HashCode *context, const struct GNUNET_IDENTITY_PublicKey *pubkey)
 Returns a contact using a specific public key. More...
 
void update_store_contact (struct GNUNET_MESSENGER_ContactStore *store, struct GNUNET_MESSENGER_Contact *contact, const struct GNUNET_HashCode *context, const struct GNUNET_HashCode *next_context, const struct GNUNET_IDENTITY_PublicKey *pubkey)
 Moves a contact from the store to another location matching a given public key and member context. More...
 
void remove_store_contact (struct GNUNET_MESSENGER_ContactStore *store, struct GNUNET_MESSENGER_Contact *contact, const struct GNUNET_HashCode *context)
 Removes a contact from the store which uses a given member context. More...
 

Detailed Description

messenger api: client implementation of GNUnet MESSENGER service

Author
Tobias Frisch

Definition in file messenger_api_contact_store.h.

Function Documentation

◆ init_contact_store()

void init_contact_store ( struct GNUNET_MESSENGER_ContactStore store)

Initializes a contact store as fully empty.

Parameters
[out]storeContact store

Definition at line 32 of file messenger_api_contact_store.c.

References GNUNET_MESSENGER_ContactStore::anonymous, GNUNET_MESSENGER_ContactStore::contacts, GNUNET_assert, GNUNET_CONTAINER_multihashmap_create(), and GNUNET_NO.

Referenced by create_handle(), and create_service().

33 {
34  GNUNET_assert (store);
35 
38 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CONTAINER_MultiHashMap * anonymous
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
struct GNUNET_CONTAINER_MultiHashMap * contacts
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear_contact_store()

void clear_contact_store ( struct GNUNET_MESSENGER_ContactStore store)

Clears a contact store, wipes its content and deallocates its memory.

Parameters

Definition at line 49 of file messenger_api_contact_store.c.

References GNUNET_MESSENGER_ContactStore::anonymous, GNUNET_MESSENGER_ContactStore::contacts, GNUNET_assert, GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), and iterate_destroy_contacts().

Referenced by destroy_handle(), and destroy_service().

50 {
51  GNUNET_assert ((store) && (store->contacts));
52 
55 
58 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CONTAINER_MultiHashMap * anonymous
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
static int iterate_destroy_contacts(void *cls, const struct GNUNET_HashCode *key, void *value)
struct GNUNET_CONTAINER_MultiHashMap * contacts
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:

◆ get_store_contact_raw()

struct GNUNET_MESSENGER_Contact* get_store_contact_raw ( struct GNUNET_MESSENGER_ContactStore store,
const struct GNUNET_HashCode context,
const struct GNUNET_HashCode key_hash 
)

Returns a contact using the hash of a specific public key.

In case the anonymous key gets used by the requested contact, it will use its provided member context to select the matching contact from the store.

In case there is no contact stored which uses the given key or context, NULL gets returned.

Parameters

Definition at line 79 of file messenger_api_contact_store.c.

References GNUNET_MESSENGER_ContactStore::contacts, GNUNET_assert, GNUNET_CONTAINER_multihashmap_get(), GNUNET_memcpy, map, and select_store_contact_map().

Referenced by handle_recv_message().

81 {
82  GNUNET_assert ((store) && (store->contacts) && (context) && (key_hash));
83 
84  struct GNUNET_HashCode hash;
85  GNUNET_memcpy(&hash, key_hash, sizeof(*key_hash));
86 
88  store, context, &hash
89  );
90 
91  return GNUNET_CONTAINER_multihashmap_get (map, &hash);
92 }
#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.
Internal representation of the hash map.
static struct GNUNET_CONTAINER_MultiPeerMap * map
Handle to the map used to store old latency values for peers.
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.
static struct GNUNET_CONTAINER_MultiHashMap * select_store_contact_map(struct GNUNET_MESSENGER_ContactStore *store, const struct GNUNET_HashCode *context, struct GNUNET_HashCode *hash)
A 512-bit hashcode.
struct GNUNET_CONTAINER_MultiHashMap * contacts
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_store_contact()

struct GNUNET_MESSENGER_Contact* get_store_contact ( struct GNUNET_MESSENGER_ContactStore store,
const struct GNUNET_HashCode context,
const struct GNUNET_IDENTITY_PublicKey pubkey 
)

Returns a contact using a specific public key.

In case the anonymous key gets used by the requested contact, it will use its provided member context to select the matching contact from the store.

In case there is no contact stored which uses the given key or context, a new contact will be created automatically.

The function returns NULL if an error occurs during allocation or validation of the contacts key.

Parameters

Definition at line 95 of file messenger_api_contact_store.c.

References GNUNET_MESSENGER_ContactStore::contacts, create_contact(), destroy_contact(), get_contact_key(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_get(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_INVALID, GNUNET_free, GNUNET_IDENTITY_public_key_to_string(), GNUNET_log, GNUNET_memcmp, GNUNET_OK, map, and select_store_contact_map().

Referenced by create_member_session(), get_handle_contact(), handle_join_message(), and reset_member_session().

97 {
98  GNUNET_assert ((store) && (store->contacts) && (context) && (pubkey));
99 
100  struct GNUNET_HashCode hash;
101  GNUNET_CRYPTO_hash (pubkey, sizeof(*pubkey), &hash);
102 
104  store, context, &hash
105  );
106 
107  struct GNUNET_MESSENGER_Contact *contact = GNUNET_CONTAINER_multihashmap_get (map, &hash);
108 
109  if (contact)
110  {
111  if (0 != GNUNET_memcmp(pubkey, get_contact_key(contact)))
112  {
114  GNUNET_log (GNUNET_ERROR_TYPE_INVALID, "Contact in store uses wrong key: %s\n", str);
115  GNUNET_free (str);
116  return NULL;
117  }
118 
119  return contact;
120  }
121 
122  contact = create_contact (pubkey);
123 
124  if (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (map, &hash, contact,
126  return contact;
127 
128  destroy_contact (contact);
129  return NULL;
130 }
const struct GNUNET_IDENTITY_PublicKey * get_contact_key(const struct GNUNET_MESSENGER_Contact *contact)
Returns the public key of a given contact.
char * GNUNET_IDENTITY_public_key_to_string(const struct GNUNET_IDENTITY_PublicKey *key)
Creates a (Base32) string representation of the public key.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Internal representation of the hash map.
struct GNUNET_MESSENGER_Contact * create_contact(const struct GNUNET_IDENTITY_PublicKey *key)
Creates and allocates a new contact with a given public key from an EGO.
static struct GNUNET_CONTAINER_MultiPeerMap * map
Handle to the map used to store old latency values for peers.
void destroy_contact(struct GNUNET_MESSENGER_Contact *contact)
Destroys a contact and frees its memory fully.
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
static struct GNUNET_CONTAINER_MultiHashMap * select_store_contact_map(struct GNUNET_MESSENGER_ContactStore *store, const struct GNUNET_HashCode *context, struct GNUNET_HashCode *hash)
A 512-bit hashcode.
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_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
#define GNUNET_log(kind,...)
struct GNUNET_CONTAINER_MultiHashMap * contacts
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_store_contact()

void update_store_contact ( struct GNUNET_MESSENGER_ContactStore store,
struct GNUNET_MESSENGER_Contact contact,
const struct GNUNET_HashCode context,
const struct GNUNET_HashCode next_context,
const struct GNUNET_IDENTITY_PublicKey pubkey 
)

Moves a contact from the store to another location matching a given public key and member context.

This function allows changes of keys or changes of member contexts!

Parameters

Definition at line 133 of file messenger_api_contact_store.c.

References GNUNET_MESSENGER_ContactStore::contacts, get_contact_key(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_multihashmap_remove(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_WARNING, GNUNET_h2s(), GNUNET_log, GNUNET_memcpy, GNUNET_OK, GNUNET_YES, map, GNUNET_MESSENGER_Contact::public_key, and select_store_contact_map().

Referenced by handle_id_message(), handle_key_message(), and switch_member_session().

136 {
137  GNUNET_assert ((store) && (store->contacts) && (contact) && (pubkey));
138 
139  const struct GNUNET_IDENTITY_PublicKey* oldkey = get_contact_key (contact);
140 
141  struct GNUNET_HashCode hash;
142  GNUNET_CRYPTO_hash (oldkey, sizeof(*oldkey), &hash);
143 
145  store, context, &hash
146  );
147 
148  if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (map, &hash, contact))
149  {
150  GNUNET_memcpy(&(contact->public_key), pubkey, sizeof(*pubkey));
151 
152  GNUNET_CRYPTO_hash (pubkey, sizeof(*pubkey), &hash);
153 
155  store, next_context, &hash
156  );
157 
158  if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (map, &hash, contact,
160  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Updating a contact failed: %s\n",
161  GNUNET_h2s(&hash));
162  }
163 }
const struct GNUNET_IDENTITY_PublicKey * get_contact_key(const struct GNUNET_MESSENGER_Contact *contact)
Returns the public key of a given contact.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_IDENTITY_PublicKey public_key
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
Internal representation of the hash map.
static struct GNUNET_CONTAINER_MultiPeerMap * map
Handle to the map used to store old latency values for peers.
, ' 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
static struct GNUNET_CONTAINER_MultiHashMap * select_store_contact_map(struct GNUNET_MESSENGER_ContactStore *store, const struct GNUNET_HashCode *context, struct GNUNET_HashCode *hash)
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.
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.
An identity key as per LSD0001.
#define GNUNET_log(kind,...)
struct GNUNET_CONTAINER_MultiHashMap * contacts
Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove_store_contact()

void remove_store_contact ( struct GNUNET_MESSENGER_ContactStore store,
struct GNUNET_MESSENGER_Contact contact,
const struct GNUNET_HashCode context 
)

Removes a contact from the store which uses a given member context.

Parameters

Definition at line 166 of file messenger_api_contact_store.c.

References GNUNET_MESSENGER_ContactStore::contacts, destroy_contact(), get_contact_key(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_remove(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_WARNING, GNUNET_h2s(), GNUNET_log, GNUNET_YES, map, pubkey, and select_store_contact_map().

Referenced by check_member_session_completion(), and destroy_member_session().

168 {
169  GNUNET_assert ((store) && (store->contacts) && (contact));
170 
171  const struct GNUNET_IDENTITY_PublicKey* pubkey = get_contact_key(contact);
172 
173  struct GNUNET_HashCode hash;
174  GNUNET_CRYPTO_hash (pubkey, sizeof(*pubkey), &hash);
175 
177  store, context, &hash
178  );
179 
180  if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (map, &hash, contact))
181  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Removing a contact failed: %s\n",
182  GNUNET_h2s(&hash));
183 
184  destroy_contact (contact);
185 }
const struct GNUNET_IDENTITY_PublicKey * get_contact_key(const struct GNUNET_MESSENGER_Contact *contact)
Returns the public key of a given contact.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
Internal representation of the hash map.
static struct GNUNET_CONTAINER_MultiPeerMap * map
Handle to the map used to store old latency values for peers.
void destroy_contact(struct GNUNET_MESSENGER_Contact *contact)
Destroys a contact and frees its memory fully.
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
static struct GNUNET_IDENTITY_PublicKey pubkey
Public key of the zone to look in.
static struct GNUNET_CONTAINER_MultiHashMap * select_store_contact_map(struct GNUNET_MESSENGER_ContactStore *store, const struct GNUNET_HashCode *context, struct GNUNET_HashCode *hash)
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.
An identity key as per LSD0001.
#define GNUNET_log(kind,...)
struct GNUNET_CONTAINER_MultiHashMap * contacts
Here is the call graph for this function:
Here is the caller graph for this function: