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.c172
1 files changed, 0 insertions, 172 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 f9e515c0f..000000000
--- a/src/transport/transport_api_cmd_send_simple.c
+++ /dev/null
@@ -1,172 +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 * The number of the local node of the actual network namespace.
40 *
41 */
42 char *m;
43
44 /**
45 * The number of the actual namespace.
46 *
47 */
48 char *n;
49
50 /**
51 * Number globally identifying the node.
52 *
53 */
54 uint32_t num;
55
56 /**
57 * Label of the cmd to start a peer.
58 *
59 */
60 const char *start_peer_label;
61};
62
63
64/**
65 * Trait function of this cmd does nothing.
66 *
67 */
68static int
69send_simple_traits (void *cls,
70 const void **ret,
71 const char *trait,
72 unsigned int index)
73{
74 return GNUNET_OK;
75}
76
77
78/**
79 * The cleanup function of this cmd frees resources the cmd allocated.
80 *
81 */
82static void
83send_simple_cleanup (void *cls,
84 const struct GNUNET_TESTING_Command *cmd)
85{
86 struct SendSimpleState *sss = cls;
87
88 GNUNET_free (sss);
89}
90
91
92/**
93 * The run method of this cmd will send a simple message to the connected peer.
94 *
95 */
96static void
97send_simple_run (void *cls,
98 const struct GNUNET_TESTING_Command *cmd,
99 struct GNUNET_TESTING_Interpreter *is)
100{
101 struct SendSimpleState *sss = cls;
102 struct GNUNET_MQ_Envelope *env;
103 struct GNUNET_TRANSPORT_TESTING_TestMessage *test;
104 struct GNUNET_MQ_Handle *mq;
105 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
106 const struct GNUNET_TESTING_Command *peer1_cmd;
107 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
108 struct GNUNET_HashCode hc;
109 int node_number;
110
111 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->start_peer_label);
112 GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd,
113 &connected_peers_map);
114
115 node_number = 1;
116 GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
117 memcpy (key,
118 &hc,
119 sizeof (*key));
120
121 mq = GNUNET_CONTAINER_multishortmap_get (connected_peers_map,
122 key);
123
124 env = GNUNET_MQ_msg_extra (test,
125 2600 - sizeof(*test),
126 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE);
127 test->num = htonl (sss->num);
128 memset (&test[1],
129 sss->num,
130 2600 - sizeof(*test));
131 GNUNET_MQ_send (mq,
132 env);
133 GNUNET_free (key);
134
135}
136
137
138/**
139 * Create command.
140 *
141 * @param label name for command.
142 * @param m The number of the local node of the actual network namespace.
143 * @param n The number of the actual namespace.
144 * @param num Number globally identifying the node.
145 * @param start_peer_label Label of the cmd to start a peer.
146 * @return command.
147 */
148struct GNUNET_TESTING_Command
149GNUNET_TRANSPORT_cmd_send_simple (const char *label,
150 char *m,
151 char *n,
152 uint32_t num,
153 const char *start_peer_label)
154{
155 struct SendSimpleState *sss;
156
157 sss = GNUNET_new (struct SendSimpleState);
158 sss->m = m;
159 sss->n = n;
160 sss->num = num;
161 sss->start_peer_label = start_peer_label;
162
163 struct GNUNET_TESTING_Command cmd = {
164 .cls = sss,
165 .label = label,
166 .run = &send_simple_run,
167 .cleanup = &send_simple_cleanup,
168 .traits = &send_simple_traits
169 };
170
171 return cmd;
172}