aboutsummaryrefslogtreecommitdiff
path: root/src/service/messenger/messenger_api_list_tunnels.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/service/messenger/messenger_api_list_tunnels.h')
-rw-r--r--src/service/messenger/messenger_api_list_tunnels.h157
1 files changed, 157 insertions, 0 deletions
diff --git a/src/service/messenger/messenger_api_list_tunnels.h b/src/service/messenger/messenger_api_list_tunnels.h
new file mode 100644
index 000000000..212f2ae21
--- /dev/null
+++ b/src/service/messenger/messenger_api_list_tunnels.h
@@ -0,0 +1,157 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2020--2023 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/messenger_api_list_tunnels.h
23 * @brief messenger api: client and service implementation of GNUnet MESSENGER service
24 */
25
26#ifndef GNUNET_MESSENGER_API_LIST_TUNNELS_H
27#define GNUNET_MESSENGER_API_LIST_TUNNELS_H
28
29#include "platform.h"
30#include "gnunet_util_lib.h"
31
32struct GNUNET_MESSENGER_ListTunnel
33{
34 struct GNUNET_MESSENGER_ListTunnel *prev;
35 struct GNUNET_MESSENGER_ListTunnel *next;
36
37 GNUNET_PEER_Id peer;
38 struct GNUNET_HashCode *hash;
39};
40
41struct GNUNET_MESSENGER_ListTunnels
42{
43 struct GNUNET_MESSENGER_ListTunnel *head;
44 struct GNUNET_MESSENGER_ListTunnel *tail;
45};
46
47/**
48 * Initializes list of tunnels peer identities as empty list.
49 *
50 * @param[out] tunnels List of peer identities
51 */
52void
53init_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels);
54
55/**
56 * Clears the list of tunnels peer identities.
57 *
58 * @param[in,out] tunnels List of peer identities
59 */
60void
61clear_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels);
62
63/**
64 * Adds a specific <i>peer</i> from a tunnel to the end of the list.
65 *
66 * Optionally adds the <i>hash</i> of the peer message from the specific <i>peer</i>.
67 *
68 * @param[in,out] tunnels List of peer identities
69 * @param[in] peer Peer identity of tunnel
70 * @param[in] hash Hash of peer message or NULL
71 */
72void
73add_to_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels,
74 const struct GNUNET_PeerIdentity *peer,
75 const struct GNUNET_HashCode *hash);
76
77/**
78 * Searches linearly through the list of tunnels peer identities for matching a
79 * specific <i>peer</i> identity and returns the matching element of the list.
80 *
81 * If no matching element is found, NULL gets returned.
82 *
83 * If <i>index</i> is not NULL, <i>index</i> will be overridden with the numeric index of
84 * the found element in the list. If no matching element is found, <i>index</i> will
85 * contain the total amount of elements in the list.
86 *
87 * @param[in,out] tunnels List of peer identities
88 * @param[in] peer Peer identity of tunnel
89 * @param[out] index Index of found element (optional)
90 * @return Element in the list with matching peer identity
91 */
92struct GNUNET_MESSENGER_ListTunnel*
93find_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels,
94 const struct GNUNET_PeerIdentity *peer,
95 size_t *index);
96
97/**
98 * Updates a specific <i>peer</i> from a tunnel in the list.
99 *
100 * This function exists to add the <i>hash</i> of a newer peer message
101 * from the specific <i>peer</i> to the list element. It can also remove
102 * the hash when NULL is provided as new <i>hash</i> value.
103 *
104 * @param[in,out] tunnels List of peer identities
105 * @param[in] peer Peer identity of tunnel
106 * @param[in] hash Hash of peer message or NULL
107 */
108void
109update_to_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels,
110 const struct GNUNET_PeerIdentity *peer,
111 const struct GNUNET_HashCode *hash);
112
113/**
114 * Tests linearly if the list of tunnels peer identities contains a specific
115 * <i>peer</i> identity and returns #GNUNET_YES on success, otherwise #GNUNET_NO.
116 *
117 * @param[in,out] tunnels List of peer identities
118 * @param[in] peer Peer identity of tunnel
119 * @return #GNUNET_YES on success, otherwise #GNUNET_NO
120 */
121int
122contains_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels,
123 const struct GNUNET_PeerIdentity *peer);
124
125/**
126 * Removes a specific <i>element</i> from the list of tunnels peer identities and returns
127 * the next element in the list.
128 *
129 * @param[in,out] tunnels List of peer identities
130 * @param[in,out] element Element of the list
131 * @return Next element in the list
132 */
133struct GNUNET_MESSENGER_ListTunnel*
134remove_from_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels,
135 struct GNUNET_MESSENGER_ListTunnel *element);
136
137/**
138 * Loads the list of tunnels peer identities from a file under a given <i>path</i>.
139 *
140 * @param[out] tunnels List of hashes
141 * @param[in] path Path of file
142 */
143void
144load_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels,
145 const char *path);
146
147/**
148 * Saves the list of tunnels peer identities to a file under a given <i>path</i>.
149 *
150 * @param[in] tunnels List of hashes
151 * @param[in] path Path of file
152 */
153void
154save_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels,
155 const char *path);
156
157#endif //GNUNET_MESSENGER_API_LIST_TUNNELS_H