aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_dhtu_plugin.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/gnunet_dhtu_plugin.h')
-rw-r--r--src/include/gnunet_dhtu_plugin.h334
1 files changed, 334 insertions, 0 deletions
diff --git a/src/include/gnunet_dhtu_plugin.h b/src/include/gnunet_dhtu_plugin.h
new file mode 100644
index 000000000..f87d36719
--- /dev/null
+++ b/src/include/gnunet_dhtu_plugin.h
@@ -0,0 +1,334 @@
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/**
22 * @author Christian Grothoff
23 *
24 * @file
25 * API for DHT network underlay
26 */
27#ifndef PLUGIN_DHTU_H
28#define PLUGIN_DHTU_H
29
30#ifdef __cplusplus
31extern "C"
32{
33#if 0 /* keep Emacsens' auto-indent happy */
34}
35#endif
36#endif
37
38
39/**
40 * Opaque handle that the underlay offers for our address to be used when
41 * sending messages to another peer.
42 */
43struct GNUNET_DHTU_Source;
44
45/**
46 * Opaque handle that the underlay offers for the target peer when sending
47 * messages to another peer.
48 */
49struct GNUNET_DHTU_Target;
50
51/**
52 * Opaque handle expressing a preference of the DHT to
53 * keep a particular target connected.
54 */
55struct GNUNET_DHTU_PreferenceHandle;
56
57/**
58 * Opaque handle for a private key used by this underlay.
59 */
60struct GNUNET_DHTU_PrivateKey;
61
62/**
63 * Handle for a public key used by another peer. Note that
64 * the underlay used must be communicated separately.
65 */
66struct GNUNET_DHTU_PublicKey
67{
68 /**
69 * How long is the public key, in network byte order.
70 */
71 uint16_t size;
72
73 /* followed by size-2 bytes of the actual public key */
74};
75
76
77/**
78 * Hash used by the DHT for keys and peers.
79 */
80struct GNUNET_DHTU_Hash
81{
82
83 /**
84 * For now, use a 512 bit hash. (To be discussed).
85 */
86 struct GNUNET_HashCode hc;
87};
88
89
90/**
91 * @brief header of what an DHTU signature signs
92 * this must be followed by "size - 8" bytes of
93 * the actual signed data
94 */
95struct GNUNET_DHTU_SignaturePurpose
96{
97 /**
98 * How many bytes does this signature sign?
99 * (including this purpose header); in network
100 * byte order (!).
101 */
102 uint32_t size GNUNET_PACKED;
103
104 /**
105 * What does this signature vouch for? This
106 * must contain a GNUNET_SIGNATURE_PURPOSE_XXX
107 * constant (from gnunet_signatures.h). In
108 * network byte order!
109 */
110 uint32_t purpose GNUNET_PACKED;
111};
112
113
114/**
115 * The datastore service will pass a pointer to a struct
116 * of this type as the first and only argument to the
117 * entry point of each datastore plugin.
118 */
119struct GNUNET_DHTU_PluginEnvironment
120{
121 /**
122 * Configuration to use.
123 */
124 const struct GNUNET_CONFIGURATION_Handle *cfg;
125
126 /**
127 * Closure to use for callbacks.
128 */
129 void *cls;
130
131 /**
132 * Function to call with new addresses of this peer.
133 *
134 * @param cls the closure
135 * @param my_id hash position of this address in the DHT
136 * @param pk private key of this peer used at @a address,
137 * pointer will remain valid until @e address_del_cb is called
138 * @param address address under which we are likely reachable,
139 * pointer will remain valid until @e address_del_cb is called; to be used for HELLOs. Example: "ip+udp://1.1.1.1:2086/"
140 * @param source handle for sending from this address, NULL if we can only receive
141 * @param[out] ctx storage space for DHT to use in association with this address
142 */
143 void
144 (*address_add_cb)(void *cls,
145 const struct GNUNET_DHTU_Hash *my_id,
146 const struct GNUNET_DHTU_PrivateKey *pk,
147 const char *address,
148 struct GNUNET_DHTU_Source *source,
149 void **ctx);
150
151 /**
152 * Function to call with expired addresses of this peer.
153 *
154 * @param[in] ctx storage space used by the DHT in association with this address
155 */
156 void
157 (*address_del_cb)(void *ctx);
158
159 /**
160 * We have a new estimate on the size of the underlay.
161 *
162 * @param cls closure
163 * @param timestamp time when the estimate was received from the server (or created by the server)
164 * @param logestimate the log(Base 2) value of the current network size estimate
165 * @param std_dev standard deviation for the estimate
166 */
167 void
168 (*network_size_cb)(void *ctx,
169 struct GNUNET_TIME_Absolute timestamp,
170 double logestimate,
171 double std_dev);
172
173 /**
174 * Function to call when we connect to a peer and can henceforth transmit to
175 * that peer.
176 *
177 * @param cls the closure
178 * @param pk public key of the target,
179 * pointer will remain valid until @e disconnect_cb is called
180 * @para peer_id hash position of the peer,
181 * pointer will remain valid until @e disconnect_cb is called
182 * @param target handle to the target,
183 * pointer will remain valid until @e disconnect_cb is called
184 * @param sctx context of the source address on which the connection happened
185 * @param[out] ctx storage space for DHT to use in association with this target
186 */
187 void
188 (*connect_cb)(void *cls,
189 const struct GNUNET_DHTU_PublicKey *pk,
190 const struct GNUNET_DHTU_Hash *peer_id,
191 struct GNUNET_DHTU_Target *target,
192 void *sctx,
193 void **ctx);
194
195 /**
196 * Function to call when we disconnected from a peer and can henceforth
197 * cannot transmit to that peer anymore.
198 *
199 * @param[in] ctx storage space used by the DHT in association with this target
200 */
201 void
202 (*disconnect_cb)(void *ctx);
203
204 /**
205 * Function to call when we receive a message.
206 *
207 * @param cls the closure
208 * @param origin where the message originated from
209 * @param[in,out] tctx ctx of target address where we received the message from
210 * @param[in,out] sctx ctx of our own source address at which we received the message
211 * @param message the message we received @param message_size number of
212 * bytes in @a message
213 */
214 void
215 (*receive_cb)(void *cls,
216 void **tctx,
217 void **sctx,
218 const void *message,
219 size_t message_size);
220
221};
222
223
224/**
225 * @brief struct returned by the initialization function of the plugin
226 */
227struct GNUNET_DHTU_PluginFunctions
228{
229 /**
230 * Closure to pass to all plugin functions.
231 */
232 void *cls;
233
234 /**
235 * Use our private key to sign a message.
236 *
237 * @param cls closure
238 * @param pk our private key to sign with
239 * @param purpose what to sign
240 * @param[out] signature, allocated on heap and returned
241 * @return -1 on error, otherwise number of bytes in @a sig
242 */
243 ssize_t
244 (*sign)(void *cls,
245 const struct GNUNET_DHTU_PrivateKey *pk,
246 const struct GNUNET_DHTU_SignaturePurpose *purpose,
247 void **sig);
248
249 /**
250 * Verify signature in @a sig over @a purpose.
251 *
252 * @param cls closure
253 * @param pk public key to verify signature of
254 * @param purpose what was being signed
255 * @param sig signature data
256 * @param sig_size number of bytes in @a sig
257 * @return #GNUNET_OK if signature is valid
258 * #GNUNET_NO if signatures are not supported
259 * #GNUNET_SYSERR if signature is invalid
260 */
261 enum GNUNET_GenericReturnValue
262 (*verify)(void *cls,
263 const struct GNUNET_DHTU_PublicKey *pk,
264 const struct GNUNET_DHTU_SignaturePurpose *purpose,
265 const void *sig,
266 size_t sig_size);
267
268
269 /**
270 * Request creation of a session with a peer at the given @a address.
271 *
272 * @param cls closure (internal context for the plugin)
273 * @param pk public key of the target
274 * @param address target address to connect to
275 */
276 void
277 (*try_connect) (void *cls,
278 const char *address);
279
280 /**
281 * Request underlay to keep the connection to @a target alive if possible.
282 * Hold may be called multiple times to express a strong preference to
283 * keep a connection, say because a @a target is in multiple tables.
284 *
285 * @param cls closure
286 * @param target connection to keep alive
287 */
288 struct GNUNET_DHTU_PreferenceHandle *
289 (*hold)(void *cls,
290 struct GNUNET_DHTU_Target *target);
291
292 /**
293 * Do no long request underlay to keep the connection alive.
294 *
295 * @param cls closure
296 * @param target connection to keep alive
297 */
298 void
299 (*drop)(struct GNUNET_DHTU_PreferenceHandle *ph);
300
301 /**
302 * Send message to some other participant over the network. Note that
303 * sending is not guaranteeing that the other peer actually received the
304 * message. For any given @a target, the DHT must wait for the @a
305 * finished_cb to be called before calling send() again.
306 *
307 * @param cls closure (internal context for the plugin)
308 * @param target receiver identification
309 * @param msg message
310 * @param msg_size number of bytes in @a msg
311 * @param finished_cb function called once transmission is done
312 * (not called if @a target disconnects, then only the
313 * disconnect_cb is called).
314 * @param finished_cb_cls closure for @a finished_cb
315 */
316 void
317 (*send) (void *cls,
318 struct GNUNET_DHTU_Target *target,
319 const void *msg,
320 size_t msg_size,
321 GNUNET_SCHEDULER_TaskCallback finished_cb,
322 void *finished_cb_cls);
323
324};
325
326
327#if 0 /* keep Emacsens' auto-indent happy */
328{
329#endif
330#ifdef __cplusplus
331}
332#endif
333
334#endif