aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport_api_cmd_send_simple.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/transport_api_cmd_send_simple.c')
-rw-r--r--src/transport/transport_api_cmd_send_simple.c156
1 files changed, 0 insertions, 156 deletions
diff --git a/src/transport/transport_api_cmd_send_simple.c b/src/transport/transport_api_cmd_send_simple.c
deleted file mode 100644
index 0631f7051..000000000
--- a/src/transport/transport_api_cmd_send_simple.c
+++ /dev/null
@@ -1,156 +0,0 @@
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
21/**
22 * @file testing_api_cmd_start_peer.c
23 * @brief cmd to start a peer.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29#include "transport-testing2.h"
30#include "transport-testing-cmds.h"
31
32/**
33 * Struct to hold information for callbacks.
34 *
35 */
36struct SendSimpleState
37{
38 /**
39 * Number globally identifying the node.
40 *
41 */
42 uint32_t num;
43
44 /**
45 * Label of the cmd to start a peer.
46 *
47 */
48 const char *start_peer_label;
49};
50
51
52/**
53 * Trait function of this cmd does nothing.
54 *
55 */
56static int
57send_simple_traits (void *cls,
58 const void **ret,
59 const char *trait,
60 unsigned int index)
61{
62 return GNUNET_OK;
63}
64
65
66/**
67 * The cleanup function of this cmd frees resources the cmd allocated.
68 *
69 */
70static void
71send_simple_cleanup (void *cls)
72{
73 struct SendSimpleState *sss = cls;
74
75 GNUNET_free (sss);
76}
77
78
79/**
80 * The run method of this cmd will send a simple message to the connected peer.
81 *
82 */
83static void
84send_simple_run (void *cls,
85 struct GNUNET_TESTING_Interpreter *is)
86{
87 struct SendSimpleState *sss = cls;
88 struct GNUNET_MQ_Envelope *env;
89 struct GNUNET_TRANSPORT_TESTING_TestMessage *test;
90 struct GNUNET_MQ_Handle *mq;
91 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
92 const struct GNUNET_TESTING_Command *peer1_cmd;
93 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
94 struct GNUNET_HashCode hc;
95 int node_number;
96
97 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
98 sss->start_peer_label);
99 GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd,
100 &connected_peers_map);
101
102 node_number = 1;
103 GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
104 memcpy (key,
105 &hc,
106 sizeof (*key));
107
108 mq = GNUNET_CONTAINER_multishortmap_get (connected_peers_map,
109 key);
110
111 env = GNUNET_MQ_msg_extra (test,
112 2600 - sizeof(*test),
113 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE);
114 test->num = htonl (sss->num);
115 memset (&test[1],
116 sss->num,
117 2600 - sizeof(*test));
118 GNUNET_MQ_send (mq,
119 env);
120 GNUNET_free (key);
121
122}
123
124
125/**
126 * Create command.
127 *
128 * @param label name for command.
129 * @param m The number of the local node of the actual network namespace.
130 * @param n The number of the actual namespace.
131 * @param num Number globally identifying the node.
132 * @param start_peer_label Label of the cmd to start a peer.
133 * @return command.
134 */
135struct GNUNET_TESTING_Command
136GNUNET_TRANSPORT_cmd_send_simple (const char *label,
137 const char *start_peer_label,
138 uint32_t num)
139{
140 struct SendSimpleState *sss;
141
142 sss = GNUNET_new (struct SendSimpleState);
143 sss->num = num;
144 sss->start_peer_label = start_peer_label;
145 {
146 struct GNUNET_TESTING_Command cmd = {
147 .cls = sss,
148 .label = label,
149 .run = &send_simple_run,
150 .cleanup = &send_simple_cleanup,
151 .traits = &send_simple_traits
152 };
153
154 return cmd;
155 }
156}