aboutsummaryrefslogtreecommitdiff
path: root/src/psycstore
diff options
context:
space:
mode:
authorGabor X Toth <*@tg-x.net>2016-09-24 01:14:32 +0000
committerGabor X Toth <*@tg-x.net>2016-09-24 01:14:32 +0000
commitea69f610a0de5186994f132290fce47063434fbf (patch)
tree963ffb0f3665b7008351ec3e03ed4954e1ee15ab /src/psycstore
parent04d825597e1785b8ca02f683c563e67efa662e7f (diff)
downloadgnunet-ea69f610a0de5186994f132290fce47063434fbf.tar.gz
gnunet-ea69f610a0de5186994f132290fce47063434fbf.zip
psycstore: switch to SERVICE API
Diffstat (limited to 'src/psycstore')
-rw-r--r--src/psycstore/gnunet-service-psycstore.c418
1 files changed, 219 insertions, 199 deletions
diff --git a/src/psycstore/gnunet-service-psycstore.c b/src/psycstore/gnunet-service-psycstore.c
index c9a6f22b8..12e1d1a8d 100644
--- a/src/psycstore/gnunet-service-psycstore.c
+++ b/src/psycstore/gnunet-service-psycstore.c
@@ -44,14 +44,14 @@
44static const struct GNUNET_CONFIGURATION_Handle *cfg; 44static const struct GNUNET_CONFIGURATION_Handle *cfg;
45 45
46/** 46/**
47 * Handle to the statistics service. 47 * Service handle.
48 */ 48 */
49static struct GNUNET_STATISTICS_Handle *stats; 49struct GNUNET_SERVICE_Handle *service;
50 50
51/** 51/**
52 * Notification context, simplifies client broadcasts. 52 * Handle to the statistics service.
53 */ 53 */
54static struct GNUNET_SERVER_NotificationContext *nc; 54static struct GNUNET_STATISTICS_Handle *stats;
55 55
56/** 56/**
57 * Database handle 57 * Database handle
@@ -72,11 +72,6 @@ static char *db_lib_name;
72static void 72static void
73shutdown_task (void *cls) 73shutdown_task (void *cls)
74{ 74{
75 if (NULL != nc)
76 {
77 GNUNET_SERVER_notification_context_destroy (nc);
78 nc = NULL;
79 }
80 if (NULL != stats) 75 if (NULL != stats)
81 { 76 {
82 GNUNET_STATISTICS_destroy (stats, GNUNET_NO); 77 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
@@ -101,8 +96,10 @@ shutdown_task (void *cls)
101 * Error message to include (or NULL for none). 96 * Error message to include (or NULL for none).
102 */ 97 */
103static void 98static void
104send_result_code (struct GNUNET_SERVER_Client *client, uint64_t op_id, 99send_result_code (struct GNUNET_SERVICE_Client *client,
105 int64_t result_code, const char *err_msg) 100 uint64_t op_id,
101 int64_t result_code,
102 const char *err_msg)
106{ 103{
107 struct OperationResult *res; 104 struct OperationResult *res;
108 size_t err_size = 0; 105 size_t err_size = 0;
@@ -110,9 +107,9 @@ send_result_code (struct GNUNET_SERVER_Client *client, uint64_t op_id,
110 if (NULL != err_msg) 107 if (NULL != err_msg)
111 err_size = strnlen (err_msg, 108 err_size = strnlen (err_msg,
112 GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (*res) - 1) + 1; 109 GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (*res) - 1) + 1;
113 res = GNUNET_malloc (sizeof (struct OperationResult) + err_size); 110 struct GNUNET_MQ_Envelope *
114 res->header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_CODE); 111 env = GNUNET_MQ_msg_extra (res, err_size,
115 res->header.size = htons (sizeof (struct OperationResult) + err_size); 112 GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_CODE);
116 res->result_code = GNUNET_htonll (result_code - INT64_MIN); 113 res->result_code = GNUNET_htonll (result_code - INT64_MIN);
117 res->op_id = op_id; 114 res->op_id = op_id;
118 if (0 < err_size) 115 if (0 < err_size)
@@ -120,13 +117,11 @@ send_result_code (struct GNUNET_SERVER_Client *client, uint64_t op_id,
120 GNUNET_memcpy (&res[1], err_msg, err_size); 117 GNUNET_memcpy (&res[1], err_msg, err_size);
121 ((char *) &res[1])[err_size - 1] = '\0'; 118 ((char *) &res[1])[err_size - 1] = '\0';
122 } 119 }
120
123 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 121 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
124 "Sending result to client: %" PRId64 " (%s)\n", 122 "Sending result to client: %" PRId64 " (%s)\n",
125 result_code, err_msg); 123 result_code, err_msg);
126 GNUNET_SERVER_notification_context_add (nc, client); 124 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
127 GNUNET_SERVER_notification_context_unicast (nc, client, &res->header,
128 GNUNET_NO);
129 GNUNET_free (res);
130} 125}
131 126
132 127
@@ -140,7 +135,7 @@ enum
140 135
141struct SendClosure 136struct SendClosure
142{ 137{
143 struct GNUNET_SERVER_Client *client; 138 struct GNUNET_SERVICE_Client *client;
144 139
145 /** 140 /**
146 * Channel's public key. 141 * Channel's public key.
@@ -196,9 +191,9 @@ send_fragment (void *cls, struct GNUNET_MULTICAST_MessageHeader *msg,
196 191
197 size_t msg_size = ntohs (msg->header.size); 192 size_t msg_size = ntohs (msg->header.size);
198 193
199 res = GNUNET_malloc (sizeof (struct FragmentResult) + msg_size); 194 struct GNUNET_MQ_Envelope *
200 res->header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_FRAGMENT); 195 env = GNUNET_MQ_msg_extra (res, msg_size,
201 res->header.size = htons (sizeof (struct FragmentResult) + msg_size); 196 GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_FRAGMENT);
202 res->op_id = sc->op_id; 197 res->op_id = sc->op_id;
203 res->psycstore_flags = htonl (flags); 198 res->psycstore_flags = htonl (flags);
204 GNUNET_memcpy (&res[1], msg, msg_size); 199 GNUNET_memcpy (&res[1], msg, msg_size);
@@ -206,10 +201,8 @@ send_fragment (void *cls, struct GNUNET_MULTICAST_MessageHeader *msg,
206 "Sending fragment %ld to client\n", 201 "Sending fragment %ld to client\n",
207 GNUNET_ntohll (msg->fragment_id)); 202 GNUNET_ntohll (msg->fragment_id));
208 GNUNET_free (msg); 203 GNUNET_free (msg);
209 GNUNET_SERVER_notification_context_add (nc, sc->client); 204
210 GNUNET_SERVER_notification_context_unicast (nc, sc->client, &res->header, 205 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (sc->client), env);
211 GNUNET_NO);
212 GNUNET_free (res);
213 return GNUNET_YES; 206 return GNUNET_YES;
214} 207}
215 208
@@ -224,30 +217,26 @@ send_state_var (void *cls, const char *name,
224 217
225 /** @todo FIXME: split up value into 64k chunks */ 218 /** @todo FIXME: split up value into 64k chunks */
226 219
227 res = GNUNET_malloc (sizeof (struct StateResult) + name_size + value_size); 220 struct GNUNET_MQ_Envelope *
228 res->header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_STATE); 221 env = GNUNET_MQ_msg_extra (res, name_size + value_size,
229 res->header.size = htons (sizeof (struct StateResult) + name_size + value_size); 222 GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_STATE);
230 res->op_id = sc->op_id; 223 res->op_id = sc->op_id;
231 res->name_size = htons (name_size); 224 res->name_size = htons (name_size);
232 GNUNET_memcpy (&res[1], name, name_size); 225 GNUNET_memcpy (&res[1], name, name_size);
233 GNUNET_memcpy ((char *) &res[1] + name_size, value, value_size); 226 GNUNET_memcpy ((char *) &res[1] + name_size, value, value_size);
234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 227 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
235 "Sending state variable %s to client\n", name); 228 "Sending state variable %s to client\n", name);
236 GNUNET_SERVER_notification_context_add (nc, sc->client); 229
237 GNUNET_SERVER_notification_context_unicast (nc, sc->client, &res->header, 230 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (sc->client), env);
238 GNUNET_NO);
239 GNUNET_free (res);
240 return GNUNET_OK; 231 return GNUNET_OK;
241} 232}
242 233
243 234
244static void 235static void
245handle_membership_store (void *cls, 236handle_client_membership_store (void *cls,
246 struct GNUNET_SERVER_Client *client, 237 const struct MembershipStoreRequest *req)
247 const struct GNUNET_MessageHeader *msg)
248{ 238{
249 const struct MembershipStoreRequest *req = 239 struct GNUNET_SERVICE_Client *client = cls;
250 (const struct MembershipStoreRequest *) msg;
251 240
252 int ret = db->membership_store (db->cls, &req->channel_key, &req->slave_key, 241 int ret = db->membership_store (db->cls, &req->channel_key, &req->slave_key,
253 req->did_join, 242 req->did_join,
@@ -260,17 +249,15 @@ handle_membership_store (void *cls,
260 _("Failed to store membership information!\n")); 249 _("Failed to store membership information!\n"));
261 250
262 send_result_code (client, req->op_id, ret, NULL); 251 send_result_code (client, req->op_id, ret, NULL);
263 GNUNET_SERVER_receive_done (client, GNUNET_OK); 252 GNUNET_SERVICE_client_continue (client);
264} 253}
265 254
266 255
267static void 256static void
268handle_membership_test (void *cls, 257handle_client_membership_test (void *cls,
269 struct GNUNET_SERVER_Client *client, 258 const struct MembershipTestRequest *req)
270 const struct GNUNET_MessageHeader *msg)
271{ 259{
272 const struct MembershipTestRequest *req = 260 struct GNUNET_SERVICE_Client *client = cls;
273 (const struct MembershipTestRequest *) msg;
274 261
275 int ret = db->membership_test (db->cls, &req->channel_key, &req->slave_key, 262 int ret = db->membership_test (db->cls, &req->channel_key, &req->slave_key,
276 GNUNET_ntohll (req->message_id)); 263 GNUNET_ntohll (req->message_id));
@@ -285,17 +272,15 @@ handle_membership_test (void *cls,
285 } 272 }
286 273
287 send_result_code (client, req->op_id, ret, NULL); 274 send_result_code (client, req->op_id, ret, NULL);
288 GNUNET_SERVER_receive_done (client, GNUNET_OK); 275 GNUNET_SERVICE_client_continue (client);
289} 276}
290 277
291 278
292static void 279static void
293handle_fragment_store (void *cls, 280handle_client_fragment_store (void *cls,
294 struct GNUNET_SERVER_Client *client, 281 const struct FragmentStoreRequest *req)
295 const struct GNUNET_MessageHeader *msg)
296{ 282{
297 const struct FragmentStoreRequest *req = 283 struct GNUNET_SERVICE_Client *client = cls;
298 (const struct FragmentStoreRequest *) msg;
299 284
300 int ret = db->fragment_store (db->cls, &req->channel_key, 285 int ret = db->fragment_store (db->cls, &req->channel_key,
301 (const struct GNUNET_MULTICAST_MessageHeader *) 286 (const struct GNUNET_MULTICAST_MessageHeader *)
@@ -306,17 +291,16 @@ handle_fragment_store (void *cls,
306 _("Failed to store fragment!\n")); 291 _("Failed to store fragment!\n"));
307 292
308 send_result_code (client, req->op_id, ret, NULL); 293 send_result_code (client, req->op_id, ret, NULL);
309 GNUNET_SERVER_receive_done (client, GNUNET_OK); 294 GNUNET_SERVICE_client_continue (client);
310} 295}
311 296
312 297
313static void 298static void
314handle_fragment_get (void *cls, 299handle_client_fragment_get (void *cls,
315 struct GNUNET_SERVER_Client *client, 300 const struct FragmentGetRequest *req)
316 const struct GNUNET_MessageHeader *msg)
317{ 301{
318 const struct FragmentGetRequest * 302 struct GNUNET_SERVICE_Client *client = cls;
319 req = (const struct FragmentGetRequest *) msg; 303
320 struct SendClosure 304 struct SendClosure
321 sc = { .op_id = req->op_id, 305 sc = { .op_id = req->op_id,
322 .client = client, 306 .client = client,
@@ -364,18 +348,17 @@ handle_fragment_get (void *cls,
364 _("Failed to get fragment!\n")); 348 _("Failed to get fragment!\n"));
365 } 349 }
366 send_result_code (client, req->op_id, (ret < 0) ? ret : ret_frags, NULL); 350 send_result_code (client, req->op_id, (ret < 0) ? ret : ret_frags, NULL);
367 GNUNET_SERVER_receive_done (client, GNUNET_OK); 351 GNUNET_SERVICE_client_continue (client);
368} 352}
369 353
370 354
371static void 355static void
372handle_message_get (void *cls, 356handle_client_message_get (void *cls,
373 struct GNUNET_SERVER_Client *client, 357 const struct MessageGetRequest *req)
374 const struct GNUNET_MessageHeader *msg)
375{ 358{
376 const struct MessageGetRequest * 359 struct GNUNET_SERVICE_Client *client = cls;
377 req = (const struct MessageGetRequest *) msg; 360
378 uint16_t size = ntohs (msg->size); 361 uint16_t size = ntohs (req->header.size);
379 const char *method_prefix = (const char *) &req[1]; 362 const char *method_prefix = (const char *) &req[1];
380 363
381 if (size < sizeof (*req) + 1 364 if (size < sizeof (*req) + 1
@@ -386,7 +369,7 @@ handle_message_get (void *cls,
386 size, 369 size,
387 (unsigned int) (sizeof (*req) + 1)); 370 (unsigned int) (sizeof (*req) + 1));
388 GNUNET_break (0); 371 GNUNET_break (0);
389 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 372 GNUNET_SERVICE_client_drop (client);
390 return; 373 return;
391 } 374 }
392 375
@@ -424,17 +407,16 @@ handle_message_get (void *cls,
424 } 407 }
425 408
426 send_result_code (client, req->op_id, (ret < 0) ? ret : ret_frags, NULL); 409 send_result_code (client, req->op_id, (ret < 0) ? ret : ret_frags, NULL);
427 GNUNET_SERVER_receive_done (client, GNUNET_OK); 410 GNUNET_SERVICE_client_continue (client);
428} 411}
429 412
430 413
431static void 414static void
432handle_message_get_fragment (void *cls, 415handle_client_message_get_fragment (void *cls,
433 struct GNUNET_SERVER_Client *client, 416 const struct MessageGetFragmentRequest *req)
434 const struct GNUNET_MessageHeader *msg)
435{ 417{
436 const struct MessageGetFragmentRequest * 418 struct GNUNET_SERVICE_Client *client = cls;
437 req = (const struct MessageGetFragmentRequest *) msg; 419
438 struct SendClosure 420 struct SendClosure
439 sc = { .op_id = req->op_id, .client = client, 421 sc = { .op_id = req->op_id, .client = client,
440 .channel_key = req->channel_key, .slave_key = req->slave_key, 422 .channel_key = req->channel_key, .slave_key = req->slave_key,
@@ -455,26 +437,28 @@ handle_message_get_fragment (void *cls,
455 } 437 }
456 438
457 send_result_code (client, req->op_id, ret, NULL); 439 send_result_code (client, req->op_id, ret, NULL);
458 GNUNET_SERVER_receive_done (client, GNUNET_OK); 440 GNUNET_SERVICE_client_continue (client);
459} 441}
460 442
461 443
462static void 444static void
463handle_counters_get (void *cls, 445handle_client_counters_get (void *cls,
464 struct GNUNET_SERVER_Client *client, 446 const struct OperationRequest *req)
465 const struct GNUNET_MessageHeader *msg)
466{ 447{
467 const struct OperationRequest *req = (const struct OperationRequest *) msg; 448 struct GNUNET_SERVICE_Client *client = cls;
468 struct CountersResult res = { {0} }; 449
450 struct CountersResult *res;
451 struct GNUNET_MQ_Envelope *
452 env = GNUNET_MQ_msg (res, GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS);
469 453
470 int ret = db->counters_message_get (db->cls, &req->channel_key, 454 int ret = db->counters_message_get (db->cls, &req->channel_key,
471 &res.max_fragment_id, &res.max_message_id, 455 &res->max_fragment_id, &res->max_message_id,
472 &res.max_group_generation); 456 &res->max_group_generation);
473 switch (ret) 457 switch (ret)
474 { 458 {
475 case GNUNET_OK: 459 case GNUNET_OK:
476 ret = db->counters_state_get (db->cls, &req->channel_key, 460 ret = db->counters_state_get (db->cls, &req->channel_key,
477 &res.max_state_message_id); 461 &res->max_state_message_id);
478 case GNUNET_NO: 462 case GNUNET_NO:
479 break; 463 break;
480 default: 464 default:
@@ -482,20 +466,15 @@ handle_counters_get (void *cls,
482 _("Failed to get master counters!\n")); 466 _("Failed to get master counters!\n"));
483 } 467 }
484 468
485 res.header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS); 469 res->result_code = htonl (ret);
486 res.header.size = htons (sizeof (res)); 470 res->op_id = req->op_id;
487 res.result_code = htonl (ret); 471 res->max_fragment_id = GNUNET_htonll (res->max_fragment_id);
488 res.op_id = req->op_id; 472 res->max_message_id = GNUNET_htonll (res->max_message_id);
489 res.max_fragment_id = GNUNET_htonll (res.max_fragment_id); 473 res->max_group_generation = GNUNET_htonll (res->max_group_generation);
490 res.max_message_id = GNUNET_htonll (res.max_message_id); 474 res->max_state_message_id = GNUNET_htonll (res->max_state_message_id);
491 res.max_group_generation = GNUNET_htonll (res.max_group_generation);
492 res.max_state_message_id = GNUNET_htonll (res.max_state_message_id);
493 475
494 GNUNET_SERVER_notification_context_add (nc, client); 476 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
495 GNUNET_SERVER_notification_context_unicast (nc, client, &res.header, 477 GNUNET_SERVICE_client_continue (client);
496 GNUNET_NO);
497
498 GNUNET_SERVER_receive_done (client, GNUNET_OK);
499} 478}
500 479
501 480
@@ -648,12 +627,10 @@ recv_state_fragment (void *cls, struct GNUNET_MULTICAST_MessageHeader *msg,
648 627
649 628
650static void 629static void
651handle_state_modify (void *cls, 630handle_client_state_modify (void *cls,
652 struct GNUNET_SERVER_Client *client, 631 const struct StateModifyRequest *req)
653 const struct GNUNET_MessageHeader *msg)
654{ 632{
655 const struct StateModifyRequest *req 633 struct GNUNET_SERVICE_Client *client = cls;
656 = (const struct StateModifyRequest *) msg;
657 634
658 uint64_t message_id = GNUNET_ntohll (req->message_id); 635 uint64_t message_id = GNUNET_ntohll (req->message_id);
659 uint64_t state_delta = GNUNET_ntohll (req->state_delta); 636 uint64_t state_delta = GNUNET_ntohll (req->state_delta);
@@ -696,18 +673,24 @@ handle_state_modify (void *cls,
696 } 673 }
697 674
698 send_result_code (client, req->op_id, ret, NULL); 675 send_result_code (client, req->op_id, ret, NULL);
699 GNUNET_SERVER_receive_done (client, GNUNET_OK); 676 GNUNET_SERVICE_client_continue (client);
677}
678
679
680static int
681check_client_state_sync (void *cls,
682 const struct StateSyncRequest *req)
683{
684 return GNUNET_OK;
700} 685}
701 686
702 687
703/** @todo FIXME: stop processing further state sync messages after an error */ 688/** @todo FIXME: stop processing further state sync messages after an error */
704static void 689static void
705handle_state_sync (void *cls, 690handle_client_state_sync (void *cls,
706 struct GNUNET_SERVER_Client *client, 691 const struct StateSyncRequest *req)
707 const struct GNUNET_MessageHeader *msg)
708{ 692{
709 const struct StateSyncRequest *req 693 struct GNUNET_SERVICE_Client *client = cls;
710 = (const struct StateSyncRequest *) msg;
711 694
712 int ret = GNUNET_SYSERR; 695 int ret = GNUNET_SYSERR;
713 const char *name = (const char *) &req[1]; 696 const char *name = (const char *) &req[1];
@@ -751,17 +734,15 @@ handle_state_sync (void *cls,
751 } 734 }
752 } 735 }
753 send_result_code (client, req->op_id, ret, NULL); 736 send_result_code (client, req->op_id, ret, NULL);
754 GNUNET_SERVER_receive_done (client, GNUNET_OK); 737 GNUNET_SERVICE_client_continue (client);
755} 738}
756 739
757 740
758static void 741static void
759handle_state_reset (void *cls, 742handle_client_state_reset (void *cls,
760 struct GNUNET_SERVER_Client *client, 743 const struct OperationRequest *req)
761 const struct GNUNET_MessageHeader *msg)
762{ 744{
763 const struct OperationRequest *req = 745 struct GNUNET_SERVICE_Client *client = cls;
764 (const struct OperationRequest *) msg;
765 746
766 int ret = db->state_reset (db->cls, &req->channel_key); 747 int ret = db->state_reset (db->cls, &req->channel_key);
767 748
@@ -770,36 +751,39 @@ handle_state_reset (void *cls,
770 _("Failed to reset state!\n")); 751 _("Failed to reset state!\n"));
771 752
772 send_result_code (client, req->op_id, ret, NULL); 753 send_result_code (client, req->op_id, ret, NULL);
773 GNUNET_SERVER_receive_done (client, GNUNET_OK); 754 GNUNET_SERVICE_client_continue (client);
774} 755}
775 756
776 757
777static void 758static void
778handle_state_hash_update (void *cls, 759handle_client_state_hash_update (void *cls,
779 struct GNUNET_SERVER_Client *client, 760 const struct StateHashUpdateRequest *req)
780 const struct GNUNET_MessageHeader *msg)
781{ 761{
782 const struct OperationRequest *req = 762 struct GNUNET_SERVICE_Client *client = cls;
783 (const struct OperationRequest *) msg;
784 763
785 int ret = db->state_reset (db->cls, &req->channel_key); 764 int ret = db->state_reset (db->cls, &req->channel_key);
786
787 if (ret != GNUNET_OK) 765 if (ret != GNUNET_OK)
788 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 766 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
789 _("Failed to reset state!\n")); 767 _("Failed to reset state!\n"));
790 768
791 send_result_code (client, req->op_id, ret, NULL); 769 send_result_code (client, req->op_id, ret, NULL);
792 GNUNET_SERVER_receive_done (client, GNUNET_OK); 770 GNUNET_SERVICE_client_continue (client);
771}
772
773
774static int
775check_client_state_get (void *cls,
776 const struct OperationRequest *req)
777{
778 return GNUNET_OK;
793} 779}
794 780
795 781
796static void 782static void
797handle_state_get (void *cls, 783handle_client_state_get (void *cls,
798 struct GNUNET_SERVER_Client *client, 784 const struct OperationRequest *req)
799 const struct GNUNET_MessageHeader *msg)
800{ 785{
801 const struct OperationRequest *req = 786 struct GNUNET_SERVICE_Client *client = cls;
802 (const struct OperationRequest *) msg;
803 787
804 struct SendClosure sc = { .op_id = req->op_id, .client = client }; 788 struct SendClosure sc = { .op_id = req->op_id, .client = client };
805 int64_t ret = GNUNET_SYSERR; 789 int64_t ret = GNUNET_SYSERR;
@@ -840,17 +824,23 @@ handle_state_get (void *cls,
840 } 824 }
841 825
842 send_result_code (client, req->op_id, ret, NULL); 826 send_result_code (client, req->op_id, ret, NULL);
843 GNUNET_SERVER_receive_done (client, GNUNET_OK); 827 GNUNET_SERVICE_client_continue (client);
828}
829
830
831static int
832check_client_state_get_prefix (void *cls,
833 const struct OperationRequest *req)
834{
835 return GNUNET_OK;
844} 836}
845 837
846 838
847static void 839static void
848handle_state_get_prefix (void *cls, 840handle_client_state_get_prefix (void *cls,
849 struct GNUNET_SERVER_Client *client, 841 const struct OperationRequest *req)
850 const struct GNUNET_MessageHeader *msg)
851{ 842{
852 const struct OperationRequest *req = 843 struct GNUNET_SERVICE_Client *client = cls;
853 (const struct OperationRequest *) msg;
854 844
855 struct SendClosure sc = { .op_id = req->op_id, .client = client }; 845 struct SendClosure sc = { .op_id = req->op_id, .client = client };
856 int64_t ret = GNUNET_SYSERR; 846 int64_t ret = GNUNET_SYSERR;
@@ -879,72 +869,59 @@ handle_state_get_prefix (void *cls,
879 } 869 }
880 870
881 send_result_code (client, req->op_id, ret, NULL); 871 send_result_code (client, req->op_id, ret, NULL);
882 GNUNET_SERVER_receive_done (client, GNUNET_OK); 872 GNUNET_SERVICE_client_continue (client);
883} 873}
884 874
885 875
886/** 876/**
887 * Initialize the PSYCstore service. 877 * A new client connected.
888 * 878 *
889 * @param cls Closure. 879 * @param cls NULL
890 * @param server The initialized server. 880 * @param client client to add
891 * @param c Configuration to use. 881 * @param mq message queue for @a client
882 * @return @a client
892 */ 883 */
893static void 884static void *
894run (void *cls, struct GNUNET_SERVER_Handle *server, 885client_notify_connect (void *cls,
895 const struct GNUNET_CONFIGURATION_Handle *c) 886 struct GNUNET_SERVICE_Client *client,
887 struct GNUNET_MQ_Handle *mq)
896{ 888{
897 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 889 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client connected: %p\n", client);
898 { &handle_membership_store, NULL,
899 GNUNET_MESSAGE_TYPE_PSYCSTORE_MEMBERSHIP_STORE,
900 sizeof (struct MembershipStoreRequest) },
901
902 { &handle_membership_test, NULL,
903 GNUNET_MESSAGE_TYPE_PSYCSTORE_MEMBERSHIP_TEST,
904 sizeof (struct MembershipTestRequest) },
905
906 { &handle_fragment_store, NULL,
907 GNUNET_MESSAGE_TYPE_PSYCSTORE_FRAGMENT_STORE, 0, },
908
909 { &handle_fragment_get, NULL,
910 GNUNET_MESSAGE_TYPE_PSYCSTORE_FRAGMENT_GET,
911 sizeof (struct FragmentGetRequest) },
912
913 { &handle_message_get, NULL,
914 GNUNET_MESSAGE_TYPE_PSYCSTORE_MESSAGE_GET, 0 },
915
916 { &handle_message_get_fragment, NULL,
917 GNUNET_MESSAGE_TYPE_PSYCSTORE_MESSAGE_GET_FRAGMENT,
918 sizeof (struct MessageGetFragmentRequest) },
919 890
920 { &handle_counters_get, NULL, 891 return client;
921 GNUNET_MESSAGE_TYPE_PSYCSTORE_COUNTERS_GET, 892}
922 sizeof (struct OperationRequest) },
923
924 { &handle_state_modify, NULL,
925 GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_MODIFY, 0 },
926
927 { &handle_state_sync, NULL,
928 GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_SYNC, 0 },
929
930 { &handle_state_reset, NULL,
931 GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_RESET,
932 sizeof (struct OperationRequest) },
933
934 { &handle_state_hash_update, NULL,
935 GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_HASH_UPDATE,
936 sizeof (struct StateHashUpdateRequest) },
937 893
938 { &handle_state_get, NULL,
939 GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_GET, 0 },
940 894
941 { &handle_state_get_prefix, NULL, 895/**
942 GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_GET_PREFIX, 0 }, 896 * Called whenever a client is disconnected.
897 * Frees our resources associated with that client.
898 *
899 * @param cls closure
900 * @param client identification of the client
901 * @param app_ctx must match @a client
902 */
903static void
904client_notify_disconnect (void *cls,
905 struct GNUNET_SERVICE_Client *client,
906 void *app_ctx)
907{
908}
943 909
944 { NULL, NULL, 0, 0 }
945 };
946 910
911/**
912 * Initialize the PSYCstore service.
913 *
914 * @param cls Closure.
915 * @param server The initialized server.
916 * @param c Configuration to use.
917 */
918static void
919run (void *cls,
920 const struct GNUNET_CONFIGURATION_Handle *c,
921 struct GNUNET_SERVICE_Handle *svc)
922{
947 cfg = c; 923 cfg = c;
924 service = svc;
948 925
949 /* Loading database plugin */ 926 /* Loading database plugin */
950 char *database; 927 char *database;
@@ -974,28 +951,71 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
974 } 951 }
975 952
976 stats = GNUNET_STATISTICS_create ("psycstore", cfg); 953 stats = GNUNET_STATISTICS_create ("psycstore", cfg);
977 GNUNET_SERVER_add_handlers (server, handlers); 954 GNUNET_SCHEDULER_add_shutdown (shutdown_task,
978 nc = GNUNET_SERVER_notification_context_create (server, 1);
979 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
980 NULL); 955 NULL);
981} 956}
982 957
983
984/** 958/**
985 * The main function for the service. 959 * Define "main" method using service macro.
986 *
987 * @param argc number of arguments from the command line
988 * @param argv command line arguments
989 * @return 0 ok, 1 on error
990 */ 960 */
991int 961GNUNET_SERVICE_MAIN
992main (int argc, char *const *argv) 962("psycstore",
993{ 963 GNUNET_SERVICE_OPTION_NONE,
994 return (GNUNET_OK == 964 run,
995 GNUNET_SERVICE_run (argc, argv, "psycstore", 965 client_notify_connect,
996 GNUNET_SERVICE_OPTION_NONE, 966 client_notify_disconnect,
997 &run, NULL)) ? 0 : 1; 967 NULL,
998} 968 GNUNET_MQ_hd_fixed_size (client_membership_store,
999 969 GNUNET_MESSAGE_TYPE_PSYCSTORE_MEMBERSHIP_STORE,
970 struct MembershipStoreRequest,
971 NULL),
972 GNUNET_MQ_hd_fixed_size (client_membership_test,
973 GNUNET_MESSAGE_TYPE_PSYCSTORE_MEMBERSHIP_TEST,
974 struct MembershipTestRequest,
975 NULL),
976 GNUNET_MQ_hd_fixed_size (client_fragment_store,
977 GNUNET_MESSAGE_TYPE_PSYCSTORE_FRAGMENT_STORE,
978 struct FragmentStoreRequest,
979 NULL),
980 GNUNET_MQ_hd_fixed_size (client_fragment_get,
981 GNUNET_MESSAGE_TYPE_PSYCSTORE_FRAGMENT_GET,
982 struct FragmentGetRequest,
983 NULL),
984 GNUNET_MQ_hd_fixed_size (client_message_get,
985 GNUNET_MESSAGE_TYPE_PSYCSTORE_MESSAGE_GET,
986 struct MessageGetRequest,
987 NULL),
988 GNUNET_MQ_hd_fixed_size (client_message_get_fragment,
989 GNUNET_MESSAGE_TYPE_PSYCSTORE_MESSAGE_GET_FRAGMENT,
990 struct MessageGetFragmentRequest,
991 NULL),
992 GNUNET_MQ_hd_fixed_size (client_counters_get,
993 GNUNET_MESSAGE_TYPE_PSYCSTORE_COUNTERS_GET,
994 struct OperationRequest,
995 NULL),
996 GNUNET_MQ_hd_fixed_size (client_state_modify,
997 GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_MODIFY,
998 struct StateModifyRequest,
999 NULL),
1000 GNUNET_MQ_hd_var_size (client_state_sync,
1001 GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_SYNC,
1002 struct StateSyncRequest,
1003 NULL),
1004 GNUNET_MQ_hd_fixed_size (client_state_reset,
1005 GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_RESET,
1006 struct OperationRequest,
1007 NULL),
1008 GNUNET_MQ_hd_fixed_size (client_state_hash_update,
1009 GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_HASH_UPDATE,
1010 struct StateHashUpdateRequest,
1011 NULL),
1012 GNUNET_MQ_hd_var_size (client_state_get,
1013 GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_GET,
1014 struct OperationRequest,
1015 NULL),
1016 GNUNET_MQ_hd_var_size (client_state_get_prefix,
1017 GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_GET_PREFIX,
1018 struct OperationRequest,
1019 NULL));
1000 1020
1001/* end of gnunet-service-psycstore.c */ 1021/* end of gnunet-service-psycstore.c */