pmsg = (struct GNUNET_PSYC_MessageHeader *) GNUNET_MQ_extract_nested_mh (res);
uint16_t size = ntohs (res->header.size);
- if (NULL == pmsg || size < sizeof (*res) + sizeof (*pmsg))
+ if ( (NULL == pmsg) ||
+ (size < sizeof (*res) + sizeof (*pmsg)) )
{ /* Error, message too small. */
GNUNET_break_op (0);
return GNUNET_SYSERR;
struct GNUNET_PSYC_Channel *chn = cls;
struct GNUNET_PSYC_MessageHeader *
pmsg = (struct GNUNET_PSYC_MessageHeader *) GNUNET_MQ_extract_nested_mh (res);
+ GNUNET_ResultCallback result_cb = NULL;
+ struct GNUNET_PSYC_HistoryRequest *hist = NULL;
LOG (GNUNET_ERROR_TYPE_DEBUG,
"%p Received historic fragment for message #%" PRIu64 ".\n",
- chn, GNUNET_ntohll (pmsg->message_id));
-
- GNUNET_ResultCallback result_cb = NULL;
- struct GNUNET_PSYC_HistoryRequest *hist = NULL;
+ chn,
+ GNUNET_ntohll (pmsg->message_id));
if (GNUNET_YES != GNUNET_OP_get (chn->op,
GNUNET_ntohll (res->op_id),
const struct GNUNET_OperationResultMessage *res)
{
const struct GNUNET_MessageHeader *mod = GNUNET_MQ_extract_nested_mh (res);
- uint16_t mod_size = ntohs (mod->size);
- uint16_t size = ntohs (res->header.size);
+ uint16_t mod_size;
+ uint16_t size;
- if (NULL == mod || size - sizeof (*res) != mod_size)
+ if (NULL == mod)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ mod_size = ntohs (mod->size);
+ size = ntohs (res->header.size);
+ if (size - sizeof (*res) != mod_size)
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
const struct GNUNET_MessageHeader *mod = GNUNET_MQ_extract_nested_mh (res);
+ if (NULL == mod)
+ {
+ GNUNET_break_op (0);
+ return;
+ }
uint16_t mod_size = ntohs (mod->size);
switch (ntohs (mod->type))
const char *name = (const char *) &pmod[1];
uint16_t name_size = ntohs (pmod->name_size);
- if ('\0' != name[name_size - 1])
+ if (0 == name_size
+ || mod_size - sizeof (*pmod) < name_size
+ || '\0' != name[name_size - 1])
{
- GNUNET_break (0);
+ GNUNET_break_op (0);
return;
}
sr->var_cb (sr->cls, mod, name, name + name_size,
check_master_join_request (void *cls,
const struct GNUNET_PSYC_JoinRequestMessage *req)
{
+ if ( ((sizeof (*req) + sizeof (struct GNUNET_PSYC_Message)) <= ntohs (req->header.size)) &&
+ (NULL == GNUNET_MQ_extract_nested_mh (req)) )
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
join_msg = (struct GNUNET_PSYC_Message *) GNUNET_MQ_extract_nested_mh (req);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Received join_msg of type %u and size %u.\n",
- ntohs (join_msg->header.type), ntohs (join_msg->header.size));
+ ntohs (join_msg->header.type),
+ ntohs (join_msg->header.size));
}
struct GNUNET_PSYC_JoinHandle *jh = GNUNET_malloc (sizeof (*jh));
GNUNET_MQ_discard (chn->connect_env);
chn->connect_env = NULL;
}
+ if (NULL != chn->mq)
+ {
+ GNUNET_MQ_destroy (chn->mq);
+ chn->mq = NULL;
+ }
if (NULL != chn->disconnect_cb)
{
chn->disconnect_cb (chn->disconnect_cls);
chn->disconnect_cb = NULL;
}
-}
-
-
-static void
-master_cleanup (void *cls)
-{
- struct GNUNET_PSYC_Master *mst = cls;
- channel_cleanup (&mst->chn);
- GNUNET_free (mst);
-}
-
-
-static void
-slave_cleanup (void *cls)
-{
- struct GNUNET_PSYC_Slave *slv = cls;
- channel_cleanup (&slv->chn);
- GNUNET_free (slv);
+ GNUNET_free (chn);
}
chn->disconnect_cb = cb;
chn->disconnect_cls = cls;
- // FIXME: wait till queued messages are sent
if (NULL != chn->mq)
{
- GNUNET_MQ_destroy (chn->mq);
- chn->mq = NULL;
+ struct GNUNET_MQ_Envelope *env = GNUNET_MQ_get_last_envelope (chn->mq);
+ if (NULL != env)
+ {
+ GNUNET_MQ_notify_sent (env, (GNUNET_SCHEDULER_TaskCallback) channel_cleanup, chn);
+ }
+ else
+ {
+ channel_cleanup (chn);
+ }
+ }
+ else
+ {
+ channel_cleanup (chn);
}
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Master client disconnected (%d), re-connecting\n",
(int) error);
- if (NULL != chn->mq)
- {
- GNUNET_MQ_destroy (chn->mq);
- chn->mq = NULL;
- }
if (NULL != chn->tmit)
{
GNUNET_PSYC_transmit_destroy (chn->tmit);
chn->tmit = NULL;
}
-
+ if (NULL != chn->mq)
+ {
+ GNUNET_MQ_destroy (chn->mq);
+ chn->mq = NULL;
+ }
chn->reconnect_task = GNUNET_SCHEDULER_add_delayed (chn->reconnect_delay,
master_reconnect,
mst);
{
struct GNUNET_PSYC_Channel *chn = &mst->chn;
- GNUNET_MQ_hd_fixed_size (master_start_ack,
- GNUNET_MESSAGE_TYPE_PSYC_MASTER_START_ACK,
- struct GNUNET_PSYC_CountersResultMessage);
-
- GNUNET_MQ_hd_var_size (master_join_request,
- GNUNET_MESSAGE_TYPE_PSYC_JOIN_REQUEST,
- struct GNUNET_PSYC_JoinRequestMessage);
-
- GNUNET_MQ_hd_var_size (channel_message,
- GNUNET_MESSAGE_TYPE_PSYC_MESSAGE,
- struct GNUNET_PSYC_MessageHeader);
-
- GNUNET_MQ_hd_fixed_size (channel_message_ack,
- GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_ACK,
- struct GNUNET_MessageHeader);
-
- GNUNET_MQ_hd_var_size (channel_history_result,
- GNUNET_MESSAGE_TYPE_PSYC_HISTORY_RESULT,
- struct GNUNET_OperationResultMessage);
-
- GNUNET_MQ_hd_var_size (channel_state_result,
- GNUNET_MESSAGE_TYPE_PSYC_STATE_RESULT,
- struct GNUNET_OperationResultMessage);
-
- GNUNET_MQ_hd_var_size (channel_result,
- GNUNET_MESSAGE_TYPE_PSYC_RESULT_CODE,
- struct GNUNET_OperationResultMessage);
-
struct GNUNET_MQ_MessageHandler handlers[] = {
- make_master_start_ack_handler (mst),
- make_master_join_request_handler (mst),
- make_channel_message_handler (chn),
- make_channel_message_ack_handler (chn),
- make_channel_history_result_handler (chn),
- make_channel_state_result_handler (chn),
- make_channel_result_handler (chn),
+ GNUNET_MQ_hd_fixed_size (master_start_ack,
+ GNUNET_MESSAGE_TYPE_PSYC_MASTER_START_ACK,
+ struct GNUNET_PSYC_CountersResultMessage,
+ mst),
+ GNUNET_MQ_hd_var_size (master_join_request,
+ GNUNET_MESSAGE_TYPE_PSYC_JOIN_REQUEST,
+ struct GNUNET_PSYC_JoinRequestMessage,
+ mst),
+ GNUNET_MQ_hd_var_size (channel_message,
+ GNUNET_MESSAGE_TYPE_PSYC_MESSAGE,
+ struct GNUNET_PSYC_MessageHeader,
+ chn),
+ GNUNET_MQ_hd_fixed_size (channel_message_ack,
+ GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_ACK,
+ struct GNUNET_MessageHeader,
+ chn),
+ GNUNET_MQ_hd_var_size (channel_history_result,
+ GNUNET_MESSAGE_TYPE_PSYC_HISTORY_RESULT,
+ struct GNUNET_OperationResultMessage,
+ chn),
+ GNUNET_MQ_hd_var_size (channel_state_result,
+ GNUNET_MESSAGE_TYPE_PSYC_STATE_RESULT,
+ struct GNUNET_OperationResultMessage,
+ chn),
+ GNUNET_MQ_hd_var_size (channel_result,
+ GNUNET_MESSAGE_TYPE_PSYC_RESULT_CODE,
+ struct GNUNET_OperationResultMessage,
+ chn),
GNUNET_MQ_handler_end ()
};
- chn->mq = GNUNET_CLIENT_connecT (chn->cfg, "psyc",
+ chn->mq = GNUNET_CLIENT_connect (chn->cfg, "psyc",
handlers, master_disconnected, mst);
GNUNET_assert (NULL != chn->mq);
chn->tmit = GNUNET_PSYC_transmit_create (chn->mq);
GNUNET_PSYC_MessagePartCallback message_part_cb,
void *cls)
{
- struct GNUNET_PSYC_Master *mst = GNUNET_malloc (sizeof (*mst));
+ struct GNUNET_PSYC_Master *mst = GNUNET_new (struct GNUNET_PSYC_Master);
struct GNUNET_PSYC_Channel *chn = &mst->chn;
+ struct MasterStartRequest *req;
- struct MasterStartRequest *req = GNUNET_malloc (sizeof (*req));
chn->connect_env = GNUNET_MQ_msg (req,
GNUNET_MESSAGE_TYPE_PSYC_MASTER_START);
req->channel_key = *channel_key;
/* FIXME: send msg to service */
channel_disconnect (chn, stop_cb, stop_cls);
- master_cleanup (mst);
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Slave client disconnected (%d), re-connecting\n",
(int) error);
- if (NULL != chn->mq)
- {
- GNUNET_MQ_destroy (chn->mq);
- chn->mq = NULL;
- }
if (NULL != chn->tmit)
{
GNUNET_PSYC_transmit_destroy (chn->tmit);
chn->tmit = NULL;
}
+ if (NULL != chn->mq)
+ {
+ GNUNET_MQ_destroy (chn->mq);
+ chn->mq = NULL;
+ }
chn->reconnect_task = GNUNET_SCHEDULER_add_delayed (chn->reconnect_delay,
slave_reconnect,
slv);
{
struct GNUNET_PSYC_Channel *chn = &slv->chn;
- GNUNET_MQ_hd_fixed_size (slave_join_ack,
- GNUNET_MESSAGE_TYPE_PSYC_SLAVE_JOIN_ACK,
- struct GNUNET_PSYC_CountersResultMessage);
-
- GNUNET_MQ_hd_var_size (slave_join_decision,
- GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION,
- struct GNUNET_PSYC_JoinDecisionMessage);
-
- GNUNET_MQ_hd_var_size (channel_message,
- GNUNET_MESSAGE_TYPE_PSYC_MESSAGE,
- struct GNUNET_PSYC_MessageHeader);
-
- GNUNET_MQ_hd_fixed_size (channel_message_ack,
- GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_ACK,
- struct GNUNET_MessageHeader);
-
- GNUNET_MQ_hd_var_size (channel_history_result,
- GNUNET_MESSAGE_TYPE_PSYC_HISTORY_RESULT,
- struct GNUNET_OperationResultMessage);
-
- GNUNET_MQ_hd_var_size (channel_state_result,
- GNUNET_MESSAGE_TYPE_PSYC_STATE_RESULT,
- struct GNUNET_OperationResultMessage);
-
- GNUNET_MQ_hd_var_size (channel_result,
- GNUNET_MESSAGE_TYPE_PSYC_RESULT_CODE,
- struct GNUNET_OperationResultMessage);
-
struct GNUNET_MQ_MessageHandler handlers[] = {
- make_slave_join_ack_handler (slv),
- make_slave_join_decision_handler (slv),
- make_channel_message_handler (chn),
- make_channel_message_ack_handler (chn),
- make_channel_history_result_handler (chn),
- make_channel_state_result_handler (chn),
- make_channel_result_handler (chn),
+ GNUNET_MQ_hd_fixed_size (slave_join_ack,
+ GNUNET_MESSAGE_TYPE_PSYC_SLAVE_JOIN_ACK,
+ struct GNUNET_PSYC_CountersResultMessage,
+ slv),
+ GNUNET_MQ_hd_var_size (slave_join_decision,
+ GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION,
+ struct GNUNET_PSYC_JoinDecisionMessage,
+ slv),
+ GNUNET_MQ_hd_var_size (channel_message,
+ GNUNET_MESSAGE_TYPE_PSYC_MESSAGE,
+ struct GNUNET_PSYC_MessageHeader,
+ chn),
+ GNUNET_MQ_hd_fixed_size (channel_message_ack,
+ GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_ACK,
+ struct GNUNET_MessageHeader,
+ chn),
+ GNUNET_MQ_hd_var_size (channel_history_result,
+ GNUNET_MESSAGE_TYPE_PSYC_HISTORY_RESULT,
+ struct GNUNET_OperationResultMessage,
+ chn),
+ GNUNET_MQ_hd_var_size (channel_state_result,
+ GNUNET_MESSAGE_TYPE_PSYC_STATE_RESULT,
+ struct GNUNET_OperationResultMessage,
+ chn),
+ GNUNET_MQ_hd_var_size (channel_result,
+ GNUNET_MESSAGE_TYPE_PSYC_RESULT_CODE,
+ struct GNUNET_OperationResultMessage,
+ chn),
GNUNET_MQ_handler_end ()
};
- chn->mq = GNUNET_CLIENT_connecT (chn->cfg, "psyc",
+ chn->mq = GNUNET_CLIENT_connect (chn->cfg, "psyc",
handlers, slave_disconnected, slv);
GNUNET_assert (NULL != chn->mq);
chn->tmit = GNUNET_PSYC_transmit_create (chn->mq);
/* FIXME: send msg to service */
channel_disconnect (chn, part_cb, part_cls);
- slave_cleanup (slv);
}