aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-05-25 08:25:18 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-05-25 08:25:18 +0000
commit1e46552077655aeb2f54e59cad77edcdffe3f1ce (patch)
treed63783ed000654c92d0ba9829923843c15e47c33 /src/transport
parent9f0a09cc13f4738303cd38e1b44b4f64df66e133 (diff)
downloadgnunet-1e46552077655aeb2f54e59cad77edcdffe3f1ce.tar.gz
gnunet-1e46552077655aeb2f54e59cad77edcdffe3f1ce.zip
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c105
1 files changed, 26 insertions, 79 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index 6f1c4efa5..8dd3190f7 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -842,69 +842,15 @@ set_address (struct NeighbourAddress *na,
842 } 842 }
843} 843}
844 844
845/**
846 * Free a neighbour map entry.
847 *
848 * @param n entry to free
849 */
850static void
851free_neighbour_without_terminating_sessions (struct NeighbourMapEntry *n)
852{
853 struct MessageQueue *mq;
854 n->is_active = NULL; /* always free'd by its own continuation! */
855
856 /* fail messages currently in the queue */
857 while (NULL != (mq = n->messages_head))
858 {
859 GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq);
860 if (NULL != mq->cont)
861 mq->cont (mq->cont_cls, GNUNET_SYSERR);
862 GNUNET_free (mq);
863 }
864 /* It is too late to send other peer disconnect notifications, but at
865 least internally we need to get clean... */
866 if (GNUNET_YES == test_connected (n))
867 {
868 GNUNET_STATISTICS_set (GST_stats,
869 gettext_noop ("# peers connected"),
870 --neighbours_connected,
871 GNUNET_NO);
872 disconnect_notify_cb (callback_cls, &n->id);
873 }
874
875 n->state = S_DISCONNECT_FINISHED;
876
877 GNUNET_assert (GNUNET_YES ==
878 GNUNET_CONTAINER_multihashmap_remove (neighbours,
879 &n->id.hashPubKey, n));
880
881 /* cut transport-level connection */
882 free_address (&n->primary_address);
883 free_address (&n->alternative_address);
884
885 // FIXME-ATS-API: we might want to be more specific about
886 // which states we do this from in the future (ATS should
887 // have given us a 'suggest_address' handle, and if we have
888 // such a handle, we should cancel the operation here!
889 GNUNET_ATS_suggest_address_cancel (GST_ats, &n->id);
890
891 if (GNUNET_SCHEDULER_NO_TASK != n->task)
892 {
893 GNUNET_SCHEDULER_cancel (n->task);
894 n->task = GNUNET_SCHEDULER_NO_TASK;
895 }
896 /* free rest of memory */
897 GNUNET_free (n);
898}
899
900 845
901/** 846/**
902 * Free a neighbour map entry. 847 * Free a neighbour map entry.
903 * 848 *
904 * @param n entry to free 849 * @param n entry to free
850 * @param terminate tell plugin to terminate sessions
905 */ 851 */
906static void 852static void
907free_neighbour (struct NeighbourMapEntry *n) 853free_neighbour (struct NeighbourMapEntry *n, int terminate)
908{ 854{
909 struct MessageQueue *mq; 855 struct MessageQueue *mq;
910 struct GNUNET_TRANSPORT_PluginFunctions *papi; 856 struct GNUNET_TRANSPORT_PluginFunctions *papi;
@@ -939,8 +885,9 @@ free_neighbour (struct NeighbourMapEntry *n)
939 API gives us not even the means to selectively kill only one of 885 API gives us not even the means to selectively kill only one of
940 them! Killing all sessions like this seems to be very, very 886 them! Killing all sessions like this seems to be very, very
941 wrong. */ 887 wrong. */
942 if ( (NULL != n->primary_address.address) && 888 if ((GNUNET_YES == terminate) &&
943 (NULL != (papi = GST_plugins_find (n->primary_address.address->transport_name))) ) 889 (NULL != n->primary_address.address) &&
890 (NULL != (papi = GST_plugins_find (n->primary_address.address->transport_name))))
944 papi->disconnect (papi->cls, &n->id); 891 papi->disconnect (papi->cls, &n->id);
945 892
946 n->state = S_DISCONNECT_FINISHED; 893 n->state = S_DISCONNECT_FINISHED;
@@ -1102,7 +1049,7 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
1102 case S_INIT_BLACKLIST: 1049 case S_INIT_BLACKLIST:
1103 /* other peer is completely unaware of us, no need to send DISCONNECT */ 1050 /* other peer is completely unaware of us, no need to send DISCONNECT */
1104 n->state = S_DISCONNECT_FINISHED; 1051 n->state = S_DISCONNECT_FINISHED;
1105 free_neighbour (n); 1052 free_neighbour (n, GNUNET_NO);
1106 return; 1053 return;
1107 case S_CONNECT_SENT: 1054 case S_CONNECT_SENT:
1108 send_disconnect (n); 1055 send_disconnect (n);
@@ -1112,7 +1059,7 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
1112 case S_CONNECT_RECV_BLACKLIST: 1059 case S_CONNECT_RECV_BLACKLIST:
1113 /* we never ACK'ed the other peer's request, no need to send DISCONNECT */ 1060 /* we never ACK'ed the other peer's request, no need to send DISCONNECT */
1114 n->state = S_DISCONNECT_FINISHED; 1061 n->state = S_DISCONNECT_FINISHED;
1115 free_neighbour (n); 1062 free_neighbour (n, GNUNET_NO);
1116 return; 1063 return;
1117 case S_CONNECT_RECV_ACK: 1064 case S_CONNECT_RECV_ACK:
1118 /* we DID ACK the other peer's request, must send DISCONNECT */ 1065 /* we DID ACK the other peer's request, must send DISCONNECT */
@@ -1714,7 +1661,7 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target)
1714 case S_NOT_CONNECTED: 1661 case S_NOT_CONNECTED:
1715 /* this should not be possible */ 1662 /* this should not be possible */
1716 GNUNET_break (0); 1663 GNUNET_break (0);
1717 free_neighbour (n); 1664 free_neighbour (n, GNUNET_NO);
1718 break; 1665 break;
1719 case S_INIT_ATS: 1666 case S_INIT_ATS:
1720 case S_INIT_BLACKLIST: 1667 case S_INIT_BLACKLIST:
@@ -1738,7 +1685,7 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target)
1738 return; /* already connected */ 1685 return; /* already connected */
1739 case S_DISCONNECT: 1686 case S_DISCONNECT:
1740 /* get rid of remains, ready to re-try immediately */ 1687 /* get rid of remains, ready to re-try immediately */
1741 free_neighbour (n); 1688 free_neighbour (n, GNUNET_NO);
1742 break; 1689 break;
1743 case S_DISCONNECT_FINISHED: 1690 case S_DISCONNECT_FINISHED:
1744 /* should not be possible */ 1691 /* should not be possible */
@@ -1746,7 +1693,7 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target)
1746 default: 1693 default:
1747 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unhandled state `%s' \n",print_state (n->state)); 1694 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unhandled state `%s' \n",print_state (n->state));
1748 GNUNET_break (0); 1695 GNUNET_break (0);
1749 free_neighbour (n); 1696 free_neighbour (n, GNUNET_NO);
1750 break; 1697 break;
1751 } 1698 }
1752 } 1699 }
@@ -1794,7 +1741,7 @@ handle_test_blacklist_cont (void *cls,
1794 case S_NOT_CONNECTED: 1741 case S_NOT_CONNECTED:
1795 /* this should not be possible */ 1742 /* this should not be possible */
1796 GNUNET_break (0); 1743 GNUNET_break (0);
1797 free_neighbour (n); 1744 free_neighbour (n, GNUNET_NO);
1798 break; 1745 break;
1799 case S_INIT_ATS: 1746 case S_INIT_ATS:
1800 /* still waiting on ATS suggestion */ 1747 /* still waiting on ATS suggestion */
@@ -1962,7 +1909,7 @@ handle_test_blacklist_cont (void *cls,
1962 default: 1909 default:
1963 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unhandled state `%s' \n",print_state (n->state)); 1910 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unhandled state `%s' \n",print_state (n->state));
1964 GNUNET_break (0); 1911 GNUNET_break (0);
1965 free_neighbour (n); 1912 free_neighbour (n, GNUNET_NO);
1966 break; 1913 break;
1967 } 1914 }
1968 cleanup: 1915 cleanup:
@@ -2111,7 +2058,7 @@ GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
2111 break; 2058 break;
2112 case S_DISCONNECT: 2059 case S_DISCONNECT:
2113 /* get rid of remains without terminating sessions, ready to re-try */ 2060 /* get rid of remains without terminating sessions, ready to re-try */
2114 free_neighbour_without_terminating_sessions (n); 2061 free_neighbour (n, GNUNET_YES);
2115 n = setup_neighbour (peer); 2062 n = setup_neighbour (peer);
2116 n->state = S_CONNECT_RECV_ATS; 2063 n->state = S_CONNECT_RECV_ATS;
2117 GNUNET_ATS_reset_backoff (GST_ats, peer); 2064 GNUNET_ATS_reset_backoff (GST_ats, peer);
@@ -2124,7 +2071,7 @@ GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
2124 default: 2071 default:
2125 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unhandled state `%s' \n",print_state (n->state)); 2072 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unhandled state `%s' \n",print_state (n->state));
2126 GNUNET_break (0); 2073 GNUNET_break (0);
2127 free_neighbour (n); 2074 free_neighbour (n, GNUNET_NO);
2128 break; 2075 break;
2129 } 2076 }
2130} 2077}
@@ -2193,7 +2140,7 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
2193 { 2140 {
2194 case S_NOT_CONNECTED: 2141 case S_NOT_CONNECTED:
2195 GNUNET_break (0); 2142 GNUNET_break (0);
2196 free_neighbour (n); 2143 free_neighbour (n, GNUNET_NO);
2197 return; 2144 return;
2198 case S_INIT_ATS: 2145 case S_INIT_ATS:
2199 set_address (&n->primary_address, 2146 set_address (&n->primary_address,
@@ -2360,7 +2307,7 @@ master_task (void *cls,
2360 /* invalid state for master task, clean up */ 2307 /* invalid state for master task, clean up */
2361 GNUNET_break (0); 2308 GNUNET_break (0);
2362 n->state = S_DISCONNECT_FINISHED; 2309 n->state = S_DISCONNECT_FINISHED;
2363 free_neighbour (n); 2310 free_neighbour (n, GNUNET_NO);
2364 return; 2311 return;
2365 case S_INIT_ATS: 2312 case S_INIT_ATS:
2366 if (0 == delay.rel_value) 2313 if (0 == delay.rel_value)
@@ -2369,7 +2316,7 @@ master_task (void *cls,
2369 "Connection to `%s' timed out waiting for ATS to provide address\n", 2316 "Connection to `%s' timed out waiting for ATS to provide address\n",
2370 GNUNET_i2s (&n->id)); 2317 GNUNET_i2s (&n->id));
2371 n->state = S_DISCONNECT_FINISHED; 2318 n->state = S_DISCONNECT_FINISHED;
2372 free_neighbour (n); 2319 free_neighbour (n, GNUNET_NO);
2373 return; 2320 return;
2374 } 2321 }
2375 break; 2322 break;
@@ -2380,7 +2327,7 @@ master_task (void *cls,
2380 "Connection to `%s' timed out waiting for BLACKLIST to approve address\n", 2327 "Connection to `%s' timed out waiting for BLACKLIST to approve address\n",
2381 GNUNET_i2s (&n->id)); 2328 GNUNET_i2s (&n->id));
2382 n->state = S_DISCONNECT_FINISHED; 2329 n->state = S_DISCONNECT_FINISHED;
2383 free_neighbour (n); 2330 free_neighbour (n, GNUNET_NO);
2384 return; 2331 return;
2385 } 2332 }
2386 break; 2333 break;
@@ -2401,7 +2348,7 @@ master_task (void *cls,
2401 "Connection to `%s' timed out waiting ATS to provide address to use for CONNECT_ACK\n", 2348 "Connection to `%s' timed out waiting ATS to provide address to use for CONNECT_ACK\n",
2402 GNUNET_i2s (&n->id)); 2349 GNUNET_i2s (&n->id));
2403 n->state = S_DISCONNECT_FINISHED; 2350 n->state = S_DISCONNECT_FINISHED;
2404 free_neighbour (n); 2351 free_neighbour (n, GNUNET_NO);
2405 return; 2352 return;
2406 } 2353 }
2407 break; 2354 break;
@@ -2412,7 +2359,7 @@ master_task (void *cls,
2412 "Connection to `%s' timed out waiting BLACKLIST to approve address to use for CONNECT_ACK\n", 2359 "Connection to `%s' timed out waiting BLACKLIST to approve address to use for CONNECT_ACK\n",
2413 GNUNET_i2s (&n->id)); 2360 GNUNET_i2s (&n->id));
2414 n->state = S_DISCONNECT_FINISHED; 2361 n->state = S_DISCONNECT_FINISHED;
2415 free_neighbour (n); 2362 free_neighbour (n, GNUNET_NO);
2416 return; 2363 return;
2417 } 2364 }
2418 break; 2365 break;
@@ -2497,7 +2444,7 @@ master_task (void *cls,
2497 "Cleaning up connection to `%s' after sending DISCONNECT\n", 2444 "Cleaning up connection to `%s' after sending DISCONNECT\n",
2498 GNUNET_i2s (&n->id)); 2445 GNUNET_i2s (&n->id));
2499 n->state = S_DISCONNECT_FINISHED; 2446 n->state = S_DISCONNECT_FINISHED;
2500 free_neighbour (n); 2447 free_neighbour (n, GNUNET_NO);
2501 return; 2448 return;
2502 case S_DISCONNECT_FINISHED: 2449 case S_DISCONNECT_FINISHED:
2503 /* how did we get here!? */ 2450 /* how did we get here!? */
@@ -2584,7 +2531,7 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
2584 { 2531 {
2585 case S_NOT_CONNECTED: 2532 case S_NOT_CONNECTED:
2586 GNUNET_break (0); 2533 GNUNET_break (0);
2587 free_neighbour (n); 2534 free_neighbour (n, GNUNET_NO);
2588 return; 2535 return;
2589 case S_INIT_ATS: 2536 case S_INIT_ATS:
2590 case S_INIT_BLACKLIST: 2537 case S_INIT_BLACKLIST:
@@ -2724,11 +2671,11 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
2724 { 2671 {
2725 case S_NOT_CONNECTED: 2672 case S_NOT_CONNECTED:
2726 GNUNET_break (0); 2673 GNUNET_break (0);
2727 free_neighbour (n); 2674 free_neighbour (n, GNUNET_NO);
2728 return; 2675 return;
2729 case S_INIT_ATS: 2676 case S_INIT_ATS:
2730 GNUNET_break (0); 2677 GNUNET_break (0);
2731 free_neighbour (n); 2678 free_neighbour (n, GNUNET_NO);
2732 return; 2679 return;
2733 case S_INIT_BLACKLIST: 2680 case S_INIT_BLACKLIST:
2734 case S_CONNECT_SENT: 2681 case S_CONNECT_SENT:
@@ -2743,7 +2690,7 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
2743 case S_CONNECT_RECV_ACK: 2690 case S_CONNECT_RECV_ACK:
2744 /* error on inbound session; free neighbour entirely */ 2691 /* error on inbound session; free neighbour entirely */
2745 free_address (&n->primary_address); 2692 free_address (&n->primary_address);
2746 free_neighbour (n); 2693 free_neighbour (n, GNUNET_NO);
2747 return; 2694 return;
2748 case S_CONNECTED: 2695 case S_CONNECTED:
2749 free_address (&n->primary_address); 2696 free_address (&n->primary_address);
@@ -3153,7 +3100,7 @@ disconnect_all_neighbours (void *cls, const GNUNET_HashCode * key, void *value)
3153 "Disconnecting peer `%4s', %s\n", 3100 "Disconnecting peer `%4s', %s\n",
3154 GNUNET_i2s (&n->id), "SHUTDOWN_TASK"); 3101 GNUNET_i2s (&n->id), "SHUTDOWN_TASK");
3155 n->state = S_DISCONNECT_FINISHED; 3102 n->state = S_DISCONNECT_FINISHED;
3156 free_neighbour (n); 3103 free_neighbour (n, GNUNET_NO);
3157 return GNUNET_OK; 3104 return GNUNET_OK;
3158} 3105}
3159 3106