GNUnet  0.11.x
transport_api_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_ng_lib.h"
32 #include "transport-testing-cmds.h"
33 
37 #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
38 
39 
45 {
46  // Label of the cmd to start the peer.
47  const char *start_label;
48 };
49 
50 
55 static void
56 stop_peer_run (void *cls,
57  const struct GNUNET_TESTING_Command *cmd,
59 {
60  struct StopPeerState *stop_ps = cls;
61  struct StartPeerState *sps;
62  const struct GNUNET_TESTING_Command *start_cmd;
63 
66  &sps);
67 
68  if (NULL != sps->pic)
69  {
71  sps->pic = NULL;
72  }
73  if (NULL != sps->th)
74  {
76  sps->th = NULL;
77  }
78  if (NULL != sps->ah)
79  {
81  sps->ah = NULL;
82  }
83  if (NULL != sps->ph)
84  {
86  "Disconnecting from PEERSTORE service\n");
88  sps->ph = NULL;
89  }
90  if (NULL != sps->peer)
91  {
92  if (GNUNET_OK !=
94  {
96  "Testing lib failed to stop peer %u (`%s')\n",
97  sps->no,
98  GNUNET_i2s (&sps->id));
99  }
101  sps->peer = NULL;
102  }
103  if (NULL != sps->rh_task)
105  sps->rh_task = NULL;
106 
107 }
108 
109 
114 static void
116  const struct GNUNET_TESTING_Command *cmd)
117 {
118  struct StopPeerState *sps = cls;
119 
120  GNUNET_free (sps);
121 }
122 
123 
128 static int
129 stop_peer_traits (void *cls,
130  const void **ret,
131  const char *trait,
132  unsigned int index)
133 {
134  return GNUNET_OK;
135 }
136 
137 
147  const char *start_label)
148 {
149  struct StopPeerState *sps;
150 
151  sps = GNUNET_new (struct StopPeerState);
152  sps->start_label = start_label;
153 
154  struct GNUNET_TESTING_Command cmd = {
155  .cls = sps,
156  .label = label,
157  .run = &stop_peer_run,
158  .cleanup = &stop_peer_cleanup,
159  .traits = &stop_peer_traits
160  };
161 
162  return cmd;
163 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_log(kind,...)
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_NO
Definition: gnunet_common.h:94
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(const char *label)
Lookup command by label.
Bandwidth allocation API for applications to interact with.
void GNUNET_TRANSPORT_application_done(struct GNUNET_TRANSPORT_ApplicationHandle *ch)
Shutdown TRANSPORT application client.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_PEERSTORE_iterate_cancel(struct GNUNET_PEERSTORE_IterateContext *ic)
Cancel an iterate request Please do not call after the iterate request is done.
void GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h, int sync_first)
Disconnect from the PEERSTORE service.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
int GNUNET_TESTING_peer_stop(struct GNUNET_TESTING_Peer *peer)
Stop the peer.
Definition: testing.c:1457
void GNUNET_TESTING_peer_destroy(struct GNUNET_TESTING_Peer *peer)
Destroy the peer.
Definition: testing.c:1549
void GNUNET_TRANSPORT_core_disconnect(struct GNUNET_TRANSPORT_CoreHandle *handle)
Disconnect from the transport service.
A command to be run by the interpreter.
const char * label
Label for the command.
void * cls
Closure for all commands with command-specific context information.
Global state of the interpreter, used by a command to access information about other commands.
Definition: testing.h:35
unsigned int no
An unique number to identify the peer.
struct GNUNET_PeerIdentity id
Peer identity.
struct GNUNET_PEERSTORE_Handle * ph
Peer's PEERSTORE Handle.
struct GNUNET_SCHEDULER_Task * rh_task
Hello get task.
struct GNUNET_PEERSTORE_IterateContext * pic
Peer's transport get hello handle to retrieve peer's HELLO message.
struct GNUNET_TESTING_Peer * peer
struct GNUNET_TRANSPORT_CoreHandle * th
Peer's transport service handle.
struct GNUNET_TRANSPORT_ApplicationHandle * ah
Application handle.
Struct to hold information for callbacks.
struct GNUNET_TESTING_Interpreter * is
int GNUNET_TRANSPORT_get_trait_state(const struct GNUNET_TESTING_Command *cmd, struct StartPeerState **sps)
Function to get the trait with the struct StartPeerState.
struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_stop_peer(const char *label, const char *start_label)
Create command.
static int stop_peer_traits(void *cls, const void **ret, const char *trait, unsigned int index)
Trait function of this cmd does nothing.
#define LOG(kind,...)
Generic logging shortcut.
static void stop_peer_cleanup(void *cls, const struct GNUNET_TESTING_Command *cmd)
The cleanup function of this cmd frees resources the cmd allocated.
static void stop_peer_run(void *cls, const struct GNUNET_TESTING_Command *cmd, 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...