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"
36 #include "gnunet_testing_lib-new.h"
39 #define GNUNET_TRANSPORT_TESTING_ConnectRequest void *
43 * Context for a single peer
48 * Callback when two peers are connected and both have called the connect callback
49 * to notify clients about a new peer
51 typedef void (*GNUNET_TRANSPORT_TESTING_start_cb) (struct PeerContext * p,
55 * Callback when two peers are connected and both have called the connect callback
56 * to notify clients about a new peer
58 typedef void (*GNUNET_TRANSPORT_TESTING_connect_cb) (struct PeerContext * p1,
59 struct PeerContext * p2,
64 * Definition for a transport testing handle
66 struct GNUNET_TRANSPORT_TESTING_handle;
69 * Context for a single peer
74 * Next element in the DLL
76 struct PeerContext *next;
79 * Previous element in the DLL
81 struct PeerContext *prev;
84 * Transport testing handle this peer belongs to
86 struct GNUNET_TRANSPORT_TESTING_handle *tth;
89 * Peer's configuration
91 struct GNUNET_CONFIGURATION_Handle *cfg;
94 * Peer's transport service handle
96 struct GNUNET_TRANSPORT_Handle *th;
99 * Peer's transport get hello handle to retrieve peer's HELLO message
101 struct GNUNET_TRANSPORT_GetHelloHandle *ghh;
104 * Peer's testing handle
106 struct GNUNET_TESTING_Peer *peer;
111 struct GNUNET_PeerIdentity id;
114 * Handle for the peer's ARM process
116 struct GNUNET_OS_Process *arm_proc;
121 GNUNET_TRANSPORT_ReceiveCallback rec;
124 * Notify connect callback
126 GNUNET_TRANSPORT_NotifyConnect nc;
129 * Notify disconnect callback
131 GNUNET_TRANSPORT_NotifyDisconnect nd;
134 * Startup completed callback
136 GNUNET_TRANSPORT_TESTING_start_cb start_cb;
139 * Peers HELLO Message
141 struct GNUNET_HELLO_Message *hello;
144 * Closure for the callbacks
149 * Peer's service home directory
159 * An unique number to identify the peer
165 struct ConnectingContext
167 struct ConnectingContext *next;
168 struct ConnectingContext *prev;
169 struct PeerContext *p1;
170 struct PeerContext *p2;
171 GNUNET_SCHEDULER_TaskIdentifier tct;
172 GNUNET_TRANSPORT_TESTING_connect_cb cb;
174 struct GNUNET_TRANSPORT_Handle *th_p1;
175 struct GNUNET_TRANSPORT_Handle *th_p2;
180 struct GNUNET_TRANSPORT_TESTING_handle
182 struct ConnectingContext *cc_head;
183 struct ConnectingContext *cc_tail;
189 struct PeerContext *p_head;
190 struct PeerContext *p_tail;
195 * Start a peer with the given configuration
196 * @param tth the testing handle
197 * @param cfgname configuration file
198 * @param peer_id the peer_id
199 * @param rec receive callback
200 * @param nc connect callback
201 * @param nd disconnect callback
202 * @param start_cb start callback
203 * @param cb_cls closure for callback
204 * @return the peer context
207 GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle
208 *tth, const char *cfgname, int peer_id,
209 GNUNET_TRANSPORT_ReceiveCallback rec,
210 GNUNET_TRANSPORT_NotifyConnect nc,
211 GNUNET_TRANSPORT_NotifyDisconnect nd,
212 GNUNET_TRANSPORT_TESTING_start_cb start_cb,
217 * shutdown the given peer
218 * @param tth the testing handle
223 GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth,
224 struct PeerContext *pc);
228 * Restart the given peer
229 * @param tth testing handle
231 * @param cfgname the cfg file used to restart
232 * @param restart_cb restart callback
233 * @param cb_cls callback closure
234 * @return GNUNET_OK in success otherwise GNUNET_SYSERR
237 GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_handle
238 *tth, struct PeerContext *p,
240 GNUNET_TRANSPORT_TESTING_start_cb
241 restart_cb, void *cb_cls);
244 * Connect the given peers and call the callback when both peers report the
245 * inbound connection. Remarks: start_peer's notify_connect callback can be called
248 * @param tth transport testing handle
251 * @param cb the callback to call when both peers notified that they are connected
252 * @param cls callback cls
253 * @return a connect request handle
255 GNUNET_TRANSPORT_TESTING_ConnectRequest
256 GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle *tth,
257 struct PeerContext *p1,
258 struct PeerContext *p2,
259 GNUNET_TRANSPORT_TESTING_connect_cb cb,
263 * Cancel the request to connect two peers
264 * Tou MUST cancel the request if you stop the peers before the peers connected succesfully
266 * @param ccr a connect request handle
269 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct
270 GNUNET_TRANSPORT_TESTING_handle
272 GNUNET_TRANSPORT_TESTING_ConnectRequest
276 * Clean up the transport testing
277 * @param tth transport testing handle
280 GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle *tth);
283 * Initialize the transport testing
284 * @return transport testing handle
286 struct GNUNET_TRANSPORT_TESTING_handle *
287 GNUNET_TRANSPORT_TESTING_init ();
290 * Some utility functions
294 * Extracts the test filename from an absolute file name and removes the extension
295 * @param file absolute file name
296 * @param dest where to store result
299 GNUNET_TRANSPORT_TESTING_get_test_name (const char *file, char **dest);
302 * This function takes the filename (e.g. argv[0), removes a "lt-"-prefix and
303 * if existing ".exe"-prefix and adds the peer-number
305 * @param file filename of the test, e.g. argv[0]
306 * @param dest where to write the filename
307 * @param count peer number
310 GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, char **dest,
315 * Extracts the plugin anme from an absolute file name and the test name
316 * @param file absolute file name
317 * @param test test name
318 * @param dest where to store result
321 GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *executable,
322 const char *testname,
327 * Extracts the filename from an absolute file name and removes the extenstion
328 * @param file absolute file name
329 * @param dest where to store result
332 GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file,
335 /* end of transport_testing.h */