3 This file is part of GNUnet.
4 Copyright (C) 2001-2017 GNUnet e.V.
6 GNUnet is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 3, or (at your
9 option) any later version.
11 GNUnet is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNUnet; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
23 * @file cadet/gnunet-service-cadet-new_peer.h
24 * @brief Information we track per peer.
25 * @author Bartlomiej Polot
26 * @author Christian Grothoff
28 #ifndef GNUNET_SERVICE_CADET_PEER_H
29 #define GNUNET_SERVICE_CADET_PEER_H
31 #include "gnunet-service-cadet-new.h"
32 #include "gnunet_hello_lib.h"
36 * Get the static string for a peer ID.
40 * @return Static string for it's ID.
43 GCP_2s (const struct CadetPeer *peer);
47 * Retrieve the CadetPeer stucture associated with the
48 * peer. Optionally create one and insert it in the appropriate
49 * structures if the peer is not known yet.
51 * @param peer_id Full identity of the peer.
52 * @param create #GNUNET_YES if a new peer should be created if unknown.
53 * #GNUNET_NO to return NULL if peer is unknown.
54 * @return Existing or newly created peer structure.
55 * NULL if unknown and not requested @a create
58 GCP_get (const struct GNUNET_PeerIdentity *peer_id,
63 * Obtain the peer identity for a `struct CadetPeer`.
65 * @param cp our peer handle
66 * @return the peer identity
68 const struct GNUNET_PeerIdentity *
69 GCP_get_id (struct CadetPeer *cp);
73 * Iterate over all known peers.
75 * @param iter Iterator.
76 * @param cls Closure for @c iter.
79 GCP_iterate_all (GNUNET_CONTAINER_PeerMapIterator iter,
84 * Count the number of known paths toward the peer.
86 * @param cp Peer to get path info.
87 * @return Number of known paths.
90 GCP_count_paths (const struct CadetPeer *cp);
97 * @param path Path itself
98 * @param off offset of the target peer in @a path
99 * @return #GNUNET_YES if should keep iterating.
100 * #GNUNET_NO otherwise.
103 (*GCP_PathIterator) (void *cls,
104 struct CadetPeerPath *path,
109 * Iterate over the paths to a peer.
111 * @param cp Peer to get path info.
112 * @param callback Function to call for every path.
113 * @param callback_cls Closure for @a callback.
114 * @return Number of iterated paths.
117 GCP_iterate_paths (struct CadetPeer *cp,
118 GCP_PathIterator callback,
123 * Iterate over the paths to @a peer where
124 * @a peer is at distance @a dist from us.
126 * @param peer Peer to get path info.
127 * @param dist desired distance of @a peer to us on the path
128 * @param callback Function to call for every path.
129 * @param callback_cls Closure for @a callback.
130 * @return Number of iterated paths.
133 GCP_iterate_paths_at (struct CadetPeer *peer,
135 GCP_PathIterator callback,
140 * Remove an entry from the DLL of all of the paths that this peer is on.
142 * @param cp peer to modify
143 * @param entry an entry on a path
144 * @param off offset of this peer on the path
147 GCP_path_entry_remove (struct CadetPeer *cp,
148 struct CadetPeerPathEntry *entry,
153 * Add an entry to the DLL of all of the paths that this peer is on.
155 * @param cp peer to modify
156 * @param entry an entry on a path
157 * @param off offset of this peer on the path
160 GCP_path_entry_add (struct CadetPeer *cp,
161 struct CadetPeerPathEntry *entry,
166 * Get the tunnel towards a peer.
168 * @param cp Peer to get from.
169 * @param create #GNUNET_YES to create a tunnel if we do not have one
170 * @return Tunnel towards peer.
173 GCP_get_tunnel (struct CadetPeer *cp,
178 * The tunnel to the given peer no longer exists, remove it from our
179 * data structures, and possibly clean up the peer itself.
181 * @param cp the peer affected
182 * @param t the dead tunnel
185 GCP_drop_tunnel (struct CadetPeer *cp,
186 struct CadetTunnel *t);
190 * Try adding a @a path to this @a cp. If the peer already
191 * has plenty of paths, return NULL.
193 * @param cp peer to which the @a path leads to
194 * @param path a path looking for an owner; may not be fully initialized yet!
195 * @param off offset of @a cp in @a path
196 * @return NULL if this peer does not care to become a new owner,
197 * otherwise the node in the peer's path heap for the @a path.
199 struct GNUNET_CONTAINER_HeapNode *
200 GCP_attach_path (struct CadetPeer *cp,
201 struct CadetPeerPath *path,
206 * This peer can no longer own @a path as the path
207 * has been extended and a peer further down the line
208 * is now the new owner.
210 * @param cp old owner of the @a path
211 * @param path path where the ownership is lost
212 * @param hn note in @a cp's path heap that must be deleted
215 GCP_detach_path (struct CadetPeer *cp,
216 struct CadetPeerPath *path,
217 struct GNUNET_CONTAINER_HeapNode *hn);
221 * Add a @a connection to this @a cp.
223 * @param cp peer via which the @a connection goes
224 * @param cc the connection to add
227 GCP_add_connection (struct CadetPeer *cp,
228 struct CadetConnection *cc);
232 * Remove a @a connection that went via this @a cp.
234 * @param cp peer via which the @a connection went
235 * @param cc the connection to remove
238 GCP_remove_connection (struct CadetPeer *cp,
239 struct CadetConnection *cc);
243 * We got a HELLO for a @a cp, remember it, and possibly
244 * trigger adequate actions (like trying to connect).
246 * @param cp the peer we got a HELLO for
247 * @param hello the HELLO to remember
250 GCP_set_hello (struct CadetPeer *cp,
251 const struct GNUNET_HELLO_Message *hello);
255 * Clean up all entries about all peers.
256 * Must only be called after all tunnels, CORE-connections and
257 * connections are down.
260 GCP_destroy_all_peers (void);
264 * Data structure used to track whom we have to notify about changes
265 * to our message queue.
267 struct GCP_MessageQueueManager;
271 * Function to call with updated message queue object.
274 * @param mq NULL if MQ is gone, otherwise an active message queue
277 (*GCP_MessageQueueNotificationCallback)(void *cls,
278 struct GNUNET_MQ_Handle *mq);
282 * Start message queue change notifications.
284 * @param cp peer to notify for
285 * @param cb function to call if mq becomes available or unavailable
286 * @param cb_cls closure for @a cb
287 * @return handle to cancel request
289 struct GCP_MessageQueueManager *
290 GCP_request_mq (struct CadetPeer *cp,
291 GCP_MessageQueueNotificationCallback cb,
296 * Stops message queue change notifications.
298 * @param mqm handle matching request to cancel
301 GCP_request_mq_cancel (struct GCP_MessageQueueManager *mqm);
305 * Set the message queue to @a mq for peer @a cp and notify watchers.
307 * @param cp peer to modify
308 * @param mq message queue to set (can be NULL)
311 GCP_set_mq (struct CadetPeer *cp,
312 struct GNUNET_MQ_Handle *mq);
316 * Send the message in @a env to @a cp.
319 * @param env envelope with the message to send
322 GCP_send (struct CadetPeer *cp,
323 struct GNUNET_MQ_Envelope *env);