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 3, 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
28 #include "gnunet_util_lib.h"
29 #include "gnunet_hello_lib.h"
30 #include "gnunet_transport_service.h"
31 #include "gnunet_testing_lib.h"
34 #define GNUNET_TRANSPORT_TESTING_ConnectRequest void *
38 * Context for a single peer
43 * Callback when two peers are connected and both have called the connect callback
44 * to notify clients about a new peer
46 typedef void (*GNUNET_TRANSPORT_TESTING_start_cb) (struct PeerContext * p,
50 * Callback when two peers are connected and both have called the connect callback
51 * to notify clients about a new peer
53 typedef void (*GNUNET_TRANSPORT_TESTING_connect_cb) (struct PeerContext * p1,
54 struct PeerContext * p2,
59 * Definition for a transport testing handle
61 struct GNUNET_TRANSPORT_TESTING_handle;
64 * Context for a single peer
69 * Next element in the DLL
71 struct PeerContext *next;
74 * Previous element in the DLL
76 struct PeerContext *prev;
79 * Transport testing handle this peer belongs to
81 struct GNUNET_TRANSPORT_TESTING_handle *tth;
84 * Peer's configuration
86 struct GNUNET_CONFIGURATION_Handle *cfg;
89 * Peer's transport service handle
91 struct GNUNET_TRANSPORT_Handle *th;
94 * Peer's transport get hello handle to retrieve peer's HELLO message
96 struct GNUNET_TRANSPORT_GetHelloHandle *ghh;
99 * Peer's testing handle
101 struct GNUNET_TESTING_Peer *peer;
106 struct GNUNET_PeerIdentity id;
109 * Handle for the peer's ARM process
111 struct GNUNET_OS_Process *arm_proc;
116 GNUNET_TRANSPORT_ReceiveCallback rec;
119 * Notify connect callback
121 GNUNET_TRANSPORT_NotifyConnect nc;
124 * Notify disconnect callback
126 GNUNET_TRANSPORT_NotifyDisconnect nd;
129 * Startup completed callback
131 GNUNET_TRANSPORT_TESTING_start_cb start_cb;
134 * Peers HELLO Message
136 struct GNUNET_HELLO_Message *hello;
139 * Closure for the callbacks
144 * An unique number to identify the peer
150 struct ConnectingContext
152 struct ConnectingContext *next;
153 struct ConnectingContext *prev;
154 struct PeerContext *p1;
155 struct PeerContext *p2;
156 GNUNET_SCHEDULER_TaskIdentifier tct;
157 GNUNET_TRANSPORT_TESTING_connect_cb cb;
159 struct GNUNET_TRANSPORT_Handle *th_p1;
160 struct GNUNET_TRANSPORT_Handle *th_p2;
165 struct GNUNET_TRANSPORT_TESTING_handle
168 * Testing library system handle
170 struct GNUNET_TESTING_System *tl_system;
173 * head DLL of connect contexts
175 struct ConnectingContext *cc_head;
178 * head DLL of connect contexts
180 struct ConnectingContext *cc_tail;
185 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 */