diff options
Diffstat (limited to 'src/service/messenger/gnunet-service-messenger_message_store.h')
-rw-r--r-- | src/service/messenger/gnunet-service-messenger_message_store.h | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/src/service/messenger/gnunet-service-messenger_message_store.h b/src/service/messenger/gnunet-service-messenger_message_store.h new file mode 100644 index 000000000..262d10555 --- /dev/null +++ b/src/service/messenger/gnunet-service-messenger_message_store.h | |||
@@ -0,0 +1,168 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020--2021 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_util_lib.h" | ||
31 | |||
32 | struct GNUNET_MESSENGER_MessageEntry | ||
33 | { | ||
34 | off_t offset; | ||
35 | uint16_t length; | ||
36 | }; | ||
37 | |||
38 | struct GNUNET_MESSENGER_Message; | ||
39 | |||
40 | struct GNUNET_MESSENGER_MessageLink | ||
41 | { | ||
42 | uint8_t multiple; | ||
43 | |||
44 | struct GNUNET_HashCode first; | ||
45 | struct GNUNET_HashCode second; | ||
46 | }; | ||
47 | |||
48 | struct GNUNET_MESSENGER_MessageStore | ||
49 | { | ||
50 | struct GNUNET_DISK_FileHandle *storage_messages; | ||
51 | |||
52 | struct GNUNET_CONTAINER_MultiHashMap *entries; | ||
53 | struct GNUNET_CONTAINER_MultiHashMap *messages; | ||
54 | struct GNUNET_CONTAINER_MultiHashMap *links; | ||
55 | |||
56 | int rewrite_entries; | ||
57 | int write_links; | ||
58 | }; | ||
59 | |||
60 | /** | ||
61 | * Initializes a message <i>store</i> as fully empty. | ||
62 | * | ||
63 | * @param[out] store Message store | ||
64 | */ | ||
65 | void | ||
66 | init_message_store (struct GNUNET_MESSENGER_MessageStore *store); | ||
67 | |||
68 | /** | ||
69 | * Clears a message <i>store</i>, wipes its content and deallocates its memory. | ||
70 | * | ||
71 | * @param[in,out] store Message store | ||
72 | */ | ||
73 | void | ||
74 | clear_message_store (struct GNUNET_MESSENGER_MessageStore *store); | ||
75 | |||
76 | /** | ||
77 | * Loads messages from a <i>directory</i> into a message <i>store</i>. | ||
78 | * | ||
79 | * @param[out] store Message store | ||
80 | * @param[in] directory Path to a directory | ||
81 | */ | ||
82 | void | ||
83 | load_message_store (struct GNUNET_MESSENGER_MessageStore *store, | ||
84 | const char *directory); | ||
85 | |||
86 | /** | ||
87 | * Saves messages from a message <i>store</i> into a <i>directory</i>. | ||
88 | * | ||
89 | * @param[in] store Message store | ||
90 | * @param[in] directory Path to a directory | ||
91 | */ | ||
92 | void | ||
93 | save_message_store (struct GNUNET_MESSENGER_MessageStore *store, | ||
94 | const char *directory); | ||
95 | |||
96 | /** | ||
97 | * Checks if a message matching a given <i>hash</i> is stored in a message <i>store</i>. | ||
98 | * The function returns #GNUNET_YES if a match is found, #GNUNET_NO otherwise. | ||
99 | * | ||
100 | * The message has not to be loaded from disk into memory for this check! | ||
101 | * | ||
102 | * @param[in] store Message store | ||
103 | * @param[in] hash Hash of message | ||
104 | * @return #GNUNET_YES on match, otherwise #GNUNET_NO | ||
105 | */ | ||
106 | int | ||
107 | contains_store_message (const struct GNUNET_MESSENGER_MessageStore *store, | ||
108 | const struct GNUNET_HashCode *hash); | ||
109 | |||
110 | /** | ||
111 | * Returns the message from a message <i>store</i> matching a given <i>hash</i>. If no matching | ||
112 | * message is found, NULL gets returned. | ||
113 | * | ||
114 | * This function requires the message to be loaded into memory! | ||
115 | * @see contains_store_message() | ||
116 | * | ||
117 | * @param[in,out] store Message store | ||
118 | * @param[in] hash Hash of message | ||
119 | * @return Message or NULL | ||
120 | */ | ||
121 | const struct GNUNET_MESSENGER_Message* | ||
122 | get_store_message (struct GNUNET_MESSENGER_MessageStore *store, | ||
123 | const struct GNUNET_HashCode *hash); | ||
124 | |||
125 | /** | ||
126 | * Returns the message link from a message <i>store</i> matching a given <i>hash</i>. If the | ||
127 | * flag is set to #GNUNET_YES, only links from deleted messages will be returned or NULL. | ||
128 | * | ||
129 | * Otherwise message links will also returned for messages found in the store under the given | ||
130 | * hash. The link which will be returned copies link information from the message for | ||
131 | * temporary usage. | ||
132 | * | ||
133 | * @param[in,out] store Message store | ||
134 | * @param[in] hash Hash of message | ||
135 | * @param[in] deleted_only Flag | ||
136 | * @return Message link or NULL | ||
137 | */ | ||
138 | const struct GNUNET_MESSENGER_MessageLink* | ||
139 | get_store_message_link (struct GNUNET_MESSENGER_MessageStore *store, | ||
140 | const struct GNUNET_HashCode *hash, | ||
141 | int deleted_only); | ||
142 | |||
143 | /** | ||
144 | * Stores a message into the message store. The result indicates if the operation was successful. | ||
145 | * | ||
146 | * @param[in,out] store Message store | ||
147 | * @param[in] hash Hash of message | ||
148 | * @param[in,out] message Message | ||
149 | * @return #GNUNET_OK on success, otherwise #GNUNET_NO | ||
150 | */ | ||
151 | int | ||
152 | put_store_message (struct GNUNET_MESSENGER_MessageStore *store, | ||
153 | const struct GNUNET_HashCode *hash, | ||
154 | struct GNUNET_MESSENGER_Message *message); | ||
155 | |||
156 | /** | ||
157 | * Deletes a message in the message store. It will be removed from disk space and memory. The result | ||
158 | * indicates if the operation was successful. | ||
159 | * | ||
160 | * @param[in,out] store Message store | ||
161 | * @param[in] hash Hash of message | ||
162 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | ||
163 | */ | ||
164 | int | ||
165 | delete_store_message (struct GNUNET_MESSENGER_MessageStore *store, | ||
166 | const struct GNUNET_HashCode *hash); | ||
167 | |||
168 | #endif //GNUNET_SERVICE_MESSENGER_MESSAGE_STORE_H | ||