GNUnet  0.11.x
testing_api_cmd_send_peer_ready.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 "testing_cmds.h"
30 
31 
37 {
43 
49 };
50 
51 
56 static enum GNUNET_GenericReturnValue
57 send_peer_ready_traits (void *cls,
58  const void **ret,
59  const char *trait,
60  unsigned int index)
61 {
62  return GNUNET_NO;
63 }
64 
65 
70 static void
72 {
73  struct SendPeerReadyState *sprs = cls;
74 
75  GNUNET_free (sprs->reply);
76  GNUNET_free (sprs);
77 }
78 
79 
84 static void
87 {
88  struct SendPeerReadyState *sprs = cls;
89  struct GNUNET_CMDS_PEER_STARTED *reply;
90  size_t msg_length;
91 
92  msg_length = sizeof(struct GNUNET_CMDS_PEER_STARTED);
93  reply = GNUNET_new (struct GNUNET_CMDS_PEER_STARTED);
95  reply->header.size = htons ((uint16_t) msg_length);
96  sprs->reply = reply;
97  sprs->write_message ((struct GNUNET_MessageHeader *) reply, msg_length);
98 }
99 
100 
111 {
112  struct SendPeerReadyState *sprs;
113 
114  sprs = GNUNET_new (struct SendPeerReadyState);
116  {
117  struct GNUNET_TESTING_Command cmd = {
118  .cls = sprs,
119  .label = label,
120  .run = &send_peer_ready_run,
121  .cleanup = &send_peer_ready_cleanup,
122  .traits = &send_peer_ready_traits
123  };
124 
125  return cmd;
126  }
127 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
static int write_message(uint16_t message_type, const char *data, size_t data_length)
Write message to the master process.
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:92
@ GNUNET_NO
Definition: gnunet_common.h:94
void(* TESTING_CMD_HELPER_write_cb)(struct GNUNET_MessageHeader *message, size_t msg_length)
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED.
Definition: testing_cmds.h:69
Header for all communications.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
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.
Struct to hold information for callbacks.
struct GNUNET_CMDS_PEER_STARTED * reply
The message send back to the master loop.
TESTING_CMD_HELPER_write_cb write_message
Callback to write messages to the master loop.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_send_peer_ready(const char *label, TESTING_CMD_HELPER_write_cb write_message)
Create command.
static void send_peer_ready_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
This function sends a GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED message to the master loop.
static void send_peer_ready_cleanup(void *cls)
The cleanup function of this cmd frees resources the cmd allocated.
static enum GNUNET_GenericReturnValue send_peer_ready_traits(void *cls, const void **ret, const char *trait, unsigned int index)
Trait function of this cmd does nothing.
Message formats for communication between testing cmds helper and testcase plugins.