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.h187
1 files changed, 187 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..e4b709c3b
--- /dev/null
+++ b/src/service/messenger/messenger_api_list_tunnels.h
@@ -0,0 +1,187 @@
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 "gnunet_messenger_service.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 struct GNUNET_MESSENGER_MessageConnection connection;
41};
42
43struct GNUNET_MESSENGER_ListTunnels
44{
45 struct GNUNET_MESSENGER_ListTunnel *head;
46 struct GNUNET_MESSENGER_ListTunnel *tail;
47};
48
49/**
50 * Initializes list of tunnels peer identities as empty list.
51 *
52 * @param[out] tunnels List of tunnels
53 */
54void
55init_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels);
56
57/**
58 * Clears the list of tunnels peer identities.
59 *
60 * @param[in,out] tunnels List of tunnels
61 */
62void
63clear_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels);
64
65/**
66 * Adds a specific <i>peer</i> from a tunnel to the end of the list.
67 *
68 * Optionally adds the <i>hash</i> of the peer message from the specific <i>peer</i>.
69 *
70 * @param[in,out] tunnels List of tunnels
71 * @param[in] peer Peer identity of tunnel
72 * @param[in] hash Hash of peer message or NULL
73 */
74void
75add_to_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels,
76 const struct GNUNET_PeerIdentity *peer,
77 const struct GNUNET_HashCode *hash);
78
79/**
80 * Searches linearly through the list of tunnels peer identities for matching a
81 * specific <i>peer</i> identity and returns the matching element of the list.
82 *
83 * If no matching element is found, NULL gets returned.
84 *
85 * If <i>index</i> is not NULL, <i>index</i> will be overridden with the numeric index of
86 * the found element in the list. If no matching element is found, <i>index</i> will
87 * contain the total amount of elements in the list.
88 *
89 * @param[in,out] tunnels List of tunnels
90 * @param[in] peer Peer identity of tunnel
91 * @param[out] index Index of found element (optional)
92 * @return Element in the list with matching peer identity
93 */
94struct GNUNET_MESSENGER_ListTunnel*
95find_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels,
96 const struct GNUNET_PeerIdentity *peer,
97 size_t *index);
98
99/**
100 * Searches linearly through the list of tunnels peer identities for matching
101 * against a specific <i>peer</i> identity and returns an element of the list
102 * which does not match it.
103 *
104 * @param[in,out] tunnels List of tunnels
105 * @param[in] peer Peer identity of tunnel
106 * @return Element in the list with unmatching peer identity
107 */
108struct GNUNET_MESSENGER_ListTunnel*
109find_list_tunnels_alternate (struct GNUNET_MESSENGER_ListTunnels *tunnels,
110 const struct GNUNET_PeerIdentity *peer);
111
112/**
113 * Verifies that a specific tunnel selected by its <i>peer</i> identity in a
114 * list of <i>tunnels</i> is the first in order with a given connection <i>flag</i>.
115 *
116 * @param[in] tunnels List of tunnels
117 * @param[in] peer Peer identity of tunnel
118 * @param[in] flag Connection flag mask
119 * @return #GNUNET_OK on success, otherwise #GNUNET_SYSERR
120 */
121enum GNUNET_GenericReturnValue
122verify_list_tunnels_flag_token (const struct
123 GNUNET_MESSENGER_ListTunnels *tunnels,
124 const struct GNUNET_PeerIdentity *peer,
125 enum GNUNET_MESSENGER_ConnectionFlags flag);
126
127/**
128 * Updates a specific <i>peer</i> from a tunnel in the list.
129 *
130 * This function exists to add the <i>hash</i> of a newer peer message
131 * from the specific <i>peer</i> to the list element. It can also remove
132 * the hash when NULL is provided as new <i>hash</i> value.
133 *
134 * @param[in,out] tunnels List of tunnels
135 * @param[in] peer Peer identity of tunnel
136 * @param[in] hash Hash of peer message or NULL
137 */
138void
139update_to_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels,
140 const struct GNUNET_PeerIdentity *peer,
141 const struct GNUNET_HashCode *hash);
142
143/**
144 * Tests linearly if the list of tunnels peer identities contains a specific
145 * <i>peer</i> identity and returns #GNUNET_YES on success, otherwise #GNUNET_NO.
146 *
147 * @param[in,out] tunnels List of tunnels
148 * @param[in] peer Peer identity of tunnel
149 * @return #GNUNET_YES on success, otherwise #GNUNET_NO
150 */
151enum GNUNET_GenericReturnValue
152contains_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels,
153 const struct GNUNET_PeerIdentity *peer);
154
155/**
156 * Removes a specific <i>element</i> from the list of tunnels peer identities and returns
157 * the next element in the list.
158 *
159 * @param[in,out] tunnels List of tunnels
160 * @param[in,out] element Element of the list
161 * @return Next element in the list
162 */
163struct GNUNET_MESSENGER_ListTunnel*
164remove_from_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels,
165 struct GNUNET_MESSENGER_ListTunnel *element);
166
167/**
168 * Loads the list of tunnels peer identities from a file under a given <i>path</i>.
169 *
170 * @param[out] tunnels List of tunnels
171 * @param[in] path Path of file
172 */
173void
174load_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels,
175 const char *path);
176
177/**
178 * Saves the list of tunnels peer identities to a file under a given <i>path</i>.
179 *
180 * @param[in] tunnels List of tunnels
181 * @param[in] path Path of file
182 */
183void
184save_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels,
185 const char *path);
186
187#endif //GNUNET_MESSENGER_API_LIST_TUNNELS_H