GNUnet 0.22.2
testing_arm_cmd_stop_peer.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_lib.h"
29#include "gnunet_testbed_lib.h"
31#include "gnunet_arm_service.h"
32
33
38{
42 const char *start_label;
43
47 const char *label;
48
50
52
54};
55
56
67static void
69 void *cls,
72{
73 struct StopPeerState *stop_ps = cls;
74
75 stop_ps->op = NULL;
77 {
78 GNUNET_TESTING_async_fail (&stop_ps->ac);
79 return;
80 }
82}
83
84
89static void
90stop_peer_run (void *cls,
92{
93 struct StopPeerState *stop_ps = cls;
94 const struct GNUNET_TESTING_Command *start_cmd;
95 struct GNUNET_ARM_Handle *ah;
96
97 stop_ps->is = is;
98 start_cmd
100 stop_ps->start_label);
101 if (NULL == start_cmd)
103 if (GNUNET_OK !=
104 GNUNET_TESTING_ARM_get_trait_arm_handle (start_cmd,
105 &ah))
108 "arm",
109 &stop_cb,
110 stop_ps);
111 if (NULL == stop_ps->op)
113}
114
115
120static void
122{
123 struct StopPeerState *sps = cls;
124
125 if (NULL != sps->op)
126 {
128 sps->label);
130 sps->op = NULL;
131 }
132 GNUNET_free (sps);
133}
134
135
140static int
142 const void **ret,
143 const char *trait,
144 unsigned int index)
145{
146 struct GNUNET_TESTING_Trait traits[] = {
148 };
149
150 (void) cls;
152 ret,
153 trait,
154 index);
155}
156
157
160 const char *start_label)
161{
162 struct StopPeerState *sps;
163
164 sps = GNUNET_new (struct StopPeerState);
166 sps->label = label;
168 sps,
169 label,
173 &sps->ac);
174}
static int ret
Final status code.
Definition: gnunet-arm.c:93
static struct GNUNET_TESTING_Interpreter * is
static struct GNUNET_NAT_AUTO_AutoHandle * ah
Handle to ongoing autoconfiguration.
static int result
Global testing status.
struct GNUNET_TESTING_Command GNUNET_TESTING_command_new_ac(void *cls, const char *label, GNUNET_TESTING_CommandRunRoutine run, GNUNET_TESTING_CommandCleanupRoutine cleanup, GNUNET_TESTING_CommandGetTraits traits, struct GNUNET_TESTING_AsyncContext *ac)
Create a new command that may be asynchronous.
void GNUNET_TESTING_async_finish(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has finished.
#define GNUNET_TESTING_FAIL(is)
Print failing line number and trigger shutdown.
void GNUNET_TESTING_async_fail(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has failed.
#define GNUNET_TESTING_command_incomplete(is, label)
Log an error message about a command not having run to completion.
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(struct GNUNET_TESTING_Interpreter *is, const char *label)
Lookup command by label.
struct GNUNET_TESTING_Trait GNUNET_TESTING_trait_end(void)
"end" of traits array.
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait(const struct GNUNET_TESTING_Trait *traits, const void **ret, const char *trait, unsigned int index)
Obtain value of a trait from a command.
struct GNUNET_ARM_Operation * GNUNET_ARM_request_service_stop(struct GNUNET_ARM_Handle *h, const char *service_name, GNUNET_ARM_ResultCallback cont, void *cont_cls)
Request a service to be stopped.
Definition: arm_api.c:1050
GNUNET_ARM_Result
Replies to ARM requests.
GNUNET_ARM_RequestStatus
Statuses of the requests that client can send to ARM.
void GNUNET_ARM_operation_cancel(struct GNUNET_ARM_Operation *op)
Abort an operation.
Definition: arm_api.c:795
@ GNUNET_ARM_RESULT_STOPPED
Service was stopped (never sent for ARM itself).
@ GNUNET_OK
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
Handle for interacting with ARM.
Definition: arm_api.c:103
Entry in a doubly-linked list of operations awaiting for replies (in-order) from the ARM service.
Definition: arm_api.c:41
State each asynchronous command must have in its closure.
A command to be run by the interpreter.
struct GNUNET_TESTING_CommandLabel label
Label for the command.
Global state of the interpreter, used by a command to access information about other commands.
A struct GNUNET_TESTING_Trait can be used to exchange data between cmds.
unsigned int index
Index number associated with the trait.
Struct to hold information for callbacks.
const char * start_label
Label of the cmd to start the peer.
const char * label
Label of the cmd.
struct GNUNET_TESTING_Interpreter * is
struct GNUNET_ARM_Operation * op
struct GNUNET_TESTING_AsyncContext ac
static enum GNUNET_GenericReturnValue traits(void *cls, const void **ret, const char *trait, unsigned int index)
This function prepares an array with traits.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_stop_peer(const char *label, const char *start_label)
Create command.
static void stop_cb(void *cls, enum GNUNET_ARM_RequestStatus rs, enum GNUNET_ARM_Result result)
Function called in response to a start/stop request.
static int stop_peer_traits(void *cls, const void **ret, const char *trait, unsigned int index)
Trait function of this cmd does nothing.
static void stop_peer_cleanup(void *cls)
The cleanup function of this cmd frees resources the cmd allocated.
static void stop_peer_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
The run method of this cmd will stop all services of a peer which were used to test the transport ser...