GNUnet  0.11.x
testbed_api_cmd_controller.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 
33 
37 #define LOG(kind, ...) \
38  GNUNET_log (kind, __VA_ARGS__)
39 
40 
47 static void
49  const struct GNUNET_TESTING_Command *cmd)
50 {
51  (void) cls;
52 }
53 
54 
62 static void
64  const struct GNUNET_TESTBED_EventInformation *event)
65 {
66  struct ControllerState *cs = cls;
67 
68  if (NULL != event->details.operation_finished.emsg)
69  {
70  LOG (GNUNET_ERROR_TYPE_ERROR, "There was an operation error: %s\n",
71  event->details.operation_finished.emsg);
73  }
74  else if (NULL == event->details.operation_finished.generic)
75  {
77  }
78 }
79 
80 
81 static void
82 controller_run (void *cls,
83  const struct GNUNET_TESTING_Command *cmd,
85 {
86  struct ControllerState *cs = cls;
87 
88  cs->is = is;
89 
90  cs->controller =
92  cs);
93 
94 
95 }
96 
106 static int
107 controller_traits (void *cls,
108  const void **ret,
109  const char *trait,
110  unsigned int index)
111 {
112  (void) cls;
113 
114  struct ControllerState *cs = cls;
115 
116 
117  struct GNUNET_TESTING_Trait traits[] = {
118  {
119  .index = 0,
120  .trait_name = "controller",
121  .ptr = (const void *) cs->controller,
122  },
124  };
125 
126  return GNUNET_TESTING_get_trait (traits,
127  ret,
128  trait,
129  index);
130  return GNUNET_OK;
131 }
132 
133 
141 int
143  struct GNUNET_TESTBED_Controller **
144  controller)
145 {
146  return cmd->traits (cmd->cls,
147  (const void **) controller,
148  "controller",
149  (unsigned int) 0);
150 }
151 
152 
158 void
160 {
162  "Shutting down...\n");
163 
165 
166  if (NULL != cs->abort_task)
168  if (NULL != cs->reg_handle)
170  if (NULL != cs->controller)
172  if (NULL != cs->cfg)
174  if (NULL != cs->cp)
176  if (NULL != cs->host)
178 }
179 
180 
181 
184  const char *host,
185  uint64_t event_mask)
186 {
187  struct ControllerState *cs;
188 
189  cs = GNUNET_new (struct ControllerState);
190  cs->event_mask = event_mask;
191  cs->hostname = host;
192 
193 
194  struct GNUNET_TESTING_Command cmd = {
195  .cls = cs,
196  .label = label,
197  .run = &controller_run,
198  .cleanup = &controller_cleanup,
199  .traits = &controller_traits
200  };
201 
202  return cmd;
203 }
void GNUNET_TESTBED_cancel_registration(struct GNUNET_TESTBED_HostRegistrationHandle *handle)
Cancel the pending registration.
void GNUNET_TESTBED_controller_disconnect(struct GNUNET_TESTBED_Controller *c)
Stop the given controller (also will terminate all peers and controllers dependent on this controller...
Definition: testbed_api.c:1721
Handle to interact with a GNUnet testbed controller.
Definition: testbed_api.h:197
struct GNUNET_TESTING_Command GNUNET_TESTBED_cmd_controller(const char *label, const char *host, uint64_t event_mask)
static int controller_traits(void *cls, const void **ret, const char *trait, unsigned int index)
data structures shared amongst components of TESTBED service
int GNUNET_TESTBED_get_trait_controller(const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTBED_Controller **controller)
Offer data from trait.
union GNUNET_TESTBED_EventInformation::@43 details
Details about the event.
const char * label
Label for the command.
void GNUNET_TESTBED_controller_stop(struct GNUNET_TESTBED_ControllerProc *cproc)
Stop the controller process (also will terminate all peers and controllers dependent on this controll...
A command to be run by the interpreter.
Argument to GNUNET_TESTBED_ControllerCallback with details about the event.
static void controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
Signature of the event handler function called by the respective event controller.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_TESTING_Interpreter * is
Interpreter state.
struct GNUNET_TESTBED_HostRegistrationHandle * reg_handle
Handle for host registration.
struct GNUNET_CONFIGURATION_Handle * cfg
The configuration to use as a template while starting a controller on this host.
int controller_going_down
Flag indicating controller is going down.
Global state of the interpreter, used by a command to access information about other commands...
Definition: testing.h:34
unsigned int index
Index number associated with the trait.
struct GNUNET_TESTING_Interpreter * is
struct GNUNET_TESTBED_Host * host
The host to run peers and controllers on.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
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
int(* traits)(void *cls, const void **ret, const char *trait, unsigned int index)
Extract information from a command that is useful for other commands.
static void controller_run(void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is)
uint64_t event_mask
Global event mask for all testbed events.
struct GNUNET_TESTBED_ControllerProc * cp
The controller process.
void GNUNET_TESTBED_host_destroy(struct GNUNET_TESTBED_Host *host)
Destroy a host handle.
struct GNUNET_SCHEDULER_Task * abort_task
Abort task identifier.
int GNUNET_TESTING_get_trait(const struct GNUNET_TESTING_Trait *traits, const void **ret, const char *trait, unsigned int index)
Extract a trait.
struct GNUNET_TESTBED_Controller * GNUNET_TESTBED_controller_connect(struct GNUNET_TESTBED_Host *host, uint64_t event_mask, GNUNET_TESTBED_ControllerCallback cc, void *cc_cls)
Connect to a controller process.
Definition: testbed_api.c:1555
struct GNUNET_TESTBED_EventInformation::@43::@48 operation_finished
Details about an operation finished event.
uint64_t event_mask
A bit mask with set of events to call the controller for.
#define LOG(kind,...)
Generic logging shortcut.
void * cls
Closure for all commands with command-specific context information.
static void controller_cleanup(void *cls, const struct GNUNET_TESTING_Command *cmd)
internal API to access the &#39;hosts&#39; subsystem
void GNUNET_TESTBED_shutdown_controller(struct ControllerState *cs)
Shutdown nicely.
const char * hostname
Name of the host, use "NULL" for localhost.
struct GNUNET_TESTING_Trait GNUNET_TESTING_trait_end(void)
"end" trait.
struct GNUNET_TESTBED_Controller * controller
The controller handle.
struct GNUNET_TESTBED_Operation * op
Handle for the corresponding operation that generated this event.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972