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"
38 #define GNUNET_TRANSPORT_TESTING_ConnectRequest void *
42 * Context for a single peer
47 * Callback when two peers are connected and both have called the connect callback
48 * to notify clients about a new peer
50 typedef void (*GNUNET_TRANSPORT_TESTING_start_cb) (struct PeerContext * p,
54 * Callback when two peers are connected and both have called the connect callback
55 * to notify clients about a new peer
57 typedef void (*GNUNET_TRANSPORT_TESTING_connect_cb) (struct PeerContext * p1,
58 struct PeerContext * p2,
63 struct GNUNET_TRANSPORT_TESTING_handle;
66 * Context for a single peer
70 struct PeerContext *next;
71 struct PeerContext *prev;
73 struct GNUNET_TRANSPORT_TESTING_handle *tth;
75 struct GNUNET_CONFIGURATION_Handle *cfg;
77 struct GNUNET_TRANSPORT_Handle *th;
79 struct GNUNET_TRANSPORT_GetHelloHandle *ghh;
81 struct GNUNET_PeerIdentity id;
83 struct GNUNET_OS_Process *arm_proc;
85 GNUNET_TRANSPORT_ReceiveCallback rec;
87 GNUNET_TRANSPORT_NotifyConnect nc;
89 GNUNET_TRANSPORT_NotifyDisconnect nd;
91 GNUNET_TRANSPORT_TESTING_start_cb start_cb;
93 struct GNUNET_HELLO_Message *hello;
105 struct ConnectingContext
107 struct ConnectingContext *next;
108 struct ConnectingContext *prev;
109 struct PeerContext *p1;
110 struct PeerContext *p2;
111 GNUNET_SCHEDULER_TaskIdentifier tct;
112 GNUNET_TRANSPORT_TESTING_connect_cb cb;
114 struct GNUNET_TRANSPORT_Handle *th_p1;
115 struct GNUNET_TRANSPORT_Handle *th_p2;
120 struct GNUNET_TRANSPORT_TESTING_handle
122 struct ConnectingContext *cc_head;
123 struct ConnectingContext *cc_tail;
129 struct PeerContext *p_head;
130 struct PeerContext *p_tail;
135 * Start a peer with the given configuration
136 * @param tth the testing handle
137 * @param cfgname configuration file
138 * @param peer_id the peer_id
139 * @param rec receive callback
140 * @param nc connect callback
141 * @param nd disconnect callback
142 * @param start_cb start callback
143 * @param cb_cls closure for callback
144 * @return the peer context
147 GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle
148 *tth, const char *cfgname, int peer_id,
149 GNUNET_TRANSPORT_ReceiveCallback rec,
150 GNUNET_TRANSPORT_NotifyConnect nc,
151 GNUNET_TRANSPORT_NotifyDisconnect nd,
152 GNUNET_TRANSPORT_TESTING_start_cb start_cb,
157 * shutdown the given peer
158 * @param tth the testing handle
163 GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth,
164 struct PeerContext *pc);
168 * Restart the given peer
169 * @param tth testing handle
171 * @param cfgname the cfg file used to restart
172 * @param restart_cb restart callback
173 * @param cb_cls callback closure
174 * @return GNUNET_OK in success otherwise GNUNET_SYSERR
177 GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_handle
178 *tth, struct PeerContext *p,
180 GNUNET_TRANSPORT_TESTING_start_cb
181 restart_cb, void *cb_cls);
184 * Connect the given peers and call the callback when both peers report the
185 * inbound connection. Remarks: start_peer's notify_connect callback can be called
188 * @param tth transport testing handle
191 * @param cb the callback to call when both peers notified that they are connected
192 * @param cls callback cls
193 * @return a connect request handle
195 GNUNET_TRANSPORT_TESTING_ConnectRequest
196 GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle *tth,
197 struct PeerContext *p1,
198 struct PeerContext *p2,
199 GNUNET_TRANSPORT_TESTING_connect_cb cb,
203 * Cancel the request to connect two peers
204 * Tou MUST cancel the request if you stop the peers before the peers connected succesfully
206 * @param ccr a connect request handle
209 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct
210 GNUNET_TRANSPORT_TESTING_handle
212 GNUNET_TRANSPORT_TESTING_ConnectRequest
216 * Clean up the transport testing
217 * @param tth transport testing handle
220 GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle *tth);
223 * Initialize the transport testing
224 * @return transport testing handle
226 struct GNUNET_TRANSPORT_TESTING_handle *
227 GNUNET_TRANSPORT_TESTING_init ();
230 * Some utility functions
234 * Extracts the test filename from an absolute file name and removes the extension
235 * @param file absolute file name
236 * @param dest where to store result
239 GNUNET_TRANSPORT_TESTING_get_test_name (const char *file, char **dest);
242 * This function takes the filename (e.g. argv[0), removes a "lt-"-prefix and
243 * if existing ".exe"-prefix and adds the peer-number
245 * @param file filename of the test, e.g. argv[0]
246 * @param dest where to write the filename
247 * @param count peer number
250 GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, char **dest,
255 * Extracts the plugin anme from an absolute file name and the test name
256 * @param file absolute file name
257 * @param test test name
258 * @param dest where to store result
261 GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *executable,
262 const char *testname,
267 * Extracts the filename from an absolute file name and removes the extenstion
268 * @param file absolute file name
269 * @param dest where to store result
272 GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file,
275 /* end of transport_testing.h */