aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_testbed_ng_service.h3
-rw-r--r--src/include/gnunet_testing_ng_lib.h37
-rw-r--r--src/include/gnunet_testing_plugin.h4
-rw-r--r--src/testbed/gnunet-cmds-helper.c5
-rw-r--r--src/testbed/plugin_testcmd.c6
-rw-r--r--src/testbed/test_testbed_api_cmd_netjail.c5
-rw-r--r--src/testbed/testbed_api_cmd_netjail_start_testbed.c9
-rw-r--r--src/testing/Makefile.am1
-rw-r--r--src/testing/testing_api_cmd_start_peer.c296
-rw-r--r--src/testing/testing_api_cmd_system_create.c14
-rw-r--r--src/transport/Makefile.am29
-rw-r--r--src/transport/plugin_cmd_simple_send.c122
-rw-r--r--src/transport/test_transport_api_cmd_simple_send.c80
-rw-r--r--src/transport/transport_api_cmd_connecting_peers.c178
-rw-r--r--src/transport/transport_api_cmd_send_simple.c136
-rw-r--r--src/transport/transport_api_cmd_start_peer.c558
16 files changed, 1175 insertions, 308 deletions
diff --git a/src/include/gnunet_testbed_ng_service.h b/src/include/gnunet_testbed_ng_service.h
index caaee26b6..49e9f56bc 100644
--- a/src/include/gnunet_testbed_ng_service.h
+++ b/src/include/gnunet_testbed_ng_service.h
@@ -232,7 +232,8 @@ GNUNET_TESTBED_cmd_netjail_start (const char *label,
232struct GNUNET_TESTING_Command 232struct GNUNET_TESTING_Command
233GNUNET_TESTBED_cmd_netjail_start_testbed (const char *label, 233GNUNET_TESTBED_cmd_netjail_start_testbed (const char *label,
234 char *local_m, 234 char *local_m,
235 char *global_n); 235 char *global_n,
236 char *plugin_name);
236 237
237 238
238/** 239/**
diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h
index 8927fd4f1..994ce31f1 100644
--- a/src/include/gnunet_testing_ng_lib.h
+++ b/src/include/gnunet_testing_ng_lib.h
@@ -29,6 +29,8 @@
29 29
30#include "gnunet_util_lib.h" 30#include "gnunet_util_lib.h"
31#include "gnunet_testing_plugin.h" 31#include "gnunet_testing_plugin.h"
32#include "gnunet_transport_application_service.h"
33#include "gnunet_testing_lib.h"
32 34
33 35
34/* ********************* Helper functions ********************* */ 36/* ********************* Helper functions ********************* */
@@ -831,4 +833,39 @@ int
831GNUNET_TESTING_get_trait_what_am_i (const struct GNUNET_TESTING_Command *cmd, 833GNUNET_TESTING_get_trait_what_am_i (const struct GNUNET_TESTING_Command *cmd,
832 char **what_am_i); 834 char **what_am_i);
833 835
836int
837GNUNET_TESTING_get_trait_application_handle (const struct
838 GNUNET_TESTING_Command *cmd,
839 struct
840 GNUNET_TRANSPORT_ApplicationHandle
841 **ah);
842
843int
844GNUNET_TESTING_get_trait_peer_id (const struct
845 GNUNET_TESTING_Command *cmd,
846 struct GNUNET_PeerIdentity **id);
847
848int
849GNUNET_TESTING_get_trait_connected_peers_map (const struct
850 GNUNET_TESTING_Command
851 *cmd,
852 struct
853 GNUNET_CONTAINER_MultiPeerMap **
854 connected_peers_map);
855int
856GNUNET_TESTING_get_trait_hello_size (const struct
857 GNUNET_TESTING_Command
858 *cmd,
859 size_t **hello_size);
860
861int
862GNUNET_TESTING_get_trait_hello (const struct
863 GNUNET_TESTING_Command
864 *cmd,
865 char **hello);
866
867int
868GNUNET_TESTING_get_trait_test_system (const struct
869 GNUNET_TESTING_Command *cmd,
870 struct GNUNET_TESTING_System **test_system);
834#endif 871#endif
diff --git a/src/include/gnunet_testing_plugin.h b/src/include/gnunet_testing_plugin.h
index 6a54cacd2..8395e2a49 100644
--- a/src/include/gnunet_testing_plugin.h
+++ b/src/include/gnunet_testing_plugin.h
@@ -43,7 +43,9 @@ typedef void
43typedef void 43typedef void
44(*GNUNET_TESTING_PLUGIN_StartTestCase) (TESTBED_CMD_HELPER_write_cb 44(*GNUNET_TESTING_PLUGIN_StartTestCase) (TESTBED_CMD_HELPER_write_cb
45 write_message, char *router_ip, 45 write_message, char *router_ip,
46 char *node_ip); 46 char *node_ip,
47 char *n,
48 char *m);
47 49
48typedef void 50typedef void
49(*GNUNET_TESTING_PLUGIN_ALL_PEERS_STARTED) (); 51(*GNUNET_TESTING_PLUGIN_ALL_PEERS_STARTED) ();
diff --git a/src/testbed/gnunet-cmds-helper.c b/src/testbed/gnunet-cmds-helper.c
index 0d618bd48..113e3c386 100644
--- a/src/testbed/gnunet-cmds-helper.c
+++ b/src/testbed/gnunet-cmds-helper.c
@@ -427,7 +427,8 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
427 strcat (node_ip, NODE_BASE_IP); 427 strcat (node_ip, NODE_BASE_IP);
428 strcat (node_ip, plugin->n); 428 strcat (node_ip, plugin->n);
429 429
430 plugin->api->start_testcase (&write_message, router_ip, node_ip); 430 plugin->api->start_testcase (&write_message, router_ip, node_ip, plugin->m,
431 plugin->n);
431 432
432 LOG (GNUNET_ERROR_TYPE_ERROR, 433 LOG (GNUNET_ERROR_TYPE_ERROR,
433 "We got here!\n"); 434 "We got here!\n");
@@ -479,8 +480,6 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
479 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED == ntohs ( 480 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED == ntohs (
480 message->type)) 481 message->type))
481 { 482 {
482 LOG (GNUNET_ERROR_TYPE_ERROR,
483 "We got here 8!\n");
484 plugin->api->all_peers_started (); 483 plugin->api->all_peers_started ();
485 return GNUNET_OK; 484 return GNUNET_OK;
486 } 485 }
diff --git a/src/testbed/plugin_testcmd.c b/src/testbed/plugin_testcmd.c
index 70b6ad3ae..797826781 100644
--- a/src/testbed/plugin_testcmd.c
+++ b/src/testbed/plugin_testcmd.c
@@ -46,7 +46,9 @@ all_peers_started ()
46 46
47static void 47static void
48start_testcase (TESTBED_CMD_HELPER_write_cb write_message, char *router_ip, 48start_testcase (TESTBED_CMD_HELPER_write_cb write_message, char *router_ip,
49 char *node_ip) 49 char *node_ip,
50 char *n,
51 char *m)
50{ 52{
51 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); 53 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
52 54
@@ -110,4 +112,4 @@ libgnunet_plugin_testcmd_done (void *cls)
110} 112}
111 113
112 114
113/* end of plugin_gnsrecord_dns.c */ 115/* end of plugin_testcmd.c */
diff --git a/src/testbed/test_testbed_api_cmd_netjail.c b/src/testbed/test_testbed_api_cmd_netjail.c
index e5fc0877e..8bb9e40e8 100644
--- a/src/testbed/test_testbed_api_cmd_netjail.c
+++ b/src/testbed/test_testbed_api_cmd_netjail.c
@@ -19,7 +19,7 @@
19 */ 19 */
20 20
21/** 21/**
22 * @file testing/test_testing_api_cmd_netjail.c 22 * @file testing/test_testbed_api_cmd_netjail.c
23 * @brief Test case executing a script in a network name space. 23 * @brief Test case executing a script in a network name space.
24 * @author t3sserakt 24 * @author t3sserakt
25 */ 25 */
@@ -44,7 +44,8 @@ run (void *cls)
44 "2"), 44 "2"),
45 GNUNET_TESTBED_cmd_netjail_start_testbed ("netjail-start-testbed-1", 45 GNUNET_TESTBED_cmd_netjail_start_testbed ("netjail-start-testbed-1",
46 "2", 46 "2",
47 "2"), 47 "2",
48 "libgnunet_plugin_testcmd"),
48 GNUNET_TESTBED_cmd_stop_testbed ("stop-testbed", 49 GNUNET_TESTBED_cmd_stop_testbed ("stop-testbed",
49 "netjail-start-testbed-1", 50 "netjail-start-testbed-1",
50 "2", 51 "2",
diff --git a/src/testbed/testbed_api_cmd_netjail_start_testbed.c b/src/testbed/testbed_api_cmd_netjail_start_testbed.c
index bc4674b74..9b68c52f6 100644
--- a/src/testbed/testbed_api_cmd_netjail_start_testbed.c
+++ b/src/testbed/testbed_api_cmd_netjail_start_testbed.c
@@ -97,6 +97,8 @@ struct NetJailState
97 struct GNUNET_TESTBED_Host **host; 97 struct GNUNET_TESTBED_Host **host;
98 98
99 unsigned int n_host; 99 unsigned int n_host;
100
101 char *plugin_name;
100}; 102};
101 103
102struct TestbedCount 104struct TestbedCount
@@ -345,6 +347,7 @@ start_testbed (struct NetJailState *ns, struct
345 347
346 cfg = GNUNET_CONFIGURATION_dup (config); 348 cfg = GNUNET_CONFIGURATION_dup (config);
347 349
350 // TODO We do not need this?
348 GNUNET_array_append (ns->host, ns->n_host, 351 GNUNET_array_append (ns->host, ns->n_host,
349 GNUNET_TESTBED_host_create_with_id (tbc->count - 1, 352 GNUNET_TESTBED_host_create_with_id (tbc->count - 1,
350 NULL, 353 NULL,
@@ -374,7 +377,7 @@ start_testbed (struct NetJailState *ns, struct
374 377
375 msg = create_helper_init_msg_ (m_char, 378 msg = create_helper_init_msg_ (m_char,
376 n_char, 379 n_char,
377 "libgnunet_plugin_testcmd"); 380 ns->plugin_name);
378 GNUNET_array_append (ns->msg, ns->n_msg, &msg->header); 381 GNUNET_array_append (ns->msg, ns->n_msg, &msg->header);
379 382
380 GNUNET_array_append (ns->shandle, ns->n_shandle, GNUNET_HELPER_send ( 383 GNUNET_array_append (ns->shandle, ns->n_shandle, GNUNET_HELPER_send (
@@ -506,13 +509,15 @@ netjail_start_finish (void *cls,
506struct GNUNET_TESTING_Command 509struct GNUNET_TESTING_Command
507GNUNET_TESTBED_cmd_netjail_start_testbed (const char *label, 510GNUNET_TESTBED_cmd_netjail_start_testbed (const char *label,
508 char *local_m, 511 char *local_m,
509 char *global_n) 512 char *global_n,
513 char *plugin_name)
510{ 514{
511 struct NetJailState *ns; 515 struct NetJailState *ns;
512 516
513 ns = GNUNET_new (struct NetJailState); 517 ns = GNUNET_new (struct NetJailState);
514 ns->local_m = local_m; 518 ns->local_m = local_m;
515 ns->global_n = global_n; 519 ns->global_n = global_n;
520 ns->plugin_name = plugin_name;
516 521
517 struct GNUNET_TESTING_Command cmd = { 522 struct GNUNET_TESTING_Command cmd = {
518 .cls = ns, 523 .cls = ns,
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index 95fc5c805..868e3fcec 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -16,6 +16,7 @@ lib_LTLIBRARIES = \
16 16
17libgnunettesting_la_SOURCES = \ 17libgnunettesting_la_SOURCES = \
18 testing.c \ 18 testing.c \
19 testing_api_cmd_system_create.c \
19 testing_api_cmd_batch.c \ 20 testing_api_cmd_batch.c \
20 testing_api_cmd_hello_world.c \ 21 testing_api_cmd_hello_world.c \
21 testing_api_cmd_hello_world_birth.c \ 22 testing_api_cmd_hello_world_birth.c \
diff --git a/src/testing/testing_api_cmd_start_peer.c b/src/testing/testing_api_cmd_start_peer.c
deleted file mode 100644
index 0f8c618b8..000000000
--- a/src/testing/testing_api_cmd_start_peer.c
+++ /dev/null
@@ -1,296 +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
30
31struct StartPeerState
32{
33 /**
34 * Receive callback
35 */
36 struct GNUNET_MQ_MessageHandler *handlers;
37
38 const char *cfgname;
39
40 /**
41 * Peer's configuration
42 */
43 struct GNUNET_CONFIGURATION_Handle *cfg;
44
45 struct GNUNET_TESTING_Peer *peer;
46
47 /**
48 * Peer identity
49 */
50 struct GNUNET_PeerIdentity id;
51
52 /**
53 * Peer's transport service handle
54 */
55 struct GNUNET_TRANSPORT_CoreHandle *th;
56
57 /**
58 * Application handle
59 */
60 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
61
62 /**
63 * Peer's PEERSTORE Handle
64 */
65 struct GNUNET_PEERSTORE_Handle *ph;
66
67 /**
68 * Hello get task
69 */
70 struct GNUNET_SCHEDULER_Task *rh_task;
71
72 /**
73 * Peer's transport get hello handle to retrieve peer's HELLO message
74 */
75 struct GNUNET_PEERSTORE_IterateContext *pic;
76
77 /**
78 * Hello
79 */
80 char *hello;
81
82 /**
83 * Hello size
84 */
85 size_t hello_size;
86
87 char *m;
88
89 char *n;
90
91 unsigned int finished;
92};
93
94
95static void
96retrieve_hello (void *cls);
97
98static void
99hello_iter_cb (void *cb_cls,
100 const struct GNUNET_PEERSTORE_Record *record,
101 const char *emsg)
102{
103 struct StartPeerState *sps = cb_cls;
104 if (NULL == record)
105 {
106 sps->pic = NULL;
107 sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, p);
108 return;
109 }
110 // Check record type et al?
111 sps->hello_size = record->value_size;
112 sps->hello = GNUNET_malloc (sps->hello_size);
113 memcpy (sps->hello, record->value, sps->hello_size);
114 p->hello[p->hello_size - 1] = '\0';
115
116 GNUNET_PEERSTORE_iterate_cancel (sps->pic);
117 sps->pic = NULL;
118 sps->finished = GNUNET_YES;
119}
120
121
122static void
123retrieve_hello (void *cls)
124{
125 struct StartPeerState *sps = cls;
126 sps->rh_task = NULL;
127 sps->pic = GNUNET_PEERSTORE_iterate (sps->ph,
128 "transport",
129 &sps->id,
130 GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY,
131 hello_iter_cb,
132 sps);
133
134}
135
136static int
137start_peer_finish (void *cls,
138 GNUNET_SCHEDULER_TaskCallback cont,
139 void *cont_cls)
140{
141 struct StartPeerState *sps = cls;
142
143 return sps->finished;
144}
145
146
147static void
148start_peer_run (void *cls,
149 const struct GNUNET_TESTING_Command *cmd,
150 struct GNUNET_TESTING_Interpreter *is)
151{
152 struct StartPeerState *sps = cls;
153 char *emsg = NULL;
154 struct GNUNET_PeerIdentity dummy;
155
156 if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname))
157 {
158 LOG (GNUNET_ERROR_TYPE_ERROR,
159 "File not found: `%s'\n",
160 cfgname);
161 return NULL;
162 }
163
164 if (NULL != handlers)
165 {
166 for (i = 0; NULL != handlers[i].cb; i++)
167 ;
168 sps->handlers = GNUNET_new_array (i + 1,
169 struct GNUNET_MQ_MessageHandler);
170 GNUNET_memcpy (sps->handlers,
171 handlers,
172 i * sizeof(struct GNUNET_MQ_MessageHandler));
173 }
174 sps->cfg = GNUNET_CONFIGURATION_create ();
175 GNUNET_assert (GNUNET_OK ==
176 GNUNET_CONFIGURATION_load (sps->cfg, sps->cfgname));
177 if (GNUNET_SYSERR ==
178 GNUNET_TESTING_configuration_create (tl_system,
179 sps->cfg))
180 {
181 LOG (GNUNET_ERROR_TYPE_ERROR,
182 "Testing library failed to create unique configuration based on `%s'\n",
183 sps->cfgname);
184 GNUNET_CONFIGURATION_destroy (sps->cfg);
185 GNUNET_TESTING_interpreter_fail ();
186 }
187
188 sps->peer = GNUNET_TESTING_peer_configure (tth->tl_system,
189 p->cfg,
190 p->no,
191 NULL,
192 &emsg);
193 if (NULL == sps->peer)
194 {
195 LOG (GNUNET_ERROR_TYPE_ERROR,
196 "Testing library failed to create unique configuration based on `%s': `%s'\n",
197 cfgname,
198 emsg);
199 GNUNET_free (emsg);
200 GNUNET_TESTING_interpreter_fail ();
201 }
202
203 if (GNUNET_OK != GNUNET_TESTING_peer_start (p->peer))
204 {
205 LOG (GNUNET_ERROR_TYPE_ERROR,
206 "Testing library failed to create unique configuration based on `%s'\n",
207 cfgname);
208 GNUNET_free (emsg);
209 GNUNET_TESTING_interpreter_fail ();
210 }
211
212 memset (&dummy,
213 '\0',
214 sizeof(dummy));
215 GNUNET_TESTING_peer_get_identity (sps->peer,
216 &sps->id);
217 if (0 == memcmp (&dummy,
218 &sps->id,
219 sizeof(struct GNUNET_PeerIdentity)))
220 {
221 LOG (GNUNET_ERROR_TYPE_ERROR,
222 "Testing library failed to obtain peer identity for peer %s_%s\n",
223 p->no);
224 GNUNET_free (emsg);
225 GNUNET_TESTING_interpreter_fail ();
226 }
227 LOG (GNUNET_ERROR_TYPE_DEBUG,
228 "Peer %u configured with identity `%s'\n",
229 p->no,
230 GNUNET_i2s_full (&p->id));
231 sps->th = GNUNET_TRANSPORT_core_connect (p->cfg,
232 NULL,
233 handlers,
234 p,
235 &notify_connect,
236 &notify_disconnect);
237 if (NULL == sps->th)
238 {
239 LOG (GNUNET_ERROR_TYPE_ERROR,
240 "Failed to connect to transport service for peer `%s': `%s'\n",
241 cfgname,
242 emsg);
243 GNUNET_free (emsg);
244 GNUNET_TESTING_interpreter_fail ();
245 }
246 sps->ph = GNUNET_PEERSTORE_connect (p->cfg);
247 if (NULL == sps->th)
248 {
249 LOG (GNUNET_ERROR_TYPE_ERROR,
250 "Failed to connect to peerstore service for peer `%s': `%s'\n",
251 cfgname,
252 emsg);
253 GNUNET_free (emsg);
254 GNUNET_TESTING_interpreter_fail ();
255 }
256 sps->ah = GNUNET_TRANSPORT_application_init (p->cfg);
257 if (NULL == sps->ah)
258 {
259 LOG (GNUNET_ERROR_TYPE_ERROR,
260 "Failed to initialize the TRANSPORT application suggestion client handle for peer `%s': `%s'\n",
261 cfgname,
262 emsg);
263 GNUNET_free (emsg);
264 GNUNET_TESTING_interpreter_fail ();
265 }
266 p->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, p);
267}
268
269
270/**
271 * Create command.
272 *
273 * @param label name for command.
274 * @return command.
275 */
276struct GNUNET_TESTING_Command
277GNUNET_TESTING_cmd_start_peer (const char *label,
278 char *m,
279 char *n)
280{
281 struct StartPeerState *sps;
282
283 sps = GNUNET_new (struct StartPeerState);
284 sps->m = m;
285 sps->n = n;
286
287 struct GNUNET_TESTING_Command cmd = {
288 .cls = sps,
289 .label = label,
290 .run = &start_peer_run,
291 .cleanup = &start_peer_cleanup,
292 .traits = &start_peer_traits
293 };
294
295 return cmd;
296}
diff --git a/src/testing/testing_api_cmd_system_create.c b/src/testing/testing_api_cmd_system_create.c
index ad0aa4f90..a324940bb 100644
--- a/src/testing/testing_api_cmd_system_create.c
+++ b/src/testing/testing_api_cmd_system_create.c
@@ -26,10 +26,13 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h" 28#include "gnunet_testing_ng_lib.h"
29#include "gnunet_testing_lib.h"
29 30
30struct TestSystemState 31struct TestSystemState
31{ 32{
32 struct GNUNET_TESTING_System *test_system; 33 struct GNUNET_TESTING_System *test_system;
34
35 const char *testdir;
33}; 36};
34 37
35 38
@@ -83,6 +86,17 @@ GNUNET_TESTING_get_trait_test_system (const struct
83} 86}
84 87
85 88
89static void
90system_create_cleanup (void *cls,
91 const struct GNUNET_TESTING_Command *cmd)
92{
93 struct TestSystemState *tss = cls;
94
95 GNUNET_free (tss->test_system);
96 GNUNET_free (tss);
97}
98
99
86/** 100/**
87 * Create command. 101 * Create command.
88 * 102 *
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index bc3004a70..9f680ad3b 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -167,6 +167,9 @@ libgnunettransporttesting_la_LDFLAGS = \
167 $(GN_LIB_LDFLAGS) 167 $(GN_LIB_LDFLAGS)
168 168
169libgnunettransporttesting2_la_SOURCES = \ 169libgnunettransporttesting2_la_SOURCES = \
170 transport_api_cmd_connecting_peers.c \
171 transport_api_cmd_start_peer.c \
172 transport_api_cmd_send_simple.c \
170 transport-testing2.c transport-testing2.h \ 173 transport-testing2.c transport-testing2.h \
171 transport-testing-filenames2.c \ 174 transport-testing-filenames2.c \
172 transport-testing-loggers2.c \ 175 transport-testing-loggers2.c \
@@ -394,7 +397,19 @@ plugin_LTLIBRARIES = \
394 $(HTTP_SERVER_PLUGIN_LA) \ 397 $(HTTP_SERVER_PLUGIN_LA) \
395 $(HTTPS_SERVER_PLUGIN_LA) \ 398 $(HTTPS_SERVER_PLUGIN_LA) \
396 $(WLAN_PLUGIN_LA) \ 399 $(WLAN_PLUGIN_LA) \
397 $(BT_PLUGIN_LA) 400 $(BT_PLUGIN_LA)
401 # libgnunet_plugin_simple_send.la
402
403# libgnunet_plugin_cmd_simple_send_la_SOURCES = \
404# plugin_cmd_simple_send.c
405# libgnunet_plugin_cmd_simple_send_la_LIBADD = \
406# $(top_builddir)/src/util/libgnunetutil.la \
407# $(top_builddir)/src/testing/libgnunettesting.la \
408# $(top_builddir)/src/statistics/libgnunetstatistics.la \
409# $(top_builddir)/src/testbed/libgnunettestbed.la \
410# $(LTLIBINTL)
411# libgnunet_plugin_cmd_simple_send_la_LDFLAGS = \
412# $(GN_PLUGIN_LDFLAGS)
398 413
399if HAVE_EXPERIMENTAL 414if HAVE_EXPERIMENTAL
400plugin_LTLIBRARIES += libgnunet_plugin_transport_udp.la 415plugin_LTLIBRARIES += libgnunet_plugin_transport_udp.la
@@ -541,6 +556,7 @@ libgnunet_plugin_transport_https_server_la_CFLAGS = \
541 556
542if HAVE_TESTING 557if HAVE_TESTING
543check_PROGRAMS = \ 558check_PROGRAMS = \
559 test_transport_api_cmd_simple_send \
544 test_transport_address_switch_tcp \ 560 test_transport_address_switch_tcp \
545 test_transport_testing_startstop \ 561 test_transport_testing_startstop \
546 test_transport_testing_restart \ 562 test_transport_testing_restart \
@@ -629,6 +645,7 @@ endif
629if ENABLE_TEST_RUN 645if ENABLE_TEST_RUN
630AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; 646AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME;
631TESTS = \ 647TESTS = \
648 test_transport_api_cmd_simple_send \
632 test_transport_address_switch_tcp \ 649 test_transport_address_switch_tcp \
633 $(HTTP_SWITCH) \ 650 $(HTTP_SWITCH) \
634 $(HTTPS_SWITCH) \ 651 $(HTTPS_SWITCH) \
@@ -705,6 +722,16 @@ TESTS += \
705endif 722endif
706endif 723endif
707 724
725test_transport_api_cmd_simple_send_SOURCES = \
726 test_transport_api_cmd_simple_send.c
727test_transport_api_cmd_simple_send_LDADD = \
728 $(top_builddir)/src/testing/libgnunettesting.la \
729 $(top_builddir)/src/util/libgnunetutil.la \
730 $(top_builddir)/src/testbed/libgnunettestbed.la \
731 libgnunettransport.la \
732 $(top_builddir)/src/hello/libgnunethello.la \
733 libgnunettransporttesting.la
734
708test_transport_testing_startstop_SOURCES = \ 735test_transport_testing_startstop_SOURCES = \
709 test_transport_testing_startstop.c 736 test_transport_testing_startstop.c
710test_transport_testing_startstop_LDADD = \ 737test_transport_testing_startstop_LDADD = \
diff --git a/src/transport/plugin_cmd_simple_send.c b/src/transport/plugin_cmd_simple_send.c
new file mode 100644
index 000000000..ed3481c00
--- /dev/null
+++ b/src/transport/plugin_cmd_simple_send.c
@@ -0,0 +1,122 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2013, 2014 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 testbed/plugin_testcmd.c
23 * @brief a plugin to provide the API for running test cases.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_testbed_ng_service.h"
30
31/**
32 * Generic logging shortcut
33 */
34#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
35
36#define BASE_DIR "testdir"
37
38
39static void
40start_testcase (TESTBED_CMD_HELPER_write_cb write_message, char *router_ip,
41 char *node_ip,
42 char *m,
43 char *n)
44{
45 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
46 char *testdir;
47
48 testdir = GNUNET_malloc (strlen (basedir) + strlen (m) + strlen (n)
49 + 1);
50
51 strcpy (testdir, BASE_DIR);
52 strcat (testdir, m);
53 strcat (testdir, n);
54
55 struct GNUNET_TESTING_Command commands[] = {
56 GNUNET_TESTING_cmd_system_create ("system-create-1",
57 testdir),
58 GNUNET_TESTING_cmd_start_peer ("start-peer-1",
59 "system-create-1",
60 m,
61 n,
62 struct GNUNET_MQ_MessageHandler *handlers,
63 const char *cfgname),
64 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready-1",
65 write_message),
66 GNUNET_TESTING_cmd_block_until_all_peers_started ("block-1",
67 &are_all_peers_started),
68 GNUNET_TESTING_cmd_connect_peers ("connect-peers-1",
69 "start-peer-1",
70 "this is useless"),
71 /*GNUNET_TESTING_cmd_send_simple ("send-simple-1",
72 char *m,
73 char *n,
74 uint32_t num,
75 const char *peer1_label,
76 const char *peer2_label),*/
77 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished-1",
78 write_message)
79 };
80
81 GNUNET_TESTING_run (NULL,
82 commands,
83 GNUNET_TIME_UNIT_FOREVER_REL);
84
85}
86
87
88/**
89 * Entry point for the plugin.
90 *
91 * @param cls NULL
92 * @return the exported block API
93 */
94void *
95libgnunet_plugin_testcmd_init (void *cls)
96{
97 struct GNUNET_TESTING_PluginFunctions *api;
98
99 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
100 api->start_testcase = &start_testcase;
101 api->all_peers_started = &all_peers_started;
102 return api;
103}
104
105
106/**
107 * Exit point from the plugin.
108 *
109 * @param cls the return value from #libgnunet_plugin_block_test_init
110 * @return NULL
111 */
112void *
113libgnunet_plugin_testcmd_done (void *cls)
114{
115 struct GNUNET_TESTING_PluginFunctions *api = cls;
116
117 GNUNET_free (api);
118 return NULL;
119}
120
121
122/* end of plugin_testcmd.c */
diff --git a/src/transport/test_transport_api_cmd_simple_send.c b/src/transport/test_transport_api_cmd_simple_send.c
new file mode 100644
index 000000000..36c7d23b2
--- /dev/null
+++ b/src/transport/test_transport_api_cmd_simple_send.c
@@ -0,0 +1,80 @@
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 transport/test_transport_api_cmd_simple_send.c
23 * @brief Test case executing a script which sends a test message between two peers.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_testbed_ng_service.h"
29#include "gnunet_util_lib.h"
30
31
32/**
33 * Main function to run the test cases.
34 *
35 * @param cls not used.
36 *
37 */
38static void
39run (void *cls)
40{
41 struct GNUNET_TESTING_Command commands[] = {
42 GNUNET_TESTBED_cmd_netjail_start ("netjail-start-1",
43 "2",
44 "2"),
45 GNUNET_TESTBED_cmd_netjail_start_testbed ("netjail-start-testbed-1",
46 "2",
47 "2",
48 "libgnunet_plugin_cmd_simple_send"),
49 GNUNET_TESTBED_cmd_stop_testbed ("stop-testbed",
50 "netjail-start-testbed-1",
51 "2",
52 "2"),
53 GNUNET_TESTBED_cmd_netjail_stop ("netjail-stop-1",
54 "2",
55 "2"),
56 GNUNET_TESTING_cmd_end ()
57 };
58
59 GNUNET_TESTING_run (NULL,
60 commands,
61 GNUNET_TIME_UNIT_FOREVER_REL);
62}
63
64
65int
66main (int argc,
67 char *const *argv)
68{
69 int rv = 0;
70
71 GNUNET_log_setup ("test-netjail",
72 "DEBUG",
73 NULL);
74 GNUNET_SCHEDULER_run (&run,
75 NULL);
76
77 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
78 "Test finished!\n");
79 return rv;
80}
diff --git a/src/transport/transport_api_cmd_connecting_peers.c b/src/transport/transport_api_cmd_connecting_peers.c
new file mode 100644
index 000000000..297b90864
--- /dev/null
+++ b/src/transport/transport_api_cmd_connecting_peers.c
@@ -0,0 +1,178 @@
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_transport_application_service.h"
30#include "gnunet_hello_lib.h"
31
32/**
33 * Generic logging shortcut
34 */
35#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
36
37struct ConnectPeersState
38{
39 const char *peer1_label;
40
41 const char *peer2_label;
42};
43
44
45static void
46connect_peers_run (void *cls,
47 const struct GNUNET_TESTING_Command *cmd,
48 struct GNUNET_TESTING_Interpreter *is)
49{
50 struct ConnectPeersState *cps = cls;
51 const struct GNUNET_TESTING_Command *peer1_cmd;
52 const struct GNUNET_TESTING_Command *peer2_cmd;
53 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
54 struct GNUNET_PeerIdentity *id;
55 char *addr;
56 struct GNUNET_TIME_Absolute t;
57 char *hello;
58 size_t *hello_size;
59 enum GNUNET_NetworkType nt = 0;
60
61 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->peer1_label);
62 GNUNET_TESTING_get_trait_application_handle (peer1_cmd,
63 &ah);
64
65 GNUNET_TESTING_get_trait_hello (peer1_cmd,
66 &hello);
67
68 LOG (GNUNET_ERROR_TYPE_ERROR,
69 "hello: %s\n",
70 hello);
71
72 // TODO This does not work, because the other peer is running in another local loop. We need to message between different local loops. For now we will create the hello manually with the known information about the other local peers.
73 // ---------------------------------------------
74 /*peer2_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->peer2_label);
75 GNUNET_TESTING_get_trait_peer_id (peer2_cmd,
76 &id);
77 GNUNET_TESTING_get_trait_hello (peer2_cmd,
78 &hello);
79 GNUNET_TESTING_get_trait_hello_size (peer2_cmd,
80 &hello_size);
81
82 addr = GNUNET_HELLO_extract_address (hello,
83 *hello_size,
84 id,
85 &nt,
86 &t);
87
88 //----------------------------------------------
89
90 GNUNET_TRANSPORT_application_validate (ah,
91 id,
92 nt,
93 addr);*/
94}
95
96
97static int
98connect_peers_finish (void *cls,
99 GNUNET_SCHEDULER_TaskCallback cont,
100 void *cont_cls)
101{
102 /*struct ConnectPeersState *cps = cls;
103 const struct GNUNET_TESTING_Command *peer1_cmd;
104 const struct GNUNET_TESTING_Command *peer2_cmd;
105 struct GNUNET_CONTAINER_MultiPeerMap *connected_peers_map;
106 unsigned int ret;
107 struct GNUNET_PeerIdentity *id;
108
109 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->peer1_label);
110 GNUNET_TESTING_get_trait_peer_id (peer1_cmd,
111 &id);
112
113 peer2_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->peer2_label);
114 GNUNET_TESTING_get_trait_connected_peers_map (peer2_cmd,
115 &connected_peers_map);
116
117 ret = GNUNET_CONTAINER_multipeermap_contains (connected_peers_map,
118 id);
119
120 if (GNUNET_YES == ret)
121 {
122 cont (cont_cls);
123 }
124
125 return ret;*/
126 return GNUNET_OK;
127}
128
129
130static int
131connect_peers_traits (void *cls,
132 const void **ret,
133 const char *trait,
134 unsigned int index)
135{
136 return GNUNET_OK;
137}
138
139
140static void
141connect_peers_cleanup (void *cls,
142 const struct GNUNET_TESTING_Command *cmd)
143{
144 struct ConnectPeersState *cps = cls;
145
146 GNUNET_free (cps);
147}
148
149
150/**
151 * Create command.
152 *
153 * @param label name for command.
154 * @return command.
155 */
156struct GNUNET_TESTING_Command
157GNUNET_TESTING_cmd_connect_peers (const char *label,
158 const char *peer1_label,
159 const char *peer2_label)
160{
161 struct ConnectPeersState *cps;
162
163 cps = GNUNET_new (struct ConnectPeersState);
164 cps->peer1_label = peer1_label;
165 cps->peer2_label = peer2_label;
166
167
168 struct GNUNET_TESTING_Command cmd = {
169 .cls = cps,
170 .label = label,
171 .run = &connect_peers_run,
172 .finish = &connect_peers_finish,
173 .cleanup = &connect_peers_cleanup,
174 .traits = &connect_peers_traits
175 };
176
177 return cmd;
178}
diff --git a/src/transport/transport_api_cmd_send_simple.c b/src/transport/transport_api_cmd_send_simple.c
new file mode 100644
index 000000000..e4ac199d1
--- /dev/null
+++ b/src/transport/transport_api_cmd_send_simple.c
@@ -0,0 +1,136 @@
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-testing.h"
30
31struct SendSimpleState
32{
33 char *m;
34
35 char *n;
36
37 uint32_t num;
38
39 const char *peer1_label;
40
41 const char *peer2_label;
42};
43
44static int
45send_simple_traits (void *cls,
46 const void **ret,
47 const char *trait,
48 unsigned int index)
49{
50 return GNUNET_OK;
51}
52
53
54static void
55send_simple_cleanup (void *cls,
56 const struct GNUNET_TESTING_Command *cmd)
57{
58 struct SendSimpleState *sss = cls;
59
60 GNUNET_free (sss);
61}
62
63
64static void
65send_simple_run (void *cls,
66 const struct GNUNET_TESTING_Command *cmd,
67 struct GNUNET_TESTING_Interpreter *is)
68{
69 struct SendSimpleState *sss = cls;
70 struct GNUNET_MQ_Envelope *env;
71 struct GNUNET_TRANSPORT_TESTING_TestMessage *test;
72 struct GNUNET_MQ_Handle *mq;
73 struct GNUNET_CONTAINER_MultiPeerMap *connected_peers_map;
74 struct GNUNET_PeerIdentity *id;
75 const struct GNUNET_TESTING_Command *peer1_cmd;
76 const struct GNUNET_TESTING_Command *peer2_cmd;
77
78 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->peer1_label);
79 GNUNET_TESTING_get_trait_connected_peers_map (peer1_cmd,
80 &connected_peers_map);
81
82 peer2_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->peer2_label);
83 GNUNET_TESTING_get_trait_peer_id (peer2_cmd,
84 &id);
85
86 mq = GNUNET_CONTAINER_multipeermap_get (connected_peers_map,
87 id);
88
89 env = GNUNET_MQ_msg_extra (test,
90 2600 - sizeof(*test),
91 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE);
92 test->num = htonl (sss->num);
93 memset (&test[1],
94 sss->num,
95 2600 - sizeof(*test));
96 /*GNUNET_MQ_notify_sent (env,
97 cont,
98 cont_cls);*/
99 GNUNET_MQ_send (mq,
100 env);
101
102
103}
104
105
106/**
107 * Create command.
108 *
109 * @param label name for command.
110 * @return command.
111 */
112struct GNUNET_TESTING_Command
113GNUNET_TESTING_cmd_send_simple (const char *label,
114 char *m,
115 char *n,
116 uint32_t num,
117 const char *peer1_label,
118 const char *peer2_label)
119{
120 struct SendSimpleState *sss;
121
122 sss = GNUNET_new (struct SendSimpleState);
123 sss->m = m;
124 sss->n = n;
125 sss->num = num;
126
127 struct GNUNET_TESTING_Command cmd = {
128 .cls = sss,
129 .label = label,
130 .run = &send_simple_run,
131 .cleanup = &send_simple_cleanup,
132 .traits = &send_simple_traits
133 };
134
135 return cmd;
136}
diff --git a/src/transport/transport_api_cmd_start_peer.c b/src/transport/transport_api_cmd_start_peer.c
new file mode 100644
index 000000000..4077b7561
--- /dev/null
+++ b/src/transport/transport_api_cmd_start_peer.c
@@ -0,0 +1,558 @@
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_peerstore_service.h"
30#include "gnunet_transport_core_service.h"
31
32/**
33 * Generic logging shortcut
34 */
35#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
36
37struct StartPeerState
38{
39 /**
40 * Receive callback
41 */
42 struct GNUNET_MQ_MessageHandler *handlers;
43
44 const char *cfgname;
45
46 /**
47 * Peer's configuration
48 */
49 struct GNUNET_CONFIGURATION_Handle *cfg;
50
51 struct GNUNET_TESTING_Peer *peer;
52
53 /**
54 * Peer identity
55 */
56 struct GNUNET_PeerIdentity *id;
57
58 /**
59 * Peer's transport service handle
60 */
61 struct GNUNET_TRANSPORT_CoreHandle *th;
62
63 /**
64 * Application handle
65 */
66 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
67
68 /**
69 * Peer's PEERSTORE Handle
70 */
71 struct GNUNET_PEERSTORE_Handle *ph;
72
73 /**
74 * Hello get task
75 */
76 struct GNUNET_SCHEDULER_Task *rh_task;
77
78 /**
79 * Peer's transport get hello handle to retrieve peer's HELLO message
80 */
81 struct GNUNET_PEERSTORE_IterateContext *pic;
82
83 /**
84 * Hello
85 */
86 char *hello;
87
88 /**
89 * Hello size
90 */
91 size_t hello_size;
92
93 char *m;
94
95 char *n;
96
97 unsigned int finished;
98
99 const char *system_label;
100
101 /**
102 * An unique number to identify the peer
103 */
104 unsigned int no;
105
106 struct GNUNET_CONTAINER_MultiPeerMap *connected_peers_map;
107
108 struct GNUNET_TESTING_System *tl_system;
109
110};
111
112
113static void
114retrieve_hello (void *cls);
115
116static void
117hello_iter_cb (void *cb_cls,
118 const struct GNUNET_PEERSTORE_Record *record,
119 const char *emsg)
120{
121 struct StartPeerState *sps = cb_cls;
122 if (NULL == record)
123 {
124 sps->pic = NULL;
125 sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps);
126 return;
127 }
128 // Check record type et al?
129 sps->hello_size = record->value_size;
130 sps->hello = GNUNET_malloc (sps->hello_size);
131 memcpy (sps->hello, record->value, sps->hello_size);
132 sps->hello[sps->hello_size - 1] = '\0';
133
134 GNUNET_PEERSTORE_iterate_cancel (sps->pic);
135 sps->pic = NULL;
136 sps->finished = GNUNET_YES;
137}
138
139
140static void
141retrieve_hello (void *cls)
142{
143 struct StartPeerState *sps = cls;
144 sps->rh_task = NULL;
145 sps->pic = GNUNET_PEERSTORE_iterate (sps->ph,
146 "transport",
147 sps->id,
148 GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY,
149 hello_iter_cb,
150 sps);
151
152}
153
154static int
155start_peer_finish (void *cls,
156 GNUNET_SCHEDULER_TaskCallback cont,
157 void *cont_cls)
158{
159 struct StartPeerState *sps = cls;
160
161 if (GNUNET_YES == sps->finished)
162 {
163 cont (cont_cls);
164 }
165
166 return sps->finished;
167}
168
169
170static void
171notify_disconnect (void *cls,
172 const struct GNUNET_PeerIdentity *peer,
173 void *handler_cls)
174{
175 struct StartPeerState *sps = cls;
176
177 LOG (GNUNET_ERROR_TYPE_DEBUG,
178 "Peer %s disconnected from peer %u (`%s')\n",
179 GNUNET_i2s (peer),
180 sps->no,
181 GNUNET_i2s (sps->id));
182
183}
184
185
186static void *
187notify_connect (void *cls,
188 const struct GNUNET_PeerIdentity *peer,
189 struct GNUNET_MQ_Handle *mq)
190{
191 struct StartPeerState *sps = cls;
192
193
194 void *ret;
195
196
197 LOG (GNUNET_ERROR_TYPE_DEBUG,
198 "Peer %s connected to peer %u (`%s')\n",
199 GNUNET_i2s (peer),
200 sps->no,
201 GNUNET_i2s (sps->id));
202
203 GNUNET_CONTAINER_multipeermap_put (sps->connected_peers_map,
204 peer,
205 mq,
206 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
207
208 // TODO what does the handler function need?
209 return ret;
210}
211
212
213static void
214start_peer_run (void *cls,
215 const struct GNUNET_TESTING_Command *cmd,
216 struct GNUNET_TESTING_Interpreter *is)
217{
218 struct StartPeerState *sps = cls;
219 char *emsg = NULL;
220 struct GNUNET_PeerIdentity dummy;
221 const struct GNUNET_TESTING_Command *system_cmd;
222 struct GNUNET_TESTING_System *tl_system;
223
224 if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname))
225 {
226 LOG (GNUNET_ERROR_TYPE_ERROR,
227 "File not found: `%s'\n",
228 sps->cfgname);
229 GNUNET_TESTING_interpreter_fail ();
230 return;
231 }
232
233
234 sps->cfg = GNUNET_CONFIGURATION_create ();
235 GNUNET_assert (GNUNET_OK ==
236 GNUNET_CONFIGURATION_load (sps->cfg, sps->cfgname));
237
238 system_cmd = GNUNET_TESTING_interpreter_lookup_command (sps->system_label);
239 GNUNET_TESTING_get_trait_test_system (system_cmd,
240 &tl_system);
241
242 sps->tl_system = tl_system;
243
244 if (GNUNET_SYSERR ==
245 GNUNET_TESTING_configuration_create (tl_system,
246 sps->cfg))
247 {
248 LOG (GNUNET_ERROR_TYPE_ERROR,
249 "Testing library failed to create unique configuration based on `%s'\n",
250 sps->cfgname);
251 GNUNET_CONFIGURATION_destroy (sps->cfg);
252 GNUNET_TESTING_interpreter_fail ();
253 }
254
255 sps->peer = GNUNET_TESTING_peer_configure (sps->tl_system,
256 sps->cfg,
257 sps->no,
258 NULL,
259 &emsg);
260 if (NULL == sps->peer)
261 {
262 LOG (GNUNET_ERROR_TYPE_ERROR,
263 "Testing library failed to create unique configuration based on `%s': `%s'\n",
264 sps->cfgname,
265 emsg);
266 GNUNET_free (emsg);
267 GNUNET_TESTING_interpreter_fail ();
268 }
269
270 if (GNUNET_OK != GNUNET_TESTING_peer_start (sps->peer))
271 {
272 LOG (GNUNET_ERROR_TYPE_ERROR,
273 "Testing library failed to create unique configuration based on `%s'\n",
274 sps->cfgname);
275 GNUNET_free (emsg);
276 GNUNET_TESTING_interpreter_fail ();
277 }
278
279 memset (&dummy,
280 '\0',
281 sizeof(dummy));
282 GNUNET_TESTING_peer_get_identity (sps->peer,
283 sps->id);
284 if (0 == memcmp (&dummy,
285 &sps->id,
286 sizeof(struct GNUNET_PeerIdentity)))
287 {
288 LOG (GNUNET_ERROR_TYPE_ERROR,
289 "Testing library failed to obtain peer identity for peer %u\n",
290 sps->no);
291 GNUNET_free (emsg);
292 GNUNET_TESTING_interpreter_fail ();
293 }
294 LOG (GNUNET_ERROR_TYPE_DEBUG,
295 "Peer %u configured with identity `%s'\n",
296 sps->no,
297 GNUNET_i2s_full (sps->id));
298 sps->th = GNUNET_TRANSPORT_core_connect (sps->cfg,
299 NULL,
300 sps->handlers,
301 sps,
302 &notify_connect,
303 &notify_disconnect);
304 if (NULL == sps->th)
305 {
306 LOG (GNUNET_ERROR_TYPE_ERROR,
307 "Failed to connect to transport service for peer `%s': `%s'\n",
308 sps->cfgname,
309 emsg);
310 GNUNET_free (emsg);
311 GNUNET_TESTING_interpreter_fail ();
312 }
313 sps->ph = GNUNET_PEERSTORE_connect (sps->cfg);
314 if (NULL == sps->th)
315 {
316 LOG (GNUNET_ERROR_TYPE_ERROR,
317 "Failed to connect to peerstore service for peer `%s': `%s'\n",
318 sps->cfgname,
319 emsg);
320 GNUNET_free (emsg);
321 GNUNET_TESTING_interpreter_fail ();
322 }
323 sps->ah = GNUNET_TRANSPORT_application_init (sps->cfg);
324 if (NULL == sps->ah)
325 {
326 LOG (GNUNET_ERROR_TYPE_ERROR,
327 "Failed to initialize the TRANSPORT application suggestion client handle for peer `%s': `%s'\n",
328 sps->cfgname,
329 emsg);
330 GNUNET_free (emsg);
331 GNUNET_TESTING_interpreter_fail ();
332 }
333 sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps);
334}
335
336
337static void
338start_peer_cleanup (void *cls,
339 const struct GNUNET_TESTING_Command *cmd)
340{
341 struct StartPeerState *sps = cls;
342
343 if (NULL != sps->rh_task)
344 GNUNET_SCHEDULER_cancel (sps->rh_task);
345 sps->rh_task = NULL;
346 if (NULL != sps->ah)
347 {
348 GNUNET_TRANSPORT_application_done (sps->ah);
349 sps->ah = NULL;
350 }
351 if (NULL != sps->ph)
352 {
353 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
354 "Disconnecting from PEERSTORE service\n");
355 GNUNET_PEERSTORE_disconnect (sps->ph, GNUNET_NO);
356 sps->ph = NULL;
357 }
358 if (NULL != sps->handlers)
359 {
360 GNUNET_free (sps->handlers);
361 sps->handlers = NULL;
362 }
363 if (NULL != sps->cfg)
364 {
365 GNUNET_CONFIGURATION_destroy (sps->cfg);
366 sps->cfg = NULL;
367 }
368 if (NULL != sps->peer)
369 {
370 if (GNUNET_OK !=
371 GNUNET_TESTING_peer_stop (sps->peer))
372 {
373 LOG (GNUNET_ERROR_TYPE_DEBUG,
374 "Testing lib failed to stop peer %u (`%s')\n",
375 sps->no,
376 GNUNET_i2s (sps->id));
377 }
378 GNUNET_TESTING_peer_destroy (sps->peer);
379 sps->peer = NULL;
380 }
381 if (NULL != sps->th)
382 {
383 GNUNET_TRANSPORT_core_disconnect (sps->th);
384 sps->th = NULL;
385 }
386 if (NULL != sps->tl_system)
387 {
388 GNUNET_free (sps->tl_system);
389 }
390 GNUNET_free (sps->hello);
391 GNUNET_free (sps->connected_peers_map);
392 GNUNET_free (sps);
393}
394
395
396static int
397start_peer_traits (void *cls,
398 const void **ret,
399 const char *trait,
400 unsigned int index)
401{
402 struct StartPeerState *sps = cls;
403 struct GNUNET_TRANSPORT_ApplicationHandle *ah = sps->ah;
404 struct GNUNET_PeerIdentity *id = sps->id;
405 struct GNUNET_CONTAINER_MultiPeerMap *connected_peers_map =
406 sps->connected_peers_map;
407 char *hello = sps->hello;
408 size_t hello_size = sps->hello_size;
409
410
411 struct GNUNET_TESTING_Trait traits[] = {
412 {
413 .index = 0,
414 .trait_name = "application_handle",
415 .ptr = (const void *) ah,
416 },
417 {
418 .index = 1,
419 .trait_name = "peer_id",
420 .ptr = (const void *) id,
421 },
422 {
423 .index = 2,
424 .trait_name = "connected_peers_map",
425 .ptr = (const void *) connected_peers_map,
426 },
427 {
428 .index = 3,
429 .trait_name = "hello",
430 .ptr = (const void *) hello,
431 },
432 {
433 .index = 4,
434 .trait_name = "hello_size",
435 .ptr = (const void *) hello_size,
436 },
437 GNUNET_TESTING_trait_end ()
438 };
439
440 return GNUNET_TESTING_get_trait (traits,
441 ret,
442 trait,
443 index);
444}
445
446int
447GNUNET_TESTING_get_trait_hello_size (const struct
448 GNUNET_TESTING_Command
449 *cmd,
450 size_t **hello_size)
451{
452 return cmd->traits (cmd->cls,
453 (const void **) hello_size,
454 "hello_size",
455 (unsigned int) 4);
456}
457
458int
459GNUNET_TESTING_get_trait_hello (const struct
460 GNUNET_TESTING_Command
461 *cmd,
462 char **hello)
463{
464 return cmd->traits (cmd->cls,
465 (const void **) hello,
466 "hello",
467 (unsigned int) 3);
468}
469
470int
471GNUNET_TESTING_get_trait_connected_peers_map (const struct
472 GNUNET_TESTING_Command
473 *cmd,
474 struct
475 GNUNET_CONTAINER_MultiPeerMap **
476 connected_peers_map)
477{
478 return cmd->traits (cmd->cls,
479 (const void **) connected_peers_map,
480 "connected_peers_map",
481 (unsigned int) 2);
482}
483
484
485int
486GNUNET_TESTING_get_trait_application_handle (const struct
487 GNUNET_TESTING_Command *cmd,
488 struct
489 GNUNET_TRANSPORT_ApplicationHandle
490 **ah)
491{
492 return cmd->traits (cmd->cls,
493 (const void **) ah,
494 "application_handle",
495 (unsigned int) 0);
496}
497
498
499int
500GNUNET_TESTING_get_trait_peer_id (const struct
501 GNUNET_TESTING_Command *cmd,
502 struct GNUNET_PeerIdentity **id)
503{
504 return cmd->traits (cmd->cls,
505 (const void **) id,
506 "peer_id",
507 (unsigned int) 1);
508}
509
510
511/**
512 * Create command.
513 *
514 * @param label name for command.
515 * @return command.
516 */
517struct GNUNET_TESTING_Command
518GNUNET_TESTING_cmd_start_peer (const char *label,
519 const char *system_label,
520 char *m,
521 char *n,
522 struct GNUNET_MQ_MessageHandler *handlers,
523 const char *cfgname)
524{
525 struct StartPeerState *sps;
526 struct GNUNET_CONTAINER_MultiPeerMap *connected_peers_map =
527 GNUNET_CONTAINER_multipeermap_create (1,GNUNET_NO);
528 unsigned int i;
529
530 sps = GNUNET_new (struct StartPeerState);
531 sps->m = m;
532 sps->n = n;
533 sps->system_label = system_label;
534 sps->connected_peers_map = connected_peers_map;
535 sps->cfgname = cfgname;
536
537 if (NULL != handlers)
538 {
539 for (i = 0; NULL != handlers[i].cb; i++)
540 ;
541 sps->handlers = GNUNET_new_array (i + 1,
542 struct GNUNET_MQ_MessageHandler);
543 GNUNET_memcpy (sps->handlers,
544 handlers,
545 i * sizeof(struct GNUNET_MQ_MessageHandler));
546 }
547
548 struct GNUNET_TESTING_Command cmd = {
549 .cls = sps,
550 .label = label,
551 .run = &start_peer_run,
552 .finish = &start_peer_finish,
553 .cleanup = &start_peer_cleanup,
554 .traits = &start_peer_traits
555 };
556
557 return cmd;
558}