GNUnet 0.22.2
transport_api_cmd_send_simple.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_testing_netjail_lib.h"
30#include "transport-testing2.h"
32
36#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
37
43{
48 uint32_t num;
49
54 const char *start_peer_label;
55
60 const char *create_label;
61
66};
67
68
73static void
75{
76 struct SendSimpleState *sss = cls;
77
78 GNUNET_free (sss);
79}
80
81
82static int
83send_simple_cb (void *cls,
84 const struct GNUNET_ShortHashCode *key,
85 void *value)
86{
87 struct SendSimpleState *sss = cls;
88 struct GNUNET_MQ_Handle *mq = value;
89 struct GNUNET_MQ_Envelope *env;
91
93 "Sending simple test message with mq %p\n",
94 mq);
95
97 1000 - sizeof(*test),
99 test->num = htonl (sss->num);
100 memset (&test[1],
101 sss->num,
102 1000 - sizeof(*test));
104 env);
105 return GNUNET_OK;
106}
107
108
113static void
116{
117 struct SendSimpleState *sss = cls;
118 const struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
119 const struct GNUNET_TESTING_Command *peer1_cmd;
120 const struct GNUNET_TESTING_Command *system_cmd;
121 const struct GNUNET_TESTBED_System *tl_system;
122
124 sss->start_peer_label);
126 &connected_peers_map);
127
129 sss->create_label);
130 GNUNET_TESTING_get_trait_test_system (system_cmd,
131 &tl_system);
132
135 connected_peers_map, send_simple_cb,
136 sss);
137}
138
139
142 const char *start_peer_label,
143 const char *create_label,
144 uint32_t num,
146 topology)
147{
148 struct SendSimpleState *sss;
149
150 sss = GNUNET_new (struct SendSimpleState);
151 sss->num = num;
154 sss->topology = topology;
155
156 return GNUNET_TESTING_command_new (sss,
157 label,
160 NULL);
161}
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static struct GNUNET_TESTING_Interpreter * is
struct GNUNET_HashCode key
The key used in the DHT.
static char * value
Value of the record to add/remove.
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(struct GNUNET_TESTING_Interpreter *is, const char *label)
Lookup command by label.
#define GNUNET_TESTING_command_new(cls, label, run, cleanup, traits)
Create a new command.
enum GNUNET_GenericReturnValue GNUNET_TRANSPORT_TESTING_get_trait_connected_peers_map(const struct GNUNET_TESTING_Command *cmd, const struct GNUNET_CONTAINER_MultiShortmap **ret)
int GNUNET_CONTAINER_multishortmap_iterate(struct GNUNET_CONTAINER_MultiShortmap *map, GNUNET_CONTAINER_ShortmapIterator it, void *it_cls)
Iterate over all entries in the map.
@ GNUNET_OK
@ 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_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:305
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:61
Internal representation of the hash map.
Handle to a message queue.
Definition: mq.c:87
A 256-bit hashcode.
Handle for a system on which GNUnet peers are executed; a system is used for reserving unique paths a...
Definition: testbed.c:54
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.
Toplogy of our netjail setup.
uint32_t num
Monotonically increasing counter throughout the test.
Struct to hold information for callbacks.
const char * create_label
Label of the cmd which started the test system.
uint32_t num
Number globally identifying the node.
struct GNUNET_TESTING_NetjailTopology * topology
The topology we get the connected nodes from.
const char * start_peer_label
Label of the cmd to start a peer.
#define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
Message type used by GNUNET_TRANSPORT_TESTING_simple_send().
static void send_simple_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
The run method of this cmd will send a simple message to the connected peers.
static void send_simple_cleanup(void *cls)
The cleanup function of this cmd frees resources the cmd allocated.
struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_send_simple(const char *label, const char *start_peer_label, const char *create_label, uint32_t num, struct GNUNET_TESTING_NetjailTopology *topology)
Create command.
#define LOG(kind,...)
Generic logging shortcut.
static int send_simple_cb(void *cls, const struct GNUNET_ShortHashCode *key, void *value)