diff options
Diffstat (limited to 'src/scalarproduct')
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct.c | 42 |
1 files changed, 18 insertions, 24 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct.c b/src/scalarproduct/gnunet-service-scalarproduct.c index f9024ed34..8656de3b3 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct.c +++ b/src/scalarproduct/gnunet-service-scalarproduct.c | |||
@@ -50,6 +50,7 @@ enum SessionState | |||
50 | WAITING_FOR_SERVICE_REQUEST, | 50 | WAITING_FOR_SERVICE_REQUEST, |
51 | WAITING_FOR_SERVICE_RESPONSE, | 51 | WAITING_FOR_SERVICE_RESPONSE, |
52 | SERVICE_REQUEST_RECEIVED, | 52 | SERVICE_REQUEST_RECEIVED, |
53 | SERVICE_RESPONSE_RECEIVED, | ||
53 | FINALIZED | 54 | FINALIZED |
54 | }; | 55 | }; |
55 | 56 | ||
@@ -740,8 +741,7 @@ prepare_client_end_notification (void * cls, | |||
740 | // 0 size and the first char in the product is 0, which should never be zero if encoding is used. | 741 | // 0 size and the first char in the product is 0, which should never be zero if encoding is used. |
741 | msg->product_length = htonl (0); | 742 | msg->product_length = htonl (0); |
742 | msg->range = 1; | 743 | msg->range = 1; |
743 | session->state = FINALIZED; | 744 | |
744 | |||
745 | session->msg = &msg->header; | 745 | session->msg = &msg->header; |
746 | 746 | ||
747 | //transmit this message to our client | 747 | //transmit this message to our client |
@@ -753,11 +753,11 @@ prepare_client_end_notification (void * cls, | |||
753 | session); | 753 | session); |
754 | 754 | ||
755 | // if we could not even queue our request, something is wrong | 755 | // if we could not even queue our request, something is wrong |
756 | if ( ! session->client_transmit_handle) | 756 | if ( NULL == session->client_transmit_handle) |
757 | { | 757 | { |
758 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ ("Could not send message to client (%p)! This is OK if it was disconnected beforehand already.\n"), session->client); | 758 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ ("Could not send message to client (%p)!\n"), session->client); |
759 | // usually gets freed by do_send_message | 759 | // usually gets freed by do_send_message |
760 | GNUNET_free (msg_obj); | 760 | session->msg = NULL; |
761 | GNUNET_free (msg); | 761 | GNUNET_free (msg); |
762 | } | 762 | } |
763 | else | 763 | else |
@@ -1262,7 +1262,7 @@ handle_client_request (void *cls, | |||
1262 | uint32_t i; | 1262 | uint32_t i; |
1263 | 1263 | ||
1264 | // only one concurrent session per client connection allowed, simplifies logics a lot... | 1264 | // only one concurrent session per client connection allowed, simplifies logics a lot... |
1265 | GNUNET_SERVER_client_get_user_context (client, session); | 1265 | session = GNUNET_SERVER_client_get_user_context (client, struct ServiceSession); |
1266 | if ((NULL != session) && (session->state != FINALIZED)){ | 1266 | if ((NULL != session) && (session->state != FINALIZED)){ |
1267 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1267 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1268 | return; | 1268 | return; |
@@ -1630,7 +1630,6 @@ prepare_client_response (void *cls, | |||
1630 | unsigned char * product_exported = NULL; | 1630 | unsigned char * product_exported = NULL; |
1631 | size_t product_length = 0; | 1631 | size_t product_length = 0; |
1632 | uint16_t msg_length = 0; | 1632 | uint16_t msg_length = 0; |
1633 | struct MessageObject * msg_obj; | ||
1634 | int8_t range = -1; | 1633 | int8_t range = -1; |
1635 | gcry_error_t rc; | 1634 | gcry_error_t rc; |
1636 | int sign; | 1635 | int sign; |
@@ -1683,26 +1682,23 @@ prepare_client_response (void *cls, | |||
1683 | memcpy (&msg->peer, &session->peer, sizeof ( struct GNUNET_PeerIdentity)); | 1682 | memcpy (&msg->peer, &session->peer, sizeof ( struct GNUNET_PeerIdentity)); |
1684 | msg->product_length = htonl (product_length); | 1683 | msg->product_length = htonl (product_length); |
1685 | 1684 | ||
1686 | msg_obj = GNUNET_new (struct MessageObject); | 1685 | session->msg = (struct GNUNET_MessageHeader *) msg; |
1687 | msg_obj->msg = (struct GNUNET_MessageHeader *) msg; | ||
1688 | msg_obj->transmit_handle = NULL; // don't reset the transmit handle | ||
1689 | |||
1690 | //transmit this message to our client | 1686 | //transmit this message to our client |
1691 | session->client_transmit_handle = | 1687 | session->client_transmit_handle = |
1692 | GNUNET_SERVER_notify_transmit_ready (session->client, | 1688 | GNUNET_SERVER_notify_transmit_ready (session->client, |
1693 | msg_length, | 1689 | msg_length, |
1694 | GNUNET_TIME_UNIT_FOREVER_REL, | 1690 | GNUNET_TIME_UNIT_FOREVER_REL, |
1695 | &do_send_message, | 1691 | &do_send_message, |
1696 | msg_obj); | 1692 | session); |
1697 | if ( ! session->client_transmit_handle) | 1693 | if ( NULL == session->client_transmit_handle) |
1698 | { | 1694 | { |
1699 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1695 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1700 | _ ("Could not send message to client (%p)! This probably is OK if the client disconnected before us.\n"), | 1696 | _ ("Could not send message to client (%p)!\n"), |
1701 | session->client); | 1697 | session->client); |
1702 | session->client = NULL; | 1698 | session->client = NULL; |
1703 | // callback was not called! | 1699 | // callback was not called! |
1704 | GNUNET_free (msg_obj); | ||
1705 | GNUNET_free (msg); | 1700 | GNUNET_free (msg); |
1701 | session->msg = NULL; | ||
1706 | } | 1702 | } |
1707 | else | 1703 | else |
1708 | // gracefully sent message, just terminate session structure | 1704 | // gracefully sent message, just terminate session structure |
@@ -1937,6 +1933,7 @@ handle_service_response (void *cls, | |||
1937 | 1933 | ||
1938 | count = session->used_element_count; | 1934 | count = session->used_element_count; |
1939 | session->product = NULL; | 1935 | session->product = NULL; |
1936 | session->state = SERVICE_RESPONSE_RECEIVED; | ||
1940 | 1937 | ||
1941 | //we need at least a peer and one message id to compare | 1938 | //we need at least a peer and one message id to compare |
1942 | if (sizeof (struct GNUNET_SCALARPRODUCT_service_response) > ntohs (msg->header.size)) | 1939 | if (sizeof (struct GNUNET_SCALARPRODUCT_service_response) > ntohs (msg->header.size)) |
@@ -1983,7 +1980,7 @@ handle_service_response (void *cls, | |||
1983 | PAILLIER_ELEMENT_LENGTH, &read))) | 1980 | PAILLIER_ELEMENT_LENGTH, &read))) |
1984 | { | 1981 | { |
1985 | LOG_GCRY (GNUNET_ERROR_TYPE_DEBUG, "gcry_mpi_scan", rc); | 1982 | LOG_GCRY (GNUNET_ERROR_TYPE_DEBUG, "gcry_mpi_scan", rc); |
1986 | GNUNET_break_op (0); | 1983 | GNUNET_break_op (0); |
1987 | goto invalid_msg; | 1984 | goto invalid_msg; |
1988 | } | 1985 | } |
1989 | current += PAILLIER_ELEMENT_LENGTH; | 1986 | current += PAILLIER_ELEMENT_LENGTH; |
@@ -1998,12 +1995,11 @@ handle_service_response (void *cls, | |||
1998 | PAILLIER_ELEMENT_LENGTH, &read))) | 1995 | PAILLIER_ELEMENT_LENGTH, &read))) |
1999 | { | 1996 | { |
2000 | LOG_GCRY (GNUNET_ERROR_TYPE_DEBUG, "gcry_mpi_scan", rc); | 1997 | LOG_GCRY (GNUNET_ERROR_TYPE_DEBUG, "gcry_mpi_scan", rc); |
2001 | GNUNET_break_op (0); | 1998 | GNUNET_break_op (0); |
2002 | goto invalid_msg; | 1999 | goto invalid_msg; |
2003 | } | 2000 | } |
2004 | current += PAILLIER_ELEMENT_LENGTH; | 2001 | current += PAILLIER_ELEMENT_LENGTH; |
2005 | } | 2002 | } |
2006 | |||
2007 | session->product = compute_scalar_product (session, r, r_prime, s, s_prime); | 2003 | session->product = compute_scalar_product (session, r, r_prime, s, s_prime); |
2008 | 2004 | ||
2009 | invalid_msg: | 2005 | invalid_msg: |
@@ -2018,16 +2014,14 @@ invalid_msg: | |||
2018 | GNUNET_free_non_null (r); | 2014 | GNUNET_free_non_null (r); |
2019 | GNUNET_free_non_null (r_prime); | 2015 | GNUNET_free_non_null (r_prime); |
2020 | 2016 | ||
2021 | session->state = FINALIZED; | 2017 | session->tunnel = NULL; |
2022 | // the tunnel has done its job, terminate our connection and the tunnel | ||
2023 | // the peer will be notified that the tunnel was destroyed via tunnel_destruction_handler | ||
2024 | GNUNET_CONTAINER_DLL_remove (from_client_head, from_client_tail, session); | ||
2025 | // send message with product to client | 2018 | // send message with product to client |
2026 | |||
2027 | session->client_notification_task = | 2019 | session->client_notification_task = |
2028 | GNUNET_SCHEDULER_add_now (&prepare_client_response, | 2020 | GNUNET_SCHEDULER_add_now (&prepare_client_response, |
2029 | session); | 2021 | session); |
2030 | // just close the connection. | 2022 | // the tunnel has done its job, terminate our connection and the tunnel |
2023 | // the peer will be notified that the tunnel was destroyed via tunnel_destruction_handler | ||
2024 | // just close the connection, as recommended by Christian | ||
2031 | return GNUNET_SYSERR; | 2025 | return GNUNET_SYSERR; |
2032 | } | 2026 | } |
2033 | 2027 | ||