- new_route = GNUNET_malloc (sizeof (struct Route));
- new_route->dest = delegated_host_id;
- new_route->thru = route->dest;
- route_list_add (new_route);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
-}
-
-
-/**
- * The task to be executed if the forwarded peer create operation has been
- * timed out
- *
- * @param cls the FowardedOperationContext
- * @param tc the TaskContext from the scheduler
- */
-static void
-peer_create_forward_timeout (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- struct ForwardedOperationContext *fopc = cls;
-
- GNUNET_free (fopc->cls);
- TESTBED_forwarded_operation_timeout (fopc, tc);
-}
-
-
-/**
- * Callback to be called when forwarded peer create operation is successfull. We
- * have to relay the reply msg back to the client
- *
- * @param cls ForwardedOperationContext
- * @param msg the peer create success message
- */
-static void
-peer_create_success_cb (void *cls, const struct GNUNET_MessageHeader *msg)
-{
- struct ForwardedOperationContext *fopc = cls;
- struct Peer *remote_peer;
-
- if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TESTBED_PEERCREATESUCCESS)
- {
- GNUNET_assert (NULL != fopc->cls);
- remote_peer = fopc->cls;
- peer_list_add (remote_peer);
- }
- TESTBED_forwarded_operation_reply_relay (fopc, msg);
-}
-
-
-/**
- * Function to destroy a peer
- *
- * @param peer the peer structure to destroy
- */
-void
-TESTBED_destroy_peer (struct Peer *peer)
-{
- GNUNET_break (0 == peer->reference_cnt);
- if (GNUNET_YES == peer->is_remote)
- {
- peer_list_remove (peer);
- GNUNET_free (peer);
- return;
- }
- if (GNUNET_YES == peer->details.local.is_running)
- {
- GNUNET_TESTING_peer_stop (peer->details.local.peer);
- peer->details.local.is_running = GNUNET_NO;
- }
- GNUNET_TESTING_peer_destroy (peer->details.local.peer);
- GNUNET_CONFIGURATION_destroy (peer->details.local.cfg);
- peer_list_remove (peer);
- GNUNET_free (peer);
-}
-
-
-/**
- * Callback to be called when forwarded peer destroy operation is successfull. We
- * have to relay the reply msg back to the client
- *
- * @param cls ForwardedOperationContext
- * @param msg the peer create success message
- */
-static void
-peer_destroy_success_cb (void *cls, const struct GNUNET_MessageHeader *msg)
-{
- struct ForwardedOperationContext *fopc = cls;
- struct Peer *remote_peer;
-
- if (GNUNET_MESSAGE_TYPE_TESTBED_GENERICOPSUCCESS == ntohs (msg->type))
- {
- remote_peer = fopc->cls;
- GNUNET_assert (NULL != remote_peer);
- remote_peer->destroy_flag = GNUNET_YES;
- if (0 == remote_peer->reference_cnt)
- TESTBED_destroy_peer (remote_peer);
- }
- TESTBED_forwarded_operation_reply_relay (fopc, msg);
-}
-
-
-
-/**
- * Handler for GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER messages
- *
- * @param cls NULL
- * @param client identification of the client
- * @param message the actual message
- */
-static void
-handle_peer_create (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
-{
- const struct GNUNET_TESTBED_PeerCreateMessage *msg;
- struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *reply;
- struct GNUNET_CONFIGURATION_Handle *cfg;
- struct ForwardedOperationContext *fo_ctxt;
- struct Route *route;
- struct Peer *peer;
- char *config;
- size_t dest_size;
- int ret;
- uint32_t config_size;
- uint32_t host_id;
- uint32_t peer_id;
- uint16_t msize;
-
-
- msize = ntohs (message->size);
- if (msize <= sizeof (struct GNUNET_TESTBED_PeerCreateMessage))
- {
- GNUNET_break (0); /* We need configuration */
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
- }
- msg = (const struct GNUNET_TESTBED_PeerCreateMessage *) message;
- host_id = ntohl (msg->host_id);
- peer_id = ntohl (msg->peer_id);
- if (UINT32_MAX == peer_id)
- {
- TESTBED_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
- "Cannot create peer with given ID");
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
- }
- if (host_id == TESTBED_context->host_id)
- {
- char *emsg;
-
- /* We are responsible for this peer */
- msize -= sizeof (struct GNUNET_TESTBED_PeerCreateMessage);
- config_size = ntohl (msg->config_size);
- config = GNUNET_malloc (config_size);
- dest_size = config_size;
- if (Z_OK !=
- (ret =
- uncompress ((Bytef *) config, (uLongf *) & dest_size,
- (const Bytef *) &msg[1], (uLong) msize)))
- {
- GNUNET_break (0); /* uncompression error */
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- if (config_size != dest_size)
- {
- GNUNET_break (0); /* Uncompressed config size mismatch */
- GNUNET_free (config);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- cfg = GNUNET_CONFIGURATION_create ();
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_deserialize (cfg, config, config_size, GNUNET_NO))
- {
- GNUNET_break (0); /* Configuration parsing error */
- GNUNET_free (config);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- GNUNET_free (config);
- GNUNET_CONFIGURATION_set_value_number (cfg,
- "TESTBED",
- "PEERID",
- (unsigned long long) peer_id);
- peer = GNUNET_malloc (sizeof (struct Peer));
- peer->is_remote = GNUNET_NO;
- peer->details.local.cfg = cfg;
- peer->id = peer_id;
- LOG_DEBUG ("Creating peer with id: %u\n",
- (unsigned int) peer->id);
- peer->details.local.peer =
- GNUNET_TESTING_peer_configure (TESTBED_context->system,
- peer->details.local.cfg, peer->id,
- NULL /* Peer id */ ,
- &emsg);
- if (NULL == peer->details.local.peer)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "Configuring peer failed: %s\n", emsg);
- GNUNET_free (emsg);
- GNUNET_free (peer);
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- peer->details.local.is_running = GNUNET_NO;
- peer_list_add (peer);
- reply =
- GNUNET_malloc (sizeof
- (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage));
- reply->header.size =
- htons (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage));
- reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEERCREATESUCCESS);
- reply->peer_id = msg->peer_id;
- reply->operation_id = msg->operation_id;
- TESTBED_queue_message (client, &reply->header);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
- }
-
- /* Forward peer create request */
- route = TESTBED_find_dest_route (host_id);
- if (NULL == route)
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
- }
-
- peer = GNUNET_malloc (sizeof (struct Peer));
- peer->is_remote = GNUNET_YES;
- peer->id = peer_id;
- peer->details.remote.slave = TESTBED_slave_list[route->dest];
- peer->details.remote.remote_host_id = host_id;
- fo_ctxt = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
- GNUNET_SERVER_client_keep (client);
- fo_ctxt->client = client;
- fo_ctxt->operation_id = GNUNET_ntohll (msg->operation_id);
- fo_ctxt->cls = peer; //TESTBED_slave_list[route->dest]->controller;
- fo_ctxt->type = OP_PEER_CREATE;
- fo_ctxt->opc =
- GNUNET_TESTBED_forward_operation_msg_ (TESTBED_slave_list [route->dest]->controller,
- fo_ctxt->operation_id,
- &msg->header,
- peer_create_success_cb, fo_ctxt);
- fo_ctxt->timeout_task =
- GNUNET_SCHEDULER_add_delayed (TIMEOUT, &peer_create_forward_timeout,
- fo_ctxt);
- GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fo_ctxt);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
-}
-
-
-/**
- * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
- *
- * @param cls NULL
- * @param client identification of the client
- * @param message the actual message
- */
-static void
-handle_peer_destroy (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
-{
- const struct GNUNET_TESTBED_PeerDestroyMessage *msg;
- struct ForwardedOperationContext *fopc;
- struct Peer *peer;
- uint32_t peer_id;
-
- msg = (const struct GNUNET_TESTBED_PeerDestroyMessage *) message;
- peer_id = ntohl (msg->peer_id);
- LOG_DEBUG ("Received peer destory on peer: %u and operation id: %ul\n",
- peer_id, GNUNET_ntohll (msg->operation_id));
- if ((TESTBED_peer_list_size <= peer_id) || (NULL == TESTBED_peer_list[peer_id]))
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Asked to destroy a non existent peer with id: %u\n", peer_id);
- TESTBED_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
- "Peer doesn't exist");
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
- }
- peer = TESTBED_peer_list[peer_id];
- if (GNUNET_YES == peer->is_remote)