aboutsummaryrefslogtreecommitdiff
path: root/src/service/cadet/gnunet-service-cadet_peer.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/service/cadet/gnunet-service-cadet_peer.h')
-rw-r--r--src/service/cadet/gnunet-service-cadet_peer.h433
1 files changed, 433 insertions, 0 deletions
diff --git a/src/service/cadet/gnunet-service-cadet_peer.h b/src/service/cadet/gnunet-service-cadet_peer.h
new file mode 100644
index 000000000..4c5ad4252
--- /dev/null
+++ b/src/service/cadet/gnunet-service-cadet_peer.h
@@ -0,0 +1,433 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2001-2017 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 * @file cadet/gnunet-service-cadet_peer.h
23 * @brief Information we track per peer.
24 * @author Bartlomiej Polot
25 * @author Christian Grothoff
26 */
27#ifndef GNUNET_SERVICE_CADET_PEER_H
28#define GNUNET_SERVICE_CADET_PEER_H
29
30#include "gnunet-service-cadet.h"
31#include "gnunet_util_lib.h"
32
33
34/**
35 * Get the static string for a peer ID.
36 *
37 * @param peer Peer.
38 *
39 * @return Static string for it's ID.
40 */
41const char *
42GCP_2s (const struct CadetPeer *peer);
43
44
45/**
46 * Retrieve the CadetPeer structure associated with the
47 * peer. Optionally create one and insert it in the appropriate
48 * structures if the peer is not known yet.
49 *
50 * @param peer_id Full identity of the peer.
51 * @param create #GNUNET_YES if a new peer should be created if unknown.
52 * #GNUNET_NO to return NULL if peer is unknown.
53 * @return Existing or newly created peer structure.
54 * NULL if unknown and not requested @a create
55 */
56struct CadetPeer *
57GCP_get (const struct GNUNET_PeerIdentity *peer_id,
58 int create);
59
60
61/**
62 * Calculate how desirable a path is for @a cp if
63 * @a cp is at offset @a off in the path.
64 *
65 * The 'desirability_table.c' program can be used to compute a list of
66 * sample outputs for different scenarios. Basically, we score paths
67 * lower if there are many alternatives, and higher if they are
68 * shorter than average, and very high if they are much shorter than
69 * average and without many alternatives.
70 *
71 * @param cp a peer reachable via a path
72 * @param off offset of @a cp in a path
73 * @return score how useful a path is to reach @a cp,
74 * positive scores mean path is more desirable
75 */
76double
77GCP_get_desirability_of_path (struct CadetPeer *cp,
78 unsigned int off);
79
80
81/**
82 * Obtain the peer identity for a `struct CadetPeer`.
83 *
84 * @param cp our peer handle
85 * @return the peer identity
86 */
87const struct GNUNET_PeerIdentity *
88GCP_get_id (struct CadetPeer *cp);
89
90
91/**
92 * Iterate over all known peers.
93 *
94 * @param iter Iterator.
95 * @param cls Closure for @c iter.
96 */
97void
98GCP_iterate_all (GNUNET_CONTAINER_PeerMapIterator iter,
99 void *cls);
100
101
102/**
103 * Count the number of known paths toward the peer.
104 *
105 * @param cp Peer to get path info.
106 * @return Number of known paths.
107 */
108unsigned int
109GCP_count_paths (const struct CadetPeer *cp);
110
111
112/**
113 * Drop all paths owned by this peer, and do not
114 * allow new ones to be added: We are shutting down.
115 *
116 * @param cp peer to drop paths to
117 */
118void
119GCP_drop_owned_paths (struct CadetPeer *cp);
120
121
122/**
123 * Peer path iterator.
124 *
125 * @param cls Closure.
126 * @param path Path itself
127 * @param off offset of the target peer in @a path
128 * @return #GNUNET_YES if should keep iterating.
129 * #GNUNET_NO otherwise.
130 */
131typedef int
132(*GCP_PathIterator) (void *cls,
133 struct CadetPeerPath *path,
134 unsigned int off);
135
136
137/**
138 * Iterate over the paths to a peer.
139 *
140 * @param cp Peer to get path info.
141 * @param callback Function to call for every path.
142 * @param callback_cls Closure for @a callback.
143 * @return Number of iterated paths.
144 */
145unsigned int
146GCP_iterate_paths (struct CadetPeer *cp,
147 GCP_PathIterator callback,
148 void *callback_cls);
149
150/**
151 * Iterate over the paths to a peer without direct link.
152 *
153 * @param cp Peer to get path info.
154 * @param callback Function to call for every path.
155 * @param callback_cls Closure for @a callback.
156 * @return Number of iterated paths.
157 */
158unsigned int
159GCP_iterate_indirect_paths (struct CadetPeer *cp,
160 GCP_PathIterator callback,
161 void *callback_cls);
162
163
164/**
165 * Iterate over the paths to @a peer where
166 * @a peer is at distance @a dist from us.
167 *
168 * @param cp Peer to get path info.
169 * @param dist desired distance of @a peer to us on the path
170 * @param callback Function to call for every path.
171 * @param callback_cls Closure for @a callback.
172 * @return Number of iterated paths.
173 */
174unsigned int
175GCP_iterate_paths_at (struct CadetPeer *cp,
176 unsigned int dist,
177 GCP_PathIterator callback,
178 void *callback_cls);
179
180
181/**
182 * Remove an entry from the DLL of all of the paths that this peer is on.
183 *
184 * @param cp peer to modify
185 * @param entry an entry on a path
186 * @param off offset of this peer on the path
187 */
188void
189GCP_path_entry_remove (struct CadetPeer *cp,
190 struct CadetPeerPathEntry *entry,
191 unsigned int off);
192
193
194/**
195 * Add an entry to the DLL of all of the paths that this peer is on.
196 *
197 * @param cp peer to modify
198 * @param entry an entry on a path
199 * @param off offset of this peer on the path
200 */
201void
202GCP_path_entry_add (struct CadetPeer *cp,
203 struct CadetPeerPathEntry *entry,
204 unsigned int off);
205
206
207/**
208 * Get the tunnel towards a peer.
209 *
210 * @param cp Peer to get from.
211 * @param create #GNUNET_YES to create a tunnel if we do not have one
212 * @return Tunnel towards peer.
213 */
214struct CadetTunnel *
215GCP_get_tunnel (struct CadetPeer *cp,
216 int create);
217
218
219/**
220 * The tunnel to the given peer no longer exists, remove it from our
221 * data structures, and possibly clean up the peer itself.
222 *
223 * @param cp the peer affected
224 * @param t the dead tunnel
225 */
226void
227GCP_drop_tunnel (struct CadetPeer *cp,
228 struct CadetTunnel *t);
229
230
231/**
232 * Try adding a @a path to this @a cp. If the peer already
233 * has plenty of paths, return NULL.
234 *
235 * @param cp peer to which the @a path leads to
236 * @param path a path looking for an owner; may not be fully initialized yet!
237 * @param off offset of @a cp in @a path
238 * @param force force attaching the path
239 * @return NULL if this peer does not care to become a new owner,
240 * otherwise the node in the peer's path heap for the @a path.
241 */
242struct GNUNET_CONTAINER_HeapNode *
243GCP_attach_path (struct CadetPeer *cp,
244 struct CadetPeerPath *path,
245 unsigned int off,
246 int force);
247
248
249/**
250 * This peer can no longer own @a path as the path
251 * has been extended and a peer further down the line
252 * is now the new owner.
253 *
254 * @param cp old owner of the @a path
255 * @param path path where the ownership is lost
256 * @param hn note in @a cp's path heap that must be deleted
257 */
258void
259GCP_detach_path (struct CadetPeer *cp,
260 struct CadetPeerPath *path,
261 struct GNUNET_CONTAINER_HeapNode *hn);
262
263
264/**
265 * Add a @a connection to this @a cp.
266 *
267 * @param cp peer via which the @a connection goes
268 * @param cc the connection to add
269 */
270void
271GCP_add_connection (struct CadetPeer *cp,
272 struct CadetConnection *cc);
273
274
275/**
276 * Remove a @a connection that went via this @a cp.
277 *
278 * @param cp peer via which the @a connection went
279 * @param cc the connection to remove
280 */
281void
282GCP_remove_connection (struct CadetPeer *cp,
283 struct CadetConnection *cc);
284
285
286/**
287 * We got a HELLO for a @a cp, remember it, and possibly
288 * trigger adequate actions (like trying to connect).
289 *
290 * @param cp the peer we got a HELLO for
291 * @param hello the HELLO to remember
292 */
293void
294GCP_set_hello (struct CadetPeer *cp,
295 const struct GNUNET_MessageHeader *hello);
296
297
298/**
299 * Clean up all entries about all peers.
300 * Must only be called after all tunnels, CORE-connections and
301 * connections are down.
302 */
303void
304GCP_destroy_all_peers (void);
305
306
307/**
308 * Data structure used to track whom we have to notify about changes
309 * in our ability to transmit to a given peer.
310 *
311 * All queue managers will be given equal chance for sending messages
312 * to @a cp. This construct this guarantees fairness for access to @a
313 * cp among the different message queues. Each connection or route
314 * will have its respective message queue managers for each direction.
315 */
316struct GCP_MessageQueueManager;
317
318
319/**
320 * Function to call with updated message queue object.
321 *
322 * @param cls closure
323 * @param available #GNUNET_YES if sending is now possible,
324 * #GNUNET_NO if sending is no longer possible
325 * #GNUNET_SYSERR if sending is no longer possible
326 * and the last envelope was discarded
327 */
328typedef void
329(*GCP_MessageQueueNotificationCallback)(void *cls,
330 int available);
331
332
333/**
334 * Start message queue change notifications. Will create a new slot
335 * to manage the message queue to the given @a cp.
336 *
337 * @param cp peer to notify for
338 * @param cb function to call if mq becomes available or unavailable
339 * @param cb_cls closure for @a cb
340 * @return handle to cancel request
341 */
342struct GCP_MessageQueueManager *
343GCP_request_mq (struct CadetPeer *cp,
344 GCP_MessageQueueNotificationCallback cb,
345 void *cb_cls);
346
347
348/**
349 * Test if @a cp has a core-level connection
350 *
351 * @param cp peer to test
352 * @return #GNUNET_YES if @a cp has a core-level connection
353 */
354int
355GCP_has_core_connection (struct CadetPeer *cp);
356
357
358/**
359 * Send the message in @a env via a @a mqm. Must only be called at
360 * most once after the respective
361 * #GCP_MessageQueueNotificationCallback was called with `available`
362 * set to #GNUNET_YES, and not after the callback was called with
363 * `available` set to #GNUNET_NO or #GNUNET_SYSERR.
364 *
365 * @param mqm message queue manager for the transmission
366 * @param env envelope with the message to send; must NOT
367 * yet have a #GNUNET_MQ_notify_sent() callback attached to it
368 */
369void
370GCP_send (struct GCP_MessageQueueManager *mqm,
371 struct GNUNET_MQ_Envelope *env);
372
373
374/**
375 * Send the message in @a env to @a cp, overriding queueing logic.
376 * This function should only be used to send error messages outside
377 * of flow and congestion control, similar to ICMP. Note that
378 * the envelope may be silently discarded as well.
379 *
380 * @param cp peer to send the message to
381 * @param env envelope with the message to send
382 */
383void
384GCP_send_ooo (struct CadetPeer *cp,
385 struct GNUNET_MQ_Envelope *env);
386
387
388/**
389 * Stops message queue change notifications and sends a last message.
390 * In practice, this is implemented by sending that @a last_env
391 * message immediately (if any), ignoring queue order.
392 *
393 * @param mqm handle matching request to cancel
394 * @param last_env final message to transmit, or NULL
395 */
396void
397GCP_request_mq_cancel (struct GCP_MessageQueueManager *mqm,
398 struct GNUNET_MQ_Envelope *last_env);
399
400
401/**
402 * Set the message queue to @a mq for peer @a cp and notify watchers.
403 *
404 * @param cp peer to modify
405 * @param mq message queue to set (can be NULL)
406 */
407void
408GCP_set_mq (struct CadetPeer *cp,
409 struct GNUNET_MQ_Handle *mq);
410
411/**
412 * Checking the signature for a monotime of a GNUNET_CADET_ConnectionCreateMessage.
413 *
414 * @param peer The peer that signed the monotime value.
415 * @param msg The GNUNET_CADET_ConnectionCreateMessage with the monotime value.
416 * @return GNUNET_OK if the signature is good, GNUNET_SYSERR if not.
417 */
418int
419GCP_check_monotime_sig (struct CadetPeer *peer, const struct
420 GNUNET_CADET_ConnectionCreateMessage *msg);
421
422/**
423 * Checking if a monotime value is newer than the last monotime value received from a peer. If the time value is newer it will be stored at the peer.
424 *
425 * @param peer The peer we received a new time value from.
426 * @param monotime Time value we check against the last time value we received from a peer.
427 * @return GNUNET_YES if monotime is newer than the last received time value, GNUNET_NO if monotime is not newer.
428 */
429int
430GCP_check_and_update_monotime (struct CadetPeer *peer,
431 struct GNUNET_TIME_AbsoluteNBO monotime);
432
433#endif