diff options
author | Christian Fuchs <christian.fuchs@cfuchs.net> | 2013-10-10 13:07:44 +0000 |
---|---|---|
committer | Christian Fuchs <christian.fuchs@cfuchs.net> | 2013-10-10 13:07:44 +0000 |
commit | 290fd094567179f05cdfd60a0187f0ea5d1c39ea (patch) | |
tree | 9b0e2e1cfee4b7c6bf0a4e5754ad404685a41b03 /src/scalarproduct | |
parent | 0f4a34c3c534fc01ded8ea3d94b990ca09d7ac0b (diff) | |
download | gnunet-290fd094567179f05cdfd60a0187f0ea5d1c39ea.tar.gz gnunet-290fd094567179f05cdfd60a0187f0ea5d1c39ea.zip |
simplified SP cleanup a bit
added a logics fix
Diffstat (limited to 'src/scalarproduct')
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct.c | 119 |
1 files changed, 37 insertions, 82 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct.c b/src/scalarproduct/gnunet-service-scalarproduct.c index 5bf5f1a2b..f85667874 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct.c +++ b/src/scalarproduct/gnunet-service-scalarproduct.c | |||
@@ -693,25 +693,25 @@ find_matching_session (struct ServiceSession * tail, | |||
693 | } | 693 | } |
694 | 694 | ||
695 | static void | 695 | static void |
696 | free_session (struct ServiceSession * session) | 696 | free_session_variables (struct ServiceSession * session) |
697 | { | 697 | { |
698 | unsigned int i; | 698 | unsigned int i; |
699 | 699 | ||
700 | if (session->a){ | 700 | if (session->a){ |
701 | for (i = 0; i < session->used; i++) | 701 | for (i = 0; i < session->used; i++) |
702 | if (session->a[i]) gcry_mpi_release (session->a[i]); | 702 | if (session->a[i]) gcry_mpi_release (session->a[i]); |
703 | GNUNET_free_non_null (session->a); | 703 | GNUNET_free (session->a); |
704 | } | 704 | } |
705 | GNUNET_free_non_null (session->mask); | 705 | GNUNET_free_non_null (session->mask); |
706 | if (session->r){ | 706 | if (session->r){ |
707 | for (i = 0; i < session->used; i++) | 707 | for (i = 0; i < session->used; i++) |
708 | if (session->r[i]) gcry_mpi_release (session->r[i]); | 708 | if (session->r[i]) gcry_mpi_release (session->r[i]); |
709 | GNUNET_free_non_null(session->r); | 709 | GNUNET_free(session->r); |
710 | } | 710 | } |
711 | if (session->r_prime){ | 711 | if (session->r_prime){ |
712 | for (i = 0; i < session->used; i++) | 712 | for (i = 0; i < session->used; i++) |
713 | if (session->r_prime[i]) gcry_mpi_release (session->r_prime[i]); | 713 | if (session->r_prime[i]) gcry_mpi_release (session->r_prime[i]); |
714 | GNUNET_free_non_null(session->r_prime); | 714 | GNUNET_free(session->r_prime); |
715 | } | 715 | } |
716 | if (session->s) | 716 | if (session->s) |
717 | gcry_mpi_release (session->s); | 717 | gcry_mpi_release (session->s); |
@@ -724,7 +724,6 @@ free_session (struct ServiceSession * session) | |||
724 | gcry_sexp_release (session->remote_pubkey); | 724 | gcry_sexp_release (session->remote_pubkey); |
725 | 725 | ||
726 | GNUNET_free_non_null (session->vector); | 726 | GNUNET_free_non_null (session->vector); |
727 | GNUNET_free (session); | ||
728 | } | 727 | } |
729 | /////////////////////////////////////////////////////////////////////////////// | 728 | /////////////////////////////////////////////////////////////////////////////// |
730 | // Event and Message Handlers | 729 | // Event and Message Handlers |
@@ -774,7 +773,8 @@ handle_client_disconnect (void *cls, | |||
774 | GNUNET_SERVER_notify_transmit_ready_cancel (session->client_transmit_handle); | 773 | GNUNET_SERVER_notify_transmit_ready_cancel (session->client_transmit_handle); |
775 | session->client_transmit_handle = NULL; | 774 | session->client_transmit_handle = NULL; |
776 | } | 775 | } |
777 | free_session (session); | 776 | free_session_variables (session); |
777 | GNUNET_free (session); | ||
778 | } | 778 | } |
779 | 779 | ||
780 | /** | 780 | /** |
@@ -1493,7 +1493,8 @@ handle_client_request (void *cls, | |||
1493 | else if (NULL != session) { | 1493 | else if (NULL != session) { |
1494 | // old session is already completed, clean it up | 1494 | // old session is already completed, clean it up |
1495 | GNUNET_CONTAINER_DLL_remove (from_client_head, from_client_tail, session); | 1495 | GNUNET_CONTAINER_DLL_remove (from_client_head, from_client_tail, session); |
1496 | free_session (session); | 1496 | free_session_variables (session); |
1497 | GNUNET_free (session); | ||
1497 | } | 1498 | } |
1498 | 1499 | ||
1499 | //we need at least a peer and one message id to compare | 1500 | //we need at least a peer and one message id to compare |
@@ -1715,7 +1716,8 @@ tunnel_destruction_handler (void *cls, | |||
1715 | &session->key, | 1716 | &session->key, |
1716 | session->total, | 1717 | session->total, |
1717 | NULL, NULL); | 1718 | NULL, NULL); |
1718 | free_session (session); | 1719 | free_session_variables (session); |
1720 | GNUNET_free (session); | ||
1719 | 1721 | ||
1720 | // the client has to check if it was waiting for a result | 1722 | // the client has to check if it was waiting for a result |
1721 | // or if it was a responder, no point in adding more statefulness | 1723 | // or if it was a responder, no point in adding more statefulness |
@@ -1931,6 +1933,7 @@ handle_service_request_multipart (void *cls, | |||
1931 | uint32_t contained_elements=0; | 1933 | uint32_t contained_elements=0; |
1932 | uint32_t msg_length; | 1934 | uint32_t msg_length; |
1933 | unsigned char * current; | 1935 | unsigned char * current; |
1936 | gcry_error_t rc; | ||
1934 | int32_t i = -1; | 1937 | int32_t i = -1; |
1935 | 1938 | ||
1936 | // are we in the correct state? | 1939 | // are we in the correct state? |
@@ -1953,19 +1956,15 @@ handle_service_request_multipart (void *cls, | |||
1953 | } | 1956 | } |
1954 | current = (unsigned char *) &msg[1]; | 1957 | current = (unsigned char *) &msg[1]; |
1955 | if (contained_elements != 0) { | 1958 | if (contained_elements != 0) { |
1956 | gcry_error_t ret = 0; | ||
1957 | // Convert each vector element to MPI_value | 1959 | // Convert each vector element to MPI_value |
1958 | for (i = session->transferred; i < session->transferred+contained_elements; i++) { | 1960 | for (i = session->transferred; i < session->transferred+contained_elements; i++) { |
1959 | size_t read = 0; | 1961 | size_t read = 0; |
1960 | 1962 | if (0 != (rc = gcry_mpi_scan (&session->a[i], | |
1961 | ret = gcry_mpi_scan (&session->a[i], | ||
1962 | GCRYMPI_FMT_USG, | 1963 | GCRYMPI_FMT_USG, |
1963 | ¤t[i * PAILLIER_ELEMENT_LENGTH], | 1964 | ¤t[i * PAILLIER_ELEMENT_LENGTH], |
1964 | PAILLIER_ELEMENT_LENGTH, | 1965 | PAILLIER_ELEMENT_LENGTH, |
1965 | &read); | 1966 | &read))) { |
1966 | if (ret) { | 1967 | LOG_GCRY (GNUNET_ERROR_TYPE_DEBUG, "gcry_mpi_scan", rc); |
1967 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ ("Could not translate E[a%d] to MPI!\n%s/%s\n"), | ||
1968 | i, gcry_strsource (ret), gcry_strerror (ret)); | ||
1969 | goto except; | 1968 | goto except; |
1970 | } | 1969 | } |
1971 | } | 1970 | } |
@@ -1978,7 +1977,6 @@ handle_service_request_multipart (void *cls, | |||
1978 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Got session with key %s and a matching element set, processing.\n"), GNUNET_h2s (&session->key)); | 1977 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Got session with key %s and a matching element set, processing.\n"), GNUNET_h2s (&session->key)); |
1979 | if (GNUNET_OK != compute_service_response (session, session->response)) { | 1978 | if (GNUNET_OK != compute_service_response (session, session->response)) { |
1980 | //something went wrong, remove it again... | 1979 | //something went wrong, remove it again... |
1981 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session); | ||
1982 | goto except; | 1980 | goto except; |
1983 | } | 1981 | } |
1984 | } | 1982 | } |
@@ -1999,7 +1997,8 @@ except: | |||
1999 | session->response->client_notification_task = | 1997 | session->response->client_notification_task = |
2000 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 1998 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
2001 | session->response); | 1999 | session->response); |
2002 | free_session (session); | 2000 | free_session_variables (session); |
2001 | GNUNET_free (session); | ||
2003 | return GNUNET_SYSERR; | 2002 | return GNUNET_SYSERR; |
2004 | } | 2003 | } |
2005 | 2004 | ||
@@ -2030,6 +2029,7 @@ handle_service_request (void *cls, | |||
2030 | uint32_t element_count; | 2029 | uint32_t element_count; |
2031 | uint32_t msg_length; | 2030 | uint32_t msg_length; |
2032 | unsigned char * current; | 2031 | unsigned char * current; |
2032 | gcry_error_t rc; | ||
2033 | int32_t i = -1; | 2033 | int32_t i = -1; |
2034 | enum SessionState needed_state; | 2034 | enum SessionState needed_state; |
2035 | 2035 | ||
@@ -2091,15 +2091,13 @@ handle_service_request (void *cls, | |||
2091 | current += mask_length; | 2091 | current += mask_length; |
2092 | 2092 | ||
2093 | //convert the publickey to sexp | 2093 | //convert the publickey to sexp |
2094 | if (gcry_sexp_new (&session->remote_pubkey, current, pk_length, 1)) { | 2094 | if (0 != (rc = gcry_sexp_new (&session->remote_pubkey, current, pk_length, 1))) { |
2095 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ ("Could not translate remote public key to sexpression!\n")); | 2095 | LOG_GCRY (GNUNET_ERROR_TYPE_DEBUG, "gcry_sexp_new", rc); |
2096 | GNUNET_free (session->mask); | 2096 | GNUNET_free (session->mask); |
2097 | GNUNET_free (session); | 2097 | GNUNET_free (session); |
2098 | return GNUNET_SYSERR; | 2098 | return GNUNET_SYSERR; |
2099 | } | 2099 | } |
2100 | |||
2101 | current += pk_length; | 2100 | current += pk_length; |
2102 | |||
2103 | //check if service queue contains a matching request | 2101 | //check if service queue contains a matching request |
2104 | needed_state = CLIENT_RESPONSE_RECEIVED; | 2102 | needed_state = CLIENT_RESPONSE_RECEIVED; |
2105 | session->response = find_matching_session (from_client_tail, | 2103 | session->response = find_matching_session (from_client_tail, |
@@ -2109,25 +2107,20 @@ handle_service_request (void *cls, | |||
2109 | 2107 | ||
2110 | session->a = GNUNET_malloc (sizeof (gcry_mpi_t) * used_elements); | 2108 | session->a = GNUNET_malloc (sizeof (gcry_mpi_t) * used_elements); |
2111 | session->state = WAITING_FOR_MULTIPART_TRANSMISSION; | 2109 | session->state = WAITING_FOR_MULTIPART_TRANSMISSION; |
2110 | GNUNET_CONTAINER_DLL_insert (from_service_head, from_service_tail, session); | ||
2112 | if (contained_elements != 0) { | 2111 | if (contained_elements != 0) { |
2113 | gcry_error_t ret = 0; | ||
2114 | // Convert each vector element to MPI_value | 2112 | // Convert each vector element to MPI_value |
2115 | for (i = 0; i < contained_elements; i++) { | 2113 | for (i = 0; i < contained_elements; i++) { |
2116 | size_t read = 0; | 2114 | size_t read = 0; |
2117 | 2115 | if (0 != (rc = gcry_mpi_scan (&session->a[i], | |
2118 | ret = gcry_mpi_scan (&session->a[i], | ||
2119 | GCRYMPI_FMT_USG, | 2116 | GCRYMPI_FMT_USG, |
2120 | ¤t[i * PAILLIER_ELEMENT_LENGTH], | 2117 | ¤t[i * PAILLIER_ELEMENT_LENGTH], |
2121 | PAILLIER_ELEMENT_LENGTH, | 2118 | PAILLIER_ELEMENT_LENGTH, |
2122 | &read); | 2119 | &read))) { |
2123 | if (ret) { | 2120 | LOG_GCRY (GNUNET_ERROR_TYPE_DEBUG, "gcry_mpi_scan", rc); |
2124 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ ("Could not translate E[a%d] to MPI!\n%s/%s\n"), | ||
2125 | i, gcry_strsource (ret), gcry_strerror (ret)); | ||
2126 | goto invalid_msg; | 2121 | goto invalid_msg; |
2127 | } | 2122 | } |
2128 | } | 2123 | } |
2129 | GNUNET_CONTAINER_DLL_insert (from_service_head, from_service_tail, session); | ||
2130 | |||
2131 | if (contained_elements == used_elements) { | 2124 | if (contained_elements == used_elements) { |
2132 | // single part finished | 2125 | // single part finished |
2133 | session->state = SERVICE_REQUEST_RECEIVED; | 2126 | session->state = SERVICE_REQUEST_RECEIVED; |
@@ -2135,7 +2128,6 @@ handle_service_request (void *cls, | |||
2135 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Got session with key %s and a matching element set, processing.\n"), GNUNET_h2s (&session->key)); | 2128 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Got session with key %s and a matching element set, processing.\n"), GNUNET_h2s (&session->key)); |
2136 | if (GNUNET_OK != compute_service_response (session, session->response)) { | 2129 | if (GNUNET_OK != compute_service_response (session, session->response)) { |
2137 | //something went wrong, remove it again... | 2130 | //something went wrong, remove it again... |
2138 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session); | ||
2139 | goto invalid_msg; | 2131 | goto invalid_msg; |
2140 | } | 2132 | } |
2141 | } | 2133 | } |
@@ -2149,13 +2141,15 @@ handle_service_request (void *cls, | |||
2149 | return GNUNET_OK; | 2141 | return GNUNET_OK; |
2150 | invalid_msg: | 2142 | invalid_msg: |
2151 | GNUNET_break_op (0); | 2143 | GNUNET_break_op (0); |
2144 | if ((NULL != session->next) || (NULL != session->prev) || (from_service_head == session)) | ||
2145 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session); | ||
2152 | // and notify our client-session that we could not complete the session | 2146 | // and notify our client-session that we could not complete the session |
2153 | if (session->response) | 2147 | if (session->response) |
2154 | // we just found the responder session in this queue | 2148 | // we just found the responder session in this queue |
2155 | session->response->client_notification_task = | 2149 | session->response->client_notification_task = |
2156 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 2150 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
2157 | session->response); | 2151 | session->response); |
2158 | free_session (session); | 2152 | free_session_variables (session); |
2159 | return GNUNET_SYSERR; | 2153 | return GNUNET_SYSERR; |
2160 | } | 2154 | } |
2161 | 2155 | ||
@@ -2190,8 +2184,7 @@ handle_service_response_multipart (void *cls, | |||
2190 | // are we in the correct state? | 2184 | // are we in the correct state? |
2191 | session = (struct ServiceSession *) * tunnel_ctx; | 2185 | session = (struct ServiceSession *) * tunnel_ctx; |
2192 | if ((ALICE != session->role) || (WAITING_FOR_MULTIPART_TRANSMISSION != session->state)) { | 2186 | if ((ALICE != session->role) || (WAITING_FOR_MULTIPART_TRANSMISSION != session->state)) { |
2193 | GNUNET_break_op (0); | 2187 | goto invalid_msg; |
2194 | return GNUNET_OK; | ||
2195 | } | 2188 | } |
2196 | // shorter than minimum? | 2189 | // shorter than minimum? |
2197 | if (ntohs (msg->header.size) <= sizeof (struct GNUNET_SCALARPRODUCT_multipart_message)) { | 2190 | if (ntohs (msg->header.size) <= sizeof (struct GNUNET_SCALARPRODUCT_multipart_message)) { |
@@ -2210,14 +2203,12 @@ handle_service_response_multipart (void *cls, | |||
2210 | if (0 != (rc = gcry_mpi_scan (&session->r[i], GCRYMPI_FMT_USG, current, | 2203 | if (0 != (rc = gcry_mpi_scan (&session->r[i], GCRYMPI_FMT_USG, current, |
2211 | PAILLIER_ELEMENT_LENGTH, &read))) { | 2204 | PAILLIER_ELEMENT_LENGTH, &read))) { |
2212 | LOG_GCRY (GNUNET_ERROR_TYPE_DEBUG, "gcry_mpi_scan", rc); | 2205 | LOG_GCRY (GNUNET_ERROR_TYPE_DEBUG, "gcry_mpi_scan", rc); |
2213 | GNUNET_break_op (0); | ||
2214 | goto invalid_msg; | 2206 | goto invalid_msg; |
2215 | } | 2207 | } |
2216 | current += PAILLIER_ELEMENT_LENGTH; | 2208 | current += PAILLIER_ELEMENT_LENGTH; |
2217 | if (0 != (rc = gcry_mpi_scan (&session->r_prime[i], GCRYMPI_FMT_USG, current, | 2209 | if (0 != (rc = gcry_mpi_scan (&session->r_prime[i], GCRYMPI_FMT_USG, current, |
2218 | PAILLIER_ELEMENT_LENGTH, &read))) { | 2210 | PAILLIER_ELEMENT_LENGTH, &read))) { |
2219 | LOG_GCRY (GNUNET_ERROR_TYPE_DEBUG, "gcry_mpi_scan", rc); | 2211 | LOG_GCRY (GNUNET_ERROR_TYPE_DEBUG, "gcry_mpi_scan", rc); |
2220 | GNUNET_break_op (0); | ||
2221 | goto invalid_msg; | 2212 | goto invalid_msg; |
2222 | } | 2213 | } |
2223 | current += PAILLIER_ELEMENT_LENGTH; | 2214 | current += PAILLIER_ELEMENT_LENGTH; |
@@ -2231,32 +2222,14 @@ handle_service_response_multipart (void *cls, | |||
2231 | 2222 | ||
2232 | invalid_msg: | 2223 | invalid_msg: |
2233 | GNUNET_break_op (0); | 2224 | GNUNET_break_op (0); |
2234 | if (session->s) | 2225 | free_session_variables (session); |
2235 | gcry_mpi_release (session->s); | 2226 | session->state = FINALIZED; |
2236 | if (session->s_prime) | ||
2237 | gcry_mpi_release (session->s_prime); | ||
2238 | if (session->r) | ||
2239 | for (i = 0; session->r && i < session->used; i++) | ||
2240 | if (session->r[i]) gcry_mpi_release (session->r[i]); | ||
2241 | if (session->r_prime) | ||
2242 | for (i = 0; session->r_prime && i < session->used; i++) | ||
2243 | if (session->r_prime[i]) gcry_mpi_release (session->r_prime[i]); | ||
2244 | if (session->a) | ||
2245 | for (i = 0; session->a && i < session->used; i++) | ||
2246 | if (session->a[i]) gcry_mpi_release (session->a[i]); | ||
2247 | GNUNET_free_non_null (session->r); | ||
2248 | GNUNET_free_non_null (session->r_prime); | ||
2249 | GNUNET_free_non_null (session->a); | ||
2250 | session->a = NULL; | ||
2251 | session->s = NULL; | ||
2252 | session->s_prime = NULL; | ||
2253 | session->r = NULL; | ||
2254 | session->r_prime = NULL; | ||
2255 | session->tunnel = NULL; | 2227 | session->tunnel = NULL; |
2256 | // send message with product to client | 2228 | // send message with product to client |
2257 | session->client_notification_task = | 2229 | if (ALICE == session->role) |
2258 | GNUNET_SCHEDULER_add_now (&prepare_client_response, | 2230 | session->client_notification_task = |
2259 | session); | 2231 | GNUNET_SCHEDULER_add_now (&prepare_client_response, |
2232 | session); | ||
2260 | // the tunnel has done its job, terminate our connection and the tunnel | 2233 | // the tunnel has done its job, terminate our connection and the tunnel |
2261 | // the peer will be notified that the tunnel was destroyed via tunnel_destruction_handler | 2234 | // the peer will be notified that the tunnel was destroyed via tunnel_destruction_handler |
2262 | // just close the connection, as recommended by Christian | 2235 | // just close the connection, as recommended by Christian |
@@ -2351,30 +2324,12 @@ handle_service_response (void *cls, | |||
2351 | 2324 | ||
2352 | invalid_msg: | 2325 | invalid_msg: |
2353 | GNUNET_break_op (0); | 2326 | GNUNET_break_op (0); |
2354 | if (session->s) | 2327 | free_session_variables (session); |
2355 | gcry_mpi_release (session->s); | 2328 | session->state = FINALIZED; |
2356 | if (session->s_prime) | ||
2357 | gcry_mpi_release (session->s_prime); | ||
2358 | if (session->r) | ||
2359 | for (i = 0; session->r && i < session->used; i++) | ||
2360 | if (session->r[i]) gcry_mpi_release (session->r[i]); | ||
2361 | if (session->r_prime) | ||
2362 | for (i = 0; session->r_prime && i < session->used; i++) | ||
2363 | if (session->r_prime[i]) gcry_mpi_release (session->r_prime[i]); | ||
2364 | if (session->a) | ||
2365 | for (i = 0; session->a && i < session->used; i++) | ||
2366 | if (session->a[i]) gcry_mpi_release (session->a[i]); | ||
2367 | GNUNET_free_non_null (session->r); | ||
2368 | GNUNET_free_non_null (session->r_prime); | ||
2369 | GNUNET_free_non_null (session->a); | ||
2370 | session->a = NULL; | ||
2371 | session->s = NULL; | ||
2372 | session->s_prime = NULL; | ||
2373 | session->r = NULL; | ||
2374 | session->r_prime = NULL; | ||
2375 | session->tunnel = NULL; | 2329 | session->tunnel = NULL; |
2376 | // send message with product to client | 2330 | // send message with product to client |
2377 | session->client_notification_task = | 2331 | if (ALICE == session->role) |
2332 | session->client_notification_task = | ||
2378 | GNUNET_SCHEDULER_add_now (&prepare_client_response, | 2333 | GNUNET_SCHEDULER_add_now (&prepare_client_response, |
2379 | session); | 2334 | session); |
2380 | // the tunnel has done its job, terminate our connection and the tunnel | 2335 | // the tunnel has done its job, terminate our connection and the tunnel |