aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-12-07 22:54:20 +0000
committerChristian Grothoff <christian@grothoff.org>2014-12-07 22:54:20 +0000
commit840ea5278ccb38427c76c6c14682664c643150f9 (patch)
tree7d26fd458b794bc971857710914740dffd9505cb /src
parent629a4960f97c50422770c1267aeddb175b8b89a7 (diff)
downloadgnunet-840ea5278ccb38427c76c6c14682664c643150f9.tar.gz
gnunet-840ea5278ccb38427c76c6c14682664c643150f9.zip
-style, actually call GNUNET_CADET_receive_done to receive more messages
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_scalarproduct_service.h14
-rw-r--r--src/scalarproduct/gnunet-scalarproduct.c16
-rw-r--r--src/scalarproduct/gnunet-service-scalarproduct_alice.c36
-rw-r--r--src/scalarproduct/gnunet-service-scalarproduct_bob.c28
-rw-r--r--src/scalarproduct/scalarproduct.h5
-rw-r--r--src/scalarproduct/scalarproduct_api.c192
-rw-r--r--src/scalarproduct/test_scalarproduct.conf8
7 files changed, 164 insertions, 135 deletions
diff --git a/src/include/gnunet_scalarproduct_service.h b/src/include/gnunet_scalarproduct_service.h
index 9585fbe55..d45e8608c 100644
--- a/src/include/gnunet_scalarproduct_service.h
+++ b/src/include/gnunet_scalarproduct_service.h
@@ -46,25 +46,31 @@ extern "C" {
46 */ 46 */
47enum GNUNET_SCALARPRODUCT_ResponseStatus 47enum GNUNET_SCALARPRODUCT_ResponseStatus
48{ 48{
49
50 /**
51 * Operation is still active (never returned, used internally).
52 */
53 GNUNET_SCALARPRODUCT_STATUS_ACTIVE = 0,
54
49 /** 55 /**
50 * The computation was successful. 56 * The computation was successful.
51 */ 57 */
52 GNUNET_SCALARPRODUCT_Status_Success = 0, 58 GNUNET_SCALARPRODUCT_STATUS_SUCCESS,
53 59
54 /** 60 /**
55 * We encountered some error. 61 * We encountered some error.
56 */ 62 */
57 GNUNET_SCALARPRODUCT_Status_Failure, 63 GNUNET_SCALARPRODUCT_STATUS_FAILURE,
58 64
59 /** 65 /**
60 * We got an invalid response. 66 * We got an invalid response.
61 */ 67 */
62 GNUNET_SCALARPRODUCT_Status_InvalidResponse, 68 GNUNET_SCALARPRODUCT_STATUS_INVALID_RESPONSE,
63 69
64 /** 70 /**
65 * We got disconnected from the SCALARPRODUCT service. 71 * We got disconnected from the SCALARPRODUCT service.
66 */ 72 */
67 GNUNET_SCALARPRODUCT_Status_ServiceDisconnected 73 GNUNET_SCALARPRODUCT_STATUS_DISCONNECTED
68}; 74};
69 75
70 76
diff --git a/src/scalarproduct/gnunet-scalarproduct.c b/src/scalarproduct/gnunet-scalarproduct.c
index f6e7d6af2..e812ff444 100644
--- a/src/scalarproduct/gnunet-scalarproduct.c
+++ b/src/scalarproduct/gnunet-scalarproduct.c
@@ -84,23 +84,23 @@ responder_callback (void *cls,
84{ 84{
85 switch (status) 85 switch (status)
86 { 86 {
87 case GNUNET_SCALARPRODUCT_Status_Success: 87 case GNUNET_SCALARPRODUCT_STATUS_SUCCESS:
88 ret = 0; 88 ret = 0;
89 LOG (GNUNET_ERROR_TYPE_INFO, 89 LOG (GNUNET_ERROR_TYPE_INFO,
90 "Session %s concluded.\n", 90 "Session %s concluded.\n",
91 GNUNET_h2s (&session_key)); 91 GNUNET_h2s (&session_key));
92 break; 92 break;
93 case GNUNET_SCALARPRODUCT_Status_InvalidResponse: 93 case GNUNET_SCALARPRODUCT_STATUS_INVALID_RESPONSE:
94 LOG (GNUNET_ERROR_TYPE_ERROR, 94 LOG (GNUNET_ERROR_TYPE_ERROR,
95 "Session %s failed: invalid response\n", 95 "Session %s failed: invalid response\n",
96 GNUNET_h2s (&session_key)); 96 GNUNET_h2s (&session_key));
97 break; 97 break;
98 case GNUNET_SCALARPRODUCT_Status_Failure: 98 case GNUNET_SCALARPRODUCT_STATUS_FAILURE:
99 LOG (GNUNET_ERROR_TYPE_ERROR, 99 LOG (GNUNET_ERROR_TYPE_ERROR,
100 "Session %s failed: service failure\n", 100 "Session %s failed: service failure\n",
101 GNUNET_h2s (&session_key)); 101 GNUNET_h2s (&session_key));
102 break; 102 break;
103 case GNUNET_SCALARPRODUCT_Status_ServiceDisconnected: 103 case GNUNET_SCALARPRODUCT_STATUS_DISCONNECTED:
104 LOG (GNUNET_ERROR_TYPE_ERROR, 104 LOG (GNUNET_ERROR_TYPE_ERROR,
105 "Session %s failed: service disconnect!\n", 105 "Session %s failed: service disconnect!\n",
106 GNUNET_h2s (&session_key)); 106 GNUNET_h2s (&session_key));
@@ -133,7 +133,7 @@ requester_callback (void *cls,
133 133
134 switch (status) 134 switch (status)
135 { 135 {
136 case GNUNET_SCALARPRODUCT_Status_Success: 136 case GNUNET_SCALARPRODUCT_STATUS_SUCCESS:
137 if (0 == (rc = gcry_mpi_aprint (GCRYMPI_FMT_HEX, &buf, NULL, result))) 137 if (0 == (rc = gcry_mpi_aprint (GCRYMPI_FMT_HEX, &buf, NULL, result)))
138 { 138 {
139 ret = 0; 139 ret = 0;
@@ -144,19 +144,19 @@ requester_callback (void *cls,
144 "gcry_mpi_aprint", 144 "gcry_mpi_aprint",
145 rc); 145 rc);
146 break; 146 break;
147 case GNUNET_SCALARPRODUCT_Status_InvalidResponse: 147 case GNUNET_SCALARPRODUCT_STATUS_INVALID_RESPONSE:
148 LOG (GNUNET_ERROR_TYPE_ERROR, 148 LOG (GNUNET_ERROR_TYPE_ERROR,
149 "Session %s with peer %s failed: invalid response received\n", 149 "Session %s with peer %s failed: invalid response received\n",
150 GNUNET_h2s (&session_key), 150 GNUNET_h2s (&session_key),
151 GNUNET_i2s (&peer_id)); 151 GNUNET_i2s (&peer_id));
152 break; 152 break;
153 case GNUNET_SCALARPRODUCT_Status_Failure: 153 case GNUNET_SCALARPRODUCT_STATUS_FAILURE:
154 LOG (GNUNET_ERROR_TYPE_ERROR, 154 LOG (GNUNET_ERROR_TYPE_ERROR,
155 "Session %s with peer %s failed: API failure\n", 155 "Session %s with peer %s failed: API failure\n",
156 GNUNET_h2s (&session_key), 156 GNUNET_h2s (&session_key),
157 GNUNET_i2s (&peer_id)); 157 GNUNET_i2s (&peer_id));
158 break; 158 break;
159 case GNUNET_SCALARPRODUCT_Status_ServiceDisconnected: 159 case GNUNET_SCALARPRODUCT_STATUS_DISCONNECTED:
160 LOG (GNUNET_ERROR_TYPE_ERROR, 160 LOG (GNUNET_ERROR_TYPE_ERROR,
161 "Session %s with peer %s was disconnected from service.\n", 161 "Session %s with peer %s was disconnected from service.\n",
162 GNUNET_h2s (&session_key), 162 GNUNET_h2s (&session_key),
diff --git a/src/scalarproduct/gnunet-service-scalarproduct_alice.c b/src/scalarproduct/gnunet-service-scalarproduct_alice.c
index ce796aa05..b797a378d 100644
--- a/src/scalarproduct/gnunet-service-scalarproduct_alice.c
+++ b/src/scalarproduct/gnunet-service-scalarproduct_alice.c
@@ -167,11 +167,12 @@ struct AliceServiceSession
167 uint32_t transferred_element_count; 167 uint32_t transferred_element_count;
168 168
169 /** 169 /**
170 * Is this session active (#GNUNET_YES), Concluded (#GNUNET_NO), or 170 * State of this session. In
171 * had an error (#GNUNET_SYSERR). 171 * #GNUNET_SCALARPRODUCT_STATUS_ACTIVE while operation is
172 * FIXME: replace with proper enum for status codes! 172 * ongoing, afterwards in #GNUNET_SCALARPRODUCT_STATUS_SUCCESS or
173 * #GNUNET_SCALARPRODUCT_STATUS_FAILURE.
173 */ 174 */
174 int32_t active; 175 enum GNUNET_SCALARPRODUCT_ResponseStatus status;
175 176
176 /** 177 /**
177 * Flag to prevent recursive calls to #destroy_service_session() from 178 * Flag to prevent recursive calls to #destroy_service_session() from
@@ -326,12 +327,12 @@ prepare_client_end_notification (struct AliceServiceSession *session)
326 327
327 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 328 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
328 "Sending session-end notification with status %d to client for session %s\n", 329 "Sending session-end notification with status %d to client for session %s\n",
329 session->active, 330 session->status,
330 GNUNET_h2s (&session->session_id)); 331 GNUNET_h2s (&session->session_id));
331 e = GNUNET_MQ_msg (msg, 332 e = GNUNET_MQ_msg (msg,
332 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); 333 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT);
333 msg->product_length = htonl (0); 334 msg->product_length = htonl (0);
334 msg->status = htonl (session->active); 335 msg->status = htonl (session->status);
335 GNUNET_MQ_send (session->client_mq, 336 GNUNET_MQ_send (session->client_mq,
336 e); 337 e);
337} 338}
@@ -439,11 +440,16 @@ cb_channel_destruction (void *cls,
439 "Peer disconnected, terminating session %s with peer %s\n", 440 "Peer disconnected, terminating session %s with peer %s\n",
440 GNUNET_h2s (&s->session_id), 441 GNUNET_h2s (&s->session_id),
441 GNUNET_i2s (&s->peer)); 442 GNUNET_i2s (&s->peer));
443 if (NULL != s->cadet_mq)
444 {
445 GNUNET_MQ_destroy (s->cadet_mq);
446 s->cadet_mq = NULL;
447 }
442 s->channel = NULL; 448 s->channel = NULL;
443 if (GNUNET_YES == s->active) 449 if (GNUNET_SCALARPRODUCT_STATUS_ACTIVE == s->status)
444 { 450 {
445 /* We didn't get an answer yet, fail with error */ 451 /* We didn't get an answer yet, fail with error */
446 s->active = GNUNET_SYSERR; 452 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
447 prepare_client_end_notification (s); 453 prepare_client_end_notification (s);
448 } 454 }
449} 455}
@@ -685,6 +691,7 @@ handle_bobs_cryptodata_multipart (void *cls,
685 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 691 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
686 } 692 }
687 s->transferred_element_count += contained; 693 s->transferred_element_count += contained;
694 GNUNET_CADET_receive_done (s->channel);
688 if (s->transferred_element_count != s->used_element_count) 695 if (s->transferred_element_count != s->used_element_count)
689 return GNUNET_OK; 696 return GNUNET_OK;
690 697
@@ -775,6 +782,7 @@ handle_bobs_cryptodata_message (void *cls,
775 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 782 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
776 } 783 }
777 s->transferred_element_count = contained; 784 s->transferred_element_count = contained;
785 GNUNET_CADET_receive_done (s->channel);
778 786
779 if (s->transferred_element_count != s->used_element_count) 787 if (s->transferred_element_count != s->used_element_count)
780 { 788 {
@@ -964,7 +972,7 @@ cb_intersection_element_removed (void *cls,
964 } 972 }
965 s->intersection_op = NULL; 973 s->intersection_op = NULL;
966 s->intersection_set = NULL; 974 s->intersection_set = NULL;
967 s->active = GNUNET_SYSERR; 975 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
968 prepare_client_end_notification (s); 976 prepare_client_end_notification (s);
969 return; 977 return;
970 default: 978 default:
@@ -1012,7 +1020,7 @@ cb_intersection_request_alice (void *cls,
1012 if (NULL == s->intersection_op) 1020 if (NULL == s->intersection_op)
1013 { 1021 {
1014 GNUNET_break (0); 1022 GNUNET_break (0);
1015 s->active = GNUNET_SYSERR; 1023 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
1016 prepare_client_end_notification (s); 1024 prepare_client_end_notification (s);
1017 return; 1025 return;
1018 } 1026 }
@@ -1020,7 +1028,7 @@ cb_intersection_request_alice (void *cls,
1020 GNUNET_SET_commit (s->intersection_op, 1028 GNUNET_SET_commit (s->intersection_op,
1021 s->intersection_set)) 1029 s->intersection_set))
1022 { 1030 {
1023 s->active = GNUNET_SYSERR; 1031 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
1024 prepare_client_end_notification (s); 1032 prepare_client_end_notification (s);
1025 return; 1033 return;
1026 } 1034 }
@@ -1051,7 +1059,7 @@ client_request_complete_alice (struct AliceServiceSession *s)
1051 GNUNET_CADET_OPTION_RELIABLE); 1059 GNUNET_CADET_OPTION_RELIABLE);
1052 if (NULL == s->channel) 1060 if (NULL == s->channel)
1053 { 1061 {
1054 s->active = GNUNET_SYSERR; 1062 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
1055 prepare_client_end_notification (s); 1063 prepare_client_end_notification (s);
1056 return; 1064 return;
1057 } 1065 }
@@ -1064,7 +1072,7 @@ client_request_complete_alice (struct AliceServiceSession *s)
1064 s); 1072 s);
1065 if (NULL == s->intersection_listen) 1073 if (NULL == s->intersection_listen)
1066 { 1074 {
1067 s->active = GNUNET_SYSERR; 1075 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
1068 GNUNET_CADET_channel_destroy (s->channel); 1076 GNUNET_CADET_channel_destroy (s->channel);
1069 s->channel = NULL; 1077 s->channel = NULL;
1070 prepare_client_end_notification (s); 1078 prepare_client_end_notification (s);
@@ -1227,7 +1235,7 @@ GSS_handle_alice_client_message (void *cls,
1227 1235
1228 s = GNUNET_new (struct AliceServiceSession); 1236 s = GNUNET_new (struct AliceServiceSession);
1229 s->peer = msg->peer; 1237 s->peer = msg->peer;
1230 s->active = GNUNET_YES; 1238 s->status = GNUNET_SCALARPRODUCT_STATUS_ACTIVE;
1231 s->client = client; 1239 s->client = client;
1232 s->client_mq = GNUNET_MQ_queue_for_server_client (client); 1240 s->client_mq = GNUNET_MQ_queue_for_server_client (client);
1233 s->total = total_count; 1241 s->total = total_count;
diff --git a/src/scalarproduct/gnunet-service-scalarproduct_bob.c b/src/scalarproduct/gnunet-service-scalarproduct_bob.c
index 8f946f7a3..fc0fd5bb3 100644
--- a/src/scalarproduct/gnunet-service-scalarproduct_bob.c
+++ b/src/scalarproduct/gnunet-service-scalarproduct_bob.c
@@ -175,9 +175,12 @@ struct BobServiceSession
175 uint32_t cadet_transmitted_element_count; 175 uint32_t cadet_transmitted_element_count;
176 176
177 /** 177 /**
178 * Is this session active (#GNUNET_YES), Concluded (#GNUNET_NO), or had an error (#GNUNET_SYSERR) 178 * State of this session. In
179 * #GNUNET_SCALARPRODUCT_STATUS_ACTIVE while operation is
180 * ongoing, afterwards in #GNUNET_SCALARPRODUCT_STATUS_SUCCESS or
181 * #GNUNET_SCALARPRODUCT_STATUS_FAILURE.
179 */ 182 */
180 int32_t active; 183 enum GNUNET_SCALARPRODUCT_ResponseStatus status;
181 184
182 /** 185 /**
183 * Are we already in #destroy_service_session()? 186 * Are we already in #destroy_service_session()?
@@ -448,13 +451,13 @@ prepare_client_end_notification (struct BobServiceSession *session)
448 451
449 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 452 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
450 "Sending session-end notification with status %d to client for session %s\n", 453 "Sending session-end notification with status %d to client for session %s\n",
451 session->active, 454 session->status,
452 GNUNET_h2s (&session->session_id)); 455 GNUNET_h2s (&session->session_id));
453 e = GNUNET_MQ_msg (msg, 456 e = GNUNET_MQ_msg (msg,
454 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); 457 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT);
455 msg->range = 0; 458 msg->range = 0;
456 msg->product_length = htonl (0); 459 msg->product_length = htonl (0);
457 msg->status = htonl (session->active); 460 msg->status = htonl (session->status);
458 GNUNET_MQ_send (session->client_mq, 461 GNUNET_MQ_send (session->client_mq,
459 e); 462 e);
460} 463}
@@ -483,12 +486,17 @@ cb_channel_destruction (void *cls,
483 "Peer disconnected, terminating session %s with peer %s\n", 486 "Peer disconnected, terminating session %s with peer %s\n",
484 GNUNET_h2s (&in->session_id), 487 GNUNET_h2s (&in->session_id),
485 GNUNET_i2s (&in->peer)); 488 GNUNET_i2s (&in->peer));
489 if (NULL != in->cadet_mq)
490 {
491 GNUNET_MQ_destroy (in->cadet_mq);
492 in->cadet_mq = NULL;
493 }
486 in->channel = NULL; 494 in->channel = NULL;
487 if (NULL != (s = in->s)) 495 if (NULL != (s = in->s))
488 { 496 {
489 if (GNUNET_YES == s->active) 497 if (GNUNET_SCALARPRODUCT_STATUS_ACTIVE == s->status)
490 { 498 {
491 s->active = GNUNET_SYSERR; 499 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
492 prepare_client_end_notification (s); 500 prepare_client_end_notification (s);
493 } 501 }
494 } 502 }
@@ -505,7 +513,7 @@ bob_cadet_done_cb (void *cls)
505{ 513{
506 struct BobServiceSession *session = cls; 514 struct BobServiceSession *session = cls;
507 515
508 session->active = GNUNET_NO; /* that means, done */ 516 session->status = GNUNET_SCALARPRODUCT_STATUS_SUCCESS;
509 prepare_client_end_notification (session); 517 prepare_client_end_notification (session);
510} 518}
511 519
@@ -944,6 +952,7 @@ handle_alices_cryptodata_message (void *cls,
944 CADET response(s) */ 952 CADET response(s) */
945 transmit_cryptographic_reply (s); 953 transmit_cryptographic_reply (s);
946 } 954 }
955 GNUNET_CADET_receive_done (s->cadet->channel);
947 return GNUNET_OK; 956 return GNUNET_OK;
948} 957}
949 958
@@ -984,6 +993,7 @@ cb_intersection_element_removed (void *cls,
984 case GNUNET_SET_STATUS_DONE: 993 case GNUNET_SET_STATUS_DONE:
985 s->intersection_op = NULL; 994 s->intersection_op = NULL;
986 s->intersection_set = NULL; 995 s->intersection_set = NULL;
996 GNUNET_CADET_receive_done (s->cadet->channel);
987 LOG (GNUNET_ERROR_TYPE_DEBUG, 997 LOG (GNUNET_ERROR_TYPE_DEBUG,
988 "Finished intersection, %d items remain\n", 998 "Finished intersection, %d items remain\n",
989 GNUNET_CONTAINER_multihashmap_size (s->intersected_elements)); 999 GNUNET_CONTAINER_multihashmap_size (s->intersected_elements));
@@ -1005,7 +1015,7 @@ cb_intersection_element_removed (void *cls,
1005 "Set intersection failed!\n"); 1015 "Set intersection failed!\n");
1006 s->intersection_op = NULL; 1016 s->intersection_op = NULL;
1007 s->intersection_set = NULL; 1017 s->intersection_set = NULL;
1008 s->active = GNUNET_SYSERR; 1018 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
1009 prepare_client_end_notification (s); 1019 prepare_client_end_notification (s);
1010 return; 1020 return;
1011 default: 1021 default:
@@ -1297,7 +1307,7 @@ GSS_handle_bob_client_message (void *cls,
1297 } 1307 }
1298 1308
1299 s = GNUNET_new (struct BobServiceSession); 1309 s = GNUNET_new (struct BobServiceSession);
1300 s->active = GNUNET_YES; 1310 s->status = GNUNET_SCALARPRODUCT_STATUS_ACTIVE;
1301 s->client = client; 1311 s->client = client;
1302 s->client_mq = GNUNET_MQ_queue_for_server_client (client); 1312 s->client_mq = GNUNET_MQ_queue_for_server_client (client);
1303 s->total = total_count; 1313 s->total = total_count;
diff --git a/src/scalarproduct/scalarproduct.h b/src/scalarproduct/scalarproduct.h
index a59f7641d..8f5abb3e0 100644
--- a/src/scalarproduct/scalarproduct.h
+++ b/src/scalarproduct/scalarproduct.h
@@ -154,9 +154,10 @@ struct ClientResponseMessage
154 uint32_t product_length GNUNET_PACKED; 154 uint32_t product_length GNUNET_PACKED;
155 155
156 /** 156 /**
157 * status information about the outcome of this session 157 * Status information about the outcome of this session,
158 * An `enum GNUNET_SCALARPRODUCT_ResponseStatus` (in NBO).
158 */ 159 */
159 int32_t status GNUNET_PACKED; 160 uint32_t status GNUNET_PACKED;
160 161
161 /** 162 /**
162 * Workaround for libgcrypt: -1 if negative, 0 if zero, else 1 163 * Workaround for libgcrypt: -1 if negative, 0 if zero, else 1
diff --git a/src/scalarproduct/scalarproduct_api.c b/src/scalarproduct/scalarproduct_api.c
index eea17c8f6..cae045d62 100644
--- a/src/scalarproduct/scalarproduct_api.c
+++ b/src/scalarproduct/scalarproduct_api.c
@@ -124,96 +124,9 @@ struct GNUNET_SCALARPRODUCT_ComputationHandle
124 124
125 125
126/** 126/**
127 * Handles the STATUS received from the service for a response, does 127 * Called when a response is received from the service. After basic
128 * not contain a payload. Called when we participate as "Bob" via 128 * check, the handler in `h->response_proc` is called. This functions
129 * #GNUNET_SCALARPRODUCT_accept_computation(). 129 * handles the response to the client which used the API.
130 *
131 * @param h our Handle
132 * @param msg the response received
133 * @param status the condition the request was terminated with (eg: disconnect)
134 */
135static void
136process_status_message (struct GNUNET_SCALARPRODUCT_ComputationHandle *h,
137 const struct ClientResponseMessage *msg,
138 enum GNUNET_SCALARPRODUCT_ResponseStatus status)
139{
140 if (NULL != h->cont_status)
141 h->cont_status (h->cont_cls,
142 status);
143 GNUNET_SCALARPRODUCT_cancel (h);
144}
145
146
147/**
148 * Handles the RESULT received from the service for a request, should
149 * contain a result MPI value. Called when we participate as "Alice" via
150 * #GNUNET_SCALARPRODUCT_start_computation().
151 *
152 * @param h our Handle
153 * @param msg Pointer to the response received
154 * @param status the condition the request was terminated with (eg: disconnect)
155 */
156static void
157process_result_message (struct GNUNET_SCALARPRODUCT_ComputationHandle *h,
158 const struct ClientResponseMessage *msg,
159 enum GNUNET_SCALARPRODUCT_ResponseStatus status)
160{
161 size_t product_len;
162 gcry_mpi_t result = NULL;
163 gcry_error_t rc;
164 gcry_mpi_t num;
165 size_t rsize;
166
167 if ( (GNUNET_SCALARPRODUCT_Status_Success == status) &&
168 ( (NULL == msg) ||
169 ( (ntohs (msg->header.size) - sizeof (struct ClientResponseMessage)
170 != (product_len = ntohl (msg->product_length))) ) ) )
171 {
172 GNUNET_break (0);
173 status = GNUNET_SCALARPRODUCT_Status_InvalidResponse;
174 }
175 if (GNUNET_SCALARPRODUCT_Status_Success == status)
176 {
177 result = gcry_mpi_new (0);
178
179 if (0 < product_len)
180 {
181 rsize = 0;
182 if (0 != (rc = gcry_mpi_scan (&num, GCRYMPI_FMT_STD,
183 &msg[1],
184 product_len,
185 &rsize)))
186 {
187 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR,
188 "gcry_mpi_scan",
189 rc);
190 gcry_mpi_release (result);
191 result = NULL;
192 status = GNUNET_SCALARPRODUCT_Status_InvalidResponse;
193 }
194 else
195 {
196 if (0 < ntohl (msg->range))
197 gcry_mpi_add (result, result, num);
198 else if (0 > ntohl (msg->range))
199 gcry_mpi_sub (result, result, num);
200 gcry_mpi_release (num);
201 }
202 }
203 }
204 h->cont_datum (h->cont_cls,
205 status,
206 result);
207 if (NULL != result)
208 gcry_mpi_release (result);
209 GNUNET_SCALARPRODUCT_cancel (h);
210}
211
212
213/**
214 * Called when a response is received from the service. After basic check, the
215 * handler in qe->response_proc is called. This functions handles the response
216 * to the client which used the API.
217 * 130 *
218 * @param cls Pointer to the Master Context 131 * @param cls Pointer to the Master Context
219 * @param msg Pointer to the data received in response 132 * @param msg Pointer to the data received in response
@@ -224,6 +137,7 @@ receive_cb (void *cls,
224{ 137{
225 struct GNUNET_SCALARPRODUCT_ComputationHandle *h = cls; 138 struct GNUNET_SCALARPRODUCT_ComputationHandle *h = cls;
226 const struct ClientResponseMessage *message; 139 const struct ClientResponseMessage *message;
140 enum GNUNET_SCALARPRODUCT_ResponseStatus status;
227 141
228 if (NULL == msg) 142 if (NULL == msg)
229 { 143 {
@@ -231,28 +145,31 @@ receive_cb (void *cls,
231 "Disconnected from SCALARPRODUCT service.\n"); 145 "Disconnected from SCALARPRODUCT service.\n");
232 h->response_proc (h, 146 h->response_proc (h,
233 NULL, 147 NULL,
234 GNUNET_SCALARPRODUCT_Status_ServiceDisconnected); 148 GNUNET_SCALARPRODUCT_STATUS_DISCONNECTED);
235 return; 149 return;
236 } 150 }
237 if (ntohs (msg->size) != sizeof (struct ClientResponseMessage)) 151 if (ntohs (msg->size) < sizeof (struct ClientResponseMessage))
238 { 152 {
239 GNUNET_break (0); 153 GNUNET_break (0);
240 h->response_proc (h, 154 h->response_proc (h,
241 NULL, 155 NULL,
242 GNUNET_SCALARPRODUCT_Status_InvalidResponse); 156 GNUNET_SCALARPRODUCT_STATUS_INVALID_RESPONSE);
243 return; 157 return;
244 } 158 }
245 message = (const struct ClientResponseMessage *) msg; 159 message = (const struct ClientResponseMessage *) msg;
246 if (GNUNET_SYSERR == ntohl (message->status)) 160 if (ntohs (msg->size) !=
161 ntohl (message->product_length) + sizeof (struct ClientResponseMessage))
247 { 162 {
163 GNUNET_break (0);
248 h->response_proc (h, 164 h->response_proc (h,
249 NULL, 165 NULL,
250 GNUNET_SCALARPRODUCT_Status_Failure); 166 GNUNET_SCALARPRODUCT_STATUS_INVALID_RESPONSE);
251 return; 167 return;
252 } 168 }
169 status = (enum GNUNET_SCALARPRODUCT_ResponseStatus) ntohl (message->status);
253 h->response_proc (h, 170 h->response_proc (h,
254 message, 171 message,
255 GNUNET_SCALARPRODUCT_Status_Success); 172 status);
256} 173}
257 174
258 175
@@ -282,7 +199,7 @@ do_send_message (void *cls,
282 "Failed to transmit request to SCALARPRODUCT.\n"); 199 "Failed to transmit request to SCALARPRODUCT.\n");
283 /* notify caller about the error, done here */ 200 /* notify caller about the error, done here */
284 h->response_proc (h, NULL, 201 h->response_proc (h, NULL,
285 GNUNET_SCALARPRODUCT_Status_Failure); 202 GNUNET_SCALARPRODUCT_STATUS_FAILURE);
286 return 0; 203 return 0;
287 } 204 }
288 ret = ntohs (h->msg->size); 205 ret = ntohs (h->msg->size);
@@ -330,6 +247,27 @@ do_send_message (void *cls,
330 247
331 248
332/** 249/**
250 * Handles the STATUS received from the service for a response, does
251 * not contain a payload. Called when we participate as "Bob" via
252 * #GNUNET_SCALARPRODUCT_accept_computation().
253 *
254 * @param h our Handle
255 * @param msg the response received
256 * @param status the condition the request was terminated with (eg: disconnect)
257 */
258static void
259process_status_message (struct GNUNET_SCALARPRODUCT_ComputationHandle *h,
260 const struct ClientResponseMessage *msg,
261 enum GNUNET_SCALARPRODUCT_ResponseStatus status)
262{
263 if (NULL != h->cont_status)
264 h->cont_status (h->cont_cls,
265 status);
266 GNUNET_SCALARPRODUCT_cancel (h);
267}
268
269
270/**
333 * Used by Bob's client to cooperate with Alice, 271 * Used by Bob's client to cooperate with Alice,
334 * 272 *
335 * @param cfg the gnunet configuration handle 273 * @param cfg the gnunet configuration handle
@@ -410,6 +348,66 @@ GNUNET_SCALARPRODUCT_accept_computation (const struct GNUNET_CONFIGURATION_Handl
410 348
411 349
412/** 350/**
351 * Handles the RESULT received from the service for a request, should
352 * contain a result MPI value. Called when we participate as "Alice" via
353 * #GNUNET_SCALARPRODUCT_start_computation().
354 *
355 * @param h our Handle
356 * @param msg Pointer to the response received
357 * @param status the condition the request was terminated with (eg: disconnect)
358 */
359static void
360process_result_message (struct GNUNET_SCALARPRODUCT_ComputationHandle *h,
361 const struct ClientResponseMessage *msg,
362 enum GNUNET_SCALARPRODUCT_ResponseStatus status)
363{
364 uint32_t product_len;
365 gcry_mpi_t result = NULL;
366 gcry_error_t rc;
367 gcry_mpi_t num;
368 size_t rsize;
369
370 if (GNUNET_SCALARPRODUCT_STATUS_SUCCESS == status)
371 {
372 result = gcry_mpi_new (0);
373
374 product_len = ntohl (msg->product_length);
375 if (0 < product_len)
376 {
377 rsize = 0;
378 if (0 != (rc = gcry_mpi_scan (&num, GCRYMPI_FMT_STD,
379 &msg[1],
380 product_len,
381 &rsize)))
382 {
383 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR,
384 "gcry_mpi_scan",
385 rc);
386 gcry_mpi_release (result);
387 result = NULL;
388 status = GNUNET_SCALARPRODUCT_STATUS_INVALID_RESPONSE;
389 }
390 else
391 {
392 if (0 < ntohl (msg->range))
393 gcry_mpi_add (result, result, num);
394 else if (0 > ntohl (msg->range))
395 gcry_mpi_sub (result, result, num);
396 gcry_mpi_release (num);
397 }
398 }
399 }
400 if (NULL != h->cont_datum)
401 h->cont_datum (h->cont_cls,
402 status,
403 result);
404 if (NULL != result)
405 gcry_mpi_release (result);
406 GNUNET_SCALARPRODUCT_cancel (h);
407}
408
409
410/**
413 * Request by Alice's client for computing a scalar product 411 * Request by Alice's client for computing a scalar product
414 * 412 *
415 * @param cfg the gnunet configuration handle 413 * @param cfg the gnunet configuration handle
diff --git a/src/scalarproduct/test_scalarproduct.conf b/src/scalarproduct/test_scalarproduct.conf
index 0083bc202..96a487a57 100644
--- a/src/scalarproduct/test_scalarproduct.conf
+++ b/src/scalarproduct/test_scalarproduct.conf
@@ -9,4 +9,10 @@ GNUNET_TEST_HOME = /tmp/test-scalarproduct/
9OVERLAY_TOPOLOGY = CLIQUE 9OVERLAY_TOPOLOGY = CLIQUE
10 10
11[nse] 11[nse]
12WORKBITS=0 \ No newline at end of file 12WORKBITS=0
13
14[scalarproduct-bob]
15#PREFIX = valgrind
16
17[scalarproduct-alice]
18#PREFIX = valgrind \ No newline at end of file