diff options
author | Christian Fuchs <christian.fuchs@cfuchs.net> | 2013-10-08 12:19:42 +0000 |
---|---|---|
committer | Christian Fuchs <christian.fuchs@cfuchs.net> | 2013-10-08 12:19:42 +0000 |
commit | da4d43c8e4fec1bc2f92e7387a28d074bba375dc (patch) | |
tree | 69e62c9ab39707ea3c0237e3ae9896d49c8316e6 /src/scalarproduct | |
parent | 449198d57704961b59d5b082b7b85eefa6b25739 (diff) | |
download | gnunet-da4d43c8e4fec1bc2f92e7387a28d074bba375dc.tar.gz gnunet-da4d43c8e4fec1bc2f92e7387a28d074bba375dc.zip |
How much wood... more work on multipart receiving
Diffstat (limited to 'src/scalarproduct')
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct.c | 104 |
1 files changed, 96 insertions, 8 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct.c b/src/scalarproduct/gnunet-service-scalarproduct.c index 65b6dffbf..6067833c3 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct.c +++ b/src/scalarproduct/gnunet-service-scalarproduct.c | |||
@@ -1892,6 +1892,95 @@ handle_service_request_multipart (void *cls, | |||
1892 | void **tunnel_ctx, | 1892 | void **tunnel_ctx, |
1893 | const struct GNUNET_MessageHeader * message) | 1893 | const struct GNUNET_MessageHeader * message) |
1894 | { | 1894 | { |
1895 | struct ServiceSession * session; | ||
1896 | const struct GNUNET_SCALARPRODUCT_multipart_message * msg = (const struct GNUNET_SCALARPRODUCT_multipart_message *) message; | ||
1897 | uint32_t mask_length; | ||
1898 | uint32_t pk_length; | ||
1899 | uint32_t used_elements; | ||
1900 | uint32_t contained_elements; | ||
1901 | uint32_t element_count; | ||
1902 | uint32_t msg_length; | ||
1903 | unsigned char * current; | ||
1904 | struct ServiceSession * responder_session; | ||
1905 | int32_t i = -1; | ||
1906 | enum SessionState needed_state; | ||
1907 | |||
1908 | // are we in the correct state? | ||
1909 | session = (struct ServiceSession *) * tunnel_ctx; | ||
1910 | if (BOB != session->role) { | ||
1911 | goto except; | ||
1912 | } | ||
1913 | if (WAITING_FOR_MULTIPART_TRANSMISSION != session->state) { | ||
1914 | goto except; | ||
1915 | } | ||
1916 | // shorter than minimum? | ||
1917 | if (ntohs (msg->header.size) <= sizeof (struct GNUNET_SCALARPRODUCT_multipart_message)) { | ||
1918 | goto except; | ||
1919 | } | ||
1920 | used_elements = session->used_element_count; | ||
1921 | contained_elements = ntohl (msg->multipart_element_count); | ||
1922 | msg_length = sizeof (struct GNUNET_SCALARPRODUCT_multipart_message) | ||
1923 | + contained_elements * PAILLIER_ELEMENT_LENGTH; | ||
1924 | //sanity check | ||
1925 | if (( ntohs (msg->header.size) != msg_length) | ||
1926 | || (used_elements < contained_elements + session->transferred_element_count)) { | ||
1927 | goto except; | ||
1928 | } | ||
1929 | current = (unsigned char *) &msg[1]; | ||
1930 | if (contained_elements != 0) { | ||
1931 | gcry_error_t ret = 0; | ||
1932 | // Convert each vector element to MPI_value | ||
1933 | for (i = session->transferred_element_count; i < session->transferred_element_count+contained_elements; i++) { | ||
1934 | size_t read = 0; | ||
1935 | |||
1936 | ret = gcry_mpi_scan (&session->a[i], | ||
1937 | GCRYMPI_FMT_USG, | ||
1938 | ¤t[i * PAILLIER_ELEMENT_LENGTH], | ||
1939 | PAILLIER_ELEMENT_LENGTH, | ||
1940 | &read); | ||
1941 | if (ret) { | ||
1942 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ ("Could not translate E[a%d] to MPI!\n%s/%s\n"), | ||
1943 | i, gcry_strsource (ret), gcry_strerror (ret)); | ||
1944 | goto except; | ||
1945 | } | ||
1946 | } | ||
1947 | session->transferred_element_count+=contained_elements; | ||
1948 | |||
1949 | if (session->transferred_element_count == used_elements) { | ||
1950 | // single part finished | ||
1951 | session->state = SERVICE_REQUEST_RECEIVED; | ||
1952 | if (responder_session) { | ||
1953 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Got session with key %s and a matching element set, processing.\n"), GNUNET_h2s (&session->key)); | ||
1954 | if (GNUNET_OK != compute_service_response (session, responder_session)) { | ||
1955 | //something went wrong, remove it again... | ||
1956 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session); | ||
1957 | goto except; | ||
1958 | } | ||
1959 | } | ||
1960 | else | ||
1961 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Got session with key %s without a matching element set, queueing.\n"), GNUNET_h2s (&session->key)); | ||
1962 | } | ||
1963 | else{ | ||
1964 | // multipart message | ||
1965 | } | ||
1966 | } | ||
1967 | |||
1968 | return GNUNET_OK; | ||
1969 | except: | ||
1970 | for (i = 0; i < session->transferred_element_count; i++) | ||
1971 | if (session->a[i]) | ||
1972 | gcry_mpi_release (session->a[i]); | ||
1973 | gcry_sexp_release (session->remote_pubkey); | ||
1974 | session->remote_pubkey = NULL; | ||
1975 | GNUNET_free (session->a); | ||
1976 | session->a = NULL; | ||
1977 | free_session (session); | ||
1978 | // and notify our client-session that we could not complete the session | ||
1979 | if (session->response) | ||
1980 | // we just found the responder session in this queue | ||
1981 | session->response->client_notification_task = | ||
1982 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | ||
1983 | session->response); | ||
1895 | return GNUNET_SYSERR; | 1984 | return GNUNET_SYSERR; |
1896 | } | 1985 | } |
1897 | 1986 | ||
@@ -1922,7 +2011,6 @@ handle_service_request (void *cls, | |||
1922 | uint32_t element_count; | 2011 | uint32_t element_count; |
1923 | uint32_t msg_length; | 2012 | uint32_t msg_length; |
1924 | unsigned char * current; | 2013 | unsigned char * current; |
1925 | struct ServiceSession * responder_session; | ||
1926 | int32_t i = -1; | 2014 | int32_t i = -1; |
1927 | enum SessionState needed_state; | 2015 | enum SessionState needed_state; |
1928 | 2016 | ||
@@ -1975,7 +2063,7 @@ handle_service_request (void *cls, | |||
1975 | } | 2063 | } |
1976 | 2064 | ||
1977 | memcpy (&session->peer, &session->peer, sizeof (struct GNUNET_PeerIdentity)); | 2065 | memcpy (&session->peer, &session->peer, sizeof (struct GNUNET_PeerIdentity)); |
1978 | session->element_count = ntohl (msg->element_count); | 2066 | session->element_count = element_count; |
1979 | session->used_element_count = used_elements; | 2067 | session->used_element_count = used_elements; |
1980 | session->transferred_element_count = contained_elements; | 2068 | session->transferred_element_count = contained_elements; |
1981 | session->tunnel = tunnel; | 2069 | session->tunnel = tunnel; |
@@ -2001,7 +2089,7 @@ handle_service_request (void *cls, | |||
2001 | 2089 | ||
2002 | //check if service queue contains a matching request | 2090 | //check if service queue contains a matching request |
2003 | needed_state = CLIENT_RESPONSE_RECEIVED; | 2091 | needed_state = CLIENT_RESPONSE_RECEIVED; |
2004 | responder_session = find_matching_session (from_client_tail, | 2092 | session->response = find_matching_session (from_client_tail, |
2005 | &session->key, | 2093 | &session->key, |
2006 | session->element_count, | 2094 | session->element_count, |
2007 | &needed_state, NULL); | 2095 | &needed_state, NULL); |
@@ -2030,9 +2118,9 @@ handle_service_request (void *cls, | |||
2030 | if (contained_elements == used_elements) { | 2118 | if (contained_elements == used_elements) { |
2031 | // single part finished | 2119 | // single part finished |
2032 | session->state = SERVICE_REQUEST_RECEIVED; | 2120 | session->state = SERVICE_REQUEST_RECEIVED; |
2033 | if (responder_session) { | 2121 | if (session->response) { |
2034 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Got session with key %s and a matching element set, processing.\n"), GNUNET_h2s (&session->key)); | 2122 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Got session with key %s and a matching element set, processing.\n"), GNUNET_h2s (&session->key)); |
2035 | if (GNUNET_OK != compute_service_response (session, responder_session)) { | 2123 | if (GNUNET_OK != compute_service_response (session, session->response)) { |
2036 | //something went wrong, remove it again... | 2124 | //something went wrong, remove it again... |
2037 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session); | 2125 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session); |
2038 | goto except; | 2126 | goto except; |
@@ -2056,11 +2144,11 @@ except: | |||
2056 | session->a = NULL; | 2144 | session->a = NULL; |
2057 | free_session (session); | 2145 | free_session (session); |
2058 | // and notify our client-session that we could not complete the session | 2146 | // and notify our client-session that we could not complete the session |
2059 | if (responder_session) | 2147 | if (session->response) |
2060 | // we just found the responder session in this queue | 2148 | // we just found the responder session in this queue |
2061 | responder_session->client_notification_task = | 2149 | session->response->client_notification_task = |
2062 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 2150 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
2063 | responder_session); | 2151 | session->response); |
2064 | return GNUNET_SYSERR; | 2152 | return GNUNET_SYSERR; |
2065 | } | 2153 | } |
2066 | 2154 | ||