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_hello_lib.h"
31 #include "gnunet_program_lib.h"
32 #include "gnunet_container_lib.h"
33 #include "gnunet_transport_service.h"
34 #include "gnunet_testing_lib.h"
37 #define GNUNET_TRANSPORT_TESTING_ConnectRequest void *
41 * Context for a single peer
46 * Callback when two peers are connected and both have called the connect callback
47 * to notify clients about a new peer
49 typedef void (*GNUNET_TRANSPORT_TESTING_start_cb) (struct PeerContext * p,
53 * Callback when two peers are connected and both have called the connect callback
54 * to notify clients about a new peer
56 typedef void (*GNUNET_TRANSPORT_TESTING_connect_cb) (struct PeerContext * p1,
57 struct PeerContext * p2,
62 * Definition for a transport testing handle
64 struct GNUNET_TRANSPORT_TESTING_handle;
67 * Context for a single peer
72 * Next element in the DLL
74 struct PeerContext *next;
77 * Previous element in the DLL
79 struct PeerContext *prev;
82 * Transport testing handle this peer belongs to
84 struct GNUNET_TRANSPORT_TESTING_handle *tth;
87 * Peer's configuration
89 struct GNUNET_CONFIGURATION_Handle *cfg;
92 * Peer's transport service handle
94 struct GNUNET_TRANSPORT_Handle *th;
97 * Peer's transport get hello handle to retrieve peer's HELLO message
99 struct GNUNET_TRANSPORT_GetHelloHandle *ghh;
102 * Peer's testing handle
104 struct GNUNET_TESTING_Peer *peer;
109 struct GNUNET_PeerIdentity id;
112 * Handle for the peer's ARM process
114 struct GNUNET_OS_Process *arm_proc;
119 GNUNET_TRANSPORT_ReceiveCallback rec;
122 * Notify connect callback
124 GNUNET_TRANSPORT_NotifyConnect nc;
127 * Notify disconnect callback
129 GNUNET_TRANSPORT_NotifyDisconnect nd;
132 * Startup completed callback
134 GNUNET_TRANSPORT_TESTING_start_cb start_cb;
137 * Peers HELLO Message
139 struct GNUNET_HELLO_Message *hello;
142 * Closure for the callbacks
147 * An unique number to identify the peer
153 struct ConnectingContext
155 struct ConnectingContext *next;
156 struct ConnectingContext *prev;
157 struct PeerContext *p1;
158 struct PeerContext *p2;
159 GNUNET_SCHEDULER_TaskIdentifier tct;
160 GNUNET_TRANSPORT_TESTING_connect_cb cb;
162 struct GNUNET_TRANSPORT_Handle *th_p1;
163 struct GNUNET_TRANSPORT_Handle *th_p2;
168 struct GNUNET_TRANSPORT_TESTING_handle
171 * Testing library system handle
173 struct GNUNET_TESTING_System *tl_system;
176 * head DLL of connect contexts
178 struct ConnectingContext *cc_head;
181 * head DLL of connect contexts
183 struct ConnectingContext *cc_tail;
188 struct PeerContext *p_head;
193 struct PeerContext *p_tail;
198 * Start a peer with the given configuration
199 * @param tth the testing handle
200 * @param cfgname configuration file
201 * @param peer_id the peer_id
202 * @param rec receive callback
203 * @param nc connect callback
204 * @param nd disconnect callback
205 * @param start_cb start callback
206 * @param cb_cls closure for callback
207 * @return the peer context
210 GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle
211 *tth, const char *cfgname, int peer_id,
212 GNUNET_TRANSPORT_ReceiveCallback rec,
213 GNUNET_TRANSPORT_NotifyConnect nc,
214 GNUNET_TRANSPORT_NotifyDisconnect nd,
215 GNUNET_TRANSPORT_TESTING_start_cb start_cb,
220 * shutdown the given peer
221 * @param tth the testing handle
226 GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth,
227 struct PeerContext *pc);
231 * Restart the given peer
232 * @param tth testing handle
234 * @param cfgname the cfg file used to restart
235 * @param restart_cb restart callback
236 * @param cb_cls callback closure
237 * @return GNUNET_OK in success otherwise GNUNET_SYSERR
240 GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_handle
241 *tth, struct PeerContext *p,
243 GNUNET_TRANSPORT_TESTING_start_cb
244 restart_cb, void *cb_cls);
247 * Connect the given peers and call the callback when both peers report the
248 * inbound connection. Remarks: start_peer's notify_connect callback can be called
251 * @param tth transport testing handle
254 * @param cb the callback to call when both peers notified that they are connected
255 * @param cls callback cls
256 * @return a connect request handle
258 GNUNET_TRANSPORT_TESTING_ConnectRequest
259 GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle *tth,
260 struct PeerContext *p1,
261 struct PeerContext *p2,
262 GNUNET_TRANSPORT_TESTING_connect_cb cb,
266 * Cancel the request to connect two peers
267 * Tou MUST cancel the request if you stop the peers before the peers connected succesfully
269 * @param ccr a connect request handle
272 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct
273 GNUNET_TRANSPORT_TESTING_handle
275 GNUNET_TRANSPORT_TESTING_ConnectRequest
279 * Clean up the transport testing
280 * @param tth transport testing handle
283 GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle *tth);
286 * Initialize the transport testing
287 * @return transport testing handle
289 struct GNUNET_TRANSPORT_TESTING_handle *
290 GNUNET_TRANSPORT_TESTING_init ();
293 * Some utility functions
297 * Extracts the test filename from an absolute file name and removes the extension
298 * @param file absolute file name
299 * @param dest where to store result
302 GNUNET_TRANSPORT_TESTING_get_test_name (const char *file, char **dest);
305 * This function takes the filename (e.g. argv[0), removes a "lt-"-prefix and
306 * if existing ".exe"-prefix and adds the peer-number
308 * @param file filename of the test, e.g. argv[0]
309 * @param dest where to write the filename
310 * @param count peer number
313 GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, char **dest,
318 * Extracts the plugin anme from an absolute file name and the test name
319 * @param file absolute file name
320 * @param test test name
321 * @param dest where to store result
324 GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *executable,
325 const char *testname,
330 * Extracts the filename from an absolute file name and removes the extenstion
331 * @param file absolute file name
332 * @param dest where to store result
335 GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file,
338 /* end of transport_testing.h */