GNUnet  0.11.x
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  }
160  data->cfg = GNUNET_TESTBED_extract_config_ (msg);
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 =
195  data->opc =
197  &configuration_receiver, data);
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 
267  data = GNUNET_new (struct ServiceConnectData);
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 */
void *(* GNUNET_TESTBED_ConnectAdapter)(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
Adapter function called to establish a connection to a service.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
internal API to access the &#39;operations&#39; subsystem
struct GNUNET_TESTBED_Operation * operation
The operation which created this structure.
Handle to interact with a GNUnet testbed controller.
Definition: testbed_api.h:193
Message sent from client to testing service to obtain the configuration of a peer.
Definition: testbed.h:581
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_operation_create_(void *cls, OperationStart start, OperationRelease release)
Create an &#39;operation&#39; to be performed.
struct GNUNET_TESTBED_EventInformation::@55::@60 operation_finished
Details about an operation finished event.
struct GNUNET_CONFIGURATION_Handle * cfg
The acquired configuration of the peer.
Argument to GNUNET_TESTBED_ControllerCallback with details about the event.
enum GNUNET_TESTBED_EventType type
Type of the event.
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:2208
#define GNUNET_new(type)
Allocate a struct or union of the given type.
GNUNET_TESTBED_ConnectAdapter ca
helper function callback to establish the connection
const char * emsg
Error message for the operation, NULL on success.
struct GNUNET_TESTBED_PeerGetConfigurationMessage * GNUNET_TESTBED_generate_peergetconfig_msg_(uint32_t peer_id, uint64_t operation_id)
Generate PeerGetConfigurationMessage.
void GNUNET_TESTBED_operation_queue_insert_(struct OperationQueue *queue, struct GNUNET_TESTBED_Operation *op)
Add an operation to a queue.
Event notification from a controller to a client.
Definition: testbed.h:508
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:2066
void * op_cls
Closure for operation event.
Opaque handle to an abstract operation to be executed by the testing framework.
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.
#define GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT
Message for operation events.
uint64_t event_mask
The controller event mask.
Definition: testbed_api.h:265
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
void * cb_cls
The closure for operation completion callback.
connected to service
enum State state
State information.
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:1406
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION.
Definition: testbed.h:586
A requested testbed operation has been completed.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
struct GNUNET_TESTBED_Controller * controller
Our controller context (not necessarily the controller that is responsible for starting/running the p...
GNUNET_TESTBED_DisconnectAdapter da
helper function callback to close the connection
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.
static void oprelease_service_connect(void *cls)
Callback which will be called when service connect type operation is released.
union GNUNET_TESTBED_EventInformation::@55 details
Details about the event.
struct OperationContext * opc
The operation context from GNUNET_TESTBED_forward_operation_msg_()
struct GNUNET_TESTBED_Peer * peer
The peer handle.
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:1369
State
Available states during profiling.
void * op_cls
Closure given while creating the above operation.
char * service_name
Service name.
GNUNET_TESTBED_ServiceConnectCompletionCallback cb
The operation completion callback.
internal API to access the &#39;peers&#39; subsystem
Interface for functions internally exported from testbed_api.c.
uint32_t unique_id
Globally unique ID of the peer.
void GNUNET_TESTBED_operation_begin_wait_(struct GNUNET_TESTBED_Operation *op)
Marks the given operation as waiting on the queues.
configuration data
Definition: configuration.c:85
static void opstart_service_connect(void *cls)
Function called when a service connect operation is ready.
void * cada_cls
Closure to the above callbacks.
void * cc_cls
The closure for controller callback.
Definition: testbed_api.h:208
Header for all communications.
void * op_result
The op_result pointer from ConnectAdapter.
Data accessed during service connections.
Initial state.
A peer controlled by the testing framework.
uint32_t data
The data value.
const char * GNUNET_TESTBED_parse_error_string_(const struct GNUNET_TESTBED_OperationFailureEventMessage *msg)
Checks the integrity of the OperationFailureEventMessage and if good returns the error message it con...
Definition: testbed_api.c:2180
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.
Context information for GNUNET_TESTBED_Operation.
Definition: testbed_api.h:136
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_TESTBED_ControllerCallback cc
The controller callback.
Definition: testbed_api.h:203
struct GNUNET_TESTBED_Operation * op
Handle for the corresponding operation that generated this event.
The configuration request has been sent.