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