diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-06-22 20:24:36 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-06-22 20:24:36 +0000 |
commit | 97d9a982e9f2555c51eae2279166d707b3c8a09e (patch) | |
tree | 8507bcdefe98f54c29e54a0ca7c0bb3d7e117644 /src/include | |
parent | 26fe175a9b52e63790ae673b602d4c1bb50c6c12 (diff) | |
download | gnunet-97d9a982e9f2555c51eae2279166d707b3c8a09e.tar.gz gnunet-97d9a982e9f2555c51eae2279166d707b3c8a09e.zip |
-reordering API in header to make structure more obvious
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/gnunet_transport_service.h | 614 | ||||
-rw-r--r-- | src/include/gnunet_tun_lib.h | 12 |
2 files changed, 325 insertions, 301 deletions
diff --git a/src/include/gnunet_transport_service.h b/src/include/gnunet_transport_service.h index 3a4d282e4..872cd1d8a 100644 --- a/src/include/gnunet_transport_service.h +++ b/src/include/gnunet_transport_service.h | |||
@@ -45,186 +45,11 @@ extern "C" | |||
45 | 45 | ||
46 | 46 | ||
47 | /** | 47 | /** |
48 | * Possible state of a neighbour. Initially, we are #GNUNET_TRANSPORT_PS_NOT_CONNECTED. | ||
49 | * | ||
50 | * Then, there are two main paths. If we receive a CONNECT message, we give | ||
51 | * the inbound address to ATS. After the check we ask ATS for a suggestion | ||
52 | * (#GNUNET_TRANSPORT_PS_CONNECT_RECV_ATS). If ATS makes a suggestion, we | ||
53 | * send our CONNECT_ACK and go to #GNUNET_TRANSPORT_PS_CONNECT_RECV_ACK. | ||
54 | * If we receive a SESSION_ACK, we go to #GNUNET_TRANSPORT_PS_CONNECTED | ||
55 | * (and notify everyone about the new connection). If the operation times out, | ||
56 | * we go to #GNUNET_TRANSPORT_PS_DISCONNECT. | ||
57 | * | ||
58 | * The other case is where we transmit a CONNECT message first. We | ||
59 | * start with #GNUNET_TRANSPORT_PS_INIT_ATS. If we get an address, we send | ||
60 | * the CONNECT message and go to state #GNUNET_TRANSPORT_PS_CONNECT_SENT. | ||
61 | * Once we receive a CONNECT_ACK, we go to #GNUNET_TRANSPORT_PS_CONNECTED | ||
62 | * (and notify everyone about the new connection and send | ||
63 | * back a SESSION_ACK). If the operation times out, we go to | ||
64 | * #GNUNET_TRANSPORT_PS_DISCONNECT. | ||
65 | * | ||
66 | * If the session is in trouble (i.e. transport-level disconnect or | ||
67 | * timeout), we go to #GNUNET_TRANSPORT_PS_RECONNECT_ATS where we ask ATS for a new | ||
68 | * address (we don't notify anyone about the disconnect yet). Once we | ||
69 | * have a new address, we enter #GNUNET_TRANSPORT_PS_RECONNECT_SENT and send a | ||
70 | * CONNECT message. If we receive a | ||
71 | * CONNECT_ACK, we go to #GNUNET_TRANSPORT_PS_CONNECTED and nobody noticed that we had | ||
72 | * trouble; we also send a SESSION_ACK at this time just in case. If | ||
73 | * the operation times out, we go to #GNUNET_TRANSPORT_PS_DISCONNECT (and notify everyone | ||
74 | * about the lost connection). | ||
75 | * | ||
76 | * If ATS decides to switch addresses while we have a normal | ||
77 | * connection, we go to #GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_CONNECT_SENT | ||
78 | * and send a SESSION_CONNECT. If we get a SESSION_ACK back, we switch the | ||
79 | * primary connection to the suggested alternative from ATS, go back | ||
80 | * to #GNUNET_TRANSPORT_PS_CONNECTED and send a SESSION_ACK to the other peer just to be | ||
81 | * sure. If the operation times out | ||
82 | * we go to #GNUNET_TRANSPORT_PS_CONNECTED (and notify ATS that the given alternative | ||
83 | * address is "invalid"). | ||
84 | * | ||
85 | * Once a session is in #GNUNET_TRANSPORT_PS_DISCONNECT, it is cleaned up and then goes | ||
86 | * to (#GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED). If we receive an explicit disconnect | ||
87 | * request, we can go from any state to #GNUNET_TRANSPORT_PS_DISCONNECT, possibly after | ||
88 | * generating disconnect notifications. | ||
89 | * | ||
90 | * Note that it is quite possible that while we are in any of these | ||
91 | * states, we could receive a 'CONNECT' request from the other peer. | ||
92 | * We then enter a 'weird' state where we pursue our own primary state | ||
93 | * machine (as described above), but with the 'send_connect_ack' flag | ||
94 | * set to 1. If our state machine allows us to send a 'CONNECT_ACK' | ||
95 | * (because we have an acceptable address), we send the 'CONNECT_ACK' | ||
96 | * and set the 'send_connect_ack' to 2. If we then receive a | ||
97 | * 'SESSION_ACK', we go to #GNUNET_TRANSPORT_PS_CONNECTED (and reset 'send_connect_ack' | ||
98 | * to 0). | ||
99 | * | ||
100 | */ | ||
101 | enum GNUNET_TRANSPORT_PeerState | ||
102 | { | ||
103 | /** | ||
104 | * Fresh peer or completely disconnected | ||
105 | */ | ||
106 | GNUNET_TRANSPORT_PS_NOT_CONNECTED = 0, | ||
107 | |||
108 | /** | ||
109 | * Asked to initiate connection, trying to get address from ATS | ||
110 | */ | ||
111 | GNUNET_TRANSPORT_PS_INIT_ATS, | ||
112 | |||
113 | /** | ||
114 | * Sent CONNECT message to other peer, waiting for CONNECT_ACK | ||
115 | */ | ||
116 | GNUNET_TRANSPORT_PS_CONNECT_SENT, | ||
117 | |||
118 | /** | ||
119 | * Received a CONNECT, asking ATS about address suggestions. | ||
120 | */ | ||
121 | GNUNET_TRANSPORT_PS_CONNECT_RECV_ATS, | ||
122 | |||
123 | /** | ||
124 | * CONNECT request from other peer was CONNECT_ACK'ed, waiting for | ||
125 | * SESSION_ACK. | ||
126 | */ | ||
127 | GNUNET_TRANSPORT_PS_CONNECT_RECV_ACK, | ||
128 | |||
129 | /** | ||
130 | * Got our CONNECT_ACK/SESSION_ACK, connection is up. | ||
131 | */ | ||
132 | GNUNET_TRANSPORT_PS_CONNECTED, | ||
133 | |||
134 | /** | ||
135 | * Connection got into trouble, rest of the system still believes | ||
136 | * it to be up, but we're getting a new address from ATS. | ||
137 | */ | ||
138 | GNUNET_TRANSPORT_PS_RECONNECT_ATS, | ||
139 | |||
140 | /** | ||
141 | * Sent CONNECT over new address (either by ATS telling us to switch | ||
142 | * addresses or from RECONNECT_ATS); if this fails, we need to tell | ||
143 | * the rest of the system about a disconnect. | ||
144 | */ | ||
145 | GNUNET_TRANSPORT_PS_RECONNECT_SENT, | ||
146 | |||
147 | /** | ||
148 | * We have some primary connection, but ATS suggested we switch | ||
149 | * to some alternative; we now sent a CONNECT message for the | ||
150 | * alternative session to the other peer and waiting for a | ||
151 | * CONNECT_ACK to make this our primary connection. | ||
152 | */ | ||
153 | GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_CONNECT_SENT, | ||
154 | |||
155 | /** | ||
156 | * Disconnect in progress (we're sending the DISCONNECT message to the | ||
157 | * other peer; after that is finished, the state will be cleaned up). | ||
158 | */ | ||
159 | GNUNET_TRANSPORT_PS_DISCONNECT, | ||
160 | |||
161 | /** | ||
162 | * We're finished with the disconnect; and are cleaning up the state | ||
163 | * now! We put the struct into this state when we are really in the | ||
164 | * task that calls 'free' on it and are about to remove the record | ||
165 | * from the map. We should never find a 'struct NeighbourMapEntry' | ||
166 | * in this state in the map. Accessing a 'struct NeighbourMapEntry' | ||
167 | * in this state virtually always means using memory that has been | ||
168 | * freed (the exception being the cleanup code in #free_neighbour()). | ||
169 | */ | ||
170 | GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED | ||
171 | }; | ||
172 | |||
173 | |||
174 | /** | ||
175 | * Current state of a validation process. | ||
176 | * | ||
177 | * FIXME: what state is used to indicate that a validation | ||
178 | * was successful? If that is clarified/determined, "UGH" in | ||
179 | * ~gnunet-peerinfo-gtk.c:1103 should be resolved. | ||
180 | */ | ||
181 | enum GNUNET_TRANSPORT_ValidationState | ||
182 | { | ||
183 | /** | ||
184 | * Undefined state | ||
185 | * | ||
186 | * Used for final callback indicating operation done | ||
187 | */ | ||
188 | GNUNET_TRANSPORT_VS_NONE, | ||
189 | |||
190 | /** | ||
191 | * Fresh validation entry | ||
192 | * | ||
193 | * Entry was just created, no validation process was executed | ||
194 | */ | ||
195 | GNUNET_TRANSPORT_VS_NEW, | ||
196 | |||
197 | /** | ||
198 | * Updated validation entry | ||
199 | * | ||
200 | * This is an update for an existing validation entry | ||
201 | */ | ||
202 | GNUNET_TRANSPORT_VS_UPDATE, | ||
203 | |||
204 | /** | ||
205 | * Timeout for validation entry | ||
206 | * | ||
207 | * A timeout occured during the validation process | ||
208 | */ | ||
209 | GNUNET_TRANSPORT_VS_TIMEOUT, | ||
210 | |||
211 | /** | ||
212 | * Validation entry is removed | ||
213 | * | ||
214 | * The validation entry is getting removed due to a failed validation | ||
215 | */ | ||
216 | GNUNET_TRANSPORT_VS_REMOVE | ||
217 | }; | ||
218 | |||
219 | |||
220 | /** | ||
221 | * Function called by the transport for each received message. | 48 | * Function called by the transport for each received message. |
222 | * | 49 | * |
223 | * @param cls closure | 50 | * @param cls closure |
224 | * @param peer (claimed) identity of the other peer | 51 | * @param peer (claimed) identity of the other peer |
225 | * @param message the message | 52 | * @param message the message |
226 | * @param ats performance data | ||
227 | * @param ats_count number of entries in @a ats | ||
228 | */ | 53 | */ |
229 | typedef void | 54 | typedef void |
230 | (*GNUNET_TRANSPORT_ReceiveCallback) (void *cls, | 55 | (*GNUNET_TRANSPORT_ReceiveCallback) (void *cls, |
@@ -244,8 +69,6 @@ struct GNUNET_TRANSPORT_Handle; | |||
244 | * | 69 | * |
245 | * @param cls closure | 70 | * @param cls closure |
246 | * @param peer the peer that connected | 71 | * @param peer the peer that connected |
247 | * @param ats performance data | ||
248 | * @param ats_count number of entries in @a ats (excluding 0-termination) | ||
249 | */ | 72 | */ |
250 | typedef void | 73 | typedef void |
251 | (*GNUNET_TRANSPORT_NotifyConnect) (void *cls, | 74 | (*GNUNET_TRANSPORT_NotifyConnect) (void *cls, |
@@ -264,97 +87,6 @@ typedef void | |||
264 | 87 | ||
265 | 88 | ||
266 | /** | 89 | /** |
267 | * Function to call with result of the try connect request. | ||
268 | * | ||
269 | * | ||
270 | * @param cls closure | ||
271 | * @param result #GNUNET_OK if message was transmitted to transport service | ||
272 | * #GNUNET_SYSERR if message was not transmitted to transport service | ||
273 | */ | ||
274 | typedef void | ||
275 | (*GNUNET_TRANSPORT_TryConnectCallback) (void *cls, | ||
276 | const int result); | ||
277 | |||
278 | |||
279 | /** | ||
280 | * Function to call with a textual representation of an address. This | ||
281 | * function will be called several times with different possible | ||
282 | * textual representations, and a last time with @address being NULL | ||
283 | * to signal the end of the iteration. Note that @address NULL | ||
284 | * always is the last call, regardless of the value in @a res. | ||
285 | * | ||
286 | * @param cls closure | ||
287 | * @param address NULL on end of iteration, | ||
288 | * otherwise 0-terminated printable UTF-8 string, | ||
289 | * in particular an empty string if @a res is #GNUNET_NO | ||
290 | * @param res result of the address to string conversion: | ||
291 | * if #GNUNET_OK: conversion successful | ||
292 | * if #GNUNET_NO: address was invalid (or not supported) | ||
293 | * if #GNUNET_SYSERR: communication error (IPC error) | ||
294 | */ | ||
295 | typedef void | ||
296 | (*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls, | ||
297 | const char *address, | ||
298 | int res); | ||
299 | |||
300 | |||
301 | /** | ||
302 | * Function to call with information about a peer | ||
303 | * | ||
304 | * If one_shot was set to #GNUNET_YES to iterate over all peers once, | ||
305 | * a final call with NULL for peer and address will follow when done. | ||
306 | * In this case state and timeout do not contain valid values. | ||
307 | * | ||
308 | * The #GNUNET_TRANSPORT_monitor_peers_cancel call MUST not be called from | ||
309 | * within this function! | ||
310 | * | ||
311 | * | ||
312 | * @param cls closure | ||
313 | * @param peer peer this update is about, | ||
314 | * NULL if this is the final last callback for a iteration operation | ||
315 | * @param address address, NULL for disconnect notification in monitor mode | ||
316 | * @param state current state this peer is in | ||
317 | * @param state_timeout timeout for the current state of the peer | ||
318 | */ | ||
319 | typedef void | ||
320 | (*GNUNET_TRANSPORT_PeerIterateCallback) (void *cls, | ||
321 | const struct GNUNET_PeerIdentity *peer, | ||
322 | const struct GNUNET_HELLO_Address *address, | ||
323 | enum GNUNET_TRANSPORT_PeerState state, | ||
324 | struct GNUNET_TIME_Absolute state_timeout); | ||
325 | |||
326 | |||
327 | /** | ||
328 | * Function to call with validation information about a peer | ||
329 | * | ||
330 | * This function is called by the transport validation monitoring api to | ||
331 | * indicate a change to a validation entry. The information included represent | ||
332 | * the current state of the validation entry, | ||
333 | * | ||
334 | * If the monitoring was called with one_shot=GNUNET_YES, a final callback | ||
335 | * with peer==NULL and address==NULL is executed. | ||
336 | * | ||
337 | * @param cls closure | ||
338 | * @param peer peer this update is about, | ||
339 | * NULL if this is the final last callback for a iteration operation | ||
340 | * @param address address, | ||
341 | * NULL for disconnect notification in monitor mode | ||
342 | * @param last_validation when was this address last validated | ||
343 | * @param valid_until when does this address expire | ||
344 | * @param next_validation time of the next validation operation | ||
345 | * @param state state in the validation state machine | ||
346 | */ | ||
347 | typedef void | ||
348 | (*GNUNET_TRANSPORT_ValidationIterateCallback) (void *cls, | ||
349 | const struct GNUNET_PeerIdentity *peer, | ||
350 | const struct GNUNET_HELLO_Address *address, | ||
351 | struct GNUNET_TIME_Absolute last_validation, | ||
352 | struct GNUNET_TIME_Absolute valid_until, | ||
353 | struct GNUNET_TIME_Absolute next_validation, | ||
354 | enum GNUNET_TRANSPORT_ValidationState state); | ||
355 | |||
356 | |||
357 | /** | ||
358 | * Connect to the transport service. Note that the connection may | 90 | * Connect to the transport service. Note that the connection may |
359 | * complete (or fail) asynchronously. | 91 | * complete (or fail) asynchronously. |
360 | * | 92 | * |
@@ -388,7 +120,7 @@ GNUNET_TRANSPORT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
388 | * See also the "max carry" in `struct GNUNET_BANDWIDTH_Tracker`. | 120 | * See also the "max carry" in `struct GNUNET_BANDWIDTH_Tracker`. |
389 | * | 121 | * |
390 | * @param cls the closure | 122 | * @param cls the closure |
391 | * @param peer peer that we have excess bandwidth to | 123 | * @param neighbour peer that we have excess bandwidth to |
392 | */ | 124 | */ |
393 | typedef void | 125 | typedef void |
394 | (*GNUNET_TRANSPORT_NotifyExcessBandwidth)(void *cls, | 126 | (*GNUNET_TRANSPORT_NotifyExcessBandwidth)(void *cls, |
@@ -428,11 +160,24 @@ void | |||
428 | GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle); | 160 | GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle); |
429 | 161 | ||
430 | 162 | ||
163 | /* ************************* Connections *********************** */ | ||
164 | |||
431 | /** | 165 | /** |
432 | * Opaque handle for a transmission-ready request. | 166 | * Opaque handle for a transmission-ready request. |
433 | */ | 167 | */ |
434 | struct GNUNET_TRANSPORT_TryConnectHandle; | 168 | struct GNUNET_TRANSPORT_TryConnectHandle; |
435 | 169 | ||
170 | /** | ||
171 | * Function to call with result of the try connect request. | ||
172 | * | ||
173 | * @param cls closure | ||
174 | * @param result #GNUNET_OK if message was transmitted to transport service | ||
175 | * #GNUNET_SYSERR if message was not transmitted to transport service | ||
176 | */ | ||
177 | typedef void | ||
178 | (*GNUNET_TRANSPORT_TryConnectCallback) (void *cls, | ||
179 | const int result); | ||
180 | |||
436 | 181 | ||
437 | /** | 182 | /** |
438 | * Ask the transport service to establish a connection to | 183 | * Ask the transport service to establish a connection to |
@@ -464,8 +209,7 @@ GNUNET_TRANSPORT_try_connect_cancel (struct GNUNET_TRANSPORT_TryConnectHandle *t | |||
464 | 209 | ||
465 | 210 | ||
466 | /** | 211 | /** |
467 | * Ask the transport service to establish a disconnect from | 212 | * Ask the transport service to disconnect from the given peer. |
468 | * the given peer. | ||
469 | * | 213 | * |
470 | * @param handle connection to transport service | 214 | * @param handle connection to transport service |
471 | * @param target who we should try to disconnect from | 215 | * @param target who we should try to disconnect from |
@@ -483,8 +227,8 @@ GNUNET_TRANSPORT_try_disconnect (struct GNUNET_TRANSPORT_Handle *handle, | |||
483 | 227 | ||
484 | 228 | ||
485 | /** | 229 | /** |
486 | * Cancel the request to transport to try a disconnect | 230 | * Cancel the request to transport to disconnect. |
487 | * Callback will not be called | 231 | * Callback will not be called anymore. |
488 | * | 232 | * |
489 | * @param tch handle for operation to cancel | 233 | * @param tch handle for operation to cancel |
490 | */ | 234 | */ |
@@ -492,6 +236,8 @@ void | |||
492 | GNUNET_TRANSPORT_try_disconnect_cancel (struct GNUNET_TRANSPORT_TryConnectHandle *tch); | 236 | GNUNET_TRANSPORT_try_disconnect_cancel (struct GNUNET_TRANSPORT_TryConnectHandle *tch); |
493 | 237 | ||
494 | 238 | ||
239 | /* ************************* Sending *************************** */ | ||
240 | |||
495 | /** | 241 | /** |
496 | * Opaque handle for a transmission-ready request. | 242 | * Opaque handle for a transmission-ready request. |
497 | */ | 243 | */ |
@@ -530,7 +276,7 @@ typedef size_t | |||
530 | * @param notify_cls closure for @a notify | 276 | * @param notify_cls closure for @a notify |
531 | * @return NULL if someone else is already waiting to be notified | 277 | * @return NULL if someone else is already waiting to be notified |
532 | * non-NULL if the notify callback was queued (can be used to cancel | 278 | * non-NULL if the notify callback was queued (can be used to cancel |
533 | * using GNUNET_TRANSPORT_notify_transmit_ready_cancel) | 279 | * using #GNUNET_TRANSPORT_notify_transmit_ready_cancel()) |
534 | */ | 280 | */ |
535 | struct GNUNET_TRANSPORT_TransmitHandle * | 281 | struct GNUNET_TRANSPORT_TransmitHandle * |
536 | GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle *handle, | 282 | GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle *handle, |
@@ -550,23 +296,6 @@ void | |||
550 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct GNUNET_TRANSPORT_TransmitHandle *th); | 296 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct GNUNET_TRANSPORT_TransmitHandle *th); |
551 | 297 | ||
552 | 298 | ||
553 | /** | ||
554 | * Function called whenever there is an update to the | ||
555 | * HELLO of this peer. | ||
556 | * | ||
557 | * @param cls closure | ||
558 | * @param hello our updated HELLO | ||
559 | */ | ||
560 | typedef void | ||
561 | (*GNUNET_TRANSPORT_HelloUpdateCallback) (void *cls, | ||
562 | const struct GNUNET_MessageHeader *hello); | ||
563 | |||
564 | |||
565 | /** | ||
566 | * Handle to cancel a #GNUNET_TRANSPORT_get_hello() operation. | ||
567 | */ | ||
568 | struct GNUNET_TRANSPORT_GetHelloHandle; | ||
569 | |||
570 | 299 | ||
571 | /** | 300 | /** |
572 | * Checks if a given peer is connected to us | 301 | * Checks if a given peer is connected to us |
@@ -580,6 +309,9 @@ GNUNET_TRANSPORT_check_peer_connected (struct GNUNET_TRANSPORT_Handle *handle, | |||
580 | const struct GNUNET_PeerIdentity *peer); | 309 | const struct GNUNET_PeerIdentity *peer); |
581 | 310 | ||
582 | 311 | ||
312 | |||
313 | /* *********************** Metric manipulation ***************** */ | ||
314 | |||
583 | /** | 315 | /** |
584 | * Set transport metrics for a peer and a direction | 316 | * Set transport metrics for a peer and a direction |
585 | * | 317 | * |
@@ -615,6 +347,27 @@ GNUNET_TRANSPORT_set_traffic_metric (struct GNUNET_TRANSPORT_Handle *handle, | |||
615 | size_t ats_count); | 347 | size_t ats_count); |
616 | 348 | ||
617 | 349 | ||
350 | /* *************************** HELLO *************************** */ | ||
351 | |||
352 | |||
353 | /** | ||
354 | * Function called whenever there is an update to the | ||
355 | * HELLO of this peer. | ||
356 | * | ||
357 | * @param cls closure | ||
358 | * @param hello our updated HELLO | ||
359 | */ | ||
360 | typedef void | ||
361 | (*GNUNET_TRANSPORT_HelloUpdateCallback) (void *cls, | ||
362 | const struct GNUNET_MessageHeader *hello); | ||
363 | |||
364 | |||
365 | /** | ||
366 | * Handle to cancel a #GNUNET_TRANSPORT_get_hello() operation. | ||
367 | */ | ||
368 | struct GNUNET_TRANSPORT_GetHelloHandle; | ||
369 | |||
370 | |||
618 | /** | 371 | /** |
619 | * Obtain updates on changes to the HELLO message for this peer. The callback | 372 | * Obtain updates on changes to the HELLO message for this peer. The callback |
620 | * given in this function is never called synchronously. | 373 | * given in this function is never called synchronously. |
@@ -674,6 +427,8 @@ void | |||
674 | GNUNET_TRANSPORT_offer_hello_cancel (struct GNUNET_TRANSPORT_OfferHelloHandle *ohh); | 427 | GNUNET_TRANSPORT_offer_hello_cancel (struct GNUNET_TRANSPORT_OfferHelloHandle *ohh); |
675 | 428 | ||
676 | 429 | ||
430 | /* *********************** Address to String ******************* */ | ||
431 | |||
677 | /** | 432 | /** |
678 | * Handle to cancel a pending address lookup. | 433 | * Handle to cancel a pending address lookup. |
679 | */ | 434 | */ |
@@ -681,6 +436,28 @@ struct GNUNET_TRANSPORT_AddressToStringContext; | |||
681 | 436 | ||
682 | 437 | ||
683 | /** | 438 | /** |
439 | * Function to call with a textual representation of an address. This | ||
440 | * function will be called several times with different possible | ||
441 | * textual representations, and a last time with @address being NULL | ||
442 | * to signal the end of the iteration. Note that @address NULL | ||
443 | * always is the last call, regardless of the value in @a res. | ||
444 | * | ||
445 | * @param cls closure | ||
446 | * @param address NULL on end of iteration, | ||
447 | * otherwise 0-terminated printable UTF-8 string, | ||
448 | * in particular an empty string if @a res is #GNUNET_NO | ||
449 | * @param res result of the address to string conversion: | ||
450 | * if #GNUNET_OK: conversion successful | ||
451 | * if #GNUNET_NO: address was invalid (or not supported) | ||
452 | * if #GNUNET_SYSERR: communication error (IPC error) | ||
453 | */ | ||
454 | typedef void | ||
455 | (*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls, | ||
456 | const char *address, | ||
457 | int res); | ||
458 | |||
459 | |||
460 | /** | ||
684 | * Convert a binary address into a human readable address. | 461 | * Convert a binary address into a human readable address. |
685 | * | 462 | * |
686 | * @param cfg configuration to use | 463 | * @param cfg configuration to use |
@@ -710,6 +487,136 @@ void | |||
710 | GNUNET_TRANSPORT_address_to_string_cancel (struct GNUNET_TRANSPORT_AddressToStringContext *pic); | 487 | GNUNET_TRANSPORT_address_to_string_cancel (struct GNUNET_TRANSPORT_AddressToStringContext *pic); |
711 | 488 | ||
712 | 489 | ||
490 | /* *********************** Monitoring ************************** */ | ||
491 | |||
492 | |||
493 | /** | ||
494 | * Possible state of a neighbour. Initially, we are #GNUNET_TRANSPORT_PS_NOT_CONNECTED. | ||
495 | * | ||
496 | * Then, there are two main paths. If we receive a CONNECT message, we give | ||
497 | * the inbound address to ATS. After the check we ask ATS for a suggestion | ||
498 | * (#GNUNET_TRANSPORT_PS_CONNECT_RECV_ATS). If ATS makes a suggestion, we | ||
499 | * send our CONNECT_ACK and go to #GNUNET_TRANSPORT_PS_CONNECT_RECV_ACK. | ||
500 | * If we receive a SESSION_ACK, we go to #GNUNET_TRANSPORT_PS_CONNECTED | ||
501 | * (and notify everyone about the new connection). If the operation times out, | ||
502 | * we go to #GNUNET_TRANSPORT_PS_DISCONNECT. | ||
503 | * | ||
504 | * The other case is where we transmit a CONNECT message first. We | ||
505 | * start with #GNUNET_TRANSPORT_PS_INIT_ATS. If we get an address, we send | ||
506 | * the CONNECT message and go to state #GNUNET_TRANSPORT_PS_CONNECT_SENT. | ||
507 | * Once we receive a CONNECT_ACK, we go to #GNUNET_TRANSPORT_PS_CONNECTED | ||
508 | * (and notify everyone about the new connection and send | ||
509 | * back a SESSION_ACK). If the operation times out, we go to | ||
510 | * #GNUNET_TRANSPORT_PS_DISCONNECT. | ||
511 | * | ||
512 | * If the session is in trouble (i.e. transport-level disconnect or | ||
513 | * timeout), we go to #GNUNET_TRANSPORT_PS_RECONNECT_ATS where we ask ATS for a new | ||
514 | * address (we don't notify anyone about the disconnect yet). Once we | ||
515 | * have a new address, we enter #GNUNET_TRANSPORT_PS_RECONNECT_SENT and send a | ||
516 | * CONNECT message. If we receive a | ||
517 | * CONNECT_ACK, we go to #GNUNET_TRANSPORT_PS_CONNECTED and nobody noticed that we had | ||
518 | * trouble; we also send a SESSION_ACK at this time just in case. If | ||
519 | * the operation times out, we go to #GNUNET_TRANSPORT_PS_DISCONNECT (and notify everyone | ||
520 | * about the lost connection). | ||
521 | * | ||
522 | * If ATS decides to switch addresses while we have a normal | ||
523 | * connection, we go to #GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_CONNECT_SENT | ||
524 | * and send a SESSION_CONNECT. If we get a SESSION_ACK back, we switch the | ||
525 | * primary connection to the suggested alternative from ATS, go back | ||
526 | * to #GNUNET_TRANSPORT_PS_CONNECTED and send a SESSION_ACK to the other peer just to be | ||
527 | * sure. If the operation times out | ||
528 | * we go to #GNUNET_TRANSPORT_PS_CONNECTED (and notify ATS that the given alternative | ||
529 | * address is "invalid"). | ||
530 | * | ||
531 | * Once a session is in #GNUNET_TRANSPORT_PS_DISCONNECT, it is cleaned up and then goes | ||
532 | * to (#GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED). If we receive an explicit disconnect | ||
533 | * request, we can go from any state to #GNUNET_TRANSPORT_PS_DISCONNECT, possibly after | ||
534 | * generating disconnect notifications. | ||
535 | * | ||
536 | * Note that it is quite possible that while we are in any of these | ||
537 | * states, we could receive a 'CONNECT' request from the other peer. | ||
538 | * We then enter a 'weird' state where we pursue our own primary state | ||
539 | * machine (as described above), but with the 'send_connect_ack' flag | ||
540 | * set to 1. If our state machine allows us to send a 'CONNECT_ACK' | ||
541 | * (because we have an acceptable address), we send the 'CONNECT_ACK' | ||
542 | * and set the 'send_connect_ack' to 2. If we then receive a | ||
543 | * 'SESSION_ACK', we go to #GNUNET_TRANSPORT_PS_CONNECTED (and reset 'send_connect_ack' | ||
544 | * to 0). | ||
545 | * | ||
546 | */ | ||
547 | enum GNUNET_TRANSPORT_PeerState | ||
548 | { | ||
549 | /** | ||
550 | * Fresh peer or completely disconnected | ||
551 | */ | ||
552 | GNUNET_TRANSPORT_PS_NOT_CONNECTED = 0, | ||
553 | |||
554 | /** | ||
555 | * Asked to initiate connection, trying to get address from ATS | ||
556 | */ | ||
557 | GNUNET_TRANSPORT_PS_INIT_ATS, | ||
558 | |||
559 | /** | ||
560 | * Sent CONNECT message to other peer, waiting for CONNECT_ACK | ||
561 | */ | ||
562 | GNUNET_TRANSPORT_PS_CONNECT_SENT, | ||
563 | |||
564 | /** | ||
565 | * Received a CONNECT, asking ATS about address suggestions. | ||
566 | */ | ||
567 | GNUNET_TRANSPORT_PS_CONNECT_RECV_ATS, | ||
568 | |||
569 | /** | ||
570 | * CONNECT request from other peer was CONNECT_ACK'ed, waiting for | ||
571 | * SESSION_ACK. | ||
572 | */ | ||
573 | GNUNET_TRANSPORT_PS_CONNECT_RECV_ACK, | ||
574 | |||
575 | /** | ||
576 | * Got our CONNECT_ACK/SESSION_ACK, connection is up. | ||
577 | */ | ||
578 | GNUNET_TRANSPORT_PS_CONNECTED, | ||
579 | |||
580 | /** | ||
581 | * Connection got into trouble, rest of the system still believes | ||
582 | * it to be up, but we're getting a new address from ATS. | ||
583 | */ | ||
584 | GNUNET_TRANSPORT_PS_RECONNECT_ATS, | ||
585 | |||
586 | /** | ||
587 | * Sent CONNECT over new address (either by ATS telling us to switch | ||
588 | * addresses or from RECONNECT_ATS); if this fails, we need to tell | ||
589 | * the rest of the system about a disconnect. | ||
590 | */ | ||
591 | GNUNET_TRANSPORT_PS_RECONNECT_SENT, | ||
592 | |||
593 | /** | ||
594 | * We have some primary connection, but ATS suggested we switch | ||
595 | * to some alternative; we now sent a CONNECT message for the | ||
596 | * alternative session to the other peer and waiting for a | ||
597 | * CONNECT_ACK to make this our primary connection. | ||
598 | */ | ||
599 | GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_CONNECT_SENT, | ||
600 | |||
601 | /** | ||
602 | * Disconnect in progress (we're sending the DISCONNECT message to the | ||
603 | * other peer; after that is finished, the state will be cleaned up). | ||
604 | */ | ||
605 | GNUNET_TRANSPORT_PS_DISCONNECT, | ||
606 | |||
607 | /** | ||
608 | * We're finished with the disconnect; and are cleaning up the state | ||
609 | * now! We put the struct into this state when we are really in the | ||
610 | * task that calls 'free' on it and are about to remove the record | ||
611 | * from the map. We should never find a 'struct NeighbourMapEntry' | ||
612 | * in this state in the map. Accessing a 'struct NeighbourMapEntry' | ||
613 | * in this state virtually always means using memory that has been | ||
614 | * freed (the exception being the cleanup code in #free_neighbour()). | ||
615 | */ | ||
616 | GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED | ||
617 | }; | ||
618 | |||
619 | |||
713 | /** | 620 | /** |
714 | * Convert a transport state to a human readable string. | 621 | * Convert a transport state to a human readable string. |
715 | * | 622 | * |
@@ -730,19 +637,36 @@ GNUNET_TRANSPORT_is_connected (enum GNUNET_TRANSPORT_PeerState state); | |||
730 | 637 | ||
731 | 638 | ||
732 | /** | 639 | /** |
733 | * Convert validation state to human-readable string. | 640 | * Handle for a #GNUNET_TRANSPORT_monitor_peers operation. |
734 | * | ||
735 | * @param state the state value | ||
736 | * @return corresponding string | ||
737 | */ | 641 | */ |
738 | const char * | 642 | struct GNUNET_TRANSPORT_PeerMonitoringContext; |
739 | GNUNET_TRANSPORT_vs2s (enum GNUNET_TRANSPORT_ValidationState state); | ||
740 | 643 | ||
741 | 644 | ||
742 | /** | 645 | /** |
743 | * Handle for a #GNUNET_TRANSPORT_monitor_peers operation. | 646 | * Function to call with information about a peer |
647 | * | ||
648 | * If one_shot was set to #GNUNET_YES to iterate over all peers once, | ||
649 | * a final call with NULL for peer and address will follow when done. | ||
650 | * In this case state and timeout do not contain valid values. | ||
651 | * | ||
652 | * The #GNUNET_TRANSPORT_monitor_peers_cancel call MUST not be called from | ||
653 | * within this function! | ||
654 | * | ||
655 | * | ||
656 | * @param cls closure | ||
657 | * @param peer peer this update is about, | ||
658 | * NULL if this is the final last callback for a iteration operation | ||
659 | * @param address address, NULL for disconnect notification in monitor mode | ||
660 | * @param state current state this peer is in | ||
661 | * @param state_timeout timeout for the current state of the peer | ||
744 | */ | 662 | */ |
745 | struct GNUNET_TRANSPORT_PeerMonitoringContext; | 663 | typedef void |
664 | (*GNUNET_TRANSPORT_PeerIterateCallback) (void *cls, | ||
665 | const struct GNUNET_PeerIdentity *peer, | ||
666 | const struct GNUNET_HELLO_Address *address, | ||
667 | enum GNUNET_TRANSPORT_PeerState state, | ||
668 | struct GNUNET_TIME_Absolute state_timeout); | ||
669 | |||
746 | 670 | ||
747 | /** | 671 | /** |
748 | * Return information about a specific peer or all peers currently known to | 672 | * Return information about a specific peer or all peers currently known to |
@@ -794,6 +718,93 @@ GNUNET_TRANSPORT_monitor_peers_cancel (struct GNUNET_TRANSPORT_PeerMonitoringCon | |||
794 | */ | 718 | */ |
795 | struct GNUNET_TRANSPORT_ValidationMonitoringContext; | 719 | struct GNUNET_TRANSPORT_ValidationMonitoringContext; |
796 | 720 | ||
721 | |||
722 | /** | ||
723 | * Current state of a validation process. | ||
724 | * | ||
725 | * FIXME: what state is used to indicate that a validation | ||
726 | * was successful? If that is clarified/determined, "UGH" in | ||
727 | * ~gnunet-peerinfo-gtk.c:1103 should be resolved. | ||
728 | */ | ||
729 | enum GNUNET_TRANSPORT_ValidationState | ||
730 | { | ||
731 | /** | ||
732 | * Undefined state | ||
733 | * | ||
734 | * Used for final callback indicating operation done | ||
735 | */ | ||
736 | GNUNET_TRANSPORT_VS_NONE, | ||
737 | |||
738 | /** | ||
739 | * Fresh validation entry | ||
740 | * | ||
741 | * Entry was just created, no validation process was executed | ||
742 | */ | ||
743 | GNUNET_TRANSPORT_VS_NEW, | ||
744 | |||
745 | /** | ||
746 | * Updated validation entry | ||
747 | * | ||
748 | * This is an update for an existing validation entry | ||
749 | */ | ||
750 | GNUNET_TRANSPORT_VS_UPDATE, | ||
751 | |||
752 | /** | ||
753 | * Timeout for validation entry | ||
754 | * | ||
755 | * A timeout occured during the validation process | ||
756 | */ | ||
757 | GNUNET_TRANSPORT_VS_TIMEOUT, | ||
758 | |||
759 | /** | ||
760 | * Validation entry is removed | ||
761 | * | ||
762 | * The validation entry is getting removed due to a failed validation | ||
763 | */ | ||
764 | GNUNET_TRANSPORT_VS_REMOVE | ||
765 | }; | ||
766 | |||
767 | |||
768 | /** | ||
769 | * Function to call with validation information about a peer | ||
770 | * | ||
771 | * This function is called by the transport validation monitoring api to | ||
772 | * indicate a change to a validation entry. The information included represent | ||
773 | * the current state of the validation entry, | ||
774 | * | ||
775 | * If the monitoring was called with one_shot=GNUNET_YES, a final callback | ||
776 | * with peer==NULL and address==NULL is executed. | ||
777 | * | ||
778 | * @param cls closure | ||
779 | * @param peer peer this update is about, | ||
780 | * NULL if this is the final last callback for a iteration operation | ||
781 | * @param address address, | ||
782 | * NULL for disconnect notification in monitor mode | ||
783 | * @param last_validation when was this address last validated | ||
784 | * @param valid_until when does this address expire | ||
785 | * @param next_validation time of the next validation operation | ||
786 | * @param state state in the validation state machine | ||
787 | */ | ||
788 | typedef void | ||
789 | (*GNUNET_TRANSPORT_ValidationIterateCallback) (void *cls, | ||
790 | const struct GNUNET_PeerIdentity *peer, | ||
791 | const struct GNUNET_HELLO_Address *address, | ||
792 | struct GNUNET_TIME_Absolute last_validation, | ||
793 | struct GNUNET_TIME_Absolute valid_until, | ||
794 | struct GNUNET_TIME_Absolute next_validation, | ||
795 | enum GNUNET_TRANSPORT_ValidationState state); | ||
796 | |||
797 | |||
798 | /** | ||
799 | * Convert validation state to human-readable string. | ||
800 | * | ||
801 | * @param state the state value | ||
802 | * @return corresponding string | ||
803 | */ | ||
804 | const char * | ||
805 | GNUNET_TRANSPORT_vs2s (enum GNUNET_TRANSPORT_ValidationState state); | ||
806 | |||
807 | |||
797 | /** | 808 | /** |
798 | * Return information about pending address validation operations for a specific | 809 | * Return information about pending address validation operations for a specific |
799 | * or all peers | 810 | * or all peers |
@@ -825,6 +836,8 @@ void | |||
825 | GNUNET_TRANSPORT_monitor_validation_entries_cancel (struct GNUNET_TRANSPORT_ValidationMonitoringContext *vic); | 836 | GNUNET_TRANSPORT_monitor_validation_entries_cancel (struct GNUNET_TRANSPORT_ValidationMonitoringContext *vic); |
826 | 837 | ||
827 | 838 | ||
839 | /* *********************** Blacklisting ************************ */ | ||
840 | |||
828 | /** | 841 | /** |
829 | * Handle for blacklisting peers. | 842 | * Handle for blacklisting peers. |
830 | */ | 843 | */ |
@@ -840,8 +853,7 @@ struct GNUNET_TRANSPORT_Blacklist; | |||
840 | */ | 853 | */ |
841 | typedef int | 854 | typedef int |
842 | (*GNUNET_TRANSPORT_BlacklistCallback) (void *cls, | 855 | (*GNUNET_TRANSPORT_BlacklistCallback) (void *cls, |
843 | const struct | 856 | const struct GNUNET_PeerIdentity *pid); |
844 | GNUNET_PeerIdentity * pid); | ||
845 | 857 | ||
846 | 858 | ||
847 | /** | 859 | /** |
diff --git a/src/include/gnunet_tun_lib.h b/src/include/gnunet_tun_lib.h index 7d1e7cfed..276a42144 100644 --- a/src/include/gnunet_tun_lib.h +++ b/src/include/gnunet_tun_lib.h | |||
@@ -185,6 +185,18 @@ struct GNUNET_TUN_IPv6Header | |||
185 | 185 | ||
186 | 186 | ||
187 | /** | 187 | /** |
188 | * TCP flags. | ||
189 | */ | ||
190 | #define GNUNET_TUN_TCP_FLAGS_FIN 1 | ||
191 | #define GNUNET_TUN_TCP_FLAGS_SYN 2 | ||
192 | #define GNUNET_TUN_TCP_FLAGS_RST 4 | ||
193 | #define GNUNET_TUN_TCP_FLAGS_PSH 8 | ||
194 | #define GNUNET_TUN_TCP_FLAGS_ACK 16 | ||
195 | #define GNUNET_TUN_TCP_FLAGS_URG 32 | ||
196 | #define GNUNET_TUN_TCP_FLAGS_ECE 64 | ||
197 | #define GNUNET_TUN_TCP_FLAGS_CWR 128 | ||
198 | |||
199 | /** | ||
188 | * TCP packet header. | 200 | * TCP packet header. |
189 | */ | 201 | */ |
190 | struct GNUNET_TUN_TcpHeader | 202 | struct GNUNET_TUN_TcpHeader |