GNUnet 0.22.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--2024 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
57
58 entry = value;
59
60 GNUNET_free (entry);
61 return GNUNET_YES;
62}
63
64
67 const struct GNUNET_HashCode *key,
68 void *value)
69{
70 struct GNUNET_MESSENGER_Message *message;
71
73
74 message = value;
75
76 destroy_message (message);
77 return GNUNET_YES;
78}
79
80
83 const struct GNUNET_HashCode *key,
84 void *value)
85{
86 struct GNUNET_HashCode *previous;
87
89
90 previous = value;
91
92 GNUNET_free (previous);
93 return GNUNET_YES;
94}
95
96
97void
99{
100 GNUNET_assert (store);
101
102 if (store->storage_messages)
103 {
105
106 store->storage_messages = NULL;
107 }
108
114 NULL);
117
122}
123
124
126{
129};
130
131#define load_message_store_attribute_failed(file, attribute) \
132 sizeof(attribute) != GNUNET_DISK_file_read (file, &(attribute), \
133 sizeof(attribute))
134
135#define save_message_store_attribute_failed(file, attribute) \
136 sizeof(attribute) != GNUNET_DISK_file_write (file, &(attribute), \
137 sizeof(attribute))
138
139static void
141 const char *filename)
142{
143 enum GNUNET_DISK_AccessPermissions permission;
144 struct GNUNET_DISK_FileHandle *entries;
146 struct GNUNET_MESSENGER_MessageEntry *entry;
147
148 permission = (GNUNET_DISK_PERM_USER_READ);
150 permission);
151
152 if (! entries)
153 return;
154
155 memset (&storage, 0, sizeof(storage));
156
157 do
158 {
159 entry = NULL;
160
161 if ((load_message_store_attribute_failed (entries, storage.hash)) ||
162 (load_message_store_attribute_failed (entries, storage.entry.offset)) ||
164 break;
165
167
168 GNUNET_memcpy (entry, &(storage.entry), sizeof(*entry));
169
171 &(storage.hash)))
172 ||
174 &(storage.hash), entry,
176 {
178 break;
179 }
180 }
181 while (entry);
182
183 if (entry)
184 GNUNET_free (entry);
185
186 GNUNET_DISK_file_close (entries);
187}
188
189
191{
194};
195
196static void
198 const char *filename)
199{
200 enum GNUNET_DISK_AccessPermissions permission;
201 struct GNUNET_DISK_FileHandle *entries;
203 struct GNUNET_MESSENGER_MessageLink *link;
204
205 permission = (GNUNET_DISK_PERM_USER_READ);
206
208 permission);
209
210 if (! entries)
211 return;
212
213 memset (&storage, 0, sizeof(storage));
214
215 do
216 {
217 link = NULL;
218
219 if ((load_message_store_attribute_failed (entries, storage.hash)) ||
221 storage.link.multiple)) ||
222 (load_message_store_attribute_failed (entries, storage.link.first)) ||
223 ((GNUNET_YES == storage.link.multiple) &&
224 (load_message_store_attribute_failed (entries, storage.link.second))))
225 break;
226
228
229 GNUNET_memcpy (link, &(storage.link), sizeof(*link));
230
232 &(storage.hash)))
233 ||
235 &(storage.hash), link,
237
238 break;
239 }
240 while (link);
241
242 if (link)
243 GNUNET_free (link);
244
245 GNUNET_DISK_file_close (entries);
246}
247
248
249void
251 const char *directory)
252{
253 enum GNUNET_DISK_AccessPermissions permission;
254 char *filename;
255
256 GNUNET_assert ((store) && (directory));
257
259
260 if (store->storage_messages)
262
263 GNUNET_asprintf (&filename, "%s%s", directory, "messages.store");
264
268 permission);
269 else
270 store->storage_messages = NULL;
271
273
274 if (! store->storage_messages)
275 return;
276
277 GNUNET_asprintf (&filename, "%s%s", directory, "entries.store");
278
281
283
284 GNUNET_asprintf (&filename, "%s%s", directory, "links.store");
285
288
290}
291
292
294{
296
298};
299
302 const struct GNUNET_HashCode *key,
303 void *value)
304{
306 struct GNUNET_MESSENGER_MessageLink *link;
307
308 GNUNET_assert ((cls) && (key) && (value));
309
310 save = cls;
311 link = value;
312
313 if ((save_message_store_attribute_failed (save->storage, (*key))) ||
316 return GNUNET_NO;
317
318 if ((GNUNET_YES == link->multiple) &&
320 return GNUNET_NO;
321
322 return GNUNET_YES;
323}
324
325
328 const struct GNUNET_HashCode *key,
329 void *value)
330{
332 struct GNUNET_MESSENGER_MessageEntry *entry;
333
334 GNUNET_assert ((cls) && (key) && (value));
335
336 save = cls;
337 entry = value;
338
339 if ((save_message_store_attribute_failed (save->storage, (*key))) ||
340 (save_message_store_attribute_failed (save->storage, entry->offset)) ||
342 return GNUNET_NO;
343
344 return GNUNET_YES;
345}
346
347
350 const struct GNUNET_HashCode *key,
351 void *value)
352{
355 struct GNUNET_MESSENGER_Message *message;
356
357 GNUNET_assert ((cls) && (key) && (value));
358
359 save = cls;
360
362 key))
363 return GNUNET_YES;
364
365 message = value;
366
367 GNUNET_memcpy (&(storage.hash), key, sizeof(storage.hash));
368
369 storage.entry.length = get_message_size (message, GNUNET_YES);
370 storage.entry.offset = GNUNET_DISK_file_seek (save->store->storage_messages,
372
373 if ((GNUNET_SYSERR == storage.entry.offset) ||
374 (save_message_store_attribute_failed (save->storage, storage.hash)) ||
376 storage.entry.offset)) ||
378 storage.entry.length)))
379 return GNUNET_NO;
380
381 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Storing message with hash: %s\n",
382 GNUNET_h2s (&(storage.hash)));
383
384 {
385 char *buffer;
386 buffer = GNUNET_malloc (storage.entry.length);
387
388 encode_message (message, storage.entry.length, buffer, GNUNET_YES);
389
390 GNUNET_DISK_file_write (save->store->storage_messages, buffer,
391 storage.entry.length);
392
393 GNUNET_free (buffer);
394 }
395
396 return GNUNET_YES;
397}
398
399
400void
402 const char *directory)
403{
405 enum GNUNET_DISK_AccessPermissions permission;
406 char *filename;
407
408 GNUNET_assert ((store) && (directory));
409
411
413 goto save_entries;
414
415 GNUNET_asprintf (&filename, "%s%s", directory, "links.store");
416
417 save.store = store;
419 | GNUNET_DISK_OPEN_CREATE, permission);
420
422
423 if (! save.storage)
424 goto save_entries;
425
426 if (GNUNET_SYSERR == GNUNET_DISK_file_seek (save.storage, 0,
428 goto close_links;
429
431 &save);
433
434close_links:
436
437save_entries:
438 GNUNET_asprintf (&filename, "%s%s", directory, "entries.store");
439
440 save.store = store;
442 | GNUNET_DISK_OPEN_CREATE, permission);
443
445
446 if (! save.storage)
447 return;
448
450 {
451 if (GNUNET_SYSERR == GNUNET_DISK_file_seek (save.storage, 0,
453 goto close_entries;
454
456 &save);
458 }
459 else if (GNUNET_SYSERR == GNUNET_DISK_file_seek (save.storage, 0,
461 goto close_entries;
462
465
466 GNUNET_asprintf (&filename, "%s%s", directory, "messages.store");
467
471 permission);
472
474
476 {
479
481 GNUNET_DISK_file_sync (save.storage);
482 }
483
484close_entries:
486}
487
488
491 const struct GNUNET_HashCode *hash)
492{
493 GNUNET_assert ((store) && (hash));
494
496 hash))
497 return GNUNET_YES;
498
500 hash))
501 return GNUNET_YES;
502
504}
505
506
507const struct GNUNET_MESSENGER_Message*
509 const struct GNUNET_HashCode *hash)
510{
511 struct GNUNET_MESSENGER_Message *message;
512 const struct GNUNET_MESSENGER_MessageEntry *entry;
513 enum GNUNET_GenericReturnValue decoding;
514 struct GNUNET_HashCode check;
515 char *buffer;
516
517 GNUNET_assert ((store) && (hash));
518
519 message = GNUNET_CONTAINER_multihashmap_get (store->messages, hash);
520
521 if (message)
522 return message;
523
524 message = GNUNET_CONTAINER_multihashmap_get (store->discourses, hash);
525
526 if (message)
527 return message;
528
529 if (! store->storage_messages)
530 return NULL;
531
532 entry = GNUNET_CONTAINER_multihashmap_get (store->entries, hash);
533
534 if (! entry)
535 return NULL;
536
537 if (entry->offset != GNUNET_DISK_file_seek (store->storage_messages,
538 entry->offset,
540 return message;
541
542 buffer = GNUNET_malloc (entry->length);
543
544 if (! buffer)
545 return NULL;
546
547 if ((GNUNET_DISK_file_read (store->storage_messages, buffer, entry->length) !=
548 entry->length) ||
550 GNUNET_YES)))
551 goto free_buffer;
552
554 decoding = decode_message (message, entry->length, buffer,
555 GNUNET_YES, NULL);
556
557 hash_message (message, entry->length, buffer, &check);
558
559 if ((GNUNET_YES != decoding) || (GNUNET_CRYPTO_hash_cmp (hash, &check) != 0))
560 {
562 hash, entry))
564 "Corrupted entry could not be removed from store: %s\n",
565 GNUNET_h2s (hash));
566
568
569 goto free_message;
570 }
571
573 message,
575
576 goto free_buffer;
577
578 free_message : destroy_message (message);
579 message = NULL;
580
581free_buffer:
582 GNUNET_free (buffer);
583
584 return message;
585}
586
587
590 const struct GNUNET_HashCode *hash,
591 enum GNUNET_GenericReturnValue deleted_only)
592{
593 const struct GNUNET_MESSENGER_Message *message;
594
595 if (deleted_only)
596 goto get_link;
597
598 message = get_store_message (store, hash);
599
600 if (message)
601 {
602 static struct GNUNET_MESSENGER_MessageLink link;
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 return &link;
618 }
619
620get_link:
621 return GNUNET_CONTAINER_multihashmap_get (store->links, hash);
622}
623
624
625static void
627 const struct GNUNET_HashCode *hash,
628 const struct GNUNET_MESSENGER_Message *message)
629{
630 struct GNUNET_MESSENGER_MessageLink *link;
631
632 GNUNET_assert ((store) && (hash) && (message));
633
635
636 GNUNET_memcpy (&(link->first), &(message->header.previous),
637 sizeof(link->first));
638
641
642 if (GNUNET_YES == link->multiple)
643 GNUNET_memcpy (&(link->second), &(message->body.merge.previous),
644 sizeof(link->second));
645 else
646 GNUNET_memcpy (&(link->second), &(message->header.previous),
647 sizeof(link->second));
648
649 if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (store->links, hash, link,
651
652 GNUNET_free (link);
653 else
654 store->write_links = GNUNET_YES;
655}
656
657
660 const struct GNUNET_HashCode *hash,
661 struct GNUNET_MESSENGER_Message *message)
662{
664
665 GNUNET_assert ((store) && (hash) && (message));
666
667 map = store->messages;
668
669 if (get_message_discourse (message))
670 map = store->discourses;
671
672 return GNUNET_CONTAINER_multihashmap_put (map, hash, message,
674}
675
676
679 const struct GNUNET_HashCode *hash)
680{
681 const struct GNUNET_MESSENGER_MessageEntry *entry;
682
683 GNUNET_assert ((store) && (hash));
684
685 entry = GNUNET_CONTAINER_multihashmap_get (store->entries, hash);
686
687 if (! entry)
688 goto clear_memory;
689
690 {
691 const struct GNUNET_MESSENGER_Message *message;
692 message = get_store_message (store, hash);
693
694 if (message)
695 add_link (store, hash, message);
696 }
697
698 if (! store->storage_messages)
699 goto clear_entry;
700
701 if (entry->offset != GNUNET_DISK_file_seek (store->storage_messages,
702 entry->offset,
704 return GNUNET_SYSERR;
705
706 {
707 char *clear_buffer;
708 clear_buffer = GNUNET_malloc (entry->length);
709
710 if (! clear_buffer)
711 return GNUNET_SYSERR;
712
713 GNUNET_CRYPTO_zero_keys (clear_buffer, entry->length);
714
715 if ((entry->length != GNUNET_DISK_file_write (store->storage_messages,
716 clear_buffer, entry->length)) ||
717 (GNUNET_OK
718 !=
720 store->storage_messages)))
721 {
722 GNUNET_free (clear_buffer);
723 return GNUNET_SYSERR;
724 }
725
726 GNUNET_free (clear_buffer);
727 }
728
729clear_entry:
731 entry))
733
734clear_memory:
736 return GNUNET_OK;
737}
738
739
741{
745};
746
749 const struct GNUNET_HashCode *key,
750 void *value)
751{
753 struct GNUNET_MESSENGER_Message *message;
754 const struct GNUNET_ShortHashCode *discourse;
755
756 GNUNET_assert ((cls) && (key) && (value));
757
758 cleanup = cls;
759 message = value;
760
761 discourse = get_message_discourse (message);
762
763 if ((! discourse) || (0 != GNUNET_memcmp (discourse, &(cleanup->discourse))))
764 return GNUNET_YES;
765
766 {
769
770 if (GNUNET_TIME_absolute_cmp(timestamp, >=, cleanup->timestamp))
771 return GNUNET_YES;
772 }
773
775 destroy_message(message);
776
777 return GNUNET_YES;
778}
779
780void
782 const struct GNUNET_ShortHashCode *discourse,
783 const struct GNUNET_TIME_Absolute timestamp)
784{
787
788 GNUNET_assert ((store) && (discourse));
789
791
792 cleanup.list = &list;
793 cleanup.timestamp = timestamp;
794
795 GNUNET_memcpy (&(cleanup.discourse), discourse,
796 sizeof (struct GNUNET_ShortHashCode));
797
800 &cleanup);
801
802 {
803 struct GNUNET_MESSENGER_ListMessage *element;
804 for (element = list.head; element; element = element->next)
806 }
807
809}
static int list
Set if we should print a list of currently running services.
Definition: gnunet-arm.c:68
static uint64_t timestamp(void)
Get current timestamp.
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:1234
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:520
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:697
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:206
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:660
@ 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:218
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:741
#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.