diff options
Diffstat (limited to 'src/transport/gnunet-service-transport_neighbours.c')
-rw-r--r-- | src/transport/gnunet-service-transport_neighbours.c | 169 |
1 files changed, 4 insertions, 165 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index 7183f1f84..d451991f1 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c | |||
@@ -231,167 +231,6 @@ struct MessageQueue | |||
231 | }; | 231 | }; |
232 | 232 | ||
233 | 233 | ||
234 | /** | ||
235 | * Possible state of a neighbour. Initially, we are #S_NOT_CONNECTED. | ||
236 | * | ||
237 | * Then, there are two main paths. If we receive a CONNECT message, we | ||
238 | * first run a check against the blacklist (#S_CONNECT_RECV_BLACKLIST_INBOUND). | ||
239 | * If this check is successful, we give the inbound address to ATS. | ||
240 | * After the check we ask ATS for a suggestion (S_CONNECT_RECV_ATS). | ||
241 | * If ATS makes a suggestion, we ALSO give that suggestion to the blacklist | ||
242 | * (#S_CONNECT_RECV_BLACKLIST). Once the blacklist approves the | ||
243 | * address we got from ATS, we send our CONNECT_ACK and go to | ||
244 | * #S_CONNECT_RECV_ACK. If we receive a SESSION_ACK, we go to | ||
245 | * #S_CONNECTED (and notify everyone about the new connection). If the | ||
246 | * operation times out, we go to #S_DISCONNECT. | ||
247 | * | ||
248 | * The other case is where we transmit a CONNECT message first. We | ||
249 | * start with #S_INIT_ATS. If we get an address, we enter | ||
250 | * #S_INIT_BLACKLIST and check the blacklist. If the blacklist is OK | ||
251 | * with the connection, we actually send the CONNECT message and go to | ||
252 | * state S_CONNECT_SENT. Once we receive a CONNECT_ACK, we go to | ||
253 | * #S_CONNECTED (and notify everyone about the new connection and send | ||
254 | * back a SESSION_ACK). If the operation times out, we go to | ||
255 | * #S_DISCONNECT. | ||
256 | * | ||
257 | * If the session is in trouble (i.e. transport-level disconnect or | ||
258 | * timeout), we go to #S_RECONNECT_ATS where we ask ATS for a new | ||
259 | * address (we don't notify anyone about the disconnect yet). Once we | ||
260 | * have a new address, we go to #S_RECONNECT_BLACKLIST to check the new | ||
261 | * address against the blacklist. If the blacklist approves, we enter | ||
262 | * #S_RECONNECT_SENT and send a CONNECT message. If we receive a | ||
263 | * CONNECT_ACK, we go to #S_CONNECTED and nobody noticed that we had | ||
264 | * trouble; we also send a SESSION_ACK at this time just in case. If | ||
265 | * the operation times out, we go to S_DISCONNECT (and notify everyone | ||
266 | * about the lost connection). | ||
267 | * | ||
268 | * If ATS decides to switch addresses while we have a normal | ||
269 | * connection, we go to #S_CONNECTED_SWITCHING_BLACKLIST to check the | ||
270 | * new address against the blacklist. If the blacklist approves, we | ||
271 | * go to #S_CONNECTED_SWITCHING_CONNECT_SENT and send a | ||
272 | * SESSION_CONNECT. If we get a SESSION_ACK back, we switch the | ||
273 | * primary connection to the suggested alternative from ATS, go back | ||
274 | * to #S_CONNECTED and send a SESSION_ACK to the other peer just to be | ||
275 | * sure. If the operation times out (or the blacklist disapproves), | ||
276 | * we go to #S_CONNECTED (and notify ATS that the given alternative | ||
277 | * address is "invalid"). | ||
278 | * | ||
279 | * Once a session is in #S_DISCONNECT, it is cleaned up and then goes | ||
280 | * to (#S_DISCONNECT_FINISHED). If we receive an explicit disconnect | ||
281 | * request, we can go from any state to #S_DISCONNECT, possibly after | ||
282 | * generating disconnect notifications. | ||
283 | * | ||
284 | * Note that it is quite possible that while we are in any of these | ||
285 | * states, we could receive a 'CONNECT' request from the other peer. | ||
286 | * We then enter a 'weird' state where we pursue our own primary state | ||
287 | * machine (as described above), but with the 'send_connect_ack' flag | ||
288 | * set to 1. If our state machine allows us to send a 'CONNECT_ACK' | ||
289 | * (because we have an acceptable address), we send the 'CONNECT_ACK' | ||
290 | * and set the 'send_connect_ack' to 2. If we then receive a | ||
291 | * 'SESSION_ACK', we go to #S_CONNECTED (and reset 'send_connect_ack' | ||
292 | * to 0). | ||
293 | * | ||
294 | */ | ||
295 | enum State | ||
296 | { | ||
297 | /** | ||
298 | * fresh peer or completely disconnected | ||
299 | */ | ||
300 | S_NOT_CONNECTED = 0, | ||
301 | |||
302 | /** | ||
303 | * Asked to initiate connection, trying to get address from ATS | ||
304 | */ | ||
305 | S_INIT_ATS, | ||
306 | |||
307 | /** | ||
308 | * Asked to initiate connection, trying to get address approved | ||
309 | * by blacklist. | ||
310 | */ | ||
311 | S_INIT_BLACKLIST, | ||
312 | |||
313 | /** | ||
314 | * Sent CONNECT message to other peer, waiting for CONNECT_ACK | ||
315 | */ | ||
316 | S_CONNECT_SENT, | ||
317 | |||
318 | /** | ||
319 | * Received a CONNECT, do a blacklist check for inbound address | ||
320 | */ | ||
321 | S_CONNECT_RECV_BLACKLIST_INBOUND, | ||
322 | |||
323 | /** | ||
324 | * Received a CONNECT, asking ATS about address suggestions. | ||
325 | */ | ||
326 | S_CONNECT_RECV_ATS, | ||
327 | |||
328 | /** | ||
329 | * Received CONNECT from other peer, got an address, checking with blacklist. | ||
330 | */ | ||
331 | S_CONNECT_RECV_BLACKLIST, | ||
332 | |||
333 | /** | ||
334 | * CONNECT request from other peer was SESSION_ACK'ed, waiting for | ||
335 | * SESSION_ACK. | ||
336 | */ | ||
337 | S_CONNECT_RECV_ACK, | ||
338 | |||
339 | /** | ||
340 | * Got our CONNECT_ACK/SESSION_ACK, connection is up. | ||
341 | */ | ||
342 | S_CONNECTED, | ||
343 | |||
344 | /** | ||
345 | * Connection got into trouble, rest of the system still believes | ||
346 | * it to be up, but we're getting a new address from ATS. | ||
347 | */ | ||
348 | S_RECONNECT_ATS, | ||
349 | |||
350 | /** | ||
351 | * Connection got into trouble, rest of the system still believes | ||
352 | * it to be up; we are checking the new address against the blacklist. | ||
353 | */ | ||
354 | S_RECONNECT_BLACKLIST, | ||
355 | |||
356 | /** | ||
357 | * Sent CONNECT over new address (either by ATS telling us to switch | ||
358 | * addresses or from RECONNECT_ATS); if this fails, we need to tell | ||
359 | * the rest of the system about a disconnect. | ||
360 | */ | ||
361 | S_RECONNECT_SENT, | ||
362 | |||
363 | /** | ||
364 | * We have some primary connection, but ATS suggested we switch | ||
365 | * to some alternative; we're now checking the alternative against | ||
366 | * the blacklist. | ||
367 | */ | ||
368 | S_CONNECTED_SWITCHING_BLACKLIST, | ||
369 | |||
370 | /** | ||
371 | * We have some primary connection, but ATS suggested we switch | ||
372 | * to some alternative; we now sent a CONNECT message for the | ||
373 | * alternative session to the other peer and waiting for a | ||
374 | * CONNECT_ACK to make this our primary connection. | ||
375 | */ | ||
376 | S_CONNECTED_SWITCHING_CONNECT_SENT, | ||
377 | |||
378 | /** | ||
379 | * Disconnect in progress (we're sending the DISCONNECT message to the | ||
380 | * other peer; after that is finished, the state will be cleaned up). | ||
381 | */ | ||
382 | S_DISCONNECT, | ||
383 | |||
384 | /** | ||
385 | * We're finished with the disconnect; and are cleaning up the state | ||
386 | * now! We put the struct into this state when we are really in the | ||
387 | * task that calls 'free' on it and are about to remove the record | ||
388 | * from the map. We should never find a 'struct NeighbourMapEntry' | ||
389 | * in this state in the map. Accessing a 'struct NeighbourMapEntry' | ||
390 | * in this state virtually always means using memory that has been | ||
391 | * freed (the exception being the cleanup code in #free_neighbour()). | ||
392 | */ | ||
393 | S_DISCONNECT_FINISHED | ||
394 | }; | ||
395 | 234 | ||
396 | 235 | ||
397 | /** | 236 | /** |
@@ -534,7 +373,7 @@ struct NeighbourMapEntry | |||
534 | /** | 373 | /** |
535 | * The current state of the peer. | 374 | * The current state of the peer. |
536 | */ | 375 | */ |
537 | enum State state; | 376 | enum GNUNET_TRANSPORT_PeerState state; |
538 | 377 | ||
539 | /** | 378 | /** |
540 | * Did we sent an KEEP_ALIVE message and are we expecting a response? | 379 | * Did we sent an KEEP_ALIVE message and are we expecting a response? |
@@ -641,7 +480,7 @@ static GNUNET_TRANSPORT_NotifyDisconnect disconnect_notify_cb; | |||
641 | /** | 480 | /** |
642 | * Function to call when we changed an active address of a neighbour. | 481 | * Function to call when we changed an active address of a neighbour. |
643 | */ | 482 | */ |
644 | static GNUNET_TRANSPORT_PeerIterateCallback address_change_cb; | 483 | static GNUNET_TRANSPORT_AddressChangeCallback address_change_cb; |
645 | 484 | ||
646 | /** | 485 | /** |
647 | * counter for connected neighbours | 486 | * counter for connected neighbours |
@@ -681,7 +520,7 @@ lookup_neighbour (const struct GNUNET_PeerIdentity *pid) | |||
681 | * @return corresponding string | 520 | * @return corresponding string |
682 | */ | 521 | */ |
683 | static const char * | 522 | static const char * |
684 | print_state (enum State state) | 523 | print_state (enum GNUNET_TRANSPORT_PeerState state) |
685 | { | 524 | { |
686 | switch (state) | 525 | switch (state) |
687 | { | 526 | { |
@@ -3616,7 +3455,7 @@ void | |||
3616 | GST_neighbours_start (void *cls, | 3455 | GST_neighbours_start (void *cls, |
3617 | NotifyConnect connect_cb, | 3456 | NotifyConnect connect_cb, |
3618 | GNUNET_TRANSPORT_NotifyDisconnect disconnect_cb, | 3457 | GNUNET_TRANSPORT_NotifyDisconnect disconnect_cb, |
3619 | GNUNET_TRANSPORT_PeerIterateCallback peer_address_cb, | 3458 | GNUNET_TRANSPORT_AddressChangeCallback peer_address_cb, |
3620 | unsigned int max_fds) | 3459 | unsigned int max_fds) |
3621 | { | 3460 | { |
3622 | callback_cls = cls; | 3461 | callback_cls = cls; |