diff options
-rw-r--r-- | src/scalarproduct/Makefile.am | 1 | ||||
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct.c | 182 | ||||
-rw-r--r-- | src/scalarproduct/gnunet_scalarproduct.h | 2 |
3 files changed, 79 insertions, 106 deletions
diff --git a/src/scalarproduct/Makefile.am b/src/scalarproduct/Makefile.am index 33ddfcf60..33d7df571 100644 --- a/src/scalarproduct/Makefile.am +++ b/src/scalarproduct/Makefile.am | |||
@@ -38,7 +38,6 @@ gnunet_service_scalarproduct_SOURCES = \ | |||
38 | gnunet-service-scalarproduct.c | 38 | gnunet-service-scalarproduct.c |
39 | gnunet_service_scalarproduct_LDADD = \ | 39 | gnunet_service_scalarproduct_LDADD = \ |
40 | $(top_builddir)/src/util/libgnunetutil.la \ | 40 | $(top_builddir)/src/util/libgnunetutil.la \ |
41 | $(top_builddir)/src/core/libgnunetcore.la \ | ||
42 | $(top_builddir)/src/mesh/libgnunetmesh.la \ | 41 | $(top_builddir)/src/mesh/libgnunetmesh.la \ |
43 | $(top_builddir)/src/set/libgnunetset.la \ | 42 | $(top_builddir)/src/set/libgnunetset.la \ |
44 | -lgcrypt \ | 43 | -lgcrypt \ |
diff --git a/src/scalarproduct/gnunet-service-scalarproduct.c b/src/scalarproduct/gnunet-service-scalarproduct.c index 37b3dedf9..5f48ff056 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct.c +++ b/src/scalarproduct/gnunet-service-scalarproduct.c | |||
@@ -33,14 +33,22 @@ | |||
33 | #include "gnunet_scalarproduct_service.h" | 33 | #include "gnunet_scalarproduct_service.h" |
34 | #include "gnunet_scalarproduct.h" | 34 | #include "gnunet_scalarproduct.h" |
35 | 35 | ||
36 | |||
37 | #define LOG(kind,...) GNUNET_log_from (kind, "scalarproduct", __VA_ARGS__) | ||
38 | |||
39 | /** | ||
40 | * Log an error message at log-level 'level' that indicates | ||
41 | * a failure of the command 'cmd' with the message given | ||
42 | * by gcry_strerror(rc). | ||
43 | */ | ||
44 | #define LOG_GCRY(level, cmd, rc) do { LOG(level, _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, gcry_strerror(rc)); } while(0) | ||
45 | |||
46 | |||
47 | |||
36 | /////////////////////////////////////////////////////////////////////////////// | 48 | /////////////////////////////////////////////////////////////////////////////// |
37 | // Global Variables | 49 | // Global Variables |
38 | /////////////////////////////////////////////////////////////////////////////// | 50 | /////////////////////////////////////////////////////////////////////////////// |
39 | 51 | ||
40 | /** | ||
41 | * Handle to the core service (NULL until we've connected to it). | ||
42 | */ | ||
43 | static struct GNUNET_CORE_Handle *my_core; | ||
44 | 52 | ||
45 | /** | 53 | /** |
46 | * Handle to the core service (NULL until we've connected to it). | 54 | * Handle to the core service (NULL until we've connected to it). |
@@ -383,7 +391,9 @@ do_send_message (void *cls, size_t size, void *buf) | |||
383 | if (info->transmit_handle) | 391 | if (info->transmit_handle) |
384 | *info->transmit_handle = NULL; | 392 | *info->transmit_handle = NULL; |
385 | 393 | ||
386 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Sent a message of type %hu.\n"), ntohs (msg->type)); | 394 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
395 | "Sent a message of type %hu.\n", | ||
396 | ntohs (msg->type)); | ||
387 | GNUNET_free(msg); | 397 | GNUNET_free(msg); |
388 | GNUNET_free(info); | 398 | GNUNET_free(info); |
389 | return written; | 399 | return written; |
@@ -479,7 +489,7 @@ generate_random_vector (uint16_t length) | |||
479 | */ | 489 | */ |
480 | static struct ServiceSession * | 490 | static struct ServiceSession * |
481 | find_matching_session (struct ServiceSession * tail, | 491 | find_matching_session (struct ServiceSession * tail, |
482 | struct GNUNET_HashCode * key, | 492 | const struct GNUNET_HashCode * key, |
483 | uint16_t element_count, | 493 | uint16_t element_count, |
484 | enum SessionState * state, | 494 | enum SessionState * state, |
485 | const struct GNUNET_PeerIdentity * peerid) | 495 | const struct GNUNET_PeerIdentity * peerid) |
@@ -527,7 +537,7 @@ destroy_tunnel (void *cls, | |||
527 | static void | 537 | static void |
528 | free_session (struct ServiceSession * session) | 538 | free_session (struct ServiceSession * session) |
529 | { | 539 | { |
530 | int i; | 540 | unsigned int i; |
531 | 541 | ||
532 | if (FINALIZED != session->state) | 542 | if (FINALIZED != session->state) |
533 | { | 543 | { |
@@ -613,8 +623,6 @@ prepare_client_end_notification (void * cls, | |||
613 | struct GNUNET_SCALARPRODUCT_client_response * msg; | 623 | struct GNUNET_SCALARPRODUCT_client_response * msg; |
614 | struct MessageObject * msg_obj; | 624 | struct MessageObject * msg_obj; |
615 | 625 | ||
616 | GNUNET_assert (NULL != session); | ||
617 | |||
618 | msg = GNUNET_new (struct GNUNET_SCALARPRODUCT_client_response); | 626 | msg = GNUNET_new (struct GNUNET_SCALARPRODUCT_client_response); |
619 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SERVICE_TO_CLIENT); | 627 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SERVICE_TO_CLIENT); |
620 | memcpy (&msg->key, &session->key, sizeof (struct GNUNET_HashCode)); | 628 | memcpy (&msg->key, &session->key, sizeof (struct GNUNET_HashCode)); |
@@ -623,8 +631,8 @@ prepare_client_end_notification (void * cls, | |||
623 | // 0 size and the first char in the product is 0, which should never be zero if encoding is used. | 631 | // 0 size and the first char in the product is 0, which should never be zero if encoding is used. |
624 | msg->product_length = htonl (0); | 632 | msg->product_length = htonl (0); |
625 | 633 | ||
626 | msg_obj = GNUNET_malloc (sizeof (struct MessageObject)); | 634 | msg_obj = GNUNET_new (struct MessageObject); |
627 | msg_obj->msg = (struct GNUNET_MessageHeader *) msg; | 635 | msg_obj->msg = &msg->header; |
628 | msg_obj->transmit_handle = NULL; // do not reset the transmit handle, please | 636 | msg_obj->transmit_handle = NULL; // do not reset the transmit handle, please |
629 | 637 | ||
630 | //transmit this message to our client | 638 | //transmit this message to our client |
@@ -686,14 +694,11 @@ prepare_service_response (gcry_mpi_t * kp, | |||
686 | size_t element_length = 0; | 694 | size_t element_length = 0; |
687 | int i; | 695 | int i; |
688 | 696 | ||
689 | GNUNET_assert (request); | ||
690 | |||
691 | msg_length = sizeof (struct GNUNET_SCALARPRODUCT_service_response) | 697 | msg_length = sizeof (struct GNUNET_SCALARPRODUCT_service_response) |
692 | + 2 * request->used_element_count * PAILLIER_ELEMENT_LENGTH // kp, kq | 698 | + 2 * request->used_element_count * PAILLIER_ELEMENT_LENGTH // kp, kq |
693 | + 2 * PAILLIER_ELEMENT_LENGTH; // s, stick | 699 | + 2 * PAILLIER_ELEMENT_LENGTH; // s, stick |
694 | 700 | ||
695 | msg = GNUNET_malloc (msg_length); | 701 | msg = GNUNET_malloc (msg_length); |
696 | GNUNET_assert (msg); | ||
697 | 702 | ||
698 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_TO_ALICE); | 703 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_TO_ALICE); |
699 | msg->header.size = htons (msg_length); | 704 | msg->header.size = htons (msg_length); |
@@ -838,7 +843,6 @@ compute_service_response (struct ServiceSession * request, | |||
838 | gcry_sexp_t tmp_exp; | 843 | gcry_sexp_t tmp_exp; |
839 | uint32_t value; | 844 | uint32_t value; |
840 | 845 | ||
841 | GNUNET_assert (request != NULL && response != NULL); | ||
842 | count = request->used_element_count; | 846 | count = request->used_element_count; |
843 | 847 | ||
844 | b = GNUNET_malloc (sizeof (gcry_mpi_t) * count); | 848 | b = GNUNET_malloc (sizeof (gcry_mpi_t) * count); |
@@ -990,7 +994,8 @@ compute_service_response (struct ServiceSession * request, | |||
990 | 994 | ||
991 | // copy the Kp[], Kq[], S and Stick into a new message | 995 | // copy the Kp[], Kq[], S and Stick into a new message |
992 | if (GNUNET_YES != prepare_service_response (kp, kq, s, stick, request, response)) | 996 | if (GNUNET_YES != prepare_service_response (kp, kq, s, stick, request, response)) |
993 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Computation of values for alice failed!\n")); | 997 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Failed to communicate with `%s', scalar product calculation aborted.\n"), |
998 | GNUNET_i2s (&request->peer)); | ||
994 | else | 999 | else |
995 | ret = GNUNET_OK; | 1000 | ret = GNUNET_OK; |
996 | 1001 | ||
@@ -1022,9 +1027,9 @@ except: | |||
1022 | * Executed by Alice, fills in a service-request message and sends it to the given peer | 1027 | * Executed by Alice, fills in a service-request message and sends it to the given peer |
1023 | * | 1028 | * |
1024 | * @param session the session associated with this request, then also holds the CORE-handle | 1029 | * @param session the session associated with this request, then also holds the CORE-handle |
1025 | * @return GNUNET_SYSERR if we could not send the message | 1030 | * @return #GNUNET_SYSERR if we could not send the message |
1026 | * GNUNET_NO if the message was too large | 1031 | * #GNUNET_NO if the message was too large |
1027 | * GNUNET_OK if we sent it | 1032 | * #GNUNET_OK if we sent it |
1028 | */ | 1033 | */ |
1029 | static void | 1034 | static void |
1030 | prepare_service_request (void *cls, | 1035 | prepare_service_request (void *cls, |
@@ -1128,7 +1133,7 @@ prepare_service_request (void *cls, | |||
1128 | gcry_mpi_release (a); | 1133 | gcry_mpi_release (a); |
1129 | gcry_mpi_release (r); | 1134 | gcry_mpi_release (r); |
1130 | 1135 | ||
1131 | msg_obj = GNUNET_malloc (sizeof (struct MessageObject)); | 1136 | msg_obj = GNUNET_new (struct MessageObject); |
1132 | msg_obj->msg = (struct GNUNET_MessageHeader *) msg; | 1137 | msg_obj->msg = (struct GNUNET_MessageHeader *) msg; |
1133 | msg_obj->transmit_handle = (void *) &session->service_transmit_handle; //and reset the transmit handle | 1138 | msg_obj->transmit_handle = (void *) &session->service_transmit_handle; //and reset the transmit handle |
1134 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Transmitting service request.\n")); | 1139 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Transmitting service request.\n")); |
@@ -1158,9 +1163,9 @@ prepare_service_request (void *cls, | |||
1158 | /** | 1163 | /** |
1159 | * Method called whenever a peer has disconnected from the tunnel. | 1164 | * Method called whenever a peer has disconnected from the tunnel. |
1160 | * Implementations of this callback must NOT call | 1165 | * Implementations of this callback must NOT call |
1161 | * GNUNET_MESH_tunnel_destroy immediately, but instead schedule those | 1166 | * #GNUNET_MESH_tunnel_destroy immediately, but instead schedule those |
1162 | * to run in some other task later. However, calling | 1167 | * to run in some other task later. However, calling |
1163 | * "GNUNET_MESH_notify_transmit_ready_cancel" is allowed. | 1168 | * #GNUNET_MESH_notify_transmit_ready_cancel is allowed. |
1164 | * | 1169 | * |
1165 | * @param cls closure | 1170 | * @param cls closure |
1166 | * @param peer peer identity the tunnel stopped working with | 1171 | * @param peer peer identity the tunnel stopped working with |
@@ -1171,8 +1176,10 @@ tunnel_peer_disconnect_handler (void *cls, const struct GNUNET_PeerIdentity * pe | |||
1171 | // as we have only one peer connected in each session, just remove the session and say good bye | 1176 | // as we have only one peer connected in each session, just remove the session and say good bye |
1172 | struct ServiceSession * session = cls; | 1177 | struct ServiceSession * session = cls; |
1173 | struct ServiceSession * curr; | 1178 | struct ServiceSession * curr; |
1174 | GNUNET_assert(cls); | 1179 | |
1175 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Peer (%s) disconnected from our tunnel!\n"), GNUNET_i2s (peer)); | 1180 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1181 | "Peer (%s) disconnected from our tunnel!\n", | ||
1182 | GNUNET_i2s (peer)); | ||
1176 | 1183 | ||
1177 | if ((session->role == ALICE) && (FINALIZED != session->state) && ( ! do_shutdown)) | 1184 | if ((session->role == ALICE) && (FINALIZED != session->state) && ( ! do_shutdown)) |
1178 | { | 1185 | { |
@@ -1182,12 +1189,12 @@ tunnel_peer_disconnect_handler (void *cls, const struct GNUNET_PeerIdentity * pe | |||
1182 | GNUNET_CONTAINER_DLL_remove (from_client_head, from_client_tail, session); | 1189 | GNUNET_CONTAINER_DLL_remove (from_client_head, from_client_tail, session); |
1183 | break; | 1190 | break; |
1184 | } | 1191 | } |
1192 | // FIXME: dangling tasks, code duplication, use-after-free, fun... | ||
1185 | GNUNET_SCHEDULER_add_now (&destroy_tunnel, | 1193 | GNUNET_SCHEDULER_add_now (&destroy_tunnel, |
1186 | session); | 1194 | session); |
1187 | // if this happened before we received the answer, we must terminate the session | 1195 | // if this happened before we received the answer, we must terminate the session |
1188 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 1196 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
1189 | &prepare_client_end_notification, | 1197 | session); |
1190 | session); | ||
1191 | } | 1198 | } |
1192 | } | 1199 | } |
1193 | 1200 | ||
@@ -1207,7 +1214,7 @@ handle_client_request (void *cls, | |||
1207 | struct GNUNET_SERVER_Client *client, | 1214 | struct GNUNET_SERVER_Client *client, |
1208 | const struct GNUNET_MessageHeader *message) | 1215 | const struct GNUNET_MessageHeader *message) |
1209 | { | 1216 | { |
1210 | struct GNUNET_SCALARPRODUCT_client_request * msg = (struct GNUNET_SCALARPRODUCT_client_request *) message; | 1217 | const struct GNUNET_SCALARPRODUCT_client_request * msg = (const struct GNUNET_SCALARPRODUCT_client_request *) message; |
1211 | struct ServiceSession * session; | 1218 | struct ServiceSession * session; |
1212 | uint16_t element_count; | 1219 | uint16_t element_count; |
1213 | uint16_t mask_length; | 1220 | uint16_t mask_length; |
@@ -1220,7 +1227,8 @@ handle_client_request (void *cls, | |||
1220 | //we need at least a peer and one message id to compare | 1227 | //we need at least a peer and one message id to compare |
1221 | if (sizeof (struct GNUNET_SCALARPRODUCT_client_request) > ntohs (msg->header.size)) | 1228 | if (sizeof (struct GNUNET_SCALARPRODUCT_client_request) > ntohs (msg->header.size)) |
1222 | { | 1229 | { |
1223 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ ("Too short message received from client!\n")); | 1230 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1231 | _ ("Too short message received from client!\n")); | ||
1224 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1232 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1225 | return; | 1233 | return; |
1226 | } | 1234 | } |
@@ -1233,7 +1241,8 @@ handle_client_request (void *cls, | |||
1233 | if (( ntohs (msg->header.size) != (sizeof (struct GNUNET_SCALARPRODUCT_client_request) + element_count * sizeof (int32_t) + mask_length)) | 1241 | if (( ntohs (msg->header.size) != (sizeof (struct GNUNET_SCALARPRODUCT_client_request) + element_count * sizeof (int32_t) + mask_length)) |
1234 | || (0 == element_count)) | 1242 | || (0 == element_count)) |
1235 | { | 1243 | { |
1236 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ ("Invalid message received from client, session information incorrect!\n")); | 1244 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1245 | _ ("Invalid message received from client, session information incorrect!\n")); | ||
1237 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1246 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1238 | return; | 1247 | return; |
1239 | } | 1248 | } |
@@ -1249,7 +1258,7 @@ handle_client_request (void *cls, | |||
1249 | return; | 1258 | return; |
1250 | } | 1259 | } |
1251 | 1260 | ||
1252 | session = GNUNET_malloc (sizeof (struct ServiceSession)); | 1261 | session = GNUNET_new (struct ServiceSession); |
1253 | session->client = client; | 1262 | session->client = client; |
1254 | session->element_count = element_count; | 1263 | session->element_count = element_count; |
1255 | session->mask_length = mask_length; | 1264 | session->mask_length = mask_length; |
@@ -1387,7 +1396,7 @@ tunnel_incoming_handler (void *cls, struct GNUNET_MESH_Tunnel *tunnel, | |||
1387 | * Function called whenever an inbound tunnel is destroyed. Should clean up | 1396 | * Function called whenever an inbound tunnel is destroyed. Should clean up |
1388 | * any associated state. | 1397 | * any associated state. |
1389 | * | 1398 | * |
1390 | * @param cls closure (set from GNUNET_MESH_connect) | 1399 | * @param cls closure (set from #GNUNET_MESH_connect) |
1391 | * @param tunnel connection to the other end (henceforth invalid) | 1400 | * @param tunnel connection to the other end (henceforth invalid) |
1392 | * @param tunnel_ctx place where local state associated | 1401 | * @param tunnel_ctx place where local state associated |
1393 | * with the tunnel is stored (our 'struct TunnelState') | 1402 | * with the tunnel is stored (our 'struct TunnelState') |
@@ -1543,11 +1552,9 @@ prepare_client_response (void *cls, | |||
1543 | uint16_t msg_length = 0; | 1552 | uint16_t msg_length = 0; |
1544 | struct MessageObject * msg_obj; | 1553 | struct MessageObject * msg_obj; |
1545 | 1554 | ||
1546 | GNUNET_assert (session); | ||
1547 | |||
1548 | if (session->product) | 1555 | if (session->product) |
1549 | { | 1556 | { |
1550 | // get representation as string | 1557 | // get representation as string // FIXME: just log (& survive!) |
1551 | GNUNET_assert ( ! gcry_mpi_aprint (GCRYMPI_FMT_USG, | 1558 | GNUNET_assert ( ! gcry_mpi_aprint (GCRYMPI_FMT_USG, |
1552 | &product_exported, | 1559 | &product_exported, |
1553 | &product_length, | 1560 | &product_length, |
@@ -1556,7 +1563,7 @@ prepare_client_response (void *cls, | |||
1556 | session->product = NULL; | 1563 | session->product = NULL; |
1557 | } | 1564 | } |
1558 | 1565 | ||
1559 | msg_length = sizeof (struct GNUNET_SCALARPRODUCT_client_response) +product_length; | 1566 | msg_length = sizeof (struct GNUNET_SCALARPRODUCT_client_response) + product_length; |
1560 | msg = GNUNET_malloc (msg_length); | 1567 | msg = GNUNET_malloc (msg_length); |
1561 | memcpy (&msg[1], product_exported, product_length); | 1568 | memcpy (&msg[1], product_exported, product_length); |
1562 | GNUNET_free_non_null (product_exported); | 1569 | GNUNET_free_non_null (product_exported); |
@@ -1566,13 +1573,13 @@ prepare_client_response (void *cls, | |||
1566 | memcpy (&msg->peer, &session->peer, sizeof ( struct GNUNET_PeerIdentity)); | 1573 | memcpy (&msg->peer, &session->peer, sizeof ( struct GNUNET_PeerIdentity)); |
1567 | msg->product_length = htonl (product_length); | 1574 | msg->product_length = htonl (product_length); |
1568 | 1575 | ||
1569 | msg_obj = GNUNET_malloc (sizeof (struct MessageObject)); | 1576 | msg_obj = GNUNET_new (struct MessageObject); |
1570 | msg_obj->msg = (struct GNUNET_MessageHeader *) msg; | 1577 | msg_obj->msg = (struct GNUNET_MessageHeader *) msg; |
1571 | msg_obj->transmit_handle = NULL; // don't reset the transmit handle | 1578 | msg_obj->transmit_handle = NULL; // don't reset the transmit handle |
1572 | 1579 | ||
1573 | //transmit this message to our client | 1580 | //transmit this message to our client |
1574 | session->client_transmit_handle = | 1581 | session->client_transmit_handle = |
1575 | GNUNET_SERVER_notify_transmit_ready (session->client, | 1582 | GNUNET_SERVER_notify_transmit_ready (session->client, // FIXME: use after free possibility during shutdown |
1576 | msg_length, | 1583 | msg_length, |
1577 | GNUNET_TIME_UNIT_FOREVER_REL, | 1584 | GNUNET_TIME_UNIT_FOREVER_REL, |
1578 | &do_send_message, | 1585 | &do_send_message, |
@@ -1595,14 +1602,14 @@ prepare_client_response (void *cls, | |||
1595 | /** | 1602 | /** |
1596 | * Handle a request from another service to calculate a scalarproduct with us. | 1603 | * Handle a request from another service to calculate a scalarproduct with us. |
1597 | * | 1604 | * |
1598 | * @param cls closure (set from GNUNET_MESH_connect) | 1605 | * @param cls closure (set from #GNUNET_MESH_connect) |
1599 | * @param tunnel connection to the other end | 1606 | * @param tunnel connection to the other end |
1600 | * @param tunnel_ctx place to store local state associated with the tunnel | 1607 | * @param tunnel_ctx place to store local state associated with the tunnel |
1601 | * @param sender who sent the message | 1608 | * @param sender who sent the message |
1602 | * @param message the actual message | 1609 | * @param message the actual message |
1603 | * @param atsi performance data for the connection | 1610 | * @param atsi performance data for the connection |
1604 | * @return GNUNET_OK to keep the connection open, | 1611 | * @return #GNUNET_OK to keep the connection open, |
1605 | * GNUNET_SYSERR to close it (signal serious error) | 1612 | * #GNUNET_SYSERR to close it (signal serious error) |
1606 | */ | 1613 | */ |
1607 | static int | 1614 | static int |
1608 | handle_service_request (void *cls, | 1615 | handle_service_request (void *cls, |
@@ -1613,7 +1620,7 @@ handle_service_request (void *cls, | |||
1613 | const struct GNUNET_ATS_Information * atsi) | 1620 | const struct GNUNET_ATS_Information * atsi) |
1614 | { | 1621 | { |
1615 | struct ServiceSession * session; | 1622 | struct ServiceSession * session; |
1616 | struct GNUNET_SCALARPRODUCT_service_request * msg = (struct GNUNET_SCALARPRODUCT_service_request *) message; | 1623 | const struct GNUNET_SCALARPRODUCT_service_request * msg = (const struct GNUNET_SCALARPRODUCT_service_request *) message; |
1617 | uint16_t mask_length; | 1624 | uint16_t mask_length; |
1618 | uint16_t pk_length; | 1625 | uint16_t pk_length; |
1619 | uint16_t used_elements; | 1626 | uint16_t used_elements; |
@@ -1624,9 +1631,6 @@ handle_service_request (void *cls, | |||
1624 | int32_t i = -1; | 1631 | int32_t i = -1; |
1625 | enum SessionState needed_state; | 1632 | enum SessionState needed_state; |
1626 | 1633 | ||
1627 | GNUNET_assert (NULL != message); | ||
1628 | GNUNET_assert (NULL != sender); | ||
1629 | GNUNET_assert (NULL != tunnel_ctx); | ||
1630 | session = (struct ServiceSession *) * tunnel_ctx; | 1634 | session = (struct ServiceSession *) * tunnel_ctx; |
1631 | // is this tunnel already in use? | 1635 | // is this tunnel already in use? |
1632 | if ( (session->next) || (from_service_head == session)) | 1636 | if ( (session->next) || (from_service_head == session)) |
@@ -1790,14 +1794,14 @@ except: | |||
1790 | /** | 1794 | /** |
1791 | * Handle a response we got from another service we wanted to calculate a scalarproduct with. | 1795 | * Handle a response we got from another service we wanted to calculate a scalarproduct with. |
1792 | * | 1796 | * |
1793 | * @param cls closure (set from GNUNET_MESH_connect) | 1797 | * @param cls closure (set from #GNUNET_MESH_connect) |
1794 | * @param tunnel connection to the other end | 1798 | * @param tunnel connection to the other end |
1795 | * @param tunnel_ctx place to store local state associated with the tunnel | 1799 | * @param tunnel_ctx place to store local state associated with the tunnel |
1796 | * @param sender who sent the message | 1800 | * @param sender who sent the message |
1797 | * @param message the actual message | 1801 | * @param message the actual message |
1798 | * @param atsi performance data for the connection | 1802 | * @param atsi performance data for the connection |
1799 | * @return GNUNET_OK to keep the connection open, | 1803 | * @return #GNUNET_OK to keep the connection open, |
1800 | * GNUNET_SYSERR to close it (signal serious error) | 1804 | * #GNUNET_SYSERR to close it (signal serious error) |
1801 | */ | 1805 | */ |
1802 | static int | 1806 | static int |
1803 | handle_service_response (void *cls, | 1807 | handle_service_response (void *cls, |
@@ -1820,6 +1824,7 @@ handle_service_response (void *cls, | |||
1820 | size_t msg_size; | 1824 | size_t msg_size; |
1821 | gcry_mpi_t * kp = NULL; | 1825 | gcry_mpi_t * kp = NULL; |
1822 | gcry_mpi_t * kq = NULL; | 1826 | gcry_mpi_t * kq = NULL; |
1827 | int rc; | ||
1823 | 1828 | ||
1824 | GNUNET_assert (NULL != message); | 1829 | GNUNET_assert (NULL != message); |
1825 | GNUNET_assert (NULL != sender); | 1830 | GNUNET_assert (NULL != sender); |
@@ -1837,7 +1842,7 @@ handle_service_response (void *cls, | |||
1837 | //we need at least a peer and one message id to compare | 1842 | //we need at least a peer and one message id to compare |
1838 | if (sizeof (struct GNUNET_SCALARPRODUCT_service_response) > ntohs (msg->header.size)) | 1843 | if (sizeof (struct GNUNET_SCALARPRODUCT_service_response) > ntohs (msg->header.size)) |
1839 | { | 1844 | { |
1840 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ ("Too short message received from peer!\n")); | 1845 | GNUNET_break_op (0); |
1841 | goto invalid_msg; | 1846 | goto invalid_msg; |
1842 | } | 1847 | } |
1843 | used_element_count = ntohs (msg->used_element_count); | 1848 | used_element_count = ntohs (msg->used_element_count); |
@@ -1847,29 +1852,26 @@ handle_service_response (void *cls, | |||
1847 | //sanity check: is the message as long as the message_count fields suggests? | 1852 | //sanity check: is the message as long as the message_count fields suggests? |
1848 | if ((ntohs (msg->header.size) != msg_size) || (count != used_element_count)) | 1853 | if ((ntohs (msg->header.size) != msg_size) || (count != used_element_count)) |
1849 | { | 1854 | { |
1850 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ ("Invalid message received from peer!\n")); | 1855 | GNUNET_break_op (0); |
1851 | goto invalid_msg; | ||
1852 | } | ||
1853 | if (GNUNET_SERVER_MAX_MESSAGE_SIZE < msg_size) | ||
1854 | { | ||
1855 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ ("Message too large, fragmentation is currently not supported!\n")); | ||
1856 | goto invalid_msg; | 1856 | goto invalid_msg; |
1857 | } | 1857 | } |
1858 | 1858 | ||
1859 | //convert s | 1859 | //convert s |
1860 | current = (unsigned char *) &msg[1]; | 1860 | current = (unsigned char *) &msg[1]; |
1861 | if (gcry_mpi_scan (&s, GCRYMPI_FMT_USG, current, | 1861 | if (0 != (rc = gcry_mpi_scan (&s, GCRYMPI_FMT_USG, current, |
1862 | PAILLIER_ELEMENT_LENGTH, &read)) | 1862 | PAILLIER_ELEMENT_LENGTH, &read))) |
1863 | { | 1863 | { |
1864 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ ("Could not translate s to an MPI value!\n")); | 1864 | LOG_GCRY (GNUNET_ERROR_TYPE_DEBUG, "gcry_mpi_scan", rc); |
1865 | GNUNET_break_op (0); | ||
1865 | goto invalid_msg; | 1866 | goto invalid_msg; |
1866 | } | 1867 | } |
1867 | current += PAILLIER_ELEMENT_LENGTH; | 1868 | current += PAILLIER_ELEMENT_LENGTH; |
1868 | //convert stick | 1869 | //convert stick |
1869 | if (gcry_mpi_scan (&stick, GCRYMPI_FMT_USG, current, | 1870 | if (0 != (rc = gcry_mpi_scan (&stick, GCRYMPI_FMT_USG, current, |
1870 | PAILLIER_ELEMENT_LENGTH, &read)) | 1871 | PAILLIER_ELEMENT_LENGTH, &read))) |
1871 | { | 1872 | { |
1872 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ ("Could not translate s' to an MPI value!\n")); | 1873 | LOG_GCRY (GNUNET_ERROR_TYPE_DEBUG, "gcry_mpi_scan", rc); |
1874 | GNUNET_break_op (0); | ||
1873 | goto invalid_msg; | 1875 | goto invalid_msg; |
1874 | } | 1876 | } |
1875 | current += PAILLIER_ELEMENT_LENGTH; | 1877 | current += PAILLIER_ELEMENT_LENGTH; |
@@ -1878,24 +1880,26 @@ handle_service_response (void *cls, | |||
1878 | // Convert each kp[] to its MPI_value | 1880 | // Convert each kp[] to its MPI_value |
1879 | for (i = 0; i < count; i++) | 1881 | for (i = 0; i < count; i++) |
1880 | { | 1882 | { |
1881 | if (gcry_mpi_scan (&kp[i], GCRYMPI_FMT_USG, current, | 1883 | if (0 != (rc = gcry_mpi_scan (&kp[i], GCRYMPI_FMT_USG, current, |
1882 | PAILLIER_ELEMENT_LENGTH, &read)) | 1884 | PAILLIER_ELEMENT_LENGTH, &read))) |
1883 | { | 1885 | { |
1884 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ ("Could not translate Kp[%d]to an MPI value!\n"), i); | 1886 | LOG_GCRY (GNUNET_ERROR_TYPE_DEBUG, "gcry_mpi_scan", rc); |
1887 | GNUNET_break_op (0); | ||
1885 | goto invalid_msg; | 1888 | goto invalid_msg; |
1886 | } | 1889 | } |
1887 | current += PAILLIER_ELEMENT_LENGTH; | 1890 | current += PAILLIER_ELEMENT_LENGTH; |
1888 | } | 1891 | } |
1889 | 1892 | ||
1890 | 1893 | ||
1891 | kq = GNUNET_malloc (sizeof (gcry_mpi_t) * count); | 1894 | kq = GNUNET_malloc (sizeof (gcry_mpi_t) * count); |
1892 | // Convert each kq[] to its MPI_value | 1895 | // Convert each kq[] to its MPI_value |
1893 | for (i = 0; i < count; i++) | 1896 | for (i = 0; i < count; i++) |
1894 | { | 1897 | { |
1895 | if (gcry_mpi_scan (&kq[i], GCRYMPI_FMT_USG, current, | 1898 | if (0 != (rc = gcry_mpi_scan (&kq[i], GCRYMPI_FMT_USG, current, |
1896 | PAILLIER_ELEMENT_LENGTH, &read)) | 1899 | PAILLIER_ELEMENT_LENGTH, &read))) |
1897 | { | 1900 | { |
1898 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ ("Could not translate Kq[%d]to an MPI value!\n"), i); | 1901 | LOG_GCRY (GNUNET_ERROR_TYPE_DEBUG, "gcry_mpi_scan", rc); |
1902 | GNUNET_break_op (0); | ||
1899 | goto invalid_msg; | 1903 | goto invalid_msg; |
1900 | } | 1904 | } |
1901 | current += PAILLIER_ELEMENT_LENGTH; | 1905 | current += PAILLIER_ELEMENT_LENGTH; |
@@ -1919,10 +1923,9 @@ invalid_msg: | |||
1919 | // the tunnel has done its job, terminate our connection and the tunnel | 1923 | // the tunnel has done its job, terminate our connection and the tunnel |
1920 | // the peer will be notified that the tunnel was destroyed via tunnel_destruction_handler | 1924 | // the peer will be notified that the tunnel was destroyed via tunnel_destruction_handler |
1921 | GNUNET_CONTAINER_DLL_remove (from_client_head, from_client_tail, session); | 1925 | GNUNET_CONTAINER_DLL_remove (from_client_head, from_client_tail, session); |
1922 | GNUNET_SCHEDULER_add_now (&destroy_tunnel, session); | 1926 | GNUNET_SCHEDULER_add_now (&destroy_tunnel, session); // FIXME: use after free! |
1923 | // send message with product to client | 1927 | // send message with product to client |
1924 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 1928 | /* session->current_task = */ GNUNET_SCHEDULER_add_now (&prepare_client_response, session); // FIXME: dangling task! |
1925 | &prepare_client_response, session); | ||
1926 | return GNUNET_OK; | 1929 | return GNUNET_OK; |
1927 | // if success: terminate the session gracefully, else terminate with error | 1930 | // if success: terminate the session gracefully, else terminate with error |
1928 | } | 1931 | } |
@@ -1953,13 +1956,6 @@ shutdown_task (void *cls, | |||
1953 | curr->state = FINALIZED; | 1956 | curr->state = FINALIZED; |
1954 | } | 1957 | } |
1955 | } | 1958 | } |
1956 | |||
1957 | if (my_core) | ||
1958 | { | ||
1959 | GNUNET_CORE_disconnect (my_core); | ||
1960 | my_core = NULL; | ||
1961 | } | ||
1962 | |||
1963 | if (my_mesh) | 1959 | if (my_mesh) |
1964 | { | 1960 | { |
1965 | GNUNET_MESH_disconnect (my_mesh); | 1961 | GNUNET_MESH_disconnect (my_mesh); |
@@ -1969,22 +1965,6 @@ shutdown_task (void *cls, | |||
1969 | 1965 | ||
1970 | 1966 | ||
1971 | /** | 1967 | /** |
1972 | * To be called on core init/fail. | ||
1973 | * | ||
1974 | * @param cls closure, NULL | ||
1975 | * @param server handle to the server for this service | ||
1976 | * @param my_identity the public identity of this peer | ||
1977 | */ | ||
1978 | static void | ||
1979 | core_init (void *cls, struct GNUNET_CORE_Handle *server, | ||
1980 | const struct GNUNET_PeerIdentity *my_identity) | ||
1981 | { | ||
1982 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Core initialized\n")); | ||
1983 | me = *my_identity; | ||
1984 | } | ||
1985 | |||
1986 | |||
1987 | /** | ||
1988 | * Initialization of the program and message handlers | 1968 | * Initialization of the program and message handlers |
1989 | * | 1969 | * |
1990 | * @param cls closure | 1970 | * @param cls closure |
@@ -2006,9 +1986,6 @@ run (void *cls, | |||
2006 | { &handle_service_response, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_TO_ALICE, 0}, | 1986 | { &handle_service_response, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_TO_ALICE, 0}, |
2007 | {NULL, 0, 0} | 1987 | {NULL, 0, 0} |
2008 | }; | 1988 | }; |
2009 | static const struct GNUNET_CORE_MessageHandler core_handlers[] = { | ||
2010 | {NULL, 0, 0} | ||
2011 | }; | ||
2012 | static GNUNET_MESH_ApplicationType mesh_types[] = { | 1989 | static GNUNET_MESH_ApplicationType mesh_types[] = { |
2013 | GNUNET_APPLICATION_TYPE_SCALARPRODUCT, | 1990 | GNUNET_APPLICATION_TYPE_SCALARPRODUCT, |
2014 | GNUNET_APPLICATION_TYPE_END | 1991 | GNUNET_APPLICATION_TYPE_END |
@@ -2022,14 +1999,9 @@ run (void *cls, | |||
2022 | GNUNET_SERVER_disconnect_notify (server, | 1999 | GNUNET_SERVER_disconnect_notify (server, |
2023 | &handle_client_disconnect, | 2000 | &handle_client_disconnect, |
2024 | NULL); | 2001 | NULL); |
2025 | 2002 | GNUNET_break (GNUNET_OK == | |
2026 | my_core = GNUNET_CORE_connect (c, NULL, &core_init, NULL, NULL, NULL, | 2003 | GNUNET_CRYPTO_get_host_identity (c, |
2027 | GNUNET_NO, NULL, GNUNET_NO, core_handlers); | 2004 | &me)); |
2028 | if (!my_core) | ||
2029 | { | ||
2030 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Connect to CORE failed\n")); | ||
2031 | return; | ||
2032 | } | ||
2033 | my_mesh = GNUNET_MESH_connect (c, NULL, | 2005 | my_mesh = GNUNET_MESH_connect (c, NULL, |
2034 | &tunnel_incoming_handler, | 2006 | &tunnel_incoming_handler, |
2035 | &tunnel_destruction_handler, | 2007 | &tunnel_destruction_handler, |
diff --git a/src/scalarproduct/gnunet_scalarproduct.h b/src/scalarproduct/gnunet_scalarproduct.h index c661544e7..fc4e718b3 100644 --- a/src/scalarproduct/gnunet_scalarproduct.h +++ b/src/scalarproduct/gnunet_scalarproduct.h | |||
@@ -147,6 +147,8 @@ enum PeerRole | |||
147 | ALICE, | 147 | ALICE, |
148 | BOB | 148 | BOB |
149 | }; | 149 | }; |
150 | |||
151 | |||
150 | /** | 152 | /** |
151 | * A scalarproduct session which tracks: | 153 | * A scalarproduct session which tracks: |
152 | * | 154 | * |