2 This file is part of GNUnet.
3 Copyright (C) 2001-2017 GNUnet e.V.
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @file cadet/gnunet-service-cadet_peer.h
23 * @brief Information we track per peer.
24 * @author Bartlomiej Polot
25 * @author Christian Grothoff
27 #ifndef GNUNET_SERVICE_CADET_PEER_H
28 #define GNUNET_SERVICE_CADET_PEER_H
30 #include "gnunet-service-cadet.h"
31 #include "gnunet_hello_lib.h"
35 * Get the static string for a peer ID.
39 * @return Static string for it's ID.
42 GCP_2s (const struct CadetPeer *peer);
46 * Retrieve the CadetPeer stucture associated with the
47 * peer. Optionally create one and insert it in the appropriate
48 * structures if the peer is not known yet.
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
57 GCP_get (const struct GNUNET_PeerIdentity *peer_id,
62 * Calculate how desirable a path is for @a cp if
63 * @a cp is at offset @a off in the path.
65 * @param cp a peer reachable via a path
66 * @param off offset of @a cp in a path
67 * @return score how useful a path is to reach @a cp,
68 * positive scores mean path is more desirable
71 GCP_get_desirability_of_path (struct CadetPeer *cp,
76 * Obtain the peer identity for a `struct CadetPeer`.
78 * @param cp our peer handle
79 * @return the peer identity
81 const struct GNUNET_PeerIdentity *
82 GCP_get_id (struct CadetPeer *cp);
86 * Iterate over all known peers.
88 * @param iter Iterator.
89 * @param cls Closure for @c iter.
92 GCP_iterate_all (GNUNET_CONTAINER_PeerMapIterator iter,
97 * Count the number of known paths toward the peer.
99 * @param cp Peer to get path info.
100 * @return Number of known paths.
103 GCP_count_paths (const struct CadetPeer *cp);
107 * Drop all paths owned by this peer, and do not
108 * allow new ones to be added: We are shutting down.
110 * @param cp peer to drop paths to
113 GCP_drop_owned_paths (struct CadetPeer *cp);
117 * Peer path iterator.
119 * @param cls Closure.
120 * @param path Path itself
121 * @param off offset of the target peer in @a path
122 * @return #GNUNET_YES if should keep iterating.
123 * #GNUNET_NO otherwise.
126 (*GCP_PathIterator) (void *cls,
127 struct CadetPeerPath *path,
132 * Iterate over the paths to a peer.
134 * @param cp Peer to get path info.
135 * @param callback Function to call for every path.
136 * @param callback_cls Closure for @a callback.
137 * @return Number of iterated paths.
140 GCP_iterate_paths (struct CadetPeer *cp,
141 GCP_PathIterator callback,
146 * Iterate over the paths to @a peer where
147 * @a peer is at distance @a dist from us.
149 * @param cp Peer to get path info.
150 * @param dist desired distance of @a peer to us on the path
151 * @param callback Function to call for every path.
152 * @param callback_cls Closure for @a callback.
153 * @return Number of iterated paths.
156 GCP_iterate_paths_at (struct CadetPeer *cp,
158 GCP_PathIterator callback,
163 * Remove an entry from the DLL of all of the paths that this peer is on.
165 * @param cp peer to modify
166 * @param entry an entry on a path
167 * @param off offset of this peer on the path
170 GCP_path_entry_remove (struct CadetPeer *cp,
171 struct CadetPeerPathEntry *entry,
176 * Add an entry to the DLL of all of the paths that this peer is on.
178 * @param cp peer to modify
179 * @param entry an entry on a path
180 * @param off offset of this peer on the path
183 GCP_path_entry_add (struct CadetPeer *cp,
184 struct CadetPeerPathEntry *entry,
189 * Get the tunnel towards a peer.
191 * @param cp Peer to get from.
192 * @param create #GNUNET_YES to create a tunnel if we do not have one
193 * @return Tunnel towards peer.
196 GCP_get_tunnel (struct CadetPeer *cp,
201 * The tunnel to the given peer no longer exists, remove it from our
202 * data structures, and possibly clean up the peer itself.
204 * @param cp the peer affected
205 * @param t the dead tunnel
208 GCP_drop_tunnel (struct CadetPeer *cp,
209 struct CadetTunnel *t);
213 * Try adding a @a path to this @a cp. If the peer already
214 * has plenty of paths, return NULL.
216 * @param cp peer to which the @a path leads to
217 * @param path a path looking for an owner; may not be fully initialized yet!
218 * @param off offset of @a cp in @a path
219 * @param force for attaching the path
220 * @return NULL if this peer does not care to become a new owner,
221 * otherwise the node in the peer's path heap for the @a path.
223 struct GNUNET_CONTAINER_HeapNode *
224 GCP_attach_path (struct CadetPeer *cp,
225 struct CadetPeerPath *path,
231 * This peer can no longer own @a path as the path
232 * has been extended and a peer further down the line
233 * is now the new owner.
235 * @param cp old owner of the @a path
236 * @param path path where the ownership is lost
237 * @param hn note in @a cp's path heap that must be deleted
240 GCP_detach_path (struct CadetPeer *cp,
241 struct CadetPeerPath *path,
242 struct GNUNET_CONTAINER_HeapNode *hn);
246 * Add a @a connection to this @a cp.
248 * @param cp peer via which the @a connection goes
249 * @param cc the connection to add
252 GCP_add_connection (struct CadetPeer *cp,
253 struct CadetConnection *cc);
257 * Remove a @a connection that went via this @a cp.
259 * @param cp peer via which the @a connection went
260 * @param cc the connection to remove
263 GCP_remove_connection (struct CadetPeer *cp,
264 struct CadetConnection *cc);
268 * We got a HELLO for a @a cp, remember it, and possibly
269 * trigger adequate actions (like trying to connect).
271 * @param cp the peer we got a HELLO for
272 * @param hello the HELLO to remember
275 GCP_set_hello (struct CadetPeer *cp,
276 const struct GNUNET_HELLO_Message *hello);
280 * Clean up all entries about all peers.
281 * Must only be called after all tunnels, CORE-connections and
282 * connections are down.
285 GCP_destroy_all_peers (void);
289 * Data structure used to track whom we have to notify about changes
290 * in our ability to transmit to a given peer.
292 * All queue managers will be given equal chance for sending messages
293 * to @a cp. This construct this guarantees fairness for access to @a
294 * cp among the different message queues. Each connection or route
295 * will have its respective message queue managers for each direction.
297 struct GCP_MessageQueueManager;
301 * Function to call with updated message queue object.
304 * @param available #GNUNET_YES if sending is now possible,
305 * #GNUNET_NO if sending is no longer possible
306 * #GNUNET_SYSERR if sending is no longer possible
307 * and the last envelope was discarded
310 (*GCP_MessageQueueNotificationCallback)(void *cls,
315 * Start message queue change notifications. Will create a new slot
316 * to manage the message queue to the given @a cp.
318 * @param cp peer to notify for
319 * @param cb function to call if mq becomes available or unavailable
320 * @param cb_cls closure for @a cb
321 * @return handle to cancel request
323 struct GCP_MessageQueueManager *
324 GCP_request_mq (struct CadetPeer *cp,
325 GCP_MessageQueueNotificationCallback cb,
330 * Test if @a cp has a core-level connection
332 * @param cp peer to test
333 * @return #GNUNET_YES if @a cp has a core-level connection
336 GCP_has_core_connection (struct CadetPeer *cp);
340 * Send the message in @a env via a @a mqm. Must only be called at
341 * most once after the respective
342 * #GCP_MessageQueueNotificationCallback was called with `available`
343 * set to #GNUNET_YES, and not after the callback was called with
344 * `available` set to #GNUNET_NO or #GNUNET_SYSERR.
346 * @param mqm message queue manager for the transmission
347 * @param env envelope with the message to send; must NOT
348 * yet have a #GNUNET_MQ_notify_sent() callback attached to it
351 GCP_send (struct GCP_MessageQueueManager *mqm,
352 struct GNUNET_MQ_Envelope *env);
356 * Send the message in @a env to @a cp, overriding queueing logic.
357 * This function should only be used to send error messages outside
358 * of flow and congestion control, similar to ICMP. Note that
359 * the envelope may be silently discarded as well.
361 * @param cp peer to send the message to
362 * @param env envelope with the message to send
365 GCP_send_ooo (struct CadetPeer *cp,
366 struct GNUNET_MQ_Envelope *env);
370 * Stops message queue change notifications and sends a last message.
371 * In practice, this is implemented by sending that @a last_env
372 * message immediately (if any), ignoring queue order.
374 * @param mqm handle matching request to cancel
375 * @param last_env final message to transmit, or NULL
378 GCP_request_mq_cancel (struct GCP_MessageQueueManager *mqm,
379 struct GNUNET_MQ_Envelope *last_env);
383 * Set the message queue to @a mq for peer @a cp and notify watchers.
385 * @param cp peer to modify
386 * @param mq message queue to set (can be NULL)
389 GCP_set_mq (struct CadetPeer *cp,
390 struct GNUNET_MQ_Handle *mq);