diff options
Diffstat (limited to 'src/transport/transport_api_cmd_send_simple_v3.c')
-rw-r--r-- | src/transport/transport_api_cmd_send_simple_v3.c | 194 |
1 files changed, 0 insertions, 194 deletions
diff --git a/src/transport/transport_api_cmd_send_simple_v3.c b/src/transport/transport_api_cmd_send_simple_v3.c deleted file mode 100644 index a4ce2c4e9..000000000 --- a/src/transport/transport_api_cmd_send_simple_v3.c +++ /dev/null | |||
@@ -1,194 +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 | */ | ||
36 | struct 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 | * Label of the cmd which started the test system. | ||
52 | * | ||
53 | */ | ||
54 | const char *create_label; | ||
55 | |||
56 | /** | ||
57 | * The topology we get the connected nodes from. | ||
58 | */ | ||
59 | struct GNUNET_TESTING_NetjailTopology *topology; | ||
60 | }; | ||
61 | |||
62 | |||
63 | /** | ||
64 | * Trait function of this cmd does nothing. | ||
65 | * | ||
66 | */ | ||
67 | static int | ||
68 | send_simple_traits (void *cls, | ||
69 | const void **ret, | ||
70 | const char *trait, | ||
71 | unsigned int index) | ||
72 | { | ||
73 | return GNUNET_OK; | ||
74 | } | ||
75 | |||
76 | |||
77 | /** | ||
78 | * The cleanup function of this cmd frees resources the cmd allocated. | ||
79 | * | ||
80 | */ | ||
81 | static void | ||
82 | send_simple_cleanup (void *cls, | ||
83 | const struct GNUNET_TESTING_Command *cmd) | ||
84 | { | ||
85 | struct SendSimpleState *sss = cls; | ||
86 | |||
87 | GNUNET_free (sss); | ||
88 | } | ||
89 | |||
90 | |||
91 | /** | ||
92 | * The run method of this cmd will send a simple message to the connected peers. | ||
93 | * | ||
94 | */ | ||
95 | static void | ||
96 | send_simple_run (void *cls, | ||
97 | const struct GNUNET_TESTING_Command *cmd, | ||
98 | struct GNUNET_TESTING_Interpreter *is) | ||
99 | { | ||
100 | struct SendSimpleState *sss = cls; | ||
101 | struct GNUNET_MQ_Envelope *env; | ||
102 | struct GNUNET_TRANSPORT_TESTING_TestMessage *test; | ||
103 | struct GNUNET_MQ_Handle *mq; | ||
104 | struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map; | ||
105 | const struct GNUNET_TESTING_Command *peer1_cmd; | ||
106 | struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode); | ||
107 | struct GNUNET_HashCode hc; | ||
108 | struct GNUNET_TESTING_NodeConnection *node_connections_head; | ||
109 | struct GNUNET_PeerIdentity *peer; | ||
110 | struct GNUNET_CRYPTO_EddsaPublicKey public_key; | ||
111 | uint32_t num; | ||
112 | struct GNUNET_TESTING_NodeConnection *pos_connection; | ||
113 | const struct GNUNET_TESTING_Command *system_cmd; | ||
114 | struct GNUNET_TESTING_System *tl_system; | ||
115 | |||
116 | peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->start_peer_label); | ||
117 | GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd, | ||
118 | &connected_peers_map); | ||
119 | |||
120 | system_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->create_label); | ||
121 | GNUNET_TESTING_get_trait_test_system (system_cmd, | ||
122 | &tl_system); | ||
123 | |||
124 | node_connections_head = GNUNET_TESTING_get_connections (sss->num, | ||
125 | sss->topology); | ||
126 | |||
127 | for (int i = 0; i < 1; i++) | ||
128 | { | ||
129 | for (pos_connection = node_connections_head; NULL != pos_connection; | ||
130 | pos_connection = pos_connection->next) | ||
131 | { | ||
132 | num = GNUNET_TESTING_calculate_num (pos_connection, sss->topology); | ||
133 | peer = GNUNET_TESTING_get_pub_key (num, tl_system); | ||
134 | public_key = peer->public_key; | ||
135 | GNUNET_CRYPTO_hash (&public_key, sizeof(public_key), &hc); | ||
136 | |||
137 | memcpy (key, | ||
138 | &hc, | ||
139 | sizeof (*key)); | ||
140 | mq = GNUNET_CONTAINER_multishortmap_get (connected_peers_map, | ||
141 | key); | ||
142 | env = GNUNET_MQ_msg_extra (test, | ||
143 | 1000 - sizeof(*test), | ||
144 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE); | ||
145 | test->num = htonl (sss->num); | ||
146 | memset (&test[1], | ||
147 | sss->num, | ||
148 | 1000 - sizeof(*test)); | ||
149 | GNUNET_MQ_send (mq, | ||
150 | env); | ||
151 | } | ||
152 | } | ||
153 | |||
154 | GNUNET_free (key); | ||
155 | |||
156 | } | ||
157 | |||
158 | |||
159 | /** | ||
160 | * Create command. | ||
161 | * | ||
162 | * @param label name for command. | ||
163 | * @param start_peer_label Label of the cmd to start a peer. | ||
164 | * @param start_peer_label Label of the cmd which started the test system. | ||
165 | * @param num Number globally identifying the node. | ||
166 | * @param The topology for the test setup. | ||
167 | * @return command. | ||
168 | */ | ||
169 | struct GNUNET_TESTING_Command | ||
170 | GNUNET_TRANSPORT_cmd_send_simple_v3 (const char *label, | ||
171 | const char *start_peer_label, | ||
172 | const char *create_label, | ||
173 | uint32_t num, | ||
174 | struct GNUNET_TESTING_NetjailTopology * | ||
175 | topology) | ||
176 | { | ||
177 | struct SendSimpleState *sss; | ||
178 | |||
179 | sss = GNUNET_new (struct SendSimpleState); | ||
180 | sss->num = num; | ||
181 | sss->start_peer_label = start_peer_label; | ||
182 | sss->create_label = create_label; | ||
183 | sss->topology = topology; | ||
184 | |||
185 | struct GNUNET_TESTING_Command cmd = { | ||
186 | .cls = sss, | ||
187 | .label = label, | ||
188 | .run = &send_simple_run, | ||
189 | .cleanup = &send_simple_cleanup, | ||
190 | .traits = &send_simple_traits | ||
191 | }; | ||
192 | |||
193 | return cmd; | ||
194 | } | ||