diff options
Diffstat (limited to 'src/messenger/gnunet-service-messenger_message_store.h')
-rw-r--r-- | src/messenger/gnunet-service-messenger_message_store.h | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/src/messenger/gnunet-service-messenger_message_store.h b/src/messenger/gnunet-service-messenger_message_store.h new file mode 100644 index 000000000..e58459b21 --- /dev/null +++ b/src/messenger/gnunet-service-messenger_message_store.h | |||
@@ -0,0 +1,120 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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 | */ | ||
20 | /** | ||
21 | * @author Tobias Frisch | ||
22 | * @file src/messenger/gnunet-service-messenger_message_store.h | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #ifndef GNUNET_SERVICE_MESSENGER_MESSAGE_STORE_H | ||
27 | #define GNUNET_SERVICE_MESSENGER_MESSAGE_STORE_H | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_container_lib.h" | ||
31 | #include "gnunet_disk_lib.h" | ||
32 | |||
33 | struct GNUNET_MESSENGER_MessageEntry | ||
34 | { | ||
35 | off_t offset; | ||
36 | uint16_t length; | ||
37 | }; | ||
38 | |||
39 | struct GNUNET_MESSENGER_MessageStore | ||
40 | { | ||
41 | struct GNUNET_DISK_FileHandle *storage_messages; | ||
42 | |||
43 | struct GNUNET_CONTAINER_MultiHashMap *entries; | ||
44 | struct GNUNET_CONTAINER_MultiHashMap *messages; | ||
45 | }; | ||
46 | |||
47 | /** | ||
48 | * Initializes a message store as fully empty. | ||
49 | * | ||
50 | * @param store Message store | ||
51 | */ | ||
52 | void | ||
53 | init_message_store (struct GNUNET_MESSENGER_MessageStore *store); | ||
54 | |||
55 | /** | ||
56 | * Clears a message store, wipes its content and deallocates its memory. | ||
57 | * | ||
58 | * @param store Message store | ||
59 | */ | ||
60 | void | ||
61 | clear_message_store (struct GNUNET_MESSENGER_MessageStore *store); | ||
62 | |||
63 | /** | ||
64 | * Loads messages from a directory into a message store. | ||
65 | * | ||
66 | * @param store Message store | ||
67 | * @param directory Path to a directory | ||
68 | */ | ||
69 | void | ||
70 | load_message_store (struct GNUNET_MESSENGER_MessageStore *store, const char *directory); | ||
71 | |||
72 | /** | ||
73 | * Saves messages from a message store into a directory. | ||
74 | * | ||
75 | * @param store Message store | ||
76 | * @param directory Path to a directory | ||
77 | */ | ||
78 | void | ||
79 | save_message_store (struct GNUNET_MESSENGER_MessageStore *store, const char *directory); | ||
80 | |||
81 | /** | ||
82 | * Checks if a message matching a given <i>hash</i> is stored in a message store. The function returns | ||
83 | * GNUNET_YES if a match is found, GNUNET_NO otherwise. | ||
84 | * | ||
85 | * The message has not to be loaded from disk into memory for this check! | ||
86 | * | ||
87 | * @param store Message store | ||
88 | * @param hash Hash of message | ||
89 | * @return GNUNET_YES on match, otherwise GNUNET_NO | ||
90 | */ | ||
91 | int | ||
92 | contains_store_message (struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash); | ||
93 | |||
94 | /** | ||
95 | * Returns the message from a message store matching a given <i>hash</i>. If no matching message is found, | ||
96 | * NULL gets returned. | ||
97 | * | ||
98 | * This function requires the message to be loaded into memory! | ||
99 | * @see contains_store_message() | ||
100 | * | ||
101 | * @param store Message store | ||
102 | * @param hash Hash of message | ||
103 | * @return Message or NULL | ||
104 | */ | ||
105 | const struct GNUNET_MESSENGER_Message* | ||
106 | get_store_message (struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash); | ||
107 | |||
108 | /** | ||
109 | * Stores a message into the message store. The result indicates if the operation was successful. | ||
110 | * | ||
111 | * @param store Message store | ||
112 | * @param hash Hash of message | ||
113 | * @param message Message | ||
114 | * @return GNUNET_OK on success, otherwise GNUNET_NO | ||
115 | */ | ||
116 | int | ||
117 | put_store_message (struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash, | ||
118 | struct GNUNET_MESSENGER_Message *message); | ||
119 | |||
120 | #endif //GNUNET_SERVICE_MESSENGER_MESSAGE_STORE_H | ||