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;
101 struct ConnectingContext
103 struct ConnectingContext * next;
104 struct ConnectingContext * prev;
105 struct PeerContext *p1;
106 struct PeerContext *p2;
107 GNUNET_SCHEDULER_TaskIdentifier tct;
108 GNUNET_TRANSPORT_TESTING_connect_cb cb;
110 struct GNUNET_TRANSPORT_Handle *th_p1;
111 struct GNUNET_TRANSPORT_Handle *th_p2;
116 struct GNUNET_TRANSPORT_TESTING_handle
118 struct ConnectingContext * cc_head;
119 struct ConnectingContext * cc_tail;
121 struct PeerContext * p_head;
122 struct PeerContext * p_tail;
128 * Start a peer with the given configuration
129 * @param rec receive callback
130 * @param nc connect callback
131 * @param nd disconnect callback
132 * @param cb_cls closure for callback
133 * if NULL passed the PeerContext * will be used!
134 * @return the peer context
137 GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle * tth,
140 GNUNET_TRANSPORT_ReceiveCallback rec,
141 GNUNET_TRANSPORT_NotifyConnect nc,
142 GNUNET_TRANSPORT_NotifyDisconnect nd,
143 GNUNET_TRANSPORT_TESTING_start_cb start_cb,
148 * shutdown the given peer
153 GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle * tth,
154 struct PeerContext *pc);
158 * Connect the given peers and call the callback when both peers report the
159 * inbound connection. Remarks: start_peer's notify_connect callback can be called
163 * @param cb the callback to call when both peers notified that they are connected
164 * @param cb_cls callback cls
165 * @return a connect request handle
167 GNUNET_TRANSPORT_TESTING_ConnectRequest
168 GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle * tth,
169 struct PeerContext *p1,
170 struct PeerContext *p2,
171 GNUNET_TRANSPORT_TESTING_connect_cb cb,
175 * Cancel the request to connect two peers
176 * Tou MUST cancel the request if you stop the peers before the peers connected succesfully
177 * @param cc a connect request handle
180 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct GNUNET_TRANSPORT_TESTING_handle *,
184 * Clean up the transport testing
185 * @param tth transport testing handle
188 GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle * tth);
191 * Initialize the transport testing
192 * @return transport testing handle
194 struct GNUNET_TRANSPORT_TESTING_handle *
195 GNUNET_TRANSPORT_TESTING_init ();
198 * Some utility functions
202 * Extracts the test filename from an absolute file name and removes the extension
203 * @param file absolute file name
204 * @param dest where to store result
207 GNUNET_TRANSPORT_TESTING_get_test_name (const char *file, char **dest);
210 * This function takes the filename (e.g. argv[0), removes a "lt-"-prefix and
211 * if existing ".exe"-prefix and adds the peer-number
212 * @param file filename of the test, e.g. argv[0]
213 * @param cfgname where to write the result
214 * @param count peer number
217 GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, char **cfgname,
222 * Extracts the plugin anme from an absolute file name and the test name
223 * @param file absolute file name
224 * @param test test name
225 * @param dest where to store result
228 GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *executable,
229 const char *testname,
234 * Extracts the filename from an absolute file name and removes the extenstion
235 * @param file absolute file name
236 * @param dest where to store result
239 GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file,
242 /* end of transport_testing.h */