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"
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,
61 struct GNUNET_TRANSPORT_TESTING_handle;
64 * Context for a single peer
68 struct PeerContext *next;
69 struct PeerContext *prev;
71 struct GNUNET_TRANSPORT_TESTING_handle *tth;
73 struct GNUNET_CONFIGURATION_Handle *cfg;
75 struct GNUNET_TRANSPORT_Handle *th;
77 struct GNUNET_TRANSPORT_GetHelloHandle *ghh;
79 struct GNUNET_PeerIdentity id;
81 struct GNUNET_OS_Process *arm_proc;
83 GNUNET_TRANSPORT_ReceiveCallback rec;
85 GNUNET_TRANSPORT_NotifyConnect nc;
87 GNUNET_TRANSPORT_NotifyDisconnect nd;
89 GNUNET_TRANSPORT_TESTING_start_cb start_cb;
91 struct GNUNET_HELLO_Message *hello;
103 struct ConnectingContext
105 struct ConnectingContext *next;
106 struct ConnectingContext *prev;
107 struct PeerContext *p1;
108 struct PeerContext *p2;
109 GNUNET_SCHEDULER_TaskIdentifier tct;
110 GNUNET_TRANSPORT_TESTING_connect_cb cb;
112 struct GNUNET_TRANSPORT_Handle *th_p1;
113 struct GNUNET_TRANSPORT_Handle *th_p2;
118 struct GNUNET_TRANSPORT_TESTING_handle
120 struct ConnectingContext *cc_head;
121 struct ConnectingContext *cc_tail;
127 struct PeerContext *p_head;
128 struct PeerContext *p_tail;
134 * Start a peer with the given configuration
135 * @param rec receive callback
136 * @param nc connect callback
137 * @param nd disconnect callback
138 * @param cb_cls closure for callback
139 * if NULL passed the PeerContext * will be used!
140 * @return the peer context
143 GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle
144 *tth, const char *cfgname, int peer_id,
145 GNUNET_TRANSPORT_ReceiveCallback rec,
146 GNUNET_TRANSPORT_NotifyConnect nc,
147 GNUNET_TRANSPORT_NotifyDisconnect nd,
148 GNUNET_TRANSPORT_TESTING_start_cb start_cb,
153 * shutdown the given peer
158 GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth,
159 struct PeerContext *pc);
163 * Connect the given peers and call the callback when both peers report the
164 * inbound connection. Remarks: start_peer's notify_connect callback can be called
168 * @param cb the callback to call when both peers notified that they are connected
169 * @param cb_cls callback cls
170 * @return a connect request handle
172 GNUNET_TRANSPORT_TESTING_ConnectRequest
173 GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle
174 *tth, struct PeerContext *p1,
175 struct PeerContext *p2,
176 GNUNET_TRANSPORT_TESTING_connect_cb cb,
180 * Cancel the request to connect two peers
181 * Tou MUST cancel the request if you stop the peers before the peers connected succesfully
182 * @param cc a connect request handle
185 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct
186 GNUNET_TRANSPORT_TESTING_handle
190 * Clean up the transport testing
191 * @param tth transport testing handle
194 GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle *tth);
197 * Initialize the transport testing
198 * @return transport testing handle
200 struct GNUNET_TRANSPORT_TESTING_handle *
201 GNUNET_TRANSPORT_TESTING_init ();
204 * Some utility functions
208 * Extracts the test filename from an absolute file name and removes the extension
209 * @param file absolute file name
210 * @param dest where to store result
213 GNUNET_TRANSPORT_TESTING_get_test_name (const char *file, char **dest);
216 * This function takes the filename (e.g. argv[0), removes a "lt-"-prefix and
217 * if existing ".exe"-prefix and adds the peer-number
218 * @param file filename of the test, e.g. argv[0]
219 * @param cfgname where to write the result
220 * @param count peer number
223 GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, char **cfgname,
228 * Extracts the plugin anme from an absolute file name and the test name
229 * @param file absolute file name
230 * @param test test name
231 * @param dest where to store result
234 GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *executable,
235 const char *testname,
240 * Extracts the filename from an absolute file name and removes the extenstion
241 * @param file absolute file name
242 * @param dest where to store result
245 GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file,
248 /* end of transport_testing.h */