-/*
+/**
* This file is part of GNUnet
- * Copyright (C) 2013 Christian Grothoff (and other contributing authors)
+ * Copyright (C) 2013 GNUnet e.V.
*
* GNUnet is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* Task run during shutdown.
*
* @param cls unused
- * @param tc unused
*/
static void
-shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls)
{
if (NULL != nc)
{
res->op_id = op_id;
if (0 < err_size)
{
- memcpy (&res[1], err_msg, err_size);
+ GNUNET_memcpy (&res[1], err_msg, err_size);
((char *) &res[1])[err_size - 1] = '\0';
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
res->header.size = htons (sizeof (struct FragmentResult) + msg_size);
res->op_id = sc->op_id;
res->psycstore_flags = htonl (flags);
- memcpy (&res[1], msg, msg_size);
+ GNUNET_memcpy (&res[1], msg, msg_size);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sending fragment %ld to client\n",
GNUNET_ntohll (msg->fragment_id));
static int
send_state_var (void *cls, const char *name,
- const void *value, size_t value_size)
+ const void *value, uint32_t value_size)
{
struct SendClosure *sc = cls;
struct StateResult *res;
res->header.size = htons (sizeof (struct StateResult) + name_size + value_size);
res->op_id = sc->op_id;
res->name_size = htons (name_size);
- memcpy (&res[1], name, name_size);
- memcpy ((char *) &res[1] + name_size, value, value_size);
+ GNUNET_memcpy (&res[1], name, name_size);
+ GNUNET_memcpy ((char *) &res[1] + name_size, value, value_size);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sending state variable %s to client\n", name);
GNUNET_SERVER_notification_context_add (nc, sc->client);
const struct FragmentGetRequest *
req = (const struct FragmentGetRequest *) msg;
struct SendClosure
- sc = { .op_id = req->op_id, .client = client,
- .channel_key = req->channel_key, .slave_key = req->slave_key,
+ sc = { .op_id = req->op_id,
+ .client = client,
+ .channel_key = req->channel_key,
+ .slave_key = req->slave_key,
.membership_test = req->do_membership_test };
int64_t ret;
if (0 == limit)
ret = db->fragment_get (db->cls, &req->channel_key,
first_fragment_id, last_fragment_id,
- &ret_frags, &send_fragment, &sc);
+ &ret_frags, send_fragment, &sc);
else
ret = db->fragment_get_latest (db->cls, &req->channel_key, limit,
- &ret_frags, &send_fragment, &sc);
+ &ret_frags, send_fragment, &sc);
switch (ret)
{
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Message get: invalid method prefix. size: %u < %u?\n",
- size, sizeof (*req) + 1);
+ size,
+ (unsigned int) (sizeof (*req) + 1));
GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
struct SendClosure
- sc = { .op_id = req->op_id, .client = client,
- .channel_key = req->channel_key, .slave_key = req->slave_key,
+ sc = { .op_id = req->op_id,
+ .client = client,
+ .channel_key = req->channel_key,
+ .slave_key = req->slave_key,
.membership_test = req->do_membership_test };
int64_t ret;
uint64_t ret_frags = 0;
uint64_t first_message_id = GNUNET_ntohll (req->first_message_id);
uint64_t last_message_id = GNUNET_ntohll (req->last_message_id);
- uint64_t limit = GNUNET_ntohll (req->message_limit);
+ uint64_t msg_limit = GNUNET_ntohll (req->message_limit);
+ uint64_t frag_limit = GNUNET_ntohll (req->fragment_limit);
/** @todo method_prefix */
- if (0 == limit)
+ if (0 == msg_limit)
ret = db->message_get (db->cls, &req->channel_key,
- first_message_id, last_message_id,
- &ret_frags, &send_fragment, &sc);
+ first_message_id, last_message_id, frag_limit,
+ &ret_frags, send_fragment, &sc);
else
- ret = db->message_get_latest (db->cls, &req->channel_key, limit,
- &ret_frags, &send_fragment, &sc);
+ ret = db->message_get_latest (db->cls, &req->channel_key, msg_limit,
+ &ret_frags, send_fragment, &sc);
switch (ret)
{
res.header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS);
res.header.size = htons (sizeof (res));
- res.result_code = htonl (ret - INT32_MIN);
+ res.result_code = htonl (ret);
res.op_id = req->op_id;
res.max_fragment_id = GNUNET_htonll (res.max_fragment_id);
res.max_message_id = GNUNET_htonll (res.max_message_id);
struct StateModifyClosure
{
- const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key;
+ const struct GNUNET_CRYPTO_EddsaPublicKey channel_key;
struct GNUNET_PSYC_ReceiveHandle *recv;
enum GNUNET_PSYC_MessageState msg_state;
char mod_oper;
char *mod_name;
char *mod_value;
- uint64_t mod_value_size;
- uint64_t mod_value_remaining;
+ uint32_t mod_value_size;
+ uint32_t mod_value_remaining;
};
static void
-recv_state_message_part (void *cls, uint64_t message_id, uint64_t data_offset,
- uint32_t flags, const struct GNUNET_MessageHeader *msg)
+recv_state_message_part (void *cls,
+ const struct GNUNET_PSYC_MessageHeader *msg,
+ const struct GNUNET_MessageHeader *pmsg)
{
struct StateModifyClosure *scls = cls;
uint16_t psize;
- if (NULL == msg)
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "recv_state_message_part() message_id: %" PRIu64
+ ", fragment_offset: %" PRIu64 ", flags: %u\n",
+ GNUNET_ntohll (msg->message_id),
+ GNUNET_ntohll (msg->fragment_offset),
+ ntohl (msg->flags));
+
+ if (NULL == pmsg)
{
scls->msg_state = GNUNET_PSYC_MESSAGE_STATE_ERROR;
return;
}
- switch (ntohs (msg->type))
+ switch (ntohs (pmsg->type))
{
case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD:
{
case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MODIFIER:
{
struct GNUNET_PSYC_MessageModifier *
- pmod = (struct GNUNET_PSYC_MessageModifier *) msg;
+ pmod = (struct GNUNET_PSYC_MessageModifier *) pmsg;
psize = ntohs (pmod->header.size);
uint16_t name_size = ntohs (pmod->name_size);
- uint16_t value_size = ntohs (pmod->value_size);
+ uint32_t value_size = ntohl (pmod->value_size);
const char *name = (const char *) &pmod[1];
const void *value = name + name_size;
- if (GNUNET_ENV_OP_SET != pmod->oper)
+ if (GNUNET_PSYC_OP_SET != pmod->oper)
{ // Apply non-transient operation.
if (psize == sizeof (*pmod) + name_size + value_size)
{
- db->state_modify_op (db->cls, scls->channel_key,
+ db->state_modify_op (db->cls, &scls->channel_key,
pmod->oper, name, value, value_size);
}
else
{
scls->mod_oper = pmod->oper;
scls->mod_name = GNUNET_malloc (name_size);
- memcpy (scls->mod_name, name, name_size);
+ GNUNET_memcpy (scls->mod_name, name, name_size);
scls->mod_value_size = value_size;
scls->mod_value = GNUNET_malloc (scls->mod_value_size);
scls->mod_value_remaining
= scls->mod_value_size - (psize - sizeof (*pmod) - name_size);
- memcpy (scls->mod_value, value, value_size - scls->mod_value_remaining);
+ GNUNET_memcpy (scls->mod_value, value, value_size - scls->mod_value_remaining);
}
}
scls->msg_state = GNUNET_PSYC_MESSAGE_STATE_MODIFIER;
}
case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MOD_CONT:
- if (GNUNET_ENV_OP_SET != scls->mod_oper)
+ if (GNUNET_PSYC_OP_SET != scls->mod_oper)
{
if (scls->mod_value_remaining == 0)
{
GNUNET_break_op (0);
scls->msg_state = GNUNET_PSYC_MESSAGE_STATE_ERROR;
}
- psize = ntohs (msg->size);
- memcpy (scls->mod_value + (scls->mod_value_size - scls->mod_value_remaining),
- &msg[1], psize - sizeof (*msg));
- scls->mod_value_remaining -= psize - sizeof (*msg);
+ psize = ntohs (pmsg->size);
+ GNUNET_memcpy (scls->mod_value + (scls->mod_value_size - scls->mod_value_remaining),
+ &pmsg[1], psize - sizeof (*pmsg));
+ scls->mod_value_remaining -= psize - sizeof (*pmsg);
if (0 == scls->mod_value_remaining)
{
- db->state_modify_op (db->cls, scls->channel_key,
+ db->state_modify_op (db->cls, &scls->channel_key,
scls->mod_oper, scls->mod_name,
scls->mod_value, scls->mod_value_size);
GNUNET_free (scls->mod_name);
if (NULL == scls->recv)
{
- scls->recv = GNUNET_PSYC_receive_create (NULL, &recv_state_message_part,
+ scls->recv = GNUNET_PSYC_receive_create (NULL, recv_state_message_part,
scls);
}
- const struct GNUNET_PSYC_MessageHeader *
- pmsg = (const struct GNUNET_PSYC_MessageHeader *) &msg[1];
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "recv_state_fragment: %" PRIu64 "\n", GNUNET_ntohll (msg->fragment_id));
+
+ struct GNUNET_PSYC_MessageHeader *
+ pmsg = GNUNET_PSYC_message_header_create (msg, flags);
GNUNET_PSYC_receive_message (scls->recv, pmsg);
+ GNUNET_free (pmsg);
return GNUNET_YES;
}
uint64_t message_id = GNUNET_ntohll (req->message_id);
uint64_t state_delta = GNUNET_ntohll (req->state_delta);
uint64_t ret_frags = 0;
+ struct StateModifyClosure
+ scls = { .channel_key = req->channel_key };
- struct StateModifyClosure scls = { 0 };
+ int ret = db->state_modify_begin (db->cls, &req->channel_key,
+ message_id, state_delta);
- if (GNUNET_OK != db->state_modify_begin (db->cls, &req->channel_key,
- message_id, state_delta))
+ if (GNUNET_OK != ret)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to begin modifying state!\n"));
- GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to begin modifying state: %d\n"), ret);
}
-
- int ret = db->message_get (db->cls, &req->channel_key,
- message_id, message_id,
- &ret_frags, &recv_state_fragment, &scls);
-
- if (GNUNET_OK != db->state_modify_end (db->cls, &req->channel_key, message_id))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to end modifying state!\n"));
- GNUNET_break (0);
- }
-
- if (NULL != scls.recv)
+ else
{
- GNUNET_PSYC_receive_destroy (scls.recv);
+ ret = db->message_get (db->cls, &req->channel_key,
+ message_id, message_id, 0,
+ &ret_frags, recv_state_fragment, &scls);
+ if (GNUNET_OK != ret)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to modify state: %d\n"), ret);
+ GNUNET_break (0);
+ }
+ else
+ {
+ if (GNUNET_OK != db->state_modify_end (db->cls, &req->channel_key, message_id))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to end modifying state!\n"));
+ GNUNET_break (0);
+ }
+ }
+ if (NULL != scls.recv)
+ {
+ GNUNET_PSYC_receive_destroy (scls.recv);
+ }
}
send_result_code (client, req->op_id, ret, NULL);
if (GNUNET_NO == ret && name_size >= 5) /* min: _a_b\0 */
{
char *p, *n = GNUNET_malloc (name_size);
- memcpy (n, name, name_size);
+ GNUNET_memcpy (n, name, name_size);
while (&n[1] < (p = strrchr (n, '_')) && GNUNET_NO == ret)
{
*p = '\0';
GNUNET_CONFIGURATION_get_value_string (cfg, "psycstore", "database",
&database))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No database backend configured\n");
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "psycstore",
+ "database");
}
else
{
- GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_psycstore_%s", database);
+ GNUNET_asprintf (&db_lib_name,
+ "libgnunet_plugin_psycstore_%s",
+ database);
db = GNUNET_PLUGIN_load (db_lib_name, (void *) cfg);
GNUNET_free (database);
}
stats = GNUNET_STATISTICS_create ("psycstore", cfg);
GNUNET_SERVER_add_handlers (server, handlers);
nc = GNUNET_SERVER_notification_context_create (server, 1);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}