GNUnet  0.11.x
testbed_api_cmd_tng_service.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2021 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 "gnunet_util_lib.h"
28 #include "gnunet_testing_ng_lib.h"
29 #include "gnunet-service-testbed.h"
30 #include "testbed_api_hosts.h"
32 
36 #define LOG(kind, ...) \
37  GNUNET_log (kind, __VA_ARGS__)
38 
39 
46 static void
47 do_abort (void *cls)
48 {
49  struct TngState *ts = cls;
50 
51  if (GNUNET_NO == ts->service_ready)
52  {
53  LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
54  ts->abort_task = NULL;
56  }
57 }
58 
65 static void
67  const struct GNUNET_TESTING_Command *cmd)
68 {
69  (void) cls;
70 }
71 
81 static int
82 tng_service_traits (void *cls,
83  const void **ret,
84  const char *trait,
85  unsigned int index)
86 {
87  (void) cls;
88  return GNUNET_OK;
89 }
90 
91 
92 static void *
93 notify_connect (void *cls,
94  const struct GNUNET_PeerIdentity *peer,
95  struct GNUNET_MQ_Handle *mq)
96 {
97  struct TngState *ts = cls;
98 
99  if (NULL != emsg)
100  {
102  "There was an error starting the transport subsystem: %s\n",
103  emsg);
104  }
105  GNUNET_TESTING_interpreter_next (ps->is);
106  return ts->nc (ts->cb_cls);
107 
108 }
109 
110 
111 static void
112 notify_disconnect (void *cls,
113  const struct GNUNET_PeerIdentity *peer,
114  void *handler_cls)
115 {
116 }
117 
118 
119 
120 
131 static void *
132 connect_adapter (void *cls,
133  const struct GNUNET_CONFIGURATION_Handle *cfg)
134 {
135  struct TngState *ts = cls;
136 
137  service_handle = GNUNET_TRANSPORT_core_connect (cfg,
138  ts->peer_identity,
139  ts->handlers,
140  ts,
143  return service_handle;
144 }
145 
146 
154 static void
156  void *op_result)
157 {
158 }
159 
169 static void
172  void *ca_result,
173  const char *emsg)
174 {
175  struct TngState *ts = cls;
176 
177  if (NULL != emsg)
178  {
180  "An error occurred connecting to service %s\n",
181  emsg);
183  }
184 }
185 
186 
196 static void
197 pi_cb (void *cls,
199  const struct GNUNET_TESTBED_PeerInformation *pinfo,
200  const char *emsg)
201 {
202  struct TngState *ts = cls;
203 
204  ts->peer_identity = pinfo->id;
205  ts->operation =
210  ts);
211 }
212 
213 
214 static void
215 tng_service_run (void *cls,
216  const struct GNUNET_TESTING_Command *cmd,
218 {
219  struct TngState *ts = cls;
220  struct GNUNET_TESTBED_Peer *peer;
221  const struct GNUNET_TESTING_Command *peer_cmd;
222 
223  ts->is = is;
225  ts->peer_label);
227  &peer);
228 
231  &pi_cb,
232  ts);
233 }
234 
240 void
242 {
244  "Shutting down...\n");
245 }
246 
247 
250  const char *peer_label,
251  const struct GNUNET_MQ_MessageHandler *handlers,
253  void *cb_cls)
254 
255 {
256  struct TngState *ts;
257 
258  ts = GNUNET_new (struct TngState);
259  ts->servicename = servicename;
260  ts->peer_label = peer_label;
261  ts->handlers = handlers;
262  ts->nc = nc;
263  ts->nd = nd;
264  ts->cb_cls;
265 
266 
267  struct GNUNET_TESTING_Command cmd = {
268  .cls = ts,
269  .label = label,
270  .run = &tng_service_run,
271  .cleanup = &tmg_service_cleanup,
272  .traits = &tng_service_traits
273  };
274 
275  return cmd;
276 }
static void pi_cb(void *cls, struct GNUNET_TESTBED_Operation *op, const struct GNUNET_TESTBED_PeerInformation *pinfo, const char *emsg)
Callback to be called when the requested peer information is available.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
int service_ready
Flag indicating if service is ready.
static void disconnect_adapter(void *cls, void *op_result)
Adapter function called to destroy a connection to a service.
data structures shared amongst components of TESTBED service
static int tng_service_traits(void *cls, const void **ret, const char *trait, unsigned int index)
static int op_result(struct GNUNET_OP_Handle *h, uint64_t op_id, int64_t result_code, const void *data, uint16_t data_size, void **ctx, uint8_t cancel)
Remove an operation, and call its result callback (unless it was cancelled).
Definition: op.c:245
const char * label
Label for the command.
struct GNUNET_TESTBED_Operation * operation
Handle to operation.
A command to be run by the interpreter.
void GNUNET_TESTBED_shutdown_service(struct TngState *cs)
Shutdown nicely.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static void service_connect_comp_cb(void *cls, struct GNUNET_TESTBED_Operation *op, void *ca_result, const char *emsg)
Callback to be called when a service connect operation is completed.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_TRANSPORT_CoreHandle * GNUNET_TRANSPORT_core_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_PeerIdentity *self, const struct GNUNET_MQ_MessageHandler *handlers, void *cls, GNUNET_TRANSPORT_NotifyConnect nc, GNUNET_TRANSPORT_NotifyDisconnect nd)
Connect to the transport service.
void *(* GNUNET_TRANSPORT_NotifyConnect)(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Function called to notify transport users that another peer connected to us.
struct GNUNET_SCHEDULER_Task * abort_task
Abort task identifier.
const char * servicename
Name of service to start.
static void tng_service_run(void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is)
Opaque handle to an abstract operation to be executed by the testing framework.
struct GNUNET_PeerIdentity * id
The identity of the peer.
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.
struct GNUNET_PeerIdentity * peer_identity
Peer identity of the system.
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
Global state of the interpreter, used by a command to access information about other commands...
Definition: testing.h:34
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(const char *label)
Lookup command by label.
struct GNUNET_TESTING_Interpreter * is
void GNUNET_TESTBED_operation_done(struct GNUNET_TESTBED_Operation *operation)
This function is used to signal that the event information (struct GNUNET_TESTBED_EventInformation) f...
Definition: testbed_api.c:2045
Message handler for a specific message type.
struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_peer_get_information(struct GNUNET_TESTBED_Peer *peer, enum GNUNET_TESTBED_PeerInformationType pit, GNUNET_TESTBED_PeerInfoCallback cb, void *cb_cls)
Request information about a peer.
static void tng_service_cleanup(void *cls, const struct GNUNET_TESTING_Command *cmd)
struct GNUNET_TESTING_Command GNUNET_TESTBED_cmd_tng_service(const char *label, const char *peer_label, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_TRANSPORT_NotifyConnect nc, void *cb_cls)
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
static struct GNUNET_PEERINFO_NotifyContext * nc
Iterator context.
int GNUNET_TESTBED_get_trait_peer(const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTBED_Peer **peer)
Offer data from trait.
Handle to a message queue.
Definition: mq.c:85
void * cb_cls
Closure for the nc callback.
GNUNET_TRANSPORT_NotifyConnect nc
Notify connect callback.
static void notify_disconnect(void *cls, const struct GNUNET_PeerIdentity *peer, void *handler_cls)
The identity of the host (wraps the signing key of the peer).
What is the identity of the peer? Returns a &#39;const struct GNUNET_PeerIdentity *&#39;. ...
configuration data
Definition: configuration.c:84
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
#define LOG(kind,...)
Generic logging shortcut.
static void do_abort(void *cls)
abort task to run on test timed out
void * cls
Closure for all commands with command-specific context information.
internal API to access the &#39;hosts&#39; subsystem
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:144
A peer controlled by the testing framework.
const char * peer_label
Label of peer command.
const struct GNUNET_MQ_MessageHandler * handlers
Message handler for transport service.
static void * notify_connect(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
static void * connect_adapter(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
Adapter function called to establish a connection to a service.
Data returned from GNUNET_TESTBED_peer_get_information.