diff options
author | Bart Polot <bart@net.in.tum.de> | 2014-05-07 12:07:16 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2014-05-07 12:07:16 +0000 |
commit | 41716952f1d0508fb621cb5fec31406d3bd96192 (patch) | |
tree | 0ea8e1a1397babe96db05d17cb7618fc69bb88c7 /src/cadet/gnunet-service-cadet_peer.h | |
parent | 74794f20cec6fbbd007e0921e7a347655050c024 (diff) | |
download | gnunet-41716952f1d0508fb621cb5fec31406d3bd96192.tar.gz gnunet-41716952f1d0508fb621cb5fec31406d3bd96192.zip |
Renamed directory
Diffstat (limited to 'src/cadet/gnunet-service-cadet_peer.h')
-rw-r--r-- | src/cadet/gnunet-service-cadet_peer.h | 418 |
1 files changed, 418 insertions, 0 deletions
diff --git a/src/cadet/gnunet-service-cadet_peer.h b/src/cadet/gnunet-service-cadet_peer.h new file mode 100644 index 000000000..9f1146e9f --- /dev/null +++ b/src/cadet/gnunet-service-cadet_peer.h | |||
@@ -0,0 +1,418 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2013 Christian Grothoff (and other contributing authors) | ||
4 | |||
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. | ||
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 | General Public License for more details. | ||
14 | |||
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., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file cadet/gnunet-service-cadet_peer.h | ||
23 | * @brief cadet service; dealing with remote peers | ||
24 | * @author Bartlomiej Polot | ||
25 | * | ||
26 | * All functions in this file should use the prefix GMP (Gnunet Cadet Peer) | ||
27 | */ | ||
28 | |||
29 | #ifndef GNUNET_SERVICE_CADET_PEER_H | ||
30 | #define GNUNET_SERVICE_CADET_PEER_H | ||
31 | |||
32 | #ifdef __cplusplus | ||
33 | extern "C" | ||
34 | { | ||
35 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
36 | } | ||
37 | #endif | ||
38 | #endif | ||
39 | |||
40 | #include "platform.h" | ||
41 | #include "gnunet_util_lib.h" | ||
42 | |||
43 | /** | ||
44 | * Struct containing all information regarding a given peer | ||
45 | */ | ||
46 | struct CadetPeer; | ||
47 | |||
48 | /** | ||
49 | * Struct containing info about a queued transmission to this peer | ||
50 | */ | ||
51 | struct CadetPeerQueue; | ||
52 | |||
53 | #include "gnunet-service-cadet_connection.h" | ||
54 | |||
55 | /** | ||
56 | * Callback called when a queued message is sent. | ||
57 | * | ||
58 | * @param cls Closure. | ||
59 | * @param c Connection this message was on. | ||
60 | * @param sent Was it really sent? (Could have been canceled) | ||
61 | * @param type Type of message sent. | ||
62 | * @param pid Packet ID, or 0 if not applicable (create, destroy, etc). | ||
63 | * @param fwd Was this a FWD going message? | ||
64 | * @param size Size of the message. | ||
65 | * @param wait Time spent waiting for core (only the time for THIS message) | ||
66 | */ | ||
67 | typedef void (*GMP_sent) (void *cls, | ||
68 | struct CadetConnection *c, int sent, | ||
69 | uint16_t type, uint32_t pid, int fwd, size_t size, | ||
70 | struct GNUNET_TIME_Relative wait); | ||
71 | |||
72 | /******************************************************************************/ | ||
73 | /******************************** API ***********************************/ | ||
74 | /******************************************************************************/ | ||
75 | |||
76 | /** | ||
77 | * Initialize peer subsystem. | ||
78 | * | ||
79 | * @param c Configuration. | ||
80 | */ | ||
81 | void | ||
82 | GMP_init (const struct GNUNET_CONFIGURATION_Handle *c); | ||
83 | |||
84 | /** | ||
85 | * Shut down the peer subsystem. | ||
86 | */ | ||
87 | void | ||
88 | GMP_shutdown (void); | ||
89 | |||
90 | |||
91 | /** | ||
92 | * Retrieve the CadetPeer stucture associated with the peer, create one | ||
93 | * and insert it in the appropriate structures if the peer is not known yet. | ||
94 | * | ||
95 | * @param peer_id Full identity of the peer. | ||
96 | * | ||
97 | * @return Existing or newly created peer structure. | ||
98 | */ | ||
99 | struct CadetPeer * | ||
100 | GMP_get (const struct GNUNET_PeerIdentity *peer_id); | ||
101 | |||
102 | |||
103 | /** | ||
104 | * Retrieve the CadetPeer stucture associated with the peer, create one | ||
105 | * and insert it in the appropriate structures if the peer is not known yet. | ||
106 | * | ||
107 | * @param peer Short identity of the peer. | ||
108 | * | ||
109 | * @return Existing or newly created peer structure. | ||
110 | */ | ||
111 | struct CadetPeer * | ||
112 | GMP_get_short (const GNUNET_PEER_Id peer); | ||
113 | |||
114 | /** | ||
115 | * Try to establish a new connection to this peer (in its tunnel). | ||
116 | * If the peer doesn't have any path to it yet, try to get one. | ||
117 | * If the peer already has some path, send a CREATE CONNECTION towards it. | ||
118 | * | ||
119 | * @param peer Peer to connect to. | ||
120 | */ | ||
121 | void | ||
122 | GMP_connect (struct CadetPeer *peer); | ||
123 | |||
124 | /** | ||
125 | * Free a transmission that was already queued with all resources | ||
126 | * associated to the request. | ||
127 | * | ||
128 | * @param queue Queue handler to cancel. | ||
129 | * @param clear_cls Is it necessary to free associated cls? | ||
130 | * @param sent Was it really sent? (Could have been canceled) | ||
131 | * @param pid PID, if relevant (was sent and was a payload message). | ||
132 | */ | ||
133 | void | ||
134 | GMP_queue_destroy (struct CadetPeerQueue *queue, int clear_cls, | ||
135 | int sent, uint32_t pid); | ||
136 | |||
137 | /** | ||
138 | * @brief Queue and pass message to core when possible. | ||
139 | * | ||
140 | * @param peer Peer towards which to queue the message. | ||
141 | * @param cls Closure (@c type dependant). It will be used by queue_send to | ||
142 | * build the message to be sent if not already prebuilt. | ||
143 | * @param type Type of the message, 0 for a raw message. | ||
144 | * @param size Size of the message. | ||
145 | * @param c Connection this message belongs to (cannot be NULL). | ||
146 | * @param fwd Is this a message going root->dest? (FWD ACK are NOT FWD!) | ||
147 | * @param cont Continuation to be called once CORE has taken the message. | ||
148 | * @param cont_cls Closure for @c cont. | ||
149 | * | ||
150 | * @return Handle to cancel the message before it is sent. Once cont is called | ||
151 | * message has been sent and therefore the handle is no longer valid. | ||
152 | */ | ||
153 | struct CadetPeerQueue * | ||
154 | GMP_queue_add (struct CadetPeer *peer, void *cls, uint16_t type, | ||
155 | uint16_t payload_type, uint32_t payload_id, | ||
156 | size_t size, struct CadetConnection *c, int fwd, | ||
157 | GMP_sent cont, void *cont_cls); | ||
158 | |||
159 | /** | ||
160 | * Cancel all queued messages to a peer that belong to a certain connection. | ||
161 | * | ||
162 | * @param peer Peer towards whom to cancel. | ||
163 | * @param c Connection whose queued messages to cancel. Might be destroyed by | ||
164 | * the sent continuation call. | ||
165 | */ | ||
166 | void | ||
167 | GMP_queue_cancel (struct CadetPeer *peer, struct CadetConnection *c); | ||
168 | |||
169 | /** | ||
170 | * Get the first message for a connection and unqueue it. | ||
171 | * | ||
172 | * @param peer Neighboring peer. | ||
173 | * @param c Connection. | ||
174 | * | ||
175 | * @return First message for this connection. | ||
176 | */ | ||
177 | struct GNUNET_MessageHeader * | ||
178 | GMP_connection_pop (struct CadetPeer *peer, struct CadetConnection *c); | ||
179 | |||
180 | void | ||
181 | GMP_queue_unlock (struct CadetPeer *peer, struct CadetConnection *c); | ||
182 | |||
183 | /** | ||
184 | * Set tunnel. | ||
185 | * | ||
186 | * @param peer Peer. | ||
187 | * @param t Tunnel. | ||
188 | */ | ||
189 | void | ||
190 | GMP_set_tunnel (struct CadetPeer *peer, struct CadetTunnel3 *t); | ||
191 | |||
192 | /** | ||
193 | * Check whether there is a direct (core level) connection to peer. | ||
194 | * | ||
195 | * @param peer Peer to check. | ||
196 | * | ||
197 | * @return #GNUNET_YES if there is a direct connection. | ||
198 | */ | ||
199 | int | ||
200 | GMP_is_neighbor (const struct CadetPeer *peer); | ||
201 | |||
202 | /** | ||
203 | * Create and initialize a new tunnel towards a peer, in case it has none. | ||
204 | * | ||
205 | * Does not generate any traffic, just creates the local data structures. | ||
206 | * | ||
207 | * @param peer Peer towards which to create the tunnel. | ||
208 | */ | ||
209 | void | ||
210 | GMP_add_tunnel (struct CadetPeer *peer); | ||
211 | |||
212 | /** | ||
213 | * Add a connection to a neighboring peer. | ||
214 | * | ||
215 | * Store that the peer is the first hop of the connection in one | ||
216 | * direction and that on peer disconnect the connection must be | ||
217 | * notified and destroyed, for it will no longer be valid. | ||
218 | * | ||
219 | * @param peer Peer to add connection to. | ||
220 | * @param c Connection to add. | ||
221 | * | ||
222 | * @return GNUNET_OK on success. | ||
223 | */ | ||
224 | int | ||
225 | GMP_add_connection (struct CadetPeer *peer, struct CadetConnection *c); | ||
226 | |||
227 | /** | ||
228 | * Add the path to the peer and update the path used to reach it in case this | ||
229 | * is the shortest. | ||
230 | * | ||
231 | * @param peer Destination peer to add the path to. | ||
232 | * @param path New path to add. Last peer must be the peer in arg 1. | ||
233 | * Path will be either used of freed if already known. | ||
234 | * @param trusted Do we trust that this path is real? | ||
235 | * | ||
236 | * @return path if path was taken, pointer to existing duplicate if exists | ||
237 | * NULL on error. | ||
238 | */ | ||
239 | struct CadetPeerPath * | ||
240 | GMP_add_path (struct CadetPeer *peer, struct CadetPeerPath *p, int trusted); | ||
241 | |||
242 | /** | ||
243 | * Add the path to the origin peer and update the path used to reach it in case | ||
244 | * this is the shortest. | ||
245 | * The path is given in peer_info -> destination, therefore we turn the path | ||
246 | * upside down first. | ||
247 | * | ||
248 | * @param peer Peer to add the path to, being the origin of the path. | ||
249 | * @param path New path to add after being inversed. | ||
250 | * Path will be either used or freed. | ||
251 | * @param trusted Do we trust that this path is real? | ||
252 | * | ||
253 | * @return path if path was taken, pointer to existing duplicate if exists | ||
254 | * NULL on error. | ||
255 | */ | ||
256 | struct CadetPeerPath * | ||
257 | GMP_add_path_to_origin (struct CadetPeer *peer, | ||
258 | struct CadetPeerPath *path, | ||
259 | int trusted); | ||
260 | |||
261 | /** | ||
262 | * Adds a path to the info of all the peers in the path | ||
263 | * | ||
264 | * @param p Path to process. | ||
265 | * @param confirmed Whether we know if the path works or not. | ||
266 | */ | ||
267 | void | ||
268 | GMP_add_path_to_all (const struct CadetPeerPath *p, int confirmed); | ||
269 | |||
270 | /** | ||
271 | * Remove any path to the peer that has the extact same peers as the one given. | ||
272 | * | ||
273 | * @param peer Peer to remove the path from. | ||
274 | * @param path Path to remove. Is always destroyed . | ||
275 | */ | ||
276 | void | ||
277 | GMP_remove_path (struct CadetPeer *peer, struct CadetPeerPath *path); | ||
278 | |||
279 | /** | ||
280 | * Remove a connection from a neighboring peer. | ||
281 | * | ||
282 | * @param peer Peer to remove connection from. | ||
283 | * @param c Connection to remove. | ||
284 | * | ||
285 | * @return GNUNET_OK on success. | ||
286 | */ | ||
287 | int | ||
288 | GMP_remove_connection (struct CadetPeer *peer, const struct CadetConnection *c); | ||
289 | |||
290 | /** | ||
291 | * Start the DHT search for new paths towards the peer: we don't have | ||
292 | * enough good connections. | ||
293 | * | ||
294 | * @param peer Destination peer. | ||
295 | */ | ||
296 | void | ||
297 | GMP_start_search (struct CadetPeer *peer); | ||
298 | |||
299 | /** | ||
300 | * Stop the DHT search for new paths towards the peer: we already have | ||
301 | * enough good connections. | ||
302 | * | ||
303 | * @param peer Destination peer. | ||
304 | */ | ||
305 | void | ||
306 | GMP_stop_search (struct CadetPeer *peer); | ||
307 | |||
308 | /** | ||
309 | * Get the Full ID of a peer. | ||
310 | * | ||
311 | * @param peer Peer to get from. | ||
312 | * | ||
313 | * @return Full ID of peer. | ||
314 | */ | ||
315 | const struct GNUNET_PeerIdentity * | ||
316 | GMP_get_id (const struct CadetPeer *peer); | ||
317 | |||
318 | /** | ||
319 | * Get the Short ID of a peer. | ||
320 | * | ||
321 | * @param peer Peer to get from. | ||
322 | * | ||
323 | * @return Short ID of peer. | ||
324 | */ | ||
325 | GNUNET_PEER_Id | ||
326 | GMP_get_short_id (const struct CadetPeer *peer); | ||
327 | |||
328 | /** | ||
329 | * Get the tunnel towards a peer. | ||
330 | * | ||
331 | * @param peer Peer to get from. | ||
332 | * | ||
333 | * @return Tunnel towards peer. | ||
334 | */ | ||
335 | struct CadetTunnel3 * | ||
336 | GMP_get_tunnel (const struct CadetPeer *peer); | ||
337 | |||
338 | /** | ||
339 | * Set the hello message. | ||
340 | * | ||
341 | * @param peer Peer whose message to set. | ||
342 | * @param hello Hello message. | ||
343 | */ | ||
344 | void | ||
345 | GMP_set_hello (struct CadetPeer *peer, const struct GNUNET_HELLO_Message *hello); | ||
346 | |||
347 | /** | ||
348 | * Get the hello message. | ||
349 | * | ||
350 | * @param peer Peer whose message to get. | ||
351 | * | ||
352 | * @return Hello message. | ||
353 | */ | ||
354 | struct GNUNET_HELLO_Message * | ||
355 | GMP_get_hello (struct CadetPeer *peer); | ||
356 | |||
357 | |||
358 | /** | ||
359 | * Try to connect to a peer on TRANSPORT level. | ||
360 | * | ||
361 | * @param peer Peer to whom to connect. | ||
362 | */ | ||
363 | void | ||
364 | GMP_try_connect (struct CadetPeer *peer); | ||
365 | |||
366 | /** | ||
367 | * Notify a peer that a link between two other peers is broken. If any path | ||
368 | * used that link, eliminate it. | ||
369 | * | ||
370 | * @param peer Peer affected by the change. | ||
371 | * @param peer1 Peer whose link is broken. | ||
372 | * @param peer2 Peer whose link is broken. | ||
373 | */ | ||
374 | void | ||
375 | GMP_notify_broken_link (struct CadetPeer *peer, | ||
376 | struct GNUNET_PeerIdentity *peer1, | ||
377 | struct GNUNET_PeerIdentity *peer2); | ||
378 | |||
379 | /** | ||
380 | * Count the number of known paths toward the peer. | ||
381 | * | ||
382 | * @param peer Peer to get path info. | ||
383 | * | ||
384 | * @return Number of known paths. | ||
385 | */ | ||
386 | unsigned int | ||
387 | GMP_count_paths (const struct CadetPeer *peer); | ||
388 | |||
389 | /** | ||
390 | * Iterate all known peers. | ||
391 | * | ||
392 | * @param iter Iterator. | ||
393 | * @param cls Closure for @c iter. | ||
394 | */ | ||
395 | void | ||
396 | GMP_iterate_all (GNUNET_CONTAINER_PeerMapIterator iter, void *cls); | ||
397 | |||
398 | /** | ||
399 | * Get the static string for a peer ID. | ||
400 | * | ||
401 | * @param peer Peer. | ||
402 | * | ||
403 | * @return Static string for it's ID. | ||
404 | */ | ||
405 | const char * | ||
406 | GMP_2s (const struct CadetPeer *peer); | ||
407 | |||
408 | |||
409 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
410 | { | ||
411 | #endif | ||
412 | #ifdef __cplusplus | ||
413 | } | ||
414 | #endif | ||
415 | |||
416 | /* ifndef GNUNET_CADET_SERVICE_PEER_H */ | ||
417 | #endif | ||
418 | /* end of gnunet-cadet-service_peer.h */ | ||