GNUnet  0.10.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 {
40 
45 
50 };
51 
52 
61 
66 
70  void *cada_cls;
71 
75  char *service_name;
76 
80  void *op_cls;
81 
86 
91 
96 
101 
105  void *op_result;
106 
111 
115  void *cb_cls;
116 
120  enum State state;
121 };
122 
123 
131 static void
133 {
134  struct ServiceConnectData *data = cls;
135  struct GNUNET_TESTBED_Controller *c;
136  const char *emsg;
138  uint16_t mtype;
139 
140  c = data->peer->controller;
141  mtype = ntohs(msg->type);
142  emsg = NULL;
144  info.op = data->operation;
145  info.op_cls = data->op_cls;
147  {
148  emsg =
151  *)msg);
152  if (NULL == emsg)
153  emsg = "Unknown error";
154  info.details.operation_finished.emsg = emsg;
155  info.details.operation_finished.generic = NULL;
156  goto call_cb;
157  }
158  data->cfg = GNUNET_TESTBED_extract_config_(msg);
159  GNUNET_assert(NULL == data->op_result);
160  data->op_result = data->ca(data->cada_cls, data->cfg);
161  info.details.operation_finished.emsg = NULL;
162  info.details.operation_finished.generic = data->op_result;
163  data->state = SERVICE_CONNECTED;
164 
165 call_cb:
167  (NULL != c->cc))
168  c->cc(c->cc_cls, &info);
169  if (NULL != data->cb)
170  data->cb(data->cb_cls, data->operation, data->op_result, emsg);
171 }
172 
173 
179 static void
181 {
182  struct ServiceConnectData *data = cls;
184  struct GNUNET_TESTBED_Controller *c;
185  uint64_t op_id;
186 
187  GNUNET_assert(NULL != data);
188  GNUNET_assert(NULL != data->peer);
189  c = data->peer->controller;
191  msg =
193  data->opc =
195  &configuration_receiver, data);
196  GNUNET_free(msg);
197  data->state = CFG_REQUEST_QUEUED;
198 }
199 
200 
207 static void
209 {
210  struct ServiceConnectData *data = cls;
211 
212  switch (data->state)
213  {
214  case INIT:
215  break;
216 
217  case CFG_REQUEST_QUEUED:
218  GNUNET_assert(NULL != data->opc);
220  break;
221 
222  case SERVICE_CONNECTED:
223  GNUNET_assert(NULL != data->cfg);
225  if (NULL != data->da)
226  data->da(data->cada_cls, data->op_result);
227  break;
228  }
229  GNUNET_free(data);
230 }
231 
232 
256  const char *service_name,
258  cb, void *cb_cls,
261  void *cada_cls)
262 {
263  struct ServiceConnectData *data;
264 
265  data = GNUNET_new(struct ServiceConnectData);
266  data->ca = ca;
267  data->da = da;
268  data->cada_cls = cada_cls;
269  data->op_cls = op_cls;
270  data->peer = peer;
271  data->state = INIT;
272  data->cb = cb;
273  data->cb_cls = cb_cls;
274  data->operation =
278  controller->opq_parallel_service_connections,
279  data->operation);
281  controller->opq_parallel_operations,
282  data->operation);
284  return data->operation;
285 }
286 
287 /* 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:191
Message sent from client to testing service to obtain the configuration of a peer.
Definition: testbed.h:563
#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_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:2201
#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:493
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:2059
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:262
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:1399
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION.
Definition: testbed.h:567
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.
struct GNUNET_TESTBED_EventInformation::@58::@63 operation_finished
Details about an operation finished event.
static void oprelease_service_connect(void *cls)
Callback which will be called when service connect type operation is released.
struct OperationContext * opc
The operation context from GNUNET_TESTBED_forward_operation_msg_()
struct GNUNET_TESTBED_Peer * peer
The peer handle.
union GNUNET_TESTBED_EventInformation::@58 details
Details about the event.
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:1362
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:83
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:205
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:2173
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:135
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_TESTBED_ControllerCallback cc
The controller callback.
Definition: testbed_api.h:200
struct GNUNET_TESTBED_Operation * op
Handle for the corresponding operation that generated this event.
The configuration request has been sent.