aboutsummaryrefslogtreecommitdiff
path: root/src/messenger/gnunet-service-messenger_operation_store.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/messenger/gnunet-service-messenger_operation_store.h')
-rw-r--r--src/messenger/gnunet-service-messenger_operation_store.h131
1 files changed, 131 insertions, 0 deletions
diff --git a/src/messenger/gnunet-service-messenger_operation_store.h b/src/messenger/gnunet-service-messenger_operation_store.h
new file mode 100644
index 000000000..2fd604340
--- /dev/null
+++ b/src/messenger/gnunet-service-messenger_operation_store.h
@@ -0,0 +1,131 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 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_operation_store.h
23 * @brief GNUnet MESSENGER service
24 */
25
26#ifndef GNUNET_SERVICE_MESSENGER_OPERATION_STORE_H
27#define GNUNET_SERVICE_MESSENGER_OPERATION_STORE_H
28
29#include "platform.h"
30#include "gnunet_container_lib.h"
31#include "gnunet_crypto_lib.h"
32#include "gnunet_scheduler_lib.h"
33#include "gnunet_time_lib.h"
34
35struct GNUNET_MESSENGER_SrvRoom;
36
37struct GNUNET_MESSENGER_OperationStore
38{
39 struct GNUNET_MESSENGER_SrvRoom *room;
40
41 struct GNUNET_CONTAINER_MultiHashMap *operations;
42};
43
44/**
45 * Initializes an operation <i>store</i> as fully empty with a given <i>room</i>.
46 *
47 * @param[out] store Operation store
48 * @param[in/out] room Room
49 */
50void
51init_operation_store (struct GNUNET_MESSENGER_OperationStore *store, struct GNUNET_MESSENGER_SrvRoom *room);
52
53/**
54 * Clears an operation <i>store</i>, stops all operations and deallocates its memory.
55 *
56 * @param[in/out] store Operation store
57 */
58void
59clear_operation_store (struct GNUNET_MESSENGER_OperationStore *store);
60
61/**
62 * Loads operations from a <i>directory</i> into an operation <i>store</i>.
63 *
64 * @param[out] store Operation store
65 * @param[in] directory Path to a directory
66 */
67void
68load_operation_store (struct GNUNET_MESSENGER_OperationStore *store,
69 const char *directory);
70
71/**
72 * Saves operations from an operation <i>store</i> into a <i>directory</i>.
73 *
74 * @param[in] store Operation store
75 * @param[in] directory Path to a directory
76 */
77void
78save_operation_store (const struct GNUNET_MESSENGER_OperationStore *store,
79 const char *directory);
80
81/**
82 * Retruns the type of the active operation under a given <i>hash</i> in
83 * a specific operation <i>store</i>. If there is no active operation under
84 * the given <i>hash</i>, #GNUNET_MESSENGER_OP_UNKNOWN gets returned instead.
85 *
86 * @param[in] store Operation store
87 * @param[in] hash Hash of message
88 * @return Type of operation or #GNUNET_MESSENGER_OP_UNKNOWN
89 */
90enum GNUNET_MESSENGER_OperationType
91get_store_operation_type (const struct GNUNET_MESSENGER_OperationStore *store,
92 const struct GNUNET_HashCode *hash);
93
94/**
95 * Tries to use an operation under a given <i>hash</i> in a specific
96 * operation <i>store</i>. The operation will use the selected <i>type</i>
97 * if successful. The operation will be delayed by a given <i>delay</i>.
98 *
99 * If the selected type is #GNUNET_MESSENGER_OP_DELETE any active operation
100 * under the given hash will be stopped and replaced.
101 *
102 * If the new operation could be started successfully the method returns
103 * #GNUNET_OK, otherwise #GNUNET_SYSERR.
104 *
105 * @param[in/out] store Operation store
106 * @param[in] hash Hash of message
107 * @param[in] type Operation type
108 * @param[in] delay Delay
109 * @return #GNUNET_OK on success, otherwise #GNUNET_SYSERR
110 */
111int
112use_store_operation (struct GNUNET_MESSENGER_OperationStore *store,
113 const struct GNUNET_HashCode *hash,
114 enum GNUNET_MESSENGER_OperationType type,
115 struct GNUNET_TIME_Relative delay);
116
117/**
118 * Stops any active operation under a given <i>hash</i> in a specific
119 * operation <i>store</i>.
120 *
121 * Beware that calling this method will also implicitly free the memory
122 * of any active operation under the given hash!
123 *
124 * @param[in/out] store Operation store
125 * @param[in] hash Hash of message
126 */
127void
128cancel_store_operation (struct GNUNET_MESSENGER_OperationStore *store,
129 const struct GNUNET_HashCode *hash);
130
131#endif //GNUNET_SERVICE_MESSENGER_OPERATION_STORE_H