aboutsummaryrefslogtreecommitdiff
path: root/src/scalarproduct
diff options
context:
space:
mode:
authorChristian Fuchs <christian.fuchs@cfuchs.net>2013-10-09 08:53:21 +0000
committerChristian Fuchs <christian.fuchs@cfuchs.net>2013-10-09 08:53:21 +0000
commit09e50aa17f458bc9ea5d2e7c787bce962f778d7c (patch)
tree147be7923b75c5460458e368917c1267a3cd85c8 /src/scalarproduct
parentdcba7f93f6cbccbd5f103675109fb1ebb88d6b41 (diff)
downloadgnunet-09e50aa17f458bc9ea5d2e7c787bce962f778d7c.tar.gz
gnunet-09e50aa17f458bc9ea5d2e7c787bce962f778d7c.zip
made the service more resilient against out of order and simply incorrect messages
messages that arrive out of sync with the state machine are supressed and logged fixed a couple of little bugs more work on the SP multipart message support
Diffstat (limited to 'src/scalarproduct')
-rw-r--r--src/scalarproduct/gnunet-service-scalarproduct.c68
1 files changed, 28 insertions, 40 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct.c b/src/scalarproduct/gnunet-service-scalarproduct.c
index e543000fe..46567abed 100644
--- a/src/scalarproduct/gnunet-service-scalarproduct.c
+++ b/src/scalarproduct/gnunet-service-scalarproduct.c
@@ -1904,18 +1904,16 @@ handle_service_request_multipart (void *cls,
1904 struct ServiceSession * session; 1904 struct ServiceSession * session;
1905 const struct GNUNET_SCALARPRODUCT_multipart_message * msg = (const struct GNUNET_SCALARPRODUCT_multipart_message *) message; 1905 const struct GNUNET_SCALARPRODUCT_multipart_message * msg = (const struct GNUNET_SCALARPRODUCT_multipart_message *) message;
1906 uint32_t used_elements; 1906 uint32_t used_elements;
1907 uint32_t contained_elements; 1907 uint32_t contained_elements=0;
1908 uint32_t msg_length; 1908 uint32_t msg_length;
1909 unsigned char * current; 1909 unsigned char * current;
1910 int32_t i = -1; 1910 int32_t i = -1;
1911 1911
1912 // are we in the correct state? 1912 // are we in the correct state?
1913 session = (struct ServiceSession *) * tunnel_ctx; 1913 session = (struct ServiceSession *) * tunnel_ctx;
1914 if (BOB != session->role) { 1914 if ((BOB != session->role) || (WAITING_FOR_MULTIPART_TRANSMISSION != session->state)) {
1915 goto except; 1915 GNUNET_break_op (0);
1916 } 1916 return GNUNET_OK;
1917 if (WAITING_FOR_MULTIPART_TRANSMISSION != session->state) {
1918 goto except;
1919 } 1917 }
1920 // shorter than minimum? 1918 // shorter than minimum?
1921 if (ntohs (msg->header.size) <= sizeof (struct GNUNET_SCALARPRODUCT_multipart_message)) { 1919 if (ntohs (msg->header.size) <= sizeof (struct GNUNET_SCALARPRODUCT_multipart_message)) {
@@ -1971,7 +1969,7 @@ handle_service_request_multipart (void *cls,
1971 1969
1972 return GNUNET_OK; 1970 return GNUNET_OK;
1973except: 1971except:
1974 for (i = 0; i < session->transferred_element_count; i++) 1972 for (i = 0; i < session->transferred_element_count + contained_elements; i++)
1975 if (session->a[i]) 1973 if (session->a[i])
1976 gcry_mpi_release (session->a[i]); 1974 gcry_mpi_release (session->a[i]);
1977 gcry_sexp_release (session->remote_pubkey); 1975 gcry_sexp_release (session->remote_pubkey);
@@ -2019,14 +2017,9 @@ handle_service_request (void *cls,
2019 enum SessionState needed_state; 2017 enum SessionState needed_state;
2020 2018
2021 session = (struct ServiceSession *) * tunnel_ctx; 2019 session = (struct ServiceSession *) * tunnel_ctx;
2022 if (BOB != session->role) { 2020 if (WAITING_FOR_SERVICE_REQUEST != session->state) {
2023 GNUNET_break_op (0);
2024 return GNUNET_SYSERR;
2025 }
2026 // is this tunnel already in use?
2027 if ((session->next) || (from_service_head == session)) {
2028 GNUNET_break_op (0); 2021 GNUNET_break_op (0);
2029 return GNUNET_SYSERR; 2022 return GNUNET_OK;
2030 } 2023 }
2031 // Check if message was sent by me, which would be bad! 2024 // Check if message was sent by me, which would be bad!
2032 if (!memcmp (&session->peer, &me, sizeof (struct GNUNET_PeerIdentity))) { 2025 if (!memcmp (&session->peer, &me, sizeof (struct GNUNET_PeerIdentity))) {
@@ -2179,18 +2172,16 @@ handle_service_response_multipart (void *cls,
2179 unsigned char * current; 2172 unsigned char * current;
2180 size_t read; 2173 size_t read;
2181 size_t i; 2174 size_t i;
2182 uint32_t contained_element_count; 2175 uint32_t contained_element_count=0;
2183 size_t msg_size; 2176 size_t msg_size;
2184 int rc; 2177 int rc;
2185 2178
2186 GNUNET_assert (NULL != message); 2179 GNUNET_assert (NULL != message);
2187 // are we in the correct state? 2180 // are we in the correct state?
2188 session = (struct ServiceSession *) * tunnel_ctx; 2181 session = (struct ServiceSession *) * tunnel_ctx;
2189 if (ALICE != session->role) { 2182 if ((ALICE != session->role) || (WAITING_FOR_MULTIPART_TRANSMISSION != session->state)) {
2190 goto except; 2183 GNUNET_break_op (0);
2191 } 2184 return GNUNET_OK;
2192 if (WAITING_FOR_MULTIPART_TRANSMISSION != session->state) {
2193 goto except;
2194 } 2185 }
2195 // shorter than minimum? 2186 // shorter than minimum?
2196 if (ntohs (msg->header.size) <= sizeof (struct GNUNET_SCALARPRODUCT_multipart_message)) { 2187 if (ntohs (msg->header.size) <= sizeof (struct GNUNET_SCALARPRODUCT_multipart_message)) {
@@ -2203,7 +2194,6 @@ handle_service_response_multipart (void *cls,
2203 if ((ntohs (msg->header.size) != msg_size) || (session->used_element_count < contained_element_count)) { 2194 if ((ntohs (msg->header.size) != msg_size) || (session->used_element_count < contained_element_count)) {
2204 goto except; 2195 goto except;
2205 } 2196 }
2206 //convert s
2207 current = (unsigned char *) &msg[1]; 2197 current = (unsigned char *) &msg[1];
2208 // Convert each k[][perm] to its MPI_value 2198 // Convert each k[][perm] to its MPI_value
2209 for (i = 0; i < contained_element_count; i++) { 2199 for (i = 0; i < contained_element_count; i++) {
@@ -2223,12 +2213,11 @@ handle_service_response_multipart (void *cls,
2223 current += PAILLIER_ELEMENT_LENGTH; 2213 current += PAILLIER_ELEMENT_LENGTH;
2224 } 2214 }
2225 session->transferred_element_count += contained_element_count; 2215 session->transferred_element_count += contained_element_count;
2226 if (session->transferred_element_count == session->used_element_count){ 2216 if (session->transferred_element_count != session->used_element_count)
2227 session->state = SERVICE_RESPONSE_RECEIVED; 2217 return GNUNET_OK;
2228 session->product = compute_scalar_product (session); 2218 session->state = SERVICE_RESPONSE_RECEIVED;
2229 return GNUNET_SYSERR; // terminate the tunnel right away, we are done here! 2219 session->product = compute_scalar_product (session);
2230 } 2220 return GNUNET_SYSERR; // terminate the tunnel right away, we are done here!
2231 return GNUNET_OK;
2232except: 2221except:
2233 GNUNET_break_op (0); 2222 GNUNET_break_op (0);
2234 if (session->s) 2223 if (session->s)
@@ -2276,20 +2265,17 @@ handle_service_response (void *cls,
2276 unsigned char * current; 2265 unsigned char * current;
2277 size_t read; 2266 size_t read;
2278 size_t i; 2267 size_t i;
2279 uint32_t contained_element_count; 2268 uint32_t contained_element_count=0;
2280 size_t msg_size; 2269 size_t msg_size;
2281 int rc; 2270 int rc;
2282 2271
2283 GNUNET_assert (NULL != message); 2272 GNUNET_assert (NULL != message);
2284 session = (struct ServiceSession *) * tunnel_ctx; 2273 session = (struct ServiceSession *) * tunnel_ctx;
2285 if (ALICE != session->role) { 2274 if (session->state != WAITING_FOR_SERVICE_REQUEST) {
2286 GNUNET_break_op (0); 2275 GNUNET_break_op (0);
2287 return GNUNET_SYSERR; 2276 return GNUNET_OK;
2288 } 2277 }
2289 2278 //we need at least a full message
2290 session->state = WAITING_FOR_MULTIPART_TRANSMISSION;
2291
2292 //we need at least a peer and one message id to compare
2293 if (sizeof (struct GNUNET_SCALARPRODUCT_service_response) > ntohs (msg->header.size)) { 2279 if (sizeof (struct GNUNET_SCALARPRODUCT_service_response) > ntohs (msg->header.size)) {
2294 GNUNET_break_op (0); 2280 GNUNET_break_op (0);
2295 goto invalid_msg; 2281 goto invalid_msg;
@@ -2303,6 +2289,7 @@ handle_service_response (void *cls,
2303 GNUNET_break_op (0); 2289 GNUNET_break_op (0);
2304 goto invalid_msg; 2290 goto invalid_msg;
2305 } 2291 }
2292 session->state = WAITING_FOR_MULTIPART_TRANSMISSION;
2306 session->transferred_element_count = contained_element_count; 2293 session->transferred_element_count = contained_element_count;
2307 //convert s 2294 //convert s
2308 current = (unsigned char *) &msg[1]; 2295 current = (unsigned char *) &msg[1];
@@ -2340,12 +2327,13 @@ handle_service_response (void *cls,
2340 } 2327 }
2341 current += PAILLIER_ELEMENT_LENGTH; 2328 current += PAILLIER_ELEMENT_LENGTH;
2342 } 2329 }
2343 if (session->transferred_element_count == session->used_element_count){ 2330 if (session->transferred_element_count != session->used_element_count)
2344 session->state = SERVICE_RESPONSE_RECEIVED; 2331 return GNUNET_OK; //wait for the other multipart chunks
2345 session->product = compute_scalar_product (session); 2332
2346 return GNUNET_SYSERR; // terminate the tunnel right away, we are done here! 2333 session->state = SERVICE_RESPONSE_RECEIVED;
2347 } 2334 session->product = compute_scalar_product (session);
2348 return GNUNET_OK; 2335 return GNUNET_SYSERR; // terminate the tunnel right away, we are done here!
2336
2349invalid_msg: 2337invalid_msg:
2350 if (session->s) 2338 if (session->s)
2351 gcry_mpi_release (session->s); 2339 gcry_mpi_release (session->s);