diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-09-20 10:20:46 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-09-20 10:20:46 +0000 |
commit | 7e835e78aa82869715c9aee96a73ba40aad3f39f (patch) | |
tree | 000078e5b3f0b48a8f473df30b187a170b7c29b3 /src/scalarproduct | |
parent | a9f53345421cddea37be81e59d6fb56a9f095d6c (diff) | |
download | gnunet-7e835e78aa82869715c9aee96a73ba40aad3f39f.tar.gz gnunet-7e835e78aa82869715c9aee96a73ba40aad3f39f.zip |
convert non-ecc scalarproducts to new service API
Diffstat (limited to 'src/scalarproduct')
4 files changed, 295 insertions, 293 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c b/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c index ba8b4b796..0b7f24e7e 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c +++ b/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c | |||
@@ -245,8 +245,10 @@ destroy_service_session (struct AliceServiceSession *s) | |||
245 | } | 245 | } |
246 | if (NULL != s->client) | 246 | if (NULL != s->client) |
247 | { | 247 | { |
248 | GNUNET_SERVICE_client_drop (s->client); | 248 | struct GNUNET_SERVICE_Client *c = s->client; |
249 | |||
249 | s->client = NULL; | 250 | s->client = NULL; |
251 | GNUNET_SERVICE_client_drop (c); | ||
250 | } | 252 | } |
251 | if (NULL != s->channel) | 253 | if (NULL != s->channel) |
252 | { | 254 | { |
diff --git a/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c b/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c index f873b0e05..06e30706e 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c +++ b/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c | |||
@@ -319,8 +319,10 @@ destroy_service_session (struct BobServiceSession *s) | |||
319 | } | 319 | } |
320 | if (NULL != s->client) | 320 | if (NULL != s->client) |
321 | { | 321 | { |
322 | GNUNET_SERVICE_client_drop (s->client); | 322 | struct GNUNET_SERVICE_Client *c = s->client; |
323 | |||
323 | s->client = NULL; | 324 | s->client = NULL; |
325 | GNUNET_SERVICE_client_drop (c); | ||
324 | } | 326 | } |
325 | GNUNET_assert (GNUNET_YES == | 327 | GNUNET_assert (GNUNET_YES == |
326 | GNUNET_CONTAINER_multihashmap_remove (client_sessions, | 328 | GNUNET_CONTAINER_multihashmap_remove (client_sessions, |
diff --git a/src/scalarproduct/gnunet-service-scalarproduct_alice.c b/src/scalarproduct/gnunet-service-scalarproduct_alice.c index 51bfcb80f..45d1f4e2c 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct_alice.c +++ b/src/scalarproduct/gnunet-service-scalarproduct_alice.c | |||
@@ -77,7 +77,7 @@ struct AliceServiceSession | |||
77 | /** | 77 | /** |
78 | * The client this request is related to. | 78 | * The client this request is related to. |
79 | */ | 79 | */ |
80 | struct GNUNET_SERVER_Client *client; | 80 | struct GNUNET_SERVICE_Client *client; |
81 | 81 | ||
82 | /** | 82 | /** |
83 | * The message queue for the client. | 83 | * The message queue for the client. |
@@ -248,11 +248,6 @@ destroy_service_session (struct AliceServiceSession *s) | |||
248 | if (GNUNET_YES == s->in_destroy) | 248 | if (GNUNET_YES == s->in_destroy) |
249 | return; | 249 | return; |
250 | s->in_destroy = GNUNET_YES; | 250 | s->in_destroy = GNUNET_YES; |
251 | if (NULL != s->client_mq) | ||
252 | { | ||
253 | GNUNET_MQ_destroy (s->client_mq); | ||
254 | s->client_mq = NULL; | ||
255 | } | ||
256 | if (NULL != s->cadet_mq) | 251 | if (NULL != s->cadet_mq) |
257 | { | 252 | { |
258 | GNUNET_MQ_destroy (s->cadet_mq); | 253 | GNUNET_MQ_destroy (s->cadet_mq); |
@@ -260,10 +255,10 @@ destroy_service_session (struct AliceServiceSession *s) | |||
260 | } | 255 | } |
261 | if (NULL != s->client) | 256 | if (NULL != s->client) |
262 | { | 257 | { |
263 | GNUNET_SERVER_client_set_user_context (s->client, | 258 | struct GNUNET_SERVICE_Client *c = s->client; |
264 | NULL); | 259 | |
265 | GNUNET_SERVER_client_disconnect (s->client); | ||
266 | s->client = NULL; | 260 | s->client = NULL; |
261 | GNUNET_SERVICE_client_drop (c); | ||
267 | } | 262 | } |
268 | if (NULL != s->channel) | 263 | if (NULL != s->channel) |
269 | { | 264 | { |
@@ -1115,48 +1110,23 @@ client_request_complete_alice (struct AliceServiceSession *s) | |||
1115 | 1110 | ||
1116 | 1111 | ||
1117 | /** | 1112 | /** |
1118 | * We're receiving additional set data. Add it to our | 1113 | * We're receiving additional set data. Check if |
1119 | * set and if we are done, initiate the transaction. | 1114 | * @a msg is well-formed. |
1120 | * | 1115 | * |
1121 | * @param cls closure | 1116 | * @param cls client identification of the client |
1122 | * @param client identification of the client | 1117 | * @param msg the actual message |
1123 | * @param message the actual message | 1118 | * @return #GNUNET_OK if @a msg is well-formed |
1124 | */ | 1119 | */ |
1125 | static void | 1120 | static int |
1126 | GSS_handle_alice_client_message_multipart (void *cls, | 1121 | check_alice_client_message_multipart (void *cls, |
1127 | struct GNUNET_SERVER_Client *client, | 1122 | const struct ComputationBobCryptodataMultipartMessage *msg) |
1128 | const struct GNUNET_MessageHeader *message) | ||
1129 | { | 1123 | { |
1130 | const struct ComputationBobCryptodataMultipartMessage * msg; | 1124 | struct AliceServiceSession *s = cls; |
1131 | struct AliceServiceSession *s; | ||
1132 | uint32_t contained_count; | 1125 | uint32_t contained_count; |
1133 | const struct GNUNET_SCALARPRODUCT_Element *elements; | ||
1134 | uint32_t i; | ||
1135 | uint16_t msize; | 1126 | uint16_t msize; |
1136 | struct GNUNET_SET_Element set_elem; | ||
1137 | struct GNUNET_SCALARPRODUCT_Element *elem; | ||
1138 | 1127 | ||
1139 | s = GNUNET_SERVER_client_get_user_context (client, | 1128 | msize = ntohs (msg->header.size); |
1140 | struct AliceServiceSession); | ||
1141 | if (NULL == s) | ||
1142 | { | ||
1143 | /* session needs to already exist */ | ||
1144 | GNUNET_break (0); | ||
1145 | GNUNET_SERVER_receive_done (client, | ||
1146 | GNUNET_SYSERR); | ||
1147 | return; | ||
1148 | } | ||
1149 | msize = ntohs (message->size); | ||
1150 | if (msize < sizeof (struct ComputationBobCryptodataMultipartMessage)) | ||
1151 | { | ||
1152 | GNUNET_break (0); | ||
1153 | GNUNET_SERVER_receive_done (client, | ||
1154 | GNUNET_SYSERR); | ||
1155 | return; | ||
1156 | } | ||
1157 | msg = (const struct ComputationBobCryptodataMultipartMessage *) message; | ||
1158 | contained_count = ntohl (msg->element_count_contained); | 1129 | contained_count = ntohl (msg->element_count_contained); |
1159 | |||
1160 | if ( (msize != (sizeof (struct ComputationBobCryptodataMultipartMessage) + | 1130 | if ( (msize != (sizeof (struct ComputationBobCryptodataMultipartMessage) + |
1161 | contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) || | 1131 | contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) || |
1162 | (0 == contained_count) || | 1132 | (0 == contained_count) || |
@@ -1164,18 +1134,38 @@ GSS_handle_alice_client_message_multipart (void *cls, | |||
1164 | (s->total < s->client_received_element_count + contained_count) ) | 1134 | (s->total < s->client_received_element_count + contained_count) ) |
1165 | { | 1135 | { |
1166 | GNUNET_break_op (0); | 1136 | GNUNET_break_op (0); |
1167 | GNUNET_SERVER_receive_done (client, | 1137 | return GNUNET_SYSERR; |
1168 | GNUNET_SYSERR); | ||
1169 | return; | ||
1170 | } | 1138 | } |
1139 | return GNUNET_OK; | ||
1140 | } | ||
1141 | |||
1142 | |||
1143 | /** | ||
1144 | * We're receiving additional set data. Add it to our | ||
1145 | * set and if we are done, initiate the transaction. | ||
1146 | * | ||
1147 | * @param cls client identification of the client | ||
1148 | * @param msg the actual message | ||
1149 | */ | ||
1150 | static void | ||
1151 | handle_alice_client_message_multipart (void *cls, | ||
1152 | const struct ComputationBobCryptodataMultipartMessage *msg) | ||
1153 | { | ||
1154 | struct AliceServiceSession *s = cls; | ||
1155 | uint32_t contained_count; | ||
1156 | const struct GNUNET_SCALARPRODUCT_Element *elements; | ||
1157 | struct GNUNET_SET_Element set_elem; | ||
1158 | struct GNUNET_SCALARPRODUCT_Element *elem; | ||
1159 | |||
1160 | contained_count = ntohl (msg->element_count_contained); | ||
1171 | s->client_received_element_count += contained_count; | 1161 | s->client_received_element_count += contained_count; |
1172 | elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; | 1162 | elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; |
1173 | for (i = 0; i < contained_count; i++) | 1163 | for (uint32_t i = 0; i < contained_count; i++) |
1174 | { | 1164 | { |
1175 | elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); | 1165 | elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); |
1176 | GNUNET_memcpy (elem, | 1166 | GNUNET_memcpy (elem, |
1177 | &elements[i], | 1167 | &elements[i], |
1178 | sizeof (struct GNUNET_SCALARPRODUCT_Element)); | 1168 | sizeof (struct GNUNET_SCALARPRODUCT_Element)); |
1179 | if (GNUNET_SYSERR == | 1169 | if (GNUNET_SYSERR == |
1180 | GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, | 1170 | GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, |
1181 | &elem->key, | 1171 | &elem->key, |
@@ -1194,8 +1184,7 @@ GSS_handle_alice_client_message_multipart (void *cls, | |||
1194 | NULL, NULL); | 1184 | NULL, NULL); |
1195 | s->used_element_count++; | 1185 | s->used_element_count++; |
1196 | } | 1186 | } |
1197 | GNUNET_SERVER_receive_done (client, | 1187 | GNUNET_SERVICE_client_continue (s->client); |
1198 | GNUNET_OK); | ||
1199 | if (s->total != s->client_received_element_count) | 1188 | if (s->total != s->client_received_element_count) |
1200 | { | 1189 | { |
1201 | /* more to come */ | 1190 | /* more to come */ |
@@ -1207,45 +1196,29 @@ GSS_handle_alice_client_message_multipart (void *cls, | |||
1207 | 1196 | ||
1208 | /** | 1197 | /** |
1209 | * Handler for Alice's client request message. | 1198 | * Handler for Alice's client request message. |
1210 | * We are doing request-initiation to compute a scalar product with a peer. | 1199 | * Check that @a msg is well-formed. |
1211 | * | 1200 | * |
1212 | * @param cls closure | 1201 | * @param cls identification of the client |
1213 | * @param client identification of the client | 1202 | * @param msg the actual message |
1214 | * @param message the actual message | 1203 | * @return #GNUNET_OK if @a msg is well-formed |
1215 | */ | 1204 | */ |
1216 | static void | 1205 | static int |
1217 | GSS_handle_alice_client_message (void *cls, | 1206 | check_alice_client_message (void *cls, |
1218 | struct GNUNET_SERVER_Client *client, | 1207 | const struct AliceComputationMessage *msg) |
1219 | const struct GNUNET_MessageHeader *message) | ||
1220 | { | 1208 | { |
1221 | const struct AliceComputationMessage *msg; | 1209 | struct AliceServiceSession *s = cls; |
1222 | struct AliceServiceSession *s; | ||
1223 | uint32_t contained_count; | ||
1224 | uint32_t total_count; | ||
1225 | const struct GNUNET_SCALARPRODUCT_Element *elements; | ||
1226 | uint32_t i; | ||
1227 | uint16_t msize; | 1210 | uint16_t msize; |
1228 | struct GNUNET_SET_Element set_elem; | 1211 | uint32_t total_count; |
1229 | struct GNUNET_SCALARPRODUCT_Element *elem; | 1212 | uint32_t contained_count; |
1230 | 1213 | ||
1231 | s = GNUNET_SERVER_client_get_user_context (client, | 1214 | if (NULL != s->intersected_elements) |
1232 | struct AliceServiceSession); | ||
1233 | if (NULL != s) | ||
1234 | { | 1215 | { |
1235 | /* only one concurrent session per client connection allowed, | 1216 | /* only one concurrent session per client connection allowed, |
1236 | simplifies logic a lot... */ | 1217 | simplifies logic a lot... */ |
1237 | GNUNET_break (0); | 1218 | GNUNET_break (0); |
1238 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1219 | return GNUNET_SYSERR; |
1239 | return; | ||
1240 | } | ||
1241 | msize = ntohs (message->size); | ||
1242 | if (msize < sizeof (struct AliceComputationMessage)) | ||
1243 | { | ||
1244 | GNUNET_break (0); | ||
1245 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
1246 | return; | ||
1247 | } | 1220 | } |
1248 | msg = (const struct AliceComputationMessage *) message; | 1221 | msize = ntohs (msg->header.size); |
1249 | total_count = ntohl (msg->element_count_total); | 1222 | total_count = ntohl (msg->element_count_total); |
1250 | contained_count = ntohl (msg->element_count_contained); | 1223 | contained_count = ntohl (msg->element_count_contained); |
1251 | if ( (0 == total_count) || | 1224 | if ( (0 == total_count) || |
@@ -1254,15 +1227,34 @@ GSS_handle_alice_client_message (void *cls, | |||
1254 | contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) ) | 1227 | contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) ) |
1255 | { | 1228 | { |
1256 | GNUNET_break_op (0); | 1229 | GNUNET_break_op (0); |
1257 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1230 | return GNUNET_SYSERR; |
1258 | return; | ||
1259 | } | 1231 | } |
1232 | return GNUNET_OK; | ||
1233 | } | ||
1260 | 1234 | ||
1261 | s = GNUNET_new (struct AliceServiceSession); | 1235 | |
1236 | /** | ||
1237 | * Handler for Alice's client request message. | ||
1238 | * We are doing request-initiation to compute a scalar product with a peer. | ||
1239 | * | ||
1240 | * @param cls identification of the client | ||
1241 | * @param msg the actual message | ||
1242 | */ | ||
1243 | static void | ||
1244 | handle_alice_client_message (void *cls, | ||
1245 | const struct AliceComputationMessage *msg) | ||
1246 | { | ||
1247 | struct AliceServiceSession *s = cls; | ||
1248 | uint32_t contained_count; | ||
1249 | uint32_t total_count; | ||
1250 | const struct GNUNET_SCALARPRODUCT_Element *elements; | ||
1251 | struct GNUNET_SET_Element set_elem; | ||
1252 | struct GNUNET_SCALARPRODUCT_Element *elem; | ||
1253 | |||
1254 | total_count = ntohl (msg->element_count_total); | ||
1255 | contained_count = ntohl (msg->element_count_contained); | ||
1262 | s->peer = msg->peer; | 1256 | s->peer = msg->peer; |
1263 | s->status = GNUNET_SCALARPRODUCT_STATUS_ACTIVE; | 1257 | s->status = GNUNET_SCALARPRODUCT_STATUS_ACTIVE; |
1264 | s->client = client; | ||
1265 | s->client_mq = GNUNET_MQ_queue_for_server_client (client); | ||
1266 | s->total = total_count; | 1258 | s->total = total_count; |
1267 | s->client_received_element_count = contained_count; | 1259 | s->client_received_element_count = contained_count; |
1268 | s->session_id = msg->session_key; | 1260 | s->session_id = msg->session_key; |
@@ -1271,7 +1263,8 @@ GSS_handle_alice_client_message (void *cls, | |||
1271 | GNUNET_YES); | 1263 | GNUNET_YES); |
1272 | s->intersection_set = GNUNET_SET_create (cfg, | 1264 | s->intersection_set = GNUNET_SET_create (cfg, |
1273 | GNUNET_SET_OPERATION_INTERSECTION); | 1265 | GNUNET_SET_OPERATION_INTERSECTION); |
1274 | for (i = 0; i < contained_count; i++) | 1266 | |
1267 | for (uint32_t i = 0; i < contained_count; i++) | ||
1275 | { | 1268 | { |
1276 | if (0 == GNUNET_ntohll (elements[i].value)) | 1269 | if (0 == GNUNET_ntohll (elements[i].value)) |
1277 | continue; | 1270 | continue; |
@@ -1298,10 +1291,7 @@ GSS_handle_alice_client_message (void *cls, | |||
1298 | NULL, NULL); | 1291 | NULL, NULL); |
1299 | s->used_element_count++; | 1292 | s->used_element_count++; |
1300 | } | 1293 | } |
1301 | GNUNET_SERVER_client_set_user_context (client, | 1294 | GNUNET_SERVICE_client_continue (s->client); |
1302 | s); | ||
1303 | GNUNET_SERVER_receive_done (client, | ||
1304 | GNUNET_OK); | ||
1305 | if (s->total != s->client_received_element_count) | 1295 | if (s->total != s->client_received_element_count) |
1306 | { | 1296 | { |
1307 | /* wait for multipart msg */ | 1297 | /* wait for multipart msg */ |
@@ -1331,6 +1321,30 @@ shutdown_task (void *cls) | |||
1331 | 1321 | ||
1332 | 1322 | ||
1333 | /** | 1323 | /** |
1324 | * A client connected. | ||
1325 | * | ||
1326 | * Setup the associated data structure. | ||
1327 | * | ||
1328 | * @param cls closure, NULL | ||
1329 | * @param client identification of the client | ||
1330 | * @param mq message queue to communicate with @a client | ||
1331 | * @return our `struct AliceServiceSession` | ||
1332 | */ | ||
1333 | static void * | ||
1334 | client_connect_cb (void *cls, | ||
1335 | struct GNUNET_SERVICE_Client *client, | ||
1336 | struct GNUNET_MQ_Handle *mq) | ||
1337 | { | ||
1338 | struct AliceServiceSession *s; | ||
1339 | |||
1340 | s = GNUNET_new (struct AliceServiceSession); | ||
1341 | s->client = client; | ||
1342 | s->client_mq = mq; | ||
1343 | return s; | ||
1344 | } | ||
1345 | |||
1346 | |||
1347 | /** | ||
1334 | * A client disconnected. | 1348 | * A client disconnected. |
1335 | * | 1349 | * |
1336 | * Remove the associated session(s), release data structures | 1350 | * Remove the associated session(s), release data structures |
@@ -1338,25 +1352,20 @@ shutdown_task (void *cls) | |||
1338 | * | 1352 | * |
1339 | * @param cls closure, NULL | 1353 | * @param cls closure, NULL |
1340 | * @param client identification of the client | 1354 | * @param client identification of the client |
1355 | * @param app_cls our `struct AliceServiceSession` | ||
1341 | */ | 1356 | */ |
1342 | static void | 1357 | static void |
1343 | handle_client_disconnect (void *cls, | 1358 | client_disconnect_cb (void *cls, |
1344 | struct GNUNET_SERVER_Client *client) | 1359 | struct GNUNET_SERVICE_Client *client, |
1360 | void *app_cls) | ||
1345 | { | 1361 | { |
1346 | struct AliceServiceSession *s; | 1362 | struct AliceServiceSession *s = app_cls; |
1347 | 1363 | ||
1348 | if (NULL == client) | ||
1349 | return; | ||
1350 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1364 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1351 | "Client %p disconnected from us.\n", | 1365 | "Client %p disconnected from us.\n", |
1352 | client); | 1366 | client); |
1353 | s = GNUNET_SERVER_client_get_user_context (client, | ||
1354 | struct AliceServiceSession); | ||
1355 | if (NULL == s) | ||
1356 | return; | ||
1357 | s->client = NULL; | 1367 | s->client = NULL; |
1358 | GNUNET_SERVER_client_set_user_context (client, | 1368 | s->client_mq = NULL; |
1359 | NULL); | ||
1360 | destroy_service_session (s); | 1369 | destroy_service_session (s); |
1361 | } | 1370 | } |
1362 | 1371 | ||
@@ -1365,13 +1374,13 @@ handle_client_disconnect (void *cls, | |||
1365 | * Initialization of the program and message handlers | 1374 | * Initialization of the program and message handlers |
1366 | * | 1375 | * |
1367 | * @param cls closure | 1376 | * @param cls closure |
1368 | * @param server the initialized server | ||
1369 | * @param c configuration to use | 1377 | * @param c configuration to use |
1378 | * @param service the initialized service | ||
1370 | */ | 1379 | */ |
1371 | static void | 1380 | static void |
1372 | run (void *cls, | 1381 | run (void *cls, |
1373 | struct GNUNET_SERVER_Handle *server, | 1382 | const struct GNUNET_CONFIGURATION_Handle *c, |
1374 | const struct GNUNET_CONFIGURATION_Handle *c) | 1383 | struct GNUNET_SERVICE_Handle *service) |
1375 | { | 1384 | { |
1376 | static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = { | 1385 | static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = { |
1377 | { &handle_bobs_cryptodata_message, | 1386 | { &handle_bobs_cryptodata_message, |
@@ -1382,15 +1391,6 @@ run (void *cls, | |||
1382 | 0}, | 1391 | 0}, |
1383 | { NULL, 0, 0} | 1392 | { NULL, 0, 0} |
1384 | }; | 1393 | }; |
1385 | static const struct GNUNET_SERVER_MessageHandler server_handlers[] = { | ||
1386 | { &GSS_handle_alice_client_message, NULL, | ||
1387 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE, | ||
1388 | 0}, | ||
1389 | { &GSS_handle_alice_client_message_multipart, NULL, | ||
1390 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE, | ||
1391 | 0}, | ||
1392 | { NULL, NULL, 0, 0} | ||
1393 | }; | ||
1394 | 1394 | ||
1395 | cfg = c; | 1395 | cfg = c; |
1396 | /* | 1396 | /* |
@@ -1403,14 +1403,12 @@ run (void *cls, | |||
1403 | 1403 | ||
1404 | GNUNET_CRYPTO_paillier_create (&my_pubkey, | 1404 | GNUNET_CRYPTO_paillier_create (&my_pubkey, |
1405 | &my_privkey); | 1405 | &my_privkey); |
1406 | GNUNET_SERVER_add_handlers (server, | 1406 | my_cadet = GNUNET_CADET_connect (cfg, |
1407 | server_handlers); | 1407 | NULL, |
1408 | GNUNET_SERVER_disconnect_notify (server, | ||
1409 | &handle_client_disconnect, | ||
1410 | NULL); | ||
1411 | my_cadet = GNUNET_CADET_connect (cfg, NULL, | ||
1412 | &cb_channel_destruction, | 1408 | &cb_channel_destruction, |
1413 | cadet_handlers); | 1409 | cadet_handlers); |
1410 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | ||
1411 | NULL); | ||
1414 | if (NULL == my_cadet) | 1412 | if (NULL == my_cadet) |
1415 | { | 1413 | { |
1416 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1414 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -1418,28 +1416,28 @@ run (void *cls, | |||
1418 | GNUNET_SCHEDULER_shutdown (); | 1416 | GNUNET_SCHEDULER_shutdown (); |
1419 | return; | 1417 | return; |
1420 | } | 1418 | } |
1421 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | ||
1422 | NULL); | ||
1423 | |||
1424 | } | 1419 | } |
1425 | 1420 | ||
1426 | 1421 | ||
1427 | /** | 1422 | /** |
1428 | * The main function for the scalarproduct service. | 1423 | * Define "main" method using service macro. |
1429 | * | ||
1430 | * @param argc number of arguments from the command line | ||
1431 | * @param argv command line arguments | ||
1432 | * @return 0 ok, 1 on error | ||
1433 | */ | 1424 | */ |
1434 | int | 1425 | GNUNET_SERVICE_MAIN |
1435 | main (int argc, | 1426 | ("scalarproduct-alice", |
1436 | char *const *argv) | 1427 | GNUNET_SERVICE_OPTION_NONE, |
1437 | { | 1428 | &run, |
1438 | return (GNUNET_OK == | 1429 | &client_connect_cb, |
1439 | GNUNET_SERVICE_run (argc, argv, | 1430 | &client_disconnect_cb, |
1440 | "scalarproduct-alice", | 1431 | NULL, |
1441 | GNUNET_SERVICE_OPTION_NONE, | 1432 | GNUNET_MQ_hd_var_size (alice_client_message, |
1442 | &run, NULL)) ? 0 : 1; | 1433 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE, |
1443 | } | 1434 | struct AliceComputationMessage, |
1435 | NULL), | ||
1436 | GNUNET_MQ_hd_var_size (alice_client_message_multipart, | ||
1437 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE, | ||
1438 | struct ComputationBobCryptodataMultipartMessage, | ||
1439 | NULL), | ||
1440 | GNUNET_MQ_handler_end ()); | ||
1441 | |||
1444 | 1442 | ||
1445 | /* end of gnunet-service-scalarproduct_alice.c */ | 1443 | /* end of gnunet-service-scalarproduct_alice.c */ |
diff --git a/src/scalarproduct/gnunet-service-scalarproduct_bob.c b/src/scalarproduct/gnunet-service-scalarproduct_bob.c index a19c909e1..56cb91fe5 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct_bob.c +++ b/src/scalarproduct/gnunet-service-scalarproduct_bob.c | |||
@@ -79,7 +79,7 @@ struct BobServiceSession | |||
79 | /** | 79 | /** |
80 | * The client this request is related to. | 80 | * The client this request is related to. |
81 | */ | 81 | */ |
82 | struct GNUNET_SERVER_Client *client; | 82 | struct GNUNET_SERVICE_Client *client; |
83 | 83 | ||
84 | /** | 84 | /** |
85 | * Client message queue. | 85 | * Client message queue. |
@@ -354,15 +354,12 @@ destroy_service_session (struct BobServiceSession *s) | |||
354 | s->cadet = NULL; | 354 | s->cadet = NULL; |
355 | destroy_cadet_session (in); | 355 | destroy_cadet_session (in); |
356 | } | 356 | } |
357 | if (NULL != s->client_mq) | ||
358 | { | ||
359 | GNUNET_MQ_destroy (s->client_mq); | ||
360 | s->client_mq = NULL; | ||
361 | } | ||
362 | if (NULL != s->client) | 357 | if (NULL != s->client) |
363 | { | 358 | { |
364 | GNUNET_SERVER_client_disconnect (s->client); | 359 | struct GNUNET_SERVICE_Client *c = s->client; |
360 | |||
365 | s->client = NULL; | 361 | s->client = NULL; |
362 | GNUNET_SERVICE_client_drop (c); | ||
366 | } | 363 | } |
367 | GNUNET_assert (GNUNET_YES == | 364 | GNUNET_assert (GNUNET_YES == |
368 | GNUNET_CONTAINER_multihashmap_remove (client_sessions, | 365 | GNUNET_CONTAINER_multihashmap_remove (client_sessions, |
@@ -634,11 +631,11 @@ transmit_bobs_cryptodata_message (struct BobServiceSession *s) | |||
634 | 631 | ||
635 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; | 632 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; |
636 | GNUNET_memcpy (&payload[0], | 633 | GNUNET_memcpy (&payload[0], |
637 | &s->s, | 634 | &s->s, |
638 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 635 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); |
639 | GNUNET_memcpy (&payload[1], | 636 | GNUNET_memcpy (&payload[1], |
640 | &s->s_prime, | 637 | &s->s_prime, |
641 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 638 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); |
642 | 639 | ||
643 | payload = &payload[2]; | 640 | payload = &payload[2]; |
644 | // convert k[][] | 641 | // convert k[][] |
@@ -998,8 +995,8 @@ handle_alices_cryptodata_message (void *cls, | |||
998 | s->e_a = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * | 995 | s->e_a = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * |
999 | max); | 996 | max); |
1000 | GNUNET_memcpy (&s->e_a[s->cadet_received_element_count], | 997 | GNUNET_memcpy (&s->e_a[s->cadet_received_element_count], |
1001 | payload, | 998 | payload, |
1002 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * contained_elements); | 999 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * contained_elements); |
1003 | s->cadet_received_element_count += contained_elements; | 1000 | s->cadet_received_element_count += contained_elements; |
1004 | 1001 | ||
1005 | if ( (s->cadet_received_element_count == max) && | 1002 | if ( (s->cadet_received_element_count == max) && |
@@ -1209,49 +1206,24 @@ cb_channel_incoming (void *cls, | |||
1209 | } | 1206 | } |
1210 | 1207 | ||
1211 | 1208 | ||
1209 | |||
1212 | /** | 1210 | /** |
1213 | * We're receiving additional set data. Add it to our | 1211 | * We're receiving additional set data. Check it is well-formed. |
1214 | * set and if we are done, initiate the transaction. | ||
1215 | * | 1212 | * |
1216 | * @param cls closure | 1213 | * @param cls identification of the client |
1217 | * @param client identification of the client | 1214 | * @param msg the actual message |
1218 | * @param message the actual message | 1215 | * @return #GNUNET_OK if @a msg is well-formed |
1219 | */ | 1216 | */ |
1220 | static void | 1217 | static int |
1221 | GSS_handle_bob_client_message_multipart (void *cls, | 1218 | check_bob_client_message_multipart (void *cls, |
1222 | struct GNUNET_SERVER_Client *client, | 1219 | const struct ComputationBobCryptodataMultipartMessage *msg) |
1223 | const struct GNUNET_MessageHeader *message) | ||
1224 | { | 1220 | { |
1225 | const struct ComputationBobCryptodataMultipartMessage * msg; | 1221 | struct BobServiceSession *s = cls; |
1226 | struct BobServiceSession *s; | ||
1227 | uint32_t contained_count; | 1222 | uint32_t contained_count; |
1228 | const struct GNUNET_SCALARPRODUCT_Element *elements; | ||
1229 | uint32_t i; | ||
1230 | uint16_t msize; | 1223 | uint16_t msize; |
1231 | struct GNUNET_SET_Element set_elem; | ||
1232 | struct GNUNET_SCALARPRODUCT_Element *elem; | ||
1233 | 1224 | ||
1234 | s = GNUNET_SERVER_client_get_user_context (client, | 1225 | msize = ntohs (msg->header.size); |
1235 | struct BobServiceSession); | ||
1236 | if (NULL == s) | ||
1237 | { | ||
1238 | /* session needs to already exist */ | ||
1239 | GNUNET_break (0); | ||
1240 | GNUNET_SERVER_receive_done (client, | ||
1241 | GNUNET_SYSERR); | ||
1242 | return; | ||
1243 | } | ||
1244 | msize = ntohs (message->size); | ||
1245 | if (msize < sizeof (struct ComputationBobCryptodataMultipartMessage)) | ||
1246 | { | ||
1247 | GNUNET_break (0); | ||
1248 | GNUNET_SERVER_receive_done (client, | ||
1249 | GNUNET_SYSERR); | ||
1250 | return; | ||
1251 | } | ||
1252 | msg = (const struct ComputationBobCryptodataMultipartMessage *) message; | ||
1253 | contained_count = ntohl (msg->element_count_contained); | 1226 | contained_count = ntohl (msg->element_count_contained); |
1254 | |||
1255 | if ( (msize != (sizeof (struct ComputationBobCryptodataMultipartMessage) + | 1227 | if ( (msize != (sizeof (struct ComputationBobCryptodataMultipartMessage) + |
1256 | contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) || | 1228 | contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) || |
1257 | (0 == contained_count) || | 1229 | (0 == contained_count) || |
@@ -1259,18 +1231,38 @@ GSS_handle_bob_client_message_multipart (void *cls, | |||
1259 | (s->total == s->client_received_element_count) || | 1231 | (s->total == s->client_received_element_count) || |
1260 | (s->total < s->client_received_element_count + contained_count) ) | 1232 | (s->total < s->client_received_element_count + contained_count) ) |
1261 | { | 1233 | { |
1262 | GNUNET_break_op (0); | 1234 | GNUNET_break (0); |
1263 | GNUNET_SERVER_receive_done (client, | 1235 | return GNUNET_SYSERR; |
1264 | GNUNET_SYSERR); | ||
1265 | return; | ||
1266 | } | 1236 | } |
1237 | return GNUNET_OK; | ||
1238 | } | ||
1239 | |||
1240 | |||
1241 | /** | ||
1242 | * We're receiving additional set data. Add it to our | ||
1243 | * set and if we are done, initiate the transaction. | ||
1244 | * | ||
1245 | * @param cls identification of the client | ||
1246 | * @param msg the actual message | ||
1247 | */ | ||
1248 | static void | ||
1249 | handle_bob_client_message_multipart (void *cls, | ||
1250 | const struct ComputationBobCryptodataMultipartMessage *msg) | ||
1251 | { | ||
1252 | struct BobServiceSession *s = cls; | ||
1253 | uint32_t contained_count; | ||
1254 | const struct GNUNET_SCALARPRODUCT_Element *elements; | ||
1255 | struct GNUNET_SET_Element set_elem; | ||
1256 | struct GNUNET_SCALARPRODUCT_Element *elem; | ||
1257 | |||
1258 | contained_count = ntohl (msg->element_count_contained); | ||
1267 | elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; | 1259 | elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; |
1268 | for (i = 0; i < contained_count; i++) | 1260 | for (uint32_t i = 0; i < contained_count; i++) |
1269 | { | 1261 | { |
1270 | elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); | 1262 | elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); |
1271 | GNUNET_memcpy (elem, | 1263 | GNUNET_memcpy (elem, |
1272 | &elements[i], | 1264 | &elements[i], |
1273 | sizeof (struct GNUNET_SCALARPRODUCT_Element)); | 1265 | sizeof (struct GNUNET_SCALARPRODUCT_Element)); |
1274 | if (GNUNET_SYSERR == | 1266 | if (GNUNET_SYSERR == |
1275 | GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, | 1267 | GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, |
1276 | &elem->key, | 1268 | &elem->key, |
@@ -1289,8 +1281,7 @@ GSS_handle_bob_client_message_multipart (void *cls, | |||
1289 | NULL, NULL); | 1281 | NULL, NULL); |
1290 | } | 1282 | } |
1291 | s->client_received_element_count += contained_count; | 1283 | s->client_received_element_count += contained_count; |
1292 | GNUNET_SERVER_receive_done (client, | 1284 | GNUNET_SERVICE_client_continue (s->client); |
1293 | GNUNET_OK); | ||
1294 | if (s->total != s->client_received_element_count) | 1285 | if (s->total != s->client_received_element_count) |
1295 | { | 1286 | { |
1296 | /* more to come */ | 1287 | /* more to come */ |
@@ -1306,50 +1297,28 @@ GSS_handle_bob_client_message_multipart (void *cls, | |||
1306 | 1297 | ||
1307 | 1298 | ||
1308 | /** | 1299 | /** |
1309 | * Handler for Bob's a client request message. Bob is in the response | 1300 | * Handler for Bob's a client request message. Check @a msg is |
1310 | * role, keep the values + session and waiting for a matching session | 1301 | * well-formed. |
1311 | * or process a waiting request from Alice. | ||
1312 | * | 1302 | * |
1313 | * @param cls closure | 1303 | * @param cls identification of the client |
1314 | * @param client identification of the client | 1304 | * @param msg the actual message |
1315 | * @param message the actual message | 1305 | * @return #GNUNET_OK if @a msg is well-formed |
1316 | */ | 1306 | */ |
1317 | static void | 1307 | static int |
1318 | GSS_handle_bob_client_message (void *cls, | 1308 | check_bob_client_message (void *cls, |
1319 | struct GNUNET_SERVER_Client *client, | 1309 | const struct BobComputationMessage *msg) |
1320 | const struct GNUNET_MessageHeader *message) | ||
1321 | { | 1310 | { |
1322 | const struct BobComputationMessage *msg; | 1311 | struct BobServiceSession *s = cls; |
1323 | struct BobServiceSession *s; | ||
1324 | struct CadetIncomingSession *in; | ||
1325 | uint32_t contained_count; | 1312 | uint32_t contained_count; |
1326 | uint32_t total_count; | 1313 | uint32_t total_count; |
1327 | const struct GNUNET_SCALARPRODUCT_Element *elements; | ||
1328 | uint32_t i; | ||
1329 | struct GNUNET_SET_Element set_elem; | ||
1330 | struct GNUNET_SCALARPRODUCT_Element *elem; | ||
1331 | uint16_t msize; | 1314 | uint16_t msize; |
1332 | 1315 | ||
1333 | s = GNUNET_SERVER_client_get_user_context (client, | 1316 | if (GNUNET_SCALARPRODUCT_STATUS_INIT != s->status) |
1334 | struct BobServiceSession); | ||
1335 | if (NULL != s) | ||
1336 | { | 1317 | { |
1337 | /* only one concurrent session per client connection allowed, | ||
1338 | simplifies logic a lot... */ | ||
1339 | GNUNET_break (0); | 1318 | GNUNET_break (0); |
1340 | GNUNET_SERVER_receive_done (client, | 1319 | return GNUNET_SYSERR; |
1341 | GNUNET_SYSERR); | ||
1342 | return; | ||
1343 | } | ||
1344 | msize = ntohs (message->size); | ||
1345 | if (msize < sizeof (struct BobComputationMessage)) | ||
1346 | { | ||
1347 | GNUNET_break (0); | ||
1348 | GNUNET_SERVER_receive_done (client, | ||
1349 | GNUNET_SYSERR); | ||
1350 | return; | ||
1351 | } | 1320 | } |
1352 | msg = (const struct BobComputationMessage *) message; | 1321 | msize = ntohs (msg->header.size); |
1353 | total_count = ntohl (msg->element_count_total); | 1322 | total_count = ntohl (msg->element_count_total); |
1354 | contained_count = ntohl (msg->element_count_contained); | 1323 | contained_count = ntohl (msg->element_count_contained); |
1355 | if ( (0 == total_count) || | 1324 | if ( (0 == total_count) || |
@@ -1359,15 +1328,41 @@ GSS_handle_bob_client_message (void *cls, | |||
1359 | contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) ) | 1328 | contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) ) |
1360 | { | 1329 | { |
1361 | GNUNET_break_op (0); | 1330 | GNUNET_break_op (0); |
1362 | GNUNET_SERVER_receive_done (client, | 1331 | return GNUNET_SYSERR; |
1363 | GNUNET_SYSERR); | ||
1364 | return; | ||
1365 | } | 1332 | } |
1333 | if (NULL != find_matching_client_session (&msg->session_key)) | ||
1334 | { | ||
1335 | GNUNET_break (0); | ||
1336 | return GNUNET_SYSERR; | ||
1337 | } | ||
1338 | return GNUNET_OK; | ||
1339 | } | ||
1340 | |||
1341 | |||
1342 | /** | ||
1343 | * Handler for Bob's a client request message. Bob is in the response | ||
1344 | * role, keep the values + session and waiting for a matching session | ||
1345 | * or process a waiting request from Alice. | ||
1346 | * | ||
1347 | * @param cls identification of the client | ||
1348 | * @param msg the actual message | ||
1349 | */ | ||
1350 | static void | ||
1351 | handle_bob_client_message (void *cls, | ||
1352 | const struct BobComputationMessage *msg) | ||
1353 | { | ||
1354 | struct BobServiceSession *s = cls; | ||
1355 | struct CadetIncomingSession *in; | ||
1356 | uint32_t contained_count; | ||
1357 | uint32_t total_count; | ||
1358 | const struct GNUNET_SCALARPRODUCT_Element *elements; | ||
1359 | struct GNUNET_SET_Element set_elem; | ||
1360 | struct GNUNET_SCALARPRODUCT_Element *elem; | ||
1361 | |||
1362 | total_count = ntohl (msg->element_count_total); | ||
1363 | contained_count = ntohl (msg->element_count_contained); | ||
1366 | 1364 | ||
1367 | s = GNUNET_new (struct BobServiceSession); | ||
1368 | s->status = GNUNET_SCALARPRODUCT_STATUS_ACTIVE; | 1365 | s->status = GNUNET_SCALARPRODUCT_STATUS_ACTIVE; |
1369 | s->client = client; | ||
1370 | s->client_mq = GNUNET_MQ_queue_for_server_client (client); | ||
1371 | s->total = total_count; | 1366 | s->total = total_count; |
1372 | s->client_received_element_count = contained_count; | 1367 | s->client_received_element_count = contained_count; |
1373 | s->session_id = msg->session_key; | 1368 | s->session_id = msg->session_key; |
@@ -1378,23 +1373,22 @@ GSS_handle_bob_client_message (void *cls, | |||
1378 | if (NULL == s->port) | 1373 | if (NULL == s->port) |
1379 | { | 1374 | { |
1380 | GNUNET_break (0); | 1375 | GNUNET_break (0); |
1381 | GNUNET_SERVER_receive_done (client, | 1376 | GNUNET_SERVICE_client_drop (s->client); |
1382 | GNUNET_SYSERR); | ||
1383 | GNUNET_free (s); | ||
1384 | return; | 1377 | return; |
1385 | } | 1378 | } |
1386 | |||
1387 | GNUNET_break (GNUNET_YES == | 1379 | GNUNET_break (GNUNET_YES == |
1388 | GNUNET_CONTAINER_multihashmap_put (client_sessions, | 1380 | GNUNET_CONTAINER_multihashmap_put (client_sessions, |
1389 | &s->session_id, | 1381 | &s->session_id, |
1390 | s, | 1382 | s, |
1391 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1383 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
1392 | elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; | 1384 | elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; |
1393 | s->intersected_elements = GNUNET_CONTAINER_multihashmap_create (s->total, | 1385 | s->intersected_elements |
1394 | GNUNET_YES); | 1386 | = GNUNET_CONTAINER_multihashmap_create (s->total, |
1395 | s->intersection_set = GNUNET_SET_create (cfg, | 1387 | GNUNET_YES); |
1396 | GNUNET_SET_OPERATION_INTERSECTION); | 1388 | s->intersection_set |
1397 | for (i = 0; i < contained_count; i++) | 1389 | = GNUNET_SET_create (cfg, |
1390 | GNUNET_SET_OPERATION_INTERSECTION); | ||
1391 | for (uint32_t i = 0; i < contained_count; i++) | ||
1398 | { | 1392 | { |
1399 | if (0 == GNUNET_ntohll (elements[i].value)) | 1393 | if (0 == GNUNET_ntohll (elements[i].value)) |
1400 | continue; | 1394 | continue; |
@@ -1420,10 +1414,7 @@ GSS_handle_bob_client_message (void *cls, | |||
1420 | NULL, NULL); | 1414 | NULL, NULL); |
1421 | s->used_element_count++; | 1415 | s->used_element_count++; |
1422 | } | 1416 | } |
1423 | GNUNET_SERVER_client_set_user_context (client, | 1417 | GNUNET_SERVICE_client_continue (s->client); |
1424 | s); | ||
1425 | GNUNET_SERVER_receive_done (client, | ||
1426 | GNUNET_YES); | ||
1427 | if (s->total != s->client_received_element_count) | 1418 | if (s->total != s->client_received_element_count) |
1428 | { | 1419 | { |
1429 | /* multipart msg */ | 1420 | /* multipart msg */ |
@@ -1467,6 +1458,30 @@ shutdown_task (void *cls) | |||
1467 | 1458 | ||
1468 | 1459 | ||
1469 | /** | 1460 | /** |
1461 | * A client connected. | ||
1462 | * | ||
1463 | * Setup the associated data structure. | ||
1464 | * | ||
1465 | * @param cls closure, NULL | ||
1466 | * @param client identification of the client | ||
1467 | * @param mq message queue to communicate with @a client | ||
1468 | * @return our `struct BobServiceSession` | ||
1469 | */ | ||
1470 | static void * | ||
1471 | client_connect_cb (void *cls, | ||
1472 | struct GNUNET_SERVICE_Client *client, | ||
1473 | struct GNUNET_MQ_Handle *mq) | ||
1474 | { | ||
1475 | struct BobServiceSession *s; | ||
1476 | |||
1477 | s = GNUNET_new (struct BobServiceSession); | ||
1478 | s->client = client; | ||
1479 | s->client_mq = mq; | ||
1480 | return s; | ||
1481 | } | ||
1482 | |||
1483 | |||
1484 | /** | ||
1470 | * A client disconnected. | 1485 | * A client disconnected. |
1471 | * | 1486 | * |
1472 | * Remove the associated session(s), release data structures | 1487 | * Remove the associated session(s), release data structures |
@@ -1474,21 +1489,17 @@ shutdown_task (void *cls) | |||
1474 | * | 1489 | * |
1475 | * @param cls closure, NULL | 1490 | * @param cls closure, NULL |
1476 | * @param client identification of the client | 1491 | * @param client identification of the client |
1492 | * @param app_cls our `struct BobServiceSession` | ||
1477 | */ | 1493 | */ |
1478 | static void | 1494 | static void |
1479 | handle_client_disconnect (void *cls, | 1495 | client_disconnect_cb (void *cls, |
1480 | struct GNUNET_SERVER_Client *client) | 1496 | struct GNUNET_SERVICE_Client *client, |
1497 | void *app_cls) | ||
1481 | { | 1498 | { |
1482 | struct BobServiceSession *s; | 1499 | struct BobServiceSession *s = app_cls; |
1483 | 1500 | ||
1484 | if (NULL == client) | ||
1485 | return; | ||
1486 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1501 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1487 | "Client disconnected from us.\n"); | 1502 | "Client disconnected from us.\n"); |
1488 | s = GNUNET_SERVER_client_get_user_context (client, | ||
1489 | struct BobServiceSession); | ||
1490 | if (NULL == s) | ||
1491 | return; | ||
1492 | s->client = NULL; | 1503 | s->client = NULL; |
1493 | destroy_service_session (s); | 1504 | destroy_service_session (s); |
1494 | } | 1505 | } |
@@ -1498,23 +1509,14 @@ handle_client_disconnect (void *cls, | |||
1498 | * Initialization of the program and message handlers | 1509 | * Initialization of the program and message handlers |
1499 | * | 1510 | * |
1500 | * @param cls closure | 1511 | * @param cls closure |
1501 | * @param server the initialized server | ||
1502 | * @param c configuration to use | 1512 | * @param c configuration to use |
1513 | * @param service the initialized service | ||
1503 | */ | 1514 | */ |
1504 | static void | 1515 | static void |
1505 | run (void *cls, | 1516 | run (void *cls, |
1506 | struct GNUNET_SERVER_Handle *server, | 1517 | const struct GNUNET_CONFIGURATION_Handle *c, |
1507 | const struct GNUNET_CONFIGURATION_Handle *c) | 1518 | struct GNUNET_SERVICE_Handle *service) |
1508 | { | 1519 | { |
1509 | static const struct GNUNET_SERVER_MessageHandler server_handlers[] = { | ||
1510 | { &GSS_handle_bob_client_message, NULL, | ||
1511 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_BOB, | ||
1512 | 0}, | ||
1513 | { &GSS_handle_bob_client_message_multipart, NULL, | ||
1514 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_BOB, | ||
1515 | 0}, | ||
1516 | { NULL, NULL, 0, 0} | ||
1517 | }; | ||
1518 | static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = { | 1520 | static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = { |
1519 | { &handle_alices_computation_request, | 1521 | { &handle_alices_computation_request, |
1520 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SESSION_INITIALIZATION, | 1522 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SESSION_INITIALIZATION, |
@@ -1536,11 +1538,6 @@ run (void *cls, | |||
1536 | 1538 | ||
1537 | GNUNET_CRYPTO_paillier_create (&my_pubkey, | 1539 | GNUNET_CRYPTO_paillier_create (&my_pubkey, |
1538 | &my_privkey); | 1540 | &my_privkey); |
1539 | GNUNET_SERVER_add_handlers (server, | ||
1540 | server_handlers); | ||
1541 | GNUNET_SERVER_disconnect_notify (server, | ||
1542 | &handle_client_disconnect, | ||
1543 | NULL); | ||
1544 | client_sessions = GNUNET_CONTAINER_multihashmap_create (128, | 1541 | client_sessions = GNUNET_CONTAINER_multihashmap_create (128, |
1545 | GNUNET_YES); | 1542 | GNUNET_YES); |
1546 | cadet_sessions = GNUNET_CONTAINER_multihashmap_create (128, | 1543 | cadet_sessions = GNUNET_CONTAINER_multihashmap_create (128, |
@@ -1548,6 +1545,8 @@ run (void *cls, | |||
1548 | my_cadet = GNUNET_CADET_connect (cfg, NULL, | 1545 | my_cadet = GNUNET_CADET_connect (cfg, NULL, |
1549 | &cb_channel_destruction, | 1546 | &cb_channel_destruction, |
1550 | cadet_handlers); | 1547 | cadet_handlers); |
1548 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | ||
1549 | NULL); | ||
1551 | if (NULL == my_cadet) | 1550 | if (NULL == my_cadet) |
1552 | { | 1551 | { |
1553 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1552 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -1555,27 +1554,28 @@ run (void *cls, | |||
1555 | GNUNET_SCHEDULER_shutdown (); | 1554 | GNUNET_SCHEDULER_shutdown (); |
1556 | return; | 1555 | return; |
1557 | } | 1556 | } |
1558 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | ||
1559 | NULL); | ||
1560 | } | 1557 | } |
1561 | 1558 | ||
1562 | 1559 | ||
1563 | /** | 1560 | /** |
1564 | * The main function for the scalarproduct service. | 1561 | * Define "main" method using service macro. |
1565 | * | ||
1566 | * @param argc number of arguments from the command line | ||
1567 | * @param argv command line arguments | ||
1568 | * @return 0 ok, 1 on error | ||
1569 | */ | 1562 | */ |
1570 | int | 1563 | GNUNET_SERVICE_MAIN |
1571 | main (int argc, | 1564 | ("scalarproduct-bob", |
1572 | char *const *argv) | 1565 | GNUNET_SERVICE_OPTION_NONE, |
1573 | { | 1566 | &run, |
1574 | return (GNUNET_OK == | 1567 | &client_connect_cb, |
1575 | GNUNET_SERVICE_run (argc, argv, | 1568 | &client_disconnect_cb, |
1576 | "scalarproduct-bob", | 1569 | NULL, |
1577 | GNUNET_SERVICE_OPTION_NONE, | 1570 | GNUNET_MQ_hd_var_size (bob_client_message, |
1578 | &run, NULL)) ? 0 : 1; | 1571 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_BOB, |
1579 | } | 1572 | struct BobComputationMessage, |
1573 | NULL), | ||
1574 | GNUNET_MQ_hd_var_size (bob_client_message_multipart, | ||
1575 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_BOB, | ||
1576 | struct ComputationBobCryptodataMultipartMessage, | ||
1577 | NULL), | ||
1578 | GNUNET_MQ_handler_end ()); | ||
1579 | |||
1580 | 1580 | ||
1581 | /* end of gnunet-service-scalarproduct_bob.c */ | 1581 | /* end of gnunet-service-scalarproduct_bob.c */ |