GNUnet debian-0.24.3-24-gfea921bd2
plugin_gnsrecord_messenger.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2021--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#include "platform.h"
28#include "gnunet_util_lib.h"
32
33
43static char *
45 uint32_t type,
46 const void *data,
47 size_t data_size)
48{
49 (void) cls;
50 switch (type)
51 {
53 {
54 if (data_size != sizeof(struct GNUNET_MESSENGER_RoomEntryRecord))
55 {
57 return NULL;
58 }
59 {
61
63 &(record->door.public_key));
65 &(record->key), sizeof(struct GNUNET_HashCode));
66
67 char *ret;
68 GNUNET_asprintf (&ret, "%s-%s", key, door);
71 return ret;
72 }
73 }
75 {
77 {
79 return NULL;
80 }
81 {
83
84 char *name = GNUNET_strndup (record->name, 256);
86 &(record->flags), sizeof(uint32_t));
87
88 char *ret;
89 GNUNET_asprintf (&ret, "%s-%s", flags, name);
92 return ret;
93 }
94 }
96 {
98 {
100 return NULL;
101 }
102 {
104
106 &(record->key),
107 sizeof(struct GNUNET_HashCode));
109 &(record->hash),
110 sizeof(struct GNUNET_HashCode));
112 &(record->identifier),
113 sizeof(struct GNUNET_ShortHashCode));
115 &(record->shared_key),
116 sizeof(struct GNUNET_CRYPTO_SymmetricSessionKey));
118 &(record->flags),
119 sizeof(uint32_t));
120
121 char *ret;
123 &ret,
124 "%s-%s-%s-%s-%s",
125 flags,
128 hash,
129 key);
130
136 return ret;
137 }
138 }
139 default:
140 return NULL;
141 }
142}
143
144
156static int
158 uint32_t type,
159 const char *s,
160 void **data,
161 size_t *data_size)
162{
163 (void) cls;
164 if (NULL == s)
165 {
166 GNUNET_break (0);
167 return GNUNET_SYSERR;
168 }
169
170 switch (type)
171 {
173 {
174 char key[104];
175 const char *dash;
176 struct GNUNET_PeerIdentity door;
177
178 if ((NULL == (dash = strchr (s, '-'))) ||
179 (1 != sscanf (s, "%103s-", key)) ||
181 dash + 1, strlen (dash + 1), &(door.public_key))))
182 {
183 GNUNET_log (
185 _ ("Unable to parse MESSENGER_ROOM_ENTRY record `%s'\n"),
186 s);
187
188 return GNUNET_SYSERR;
189 }
190 {
193 );
194
196 key, strlen (key),
197 &(record->key), sizeof(struct GNUNET_HashCode)))
198 {
199 GNUNET_log (
201 _ ("Unable to parse MESSENGER_ROOM_ENTRY record `%s'\n"),
202 s);
203
205 return GNUNET_SYSERR;
206 }
207
208 record->door = door;
209 *data = record;
211 return GNUNET_OK;
212 }
213 }
215 {
216 char flags[8];
217 const char *dash;
218
219 if ((NULL == (dash = strchr (s, '-'))) ||
220 (1 != sscanf (s, "%7s-", flags)) ||
221 (strlen (dash + 1) > 256))
222 {
223 GNUNET_log (
225 _ ("Unable to parse MESSENGER_ROOM_DETAILS record `%s'\n"),
226 s);
227
228 return GNUNET_SYSERR;
229 }
230 {
233 );
234
236 flags, strlen (flags),
237 &(record->flags), sizeof(uint32_t)))
238 {
239 GNUNET_log (
241 _ ("Unable to parse MESSENGER_ROOM_DETAILS record `%s'\n"),
242 s);
243
245 return GNUNET_SYSERR;
246 }
247
248 GNUNET_memcpy (record->name, dash + 1, strlen (dash + 1));
249
250 *data = record;
252 return GNUNET_OK;
253 }
254 }
256 {
257 char key[104];
258 char hash[104];
259 char identifier[53];
260 char shared_key[104];
261 char flags[8];
262 const char *dash;
263 const char *s0;
264
265 s0 = s;
266 if ((NULL == (dash = strchr (s0, '-'))) ||
267 (1 != sscanf (s0, "%7s-", flags)) ||
268 (strlen (dash + 1) > 104))
269 {
270 GNUNET_log (
272 _ ("Unable to parse MESSENGER_ROOM_EPOCH_KEY record `%s'\n"),
273 s);
274
275 return GNUNET_SYSERR;
276 }
277
278 s0 = dash + 1;
279 if ((NULL == (dash = strchr (s0, '-'))) ||
280 (1 != sscanf (s0, "%103s-", shared_key)) ||
281 (strlen (dash + 1) > 53))
282 {
283 GNUNET_log (
285 _ ("Unable to parse MESSENGER_ROOM_EPOCH_KEY record `%s'\n"),
286 s);
287
288 return GNUNET_SYSERR;
289 }
290
291 s0 = dash + 1;
292 if ((NULL == (dash = strchr (s0, '-'))) ||
293 (1 != sscanf (s0, "%52s-", identifier)) ||
294 (strlen (dash + 1) > 104))
295 {
296 GNUNET_log (
298 _ ("Unable to parse MESSENGER_ROOM_EPOCH_KEY record `%s'\n"),
299 s);
300
301 return GNUNET_SYSERR;
302 }
303
304 s0 = dash + 1;
305 if ((NULL == (dash = strchr (s0, '-'))) ||
306 (1 != sscanf (s0, "%103s-", hash)) ||
307 (strlen (dash + 1) > 103))
308 {
309 GNUNET_log (
311 _ ("Unable to parse MESSENGER_ROOM_EPOCH_KEY record `%s'\n"),
312 s);
313
314 return GNUNET_SYSERR;
315 }
316
317 GNUNET_memcpy (key, dash + 1, strlen (dash + 1));
318
319 {
322 );
323
325 flags, strlen (flags),
326 &(record->flags), sizeof(uint32_t))) ||
328 shared_key, strlen (shared_key),
329 &(record->shared_key),
330 sizeof(struct GNUNET_CRYPTO_SymmetricSessionKey)))
331 ||
333 identifier, strlen (identifier),
334 &(record->identifier),
335 sizeof(struct GNUNET_ShortHashCode)))
336 ||
338 hash, strlen (hash),
339 &(record->hash),
340 sizeof(struct GNUNET_HashCode))) ||
342 key, strlen (key),
343 &(record->key),
344 sizeof(struct GNUNET_HashCode))))
345 {
346 GNUNET_log (
348 _ ("Unable to parse MESSENGER_ROOM_EPOCH_KEY record `%s'\n"),
349 s);
350
352 return GNUNET_SYSERR;
353 }
354
355 *data = record;
357 return GNUNET_OK;
358 }
359 }
360 default:
361 return GNUNET_SYSERR;
362 }
363}
364
365
370static struct
371{
372 const char *name;
373 uint32_t number;
374} name_map[] = {
375 { "MESSENGER_ROOM_ENTRY", GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY },
376 { "MESSENGER_ROOM_DETAILS", GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_DETAILS },
377 { "MESSENGER_ROOM_EPOCH_KEY", GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_EPOCH_KEY }
378 ,
379 { NULL, UINT32_MAX }
381
382
390static uint32_t
392 const char *gns_typename)
393{
394 unsigned int i;
395
396 (void) cls;
397 i = 0;
398 while ((name_map[i].name != NULL) &&
399 (0 != strcasecmp (gns_typename, name_map[i].name)))
400 i++;
401 return name_map[i].number;
402}
403
404
412static const char *
414 uint32_t type)
415{
416 unsigned int i;
417
418 (void) cls;
419 i = 0;
420 while ((name_map[i].name != NULL) &&
421 (type != name_map[i].number))
422 i++;
423 return name_map[i].name;
424}
425
426
427void *
429
436void *
438{
440
441 (void) cls;
447 return api;
448}
449
450
451void *
453
460void *
462{
464
465 GNUNET_free (api);
466 return NULL;
467}
#define GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_EPOCH_KEY
Record type to store epoch keys from a messenger room.
#define GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY
Record type to share an entry of a messenger room.
#define GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_DETAILS
Record type to store details about a messenger room.
static int ret
Final status code.
Definition: gnunet-arm.c:93
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
static char * data
The data to insert into the dht.
struct GNUNET_HashCode key
The key used in the DHT.
static uint32_t type
Type string converted to DNS type value.
static size_t data_size
Number of bytes in data.
Plugin API for GNS record types.
#define GNUNET_log(kind,...)
char * GNUNET_CRYPTO_eddsa_public_key_to_string(const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a public key to a string.
Definition: crypto_ecc.c:255
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a string representing a public key to a public key.
Definition: crypto_ecc.c:361
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_ERROR
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:807
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:832
#define _(String)
GNU gettext support macro.
Definition: platform.h:179
void * libgnunet_plugin_gnsrecord_messenger_init(void *cls)
Entry point for the plugin.
void * libgnunet_plugin_gnsrecord_messenger_done(void *cls)
Exit point from the plugin.
static char * messenger_value_to_string(void *cls, uint32_t type, const void *data, size_t data_size)
Convert the 'value' of a record to a string.
static struct @39 name_map[]
Mapping of record type numbers to human-readable record type names.
const char * name
static const char * messenger_number_to_typename(void *cls, uint32_t type)
Convert a type number to the corresponding type string (e.g.
static uint32_t messenger_typename_to_number(void *cls, const char *gns_typename)
Convert a type name (e.g.
static int messenger_string_to_value(void *cls, uint32_t type, const char *s, void **data, size_t *data_size)
Convert human-readable version of a 'value' of a record to the binary representation.
uint32_t number
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
GNUNET_GNSRECORD_TypenameToNumberFunction typename_to_number
Typename to number.
GNUNET_GNSRECORD_NumberToTypenameFunction number_to_typename
Number to typename.
GNUNET_GNSRECORD_ValueToStringFunction value_to_string
Conversion to string.
void * cls
Closure for all of the callbacks.
GNUNET_GNSRECORD_StringToValueFunction string_to_value
Conversion to binary.
A 512-bit hashcode.
A room details record specifies a custom name for a given room and some additional space for flags.
uint32_t flags
The flags of the room.
A room entry record specifies which peer is hosting a given room and may also specify the key to ente...
struct GNUNET_PeerIdentity door
The peer identity of an open door to a room.
A room epoch key record specifies an epoch key for a given room that can be identified via a given ke...
uint32_t flags
The flags of the epoch or group key.
struct GNUNET_ShortHashCode identifier
The short hash identifying the epoch or group key.
struct GNUNET_CRYPTO_SymmetricSessionKey shared_key
The shared epoch or group key in the room.
struct GNUNET_HashCode hash
The hash identifying the epoch.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_CRYPTO_EddsaPublicKey public_key
A 256-bit hashcode.