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.c112
1 files changed, 70 insertions, 42 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index a3b5639a0..fe3cadc56 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -774,7 +774,7 @@ send_outbound_quota (const struct GNUNET_PeerIdentity *target,
774 * Release its resources and give appropriate notifications 774 * Release its resources and give appropriate notifications
775 * to ATS and other subsystems. 775 * to ATS and other subsystems.
776 * 776 *
777 * @param na address we are done with; 'na' itself must NOT be 'free'd, only the contents! 777 * @param na address we are done with; @a na itself must NOT be 'free'd, only the contents!
778 */ 778 */
779static void 779static void
780free_address (struct NeighbourAddress *na) 780free_address (struct NeighbourAddress *na)
@@ -1817,10 +1817,15 @@ handle_test_blacklist_cont (void *cls,
1817 struct NeighbourMapEntry *n; 1817 struct NeighbourMapEntry *n;
1818 1818
1819 bcc->bc = NULL; 1819 bcc->bc = NULL;
1820 GNUNET_CONTAINER_DLL_remove (bc_head,
1821 bc_tail,
1822 bcc);
1820 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1823 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1821 "Connection to new address of peer `%s' based on blacklist is `%s'\n", 1824 "Connection to new address of peer `%s' based on blacklist is `%s'\n",
1822 GNUNET_i2s (peer), 1825 GNUNET_i2s (peer),
1823 (GNUNET_OK == result) ? "allowed" : "FORBIDDEN"); 1826 (GNUNET_OK == result) ? "allowed" : "FORBIDDEN");
1827 if (GNUNET_OK == result)
1828 GST_ats_add_address (bcc->na.address, bcc->na.session);
1824 if (NULL == (n = lookup_neighbour (peer))) 1829 if (NULL == (n = lookup_neighbour (peer)))
1825 goto cleanup; /* nobody left to care about new address */ 1830 goto cleanup; /* nobody left to care about new address */
1826 switch (n->state) 1831 switch (n->state)
@@ -1831,7 +1836,8 @@ handle_test_blacklist_cont (void *cls,
1831 free_neighbour (n, GNUNET_NO); 1836 free_neighbour (n, GNUNET_NO);
1832 break; 1837 break;
1833 case S_INIT_ATS: 1838 case S_INIT_ATS:
1834 /* still waiting on ATS suggestion */ 1839 /* waiting on ATS suggestion; still, pass address to ATS as a
1840 possibility */
1835 break; 1841 break;
1836 case S_INIT_BLACKLIST: 1842 case S_INIT_BLACKLIST:
1837 /* check if the address the blacklist was fine with matches 1843 /* check if the address the blacklist was fine with matches
@@ -1877,20 +1883,21 @@ handle_test_blacklist_cont (void *cls,
1877 } 1883 }
1878 break; 1884 break;
1879 case S_CONNECT_RECV_BLACKLIST_INBOUND: 1885 case S_CONNECT_RECV_BLACKLIST_INBOUND:
1880 if (GNUNET_OK == result)
1881 GST_ats_add_address (bcc->na.address, bcc->na.session);
1882
1883 n->state = S_CONNECT_RECV_ATS; 1886 n->state = S_CONNECT_RECV_ATS;
1884 n->timeout = GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT); 1887 n->timeout = GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT);
1885 GNUNET_ATS_reset_backoff (GST_ats, peer); 1888 GNUNET_ATS_reset_backoff (GST_ats, peer);
1886 n->suggest_handle = GNUNET_ATS_suggest_address (GST_ats, peer); 1889 n->suggest_handle = GNUNET_ATS_suggest_address (GST_ats, peer);
1887 break; 1890 break;
1888 case S_CONNECT_RECV_ATS: 1891 case S_CONNECT_RECV_ATS:
1889 /* still waiting on ATS suggestion, don't care about blacklist */ 1892 /* waiting on ATS suggestion, don't care about blacklist */
1890 break; 1893 break;
1891 case S_CONNECT_RECV_BLACKLIST: 1894 case S_CONNECT_RECV_BLACKLIST:
1892 if (GNUNET_YES != address_matches (&bcc->na, &n->primary_address)) 1895 if (GNUNET_YES != address_matches (&bcc->na, &n->primary_address))
1896 {
1897 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1898 "Blacklist result ignored, as it is not for our primary address\n");
1893 break; /* result for an address we currently don't care about */ 1899 break; /* result for an address we currently don't care about */
1900 }
1894 if (GNUNET_OK == result) 1901 if (GNUNET_OK == result)
1895 { 1902 {
1896 n->timeout = GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT); 1903 n->timeout = GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT);
@@ -1903,10 +1910,20 @@ handle_test_blacklist_cont (void *cls,
1903 } 1910 }
1904 else 1911 else
1905 { 1912 {
1906 // FIXME: should also possibly destroy session with plugin!? 1913 struct GNUNET_TRANSPORT_PluginFunctions *plugin;
1914
1915 plugin = GST_plugins_find (bcc->na.address->transport_name);
1916 if ( (NULL != plugin) &&
1917 (NULL != bcc->na.session) )
1918 {
1919 plugin->disconnect_session (plugin->cls,
1920 bcc->na.session);
1921 break;
1922 }
1923 GNUNET_break (NULL != plugin);
1907 GNUNET_ATS_address_destroyed (GST_ats, 1924 GNUNET_ATS_address_destroyed (GST_ats,
1908 bcc->na.address, 1925 bcc->na.address,
1909 NULL); 1926 NULL);
1910 free_address (&n->primary_address); 1927 free_address (&n->primary_address);
1911 n->state = S_INIT_ATS; 1928 n->state = S_INIT_ATS;
1912 n->timeout = GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT); 1929 n->timeout = GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT);
@@ -2016,9 +2033,6 @@ handle_test_blacklist_cont (void *cls,
2016 } 2033 }
2017 cleanup: 2034 cleanup:
2018 GNUNET_HELLO_address_free (bcc->na.address); 2035 GNUNET_HELLO_address_free (bcc->na.address);
2019 GNUNET_CONTAINER_DLL_remove (bc_head,
2020 bc_tail,
2021 bcc);
2022 GNUNET_free (bcc); 2036 GNUNET_free (bcc);
2023} 2037}
2024 2038
@@ -2042,7 +2056,7 @@ check_blacklist (const struct GNUNET_PeerIdentity *peer,
2042 struct BlackListCheckContext *bcc; 2056 struct BlackListCheckContext *bcc;
2043 struct GST_BlacklistCheck *bc; 2057 struct GST_BlacklistCheck *bc;
2044 2058
2045 bcc = GNUNET_malloc (sizeof (struct BlackListCheckContext)); 2059 bcc = GNUNET_new (struct BlackListCheckContext);
2046 bcc->na.address = GNUNET_HELLO_address_copy (address); 2060 bcc->na.address = GNUNET_HELLO_address_copy (address);
2047 bcc->na.session = session; 2061 bcc->na.session = session;
2048 bcc->na.connect_timestamp = ts; 2062 bcc->na.connect_timestamp = ts;
@@ -2067,8 +2081,9 @@ check_blacklist (const struct GNUNET_PeerIdentity *peer,
2067 * @param address address of the other peer, NULL if other peer 2081 * @param address address of the other peer, NULL if other peer
2068 * connected to us 2082 * connected to us
2069 * @param session session to use (or NULL) 2083 * @param session session to use (or NULL)
2084 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
2070 */ 2085 */
2071void 2086int
2072GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message, 2087GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
2073 const struct GNUNET_PeerIdentity *peer, 2088 const struct GNUNET_PeerIdentity *peer,
2074 const struct GNUNET_HELLO_Address *address, 2089 const struct GNUNET_HELLO_Address *address,
@@ -2084,14 +2099,19 @@ GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
2084 if (ntohs (message->size) != sizeof (struct SessionConnectMessage)) 2099 if (ntohs (message->size) != sizeof (struct SessionConnectMessage))
2085 { 2100 {
2086 GNUNET_break_op (0); 2101 GNUNET_break_op (0);
2087 return; 2102 return GNUNET_SYSERR;
2088 } 2103 }
2089 GNUNET_STATISTICS_update (GST_stats, 2104 GNUNET_STATISTICS_update (GST_stats,
2090 gettext_noop 2105 gettext_noop
2091 ("# CONNECT messages received"), 2106 ("# CONNECT messages received"),
2092 1, GNUNET_NO); 2107 1, GNUNET_NO);
2093 if (NULL == neighbours) 2108 if (NULL == neighbours)
2094 return; /* we're shutting down */ 2109 {
2110 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2111 _("CONNECT request from peer `%s' ignored due impending shutdown\n"),
2112 GNUNET_i2s (peer));
2113 return GNUNET_OK; /* we're shutting down */
2114 }
2095 scm = (const struct SessionConnectMessage *) message; 2115 scm = (const struct SessionConnectMessage *) message;
2096 GNUNET_break_op (0 == ntohl (scm->reserved)); 2116 GNUNET_break_op (0 == ntohl (scm->reserved));
2097 ts = GNUNET_TIME_absolute_ntoh (scm->timestamp); 2117 ts = GNUNET_TIME_absolute_ntoh (scm->timestamp);
@@ -2169,9 +2189,9 @@ GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
2169 "Unhandled state `%s'\n", 2189 "Unhandled state `%s'\n",
2170 print_state (n->state)); 2190 print_state (n->state));
2171 GNUNET_break (0); 2191 GNUNET_break (0);
2172 free_neighbour (n, GNUNET_NO); 2192 return GNUNET_SYSERR;
2173 break;
2174 } 2193 }
2194 return GNUNET_OK;
2175} 2195}
2176 2196
2177 2197
@@ -2485,33 +2505,32 @@ utilization_transmission (void *cls,
2485 2505
2486} 2506}
2487 2507
2508
2488void 2509void
2489GST_neighbours_notify_data_recv (const struct GNUNET_PeerIdentity *peer, 2510GST_neighbours_notify_data_recv (const struct GNUNET_PeerIdentity *peer,
2490 const struct GNUNET_HELLO_Address *address, 2511 const struct GNUNET_HELLO_Address *address,
2491 struct Session *session, 2512 struct Session *session,
2492 const struct GNUNET_MessageHeader *message) 2513 const struct GNUNET_MessageHeader *message)
2493{ 2514{
2494 struct NeighbourMapEntry *n; 2515 struct NeighbourMapEntry *n;
2516
2495 n = lookup_neighbour (peer); 2517 n = lookup_neighbour (peer);
2496 if (NULL == n) 2518 if (NULL == n)
2497 { 2519 return;
2498 return;
2499 }
2500 n->util_total_bytes_recv += ntohs(message->size); 2520 n->util_total_bytes_recv += ntohs(message->size);
2501} 2521}
2502 2522
2523
2503void 2524void
2504GST_neighbours_notify_payload_recv (const struct GNUNET_PeerIdentity *peer, 2525GST_neighbours_notify_payload_recv (const struct GNUNET_PeerIdentity *peer,
2505 const struct GNUNET_HELLO_Address *address, 2526 const struct GNUNET_HELLO_Address *address,
2506 struct Session *session, 2527 struct Session *session,
2507 const struct GNUNET_MessageHeader *message) 2528 const struct GNUNET_MessageHeader *message)
2508{ 2529{
2509 struct NeighbourMapEntry *n; 2530 struct NeighbourMapEntry *n;
2510 n = lookup_neighbour (peer); 2531 n = lookup_neighbour (peer);
2511 if (NULL == n) 2532 if (NULL == n)
2512 { 2533 return;
2513 return;
2514 }
2515 n->util_payload_bytes_recv += ntohs(message->size); 2534 n->util_payload_bytes_recv += ntohs(message->size);
2516} 2535}
2517 2536
@@ -2779,8 +2798,9 @@ send_session_ack_message (struct NeighbourMapEntry *n)
2779 * @param address address of the other peer, NULL if other peer 2798 * @param address address of the other peer, NULL if other peer
2780 * connected to us 2799 * connected to us
2781 * @param session session to use (or NULL) 2800 * @param session session to use (or NULL)
2801 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
2782 */ 2802 */
2783void 2803int
2784GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message, 2804GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
2785 const struct GNUNET_PeerIdentity *peer, 2805 const struct GNUNET_PeerIdentity *peer,
2786 const struct GNUNET_HELLO_Address *address, 2806 const struct GNUNET_HELLO_Address *address,
@@ -2797,7 +2817,7 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
2797 if (ntohs (message->size) != sizeof (struct SessionConnectMessage)) 2817 if (ntohs (message->size) != sizeof (struct SessionConnectMessage))
2798 { 2818 {
2799 GNUNET_break_op (0); 2819 GNUNET_break_op (0);
2800 return; 2820 return GNUNET_SYSERR;
2801 } 2821 }
2802 GNUNET_STATISTICS_update (GST_stats, 2822 GNUNET_STATISTICS_update (GST_stats,
2803 gettext_noop 2823 gettext_noop
@@ -2811,7 +2831,7 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
2811 gettext_noop 2831 gettext_noop
2812 ("# unexpected CONNECT_ACK messages (no peer)"), 2832 ("# unexpected CONNECT_ACK messages (no peer)"),
2813 1, GNUNET_NO); 2833 1, GNUNET_NO);
2814 return; 2834 return GNUNET_SYSERR;
2815 } 2835 }
2816 ts = GNUNET_TIME_absolute_ntoh (scm->timestamp); 2836 ts = GNUNET_TIME_absolute_ntoh (scm->timestamp);
2817 switch (n->state) 2837 switch (n->state)
@@ -2819,7 +2839,7 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
2819 case S_NOT_CONNECTED: 2839 case S_NOT_CONNECTED:
2820 GNUNET_break (0); 2840 GNUNET_break (0);
2821 free_neighbour (n, GNUNET_NO); 2841 free_neighbour (n, GNUNET_NO);
2822 return; 2842 return GNUNET_SYSERR;
2823 case S_INIT_ATS: 2843 case S_INIT_ATS:
2824 case S_INIT_BLACKLIST: 2844 case S_INIT_BLACKLIST:
2825 GNUNET_STATISTICS_update (GST_stats, 2845 GNUNET_STATISTICS_update (GST_stats,
@@ -2829,7 +2849,11 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
2829 break; 2849 break;
2830 case S_CONNECT_SENT: 2850 case S_CONNECT_SENT:
2831 if (ts.abs_value_us != n->primary_address.connect_timestamp.abs_value_us) 2851 if (ts.abs_value_us != n->primary_address.connect_timestamp.abs_value_us)
2832 break; /* ACK does not match our original CONNECT message */ 2852 {
2853 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2854 "CONNECT_ACK ignored as the timestamp does not match our CONNECT request\n");
2855 return GNUNET_OK;
2856 }
2833 n->state = S_CONNECTED; 2857 n->state = S_CONNECTED;
2834 n->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 2858 n->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
2835 GNUNET_STATISTICS_set (GST_stats, 2859 GNUNET_STATISTICS_set (GST_stats,
@@ -2901,7 +2925,7 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
2901 gettext_noop 2925 gettext_noop
2902 ("# unexpected CONNECT_ACK messages (disconnecting)"), 2926 ("# unexpected CONNECT_ACK messages (disconnecting)"),
2903 1, GNUNET_NO); 2927 1, GNUNET_NO);
2904 break; 2928 return GNUNET_SYSERR;
2905 case S_DISCONNECT_FINISHED: 2929 case S_DISCONNECT_FINISHED:
2906 GNUNET_assert (0); 2930 GNUNET_assert (0);
2907 break; 2931 break;
@@ -2910,8 +2934,9 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
2910 "Unhandled state `%s'\n", 2934 "Unhandled state `%s'\n",
2911 print_state (n->state)); 2935 print_state (n->state));
2912 GNUNET_break (0); 2936 GNUNET_break (0);
2913 break; 2937 return GNUNET_SYSERR;
2914 } 2938 }
2939 return GNUNET_OK;
2915} 2940}
2916 2941
2917 2942
@@ -2939,7 +2964,8 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
2939 bcc_next = bcc->next; 2964 bcc_next = bcc->next;
2940 if (bcc->na.session == session) 2965 if (bcc->na.session == session)
2941 { 2966 {
2942 GST_blacklist_test_cancel (bcc->bc); 2967 if (NULL != bcc->bc)
2968 GST_blacklist_test_cancel (bcc->bc);
2943 GNUNET_HELLO_address_free (bcc->na.address); 2969 GNUNET_HELLO_address_free (bcc->na.address);
2944 GNUNET_CONTAINER_DLL_remove (bc_head, 2970 GNUNET_CONTAINER_DLL_remove (bc_head,
2945 bc_tail, 2971 bc_tail,
@@ -3057,8 +3083,9 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
3057 * @param address address of the other peer, NULL if other peer 3083 * @param address address of the other peer, NULL if other peer
3058 * connected to us 3084 * connected to us
3059 * @param session session to use (or NULL) 3085 * @param session session to use (or NULL)
3086 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
3060 */ 3087 */
3061void 3088int
3062GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message, 3089GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
3063 const struct GNUNET_PeerIdentity *peer, 3090 const struct GNUNET_PeerIdentity *peer,
3064 const struct GNUNET_HELLO_Address *address, 3091 const struct GNUNET_HELLO_Address *address,
@@ -3072,14 +3099,14 @@ GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
3072 if (ntohs (message->size) != sizeof (struct GNUNET_MessageHeader)) 3099 if (ntohs (message->size) != sizeof (struct GNUNET_MessageHeader))
3073 { 3100 {
3074 GNUNET_break_op (0); 3101 GNUNET_break_op (0);
3075 return; 3102 return GNUNET_SYSERR;
3076 } 3103 }
3077 GNUNET_STATISTICS_update (GST_stats, 3104 GNUNET_STATISTICS_update (GST_stats,
3078 gettext_noop 3105 gettext_noop
3079 ("# SESSION_ACK messages received"), 3106 ("# SESSION_ACK messages received"),
3080 1, GNUNET_NO); 3107 1, GNUNET_NO);
3081 if (NULL == (n = lookup_neighbour (peer))) 3108 if (NULL == (n = lookup_neighbour (peer)))
3082 return; 3109 return GNUNET_SYSERR;
3083 /* check if we are in a plausible state for having sent 3110 /* check if we are in a plausible state for having sent
3084 a CONNECT_ACK. If not, return, otherwise break */ 3111 a CONNECT_ACK. If not, return, otherwise break */
3085 if ( ( (S_CONNECT_RECV_ACK != n->state) && 3112 if ( ( (S_CONNECT_RECV_ACK != n->state) &&
@@ -3094,7 +3121,7 @@ GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
3094 GNUNET_STATISTICS_update (GST_stats, 3121 GNUNET_STATISTICS_update (GST_stats,
3095 gettext_noop ("# unexpected SESSION_ACK messages"), 1, 3122 gettext_noop ("# unexpected SESSION_ACK messages"), 1,
3096 GNUNET_NO); 3123 GNUNET_NO);
3097 return; 3124 return GNUNET_SYSERR;
3098 } 3125 }
3099 n->state = S_CONNECTED; 3126 n->state = S_CONNECTED;
3100 n->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 3127 n->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
@@ -3113,6 +3140,7 @@ GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
3113 n->primary_address.bandwidth_in, 3140 n->primary_address.bandwidth_in,
3114 n->primary_address.bandwidth_out, 3141 n->primary_address.bandwidth_out,
3115 GNUNET_YES); 3142 GNUNET_YES);
3143 return GNUNET_OK;
3116} 3144}
3117 3145
3118 3146