2 This file is part of GNUnet.
3 (C) 2006, 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file transport-testing.h
23 * @brief testing lib for transport service
25 * @author Matthias Wachs
29 #include "gnunet_common.h"
30 #include "gnunet_getopt_lib.h"
31 #include "gnunet_hello_lib.h"
32 #include "gnunet_os_lib.h"
33 #include "gnunet_program_lib.h"
34 #include "gnunet_container_lib.h"
35 #include "gnunet_transport_service.h"
38 #define GNUNET_TRANSPORT_TESTING_ConnectRequest void *
42 * Context for a single peer
47 * Callback when two peers are connected and both have called the connect callback
48 * to notify clients about a new peer
50 typedef void (*GNUNET_TRANSPORT_TESTING_start_cb) (struct PeerContext * p,
54 * Callback when two peers are connected and both have called the connect callback
55 * to notify clients about a new peer
57 typedef void (*GNUNET_TRANSPORT_TESTING_connect_cb) (struct PeerContext * p1,
58 struct PeerContext * p2,
63 struct GNUNET_TRANSPORT_TESTING_handle;
66 * Context for a single peer
70 struct PeerContext *next;
71 struct PeerContext *prev;
73 struct GNUNET_TRANSPORT_TESTING_handle *tth;
75 struct GNUNET_CONFIGURATION_Handle *cfg;
77 struct GNUNET_TRANSPORT_Handle *th;
79 struct GNUNET_TRANSPORT_GetHelloHandle *ghh;
81 struct GNUNET_PeerIdentity id;
83 struct GNUNET_OS_Process *arm_proc;
85 GNUNET_TRANSPORT_ReceiveCallback rec;
87 GNUNET_TRANSPORT_NotifyConnect nc;
89 GNUNET_TRANSPORT_NotifyDisconnect nd;
91 GNUNET_TRANSPORT_TESTING_start_cb start_cb;
93 struct GNUNET_HELLO_Message *hello;
105 struct ConnectingContext
107 struct ConnectingContext *next;
108 struct ConnectingContext *prev;
109 struct PeerContext *p1;
110 struct PeerContext *p2;
111 GNUNET_SCHEDULER_TaskIdentifier tct;
112 GNUNET_TRANSPORT_TESTING_connect_cb cb;
114 struct GNUNET_TRANSPORT_Handle *th_p1;
115 struct GNUNET_TRANSPORT_Handle *th_p2;
120 struct GNUNET_TRANSPORT_TESTING_handle
122 struct ConnectingContext *cc_head;
123 struct ConnectingContext *cc_tail;
129 struct PeerContext *p_head;
130 struct PeerContext *p_tail;
136 * Start a peer with the given configuration
137 * @param rec receive callback
138 * @param nc connect callback
139 * @param nd disconnect callback
140 * @param cb_cls closure for callback
141 * if NULL passed the PeerContext * will be used!
142 * @return the peer context
145 GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle
146 *tth, const char *cfgname, int peer_id,
147 GNUNET_TRANSPORT_ReceiveCallback rec,
148 GNUNET_TRANSPORT_NotifyConnect nc,
149 GNUNET_TRANSPORT_NotifyDisconnect nd,
150 GNUNET_TRANSPORT_TESTING_start_cb start_cb,
155 * shutdown the given peer
160 GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth,
161 struct PeerContext *pc);
165 * Restart the given peer
166 * @param tth testing handle
168 * @param cfgname the cfg file used to restart
169 * @return GNUNET_OK in success otherwise GNUNET_SYSERR
172 GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_handle
173 *tth, struct PeerContext *p,
175 GNUNET_TRANSPORT_TESTING_start_cb
176 start_cb, void *cb_cls);
179 * Connect the given peers and call the callback when both peers report the
180 * inbound connection. Remarks: start_peer's notify_connect callback can be called
184 * @param cb the callback to call when both peers notified that they are connected
185 * @param cb_cls callback cls
186 * @return a connect request handle
188 GNUNET_TRANSPORT_TESTING_ConnectRequest
189 GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle
190 *tth, struct PeerContext *p1,
191 struct PeerContext *p2,
192 GNUNET_TRANSPORT_TESTING_connect_cb cb,
196 * Cancel the request to connect two peers
197 * Tou MUST cancel the request if you stop the peers before the peers connected succesfully
198 * @param cc a connect request handle
201 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct
202 GNUNET_TRANSPORT_TESTING_handle
206 * Clean up the transport testing
207 * @param tth transport testing handle
210 GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle *tth);
213 * Initialize the transport testing
214 * @return transport testing handle
216 struct GNUNET_TRANSPORT_TESTING_handle *
217 GNUNET_TRANSPORT_TESTING_init ();
220 * Some utility functions
224 * Extracts the test filename from an absolute file name and removes the extension
225 * @param file absolute file name
226 * @param dest where to store result
229 GNUNET_TRANSPORT_TESTING_get_test_name (const char *file, char **dest);
232 * This function takes the filename (e.g. argv[0), removes a "lt-"-prefix and
233 * if existing ".exe"-prefix and adds the peer-number
234 * @param file filename of the test, e.g. argv[0]
235 * @param cfgname where to write the result
236 * @param count peer number
239 GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, char **cfgname,
244 * Extracts the plugin anme from an absolute file name and the test name
245 * @param file absolute file name
246 * @param test test name
247 * @param dest where to store result
250 GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *executable,
251 const char *testname,
256 * Extracts the filename from an absolute file name and removes the extenstion
257 * @param file absolute file name
258 * @param dest where to store result
261 GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file,
264 /* end of transport_testing.h */