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