GNUnet  0.19.4
testbed_api_services.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2008--2013 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
26 #include "platform.h"
27 #include "testbed_api.h"
28 #include "testbed_api_peers.h"
29 #include "testbed_api_operations.h"
30 
31 
35 enum State
36 {
41 
46 
51 };
52 
53 
58 {
63 
68 
72  void *cada_cls;
73 
77  char *service_name;
78 
82  void *op_cls;
83 
88 
93 
98 
103 
107  void *op_result;
108 
113 
117  void *cb_cls;
118 
122  enum State state;
123 };
124 
125 
133 static void
135 {
136  struct ServiceConnectData *data = cls;
137  struct GNUNET_TESTBED_Controller *c;
138  const char *emsg;
140  uint16_t mtype;
141 
142  c = data->peer->controller;
143  mtype = ntohs (msg->type);
144  emsg = NULL;
146  info.op = data->operation;
147  info.op_cls = data->op_cls;
149  {
150  emsg =
153  *) msg);
154  if (NULL == emsg)
155  emsg = "Unknown error";
156  info.details.operation_finished.emsg = emsg;
157  info.details.operation_finished.generic = NULL;
158  goto call_cb;
159  }
161  GNUNET_assert (NULL == data->op_result);
162  data->op_result = data->ca (data->cada_cls, data->cfg);
163  info.details.operation_finished.emsg = NULL;
164  info.details.operation_finished.generic = data->op_result;
165  data->state = SERVICE_CONNECTED;
166 
167 call_cb:
169  (NULL != c->cc))
170  c->cc (c->cc_cls, &info);
171  if (NULL != data->cb)
172  data->cb (data->cb_cls, data->operation, data->op_result, emsg);
173 }
174 
175 
181 static void
183 {
184  struct ServiceConnectData *data = cls;
186  struct GNUNET_TESTBED_Controller *c;
187  uint64_t op_id;
188 
189  GNUNET_assert (NULL != data);
190  GNUNET_assert (NULL != data->peer);
191  c = data->peer->controller;
192  op_id = GNUNET_TESTBED_get_next_op_id (c);
193  msg =
194  GNUNET_TESTBED_generate_peergetconfig_msg_ (data->peer->unique_id, op_id);
195  data->opc =
196  GNUNET_TESTBED_forward_operation_msg_ (c, op_id, &msg->header,
198  GNUNET_free (msg);
199  data->state = CFG_REQUEST_QUEUED;
200 }
201 
202 
209 static void
211 {
212  struct ServiceConnectData *data = cls;
213 
214  switch (data->state)
215  {
216  case INIT:
217  break;
218 
219  case CFG_REQUEST_QUEUED:
220  GNUNET_assert (NULL != data->opc);
222  break;
223 
224  case SERVICE_CONNECTED:
225  GNUNET_assert (NULL != data->cfg);
227  if (NULL != data->da)
228  data->da (data->cada_cls, data->op_result);
229  break;
230  }
231  GNUNET_free (data);
232 }
233 
234 
258  const char *service_name,
260  cb, void *cb_cls,
263  void *cada_cls)
264 {
265  struct ServiceConnectData *data;
266 
268  data->ca = ca;
269  data->da = da;
270  data->cada_cls = cada_cls;
271  data->op_cls = op_cls;
272  data->peer = peer;
273  data->state = INIT;
274  data->cb = cb;
275  data->cb_cls = cb_cls;
276  data->operation =
280  controller->
281  opq_parallel_service_connections,
282  data->operation);
284  controller->opq_parallel_operations,
285  data->operation);
287  return data->operation;
288 }
289 
290 
291 /* end of testbed_api_services.c */
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
uint32_t data
The data value.
State
Available states during profiling.
#define info
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:50
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT
Message for operation events.
void(* GNUNET_TESTBED_DisconnectAdapter)(void *cls, void *op_result)
Adapter function called to destroy a connection to a service.
void(* GNUNET_TESTBED_ServiceConnectCompletionCallback)(void *cls, struct GNUNET_TESTBED_Operation *op, void *ca_result, const char *emsg)
Callback to be called when a service connect operation is completed.
struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_service_connect(void *op_cls, struct GNUNET_TESTBED_Peer *peer, const char *service_name, GNUNET_TESTBED_ServiceConnectCompletionCallback cb, void *cb_cls, GNUNET_TESTBED_ConnectAdapter ca, GNUNET_TESTBED_DisconnectAdapter da, void *cada_cls)
Connect to a service offered by the given peer.
void *(* GNUNET_TESTBED_ConnectAdapter)(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
Adapter function called to establish a connection to a service.
@ GNUNET_TESTBED_ET_OPERATION_FINISHED
A requested testbed operation has been completed.
Header for all communications.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
Handle to interact with a GNUnet testbed controller.
Definition: testbed_api.h:194
uint64_t event_mask
The controller event mask.
Definition: testbed_api.h:265
void * cc_cls
The closure for controller callback.
Definition: testbed_api.h:208
GNUNET_TESTBED_ControllerCallback cc
The controller callback.
Definition: testbed_api.h:203
Argument to GNUNET_TESTBED_ControllerCallback with details about the event.
const char * emsg
Error message for the operation, NULL on success.
Event notification from a controller to a client.
Definition: testbed.h:509
Opaque handle to an abstract operation to be executed by the testing framework.
void * cb_cls
Closure for callbacks.
Message sent from client to testing service to obtain the configuration of a peer.
Definition: testbed.h:582
A peer controlled by the testing framework.
Context information for GNUNET_TESTBED_Operation.
Definition: testbed_api.h:137
Data accessed during service connections.
GNUNET_TESTBED_ConnectAdapter ca
helper function callback to establish the connection
struct GNUNET_CONFIGURATION_Handle * cfg
The acquired configuration of the peer.
enum State state
State information.
char * service_name
Service name.
GNUNET_TESTBED_ServiceConnectCompletionCallback cb
The operation completion callback.
struct OperationContext * opc
The operation context from GNUNET_TESTBED_forward_operation_msg_()
void * op_result
The op_result pointer from ConnectAdapter.
GNUNET_TESTBED_DisconnectAdapter da
helper function callback to close the connection
struct GNUNET_TESTBED_Operation * operation
The operation which created this structure.
void * op_cls
Closure for operation event.
void * cb_cls
The closure for operation completion callback.
void * cada_cls
Closure to the above callbacks.
struct GNUNET_TESTBED_Peer * peer
The peer handle.
const char * GNUNET_TESTBED_parse_error_string_(const struct GNUNET_TESTBED_OperationFailureEventMessage *msg)
Checks the integrity of the OpeationFailureEventMessage and if good returns the error message it cont...
Definition: testbed_api.c:2150
void GNUNET_TESTBED_forward_operation_msg_cancel_(struct OperationContext *opc)
Function to cancel an operation created by simply forwarding an operation message.
Definition: testbed_api.c:1407
uint64_t GNUNET_TESTBED_get_next_op_id(struct GNUNET_TESTBED_Controller *controller)
Function to return the operation id for a controller.
Definition: testbed_api.c:2178
struct GNUNET_CONFIGURATION_Handle * GNUNET_TESTBED_extract_config_(const struct GNUNET_MessageHeader *msg)
Generates configuration by uncompressing configuration in given message.
Definition: testbed_api.c:2043
struct OperationContext * GNUNET_TESTBED_forward_operation_msg_(struct GNUNET_TESTBED_Controller *controller, uint64_t operation_id, const struct GNUNET_MessageHeader *msg, GNUNET_MQ_MessageCallback cc, void *cc_cls)
Sends the given message as an operation.
Definition: testbed_api.c:1370
Interface for functions internally exported from testbed_api.c.
struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_operation_create_(void *cls, OperationStart start, OperationRelease release)
Create an 'operation' to be performed.
void GNUNET_TESTBED_operation_queue_insert_(struct OperationQueue *queue, struct GNUNET_TESTBED_Operation *op)
Add an operation to a queue.
void GNUNET_TESTBED_operation_begin_wait_(struct GNUNET_TESTBED_Operation *op)
Marks the given operation as waiting on the queues.
internal API to access the 'operations' subsystem
struct GNUNET_TESTBED_PeerGetConfigurationMessage * GNUNET_TESTBED_generate_peergetconfig_msg_(uint32_t peer_id, uint64_t operation_id)
Generate PeerGetConfigurationMessage.
internal API to access the 'peers' subsystem
@ INIT
Initial state.
@ CFG_REQUEST_QUEUED
The configuration request has been sent.
@ SERVICE_CONNECTED
connected to service
static void opstart_service_connect(void *cls)
Function called when a service connect operation is ready.
static void configuration_receiver(void *cls, const struct GNUNET_MessageHeader *msg)
Type of a function to call when we receive a message from the service.
static void oprelease_service_connect(void *cls)
Callback which will be called when service connect type operation is released.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.