GNUnet 0.25.2-11-g84e94e98c
 
Loading...
Searching...
No Matches
messenger_api_contact_store.c File Reference
Include dependency graph for messenger_api_contact_store.c:

Go to the source code of this file.

Functions

void init_contact_store (struct GNUNET_MESSENGER_ContactStore *store)
 Initializes a contact store as fully empty.
 
static enum GNUNET_GenericReturnValue iterate_destroy_contacts (void *cls, const struct GNUNET_HashCode *key, void *value)
 
void clear_contact_store (struct GNUNET_MESSENGER_ContactStore *store)
 Clears a contact store, wipes its content and deallocates its memory.
 
static struct GNUNET_CONTAINER_MultiHashMapselect_store_contact_map (struct GNUNET_MESSENGER_ContactStore *store, const struct GNUNET_HashCode *context, struct GNUNET_HashCode *hash)
 
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.
 
struct GNUNET_MESSENGER_Contactget_store_contact (struct GNUNET_MESSENGER_ContactStore *store, const struct GNUNET_HashCode *context, const struct GNUNET_CRYPTO_BlindablePublicKey *pubkey)
 Returns a contact using a specific public key.
 
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_CRYPTO_BlindablePublicKey *pubkey)
 Moves a contact from the store to another location matching a given public key and member context.
 
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.
 

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 33 of file messenger_api_contact_store.c.

34{
35 GNUNET_assert (store);
36
39
40 store->counter = 0;
41}
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
@ GNUNET_NO
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CONTAINER_MultiHashMap * contacts
struct GNUNET_CONTAINER_MultiHashMap * anonymous

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

Referenced by create_handle(), and create_service().

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

◆ iterate_destroy_contacts()

static enum GNUNET_GenericReturnValue iterate_destroy_contacts ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Definition at line 45 of file messenger_api_contact_store.c.

48{
49 struct GNUNET_MESSENGER_Contact *contact;
50
52
53 contact = value;
54
55 destroy_contact (contact);
56 return GNUNET_YES;
57}
static char * value
Value of the record to add/remove.
@ GNUNET_YES
void destroy_contact(struct GNUNET_MESSENGER_Contact *contact)
Destroys a contact and frees its memory fully.

References destroy_contact(), GNUNET_assert, GNUNET_YES, and value.

Referenced by clear_contact_store().

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
[in,out]storeContact store

Definition at line 61 of file messenger_api_contact_store.c.

62{
63 GNUNET_assert ((store) && (store->contacts));
64
65 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Clear contact store\n");
66
71
74}
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback 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.
#define GNUNET_log(kind,...)
@ GNUNET_ERROR_TYPE_DEBUG
static enum GNUNET_GenericReturnValue iterate_destroy_contacts(void *cls, const struct GNUNET_HashCode *key, void *value)

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

Referenced by destroy_handle(), and destroy_service().

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

◆ select_store_contact_map()

static struct GNUNET_CONTAINER_MultiHashMap * select_store_contact_map ( struct GNUNET_MESSENGER_ContactStore store,
const struct GNUNET_HashCode context,
struct GNUNET_HashCode hash 
)
static

Definition at line 78 of file messenger_api_contact_store.c.

81{
82 const struct GNUNET_CRYPTO_BlindablePublicKey *anonymous;
83 struct GNUNET_HashCode anonHash;
84
85 GNUNET_assert (hash);
86
87 anonymous = get_anonymous_public_key ();
88
89 GNUNET_CRYPTO_hash (anonymous, sizeof(*anonymous), &anonHash);
90
91 if ((context) && (0 == GNUNET_CRYPTO_hash_cmp (hash, &anonHash)))
92 {
93 GNUNET_memcpy (hash, context, sizeof(*context));
94 return store->anonymous;
95 }
96 else
97 return store->contacts;
98}
static pa_context * context
Pulseaudio context.
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_CRYPTO_hash_cmp(const struct GNUNET_HashCode *h1, const struct GNUNET_HashCode *h2)
Compare function for HashCodes, producing a total ordering of all hashcodes.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
const struct GNUNET_CRYPTO_BlindablePublicKey * get_anonymous_public_key(void)
Returns the public identity key of GNUNET_IDENTITY_ego_get_anonymous() without recalculating it every...
An identity key as per LSD0001.
A 512-bit hashcode.

References GNUNET_MESSENGER_ContactStore::anonymous, GNUNET_MESSENGER_ContactStore::contacts, context, get_anonymous_public_key(), GNUNET_assert, GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_hash_cmp(), and GNUNET_memcpy.

Referenced by get_store_contact(), get_store_contact_raw(), remove_store_contact(), and update_store_contact().

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
[in,out]storeContact store
[in]contextMember context
[in]key_hashHash of public key

Definition at line 102 of file messenger_api_contact_store.c.

