GNUnet 0.26.2-14-ga82e62fdc
 
Loading...
Searching...
No Matches
messenger_api_contact.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2020--2025 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
27
30 size_t unique_id)
31{
32 struct GNUNET_MESSENGER_Contact *contact;
33
35
36 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Create new contact: %lu\n",
37 unique_id);
38
39 contact = GNUNET_new (struct GNUNET_MESSENGER_Contact);
40
41 contact->name = NULL;
42 contact->rc = 0;
43 contact->id = unique_id;
44
45 GNUNET_memcpy (&(contact->public_key), key, sizeof(contact->public_key));
46
48 8, GNUNET_NO);
49
50 return contact;
51}
52
53
56 const struct GNUNET_HashCode *key,
57 void *value)
58{
59 struct GNUNET_CRYPTO_HpkePublicKey *encryption_key;
60
61 GNUNET_assert ((key) && (value));
62
63 encryption_key = value;
64 GNUNET_free (encryption_key);
65 return GNUNET_YES;
66}
67
68
69void
71{
72 GNUNET_assert (contact);
73
74 if (contact->name)
75 GNUNET_free (contact->name);
76
79
81
82 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Free contact: %lu\n",
83 contact->id);
84
85 GNUNET_free (contact);
86}
87
88
89const char*
91{
92 GNUNET_assert (contact);
93
94 return contact->name;
95}
96
97
98void
100 const char *name)
101{
102 GNUNET_assert (contact);
103
104 if (contact->name)
105 GNUNET_free (contact->name);
106
107 contact->name = name ? GNUNET_strdup (name) : NULL;
108}
109
110
113{
114 GNUNET_assert (contact);
115
116 return &(contact->public_key);
117}
118
119
120const struct GNUNET_CRYPTO_HpkePublicKey*
122 const struct GNUNET_HashCode *key)
123{
124 GNUNET_assert ((contact) && (key));
125
127}
128
129
130void
132 const struct GNUNET_HashCode *key,
133 const struct GNUNET_CRYPTO_HpkePublicKey *
134 encryption_key)
135{
136 GNUNET_assert ((contact) && (key));
137
138 if (! encryption_key)
139 {
141 encryption_keys,
142 key))
143 return;
144
148 }
149 else
150 {
151 struct GNUNET_CRYPTO_HpkePublicKey *hpke_key;
152
154 ;
155
156 if (! hpke_key)
157 {
158 hpke_key = GNUNET_malloc (sizeof (*hpke_key));
159
161 contact->encryption_keys, key, hpke_key,
163 {
164 GNUNET_free (hpke_key);
165 return;
166 }
167 }
168
169 GNUNET_memcpy (hpke_key, encryption_key, sizeof (*hpke_key));
170 }
171}
172
173
174void
176{
177 GNUNET_assert (contact);
178
179 contact->rc++;
180}
181
182
185{
186 GNUNET_assert (contact);
187
188 if (contact->rc > 0)
189 contact->rc--;
190
191 return contact->rc ? GNUNET_NO : GNUNET_YES;
192}
193
194
195size_t
197{
198 GNUNET_assert (contact);
199
200 return contact->id;
201}
202
203
204void
206 const struct GNUNET_ShortHashCode *id,
207 struct GNUNET_HashCode *context)
208{
209 GNUNET_assert ((key) && (id) && (context));
210
211 GNUNET_CRYPTO_hash (id, sizeof(*id), context);
213}
struct GNUNET_HashCode key
The key used in the DHT.
static pa_context * context
Pulseaudio context.
static char * name
Name (label) of the records to list.
static char * value
Value of the record to add/remove.
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_CRYPTO_hash_xor(const struct GNUNET_HashCode *a, const struct GNUNET_HashCode *b, struct GNUNET_HashCode *result)
compute result = a ^ b
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_contains(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Check if the map contains any value under the given key (including values that are NULL).
int GNUNET_CONTAINER_multihashmap_remove_all(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Remove all entries for the given key from the map.
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_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
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.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_get_multiple(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map that match a particular key.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE...
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
enum GNUNET_GenericReturnValue decrease_contact_rc(struct GNUNET_MESSENGER_Contact *contact)
Decreases the reference counter if possible (can not underflow!) of a given contact and returns GNUNE...
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.
void set_contact_name(struct GNUNET_MESSENGER_Contact *contact, const char *name)
Changes the current name of a given contact by copying it from the parameter name.
void destroy_contact(struct GNUNET_MESSENGER_Contact *contact)
Destroys a contact and frees its memory fully.
void increase_contact_rc(struct GNUNET_MESSENGER_Contact *contact)
Increases the reference counter of a given contact which is zero as default.
const struct GNUNET_CRYPTO_BlindablePublicKey * get_contact_key(const struct GNUNET_MESSENGER_Contact *contact)
Returns the blindable public key of a given contact.
void set_contact_encryption_key(struct GNUNET_MESSENGER_Contact *contact, const struct GNUNET_HashCode *key, const struct GNUNET_CRYPTO_HpkePublicKey *encryption_key)
Sets or replaces the encryption_key of a given contact for a specified room that is identified via it...
static enum GNUNET_GenericReturnValue iterate_free_contact_encryption_key(void *cls, const struct GNUNET_HashCode *key, void *value)
size_t get_contact_id(const struct GNUNET_MESSENGER_Contact *contact)
Returns the locally unique identifier of a given contact.
const char * get_contact_name(const struct GNUNET_MESSENGER_Contact *contact)
Returns the current name of a given contact or NULL if no valid name was assigned yet.
void get_context_from_member(const struct GNUNET_HashCode *key, const struct GNUNET_ShortHashCode *id, struct GNUNET_HashCode *context)
Calculates the context hash of a member in a room and returns it.
const struct GNUNET_CRYPTO_HpkePublicKey * get_contact_encryption_key(const struct GNUNET_MESSENGER_Contact *contact, const struct GNUNET_HashCode *key)
Returns the HPKE public key of a given contact for a specific room that is identified via its own roo...
An identity key as per LSD0001.
A public key used for encryption.
A 512-bit hashcode.
struct GNUNET_CONTAINER_MultiHashMap * encryption_keys
struct GNUNET_CRYPTO_BlindablePublicKey public_key
A 256-bit hashcode.