This file is part of GNUnet
Copyright (C) 2008--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
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
+ GNUnet is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
GNUnet is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
+ Affero General Public License for more details.
*/
/**
/**
* The callback to call when reply is available
*/
- GNUNET_CLIENT_MessageHandler cc;
+ GNUNET_MQ_MessageCallback cc;
/**
* The closure for the above callback
{
case GNUNET_TESTBED_PIT_IDENTITY:
pinfo->result.id = GNUNET_new (struct GNUNET_PeerIdentity);
- (void) memcpy (pinfo->result.id,
+ GNUNET_memcpy (pinfo->result.id,
&msg->peer_identity,
sizeof (struct GNUNET_PeerIdentity));
break;
emsg = GNUNET_malloc (ntohs (msg->header.size)
- sizeof (struct
GNUNET_TESTBED_ControllerLinkResponse) + 1);
- memcpy (emsg, &msg[1], ntohs (msg->header.size)
- - sizeof (struct
- GNUNET_TESTBED_ControllerLinkResponse));
+ GNUNET_memcpy (emsg,
+ &msg[1],
+ ntohs (msg->header.size)- sizeof (struct GNUNET_TESTBED_ControllerLinkResponse));
event.details.operation_finished.emsg = emsg;
}
else
emsg = NULL;
barrier = NULL;
msize = ntohs (msg->header.size);
+ if (msize <= sizeof (struct GNUNET_TESTBED_BarrierStatusMsg))
+ {
+ GNUNET_break_op (0);
+ goto cleanup;
+ }
name = msg->data;
name_len = ntohs (msg->name_len);
+ if (name_len >= //name_len is strlen(barrier_name)
+ (msize - ((sizeof msg->header) + sizeof (msg->status)) ) )
+ {
+ GNUNET_break_op (0);
+ goto cleanup;
+ }
+ if ('\0' != name[name_len])
+ {
+ GNUNET_break_op (0);
+ goto cleanup;
+ }
LOG_DEBUG ("Received BARRIER_STATUS msg\n");
status = ntohs (msg->status);
if (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status)
{
status = -1;
- emsg_len = msize - (sizeof (struct GNUNET_TESTBED_BarrierStatusMsg) + name_len
- + 1);
- emsg = GNUNET_malloc (emsg_len + 1);
- memcpy (emsg,
- msg->data + name_len + 1,
- emsg_len);
+ //unlike name_len, emsg_len includes the trailing zero
+ emsg_len = msize - (sizeof (struct GNUNET_TESTBED_BarrierStatusMsg)
+ + (name_len + 1));
+ if (0 == emsg_len)
+ {
+ GNUNET_break_op (0);
+ goto cleanup;
+ }
+ if ('\0' != (msg->data[(name_len + 1) + (emsg_len - 1)]))
+ {
+ GNUNET_break_op (0);
+ goto cleanup;
+ }
+ emsg = GNUNET_malloc (emsg_len);
+ GNUNET_memcpy (emsg,
+ msg->data + name_len + 1,
+ emsg_len);
}
if (NULL == c->barrier_map)
{
GNUNET_assert (NULL != barrier->cb);
if ((GNUNET_YES == barrier->echo) &&
(GNUNET_TESTBED_BARRIERSTATUS_CROSSED == status))
- GNUNET_TESTBED_queue_message_ (c, GNUNET_copy_message (&msg->header));
- barrier->cb (barrier->cls, name, barrier, status, emsg);
+ GNUNET_TESTBED_queue_message_ (c,
+ GNUNET_copy_message (&msg->header));
+ barrier->cb (barrier->cls,
+ name,
+ barrier,
+ status,
+ emsg);
if (GNUNET_TESTBED_BARRIERSTATUS_INITIALISED == status)
return; /* just initialised; skip cleanup */
cleanup:
GNUNET_free_non_null (emsg);
- if (NULL != barrier)
+ /**
+ * Do not remove the barrier if we did not echo the status back; this is
+ * required at the chained testbed controller setup to ensure the only the
+ * test-driver echos the status and the controller hierarchy properly
+ * propagates the status.
+ */
+ if ((NULL != barrier) && (GNUNET_YES == barrier->echo))
GNUNET_TESTBED_barrier_remove_ (barrier);
}
env = GNUNET_MQ_msg_extra (m2,
size - sizeof (*m2),
type);
- memcpy (m2, msg, size);
+ GNUNET_memcpy (m2, msg, size);
GNUNET_free (msg);
GNUNET_MQ_send (controller->mq,
env);
GNUNET_TESTBED_forward_operation_msg_ (struct GNUNET_TESTBED_Controller *controller,
uint64_t operation_id,
const struct GNUNET_MessageHeader *msg,
- GNUNET_CLIENT_MessageHandler cc,
+ GNUNET_MQ_MessageCallback cc,
void *cc_cls)
{
struct OperationContext *opc;
env = GNUNET_MQ_msg_extra (m2,
size - sizeof (*m2),
type);
- memcpy (m2,
- msg,
- size);
+ GNUNET_memcpy (m2,
+ msg,
+ size);
GNUNET_MQ_send (controller->mq,
env);
data = GNUNET_new (struct ForwardedOperationData);
GNUNET_TESTBED_ControllerCallback cc,
void *cc_cls)
{
- GNUNET_MQ_hd_var_size (add_host_confirm,
- GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS,
- struct GNUNET_TESTBED_HostConfirmedMessage);
- GNUNET_MQ_hd_fixed_size (peer_conevent,
- GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT,
- struct GNUNET_TESTBED_ConnectionEventMessage);
- GNUNET_MQ_hd_fixed_size (opsuccess,
- GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS,
- struct GNUNET_TESTBED_GenericOperationSuccessEventMessage);
- GNUNET_MQ_hd_var_size (op_fail_event,
- GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT,
- struct GNUNET_TESTBED_OperationFailureEventMessage);
- GNUNET_MQ_hd_fixed_size (peer_create_success,
- GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS,
- struct GNUNET_TESTBED_PeerCreateSuccessEventMessage);
- GNUNET_MQ_hd_fixed_size (peer_event,
- GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT,
- struct GNUNET_TESTBED_PeerEventMessage);
- GNUNET_MQ_hd_var_size (peer_config,
- GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION,
- struct GNUNET_TESTBED_PeerConfigurationInformationMessage);
- GNUNET_MQ_hd_var_size (slave_config,
- GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION,
- struct GNUNET_TESTBED_SlaveConfiguration);
- GNUNET_MQ_hd_var_size (link_controllers_result,
- GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT,
- struct GNUNET_TESTBED_ControllerLinkResponse);
- GNUNET_MQ_hd_var_size (barrier_status,
- GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS,
- const struct GNUNET_TESTBED_BarrierStatusMsg);
- struct GNUNET_TESTBED_Controller *controller
- = GNUNET_new (struct GNUNET_TESTBED_Controller);
- struct GNUNET_MQ_MessageHandler handlers[] = {
- make_add_host_confirm_handler (controller),
- make_peer_conevent_handler (controller),
- make_opsuccess_handler (controller),
- make_op_fail_event_handler (controller),
- make_peer_create_success_handler (controller),
- make_peer_event_handler (controller),
- make_peer_config_handler (controller),
- make_slave_config_handler (controller),
- make_link_controllers_result_handler (controller),
- make_barrier_status_handler (controller),
- GNUNET_MQ_handler_end ()
+ struct GNUNET_TESTBED_Controller *controller
+ = GNUNET_new (struct GNUNET_TESTBED_Controller);
+ struct GNUNET_MQ_MessageHandler handlers[] = {
+ GNUNET_MQ_hd_var_size (add_host_confirm,
+ GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS,
+ struct GNUNET_TESTBED_HostConfirmedMessage,
+ controller),
+ GNUNET_MQ_hd_fixed_size (peer_conevent,
+ GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT,
+ struct GNUNET_TESTBED_ConnectionEventMessage,
+ controller),
+ GNUNET_MQ_hd_fixed_size (opsuccess,
+ GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS,
+ struct GNUNET_TESTBED_GenericOperationSuccessEventMessage,
+ controller),
+ GNUNET_MQ_hd_var_size (op_fail_event,
+ GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT,
+ struct GNUNET_TESTBED_OperationFailureEventMessage,
+ controller),
+ GNUNET_MQ_hd_fixed_size (peer_create_success,
+ GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS,
+ struct GNUNET_TESTBED_PeerCreateSuccessEventMessage,
+ controller),
+ GNUNET_MQ_hd_fixed_size (peer_event,
+ GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT,
+ struct GNUNET_TESTBED_PeerEventMessage,
+ controller),
+ GNUNET_MQ_hd_var_size (peer_config,
+ GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION,
+ struct GNUNET_TESTBED_PeerConfigurationInformationMessage,
+ controller),
+ GNUNET_MQ_hd_var_size (slave_config,
+ GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION,
+ struct GNUNET_TESTBED_SlaveConfiguration,
+ controller),
+ GNUNET_MQ_hd_var_size (link_controllers_result,
+ GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT,
+ struct GNUNET_TESTBED_ControllerLinkResponse,
+ controller),
+ GNUNET_MQ_hd_var_size (barrier_status,
+ GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS,
+ struct GNUNET_TESTBED_BarrierStatusMsg,
+ controller),
+ GNUNET_MQ_handler_end ()
};
struct GNUNET_TESTBED_InitMessage *msg;
struct GNUNET_MQ_Envelope *env;
controller->cc_cls = cc_cls;
controller->event_mask = event_mask;
controller->cfg = GNUNET_CONFIGURATION_dup (cfg);
- controller->mq = GNUNET_CLIENT_connecT (controller->cfg,
+ controller->mq = GNUNET_CLIENT_connect (controller->cfg,
"testbed",
handlers,
&mq_error_handler,
GNUNET_MESSAGE_TYPE_TESTBED_INIT);
msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host));
msg->event_mask = GNUNET_htonll (controller->event_mask);
- memcpy (&msg[1],
- controller_hostname,
- slen);
+ GNUNET_memcpy (&msg[1],
+ controller_hostname,
+ slen);
GNUNET_MQ_send (controller->mq,
env);
return controller;
}
cfg = GNUNET_CONFIGURATION_create ();
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_deserialize (cfg, (const char *) data,
+ GNUNET_CONFIGURATION_deserialize (cfg,
+ (const char *) data,
(size_t) data_len,
- GNUNET_NO))
+ NULL))
{
GNUNET_free (data);
GNUNET_break_op (0); /* De-serialization failure */
barrier->cb = cb;
barrier->cls = cls;
barrier->echo = echo;
- (void) memcpy (&barrier->key, &key, sizeof (struct GNUNET_HashCode));
+ GNUNET_memcpy (&barrier->key, &key, sizeof (struct GNUNET_HashCode));
GNUNET_assert (GNUNET_OK ==
GNUNET_CONTAINER_multihashmap_put (controller->barrier_map,
&barrier->key,
name_len,
GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT);
msg->quorum = (uint8_t) quorum;
- memcpy (msg->name,
- barrier->name,
- name_len);
+ GNUNET_memcpy (msg->name,
+ barrier->name,
+ name_len);
GNUNET_MQ_send (barrier->c->mq,
env);
return barrier;
env = GNUNET_MQ_msg_extra (msg,
slen,
GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL);
- memcpy (msg->name,
- barrier->name,
- slen);
+ GNUNET_memcpy (msg->name,
+ barrier->name,
+ slen);
GNUNET_MQ_send (barrier->c->mq,
env);
GNUNET_TESTBED_barrier_remove_ (barrier);