GNUnet 0.21.2
gnunet-service-messenger_message_store.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2020--2023 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
29
31
32void
34{
35 GNUNET_assert (store);
36
37 store->storage_messages = NULL;
38
43
45 store->write_links = GNUNET_NO;
46}
47
48
51 const struct GNUNET_HashCode *key,
52 void *value)
53{
55
56 GNUNET_free (entry);
57
58 return GNUNET_YES;
59}
60
61
64 const struct GNUNET_HashCode *key,
65 void *value)
66{
67 struct GNUNET_MESSENGER_Message *message = value;
68
69 destroy_message (message);
70
71 return GNUNET_YES;
72}
73
74
77 const struct GNUNET_HashCode *key,
78 void *value)
79{
80 struct GNUNET_HashCode *previous = value;
81
82 GNUNET_free (previous);
83
84 return GNUNET_YES;
85}
86
87
88void
90{
91 GNUNET_assert (store);
92
93 if (store->storage_messages)
94 {
96
97 store->storage_messages = NULL;
98 }
99
105 NULL);
108
113}
114
115
117{
120};
121
122#define load_message_store_attribute_failed(file, attribute) \
123 sizeof(attribute) != GNUNET_DISK_file_read (file, &(attribute), \
124 sizeof(attribute))
125
126#define save_message_store_attribute_failed(file, attribute) \
127 sizeof(attribute) != GNUNET_DISK_file_write (file, &(attribute), \
128 sizeof(attribute))
129
130static void
132 const char *filename)
133{
135
138 permission);
139
140 if (! entries)
141 return;
142
144 struct GNUNET_MESSENGER_MessageEntry *entry;
145
146 memset (&storage, 0, sizeof(storage));
147
148 do
149 {
150 entry = NULL;
151
152 if ((load_message_store_attribute_failed (entries, storage.hash)) ||
153 (load_message_store_attribute_failed (entries, storage.entry.offset)) ||
155 break;
156
158
159 GNUNET_memcpy (entry, &(storage.entry), sizeof(*entry));
160
162 &(storage.hash)))
163 ||
165 &(storage.hash), entry,
167 {
169 break;
170 }
171 }
172 while (entry);
173
174 if (entry)
175 GNUNET_free (entry);
176
177 GNUNET_DISK_file_close (entries);
178}
179
180
182{
185};
186
187static void
189 const char *filename)
190{
192
195 permission);
196
197 if (! entries)
198 return;
199
201 struct GNUNET_MESSENGER_MessageLink *link;
202
203 memset (&storage, 0, sizeof(storage));
204
205 do
206 {
207 link = NULL;
208
209 if ((load_message_store_attribute_failed (entries, storage.hash)) ||
211 storage.link.multiple)) ||
212 (load_message_store_attribute_failed (entries, storage.link.first)) ||
213 ((GNUNET_YES == storage.link.multiple) &&
214 (load_message_store_attribute_failed (entries, storage.link.second))))
215 break;
216
218
219 GNUNET_memcpy (link, &(storage.link), sizeof(*link));
220
222 &(storage.hash)))
223 ||
225 &(storage.hash), link,
227
228 break;
229 }
230 while (link);
231
232 if (link)
233 GNUNET_free (link);
234
235 GNUNET_DISK_file_close (entries);
236}
237
238
239void
241 const char *directory)
242{
243 GNUNET_assert ((store) && (directory));
244
247 );
248
249 if (store->storage_messages)
251
252 char *filename;
253 GNUNET_asprintf (&filename, "%s%s", directory, "messages.store");
254
258 permission);
259 else
260 store->storage_messages = NULL;
261
263
264 if (! store->storage_messages)
265 return;
266
267 GNUNET_asprintf (&filename, "%s%s", directory, "entries.store");
268
271
273
274 GNUNET_asprintf (&filename, "%s%s", directory, "links.store");
275
278
280}
281
282
284{
286
288};
289
292 const struct GNUNET_HashCode *key,
293 void *value)
294{
296 struct GNUNET_MESSENGER_MessageLink *link = value;
297
298 if ((save_message_store_attribute_failed (save->storage, (*key))) ||
301 return GNUNET_NO;
302
303 if ((GNUNET_YES == link->multiple) &&
305 return GNUNET_NO;
306
307 return GNUNET_YES;
308}
309
310
313 const struct GNUNET_HashCode *key,
314 void *value)
315{
317 struct GNUNET_MESSENGER_MessageEntry *entry = value;
318
319 if ((save_message_store_attribute_failed (save->storage, (*key))) ||
320 (save_message_store_attribute_failed (save->storage, entry->offset)) ||
322 return GNUNET_NO;
323
324 return GNUNET_YES;
325}
326
327
330 const struct GNUNET_HashCode *key,
331 void *value)
332{
334
336 key))
337 return GNUNET_YES;
338
339 struct GNUNET_MESSENGER_Message *message = value;
341
342 GNUNET_memcpy (&(storage.hash), key, sizeof(storage.hash));
343
344 storage.entry.length = get_message_size (message, GNUNET_YES);
345 storage.entry.offset = GNUNET_DISK_file_seek (save->store->storage_messages,
347
348 if ((GNUNET_SYSERR == storage.entry.offset) ||
349 (save_message_store_attribute_failed (save->storage, storage.hash)) ||
351 storage.entry.offset)) ||
353 storage.entry.length)))
354 return GNUNET_NO;
355
356 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Storing message with hash: %s\n",
357 GNUNET_h2s (&(storage.hash)));
358
359 char *buffer = GNUNET_malloc (storage.entry.length);
360
361 encode_message (message, storage.entry.length, buffer, GNUNET_YES);
362
363 GNUNET_DISK_file_write (save->store->storage_messages, buffer,
364 storage.entry.length);
365
366 GNUNET_free (buffer);
367 return GNUNET_YES;
368}
369
370
371void
373 const char *directory)
374{
375 GNUNET_assert ((store) && (directory));
376
378
381 );
382
383 char *filename;
384
386 goto save_entries;
387
388 GNUNET_asprintf (&filename, "%s%s", directory, "links.store");
389
390 save.store = store;
392 | GNUNET_DISK_OPEN_CREATE, permission);
393
395
396 if (! save.storage)
397 goto save_entries;
398
399 if (GNUNET_SYSERR == GNUNET_DISK_file_seek (save.storage, 0,
401 goto close_links;
402
404 &save);
406
407close_links:
409
410save_entries:
411 GNUNET_asprintf (&filename, "%s%s", directory, "entries.store");
412
413 save.store = store;
415 | GNUNET_DISK_OPEN_CREATE, permission);
416
418
419 if (! save.storage)
420 return;
421
423 {
424 if (GNUNET_SYSERR == GNUNET_DISK_file_seek (save.storage, 0,
426 goto close_entries;
427
429 &save);
431 }
432 else if (GNUNET_SYSERR == GNUNET_DISK_file_seek (save.storage, 0,
434 goto close_entries;
435
438
439 GNUNET_asprintf (&filename, "%s%s", directory, "messages.store");
440
444 permission);
445
447
449 {
452
454 GNUNET_DISK_file_sync (save.storage);
455 }
456
457close_entries:
459}
460
461
464 const struct GNUNET_HashCode *hash)
465{
466 GNUNET_assert ((store) && (hash));
467
469 hash))
470 return GNUNET_YES;
471
473 hash))
474 return GNUNET_YES;
475
477}
478
479
480const struct GNUNET_MESSENGER_Message*
482 const struct GNUNET_HashCode *hash)
483{
484 GNUNET_assert ((store) && (hash));
485
487 store->messages, hash);
488
489 if (message)
490 return message;
491
492 message = GNUNET_CONTAINER_multihashmap_get (store->discourses, hash);
493
494 if (message)
495 return message;
496
497 if (! store->storage_messages)
498 return NULL;
499
500 const struct GNUNET_MESSENGER_MessageEntry *entry =
502
503 if (! entry)
504 return NULL;
505
506 if (entry->offset != GNUNET_DISK_file_seek (store->storage_messages,
507 entry->offset,
509 return message;
510
511 char *buffer = GNUNET_malloc (entry->length);
512
513 if (! buffer)
514 return NULL;
515
516 if ((GNUNET_DISK_file_read (store->storage_messages, buffer, entry->length) !=
517 entry->length) ||
519 GNUNET_YES)))
520 goto free_buffer;
521
523
524 enum GNUNET_GenericReturnValue decoding;
525 decoding = decode_message (message, entry->length, buffer,
526 GNUNET_YES, NULL);
527
528 struct GNUNET_HashCode check;
529 hash_message (message, entry->length, buffer, &check);
530
531 if ((GNUNET_YES != decoding) || (GNUNET_CRYPTO_hash_cmp (hash, &check) != 0))
532 {
534 hash, entry))
536 "Corrupted entry could not be removed from store: %s\n",
537 GNUNET_h2s (hash));
538
540
541 goto free_message;
542 }
543
545 message,
547
548 goto free_buffer;
549
550 free_message : destroy_message (message);
551 message = NULL;
552
553free_buffer:
554 GNUNET_free (buffer);
555
556 return message;
557}
558
559
562 const struct GNUNET_HashCode *hash,
563 enum GNUNET_GenericReturnValue deleted_only)
564{
565 if (deleted_only)
566 goto get_link;
567
568 const struct GNUNET_MESSENGER_Message *message = get_store_message (store,
569 hash);
570
571 if (! message)
572 goto get_link;
573
574 static struct GNUNET_MESSENGER_MessageLink link;
575
576 GNUNET_memcpy (&(link.first), &(message->header.previous),
577 sizeof(link.first));
578
581
582 if (GNUNET_YES == link.multiple)
583 GNUNET_memcpy (&(link.second), &(message->body.merge.previous),
584 sizeof(link.second));
585 else
586 GNUNET_memcpy (&(link.second), &(message->header.previous),
587 sizeof(link.second));
588
589 return &link;
590
591get_link:
592 return GNUNET_CONTAINER_multihashmap_get (store->links, hash);
593}
594
595
596static void
598 const struct GNUNET_HashCode *hash,
599 const struct GNUNET_MESSENGER_Message *message)
600{
601 struct GNUNET_MESSENGER_MessageLink *link = GNUNET_new (struct
603
604 GNUNET_memcpy (&(link->first), &(message->header.previous),
605 sizeof(link->first));
606
609
610 if (GNUNET_YES == link->multiple)
611 GNUNET_memcpy (&(link->second), &(message->body.merge.previous),
612 sizeof(link->second));
613 else
614 GNUNET_memcpy (&(link->second), &(message->header.previous),
615 sizeof(link->second));
616
617 if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (store->links, hash, link,
619
620 GNUNET_free (link);
621 else
622 store->write_links = GNUNET_YES;
623}
624
625
628 const struct GNUNET_HashCode *hash,
629 struct GNUNET_MESSENGER_Message *message)
630{
631 GNUNET_assert ((store) && (hash) && (message));
632
634
635 if (get_message_discourse (message))
636 map = store->discourses;
637
638 return GNUNET_CONTAINER_multihashmap_put (map, hash, message,
640}
641
642
645 const struct GNUNET_HashCode *hash)
646{
647 GNUNET_assert ((store) && (hash));
648
649 const struct GNUNET_MESSENGER_MessageEntry *entry =
651
652 if (! entry)
653 goto clear_memory;
654
655 const struct GNUNET_MESSENGER_Message *message = get_store_message (store,
656 hash);
657
658 if (message)
659 add_link (store, hash, message);
660
661 if (! store->storage_messages)
662 goto clear_entry;
663
664 if (entry->offset != GNUNET_DISK_file_seek (store->storage_messages,
665 entry->offset,
667 return GNUNET_SYSERR;
668
669 char *clear_buffer = GNUNET_malloc (entry->length);
670
671 if (! clear_buffer)
672 return GNUNET_SYSERR;
673
674 GNUNET_CRYPTO_zero_keys (clear_buffer, entry->length);
675
676 if ((entry->length != GNUNET_DISK_file_write (store->storage_messages,
677 clear_buffer, entry->length)) ||
678 (GNUNET_OK
679 !=
681 store->storage_messages)))
682 {
683 GNUNET_free (clear_buffer);
684 return GNUNET_SYSERR;
685 }
686
687 GNUNET_free (clear_buffer);
688
689clear_entry:
691 entry))
693
694clear_memory:
696 return GNUNET_OK;
697}
698
699
701{
705};
706
709 const struct GNUNET_HashCode *key,
710 void *value)
711{
713 struct GNUNET_MESSENGER_Message *message = value;
714
715 const struct GNUNET_ShortHashCode *discourse = get_message_discourse (message);
716
717 if ((! discourse) || (0 != GNUNET_memcmp (discourse, &(cleanup->discourse))))
718 return GNUNET_YES;
719
720 struct GNUNET_TIME_Absolute timestamp =
722
723 if (GNUNET_TIME_absolute_cmp(timestamp, >=, cleanup->timestamp))
724 return GNUNET_YES;
725
727 destroy_message(message);
728
729 return GNUNET_YES;
730}
731
732void
734 const struct GNUNET_ShortHashCode *discourse,
735 const struct GNUNET_TIME_Absolute timestamp)
736{
737 GNUNET_assert ((store) && (discourse));
738
741
743 cleanup.list = &list;
744 cleanup.timestamp = timestamp;
745
746 GNUNET_memcpy (&(cleanup.discourse), discourse,
747 sizeof (struct GNUNET_ShortHashCode));
748
751 &cleanup);
752
753 struct GNUNET_MESSENGER_ListMessage *element;
754 for (element = list.head; element; element = element->next)
756
758}
static int list
Set if we should print a list of currently running services.
Definition: gnunet-arm.c:69
struct GNUNET_HashCode key
The key used in the DHT.
static void cleanup(void *cls)
Disconnect and shutdown.
Definition: gnunet-did.c:131
static char * filename
static char * value
Value of the record to add/remove.
void clear_list_messages(struct GNUNET_MESSENGER_ListMessages *messages)
Clears the list of message hashes.
void init_list_messages(struct GNUNET_MESSENGER_ListMessages *messages)
Initializes list of message hashes as empty list.
void add_to_list_messages(struct GNUNET_MESSENGER_ListMessages *messages, const struct GNUNET_HashCode *hash)
Adds a specific hash from a message to the end of the list.
static enum GNUNET_GenericReturnValue iterate_save_entries(void *cls, const struct GNUNET_HashCode *key, void *value)
static enum GNUNET_GenericReturnValue iterate_destroy_entries(void *cls, const struct GNUNET_HashCode *key, void *value)
static enum GNUNET_GenericReturnValue iterate_destroy_messages(void *cls, const struct GNUNET_HashCode *key, void *value)
enum GNUNET_GenericReturnValue contains_store_message(const struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash)
Checks if a message matching a given hash is stored in a message store.
void save_message_store(struct GNUNET_MESSENGER_MessageStore *store, const char *directory)
Saves messages from a message store into a directory.
static enum GNUNET_GenericReturnValue iterate_flag_for_cleanup_discourse_message(void *cls, const struct GNUNET_HashCode *key, void *value)
enum GNUNET_GenericReturnValue put_store_message(struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash, struct GNUNET_MESSENGER_Message *message)
Stores a message into the message store.
static void load_message_store_entries(struct GNUNET_MESSENGER_MessageStore *store, const char *filename)
void clear_message_store(struct GNUNET_MESSENGER_MessageStore *store)
Clears a message store, wipes its content and deallocates its memory.
#define load_message_store_attribute_failed(file, attribute)
enum GNUNET_GenericReturnValue delete_store_message(struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash)
Deletes a message in the message store.
void init_message_store(struct GNUNET_MESSENGER_MessageStore *store)
Initializes a message store as fully empty.
static enum GNUNET_GenericReturnValue iterate_save_links(void *cls, const struct GNUNET_HashCode *key, void *value)
void cleanup_store_discourse_messages_before(struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_ShortHashCode *discourse, const struct GNUNET_TIME_Absolute timestamp)
Cleans up and deletes all discourse messages existing in the message store memory before a certain ti...
#define save_message_store_attribute_failed(file, attribute)
static void load_message_store_links(struct GNUNET_MESSENGER_MessageStore *store, const char *filename)
void load_message_store(struct GNUNET_MESSENGER_MessageStore *store, const char *directory)
Loads messages from a directory into a message store.
static enum GNUNET_GenericReturnValue iterate_destroy_links(void *cls, const struct GNUNET_HashCode *key, void *value)
const struct GNUNET_MESSENGER_MessageLink * get_store_message_link(struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash, enum GNUNET_GenericReturnValue deleted_only)
Returns the message link from a message store matching a given hash.
static enum GNUNET_GenericReturnValue iterate_save_messages(void *cls, const struct GNUNET_HashCode *key, void *value)
const struct GNUNET_MESSENGER_Message * get_store_message(struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash)
Returns the message from a message store matching a given hash.
static void add_link(struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_Message *message)
static void save()
Write persistent statistics to disk.
void GNUNET_CRYPTO_zero_keys(void *buffer, size_t length)
Zero out buffer, securely against compiler optimizations.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1237
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
Definition: disk.c:482
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:686
off_t GNUNET_DISK_file_seek(const struct GNUNET_DISK_FileHandle *h, off_t offset, enum GNUNET_DISK_Seek whence)
Move the read/write pointer in a file.
Definition: disk.c:205
GNUNET_DISK_AccessPermissions
File access permissions, UNIX-style.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_sync(const struct GNUNET_DISK_FileHandle *h)
Write file changes to disk.
Definition: disk.c:1427
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1308
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:622
@ GNUNET_DISK_OPEN_READ
Open the file for reading.
@ GNUNET_DISK_OPEN_WRITE
Open the file for writing.
@ GNUNET_DISK_OPEN_CREATE
Create file if it doesn't exist.
@ GNUNET_DISK_OPEN_READWRITE
Open the file for both reading and writing.
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
@ GNUNET_DISK_SEEK_SET
Seek an absolute position (from the start of the file).
@ GNUNET_DISK_SEEK_END
Seek an absolute position from the end of the file.
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.
Definition: crypto_hash.c:221
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_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.
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.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE...
#define GNUNET_log(kind,...)
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
#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
@ GNUNET_SYSERR
#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).
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#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.
@ GNUNET_MESSENGER_KIND_UNKNOWN
The unknown kind.
@ GNUNET_MESSENGER_KIND_MERGE
The merge kind.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:737
#define GNUNET_TIME_absolute_cmp(t1, op, t2)
Compare two absolute times.
void encode_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, enum GNUNET_GenericReturnValue include_header)
Encodes a given message into a buffer of a maximal length in bytes.
const struct GNUNET_ShortHashCode * get_message_discourse(const struct GNUNET_MESSENGER_Message *message)
Returns the discourse hash of a message depending on its kind.
void hash_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, struct GNUNET_HashCode *hash)
Calculates a hash of a given buffer with a length in bytes from a message.
struct GNUNET_MESSENGER_Message * create_message(enum GNUNET_MESSENGER_MessageKind kind)
Creates and allocates a new message with a specific kind.
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
uint16_t get_message_kind_size(enum GNUNET_MESSENGER_MessageKind kind, enum GNUNET_GenericReturnValue include_header)
Returns the minimal size in bytes to encode a message of a specific kind.
uint16_t get_message_size(const struct GNUNET_MESSENGER_Message *message, enum GNUNET_GenericReturnValue include_header)
Returns the exact size in bytes to encode a given message.
enum GNUNET_GenericReturnValue decode_message(struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, enum GNUNET_GenericReturnValue include_header, uint16_t *padding)
Decodes a message from a given buffer of a maximal length in bytes.
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.
Handle used to access files (and pipes).
A 512-bit hashcode.
struct GNUNET_MESSENGER_ListMessage * next
struct GNUNET_MESSENGER_MessageMerge merge
struct GNUNET_HashCode previous
The hash of the previous message from the senders perspective.
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
struct GNUNET_TIME_AbsoluteNBO timestamp
The timestamp of the message.
struct GNUNET_HashCode previous
The hash of a second previous message.
struct GNUNET_CONTAINER_MultiHashMap * links
struct GNUNET_DISK_FileHandle * storage_messages
struct GNUNET_CONTAINER_MultiHashMap * messages
struct GNUNET_CONTAINER_MultiHashMap * entries
struct GNUNET_CONTAINER_MultiHashMap * discourses
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_MESSENGER_MessageBody body
Body.
A 256-bit hashcode.
Time for absolute times used by GNUnet, in microseconds.