diff options
Diffstat (limited to 'src/transport/transport_api_cmd_send_simple.c')
-rw-r--r-- | src/transport/transport_api_cmd_send_simple.c | 212 |
1 files changed, 0 insertions, 212 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 ade0cc914..000000000 --- a/src/transport/transport_api_cmd_send_simple.c +++ /dev/null | |||
@@ -1,212 +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 "gnunet_testing_netjail_lib.h" | ||
30 | #include "transport-testing2.h" | ||
31 | #include "transport-testing-cmds.h" | ||
32 | |||
33 | /** | ||
34 | * Generic logging shortcut | ||
35 | */ | ||
36 | #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) | ||
37 | |||
38 | /** | ||
39 | * Struct to hold information for callbacks. | ||
40 | * | ||
41 | */ | ||
42 | struct SendSimpleState | ||
43 | { | ||
44 | /** | ||
45 | * Number globally identifying the node. | ||
46 | * | ||
47 | */ | ||
48 | uint32_t num; | ||
49 | |||
50 | /** | ||
51 | * Label of the cmd to start a peer. | ||
52 | * | ||
53 | */ | ||
54 | const char *start_peer_label; | ||
55 | |||
56 | /** | ||
57 | * Label of the cmd which started the test system. | ||
58 | * | ||
59 | */ | ||
60 | const char *create_label; | ||
61 | |||
62 | /** | ||
63 | * The topology we get the connected nodes from. | ||
64 | */ | ||
65 | struct GNUNET_TESTING_NetjailTopology *topology; | ||
66 | }; | ||
67 | |||
68 | |||
69 | /** | ||
70 | * The cleanup function of this cmd frees resources the cmd allocated. | ||
71 | * | ||
72 | */ | ||
73 | static void | ||
74 | send_simple_cleanup (void *cls) | ||
75 | { | ||
76 | struct SendSimpleState *sss = cls; | ||
77 | |||
78 | GNUNET_free (sss); | ||
79 | } | ||
80 | |||
81 | |||
82 | static int | ||
83 | send_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; | ||
90 | struct GNUNET_TRANSPORT_TESTING_TestMessage *test; | ||
91 | |||
92 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
93 | "Sending simple test message\n"); | ||
94 | |||
95 | env = GNUNET_MQ_msg_extra (test, | ||
96 | 1000 - sizeof(*test), | ||
97 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE); | ||
98 | test->num = htonl (sss->num); | ||
99 | memset (&test[1], | ||
100 | sss->num, | ||
101 | 1000 - sizeof(*test)); | ||
102 | GNUNET_MQ_send (mq, | ||
103 | env); | ||
104 | return GNUNET_OK; | ||
105 | } | ||
106 | |||
107 | |||
108 | /** | ||
109 | * The run method of this cmd will send a simple message to the connected peers. | ||
110 | * | ||
111 | */ | ||
112 | static void | ||
113 | send_simple_run (void *cls, | ||
114 | struct GNUNET_TESTING_Interpreter *is) | ||
115 | { | ||
116 | struct SendSimpleState *sss = cls; | ||
117 | const struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map; | ||
118 | const struct GNUNET_TESTING_Command *peer1_cmd; | ||
119 | // struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode); | ||
120 | struct GNUNET_HashCode hc; | ||
121 | struct GNUNET_TESTING_NodeConnection *node_connections_head; | ||
122 | struct GNUNET_PeerIdentity *peer; | ||
123 | struct GNUNET_CRYPTO_EddsaPublicKey public_key; | ||
124 | uint32_t num; | ||
125 | struct GNUNET_TESTING_NodeConnection *pos_connection; | ||
126 | const struct GNUNET_TESTING_Command *system_cmd; | ||
127 | const struct GNUNET_TESTING_System *tl_system; | ||
128 | |||
129 | peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is, | ||
130 | sss->start_peer_label); | ||
131 | GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd, | ||
132 | &connected_peers_map); | ||
133 | |||
134 | system_cmd = GNUNET_TESTING_interpreter_lookup_command (is, | ||
135 | sss->create_label); | ||
136 | GNUNET_TESTING_get_trait_test_system (system_cmd, | ||
137 | &tl_system); | ||
138 | |||
139 | node_connections_head = GNUNET_TESTING_get_connections (sss->num, | ||
140 | sss->topology); | ||
141 | |||
142 | GNUNET_CONTAINER_multishortmap_iterate ( | ||
143 | (struct GNUNET_CONTAINER_MultiShortmap *) | ||
144 | connected_peers_map, send_simple_cb, | ||
145 | sss); | ||
146 | /*for (int i = 0; i < 1; i++) | ||
147 | { | ||
148 | for (pos_connection = node_connections_head; NULL != pos_connection; | ||
149 | pos_connection = pos_connection->next) | ||
150 | { | ||
151 | num = GNUNET_TESTING_calculate_num (pos_connection, sss->topology); | ||
152 | peer = GNUNET_TESTING_get_pub_key (num, tl_system); | ||
153 | public_key = peer->public_key; | ||
154 | GNUNET_CRYPTO_hash (&public_key, sizeof(public_key), &hc); | ||
155 | |||
156 | memcpy (key, | ||
157 | &hc, | ||
158 | sizeof (*key)); | ||
159 | mq = GNUNET_CONTAINER_multishortmap_get (connected_peers_map, | ||
160 | key); | ||
161 | env = GNUNET_MQ_msg_extra (test, | ||
162 | 1000 - sizeof(*test), | ||
163 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE); | ||
164 | test->num = htonl (sss->num); | ||
165 | memset (&test[1], | ||
166 | sss->num, | ||
167 | 1000 - sizeof(*test)); | ||
168 | GNUNET_MQ_send (mq, | ||
169 | env); | ||
170 | } | ||
171 | }*/ | ||
172 | |||
173 | // GNUNET_free (key); | ||
174 | |||
175 | } | ||
176 | |||
177 | |||
178 | /** | ||
179 | * Create command. | ||
180 | * | ||
181 | * @param label name for command. | ||
182 | * @param start_peer_label Label of the cmd to start a peer. | ||
183 | * @param start_peer_label Label of the cmd which started the test system. | ||
184 | * @param num Number globally identifying the node. | ||
185 | * @param The topology for the test setup. | ||
186 | * @return command. | ||
187 | */ | ||
188 | struct GNUNET_TESTING_Command | ||
189 | GNUNET_TRANSPORT_cmd_send_simple (const char *label, | ||
190 | const char *start_peer_label, | ||
191 | const char *create_label, | ||
192 | uint32_t num, | ||
193 | struct GNUNET_TESTING_NetjailTopology * | ||
194 | topology) | ||
195 | { | ||
196 | struct SendSimpleState *sss; | ||
197 | |||
198 | sss = GNUNET_new (struct SendSimpleState); | ||
199 | sss->num = num; | ||
200 | sss->start_peer_label = start_peer_label; | ||
201 | sss->create_label = create_label; | ||
202 | sss->topology = topology; | ||
203 | |||
204 | struct GNUNET_TESTING_Command cmd = { | ||
205 | .cls = sss, | ||
206 | .label = label, | ||
207 | .run = &send_simple_run, | ||
208 | .cleanup = &send_simple_cleanup | ||
209 | }; | ||
210 | |||
211 | return cmd; | ||
212 | } | ||