diff options
author | Christian Fuchs <christian.fuchs@cfuchs.net> | 2014-05-07 15:25:21 +0000 |
---|---|---|
committer | Christian Fuchs <christian.fuchs@cfuchs.net> | 2014-05-07 15:25:21 +0000 |
commit | 131ce32586090474404fb26f7ea5f25f5dde1690 (patch) | |
tree | f8b67ef353d829d4e7f88a36e31be46d814c46c2 /src/scalarproduct | |
parent | 36367311686410711f46fa3d82484a609c888acf (diff) | |
download | gnunet-131ce32586090474404fb26f7ea5f25f5dde1690.tar.gz gnunet-131ce32586090474404fb26f7ea5f25f5dde1690.zip |
- sessions now terminate correctly for both sides if invalid/unexpected msgs are received
Diffstat (limited to 'src/scalarproduct')
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct.c | 136 |
1 files changed, 93 insertions, 43 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct.c b/src/scalarproduct/gnunet-service-scalarproduct.c index 5c702d5e1..4d435f10b 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct.c +++ b/src/scalarproduct/gnunet-service-scalarproduct.c | |||
@@ -51,7 +51,9 @@ enum PeerRole | |||
51 | BOB | 51 | BOB |
52 | }; | 52 | }; |
53 | 53 | ||
54 | 54 | /** | |
55 | * DLL for sorting elements | ||
56 | */ | ||
55 | struct SortedValue | 57 | struct SortedValue |
56 | { | 58 | { |
57 | struct SortedValue * next; | 59 | struct SortedValue * next; |
@@ -482,6 +484,10 @@ free_session_variables (struct ServiceSession * session) | |||
482 | GNUNET_SET_destroy (session->intersection_set); | 484 | GNUNET_SET_destroy (session->intersection_set); |
483 | session->intersection_set = NULL; | 485 | session->intersection_set = NULL; |
484 | } | 486 | } |
487 | if (session->channel){ | ||
488 | GNUNET_CADET_channel_destroy(session->channel); | ||
489 | session->channel = NULL; | ||
490 | } | ||
485 | if (session->msg) { | 491 | if (session->msg) { |
486 | GNUNET_free (session->msg); | 492 | GNUNET_free (session->msg); |
487 | session->msg = NULL; | 493 | session->msg = NULL; |
@@ -1010,7 +1016,6 @@ cb_insert_element_sorted (void *cls, | |||
1010 | while (NULL != o); | 1016 | while (NULL != o); |
1011 | // broken DLL | 1017 | // broken DLL |
1012 | GNUNET_assert (0); | 1018 | GNUNET_assert (0); |
1013 | return GNUNET_NO; | ||
1014 | } | 1019 | } |
1015 | 1020 | ||
1016 | 1021 | ||
@@ -1058,25 +1063,20 @@ cb_intersection_element_removed (void *cls, | |||
1058 | session->sorted_elements = GNUNET_malloc (session->used_elements_count * sizeof (gcry_mpi_t)); | 1063 | session->sorted_elements = GNUNET_malloc (session->used_elements_count * sizeof (gcry_mpi_t)); |
1059 | for (i = 0; NULL != session->a_head; i++) { | 1064 | for (i = 0; NULL != session->a_head; i++) { |
1060 | struct SortedValue* a = session->a_head; | 1065 | struct SortedValue* a = session->a_head; |
1061 | if (i > session->used_elements_count) { | 1066 | GNUNET_assert (i < session->used_elements_count); |
1062 | GNUNET_assert (0); | 1067 | |
1063 | return; | ||
1064 | } | ||
1065 | session->sorted_elements[i] = a->val; | 1068 | session->sorted_elements[i] = a->val; |
1066 | GNUNET_CONTAINER_DLL_remove (session->a_head, session->a_tail, a); | 1069 | GNUNET_CONTAINER_DLL_remove (session->a_head, session->a_tail, a); |
1067 | GNUNET_free (a->elem); | 1070 | GNUNET_free (a->elem); |
1068 | } | 1071 | } |
1069 | if (i != session->used_elements_count) | 1072 | GNUNET_assert (i == session->used_elements_count); |
1070 | GNUNET_assert (0); | ||
1071 | 1073 | ||
1072 | if (ALICE == session->role) { | 1074 | if (ALICE == session->role) { |
1073 | prepare_alices_cyrptodata_message (session); | 1075 | prepare_alices_cyrptodata_message (session); |
1074 | return; | 1076 | return; |
1075 | } | 1077 | } |
1076 | else { | 1078 | else if (session->used_elements_count == session->transferred_element_count) { |
1077 | if (session->used_elements_count == session->transferred_element_count) | 1079 | compute_service_response (session); |
1078 | compute_service_response (session); | ||
1079 | |||
1080 | return; | 1080 | return; |
1081 | } | 1081 | } |
1082 | default: | 1082 | default: |
@@ -1084,19 +1084,21 @@ cb_intersection_element_removed (void *cls, | |||
1084 | } | 1084 | } |
1085 | 1085 | ||
1086 | //failed if we go here | 1086 | //failed if we go here |
1087 | GNUNET_break (0); | ||
1088 | |||
1089 | // and notify our client-session that we could not complete the session | ||
1087 | if (ALICE == session->role) { | 1090 | if (ALICE == session->role) { |
1088 | session->client_notification_task = | 1091 | session->client_notification_task = |
1089 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 1092 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
1090 | session); | 1093 | session); |
1091 | } | 1094 | } |
1092 | else { | 1095 | else { |
1093 | //TODO: Fail service session, exit tunnel | 1096 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session); |
1094 | 1097 | free_session_variables (session); | |
1095 | |||
1096 | session->response->client_notification_task = | 1098 | session->response->client_notification_task = |
1097 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 1099 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
1098 | session->response); | 1100 | session->response); |
1099 | 1101 | GNUNET_free(session); | |
1100 | } | 1102 | } |
1101 | } | 1103 | } |
1102 | 1104 | ||
@@ -1837,7 +1839,7 @@ handle_alices_cyrptodata_message_multipart (void *cls, | |||
1837 | session = (struct ServiceSession *) * channel_ctx; | 1839 | session = (struct ServiceSession *) * channel_ctx; |
1838 | //we are not bob | 1840 | //we are not bob |
1839 | if ((NULL == session->e_a) || //or we did not expect this message yet | 1841 | if ((NULL == session->e_a) || //or we did not expect this message yet |
1840 | (session->used_elements_count == session->transferred_element_count)) { //we not expecting multipart messages | 1842 | (session->used_elements_count == session->transferred_element_count)) { //we are not expecting multipart messages |
1841 | goto except; | 1843 | goto except; |
1842 | } | 1844 | } |
1843 | // shorter than minimum? | 1845 | // shorter than minimum? |
@@ -1869,15 +1871,24 @@ handle_alices_cyrptodata_message_multipart (void *cls, | |||
1869 | 1871 | ||
1870 | return GNUNET_OK; | 1872 | return GNUNET_OK; |
1871 | except: | 1873 | except: |
1874 | session->channel = NULL; | ||
1872 | // and notify our client-session that we could not complete the session | 1875 | // and notify our client-session that we could not complete the session |
1873 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session); | 1876 | free_session_variables (session); |
1874 | if (session->response) | 1877 | if (NULL != session->client){ |
1875 | // we just found the responder session in this queue | 1878 | //Alice |
1879 | session->client_notification_task = | ||
1880 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | ||
1881 | session); | ||
1882 | } | ||
1883 | else { | ||
1884 | //Bob | ||
1885 | if (NULL != session->response) | ||
1876 | session->response->client_notification_task = | 1886 | session->response->client_notification_task = |
1877 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 1887 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
1878 | session->response); | 1888 | session->response); |
1879 | free_session_variables (session); | 1889 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session); |
1880 | GNUNET_free (session); | 1890 | GNUNET_free(session); |
1891 | } | ||
1881 | return GNUNET_SYSERR; | 1892 | return GNUNET_SYSERR; |
1882 | } | 1893 | } |
1883 | 1894 | ||
@@ -1948,15 +1959,24 @@ handle_alices_cyrptodata_message (void *cls, | |||
1948 | return GNUNET_OK; | 1959 | return GNUNET_OK; |
1949 | invalid_msg: | 1960 | invalid_msg: |
1950 | GNUNET_break_op (0); | 1961 | GNUNET_break_op (0); |
1951 | if ((NULL != session->next) || (NULL != session->prev) || (from_service_head == session)) | 1962 | session->channel = NULL; |
1952 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session); | ||
1953 | // and notify our client-session that we could not complete the session | 1963 | // and notify our client-session that we could not complete the session |
1954 | if (session->response) | 1964 | free_session_variables (session); |
1955 | // we just found the responder session in this queue | 1965 | if (NULL != session->client){ |
1966 | //Alice | ||
1967 | session->client_notification_task = | ||
1968 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | ||
1969 | session); | ||
1970 | } | ||
1971 | else { | ||
1972 | //Bob | ||
1973 | if (NULL != session->response) | ||
1956 | session->response->client_notification_task = | 1974 | session->response->client_notification_task = |
1957 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 1975 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
1958 | session->response); | 1976 | session->response); |
1959 | free_session_variables (session); | 1977 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session); |
1978 | GNUNET_free(session); | ||
1979 | } | ||
1960 | return GNUNET_SYSERR; | 1980 | return GNUNET_SYSERR; |
1961 | } | 1981 | } |
1962 | 1982 | ||
@@ -2062,15 +2082,24 @@ handle_alices_computation_request (void *cls, | |||
2062 | return GNUNET_OK; | 2082 | return GNUNET_OK; |
2063 | invalid_msg: | 2083 | invalid_msg: |
2064 | GNUNET_break_op (0); | 2084 | GNUNET_break_op (0); |
2065 | if ((NULL != session->next) || (NULL != session->prev) || (from_service_head == session)) | 2085 | session->channel = NULL; |
2066 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session); | ||
2067 | // and notify our client-session that we could not complete the session | 2086 | // and notify our client-session that we could not complete the session |
2068 | if (session->response) | 2087 | free_session_variables (session); |
2069 | // we just found the responder session in this queue | 2088 | if (NULL != session->client){ |
2089 | //Alice | ||
2090 | session->client_notification_task = | ||
2091 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | ||
2092 | session); | ||
2093 | } | ||
2094 | else { | ||
2095 | //Bob | ||
2096 | if (NULL != session->response) | ||
2070 | session->response->client_notification_task = | 2097 | session->response->client_notification_task = |
2071 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 2098 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
2072 | session->response); | 2099 | session->response); |
2073 | free_session_variables (session); | 2100 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session); |
2101 | GNUNET_free(session); | ||
2102 | } | ||
2074 | return GNUNET_SYSERR; | 2103 | return GNUNET_SYSERR; |
2075 | } | 2104 | } |
2076 | 2105 | ||
@@ -2131,14 +2160,24 @@ handle_bobs_cryptodata_multipart (void *cls, | |||
2131 | session->product = compute_scalar_product (session); //never NULL | 2160 | session->product = compute_scalar_product (session); //never NULL |
2132 | 2161 | ||
2133 | invalid_msg: | 2162 | invalid_msg: |
2134 | GNUNET_break_op (NULL != session->product); //NULL if we never tried to compute it... | 2163 | GNUNET_break_op (NULL != session->product); |
2135 | 2164 | session->channel = NULL; | |
2136 | // send message with product to client | 2165 | // send message with product to client |
2137 | if (ALICE == session->role) { | 2166 | if (NULL != session->client){ |
2138 | session->channel = NULL; | 2167 | //Alice |
2139 | session->client_notification_task = | 2168 | session->client_notification_task = |
2140 | GNUNET_SCHEDULER_add_now (&prepare_client_response, | 2169 | GNUNET_SCHEDULER_add_now (&prepare_client_response, |
2141 | session); | 2170 | session); |
2171 | } | ||
2172 | else { | ||
2173 | //Bob | ||
2174 | if (NULL != session->response) | ||
2175 | session->response->client_notification_task = | ||
2176 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | ||
2177 | session->response); | ||
2178 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session); | ||
2179 | free_session_variables (session); | ||
2180 | GNUNET_free(session); | ||
2142 | } | 2181 | } |
2143 | // the channel has done its job, terminate our connection and the channel | 2182 | // the channel has done its job, terminate our connection and the channel |
2144 | // the peer will be notified that the channel was destroyed via channel_destruction_handler | 2183 | // the peer will be notified that the channel was destroyed via channel_destruction_handler |
@@ -2215,12 +2254,23 @@ handle_bobs_cryptodata_message (void *cls, | |||
2215 | 2254 | ||
2216 | invalid_msg: | 2255 | invalid_msg: |
2217 | GNUNET_break_op (NULL != session->product); | 2256 | GNUNET_break_op (NULL != session->product); |
2257 | session->channel = NULL; | ||
2218 | // send message with product to client | 2258 | // send message with product to client |
2219 | if (ALICE == session->role) { | 2259 | if (NULL != session->client){ |
2220 | session->channel = NULL; | 2260 | //Alice |
2221 | session->client_notification_task = | 2261 | session->client_notification_task = |
2222 | GNUNET_SCHEDULER_add_now (&prepare_client_response, | 2262 | GNUNET_SCHEDULER_add_now (&prepare_client_response, |
2223 | session); | 2263 | session); |
2264 | } | ||
2265 | else { | ||
2266 | //Bob | ||
2267 | if (NULL != session->response) | ||
2268 | session->response->client_notification_task = | ||
2269 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | ||
2270 | session->response); | ||
2271 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session); | ||
2272 | free_session_variables (session); | ||
2273 | GNUNET_free(session); | ||
2224 | } | 2274 | } |
2225 | // the channel has done its job, terminate our connection and the channel | 2275 | // the channel has done its job, terminate our connection and the channel |
2226 | // the peer will be notified that the channel was destroyed via channel_destruction_handler | 2276 | // the peer will be notified that the channel was destroyed via channel_destruction_handler |
@@ -2328,7 +2378,7 @@ run (void *cls, | |||
2328 | GNUNET_SCHEDULER_shutdown (); | 2378 | GNUNET_SCHEDULER_shutdown (); |
2329 | return; | 2379 | return; |
2330 | } | 2380 | } |
2331 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Mesh initialized\n")); | 2381 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("CADET initialized\n")); |
2332 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 2382 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
2333 | &shutdown_task, | 2383 | &shutdown_task, |
2334 | NULL); | 2384 | NULL); |