aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_neighbours.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/gnunet-service-transport_neighbours.c')
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c145
1 files changed, 76 insertions, 69 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index 404dadb80..7c596fbae 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -2142,16 +2142,6 @@ struct BlacklistCheckSwitchContext
2142 struct GST_BlacklistCheck *blc; 2142 struct GST_BlacklistCheck *blc;
2143 2143
2144 /** 2144 /**
2145 * Address we are asking the blacklist subsystem about.
2146 */
2147 struct GNUNET_HELLO_Address *address;
2148
2149 /**
2150 * Session we should use in conjunction with @e address, can be NULL.
2151 */
2152 struct Session *session;
2153
2154 /**
2155 * Inbound bandwidth that was assigned to @e address. 2145 * Inbound bandwidth that was assigned to @e address.
2156 */ 2146 */
2157 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; 2147 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
@@ -2169,11 +2159,17 @@ struct BlacklistCheckSwitchContext
2169 * 2159 *
2170 * @param cls blc_ctx bl context 2160 * @param cls blc_ctx bl context
2171 * @param peer the peer 2161 * @param peer the peer
2172 * @param result the result 2162 * @param address address associated with the request
2163 * @param session session associated with the request
2164 * @param result #GNUNET_OK if the connection is allowed,
2165 * #GNUNET_NO if not,
2166 * #GNUNET_SYSERR if operation was aborted
2173 */ 2167 */
2174static void 2168static void
2175try_connect_bl_check_cont (void *cls, 2169try_connect_bl_check_cont (void *cls,
2176 const struct GNUNET_PeerIdentity *peer, 2170 const struct GNUNET_PeerIdentity *peer,
2171 const struct GNUNET_HELLO_Address *address,
2172 struct Session *session,
2177 int result) 2173 int result)
2178{ 2174{
2179 struct BlacklistCheckSwitchContext *blc_ctx = cls; 2175 struct BlacklistCheckSwitchContext *blc_ctx = cls;
@@ -2281,7 +2277,9 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target)
2281 (blc = GST_blacklist_test_allowed (target, 2277 (blc = GST_blacklist_test_allowed (target,
2282 NULL, 2278 NULL,
2283 &try_connect_bl_check_cont, 2279 &try_connect_bl_check_cont,
2284 blc_ctx))) 2280 blc_ctx,
2281 NULL,
2282 NULL)))
2285 { 2283 {
2286 blc_ctx->blc = blc; 2284 blc_ctx->blc = blc;
2287 } 2285 }
@@ -2475,54 +2473,66 @@ try_run_fast_ats_update (const struct GNUNET_HELLO_Address *address,
2475 * @param cls the `struct BlacklistCheckSwitchContext` with 2473 * @param cls the `struct BlacklistCheckSwitchContext` with
2476 * the information about the future address 2474 * the information about the future address
2477 * @param peer the peer we may switch addresses on 2475 * @param peer the peer we may switch addresses on
2478 * @param result #GNUNET_NO if we are not allowed to use the new 2476 * @param address address associated with the request
2479 * address 2477 * @param session session associated with the request
2478 * @param result #GNUNET_OK if the connection is allowed,
2479 * #GNUNET_NO if not,
2480 * #GNUNET_SYSERR if operation was aborted
2480 */ 2481 */
2481static void 2482static void
2482switch_address_bl_check_cont (void *cls, 2483switch_address_bl_check_cont (void *cls,
2483 const struct GNUNET_PeerIdentity *peer, 2484 const struct GNUNET_PeerIdentity *peer,
2485 const struct GNUNET_HELLO_Address *address,
2486 struct Session *session,
2484 int result) 2487 int result)
2485{ 2488{
2486 struct BlacklistCheckSwitchContext *blc_ctx = cls; 2489 struct BlacklistCheckSwitchContext *blc_ctx = cls;
2487 struct GNUNET_TRANSPORT_PluginFunctions *papi; 2490 struct GNUNET_TRANSPORT_PluginFunctions *papi;
2488 struct NeighbourMapEntry *n; 2491 struct NeighbourMapEntry *n;
2489 2492
2490 if (result == GNUNET_NO) 2493 if (GNUNET_SYSERR == result)
2494 goto cleanup;
2495
2496 papi = GST_plugins_find (address->transport_name);
2497 GNUNET_assert (NULL != papi);
2498
2499 if (GNUNET_NO == result)
2491 { 2500 {
2492 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2501 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2493 "Blacklist denied to switch to suggested address `%s' session %p for peer `%s'\n", 2502 "Blacklist denied to switch to suggested address `%s' session %p for peer `%s'\n",
2494 GST_plugins_a2s (blc_ctx->address), 2503 GST_plugins_a2s (address),
2495 blc_ctx->session, 2504 session,
2496 GNUNET_i2s (&blc_ctx->address->peer)); 2505 GNUNET_i2s (peer));
2497 GNUNET_STATISTICS_update (GST_stats, 2506 GNUNET_STATISTICS_update (GST_stats,
2498 "# ATS suggestions ignored (blacklist denied)", 2507 "# ATS suggestions ignored (blacklist denied)",
2499 1, 2508 1,
2500 GNUNET_NO); 2509 GNUNET_NO);
2501 /* FIXME: tell plugin to force killing session here and now 2510 papi->disconnect_session (papi->cls,
2502 (note: _proper_ plugin API for this does not yet exist) */ 2511 session);
2503 GST_ats_block_address (blc_ctx->address, 2512 if (GNUNET_YES !=
2504 blc_ctx->session); 2513 GNUNET_HELLO_address_check_option (address,
2514 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
2515 GST_ats_block_address (address,
2516 NULL);
2505 goto cleanup; 2517 goto cleanup;
2506 } 2518 }
2507 2519
2508 papi = GST_plugins_find (blc_ctx->address->transport_name);
2509 GNUNET_assert (NULL != papi);
2510 2520
2511 if (NULL == blc_ctx->session) 2521 if (NULL == session)
2512 { 2522 {
2513 /* need to create a session, ATS only gave us an address */ 2523 /* need to create a session, ATS only gave us an address */
2514 blc_ctx->session = papi->get_session (papi->cls, 2524 session = papi->get_session (papi->cls,
2515 blc_ctx->address); 2525 address);
2516 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2526 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2517 "Obtained new session for peer `%s' and address '%s': %p\n", 2527 "Obtained new session for peer `%s' and address '%s': %p\n",
2518 GNUNET_i2s (&blc_ctx->address->peer), 2528 GNUNET_i2s (&address->peer),
2519 GST_plugins_a2s (blc_ctx->address), 2529 GST_plugins_a2s (address),
2520 blc_ctx->session); 2530 session);
2521 if (NULL != blc_ctx->session) 2531 if (NULL != session)
2522 GST_ats_new_session (blc_ctx->address, 2532 GST_ats_new_session (address,
2523 blc_ctx->session); 2533 session);
2524 } 2534 }
2525 if (NULL == blc_ctx->session) 2535 if (NULL == session)
2526 { 2536 {
2527 /* session creation failed, bad!, fail! */ 2537 /* session creation failed, bad!, fail! */
2528 GNUNET_STATISTICS_update (GST_stats, 2538 GNUNET_STATISTICS_update (GST_stats,
@@ -2532,10 +2542,10 @@ switch_address_bl_check_cont (void *cls,
2532 /* No session could be obtained, remove blacklist check and clean up */ 2542 /* No session could be obtained, remove blacklist check and clean up */
2533 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2543 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2534 "Failed to obtain new session for peer `%s' and address '%s'\n", 2544 "Failed to obtain new session for peer `%s' and address '%s'\n",
2535 GNUNET_i2s (&blc_ctx->address->peer), 2545 GNUNET_i2s (&address->peer),
2536 GST_plugins_a2s (blc_ctx->address)); 2546 GST_plugins_a2s (address));
2537 GST_ats_block_address (blc_ctx->address, 2547 GST_ats_block_address (address,
2538 blc_ctx->session); 2548 session);
2539 goto cleanup; 2549 goto cleanup;
2540 } 2550 }
2541 2551
@@ -2543,8 +2553,8 @@ switch_address_bl_check_cont (void *cls,
2543 it is theoretically possible that the situation changed in 2553 it is theoretically possible that the situation changed in
2544 the meantime, hence we check again here */ 2554 the meantime, hence we check again here */
2545 if (GNUNET_OK == 2555 if (GNUNET_OK ==
2546 try_run_fast_ats_update (blc_ctx->address, 2556 try_run_fast_ats_update (address,
2547 blc_ctx->session, 2557 session,
2548 blc_ctx->bandwidth_in, 2558 blc_ctx->bandwidth_in,
2549 blc_ctx->bandwidth_out)) 2559 blc_ctx->bandwidth_out))
2550 goto cleanup; /* was just a minor update, we're done */ 2560 goto cleanup; /* was just a minor update, we're done */
@@ -2558,23 +2568,23 @@ switch_address_bl_check_cont (void *cls,
2558 2568
2559 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 2569 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2560 "Peer `%s' switches to address `%s'\n", 2570 "Peer `%s' switches to address `%s'\n",
2561 GNUNET_i2s (&blc_ctx->address->peer), 2571 GNUNET_i2s (&address->peer),
2562 GST_plugins_a2s (blc_ctx->address)); 2572 GST_plugins_a2s (address));
2563 2573
2564 switch (n->state) 2574 switch (n->state)
2565 { 2575 {
2566 case GNUNET_TRANSPORT_PS_NOT_CONNECTED: 2576 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
2567 GNUNET_break (0); 2577 GNUNET_break (0);
2568 GST_ats_block_address (blc_ctx->address, 2578 GST_ats_block_address (address,
2569 blc_ctx->session); 2579 session);
2570 free_neighbour (n); 2580 free_neighbour (n);
2571 return; 2581 return;
2572 case GNUNET_TRANSPORT_PS_INIT_ATS: 2582 case GNUNET_TRANSPORT_PS_INIT_ATS:
2573 /* We requested an address and ATS suggests one: 2583 /* We requested an address and ATS suggests one:
2574 * set primary address and send SYN message*/ 2584 * set primary address and send SYN message*/
2575 set_primary_address (n, 2585 set_primary_address (n,
2576 blc_ctx->address, 2586 address,
2577 blc_ctx->session, 2587 session,
2578 blc_ctx->bandwidth_in, 2588 blc_ctx->bandwidth_in,
2579 blc_ctx->bandwidth_out); 2589 blc_ctx->bandwidth_out);
2580 if (ACK_SEND_SYN_ACK == n->ack_state) 2590 if (ACK_SEND_SYN_ACK == n->ack_state)
@@ -2594,8 +2604,8 @@ switch_address_bl_check_cont (void *cls,
2594 * Switch and send new SYN */ 2604 * Switch and send new SYN */
2595 /* ATS suggests a different address, switch again */ 2605 /* ATS suggests a different address, switch again */
2596 set_primary_address (n, 2606 set_primary_address (n,
2597 blc_ctx->address, 2607 address,
2598 blc_ctx->session, 2608 session,
2599 blc_ctx->bandwidth_in, 2609 blc_ctx->bandwidth_in,
2600 blc_ctx->bandwidth_out); 2610 blc_ctx->bandwidth_out);
2601 if (ACK_SEND_SYN_ACK == n->ack_state) 2611 if (ACK_SEND_SYN_ACK == n->ack_state)
@@ -2614,8 +2624,8 @@ switch_address_bl_check_cont (void *cls,
2614 /* We requested an address and ATS suggests one: 2624 /* We requested an address and ATS suggests one:
2615 * set primary address and send SYN_ACK message*/ 2625 * set primary address and send SYN_ACK message*/
2616 set_primary_address (n, 2626 set_primary_address (n,
2617 blc_ctx->address, 2627 address,
2618 blc_ctx->session, 2628 session,
2619 blc_ctx->bandwidth_in, 2629 blc_ctx->bandwidth_in,
2620 blc_ctx->bandwidth_out); 2630 blc_ctx->bandwidth_out);
2621 /* Send an ACK message as a response to the SYN msg */ 2631 /* Send an ACK message as a response to the SYN msg */
@@ -2638,8 +2648,8 @@ switch_address_bl_check_cont (void *cls,
2638 n->connect_ack_timestamp); 2648 n->connect_ack_timestamp);
2639 } 2649 }
2640 set_primary_address (n, 2650 set_primary_address (n,
2641 blc_ctx->address, 2651 address,
2642 blc_ctx->session, 2652 session,
2643 blc_ctx->bandwidth_in, 2653 blc_ctx->bandwidth_in,
2644 blc_ctx->bandwidth_out); 2654 blc_ctx->bandwidth_out);
2645 set_state_and_timeout (n, 2655 set_state_and_timeout (n,
@@ -2649,12 +2659,12 @@ switch_address_bl_check_cont (void *cls,
2649 case GNUNET_TRANSPORT_PS_CONNECTED: 2659 case GNUNET_TRANSPORT_PS_CONNECTED:
2650 GNUNET_assert (NULL != n->primary_address.address); 2660 GNUNET_assert (NULL != n->primary_address.address);
2651 GNUNET_assert (NULL != n->primary_address.session); 2661 GNUNET_assert (NULL != n->primary_address.session);
2652 GNUNET_break (n->primary_address.session != blc_ctx->session); 2662 GNUNET_break (n->primary_address.session != session);
2653 /* ATS asks us to switch a life connection; see if we can get 2663 /* ATS asks us to switch a life connection; see if we can get
2654 a SYN_ACK on it before we actually do this! */ 2664 a SYN_ACK on it before we actually do this! */
2655 set_alternative_address (n, 2665 set_alternative_address (n,
2656 blc_ctx->address, 2666 address,
2657 blc_ctx->session, 2667 session,
2658 blc_ctx->bandwidth_in, 2668 blc_ctx->bandwidth_in,
2659 blc_ctx->bandwidth_out); 2669 blc_ctx->bandwidth_out);
2660 set_state_and_timeout (n, 2670 set_state_and_timeout (n,
@@ -2668,8 +2678,8 @@ switch_address_bl_check_cont (void *cls,
2668 break; 2678 break;
2669 case GNUNET_TRANSPORT_PS_RECONNECT_ATS: 2679 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
2670 set_primary_address (n, 2680 set_primary_address (n,
2671 blc_ctx->address, 2681 address,
2672 blc_ctx->session, 2682 session,
2673 blc_ctx->bandwidth_in, 2683 blc_ctx->bandwidth_in,
2674 blc_ctx->bandwidth_out); 2684 blc_ctx->bandwidth_out);
2675 if (ACK_SEND_SYN_ACK == n->ack_state) 2685 if (ACK_SEND_SYN_ACK == n->ack_state)
@@ -2688,8 +2698,8 @@ switch_address_bl_check_cont (void *cls,
2688 /* ATS asks us to switch while we were trying to reconnect; switch to new 2698 /* ATS asks us to switch while we were trying to reconnect; switch to new
2689 address and send SYN again */ 2699 address and send SYN again */
2690 set_primary_address (n, 2700 set_primary_address (n,
2691 blc_ctx->address, 2701 address,
2692 blc_ctx->session, 2702 session,
2693 blc_ctx->bandwidth_in, 2703 blc_ctx->bandwidth_in,
2694 blc_ctx->bandwidth_out); 2704 blc_ctx->bandwidth_out);
2695 set_state_and_timeout (n, 2705 set_state_and_timeout (n,
@@ -2699,8 +2709,8 @@ switch_address_bl_check_cont (void *cls,
2699 break; 2709 break;
2700 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: 2710 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
2701 if ( (0 == GNUNET_HELLO_address_cmp (n->primary_address.address, 2711 if ( (0 == GNUNET_HELLO_address_cmp (n->primary_address.address,
2702 blc_ctx->address)) && 2712 address)) &&
2703 (n->primary_address.session == blc_ctx->session) ) 2713 (n->primary_address.session == session) )
2704 { 2714 {
2705 /* ATS switches back to still-active session */ 2715 /* ATS switches back to still-active session */
2706 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2716 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -2713,8 +2723,8 @@ switch_address_bl_check_cont (void *cls,
2713 } 2723 }
2714 /* ATS asks us to switch a life connection, send */ 2724 /* ATS asks us to switch a life connection, send */
2715 set_alternative_address (n, 2725 set_alternative_address (n,
2716 blc_ctx->address, 2726 address,
2717 blc_ctx->session, 2727 session,
2718 blc_ctx->bandwidth_in, 2728 blc_ctx->bandwidth_in,
2719 blc_ctx->bandwidth_out); 2729 blc_ctx->bandwidth_out);
2720 set_state_and_timeout (n, 2730 set_state_and_timeout (n,
@@ -2743,7 +2753,6 @@ switch_address_bl_check_cont (void *cls,
2743 GNUNET_CONTAINER_DLL_remove (pending_bc_head, 2753 GNUNET_CONTAINER_DLL_remove (pending_bc_head,
2744 pending_bc_tail, 2754 pending_bc_tail,
2745 blc_ctx); 2755 blc_ctx);
2746 GNUNET_HELLO_address_free (blc_ctx->address);
2747 GNUNET_free (blc_ctx); 2756 GNUNET_free (blc_ctx);
2748} 2757}
2749 2758
@@ -2811,8 +2820,6 @@ GST_neighbours_switch_to_address (const struct GNUNET_HELLO_Address *address,
2811 2820
2812 /* Perform blacklist check */ 2821 /* Perform blacklist check */
2813 blc_ctx = GNUNET_new (struct BlacklistCheckSwitchContext); 2822 blc_ctx = GNUNET_new (struct BlacklistCheckSwitchContext);
2814 blc_ctx->address = GNUNET_HELLO_address_copy (address);
2815 blc_ctx->session = session;
2816 blc_ctx->bandwidth_in = bandwidth_in; 2823 blc_ctx->bandwidth_in = bandwidth_in;
2817 blc_ctx->bandwidth_out = bandwidth_out; 2824 blc_ctx->bandwidth_out = bandwidth_out;
2818 GNUNET_CONTAINER_DLL_insert (pending_bc_head, 2825 GNUNET_CONTAINER_DLL_insert (pending_bc_head,
@@ -2821,7 +2828,9 @@ GST_neighbours_switch_to_address (const struct GNUNET_HELLO_Address *address,
2821 if (NULL != (blc = GST_blacklist_test_allowed (&address->peer, 2828 if (NULL != (blc = GST_blacklist_test_allowed (&address->peer,
2822 address->transport_name, 2829 address->transport_name,
2823 &switch_address_bl_check_cont, 2830 &switch_address_bl_check_cont,
2824 blc_ctx))) 2831 blc_ctx,
2832 address,
2833 session)))
2825 { 2834 {
2826 blc_ctx->blc = blc; 2835 blc_ctx->blc = blc;
2827 } 2836 }
@@ -3835,8 +3844,6 @@ GST_neighbours_stop ()
3835 GST_blacklist_test_cancel (cur->blc); 3844 GST_blacklist_test_cancel (cur->blc);
3836 cur->blc = NULL; 3845 cur->blc = NULL;
3837 } 3846 }
3838 if (NULL != cur->address)
3839 GNUNET_HELLO_address_free (cur->address);
3840 GNUNET_free (cur); 3847 GNUNET_free (cur);
3841 } 3848 }
3842} 3849}