aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_neighbours.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2014-03-27 15:03:17 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2014-03-27 15:03:17 +0000
commit075f1356987b48d3afd3f5c01ddebe23fa0ae240 (patch)
tree50a1afb6b14bafe34e34f262bf4a4e38c888dee5 /src/transport/gnunet-service-transport_neighbours.c
parentce53b7a21b4c04ddc36b5dd5256608560bb8bb2a (diff)
downloadgnunet-075f1356987b48d3afd3f5c01ddebe23fa0ae240.tar.gz
gnunet-075f1356987b48d3afd3f5c01ddebe23fa0ae240.zip
We do not need the address and session here
Diffstat (limited to 'src/transport/gnunet-service-transport_neighbours.c')
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c80
1 files changed, 47 insertions, 33 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index 7202ba899..025cf5f76 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -400,10 +400,15 @@ struct NeighbourMapEntry
400 int expect_latency_response; 400 int expect_latency_response;
401 401
402 /** 402 /**
403 * When a peer wants to connect we have to reply to the 1st CONNECT message
404 * with a CONNECT_ACK message. But sometime we cannot send this message
405 * immediately since we do not have an address and then we have to remember
406 * to send this message as soon as we have an address.
407 *
403 * Flag to set if we still need to send a CONNECT_ACK message to the other peer 408 * Flag to set if we still need to send a CONNECT_ACK message to the other peer
404 * (once we have an address to use and the peer has been allowed by our 409 * (once we have an address to use and the peer has been allowed by our
405 * blacklist). Initially set to #ACK_UNDEFINED. Set to #ACK_SEND_CONNECT_ACK 410 * blacklist). Initially set to #ACK_UNDEFINED. Set to #ACK_SEND_CONNECT_ACK
406 * if we need to send a CONNECT_ACK. Set to #ACK_SEND_CONNECT_ACK if we did 411 * if we need to send a CONNECT_ACK. Set to #SESSION_ACK if we did
407 * send a CONNECT_ACK and should go to 'S_CONNECTED' upon receiving a 412 * send a CONNECT_ACK and should go to 'S_CONNECTED' upon receiving a
408 * 'SESSION_ACK' (regardless of what our own state machine might say). 413 * 'SESSION_ACK' (regardless of what our own state machine might say).
409 */ 414 */
@@ -1851,6 +1856,7 @@ send_session_connect_ack_cont (void *cls,
1851 * @param address address to use 1856 * @param address address to use
1852 * @param session session to use 1857 * @param session session to use
1853 * @param timestamp timestamp to use for the ACK message 1858 * @param timestamp timestamp to use for the ACK message
1859 * @return GNUNET_SYSERR if sending immediately failed, GNUNET_OK otherwise
1854 */ 1860 */
1855static void 1861static void
1856send_connect_ack_message (const struct GNUNET_HELLO_Address *address, 1862send_connect_ack_message (const struct GNUNET_HELLO_Address *address,
@@ -2275,24 +2281,16 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target)
2275 * 2281 *
2276 * @param message possibly a 'struct SessionConnectMessage' (check format) 2282 * @param message possibly a 'struct SessionConnectMessage' (check format)
2277 * @param peer identity of the peer to switch the address for 2283 * @param peer identity of the peer to switch the address for
2278 * @param address address of the other peer, NULL if other peer
2279 * connected to us
2280 * @param session session to use (or NULL)
2281 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error 2284 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
2282 */ 2285 */
2283int 2286int
2284GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message, 2287GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
2285 const struct GNUNET_PeerIdentity *peer, 2288 const struct GNUNET_PeerIdentity *peer)
2286 const struct GNUNET_HELLO_Address *address,
2287 struct Session *session)
2288{ 2289{
2289 const struct SessionConnectMessage *scm; 2290 const struct SessionConnectMessage *scm;
2290 struct NeighbourMapEntry *n; 2291 struct NeighbourMapEntry *n;
2291 struct GNUNET_TIME_Absolute ts; 2292 struct GNUNET_TIME_Absolute ts;
2292 2293
2293 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2294 "Received CONNECT message from peer `%s' with `%s' %p\n",
2295 GNUNET_i2s (peer), GST_plugins_a2s (address), session);
2296 if (ntohs (message->size) != sizeof (struct SessionConnectMessage)) 2294 if (ntohs (message->size) != sizeof (struct SessionConnectMessage))
2297 { 2295 {
2298 GNUNET_break_op (0); 2296 GNUNET_break_op (0);
@@ -2345,10 +2343,12 @@ GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
2345 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); 2343 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
2346 break; 2344 break;
2347 case GNUNET_TRANSPORT_PS_CONNECT_RECV_ATS: 2345 case GNUNET_TRANSPORT_PS_CONNECT_RECV_ATS:
2346 /* We already wait for an address to send an CONNECT_ACK */
2348 break; 2347 break;
2349 case GNUNET_TRANSPORT_PS_CONNECT_SENT: 2348 case GNUNET_TRANSPORT_PS_CONNECT_SENT:
2350 case GNUNET_TRANSPORT_PS_CONNECT_RECV_ACK: 2349 case GNUNET_TRANSPORT_PS_CONNECT_RECV_ACK:
2351 /* Send ACK immediately */ 2350 /* Send ACK immediately */
2351 n->ack_state = ACK_SEND_SESSION_ACK;
2352 send_connect_ack_message (n->primary_address.address, 2352 send_connect_ack_message (n->primary_address.address,
2353 n->primary_address.session, ts); 2353 n->primary_address.session, ts);
2354 break; 2354 break;
@@ -2356,7 +2356,7 @@ GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
2356 /* we are already connected and can thus send the ACK immediately */ 2356 /* we are already connected and can thus send the ACK immediately */
2357 GNUNET_assert (NULL != n->primary_address.address); 2357 GNUNET_assert (NULL != n->primary_address.address);
2358 GNUNET_assert (NULL != n->primary_address.session); 2358 GNUNET_assert (NULL != n->primary_address.session);
2359 n->ack_state = ACK_UNDEFINED; 2359 n->ack_state = ACK_SEND_SESSION_ACK;
2360 send_connect_ack_message (n->primary_address.address, 2360 send_connect_ack_message (n->primary_address.address,
2361 n->primary_address.session, ts); 2361 n->primary_address.session, ts);
2362 break; 2362 break;
@@ -2364,30 +2364,27 @@ GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
2364 /* We wait for ATS address suggestion */ 2364 /* We wait for ATS address suggestion */
2365 break; 2365 break;
2366 case GNUNET_TRANSPORT_PS_RECONNECT_SENT: 2366 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
2367 /* It can never hurt to have an alternative address in the above cases, 2367 /* We received a CONNECT message while waiting for a CONNECT_ACK in fast
2368 see if it is allowed */ 2368 * reconnect. Send CONNECT_ACK immediately */
2369 if (ACK_SEND_CONNECT_ACK == n->ack_state) 2369 n->ack_state = ACK_SEND_SESSION_ACK;
2370 { 2370 send_connect_ack_message (n->primary_address.address,
2371 n->ack_state = ACK_SEND_SESSION_ACK; 2371 n->primary_address.session, n->connect_ack_timestamp);
2372 send_connect_ack_message (n->primary_address.address,
2373 n->primary_address.session, n->connect_ack_timestamp);
2374 }
2375 break; 2372 break;
2376 case GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_CONNECT_SENT: 2373 case GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_CONNECT_SENT:
2377 /* we are already connected and can thus send the ACK immediately; 2374 /* We are already connected and can thus send the ACK immediately;
2378 still, it can never hurt to have an alternative address, so also 2375 still, it can never hurt to have an alternative address, so also
2379 tell ATS about it */ 2376 tell ATS about it */
2380 GNUNET_assert (NULL != n->primary_address.address); 2377 GNUNET_assert (NULL != n->primary_address.address);
2381 GNUNET_assert (NULL != n->primary_address.session); 2378 GNUNET_assert (NULL != n->primary_address.session);
2382 n->ack_state = ACK_UNDEFINED; 2379 n->ack_state = ACK_SEND_SESSION_ACK;
2383 send_connect_ack_message (n->primary_address.address, 2380 send_connect_ack_message (n->primary_address.address,
2384 n->primary_address.session, ts); 2381 n->primary_address.session, ts);
2385 break; 2382 break;
2386 case GNUNET_TRANSPORT_PS_DISCONNECT: 2383 case GNUNET_TRANSPORT_PS_DISCONNECT:
2387 /* get rid of remains without terminating sessions, ready to re-try */ 2384 /* Get rid of remains without terminating sessions, ready to re-try */
2388 free_neighbour (n, GNUNET_YES); 2385 free_neighbour (n, GNUNET_YES);
2389 n = setup_neighbour (peer); 2386 n = setup_neighbour (peer);
2390 /* Remember the CONNECT timestamp for ACK message */ 2387 /* Remember the CONNECT time stamp for ACK message */
2391 n->ack_state = ACK_SEND_CONNECT_ACK; 2388 n->ack_state = ACK_SEND_CONNECT_ACK;
2392 n->connect_ack_timestamp = ts; 2389 n->connect_ack_timestamp = ts;
2393 /* Request an address for the peer */ 2390 /* Request an address for the peer */
@@ -2503,21 +2500,30 @@ switch_address_bl_check_cont (void *cls,
2503 * set primary address and send CONNECT message*/ 2500 * set primary address and send CONNECT message*/
2504 set_primary_address (n, blc_ctx->address, blc_ctx->session, 2501 set_primary_address (n, blc_ctx->address, blc_ctx->session,
2505 blc_ctx->bandwidth_in, blc_ctx->bandwidth_out, GNUNET_NO); 2502 blc_ctx->bandwidth_in, blc_ctx->bandwidth_out, GNUNET_NO);
2503 if ( (ACK_SEND_CONNECT_ACK == n->ack_state) )
2504 {
2505 /* Send pending CONNECT_ACK message */
2506 n->ack_state = ACK_SEND_SESSION_ACK;
2507 send_connect_ack_message (n->primary_address.address,
2508 n->primary_address.session, n->connect_ack_timestamp);
2509 }
2506 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_CONNECT_SENT, 2510 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_CONNECT_SENT,
2507 GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT)); 2511 GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT));
2508 send_session_connect (&n->primary_address); 2512 send_session_connect (&n->primary_address);
2509 break; 2513 break;
2510 case GNUNET_TRANSPORT_PS_CONNECT_SENT: 2514 case GNUNET_TRANSPORT_PS_CONNECT_SENT:
2511 /* waiting on CONNECT_ACK, send ACK if one is pending */ 2515 /* ATS suggested a new address while waiting for an CONNECT_ACK:
2516 * Switch and send new CONNECT */
2517 /* ATS suggests a different address, switch again */
2518 set_primary_address (n, blc_ctx->address, blc_ctx->session,
2519 blc_ctx->bandwidth_in, blc_ctx->bandwidth_out, GNUNET_NO);
2512 if (ACK_SEND_CONNECT_ACK == n->ack_state) 2520 if (ACK_SEND_CONNECT_ACK == n->ack_state)
2513 { 2521 {
2522 /* Send pending CONNECT_ACK message */
2514 n->ack_state = ACK_SEND_SESSION_ACK; 2523 n->ack_state = ACK_SEND_SESSION_ACK;
2515 send_connect_ack_message (n->primary_address.address, 2524 send_connect_ack_message (n->primary_address.address,
2516 n->primary_address.session, n->connect_ack_timestamp); 2525 n->primary_address.session, n->connect_ack_timestamp);
2517 } 2526 }
2518 /* ATS suggests a different address, switch again */
2519 set_primary_address (n, blc_ctx->address, blc_ctx->session,
2520 blc_ctx->bandwidth_in, blc_ctx->bandwidth_out, GNUNET_NO);
2521 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_CONNECT_SENT, 2527 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_CONNECT_SENT,
2522 GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT)); 2528 GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT));
2523 send_session_connect (&n->primary_address); 2529 send_session_connect (&n->primary_address);
@@ -2533,22 +2539,23 @@ switch_address_bl_check_cont (void *cls,
2533 send_connect_ack_message (n->primary_address.address, 2539 send_connect_ack_message (n->primary_address.address,
2534 n->primary_address.session, 2540 n->primary_address.session,
2535 n->connect_ack_timestamp); 2541 n->connect_ack_timestamp);
2536 if (ACK_SEND_CONNECT_ACK == n->ack_state) 2542 if ( (ACK_SEND_CONNECT_ACK == n->ack_state) ||
2543 (ACK_UNDEFINED == n->ack_state) )
2537 n->ack_state = ACK_SEND_SESSION_ACK; 2544 n->ack_state = ACK_SEND_SESSION_ACK;
2538 break; 2545 break;
2539 case GNUNET_TRANSPORT_PS_CONNECT_RECV_ACK: 2546 case GNUNET_TRANSPORT_PS_CONNECT_RECV_ACK:
2540 /* ATS asks us to switch while we were trying to connect; switch to new 2547 /* ATS asks us to switch while we were trying to connect; switch to new
2541 address and check blacklist again */ 2548 address and check blacklist again */
2542 set_primary_address (n, blc_ctx->address, blc_ctx->session,
2543 blc_ctx->bandwidth_in, blc_ctx->bandwidth_out, GNUNET_NO);
2544 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_CONNECT_RECV_ACK,
2545 GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT));
2546 if ( (ACK_SEND_CONNECT_ACK == n->ack_state) ) 2549 if ( (ACK_SEND_CONNECT_ACK == n->ack_state) )
2547 { 2550 {
2548 n->ack_state = ACK_SEND_SESSION_ACK; 2551 n->ack_state = ACK_SEND_SESSION_ACK;
2549 send_connect_ack_message (n->primary_address.address, 2552 send_connect_ack_message (n->primary_address.address,
2550 n->primary_address.session, n->connect_ack_timestamp); 2553 n->primary_address.session, n->connect_ack_timestamp);
2551 } 2554 }
2555 set_primary_address (n, blc_ctx->address, blc_ctx->session,
2556 blc_ctx->bandwidth_in, blc_ctx->bandwidth_out, GNUNET_NO);
2557 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_CONNECT_RECV_ACK,
2558 GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT));
2552 break; 2559 break;
2553 case GNUNET_TRANSPORT_PS_CONNECTED: 2560 case GNUNET_TRANSPORT_PS_CONNECTED:
2554 GNUNET_assert (NULL != n->primary_address.address); 2561 GNUNET_assert (NULL != n->primary_address.address);
@@ -2571,6 +2578,13 @@ switch_address_bl_check_cont (void *cls,
2571 case GNUNET_TRANSPORT_PS_RECONNECT_ATS: 2578 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
2572 set_primary_address (n, blc_ctx->address, blc_ctx->session, 2579 set_primary_address (n, blc_ctx->address, blc_ctx->session,
2573 blc_ctx->bandwidth_in, blc_ctx->bandwidth_out, GNUNET_NO); 2580 blc_ctx->bandwidth_in, blc_ctx->bandwidth_out, GNUNET_NO);
2581 if ( (ACK_SEND_CONNECT_ACK == n->ack_state) )
2582 {
2583 /* Send pending CONNECT_ACK message */
2584 n->ack_state = ACK_SEND_SESSION_ACK;
2585 send_connect_ack_message (n->primary_address.address,
2586 n->primary_address.session, n->connect_ack_timestamp);
2587 }
2574 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_RECONNECT_SENT, 2588 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_RECONNECT_SENT,
2575 GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT)); 2589 GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT));
2576 send_session_connect (&n->primary_address); 2590 send_session_connect (&n->primary_address);
@@ -3146,7 +3160,7 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
3146 1, GNUNET_NO); 3160 1, GNUNET_NO);
3147 break; 3161 break;
3148 case GNUNET_TRANSPORT_PS_RECONNECT_SENT: 3162 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
3149 /* new address worked; go back to connected! */ 3163 /* Reconnecting with new address address worked; go back to connected! */
3150 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_CONNECTED, 3164 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_CONNECTED,
3151 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); 3165 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
3152 send_session_ack_message (n); 3166 send_session_ack_message (n);