- data->p2 = p2;
- op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation));
- op->controller = p1->controller;
- op->operation_id = op->controller->operation_counter++;
- op->type = OP_OVERLAY_CONNECT;
- op->data = data;
- msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_OverlayConnectMessage));
- msg->header.size = htons (sizeof (struct
- GNUNET_TESTBED_OverlayConnectMessage));
- msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT);
- msg->peer1 = htonl (p1->unique_id);
- msg->peer2 = htonl (p2->unique_id);
- msg->operation_id = GNUNET_htonll (op->operation_id);
- GNUNET_CONTAINER_DLL_insert_tail (op->controller->op_head,
- op->controller->op_tail, op);
- GNUNET_TESTBED_queue_message_ (op->controller,
- (struct GNUNET_MessageHeader *) msg);
- return NULL;
+ data->p2 = p2;
+ data->cb = cb;
+ data->cb_cls = cb_cls;
+ opc = GNUNET_new (struct OperationContext);
+ opc->data = data;
+ opc->c = p1->controller;
+ opc->id = GNUNET_TESTBED_get_next_op_id (opc->c);
+ opc->type = OP_OVERLAY_CONNECT;
+ opc->op_cls = op_cls;
+ opc->op =
+ GNUNET_TESTBED_operation_create_ (opc, &opstart_overlay_connect,
+ &oprelease_overlay_connect);
+ GNUNET_TESTBED_host_queue_oc_ (p1->host, opc->op);
+ GNUNET_TESTBED_operation_begin_wait_ (opc->op);
+ return opc->op;
+}
+
+
+/**
+ * Function called when a peer manage service operation is ready
+ *
+ * @param cls the closure from GNUNET_TESTBED_operation_create_()
+ */
+static void
+opstart_manage_service (void *cls)
+{
+ struct OperationContext *opc = cls;
+ struct ManageServiceData *data = opc->data;
+ struct GNUNET_MQ_Envelope *env;
+ struct GNUNET_TESTBED_ManagePeerServiceMessage *msg;
+ size_t xlen;
+
+ GNUNET_assert (NULL != data);
+ xlen = data->msize - sizeof(struct GNUNET_TESTBED_ManagePeerServiceMessage);
+ env = GNUNET_MQ_msg_extra (msg,
+ xlen,
+ GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE);
+ msg->peer_id = htonl (data->peer->unique_id);
+ msg->operation_id = GNUNET_htonll (opc->id);
+ msg->start = (uint8_t) data->start;
+ GNUNET_memcpy (&msg[1],
+ data->service_name,
+ xlen);
+ GNUNET_free (data->service_name);
+ data->service_name = NULL;
+ opc->state = OPC_STATE_STARTED;
+ GNUNET_TESTBED_insert_opc_ (opc->c, opc);
+ GNUNET_MQ_send (opc->c->mq,
+ env);
+}
+
+
+/**
+ * Callback which will be called when peer manage server operation is released
+ *
+ * @param cls the closure from GNUNET_TESTBED_operation_create_()
+ */
+static void
+oprelease_manage_service (void *cls)
+{
+ struct OperationContext *opc = cls;
+ struct ManageServiceData *data;
+
+ data = opc->data;
+ switch (opc->state)
+ {
+ case OPC_STATE_STARTED:
+ GNUNET_TESTBED_remove_opc_ (opc->c, opc);
+ break;
+
+ case OPC_STATE_INIT:
+ GNUNET_assert (NULL != data);
+ GNUNET_free (data->service_name);
+ break;
+
+ case OPC_STATE_FINISHED:
+ break;
+ }
+ GNUNET_free_non_null (data);
+ GNUNET_free (opc);