diff options
author | Gabor X Toth <*@tg-x.net> | 2013-09-25 17:46:03 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2013-09-25 17:46:03 +0000 |
commit | 303d6a97bc552a337c992944c3151ea53c1f74dc (patch) | |
tree | 295d478fd8e82879830588da0c47778512ffad9b /src/psycstore/gnunet-service-psycstore.c | |
parent | ffc11bb1c2c09cda9e7bed84e56cedb8ed49d46c (diff) | |
download | gnunet-303d6a97bc552a337c992944c3151ea53c1f74dc.tar.gz gnunet-303d6a97bc552a337c992944c3151ea53c1f74dc.zip |
psycstore: single counters function for master & slave
Diffstat (limited to 'src/psycstore/gnunet-service-psycstore.c')
-rw-r--r-- | src/psycstore/gnunet-service-psycstore.c | 72 |
1 files changed, 17 insertions, 55 deletions
diff --git a/src/psycstore/gnunet-service-psycstore.c b/src/psycstore/gnunet-service-psycstore.c index 14945641f..128bfd46c 100644 --- a/src/psycstore/gnunet-service-psycstore.c +++ b/src/psycstore/gnunet-service-psycstore.c | |||
@@ -170,7 +170,7 @@ send_state_var (void *cls, const char *name, | |||
170 | res->op_id = sc->op_id; | 170 | res->op_id = sc->op_id; |
171 | res->name_size = htons (name_size); | 171 | res->name_size = htons (name_size); |
172 | memcpy (&res[1], name, name_size); | 172 | memcpy (&res[1], name, name_size); |
173 | memcpy ((void *) &res[1] + name_size, value, value_size); | 173 | memcpy ((char *) &res[1] + name_size, value, value_size); |
174 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 174 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
175 | "Sending state variable %s to client\n", name); | 175 | "Sending state variable %s to client\n", name); |
176 | GNUNET_SERVER_notification_context_add (nc, sc->client); | 176 | GNUNET_SERVER_notification_context_add (nc, sc->client); |
@@ -334,19 +334,21 @@ handle_message_get_fragment (void *cls, | |||
334 | 334 | ||
335 | 335 | ||
336 | static void | 336 | static void |
337 | handle_counters_get_master (void *cls, | 337 | handle_counters_get (void *cls, |
338 | struct GNUNET_SERVER_Client *client, | 338 | struct GNUNET_SERVER_Client *client, |
339 | const struct GNUNET_MessageHeader *msg) | 339 | const struct GNUNET_MessageHeader *msg) |
340 | { | 340 | { |
341 | const struct OperationRequest *req = (const struct OperationRequest *) msg; | 341 | const struct OperationRequest *req = (const struct OperationRequest *) msg; |
342 | struct MasterCountersResult res = { {0} }; | 342 | struct CountersResult res = { {0} }; |
343 | 343 | ||
344 | int ret = db->counters_get_master (db->cls, &req->channel_key, | 344 | int ret = db->counters_message_get (db->cls, &req->channel_key, |
345 | &res.fragment_id, &res.message_id, | 345 | &res.max_fragment_id, &res.max_message_id, |
346 | &res.group_generation); | 346 | &res.max_group_generation); |
347 | switch (ret) | 347 | switch (ret) |
348 | { | 348 | { |
349 | case GNUNET_YES: | 349 | case GNUNET_YES: |
350 | ret = db->counters_state_get (db->cls, &req->channel_key, | ||
351 | &res.max_state_message_id); | ||
350 | case GNUNET_NO: | 352 | case GNUNET_NO: |
351 | break; | 353 | break; |
352 | default: | 354 | default: |
@@ -354,50 +356,14 @@ handle_counters_get_master (void *cls, | |||
354 | _("Failed to get master counters!\n")); | 356 | _("Failed to get master counters!\n")); |
355 | } | 357 | } |
356 | 358 | ||
357 | res.header.type | 359 | res.header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS); |
358 | = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS_MASTER); | ||
359 | res.header.size = htons (sizeof (res)); | ||
360 | res.result_code = htonl (ret); | ||
361 | res.op_id = req->op_id; | ||
362 | res.fragment_id = GNUNET_htonll (res.fragment_id); | ||
363 | res.message_id = GNUNET_htonll (res.message_id); | ||
364 | res.group_generation = GNUNET_htonll (res.group_generation); | ||
365 | |||
366 | GNUNET_SERVER_notification_context_add (nc, client); | ||
367 | GNUNET_SERVER_notification_context_unicast (nc, client, &res.header, | ||
368 | GNUNET_NO); | ||
369 | |||
370 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
371 | } | ||
372 | |||
373 | |||
374 | static void | ||
375 | handle_counters_get_slave (void *cls, | ||
376 | struct GNUNET_SERVER_Client *client, | ||
377 | const struct GNUNET_MessageHeader *msg) | ||
378 | { | ||
379 | const struct OperationRequest *req = (const struct OperationRequest *) msg; | ||
380 | struct SlaveCountersResult res = { {0} }; | ||
381 | |||
382 | int ret = db->counters_get_slave (db->cls, &req->channel_key, | ||
383 | &res.max_known_msg_id); | ||
384 | |||
385 | switch (ret) | ||
386 | { | ||
387 | case GNUNET_YES: | ||
388 | case GNUNET_NO: | ||
389 | break; | ||
390 | default: | ||
391 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
392 | _("Failed to get slave counters!\n")); | ||
393 | } | ||
394 | |||
395 | res.header.type | ||
396 | = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS_SLAVE); | ||
397 | res.header.size = htons (sizeof (res)); | 360 | res.header.size = htons (sizeof (res)); |
398 | res.result_code = htonl (ret); | 361 | res.result_code = htonl (ret); |
399 | res.op_id = req->op_id; | 362 | res.op_id = req->op_id; |
400 | res.max_known_msg_id = GNUNET_htonll (res.max_known_msg_id); | 363 | res.max_fragment_id = GNUNET_htonll (res.max_fragment_id); |
364 | res.max_message_id = GNUNET_htonll (res.max_message_id); | ||
365 | res.max_group_generation = GNUNET_htonll (res.max_group_generation); | ||
366 | res.max_state_message_id = GNUNET_htonll (res.max_state_message_id); | ||
401 | 367 | ||
402 | GNUNET_SERVER_notification_context_add (nc, client); | 368 | GNUNET_SERVER_notification_context_add (nc, client); |
403 | GNUNET_SERVER_notification_context_unicast (nc, client, &res.header, | 369 | GNUNET_SERVER_notification_context_unicast (nc, client, &res.header, |
@@ -697,12 +663,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
697 | GNUNET_MESSAGE_TYPE_PSYCSTORE_MESSAGE_GET_FRAGMENT, | 663 | GNUNET_MESSAGE_TYPE_PSYCSTORE_MESSAGE_GET_FRAGMENT, |
698 | sizeof (struct MessageGetFragmentRequest) }, | 664 | sizeof (struct MessageGetFragmentRequest) }, |
699 | 665 | ||
700 | { &handle_counters_get_master, NULL, | 666 | { &handle_counters_get, NULL, |
701 | GNUNET_MESSAGE_TYPE_PSYCSTORE_COUNTERS_GET_MASTER, | 667 | GNUNET_MESSAGE_TYPE_PSYCSTORE_COUNTERS_GET, |
702 | sizeof (struct OperationRequest) }, | ||
703 | |||
704 | { &handle_counters_get_slave, NULL, | ||
705 | GNUNET_MESSAGE_TYPE_PSYCSTORE_COUNTERS_GET_SLAVE, | ||
706 | sizeof (struct OperationRequest) }, | 668 | sizeof (struct OperationRequest) }, |
707 | 669 | ||
708 | { &handle_state_modify, NULL, | 670 | { &handle_state_modify, NULL, |