diff options
author | Christian Fuchs <christian.fuchs@cfuchs.net> | 2014-05-20 09:58:47 +0000 |
---|---|---|
committer | Christian Fuchs <christian.fuchs@cfuchs.net> | 2014-05-20 09:58:47 +0000 |
commit | 8d5da67b9a88e45c184eb679505afd9ea15eda42 (patch) | |
tree | f7e19523e48f04e89e1064587da260e99d2f2179 /src/scalarproduct | |
parent | 9928bcda2275e422930209ac47d61104422563e8 (diff) | |
download | gnunet-8d5da67b9a88e45c184eb679505afd9ea15eda42.tar.gz gnunet-8d5da67b9a88e45c184eb679505afd9ea15eda42.zip |
- removed now obsolete check for the element count for an scalarproduct calculation
- removed matching for element count for the same reason
- fixed a safety check conditions logics operator from AND to OR
Diffstat (limited to 'src/scalarproduct')
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct.c | 37 | ||||
-rw-r--r-- | src/scalarproduct/scalarproduct.h | 5 |
2 files changed, 15 insertions, 27 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct.c b/src/scalarproduct/gnunet-service-scalarproduct.c index c91693e0e..2d5324eef 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct.c +++ b/src/scalarproduct/gnunet-service-scalarproduct.c | |||
@@ -506,25 +506,22 @@ cb_transfer_message (void *cls, size_t size, void *buf) | |||
506 | * | 506 | * |
507 | * @param tail - the tail of the DLL | 507 | * @param tail - the tail of the DLL |
508 | * @param key - the key we want to search for | 508 | * @param key - the key we want to search for |
509 | * @param element_count - the total element count of the dataset (session->total) | ||
510 | * @param peerid - a pointer to the peer ID of the associated peer, NULL to ignore | 509 | * @param peerid - a pointer to the peer ID of the associated peer, NULL to ignore |
511 | * @return a pointer to a matching session, or NULL | 510 | * @return a pointer to a matching session, or NULL |
512 | */ | 511 | */ |
513 | static struct ServiceSession * | 512 | static struct ServiceSession * |
514 | find_matching_session (struct ServiceSession * tail, | 513 | find_matching_session (struct ServiceSession * tail, |
515 | const struct GNUNET_HashCode * key, | 514 | const struct GNUNET_HashCode * key, |
516 | uint32_t element_count, | ||
517 | const struct GNUNET_PeerIdentity * peerid) | 515 | const struct GNUNET_PeerIdentity * peerid) |
518 | { | 516 | { |
519 | struct ServiceSession * s; | 517 | struct ServiceSession * s; |
520 | 518 | ||
521 | for (s = tail; NULL != s; s = s->prev) { | 519 | for (s = tail; NULL != s; s = s->prev) { |
522 | // if the key matches, and the element_count is same | 520 | // if the key matches, and the element_count is same |
523 | if ((!memcmp (&s->session_id, key, sizeof (struct GNUNET_HashCode))) | 521 | if (0 == memcmp (&s->session_id, key, sizeof (struct GNUNET_HashCode))) { |
524 | && (s->total == element_count)) { | ||
525 | // if peerid is NULL OR same as the peer Id in the queued request | 522 | // if peerid is NULL OR same as the peer Id in the queued request |
526 | if ((NULL == peerid) | 523 | if ((NULL == peerid) |
527 | || (!memcmp (&s->peer, peerid, sizeof (struct GNUNET_PeerIdentity)))) | 524 | || (0 == memcmp (&s->peer, peerid, sizeof (struct GNUNET_PeerIdentity)))) |
528 | // matches and is not an already terminated session | 525 | // matches and is not an already terminated session |
529 | return s; | 526 | return s; |
530 | } | 527 | } |
@@ -1091,6 +1088,7 @@ cb_intersection_element_removed (void *cls, | |||
1091 | case GNUNET_SET_STATUS_DONE: | 1088 | case GNUNET_SET_STATUS_DONE: |
1092 | //stop listening for further requests | 1089 | //stop listening for further requests |
1093 | GNUNET_SET_listen_cancel (s->intersection_listen); | 1090 | GNUNET_SET_listen_cancel (s->intersection_listen); |
1091 | s->intersection_listen = NULL; | ||
1094 | 1092 | ||
1095 | if (2 > s->used_element_count) { | 1093 | if (2 > s->used_element_count) { |
1096 | // failed! do not leak information about our single remaining element! | 1094 | // failed! do not leak information about our single remaining element! |
@@ -1122,11 +1120,18 @@ cb_intersection_element_removed (void *cls, | |||
1122 | return; | 1120 | return; |
1123 | } | 1121 | } |
1124 | default: | 1122 | default: |
1123 | if (NULL != s->intersection_listen){ | ||
1124 | GNUNET_SET_listen_cancel (s->intersection_listen); | ||
1125 | s->intersection_listen = NULL; | ||
1126 | } | ||
1127 | // the op failed and has already been invalidated by the set service | ||
1128 | s->intersection_op = NULL; | ||
1125 | break; | 1129 | break; |
1126 | } | 1130 | } |
1127 | 1131 | ||
1128 | //failed if we go here | 1132 | //failed if we go here |
1129 | GNUNET_break (0); | 1133 | GNUNET_break_op (0); |
1134 | |||
1130 | 1135 | ||
1131 | // and notify our client-session that we could not complete the session | 1136 | // and notify our client-session that we could not complete the session |
1132 | if (ALICE == s->role) { | 1137 | if (ALICE == s->role) { |
@@ -1301,7 +1306,6 @@ prepare_alices_computation_request (struct ServiceSession * s) | |||
1301 | 1306 | ||
1302 | msg = GNUNET_new (struct GNUNET_SCALARPRODUCT_service_request); | 1307 | msg = GNUNET_new (struct GNUNET_SCALARPRODUCT_service_request); |
1303 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA); | 1308 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA); |
1304 | msg->total_element_count = htonl (s->used_element_count); | ||
1305 | memcpy (&msg->session_id, &s->session_id, sizeof (struct GNUNET_HashCode)); | 1309 | memcpy (&msg->session_id, &s->session_id, sizeof (struct GNUNET_HashCode)); |
1306 | msg->header.size = htons (sizeof (struct GNUNET_SCALARPRODUCT_service_request)); | 1310 | msg->header.size = htons (sizeof (struct GNUNET_SCALARPRODUCT_service_request)); |
1307 | 1311 | ||
@@ -1406,7 +1410,7 @@ client_request_complete_bob (struct ServiceSession * client_session) | |||
1406 | //check if service queue contains a matching request | 1410 | //check if service queue contains a matching request |
1407 | s = find_matching_session (from_service_tail, | 1411 | s = find_matching_session (from_service_tail, |
1408 | &client_session->session_id, | 1412 | &client_session->session_id, |
1409 | client_session->total, NULL); | 1413 | NULL); |
1410 | if (NULL != s) { | 1414 | if (NULL != s) { |
1411 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1415 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1412 | _ ("Got client-responder-session with key %s and a matching service-request-session set, processing.\n"), | 1416 | _ ("Got client-responder-session with key %s and a matching service-request-session set, processing.\n"), |
@@ -1596,7 +1600,7 @@ handle_client_message (void *cls, | |||
1596 | // do we have a duplicate session here already? | 1600 | // do we have a duplicate session here already? |
1597 | if (NULL != find_matching_session (from_client_tail, | 1601 | if (NULL != find_matching_session (from_client_tail, |
1598 | &msg->session_key, | 1602 | &msg->session_key, |
1599 | total_count, NULL)) { | 1603 | NULL)) { |
1600 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1604 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1601 | _ ("Duplicate session information received, can not create new session with key `%s'\n"), | 1605 | _ ("Duplicate session information received, can not create new session with key `%s'\n"), |
1602 | GNUNET_h2s (&msg->session_key)); | 1606 | GNUNET_h2s (&msg->session_key)); |
@@ -2049,10 +2053,9 @@ handle_alices_computation_request (void *cls, | |||
2049 | struct ServiceSession * s; | 2053 | struct ServiceSession * s; |
2050 | struct ServiceSession * client_session; | 2054 | struct ServiceSession * client_session; |
2051 | const struct GNUNET_SCALARPRODUCT_service_request * msg = (const struct GNUNET_SCALARPRODUCT_service_request *) message; | 2055 | const struct GNUNET_SCALARPRODUCT_service_request * msg = (const struct GNUNET_SCALARPRODUCT_service_request *) message; |
2052 | uint32_t total_elements; | ||
2053 | 2056 | ||
2054 | s = (struct ServiceSession *) * channel_ctx; | 2057 | s = (struct ServiceSession *) * channel_ctx; |
2055 | if ((BOB != s->role) && (s->total != 0)) { | 2058 | if ((BOB != s->role) || (s->total != 0)) { |
2056 | // must be a fresh session | 2059 | // must be a fresh session |
2057 | goto invalid_msg; | 2060 | goto invalid_msg; |
2058 | } | 2061 | } |
@@ -2068,17 +2071,8 @@ handle_alices_computation_request (void *cls, | |||
2068 | GNUNET_break_op (0); | 2071 | GNUNET_break_op (0); |
2069 | return GNUNET_SYSERR; | 2072 | return GNUNET_SYSERR; |
2070 | } | 2073 | } |
2071 | total_elements = ntohl (msg->total_element_count); | ||
2072 | |||
2073 | //sanity check: is the message as long as the message_count fields suggests? | ||
2074 | if (1 > total_elements) { | ||
2075 | GNUNET_free (s); | ||
2076 | GNUNET_break_op (0); | ||
2077 | return GNUNET_SYSERR; | ||
2078 | } | ||
2079 | if (find_matching_session (from_service_tail, | 2074 | if (find_matching_session (from_service_tail, |
2080 | &msg->session_id, | 2075 | &msg->session_id, |
2081 | total_elements, | ||
2082 | NULL)) { | 2076 | NULL)) { |
2083 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2077 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
2084 | _ ("Got message with duplicate session key (`%s'), ignoring service request.\n"), | 2078 | _ ("Got message with duplicate session key (`%s'), ignoring service request.\n"), |
@@ -2087,7 +2081,6 @@ handle_alices_computation_request (void *cls, | |||
2087 | return GNUNET_SYSERR; | 2081 | return GNUNET_SYSERR; |
2088 | } | 2082 | } |
2089 | 2083 | ||
2090 | s->total = total_elements; | ||
2091 | s->channel = channel; | 2084 | s->channel = channel; |
2092 | 2085 | ||
2093 | // session key | 2086 | // session key |
@@ -2100,7 +2093,7 @@ handle_alices_computation_request (void *cls, | |||
2100 | //check if service queue contains a matching request | 2093 | //check if service queue contains a matching request |
2101 | client_session = find_matching_session (from_client_tail, | 2094 | client_session = find_matching_session (from_client_tail, |
2102 | &s->session_id, | 2095 | &s->session_id, |
2103 | s->total, NULL); | 2096 | NULL); |
2104 | 2097 | ||
2105 | GNUNET_CONTAINER_DLL_insert (from_service_head, from_service_tail, s); | 2098 | GNUNET_CONTAINER_DLL_insert (from_service_head, from_service_tail, s); |
2106 | 2099 | ||
diff --git a/src/scalarproduct/scalarproduct.h b/src/scalarproduct/scalarproduct.h index e83df5188..6837b3abc 100644 --- a/src/scalarproduct/scalarproduct.h +++ b/src/scalarproduct/scalarproduct.h | |||
@@ -121,11 +121,6 @@ struct GNUNET_SCALARPRODUCT_service_request { | |||
121 | struct GNUNET_MessageHeader header; | 121 | struct GNUNET_MessageHeader header; |
122 | 122 | ||
123 | /** | 123 | /** |
124 | * how many elements the total message including all multipart msgs contains | ||
125 | */ | ||
126 | uint32_t total_element_count GNUNET_PACKED; | ||
127 | |||
128 | /** | ||
129 | * the transaction/session key used to identify a session | 124 | * the transaction/session key used to identify a session |
130 | */ | 125 | */ |
131 | struct GNUNET_HashCode session_id; | 126 | struct GNUNET_HashCode session_id; |