105{
107 struct GNUNET_HashCode hash;
108
109 GNUNET_assert ((store) && (store->contacts) && (context) && (key_hash));
110
111 GNUNET_memcpy (&hash, key_hash, sizeof(*key_hash));
112
113 map = select_store_contact_map (store, context, &hash);
114
116}
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)
static struct GNUNET_CONTAINER_MultiPeerMap * map
Peermap of PeerIdentities to "struct PeerEntry" (for fast lookup).
Definition peer.c:63
Internal representation of the hash map.

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

Referenced by process_message_control(), and task_message_control().

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_CRYPTO_BlindablePublicKey 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
[in,out]storeContact store
[in]contextMember context
[in]pubkeyPublic key

Definition at line 120 of file messenger_api_contact_store.c.

123{
125 struct GNUNET_MESSENGER_Contact *contact;
126 struct GNUNET_HashCode hash;
127
128 GNUNET_assert ((store) && (store->contacts) && (pubkey));
129
130 GNUNET_CRYPTO_hash (pubkey, sizeof(*pubkey), &hash);
131
132 map = select_store_contact_map (store, context, &hash);
133 contact = GNUNET_CONTAINER_multihashmap_get (map, &hash);
134
135 if (contact)
136 {
137 if (0 != GNUNET_memcmp (pubkey, get_contact_key (contact)))
138 {
139 char *str;
141 contact));
142
144 "Contact in store uses wrong key: %s\n", str);
146 return NULL;
147 }
148
149 return contact;
150 }
151
152 contact = create_contact (pubkey, ++(store->counter));
153
154 if (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (map, &hash, contact,
156
157
158
159 return contact;
160
161 destroy_contact (contact);
162 return NULL;
163}
static struct GNUNET_CRYPTO_BlindablePublicKey pubkey
Public key of the zone to look in.
enum GNUNET_GenericReturnValue 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...
char * GNUNET_CRYPTO_blindable_public_key_to_string(const struct GNUNET_CRYPTO_BlindablePublicKey *key)
Creates a (Base32) string representation of the public key.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
@ GNUNET_OK
@ GNUNET_ERROR_TYPE_INVALID
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_MESSENGER_Contact * create_contact(const struct GNUNET_CRYPTO_BlindablePublicKey *key, size_t unique_id)
Creates and allocates a new contact with a given public key.
const struct GNUNET_CRYPTO_BlindablePublicKey * get_contact_key(const struct GNUNET_MESSENGER_Contact *contact)
Returns the public key of a given contact.
const char * str
Definition time.c:1252

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

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

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_CRYPTO_BlindablePublicKey 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
[in,out]storeContact store
[in,out]contactContact
[in]contextMember context
[in]next_contextMember context
[in]pubkeyPublic key

Definition at line 167 of file messenger_api_contact_store.c.

172{
173 const struct GNUNET_CRYPTO_BlindablePublicKey *oldkey;
175 struct GNUNET_HashCode hash;
176
177 GNUNET_assert ((store) && (store->contacts) && (contact) && (pubkey));
178
179 oldkey = get_contact_key (contact);
180 GNUNET_CRYPTO_hash (oldkey, sizeof(*oldkey), &hash);
181
182 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Update contact store entry: %s\n",
183 GNUNET_h2s (&hash));
184
185 map = select_store_contact_map (store, context, &hash);
186
187 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (map, &hash, contact))
188 {
189 GNUNET_memcpy (&(contact->public_key), pubkey, sizeof(*pubkey));
190
191 GNUNET_CRYPTO_hash (pubkey, sizeof(*pubkey), &hash);
192
193 map = select_store_contact_map (store, next_context, &hash);
194
195 if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (map, &hash, contact,
197
198
199
200 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Updating a contact failed: %s\n",
201 GNUNET_h2s (&hash));
202 }
203}
enum GNUNET_GenericReturnValue 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.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_WARNING
struct GNUNET_CRYPTO_BlindablePublicKey public_key

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

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

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
[in,out]storeContact store
[in,out]contactContact
[in]contextMember context

Definition at line 207 of file messenger_api_contact_store.c.

210{
213 struct GNUNET_HashCode hash;
214
215 GNUNET_assert ((store) && (store->contacts) && (contact));
216
217 pubkey = get_contact_key (contact);
218 GNUNET_CRYPTO_hash (pubkey, sizeof(*pubkey), &hash);
219
220 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Remove contact store entry: %s\n",
221 GNUNET_h2s (&hash));
222
223 map = select_store_contact_map (store, context, &hash);
224
225 if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (map, &hash, contact))
226 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Removing a contact failed: %s\n",
227 GNUNET_h2s (&hash));
228
229 destroy_contact (contact);
230}

References GNUNET_MESSENGER_ContactStore::contacts, context, destroy_contact(), get_contact_key(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_remove(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, 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().

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