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/gnunet-service-scalarproduct_bob.c | |
parent | a9f53345421cddea37be81e59d6fb56a9f095d6c (diff) | |
download | gnunet-7e835e78aa82869715c9aee96a73ba40aad3f39f.tar.gz gnunet-7e835e78aa82869715c9aee96a73ba40aad3f39f.zip |
convert non-ecc scalarproducts to new service API
Diffstat (limited to 'src/scalarproduct/gnunet-service-scalarproduct_bob.c')
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct_bob.c | 306 |
1 files changed, 153 insertions, 153 deletions
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 */ |