diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-12-06 12:23:19 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-12-06 12:23:19 +0000 |
commit | a3bbceff63833f97f0d517caa85826c3cbf4f2ff (patch) | |
tree | df77217ca9abd9c0ee04cea6b18f48fdd38384ab /src/scalarproduct | |
parent | f1b32958e42714ef3200563493f15dc698d837c2 (diff) | |
download | gnunet-a3bbceff63833f97f0d517caa85826c3cbf4f2ff.tar.gz gnunet-a3bbceff63833f97f0d517caa85826c3cbf4f2ff.zip |
-fix indentation
Diffstat (limited to 'src/scalarproduct')
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct.c | 78 |
1 files changed, 53 insertions, 25 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct.c b/src/scalarproduct/gnunet-service-scalarproduct.c index 43b5d0107..d6b0deeac 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct.c +++ b/src/scalarproduct/gnunet-service-scalarproduct.c | |||
@@ -486,7 +486,8 @@ encrypt_element (gcry_mpi_t c, gcry_mpi_t m, gcry_mpi_t g, gcry_mpi_t n, gcry_mp | |||
486 | 486 | ||
487 | GNUNET_assert (tmp = gcry_mpi_new (0)); | 487 | GNUNET_assert (tmp = gcry_mpi_new (0)); |
488 | 488 | ||
489 | while (0 >= gcry_mpi_cmp_ui (tmp, 1)) { | 489 | while (0 >= gcry_mpi_cmp_ui (tmp, 1)) |
490 | { | ||
490 | gcry_mpi_randomize (tmp, KEYBITS / 3, GCRY_WEAK_RANDOM); | 491 | gcry_mpi_randomize (tmp, KEYBITS / 3, GCRY_WEAK_RANDOM); |
491 | // r must be 1 < r < n | 492 | // r must be 1 < r < n |
492 | } | 493 | } |
@@ -1697,7 +1698,7 @@ handle_client_request (void *cls, | |||
1697 | if ((ntohs (msg->header.size) != (sizeof (struct GNUNET_SCALARPRODUCT_client_request) +element_count * sizeof (int32_t) + mask_length)) | 1698 | if ((ntohs (msg->header.size) != (sizeof (struct GNUNET_SCALARPRODUCT_client_request) +element_count * sizeof (int32_t) + mask_length)) |
1698 | || (0 == element_count)) { | 1699 | || (0 == element_count)) { |
1699 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1700 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1700 | _ ("Invalid message received from client, session information incorrect!\n")); | 1701 | _("Invalid message received from client, session information incorrect!\n")); |
1701 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1702 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1702 | return; | 1703 | return; |
1703 | } | 1704 | } |
@@ -1708,7 +1709,7 @@ handle_client_request (void *cls, | |||
1708 | element_count, | 1709 | element_count, |
1709 | NULL, NULL)) { | 1710 | NULL, NULL)) { |
1710 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1711 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1711 | _ ("Duplicate session information received, cannot create new session with key `%s'\n"), | 1712 | _("Duplicate session information received, cannot create new session with key `%s'\n"), |
1712 | GNUNET_h2s (&msg->key)); | 1713 | GNUNET_h2s (&msg->key)); |
1713 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1714 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1714 | return; | 1715 | return; |
@@ -1726,9 +1727,10 @@ handle_client_request (void *cls, | |||
1726 | session->vector = GNUNET_malloc (sizeof (int32_t) * element_count); | 1727 | session->vector = GNUNET_malloc (sizeof (int32_t) * element_count); |
1727 | vector = (int32_t *) & msg[1]; | 1728 | vector = (int32_t *) & msg[1]; |
1728 | 1729 | ||
1729 | if (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE == msg_type) { | 1730 | if (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE == msg_type) |
1731 | { | ||
1730 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1732 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1731 | _ ("Got client-request-session with key %s, preparing channel to remote service.\n"), | 1733 | _("Got client-request-session with key %s, preparing channel to remote service.\n"), |
1732 | GNUNET_h2s (&session->key)); | 1734 | GNUNET_h2s (&session->key)); |
1733 | 1735 | ||
1734 | session->role = ALICE; | 1736 | session->role = ALICE; |
@@ -1738,7 +1740,8 @@ handle_client_request (void *cls, | |||
1738 | 1740 | ||
1739 | // copy over the elements | 1741 | // copy over the elements |
1740 | session->used = 0; | 1742 | session->used = 0; |
1741 | for (i = 0; i < element_count; i++) { | 1743 | for (i = 0; i < element_count; i++) |
1744 | { | ||
1742 | session->vector[i] = ntohl (vector[i]); | 1745 | session->vector[i] = ntohl (vector[i]); |
1743 | if (session->vector[i] == 0) | 1746 | if (session->vector[i] == 0) |
1744 | session->mask[i / 8] &= ~(1 << (i % 8)); | 1747 | session->mask[i / 8] &= ~(1 << (i % 8)); |
@@ -1746,7 +1749,8 @@ handle_client_request (void *cls, | |||
1746 | session->used++; | 1749 | session->used++; |
1747 | } | 1750 | } |
1748 | 1751 | ||
1749 | if (0 == session->used) { | 1752 | if (0 == session->used) |
1753 | { | ||
1750 | GNUNET_break_op (0); | 1754 | GNUNET_break_op (0); |
1751 | GNUNET_free (session->vector); | 1755 | GNUNET_free (session->vector); |
1752 | GNUNET_free (session); | 1756 | GNUNET_free (session); |
@@ -1754,7 +1758,8 @@ handle_client_request (void *cls, | |||
1754 | return; | 1758 | return; |
1755 | } | 1759 | } |
1756 | //session with ourself makes no sense! | 1760 | //session with ourself makes no sense! |
1757 | if (!memcmp (&msg->peer, &me, sizeof (struct GNUNET_PeerIdentity))) { | 1761 | if (!memcmp (&msg->peer, &me, sizeof (struct GNUNET_PeerIdentity))) |
1762 | { | ||
1758 | GNUNET_break (0); | 1763 | GNUNET_break (0); |
1759 | GNUNET_free (session->vector); | 1764 | GNUNET_free (session->vector); |
1760 | GNUNET_free (session); | 1765 | GNUNET_free (session); |
@@ -1787,7 +1792,8 @@ handle_client_request (void *cls, | |||
1787 | session); | 1792 | session); |
1788 | 1793 | ||
1789 | } | 1794 | } |
1790 | else { | 1795 | else |
1796 | { | ||
1791 | struct ServiceSession * requesting_session; | 1797 | struct ServiceSession * requesting_session; |
1792 | enum SessionState needed_state = SERVICE_REQUEST_RECEIVED; | 1798 | enum SessionState needed_state = SERVICE_REQUEST_RECEIVED; |
1793 | 1799 | ||
@@ -1807,16 +1813,22 @@ handle_client_request (void *cls, | |||
1807 | &session->key, | 1813 | &session->key, |
1808 | session->total, | 1814 | session->total, |
1809 | &needed_state, NULL); | 1815 | &needed_state, NULL); |
1810 | if (NULL != requesting_session) { | 1816 | if (NULL != requesting_session) |
1811 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Got client-responder-session with key %s and a matching service-request-session set, processing.\n"), GNUNET_h2s (&session->key)); | 1817 | { |
1818 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1819 | _("Got client-responder-session with key %s and a matching service-request-session set, processing.\n"), | ||
1820 | GNUNET_h2s (&session->key)); | ||
1812 | if (GNUNET_OK != compute_service_response (requesting_session, session)) | 1821 | if (GNUNET_OK != compute_service_response (requesting_session, session)) |
1813 | session->client_notification_task = | 1822 | session->client_notification_task = |
1814 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 1823 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
1815 | session); | 1824 | session); |
1816 | 1825 | ||
1817 | } | 1826 | } |
1818 | else { | 1827 | else |
1819 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Got client-responder-session with key %s but NO matching service-request-session set, queuing element for later use.\n"), GNUNET_h2s (&session->key)); | 1828 | { |
1829 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1830 | _("Got client-responder-session with key %s but NO matching service-request-session set, queuing element for later use.\n"), | ||
1831 | GNUNET_h2s (&session->key)); | ||
1820 | // no matching session exists yet, store the response | 1832 | // no matching session exists yet, store the response |
1821 | // for later processing by handle_service_request() | 1833 | // for later processing by handle_service_request() |
1822 | } | 1834 | } |
@@ -1844,7 +1856,9 @@ channel_incoming_handler (void *cls, | |||
1844 | { | 1856 | { |
1845 | struct ServiceSession * c = GNUNET_new (struct ServiceSession); | 1857 | struct ServiceSession * c = GNUNET_new (struct ServiceSession); |
1846 | 1858 | ||
1847 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("New incoming channel from peer %s.\n"), GNUNET_i2s (initiator)); | 1859 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1860 | _("New incoming channel from peer %s.\n"), | ||
1861 | GNUNET_i2s (initiator)); | ||
1848 | 1862 | ||
1849 | c->peer = *initiator; | 1863 | c->peer = *initiator; |
1850 | c->channel = channel; | 1864 | c->channel = channel; |
@@ -1941,7 +1955,8 @@ compute_scalar_product (struct ServiceSession * session) | |||
1941 | // due to the introduced static offset S, we now also have to remove this | 1955 | // due to the introduced static offset S, we now also have to remove this |
1942 | // from the E(a_pi)(+)E(-b_pi-r_pi) and E(a_qi)(+)E(-r_qi) twice each, | 1956 | // from the E(a_pi)(+)E(-b_pi-r_pi) and E(a_qi)(+)E(-r_qi) twice each, |
1943 | // the result is E((S + a_pi) + (S -b_pi-r_pi)) and E(S + a_qi + S - r_qi) | 1957 | // the result is E((S + a_pi) + (S -b_pi-r_pi)) and E(S + a_qi + S - r_qi) |
1944 | for (i = 0; i < count; i++) { | 1958 | for (i = 0; i < count; i++) |
1959 | { | ||
1945 | decrypt_element (session->r[i], session->r[i], my_mu, my_lambda, my_n, my_nsquare); | 1960 | decrypt_element (session->r[i], session->r[i], my_mu, my_lambda, my_n, my_nsquare); |
1946 | gcry_mpi_sub (session->r[i], session->r[i], my_offset); | 1961 | gcry_mpi_sub (session->r[i], session->r[i], my_offset); |
1947 | gcry_mpi_sub (session->r[i], session->r[i], my_offset); | 1962 | gcry_mpi_sub (session->r[i], session->r[i], my_offset); |
@@ -2058,20 +2073,27 @@ handle_service_request_multipart (void *cls, | |||
2058 | } | 2073 | } |
2059 | session->transferred += contained_elements; | 2074 | session->transferred += contained_elements; |
2060 | 2075 | ||
2061 | if (session->transferred == used_elements) { | 2076 | if (session->transferred == used_elements) |
2077 | { | ||
2062 | // single part finished | 2078 | // single part finished |
2063 | session->state = SERVICE_REQUEST_RECEIVED; | 2079 | session->state = SERVICE_REQUEST_RECEIVED; |
2064 | if (session->response) { | 2080 | if (session->response) |
2065 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Got session with key %s and a matching element set, processing.\n"), GNUNET_h2s (&session->key)); | 2081 | { |
2082 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
2083 | _ ("Got session with key %s and a matching element set, processing.\n"), | ||
2084 | GNUNET_h2s (&session->key)); | ||
2066 | if (GNUNET_OK != compute_service_response (session, session->response)) { | 2085 | if (GNUNET_OK != compute_service_response (session, session->response)) { |
2067 | //something went wrong, remove it again... | 2086 | //something went wrong, remove it again... |
2068 | goto except; | 2087 | goto except; |
2069 | } | 2088 | } |
2070 | } | 2089 | } |
2071 | else | 2090 | else |
2072 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Got session with key %s without a matching element set, queueing.\n"), GNUNET_h2s (&session->key)); | 2091 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
2092 | _("Got session with key %s without a matching element set, queueing.\n"), | ||
2093 | GNUNET_h2s (&session->key)); | ||
2073 | } | 2094 | } |
2074 | else { | 2095 | else |
2096 | { | ||
2075 | // multipart message | 2097 | // multipart message |
2076 | } | 2098 | } |
2077 | } | 2099 | } |
@@ -2145,9 +2167,12 @@ handle_service_request (void *cls, | |||
2145 | +mask_length + pk_length + contained_elements * PAILLIER_ELEMENT_LENGTH; | 2167 | +mask_length + pk_length + contained_elements * PAILLIER_ELEMENT_LENGTH; |
2146 | 2168 | ||
2147 | //sanity check: is the message as long as the message_count fields suggests? | 2169 | //sanity check: is the message as long as the message_count fields suggests? |
2148 | if ((ntohs (msg->header.size) != msg_length) || (element_count < used_elements) || (used_elements < contained_elements) | 2170 | if ( (ntohs (msg->header.size) != msg_length) || |
2149 | || (used_elements == 0) || (mask_length != (element_count / 8 + (element_count % 8 ? 1 : 0))) | 2171 | (element_count < used_elements) || |
2150 | ) { | 2172 | (used_elements < contained_elements) || |
2173 | (0 == used_elements) || | ||
2174 | (mask_length != (element_count / 8 + (element_count % 8 ? 1 : 0))) ) | ||
2175 | { | ||
2151 | GNUNET_free (session); | 2176 | GNUNET_free (session); |
2152 | GNUNET_break_op (0); | 2177 | GNUNET_break_op (0); |
2153 | return GNUNET_SYSERR; | 2178 | return GNUNET_SYSERR; |
@@ -2156,8 +2181,11 @@ handle_service_request (void *cls, | |||
2156 | &msg->key, | 2181 | &msg->key, |
2157 | element_count, | 2182 | element_count, |
2158 | NULL, | 2183 | NULL, |
2159 | NULL)) { | 2184 | NULL)) |
2160 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Got message with duplicate session key (`%s'), ignoring service request.\n"), (const char *) &(msg->key)); | 2185 | { |
2186 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
2187 | _ ("Got message with duplicate session key (`%s'), ignoring service request.\n"), | ||
2188 | (const char *) &(msg->key)); | ||
2161 | GNUNET_free (session); | 2189 | GNUNET_free (session); |
2162 | return GNUNET_SYSERR; | 2190 | return GNUNET_SYSERR; |
2163 | } | 2191 | } |