2 This file is part of GNUnet.
3 Copyright (C) 2006, 2009, 2015 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, 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 struct GNUNET_TRANSPORT_TESTING_ConnectRequest;
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
47 (*GNUNET_TRANSPORT_TESTING_start_cb) (struct PeerContext *p,
51 * Callback when two peers are connected and both have called the connect callback
52 * to notify clients about a new peer
55 (*GNUNET_TRANSPORT_TESTING_connect_cb) (struct PeerContext *p1,
56 struct PeerContext *p2,
61 * Definition for a transport testing handle
63 struct GNUNET_TRANSPORT_TESTING_handle;
66 * Context for a single peer
71 * Next element in the DLL
73 struct PeerContext *next;
76 * Previous element in the DLL
78 struct PeerContext *prev;
81 * Transport testing handle this peer belongs to
83 struct GNUNET_TRANSPORT_TESTING_handle *tth;
86 * Peer's configuration
88 struct GNUNET_CONFIGURATION_Handle *cfg;
91 * Peer's transport service handle
93 struct GNUNET_TRANSPORT_Handle *th;
98 struct GNUNET_ATS_ConnectivityHandle *ats;
101 * Peer's transport get hello handle to retrieve peer's HELLO message
103 struct GNUNET_TRANSPORT_GetHelloHandle *ghh;
106 * Peer's testing handle
108 struct GNUNET_TESTING_Peer *peer;
113 struct GNUNET_PeerIdentity id;
116 * Handle for the peer's ARM process
118 struct GNUNET_OS_Process *arm_proc;
123 GNUNET_TRANSPORT_ReceiveCallback rec;
126 * Notify connect callback
128 GNUNET_TRANSPORT_NotifyConnect nc;
131 * Notify disconnect callback
133 GNUNET_TRANSPORT_NotifyDisconnect nd;
136 * Startup completed callback
138 GNUNET_TRANSPORT_TESTING_start_cb start_cb;
141 * Peers HELLO Message
143 struct GNUNET_HELLO_Message *hello;
146 * Closure for the callbacks
151 * An unique number to identify the peer
157 struct GNUNET_TRANSPORT_TESTING_ConnectRequest
159 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *next;
160 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *prev;
161 struct PeerContext *p1;
162 struct PeerContext *p2;
163 struct GNUNET_SCHEDULER_Task *tct;
164 struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh;
165 struct GNUNET_TRANSPORT_OfferHelloHandle *oh;
166 GNUNET_TRANSPORT_TESTING_connect_cb cb;
173 struct GNUNET_TRANSPORT_TESTING_handle
176 * Testing library system handle
178 struct GNUNET_TESTING_System *tl_system;
181 * head DLL of connect contexts
183 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc_head;
186 * head DLL of connect contexts
188 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc_tail;
193 struct PeerContext *p_head;
198 struct PeerContext *p_tail;
203 * Start a peer with the given configuration
205 * @param tth the testing handle
206 * @param cfgname configuration file
207 * @param peer_id the peer_id
208 * @param rec receive callback
209 * @param nc connect callback
210 * @param nd disconnect callback
211 * @param start_cb start callback
212 * @param cb_cls closure for callback
213 * @return the peer context
216 GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth,
219 GNUNET_TRANSPORT_ReceiveCallback rec,
220 GNUNET_TRANSPORT_NotifyConnect nc,
221 GNUNET_TRANSPORT_NotifyDisconnect nd,
222 GNUNET_TRANSPORT_TESTING_start_cb start_cb,
227 * shutdown the given peer
229 * @param tth the testing handle
233 GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth,
234 struct PeerContext *pc);
238 * Restart the given peer
241 * @param cfgname the cfg file used to restart
242 * @param restart_cb restart callback
243 * @param cb_cls callback closure
244 * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR
247 GNUNET_TRANSPORT_TESTING_restart_peer (struct PeerContext *p,
249 GNUNET_TRANSPORT_TESTING_start_cb restart_cb,
254 * Connect the given peers and call the callback when both peers report the
255 * inbound connection. Remarks: start_peer's notify_connect callback can be called
258 * @param tth transport testing handle
261 * @param cb the callback to call when both peers notified that they are connected
262 * @param cls callback cls
263 * @return a connect request handle
265 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *
266 GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle *tth,
267 struct PeerContext *p1,
268 struct PeerContext *p2,
269 GNUNET_TRANSPORT_TESTING_connect_cb cb,
274 * Cancel the request to connect two peers
275 * Tou MUST cancel the request if you stop the peers before the peers connected succesfully
277 * @param cc a connect request handle
280 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct GNUNET_TRANSPORT_TESTING_handle *tth,
281 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc);
285 * Clean up the transport testing
286 * @param tth transport testing handle
289 GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle *tth);
293 * Initialize the transport testing
294 * @return transport testing handle
296 struct GNUNET_TRANSPORT_TESTING_handle *
297 GNUNET_TRANSPORT_TESTING_init (void);
301 * Extracts the test filename from an absolute file name and removes the extension
302 * @param file absolute file name
303 * @param dest where to store result
306 GNUNET_TRANSPORT_TESTING_get_test_name (const char *file,
311 * This function takes the filename (e.g. argv[0), removes a "lt-"-prefix and
312 * if existing ".exe"-prefix and adds the peer-number
314 * @param file filename of the test, e.g. argv[0]
315 * @param dest where to write the filename
316 * @param count peer number
319 GNUNET_TRANSPORT_TESTING_get_config_name (const char *file,
325 * Extracts the plugin anme from an absolute file name and the test name
326 * @param file absolute file name
327 * @param test test name
328 * @param dest where to store result
331 GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *executable,
332 const char *testname,
337 * Extracts the filename from an absolute file name and removes the extenstion
338 * @param file absolute file name
339 * @param dest where to store result
342 GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file,
345 /* end of transport_testing.h */