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.c120
1 files changed, 22 insertions, 98 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index d451991f1..7d7d1f7e3 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -514,55 +514,6 @@ lookup_neighbour (const struct GNUNET_PeerIdentity *pid)
514 514
515 515
516/** 516/**
517 * Convert state to human-readable string.
518 *
519 * @param state the state value
520 * @return corresponding string
521 */
522static const char *
523print_state (enum GNUNET_TRANSPORT_PeerState state)
524{
525 switch (state)
526 {
527 case S_NOT_CONNECTED:
528 return "S_NOT_CONNECTED";
529 case S_INIT_ATS:
530 return "S_INIT_ATS";
531 case S_INIT_BLACKLIST:
532 return "S_INIT_BLACKLIST";
533 case S_CONNECT_SENT:
534 return "S_CONNECT_SENT";
535 case S_CONNECT_RECV_BLACKLIST_INBOUND:
536 return "S_CONNECT_RECV_BLACKLIST_INBOUND";
537 case S_CONNECT_RECV_ATS:
538 return "S_CONNECT_RECV_ATS";
539 case S_CONNECT_RECV_BLACKLIST:
540 return "S_CONNECT_RECV_BLACKLIST";
541 case S_CONNECT_RECV_ACK:
542 return "S_CONNECT_RECV_ACK";
543 case S_CONNECTED:
544 return "S_CONNECTED";
545 case S_RECONNECT_ATS:
546 return "S_RECONNECT_ATS";
547 case S_RECONNECT_BLACKLIST:
548 return "S_RECONNECT_BLACKLIST";
549 case S_RECONNECT_SENT:
550 return "S_RECONNECT_SENT";
551 case S_CONNECTED_SWITCHING_BLACKLIST:
552 return "S_CONNECTED_SWITCHING_BLACKLIST";
553 case S_CONNECTED_SWITCHING_CONNECT_SENT:
554 return "S_CONNECTED_SWITCHING_CONNECT_SENT";
555 case S_DISCONNECT:
556 return "S_DISCONNECT";
557 case S_DISCONNECT_FINISHED:
558 return "S_DISCONNECT_FINISHED";
559 default:
560 GNUNET_break (0);
561 return "UNDEFINED";
562 }
563}
564
565/**
566 * Test if we're connected to the given peer. 517 * Test if we're connected to the given peer.
567 * 518 *
568 * @param n neighbour entry of peer to test 519 * @param n neighbour entry of peer to test
@@ -573,35 +524,7 @@ test_connected (struct NeighbourMapEntry *n)
573{ 524{
574 if (NULL == n) 525 if (NULL == n)
575 return GNUNET_NO; 526 return GNUNET_NO;
576 switch (n->state) 527 return GNUNET_TRANSPORT_is_connected (n->state);
577 {
578 case S_NOT_CONNECTED:
579 case S_INIT_ATS:
580 case S_INIT_BLACKLIST:
581 case S_CONNECT_SENT:
582 case S_CONNECT_RECV_BLACKLIST_INBOUND:
583 case S_CONNECT_RECV_ATS:
584 case S_CONNECT_RECV_BLACKLIST:
585 case S_CONNECT_RECV_ACK:
586 return GNUNET_NO;
587 case S_CONNECTED:
588 case S_RECONNECT_ATS:
589 case S_RECONNECT_BLACKLIST:
590 case S_RECONNECT_SENT:
591 case S_CONNECTED_SWITCHING_BLACKLIST:
592 case S_CONNECTED_SWITCHING_CONNECT_SENT:
593 return GNUNET_YES;
594 case S_DISCONNECT:
595 case S_DISCONNECT_FINISHED:
596 return GNUNET_NO;
597 default:
598 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
599 "Unhandled state `%s' \n",
600 print_state (n->state));
601 GNUNET_break (0);
602 break;
603 }
604 return GNUNET_SYSERR;
605} 528}
606 529
607/** 530/**
@@ -960,7 +883,7 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
960 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 883 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
961 "Disconnecting from peer %s in state %s\n", 884 "Disconnecting from peer %s in state %s\n",
962 GNUNET_i2s (&n->id), 885 GNUNET_i2s (&n->id),
963 print_state (n->state)); 886 GNUNET_TRANSPORT_p2s (n->state));
964 /* depending on state, notify neighbour and/or upper layers of this peer 887 /* depending on state, notify neighbour and/or upper layers of this peer
965 about disconnect */ 888 about disconnect */
966 switch (n->state) 889 switch (n->state)
@@ -1022,7 +945,7 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
1022 default: 945 default:
1023 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 946 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1024 "Unhandled state `%s'\n", 947 "Unhandled state `%s'\n",
1025 print_state (n->state)); 948 GNUNET_TRANSPORT_p2s (n->state));
1026 GNUNET_break (0); 949 GNUNET_break (0);
1027 break; 950 break;
1028 } 951 }
@@ -1693,7 +1616,7 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target)
1693 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1616 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1694 "Asked to connect to peer `%s' (state: %s)\n", 1617 "Asked to connect to peer `%s' (state: %s)\n",
1695 GNUNET_i2s (target), 1618 GNUNET_i2s (target),
1696 (NULL != n) ? print_state(n->state) : "NEW PEER"); 1619 (NULL != n) ? GNUNET_TRANSPORT_p2s(n->state) : "NEW PEER");
1697 if (NULL != n) 1620 if (NULL != n)
1698 { 1621 {
1699 switch (n->state) 1622 switch (n->state)
@@ -1734,7 +1657,7 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target)
1734 default: 1657 default:
1735 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1658 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1736 "Unhandled state `%s'\n", 1659 "Unhandled state `%s'\n",
1737 print_state (n->state)); 1660 GNUNET_TRANSPORT_p2s (n->state));
1738 GNUNET_break (0); 1661 GNUNET_break (0);
1739 free_neighbour (n, GNUNET_NO); 1662 free_neighbour (n, GNUNET_NO);
1740 break; 1663 break;
@@ -1795,7 +1718,7 @@ handle_test_blacklist_cont (void *cls,
1795 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1718 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1796 "Received blacklist result for peer `%s' in state %s/%d\n", 1719 "Received blacklist result for peer `%s' in state %s/%d\n",
1797 GNUNET_i2s (peer), 1720 GNUNET_i2s (peer),
1798 print_state (n->state), 1721 GNUNET_TRANSPORT_p2s (n->state),
1799 n->send_connect_ack); 1722 n->send_connect_ack);
1800 switch (n->state) 1723 switch (n->state)
1801 { 1724 {
@@ -1992,7 +1915,7 @@ handle_test_blacklist_cont (void *cls,
1992 default: 1915 default:
1993 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1916 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1994 "Unhandled state `%s'\n", 1917 "Unhandled state `%s'\n",
1995 print_state (n->state)); 1918 GNUNET_TRANSPORT_p2s (n->state));
1996 GNUNET_break (0); 1919 GNUNET_break (0);
1997 free_neighbour (n, GNUNET_NO); 1920 free_neighbour (n, GNUNET_NO);
1998 break; 1921 break;
@@ -2093,7 +2016,7 @@ GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
2093 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2016 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2094 "Received SESSION_CONNECT for peer `%s' in state %s/%d\n", 2017 "Received SESSION_CONNECT for peer `%s' in state %s/%d\n",
2095 GNUNET_i2s (peer), 2018 GNUNET_i2s (peer),
2096 print_state (n->state), 2019 GNUNET_TRANSPORT_p2s (n->state),
2097 n->send_connect_ack); 2020 n->send_connect_ack);
2098 switch (n->state) 2021 switch (n->state)
2099 { 2022 {
@@ -2161,7 +2084,7 @@ GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
2161 default: 2084 default:
2162 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2085 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2163 "Unhandled state `%s'\n", 2086 "Unhandled state `%s'\n",
2164 print_state (n->state)); 2087 GNUNET_TRANSPORT_p2s (n->state));
2165 GNUNET_break (0); 2088 GNUNET_break (0);
2166 return GNUNET_SYSERR; 2089 return GNUNET_SYSERR;
2167 } 2090 }
@@ -2234,7 +2157,7 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
2234 address->transport_name, 2157 address->transport_name,
2235 session, 2158 session,
2236 GNUNET_i2s (peer), 2159 GNUNET_i2s (peer),
2237 print_state (n->state), 2160 GNUNET_TRANSPORT_p2s (n->state),
2238 n->send_connect_ack, 2161 n->send_connect_ack,
2239 ntohl (bandwidth_in.value__), 2162 ntohl (bandwidth_in.value__),
2240 ntohl (bandwidth_out.value__)); 2163 ntohl (bandwidth_out.value__));
@@ -2404,7 +2327,7 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
2404 default: 2327 default:
2405 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2328 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2406 "Unhandled state `%s'\n", 2329 "Unhandled state `%s'\n",
2407 print_state (n->state)); 2330 GNUNET_TRANSPORT_p2s (n->state));
2408 GNUNET_break (0); 2331 GNUNET_break (0);
2409 break; 2332 break;
2410 } 2333 }
@@ -2571,7 +2494,7 @@ master_task (void *cls,
2571 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2494 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2572 "Master task runs for neighbour `%s' in state %s with timeout in %s\n", 2495 "Master task runs for neighbour `%s' in state %s with timeout in %s\n",
2573 GNUNET_i2s (&n->id), 2496 GNUNET_i2s (&n->id),
2574 print_state(n->state), 2497 GNUNET_TRANSPORT_p2s(n->state),
2575 GNUNET_STRINGS_relative_time_to_string (delay, 2498 GNUNET_STRINGS_relative_time_to_string (delay,
2576 GNUNET_YES)); 2499 GNUNET_YES));
2577 switch (n->state) 2500 switch (n->state)
@@ -2742,7 +2665,7 @@ master_task (void *cls,
2742 default: 2665 default:
2743 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2666 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2744 "Unhandled state `%s'\n", 2667 "Unhandled state `%s'\n",
2745 print_state (n->state)); 2668 GNUNET_TRANSPORT_p2s (n->state));
2746 GNUNET_break (0); 2669 GNUNET_break (0);
2747 break; 2670 break;
2748 } 2671 }
@@ -2930,7 +2853,7 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
2930 default: 2853 default:
2931 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2854 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2932 "Unhandled state `%s'\n", 2855 "Unhandled state `%s'\n",
2933 print_state (n->state)); 2856 GNUNET_TRANSPORT_p2s (n->state));
2934 GNUNET_break (0); 2857 GNUNET_break (0);
2935 return GNUNET_SYSERR; 2858 return GNUNET_SYSERR;
2936 } 2859 }
@@ -3060,7 +2983,7 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
3060 default: 2983 default:
3061 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2984 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3062 "Unhandled state `%s'\n", 2985 "Unhandled state `%s'\n",
3063 print_state (n->state)); 2986 GNUNET_TRANSPORT_p2s (n->state));
3064 GNUNET_break (0); 2987 GNUNET_break (0);
3065 break; 2988 break;
3066 } 2989 }
@@ -3117,7 +3040,7 @@ GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
3117 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3040 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3118 "Received SESSION_ACK message from peer `%s' in state %s/%d\n", 3041 "Received SESSION_ACK message from peer `%s' in state %s/%d\n",
3119 GNUNET_i2s (peer), 3042 GNUNET_i2s (peer),
3120 print_state (n->state), 3043 GNUNET_TRANSPORT_p2s (n->state),
3121 n->send_connect_ack); 3044 n->send_connect_ack);
3122 GNUNET_STATISTICS_update (GST_stats, 3045 GNUNET_STATISTICS_update (GST_stats,
3123 gettext_noop ("# unexpected SESSION_ACK messages"), 1, 3046 gettext_noop ("# unexpected SESSION_ACK messages"), 1,
@@ -3297,7 +3220,7 @@ struct IteratorContext
3297 3220
3298 3221
3299/** 3222/**
3300 * Call the callback from the closure for each connected neighbour. 3223 * Call the callback from the closure for each neighbour.
3301 * 3224 *
3302 * @param cls the `struct IteratorContext` 3225 * @param cls the `struct IteratorContext`
3303 * @param key the hash of the public key of the neighbour 3226 * @param key the hash of the public key of the neighbour
@@ -3314,8 +3237,6 @@ neighbours_iterate (void *cls,
3314 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; 3237 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
3315 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out; 3238 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out;
3316 3239
3317 if (GNUNET_YES != test_connected (n))
3318 return GNUNET_OK;
3319 3240
3320 if (NULL != n->primary_address.address) 3241 if (NULL != n->primary_address.address)
3321 { 3242 {
@@ -3327,8 +3248,11 @@ neighbours_iterate (void *cls,
3327 bandwidth_in = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT; 3248 bandwidth_in = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT;
3328 bandwidth_out = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT; 3249 bandwidth_out = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT;
3329 } 3250 }
3330 ic->cb (ic->cb_cls, &n->id, 3251 ic->cb (ic->cb_cls,
3252 &n->id,
3331 n->primary_address.address, 3253 n->primary_address.address,
3254 n->state,
3255 n->timeout,
3332 bandwidth_in, bandwidth_out); 3256 bandwidth_in, bandwidth_out);
3333 return GNUNET_OK; 3257 return GNUNET_OK;
3334} 3258}
@@ -3415,7 +3339,7 @@ GST_neighbour_get_latency (const struct GNUNET_PeerIdentity *peer)
3415 default: 3339 default:
3416 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 3340 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3417 "Unhandled state `%s'\n", 3341 "Unhandled state `%s'\n",
3418 print_state (n->state)); 3342 GNUNET_TRANSPORT_p2s (n->state));
3419 GNUNET_break (0); 3343 GNUNET_break (0);
3420 break; 3344 break;
3421 } 3345 }