aboutsummaryrefslogtreecommitdiff
path: root/src/set
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-02-16 22:59:53 +0100
committerChristian Grothoff <christian@grothoff.org>2017-02-16 22:59:53 +0100
commita37bee0b9bf81c9a1de295cc8bb747218095942b (patch)
tree0e929174175f2352bf7844d64fbb82084d0102fb /src/set
parentd93370848ef11a11c9091747de5a57819ba8da58 (diff)
downloadgnunet-a37bee0b9bf81c9a1de295cc8bb747218095942b.tar.gz
gnunet-a37bee0b9bf81c9a1de295cc8bb747218095942b.zip
migrate SET service to new SERVICE API
Diffstat (limited to 'src/set')
-rw-r--r--src/set/gnunet-service-set.c386
-rw-r--r--src/set/gnunet-service-set.h2
-rw-r--r--src/set/gnunet-service-set_intersection.c2
-rw-r--r--src/set/gnunet-service-set_union.c2
4 files changed, 200 insertions, 192 deletions
diff --git a/src/set/gnunet-service-set.c b/src/set/gnunet-service-set.c
index e4e2535af..4e2eb6a28 100644
--- a/src/set/gnunet-service-set.c
+++ b/src/set/gnunet-service-set.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2013, 2014 GNUnet e.V. 3 Copyright (C) 2013, 2014, 2017 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -53,7 +53,7 @@ struct Listener
53 * Client that owns the listener. 53 * Client that owns the listener.
54 * Only one client may own a listener. 54 * Only one client may own a listener.
55 */ 55 */
56 struct GNUNET_SERVER_Client *client; 56 struct GNUNET_SERVICE_Client *client;
57 57
58 /** 58 /**
59 * Message queue for the client 59 * Message queue for the client
@@ -157,7 +157,7 @@ struct GNUNET_STATISTICS_Handle *_GSS_statistics;
157 * does not own a set 157 * does not own a set
158 */ 158 */
159static struct Set * 159static struct Set *
160set_get (struct GNUNET_SERVER_Client *client) 160set_get (struct GNUNET_SERVICE_Client *client)
161{ 161{
162 struct Set *set; 162 struct Set *set;
163 163
@@ -176,7 +176,7 @@ set_get (struct GNUNET_SERVER_Client *client)
176 * if there isn't any 176 * if there isn't any
177 */ 177 */
178static struct Listener * 178static struct Listener *
179listener_get (struct GNUNET_SERVER_Client *client) 179listener_get (struct GNUNET_SERVICE_Client *client)
180{ 180{
181 struct Listener *listener; 181 struct Listener *listener;
182 182
@@ -221,12 +221,12 @@ listener_destroy (struct Listener *listener)
221 * The client's destroy callback will destroy the listener again. */ 221 * The client's destroy callback will destroy the listener again. */
222 if (NULL != listener->client) 222 if (NULL != listener->client)
223 { 223 {
224 struct GNUNET_SERVER_Client *client = listener->client; 224 struct GNUNET_SERVICE_Client *client = listener->client;
225 225
226 listener->client = NULL; 226 listener->client = NULL;
227 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 227 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
228 "Disconnecting listener client\n"); 228 "Disconnecting listener client\n");
229 GNUNET_SERVER_client_disconnect (client); 229 GNUNET_SERVICE_client_drop (client);
230 return; 230 return;
231 } 231 }
232 if (NULL != listener->client_mq) 232 if (NULL != listener->client_mq)
@@ -526,10 +526,10 @@ set_destroy (struct Set *set)
526 * callback will call `set_destroy()` again in this case. We do 526 * callback will call `set_destroy()` again in this case. We do
527 * this so that the channel end handler still has a valid set handle 527 * this so that the channel end handler still has a valid set handle
528 * to destroy. */ 528 * to destroy. */
529 struct GNUNET_SERVER_Client *client = set->client; 529 struct GNUNET_SERVICE_Client *client = set->client;
530 530
531 set->client = NULL; 531 set->client = NULL;
532 GNUNET_SERVER_client_disconnect (client); 532 GNUNET_SERVICE_client_drop (client);
533 return; 533 return;
534 } 534 }
535 GNUNET_assert (NULL != set->state); 535 GNUNET_assert (NULL != set->state);
@@ -609,14 +609,33 @@ set_destroy (struct Set *set)
609 609
610 610
611/** 611/**
612 * Callback called when a client connects to the service.
613 *
614 * @param cls closure for the service
615 * @param c the new client that connected to the service
616 * @param mq the message queue used to send messages to the client
617 * @return @a c
618 */
619static void *
620client_connect_cb (void *cls,
621 struct GNUNET_SERVICE_Client *c,
622 struct GNUNET_MQ_Handle *mq)
623{
624 return c;
625}
626
627
628/**
612 * Clean up after a client has disconnected 629 * Clean up after a client has disconnected
613 * 630 *
614 * @param cls closure, unused 631 * @param cls closure, unused
615 * @param client the client to clean up after 632 * @param client the client to clean up after
633 * @param internal_cls our client-specific internal data structure
616 */ 634 */
617static void 635static void
618handle_client_disconnect (void *cls, 636client_disconnect_cb (void *cls,
619 struct GNUNET_SERVER_Client *client) 637 struct GNUNET_SERVICE_Client *client,
638 void *internal_cls)
620{ 639{
621 struct Listener *listener; 640 struct Listener *listener;
622 struct Set *set; 641 struct Set *set;
@@ -1004,15 +1023,14 @@ again:
1004 * can right now start an iteration. If all checks out, starts 1023 * can right now start an iteration. If all checks out, starts
1005 * sending the elements of the set to the client. 1024 * sending the elements of the set to the client.
1006 * 1025 *
1007 * @param cls unused 1026 * @param cls client that sent the message
1008 * @param client client that sent the message
1009 * @param m message sent by the client 1027 * @param m message sent by the client
1010 */ 1028 */
1011static void 1029static void
1012handle_client_iterate (void *cls, 1030handle_client_iterate (void *cls,
1013 struct GNUNET_SERVER_Client *client,
1014 const struct GNUNET_MessageHeader *m) 1031 const struct GNUNET_MessageHeader *m)
1015{ 1032{
1033 struct GNUNET_SERVICE_Client *client = cls;
1016 struct Set *set; 1034 struct Set *set;
1017 1035
1018 set = set_get (client); 1036 set = set_get (client);
@@ -1020,14 +1038,14 @@ handle_client_iterate (void *cls,
1020 { 1038 {
1021 /* attempt to iterate over a non existing set */ 1039 /* attempt to iterate over a non existing set */
1022 GNUNET_break (0); 1040 GNUNET_break (0);
1023 GNUNET_SERVER_client_disconnect (client); 1041 GNUNET_SERVICE_client_drop (client);
1024 return; 1042 return;
1025 } 1043 }
1026 if (NULL != set->iter) 1044 if (NULL != set->iter)
1027 { 1045 {
1028 /* Only one concurrent iterate-action allowed per set */ 1046 /* Only one concurrent iterate-action allowed per set */
1029 GNUNET_break (0); 1047 GNUNET_break (0);
1030 GNUNET_SERVER_client_disconnect (client); 1048 GNUNET_SERVICE_client_drop (client);
1031 return; 1049 return;
1032 } 1050 }
1033 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1051 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1035,8 +1053,7 @@ handle_client_iterate (void *cls,
1035 (void *) set, 1053 (void *) set,
1036 set->current_generation, 1054 set->current_generation,
1037 GNUNET_CONTAINER_multihashmap_size (set->content->elements)); 1055 GNUNET_CONTAINER_multihashmap_size (set->content->elements));
1038 GNUNET_SERVER_receive_done (client, 1056 GNUNET_SERVICE_client_continue (client);
1039 GNUNET_OK);
1040 set->content->iterator_count += 1; 1057 set->content->iterator_count += 1;
1041 set->iter = GNUNET_CONTAINER_multihashmap_iterator_create (set->content->elements); 1058 set->iter = GNUNET_CONTAINER_multihashmap_iterator_create (set->content->elements);
1042 set->iter_generation = set->current_generation; 1059 set->iter_generation = set->current_generation;
@@ -1049,19 +1066,16 @@ handle_client_iterate (void *cls,
1049 * the first request from a client, and includes the type of set 1066 * the first request from a client, and includes the type of set
1050 * operation to be performed. 1067 * operation to be performed.
1051 * 1068 *
1052 * @param cls unused 1069 * @param cls client that sent the message
1053 * @param client client that sent the message
1054 * @param m message sent by the client 1070 * @param m message sent by the client
1055 */ 1071 */
1056static void 1072static void
1057handle_client_create_set (void *cls, 1073handle_client_create_set (void *cls,
1058 struct GNUNET_SERVER_Client *client, 1074 const struct GNUNET_SET_CreateMessage *msg)
1059 const struct GNUNET_MessageHeader *m)
1060{ 1075{
1061 const struct GNUNET_SET_CreateMessage *msg; 1076 struct GNUNET_SERVICE_Client *client = cls;
1062 struct Set *set; 1077 struct Set *set;
1063 1078
1064 msg = (const struct GNUNET_SET_CreateMessage *) m;
1065 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1079 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1066 "Client created new set (operation %u)\n", 1080 "Client created new set (operation %u)\n",
1067 ntohl (msg->operation)); 1081 ntohl (msg->operation));
@@ -1069,7 +1083,7 @@ handle_client_create_set (void *cls,
1069 { 1083 {
1070 /* There can only be one set per client */ 1084 /* There can only be one set per client */
1071 GNUNET_break (0); 1085 GNUNET_break (0);
1072 GNUNET_SERVER_client_disconnect (client); 1086 GNUNET_SERVICE_client_drop (client);
1073 return; 1087 return;
1074 } 1088 }
1075 set = GNUNET_new (struct Set); 1089 set = GNUNET_new (struct Set);
@@ -1084,7 +1098,7 @@ handle_client_create_set (void *cls,
1084 default: 1098 default:
1085 GNUNET_free (set); 1099 GNUNET_free (set);
1086 GNUNET_break (0); 1100 GNUNET_break (0);
1087 GNUNET_SERVER_client_disconnect (client); 1101 GNUNET_SERVICE_client_drop (client);
1088 return; 1102 return;
1089 } 1103 }
1090 set->operation = ntohl (msg->operation); 1104 set->operation = ntohl (msg->operation);
@@ -1093,19 +1107,18 @@ handle_client_create_set (void *cls,
1093 { 1107 {
1094 /* initialization failed (i.e. out of memory) */ 1108 /* initialization failed (i.e. out of memory) */
1095 GNUNET_free (set); 1109 GNUNET_free (set);
1096 GNUNET_SERVER_client_disconnect (client); 1110 GNUNET_SERVICE_client_drop (client);
1097 return; 1111 return;
1098 } 1112 }
1099 set->content = GNUNET_new (struct SetContent); 1113 set->content = GNUNET_new (struct SetContent);
1100 set->content->refcount = 1; 1114 set->content->refcount = 1;
1101 set->content->elements = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_YES); 1115 set->content->elements = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_YES);
1102 set->client = client; 1116 set->client = client;
1103 set->client_mq = GNUNET_MQ_queue_for_server_client (client); 1117 set->client_mq = GNUNET_SERVICE_client_get_mq (client);
1104 GNUNET_CONTAINER_DLL_insert (sets_head, 1118 GNUNET_CONTAINER_DLL_insert (sets_head,
1105 sets_tail, 1119 sets_tail,
1106 set); 1120 set);
1107 GNUNET_SERVER_receive_done (client, 1121 GNUNET_SERVICE_client_continue (client);
1108 GNUNET_OK);
1109} 1122}
1110 1123
1111 1124
@@ -1206,30 +1219,27 @@ channel_new_cb (void *cls,
1206/** 1219/**
1207 * Called when a client wants to create a new listener. 1220 * Called when a client wants to create a new listener.
1208 * 1221 *
1209 * @param cls unused 1222 * @param cls client that sent the message
1210 * @param client client that sent the message 1223 * @param msg message sent by the client
1211 * @param m message sent by the client
1212 */ 1224 */
1213static void 1225static void
1214handle_client_listen (void *cls, 1226handle_client_listen (void *cls,
1215 struct GNUNET_SERVER_Client *client, 1227 const struct GNUNET_SET_ListenMessage *msg)
1216 const struct GNUNET_MessageHeader *m)
1217{ 1228{
1218 const struct GNUNET_SET_ListenMessage *msg; 1229 struct GNUNET_SERVICE_Client *client = cls;
1219 struct Listener *listener; 1230 struct Listener *listener;
1220 struct Operation *op; 1231 struct Operation *op;
1221 1232
1222 msg = (const struct GNUNET_SET_ListenMessage *) m;
1223 if (NULL != listener_get (client)) 1233 if (NULL != listener_get (client))
1224 { 1234 {
1225 /* max. one active listener per client! */ 1235 /* max. one active listener per client! */
1226 GNUNET_break (0); 1236 GNUNET_break (0);
1227 GNUNET_SERVER_client_disconnect (client); 1237 GNUNET_SERVICE_client_drop (client);
1228 return; 1238 return;
1229 } 1239 }
1230 listener = GNUNET_new (struct Listener); 1240 listener = GNUNET_new (struct Listener);
1231 listener->client = client; 1241 listener->client = client;
1232 listener->client_mq = GNUNET_MQ_queue_for_server_client (client); 1242 listener->client_mq = GNUNET_SERVICE_client_get_mq (client);
1233 listener->app_id = msg->app_id; 1243 listener->app_id = msg->app_id;
1234 listener->operation = ntohl (msg->operation); 1244 listener->operation = ntohl (msg->operation);
1235 GNUNET_CONTAINER_DLL_insert_tail (listeners_head, 1245 GNUNET_CONTAINER_DLL_insert_tail (listeners_head,
@@ -1261,8 +1271,7 @@ handle_client_listen (void *cls,
1261 incoming_suggest (op, 1271 incoming_suggest (op,
1262 listener); 1272 listener);
1263 } 1273 }
1264 GNUNET_SERVER_receive_done (client, 1274 GNUNET_SERVICE_client_continue (client);
1265 GNUNET_OK);
1266} 1275}
1267 1276
1268 1277
@@ -1270,26 +1279,22 @@ handle_client_listen (void *cls,
1270 * Called when the listening client rejects an operation 1279 * Called when the listening client rejects an operation
1271 * request by another peer. 1280 * request by another peer.
1272 * 1281 *
1273 * @param cls unused 1282 * @param cls client that sent the message
1274 * @param client client that sent the message 1283 * @param msg message sent by the client
1275 * @param m message sent by the client
1276 */ 1284 */
1277static void 1285static void
1278handle_client_reject (void *cls, 1286handle_client_reject (void *cls,
1279 struct GNUNET_SERVER_Client *client, 1287 const struct GNUNET_SET_RejectMessage *msg)
1280 const struct GNUNET_MessageHeader *m)
1281{ 1288{
1289 struct GNUNET_SERVICE_Client *client = cls;
1282 struct Operation *incoming; 1290 struct Operation *incoming;
1283 const struct GNUNET_SET_RejectMessage *msg;
1284 1291
1285 msg = (const struct GNUNET_SET_RejectMessage *) m;
1286 incoming = get_incoming (ntohl (msg->accept_reject_id)); 1292 incoming = get_incoming (ntohl (msg->accept_reject_id));
1287 if (NULL == incoming) 1293 if (NULL == incoming)
1288 { 1294 {
1289 /* no matching incoming operation for this reject */ 1295 /* no matching incoming operation for this reject */
1290 GNUNET_break (0); 1296 GNUNET_break (0);
1291 GNUNET_SERVER_receive_done (client, 1297 GNUNET_SERVICE_client_drop (client);
1292 GNUNET_SYSERR);
1293 return; 1298 return;
1294 } 1299 }
1295 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1300 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1297,24 +1302,36 @@ handle_client_reject (void *cls,
1297 incoming->spec->operation, 1302 incoming->spec->operation,
1298 GNUNET_h2s (&incoming->spec->app_id)); 1303 GNUNET_h2s (&incoming->spec->app_id));
1299 GNUNET_CADET_channel_destroy (incoming->channel); 1304 GNUNET_CADET_channel_destroy (incoming->channel);
1300 GNUNET_SERVER_receive_done (client, 1305 GNUNET_SERVICE_client_continue (client);
1301 GNUNET_OK);
1302} 1306}
1303 1307
1304 1308
1309/**
1310 * Called when a client wants to add or remove an element to a set it inhabits.
1311 *
1312 * @param cls client that sent the message
1313 * @param m message sent by the client
1314 */
1315static int
1316check_client_mutation (void *cls,
1317 const struct GNUNET_MessageHeader *m)
1318{
1319 /* FIXME: any check we might want to do here? */
1320 return GNUNET_OK;
1321}
1322
1305 1323
1306/** 1324/**
1307 * Called when a client wants to add or remove an element to a set it inhabits. 1325 * Called when a client wants to add or remove an element to a set it inhabits.
1308 * 1326 *
1309 * @param cls unused 1327 * @param cls client that sent the message
1310 * @param client client that sent the message
1311 * @param m message sent by the client 1328 * @param m message sent by the client
1312 */ 1329 */
1313static void 1330static void
1314handle_client_mutation (void *cls, 1331handle_client_mutation (void *cls,
1315 struct GNUNET_SERVER_Client *client,
1316 const struct GNUNET_MessageHeader *m) 1332 const struct GNUNET_MessageHeader *m)
1317{ 1333{
1334 struct GNUNET_SERVICE_Client *client = cls;
1318 struct Set *set; 1335 struct Set *set;
1319 1336
1320 set = set_get (client); 1337 set = set_get (client);
@@ -1322,12 +1339,11 @@ handle_client_mutation (void *cls,
1322 { 1339 {
1323 /* client without a set requested an operation */ 1340 /* client without a set requested an operation */
1324 GNUNET_break (0); 1341 GNUNET_break (0);
1325 GNUNET_SERVER_client_disconnect (client); 1342 GNUNET_SERVICE_client_drop (client);
1326 return; 1343 return;
1327 } 1344 }
1328 1345
1329 GNUNET_SERVER_receive_done (client, 1346 GNUNET_SERVICE_client_continue (client);
1330 GNUNET_OK);
1331 1347
1332 if (0 != set->content->iterator_count) 1348 if (0 != set->content->iterator_count)
1333 { 1349 {
@@ -1344,7 +1360,6 @@ handle_client_mutation (void *cls,
1344 pm); 1360 pm);
1345 return; 1361 return;
1346 } 1362 }
1347
1348 execute_mutation (set, m); 1363 execute_mutation (set, m);
1349} 1364}
1350 1365
@@ -1386,17 +1401,34 @@ advance_generation (struct Set *set)
1386 * peer. Initiates the CADET connection to the listener and sends the 1401 * peer. Initiates the CADET connection to the listener and sends the
1387 * request. 1402 * request.
1388 * 1403 *
1389 * @param cls unused 1404 * @param cls client that sent the message
1390 * @param client client that sent the message 1405 * @param msg message sent by the client
1391 * @param m message sent by the client 1406 * @return #GNUNET_OK if the message is well-formed
1407 */
1408static int
1409check_client_evaluate (void *cls,
1410 const struct GNUNET_SET_EvaluateMessage *msg)
1411{
1412 /* FIXME: suboptimal, even if the context below could be NULL,
1413 there are malformed messages this does not check for... */
1414 return GNUNET_OK;
1415}
1416
1417
1418/**
1419 * Called when a client wants to initiate a set operation with another
1420 * peer. Initiates the CADET connection to the listener and sends the
1421 * request.
1422 *
1423 * @param cls client that sent the message
1424 * @param msg message sent by the client
1392 */ 1425 */
1393static void 1426static void
1394handle_client_evaluate (void *cls, 1427handle_client_evaluate (void *cls,
1395 struct GNUNET_SERVER_Client *client, 1428 const struct GNUNET_SET_EvaluateMessage *msg)
1396 const struct GNUNET_MessageHeader *m)
1397{ 1429{
1430 struct GNUNET_SERVICE_Client *client = cls;
1398 struct Set *set; 1431 struct Set *set;
1399 const struct GNUNET_SET_EvaluateMessage *msg;
1400 struct OperationSpecification *spec; 1432 struct OperationSpecification *spec;
1401 struct Operation *op; 1433 struct Operation *op;
1402 const struct GNUNET_MessageHeader *context; 1434 const struct GNUNET_MessageHeader *context;
@@ -1405,10 +1437,9 @@ handle_client_evaluate (void *cls,
1405 if (NULL == set) 1437 if (NULL == set)
1406 { 1438 {
1407 GNUNET_break (0); 1439 GNUNET_break (0);
1408 GNUNET_SERVER_client_disconnect (client); 1440 GNUNET_SERVICE_client_drop (client);
1409 return; 1441 return;
1410 } 1442 }
1411 msg = (const struct GNUNET_SET_EvaluateMessage *) m;
1412 spec = GNUNET_new (struct OperationSpecification); 1443 spec = GNUNET_new (struct OperationSpecification);
1413 spec->operation = set->operation; 1444 spec->operation = set->operation;
1414 spec->app_id = msg->app_id; 1445 spec->app_id = msg->app_id;
@@ -1442,8 +1473,7 @@ handle_client_evaluate (void *cls,
1442 op->mq = GNUNET_CADET_mq_create (op->channel); 1473 op->mq = GNUNET_CADET_mq_create (op->channel);
1443 set->vt->evaluate (op, 1474 set->vt->evaluate (op,
1444 context); 1475 context);
1445 GNUNET_SERVER_receive_done (client, 1476 GNUNET_SERVICE_client_continue (client);
1446 GNUNET_OK);
1447} 1477}
1448 1478
1449 1479
@@ -1452,16 +1482,14 @@ handle_client_evaluate (void *cls,
1452 * that we only expect acks for set elements, not after the 1482 * that we only expect acks for set elements, not after the
1453 * #GNUNET_MESSAGE_TYPE_SET_ITER_DONE message. 1483 * #GNUNET_MESSAGE_TYPE_SET_ITER_DONE message.
1454 * 1484 *
1455 * @param cls unused 1485 * @param cls client the client
1456 * @param client the client 1486 * @param ack the message
1457 * @param m the message
1458 */ 1487 */
1459static void 1488static void
1460handle_client_iter_ack (void *cls, 1489handle_client_iter_ack (void *cls,
1461 struct GNUNET_SERVER_Client *client, 1490 const struct GNUNET_SET_IterAckMessage *ack)
1462 const struct GNUNET_MessageHeader *m)
1463{ 1491{
1464 const struct GNUNET_SET_IterAckMessage *ack; 1492 struct GNUNET_SERVICE_Client *client = cls;
1465 struct Set *set; 1493 struct Set *set;
1466 1494
1467 set = set_get (client); 1495 set = set_get (client);
@@ -1469,7 +1497,7 @@ handle_client_iter_ack (void *cls,
1469 { 1497 {
1470 /* client without a set acknowledged receiving a value */ 1498 /* client without a set acknowledged receiving a value */
1471 GNUNET_break (0); 1499 GNUNET_break (0);
1472 GNUNET_SERVER_client_disconnect (client); 1500 GNUNET_SERVICE_client_drop (client);
1473 return; 1501 return;
1474 } 1502 }
1475 if (NULL == set->iter) 1503 if (NULL == set->iter)
@@ -1477,12 +1505,10 @@ handle_client_iter_ack (void *cls,
1477 /* client sent an ack, but we were not expecting one (as 1505 /* client sent an ack, but we were not expecting one (as
1478 set iteration has finished) */ 1506 set iteration has finished) */
1479 GNUNET_break (0); 1507 GNUNET_break (0);
1480 GNUNET_SERVER_client_disconnect (client); 1508 GNUNET_SERVICE_client_drop (client);
1481 return; 1509 return;
1482 } 1510 }
1483 ack = (const struct GNUNET_SET_IterAckMessage *) m; 1511 GNUNET_SERVICE_client_continue (client);
1484 GNUNET_SERVER_receive_done (client,
1485 GNUNET_OK);
1486 if (ntohl (ack->send_more)) 1512 if (ntohl (ack->send_more))
1487 { 1513 {
1488 send_client_element (set); 1514 send_client_element (set);
@@ -1497,18 +1523,16 @@ handle_client_iter_ack (void *cls,
1497 1523
1498 1524
1499/** 1525/**
1500 * Handle a request from the client to 1526 * Handle a request from the client to copy a set.
1501 * copy a set.
1502 * 1527 *
1503 * @param cls unused 1528 * @param cls the client
1504 * @param client the client
1505 * @param mh the message 1529 * @param mh the message
1506 */ 1530 */
1507static void 1531static void
1508handle_client_copy_lazy_prepare (void *cls, 1532handle_client_copy_lazy_prepare (void *cls,
1509 struct GNUNET_SERVER_Client *client,
1510 const struct GNUNET_MessageHeader *mh) 1533 const struct GNUNET_MessageHeader *mh)
1511{ 1534{
1535 struct GNUNET_SERVICE_Client *client = cls;
1512 struct Set *set; 1536 struct Set *set;
1513 struct LazyCopyRequest *cr; 1537 struct LazyCopyRequest *cr;
1514 struct GNUNET_MQ_Envelope *ev; 1538 struct GNUNET_MQ_Envelope *ev;
@@ -1519,7 +1543,7 @@ handle_client_copy_lazy_prepare (void *cls,
1519 { 1543 {
1520 /* client without a set requested an operation */ 1544 /* client without a set requested an operation */
1521 GNUNET_break (0); 1545 GNUNET_break (0);
1522 GNUNET_SERVER_client_disconnect (client); 1546 GNUNET_SERVICE_client_drop (client);
1523 return; 1547 return;
1524 } 1548 }
1525 1549
@@ -1540,8 +1564,7 @@ handle_client_copy_lazy_prepare (void *cls,
1540 GNUNET_MQ_send (set->client_mq, ev); 1564 GNUNET_MQ_send (set->client_mq, ev);
1541 1565
1542 1566
1543 GNUNET_SERVER_receive_done (client, 1567 GNUNET_SERVICE_client_continue (client);
1544 GNUNET_OK);
1545 1568
1546 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1569 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1547 "Client requested lazy copy\n"); 1570 "Client requested lazy copy\n");
@@ -1549,21 +1572,17 @@ handle_client_copy_lazy_prepare (void *cls,
1549 1572
1550 1573
1551/** 1574/**
1552 * Handle a request from the client to 1575 * Handle a request from the client to connect to a copy of a set.
1553 * connect to a copy of a set.
1554 * 1576 *
1555 * @param cls unused 1577 * @param cls the client
1556 * @param client the client 1578 * @param msg the message
1557 * @param mh the message
1558 */ 1579 */
1559static void 1580static void
1560handle_client_copy_lazy_connect (void *cls, 1581handle_client_copy_lazy_connect (void *cls,
1561 struct GNUNET_SERVER_Client *client, 1582 const struct GNUNET_SET_CopyLazyConnectMessage *msg)
1562 const struct GNUNET_MessageHeader *mh)
1563{ 1583{
1584 struct GNUNET_SERVICE_Client *client = cls;
1564 struct LazyCopyRequest *cr; 1585 struct LazyCopyRequest *cr;
1565 const struct GNUNET_SET_CopyLazyConnectMessage *msg =
1566 (const struct GNUNET_SET_CopyLazyConnectMessage *) mh;
1567 struct Set *set; 1586 struct Set *set;
1568 int found; 1587 int found;
1569 1588
@@ -1571,7 +1590,7 @@ handle_client_copy_lazy_connect (void *cls,
1571 { 1590 {
1572 /* There can only be one set per client */ 1591 /* There can only be one set per client */
1573 GNUNET_break (0); 1592 GNUNET_break (0);
1574 GNUNET_SERVER_client_disconnect (client); 1593 GNUNET_SERVICE_client_drop (client);
1575 return; 1594 return;
1576 } 1595 }
1577 1596
@@ -1590,7 +1609,7 @@ handle_client_copy_lazy_connect (void *cls,
1590 { 1609 {
1591 /* client asked for copy with cookie we don't know */ 1610 /* client asked for copy with cookie we don't know */
1592 GNUNET_break (0); 1611 GNUNET_break (0);
1593 GNUNET_SERVER_client_disconnect (client); 1612 GNUNET_SERVICE_client_drop (client);
1594 return; 1613 return;
1595 } 1614 }
1596 1615
@@ -1619,7 +1638,7 @@ handle_client_copy_lazy_connect (void *cls,
1619 GNUNET_break (0); 1638 GNUNET_break (0);
1620 GNUNET_free (set); 1639 GNUNET_free (set);
1621 GNUNET_free (cr); 1640 GNUNET_free (cr);
1622 GNUNET_SERVER_client_disconnect (client); 1641 GNUNET_SERVICE_client_drop (client);
1623 return; 1642 return;
1624 } 1643 }
1625 1644
@@ -1639,15 +1658,14 @@ handle_client_copy_lazy_connect (void *cls,
1639 1658
1640 1659
1641 set->client = client; 1660 set->client = client;
1642 set->client_mq = GNUNET_MQ_queue_for_server_client (client); 1661 set->client_mq = GNUNET_SERVICE_client_get_mq (client);
1643 GNUNET_CONTAINER_DLL_insert (sets_head, 1662 GNUNET_CONTAINER_DLL_insert (sets_head,
1644 sets_tail, 1663 sets_tail,
1645 set); 1664 set);
1646 1665
1647 GNUNET_free (cr); 1666 GNUNET_free (cr);
1648 1667
1649 GNUNET_SERVER_receive_done (client, 1668 GNUNET_SERVICE_client_continue (client);
1650 GNUNET_OK);
1651 1669
1652 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1670 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1653 "Client connected to lazy set\n"); 1671 "Client connected to lazy set\n");
@@ -1655,20 +1673,16 @@ handle_client_copy_lazy_connect (void *cls,
1655 1673
1656 1674
1657/** 1675/**
1658 * Handle a request from the client to 1676 * Handle a request from the client to cancel a running set operation.
1659 * cancel a running set operation.
1660 * 1677 *
1661 * @param cls unused 1678 * @param cls the client
1662 * @param client the client 1679 * @param msg the message
1663 * @param mh the message
1664 */ 1680 */
1665static void 1681static void
1666handle_client_cancel (void *cls, 1682handle_client_cancel (void *cls,
1667 struct GNUNET_SERVER_Client *client, 1683 const struct GNUNET_SET_CancelMessage *msg)
1668 const struct GNUNET_MessageHeader *mh)
1669{ 1684{
1670 const struct GNUNET_SET_CancelMessage *msg = 1685 struct GNUNET_SERVICE_Client *client = cls;
1671 (const struct GNUNET_SET_CancelMessage *) mh;
1672 struct Set *set; 1686 struct Set *set;
1673 struct Operation *op; 1687 struct Operation *op;
1674 int found; 1688 int found;
@@ -1678,7 +1692,7 @@ handle_client_cancel (void *cls,
1678 { 1692 {
1679 /* client without a set requested an operation */ 1693 /* client without a set requested an operation */
1680 GNUNET_break (0); 1694 GNUNET_break (0);
1681 GNUNET_SERVER_client_disconnect (client); 1695 GNUNET_SERVICE_client_drop (client);
1682 return; 1696 return;
1683 } 1697 }
1684 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1698 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1708,8 +1722,7 @@ handle_client_cancel (void *cls,
1708 _GSS_operation_destroy (op, 1722 _GSS_operation_destroy (op,
1709 GNUNET_YES); 1723 GNUNET_YES);
1710 } 1724 }
1711 GNUNET_SERVER_receive_done (client, 1725 GNUNET_SERVICE_client_continue (client);
1712 GNUNET_OK);
1713} 1726}
1714 1727
1715 1728
@@ -1718,28 +1731,25 @@ handle_client_cancel (void *cls,
1718 * came from a remote peer. We forward the accept to the associated 1731 * came from a remote peer. We forward the accept to the associated
1719 * operation for handling 1732 * operation for handling
1720 * 1733 *
1721 * @param cls unused 1734 * @param cls the client
1722 * @param client the client 1735 * @param msg the message
1723 * @param mh the message
1724 */ 1736 */
1725static void 1737static void
1726handle_client_accept (void *cls, 1738handle_client_accept (void *cls,
1727 struct GNUNET_SERVER_Client *client, 1739 const struct GNUNET_SET_AcceptMessage *msg)
1728 const struct GNUNET_MessageHeader *mh)
1729{ 1740{
1741 struct GNUNET_SERVICE_Client *client = cls;
1730 struct Set *set; 1742 struct Set *set;
1731 const struct GNUNET_SET_AcceptMessage *msg;
1732 struct Operation *op; 1743 struct Operation *op;
1733 struct GNUNET_SET_ResultMessage *result_message; 1744 struct GNUNET_SET_ResultMessage *result_message;
1734 struct GNUNET_MQ_Envelope *ev; 1745 struct GNUNET_MQ_Envelope *ev;
1735 1746
1736 msg = (const struct GNUNET_SET_AcceptMessage *) mh;
1737 set = set_get (client); 1747 set = set_get (client);
1738 if (NULL == set) 1748 if (NULL == set)
1739 { 1749 {
1740 /* client without a set requested to accept */ 1750 /* client without a set requested to accept */
1741 GNUNET_break (0); 1751 GNUNET_break (0);
1742 GNUNET_SERVER_client_disconnect (client); 1752 GNUNET_SERVICE_client_drop (client);
1743 return; 1753 return;
1744 } 1754 }
1745 op = get_incoming (ntohl (msg->accept_reject_id)); 1755 op = get_incoming (ntohl (msg->accept_reject_id));
@@ -1755,7 +1765,7 @@ handle_client_accept (void *cls,
1755 result_message->element_type = 0; 1765 result_message->element_type = 0;
1756 result_message->result_status = htons (GNUNET_SET_STATUS_FAILURE); 1766 result_message->result_status = htons (GNUNET_SET_STATUS_FAILURE);
1757 GNUNET_MQ_send (set->client_mq, ev); 1767 GNUNET_MQ_send (set->client_mq, ev);
1758 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1768 GNUNET_SERVICE_client_continue (client);
1759 return; 1769 return;
1760 } 1770 }
1761 1771
@@ -1781,8 +1791,7 @@ handle_client_accept (void *cls,
1781 1791
1782 op->vt = set->vt; 1792 op->vt = set->vt;
1783 op->vt->accept (op); 1793 op->vt->accept (op);
1784 GNUNET_SERVER_receive_done (client, 1794 GNUNET_SERVICE_client_continue (client);
1785 GNUNET_OK);
1786} 1795}
1787 1796
1788 1797
@@ -1909,53 +1918,14 @@ dispatch_p2p_message (void *cls,
1909 * method to run service-specific setup code. 1918 * method to run service-specific setup code.
1910 * 1919 *
1911 * @param cls closure 1920 * @param cls closure
1912 * @param server the initialized server
1913 * @param cfg configuration to use 1921 * @param cfg configuration to use
1922 * @param service the initialized service
1914 */ 1923 */
1915static void 1924static void
1916run (void *cls, 1925run (void *cls,
1917 struct GNUNET_SERVER_Handle *server, 1926 const struct GNUNET_CONFIGURATION_Handle *cfg,
1918 const struct GNUNET_CONFIGURATION_Handle *cfg) 1927 struct GNUNET_SERVICE_Handle *service)
1919{ 1928{
1920 static const struct GNUNET_SERVER_MessageHandler server_handlers[] = {
1921 { &handle_client_accept, NULL,
1922 GNUNET_MESSAGE_TYPE_SET_ACCEPT,
1923 sizeof (struct GNUNET_SET_AcceptMessage)},
1924 { &handle_client_iter_ack, NULL,
1925 GNUNET_MESSAGE_TYPE_SET_ITER_ACK,
1926 sizeof (struct GNUNET_SET_IterAckMessage) },
1927 { &handle_client_mutation, NULL,
1928 GNUNET_MESSAGE_TYPE_SET_ADD,
1929 0},
1930 { &handle_client_create_set, NULL,
1931 GNUNET_MESSAGE_TYPE_SET_CREATE,
1932 sizeof (struct GNUNET_SET_CreateMessage)},
1933 { &handle_client_iterate, NULL,
1934 GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST,
1935 sizeof (struct GNUNET_MessageHeader)},
1936 { &handle_client_evaluate, NULL,
1937 GNUNET_MESSAGE_TYPE_SET_EVALUATE,
1938 0},
1939 { &handle_client_listen, NULL,
1940 GNUNET_MESSAGE_TYPE_SET_LISTEN,
1941 sizeof (struct GNUNET_SET_ListenMessage)},
1942 { &handle_client_reject, NULL,
1943 GNUNET_MESSAGE_TYPE_SET_REJECT,
1944 sizeof (struct GNUNET_SET_RejectMessage)},
1945 { &handle_client_mutation, NULL,
1946 GNUNET_MESSAGE_TYPE_SET_REMOVE,
1947 0},
1948 { &handle_client_cancel, NULL,
1949 GNUNET_MESSAGE_TYPE_SET_CANCEL,
1950 sizeof (struct GNUNET_SET_CancelMessage)},
1951 { &handle_client_copy_lazy_prepare, NULL,
1952 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE,
1953 sizeof (struct GNUNET_MessageHeader)},
1954 { &handle_client_copy_lazy_connect, NULL,
1955 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT,
1956 sizeof (struct GNUNET_SET_CopyLazyConnectMessage)},
1957 { NULL, NULL, 0, 0}
1958 };
1959 static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = { 1929 static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
1960 { &dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, 0}, 1930 { &dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, 0},
1961 { &dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF, 0}, 1931 { &dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF, 0},
@@ -1974,12 +1944,8 @@ run (void *cls,
1974 }; 1944 };
1975 1945
1976 configuration = cfg; 1946 configuration = cfg;
1977 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); 1947 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
1978 GNUNET_SERVER_disconnect_notify (server, 1948 NULL);
1979 &handle_client_disconnect,
1980 NULL);
1981 GNUNET_SERVER_add_handlers (server,
1982 server_handlers);
1983 _GSS_statistics = GNUNET_STATISTICS_create ("set", cfg); 1949 _GSS_statistics = GNUNET_STATISTICS_create ("set", cfg);
1984 cadet = GNUNET_CADET_connect (cfg, 1950 cadet = GNUNET_CADET_connect (cfg,
1985 NULL, 1951 NULL,
@@ -1988,29 +1954,71 @@ run (void *cls,
1988 if (NULL == cadet) 1954 if (NULL == cadet)
1989 { 1955 {
1990 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1956 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1991 _("Could not connect to cadet service\n")); 1957 _("Could not connect to CADET service\n"));
1992 return; 1958 return;
1993 } 1959 }
1994} 1960}
1995 1961
1996 1962
1997/** 1963/**
1998 * The main function for the set service. 1964 * Define "main" method using service macro.
1999 *
2000 * @param argc number of arguments from the command line
2001 * @param argv command line arguments
2002 * @return 0 ok, 1 on error
2003 */ 1965 */
2004int 1966GNUNET_SERVICE_MAIN
2005main (int argc, 1967("set",
2006 char *const *argv) 1968 GNUNET_SERVICE_OPTION_NONE,
2007{ 1969 &run,
2008 int ret; 1970 &client_connect_cb,
1971 &client_disconnect_cb,
1972 NULL,
1973 GNUNET_MQ_hd_fixed_size (client_accept,
1974 GNUNET_MESSAGE_TYPE_SET_ACCEPT,
1975 struct GNUNET_SET_AcceptMessage,
1976 NULL),
1977 GNUNET_MQ_hd_fixed_size (client_iter_ack,
1978 GNUNET_MESSAGE_TYPE_SET_ITER_ACK,
1979 struct GNUNET_SET_IterAckMessage,
1980 NULL),
1981 GNUNET_MQ_hd_var_size (client_mutation,
1982 GNUNET_MESSAGE_TYPE_SET_ADD,
1983 struct GNUNET_MessageHeader,
1984 NULL),
1985 GNUNET_MQ_hd_fixed_size (client_create_set,
1986 GNUNET_MESSAGE_TYPE_SET_CREATE,
1987 struct GNUNET_SET_CreateMessage,
1988 NULL),
1989 GNUNET_MQ_hd_fixed_size (client_iterate,
1990 GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST,
1991 struct GNUNET_MessageHeader,
1992 NULL),
1993 GNUNET_MQ_hd_var_size (client_evaluate,
1994 GNUNET_MESSAGE_TYPE_SET_EVALUATE,
1995 struct GNUNET_SET_EvaluateMessage,
1996 NULL),
1997 GNUNET_MQ_hd_fixed_size (client_listen,
1998 GNUNET_MESSAGE_TYPE_SET_LISTEN,
1999 struct GNUNET_SET_ListenMessage,
2000 NULL),
2001 GNUNET_MQ_hd_fixed_size (client_reject,
2002 GNUNET_MESSAGE_TYPE_SET_REJECT,
2003 struct GNUNET_SET_RejectMessage,
2004 NULL),
2005 GNUNET_MQ_hd_var_size (client_mutation,
2006 GNUNET_MESSAGE_TYPE_SET_REMOVE,
2007 struct GNUNET_MessageHeader,
2008 NULL),
2009 GNUNET_MQ_hd_fixed_size (client_cancel,
2010 GNUNET_MESSAGE_TYPE_SET_CANCEL,
2011 struct GNUNET_SET_CancelMessage,
2012 NULL),
2013 GNUNET_MQ_hd_fixed_size (client_copy_lazy_prepare,
2014 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE,
2015 struct GNUNET_MessageHeader,
2016 NULL),
2017 GNUNET_MQ_hd_fixed_size (client_copy_lazy_connect,
2018 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT,
2019 struct GNUNET_SET_CopyLazyConnectMessage,
2020 NULL),
2021 GNUNET_MQ_handler_end ());
2009 2022
2010 ret = GNUNET_SERVICE_run (argc, argv, "set",
2011 GNUNET_SERVICE_OPTION_NONE,
2012 &run, NULL);
2013 return (GNUNET_OK == ret) ? 0 : 1;
2014}
2015 2023
2016/* end of gnunet-service-set.c */ 2024/* end of gnunet-service-set.c */
diff --git a/src/set/gnunet-service-set.h b/src/set/gnunet-service-set.h
index 9e1ffd01a..573a2b7d9 100644
--- a/src/set/gnunet-service-set.h
+++ b/src/set/gnunet-service-set.h
@@ -520,7 +520,7 @@ struct Set
520 * Client that owns the set. Only one client may own a set, 520 * Client that owns the set. Only one client may own a set,
521 * and there can only be one set per client. 521 * and there can only be one set per client.
522 */ 522 */
523 struct GNUNET_SERVER_Client *client; 523 struct GNUNET_SERVICE_Client *client;
524 524
525 /** 525 /**
526 * Message queue for the client. 526 * Message queue for the client.
diff --git a/src/set/gnunet-service-set_intersection.c b/src/set/gnunet-service-set_intersection.c
index 258ad6443..9fe1eabe6 100644
--- a/src/set/gnunet-service-set_intersection.c
+++ b/src/set/gnunet-service-set_intersection.c
@@ -1032,7 +1032,7 @@ intersection_evaluate (struct Operation *op,
1032 { 1032 {
1033 /* the context message is too large!? */ 1033 /* the context message is too large!? */
1034 GNUNET_break (0); 1034 GNUNET_break (0);
1035 GNUNET_SERVER_client_disconnect (op->spec->set->client); 1035 GNUNET_SERVICE_client_drop (op->spec->set->client);
1036 return; 1036 return;
1037 } 1037 }
1038 msg->operation = htonl (GNUNET_SET_OPERATION_INTERSECTION); 1038 msg->operation = htonl (GNUNET_SET_OPERATION_INTERSECTION);
diff --git a/src/set/gnunet-service-set_union.c b/src/set/gnunet-service-set_union.c
index e22465fd3..acaabd94a 100644
--- a/src/set/gnunet-service-set_union.c
+++ b/src/set/gnunet-service-set_union.c
@@ -1594,7 +1594,7 @@ union_evaluate (struct Operation *op,
1594 { 1594 {
1595 /* the context message is too large */ 1595 /* the context message is too large */
1596 GNUNET_break (0); 1596 GNUNET_break (0);
1597 GNUNET_SERVER_client_disconnect (op->spec->set->client); 1597 GNUNET_SERVICE_client_drop (op->spec->set->client);
1598 return; 1598 return;
1599 } 1599 }
1600 msg->operation = htonl (GNUNET_SET_OPERATION_UNION); 1600 msg->operation = htonl (GNUNET_SET_OPERATION_UNION);