96fe216e98dbe537a6d3997fdfeb3563082ad39b
[oweals/gnunet.git] / src / transport / transport-testing.h
1 /*
2      This file is part of GNUnet.
3      (C) 2006, 2009 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19 */
20
21 /**
22  * @file transport_testing.h
23  * @brief testing lib for transport service
24  *
25  * @author Matthias Wachs
26  */
27
28 #include "platform.h"
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_transport_service.h"
35
36 #define GNUNET_TRANSPORT_TESTING_ConnectRequest void *
37
38 /**
39  * Context for a single peer
40  */
41 struct PeerContext
42 {
43   struct GNUNET_CONFIGURATION_Handle *cfg;
44
45   struct GNUNET_TRANSPORT_Handle *th;
46
47   struct GNUNET_PeerIdentity id;
48
49   struct GNUNET_OS_Process *arm_proc;
50
51   GNUNET_TRANSPORT_ReceiveCallback rec;
52
53   GNUNET_TRANSPORT_NotifyConnect nc;
54
55   GNUNET_TRANSPORT_NotifyDisconnect nd;
56
57   void *cb_cls;
58
59   char *servicehome;
60 };
61
62 /**
63  * Callback when two peers are connected and both have called the connect callback
64  * to notify clients about a new peer
65  */
66 typedef void (*GNUNET_TRANSPORT_TESTING_connect_cb) (struct PeerContext * p1,
67                                                      struct PeerContext * p2,
68                                                      void *cls);
69
70
71 /**
72  * Start a peer with the given configuration
73  * @param rec receive callback
74  * @param nc connect callback
75  * @param nd disconnect callback
76  * @param cb_cls closure for callback
77  *   if NULL passed the PeerContext * will be used!
78  * @return the peer context
79  */
80 struct PeerContext *
81 GNUNET_TRANSPORT_TESTING_start_peer (const char *cfgname,
82                                      GNUNET_TRANSPORT_ReceiveCallback rec,
83                                      GNUNET_TRANSPORT_NotifyConnect nc,
84                                      GNUNET_TRANSPORT_NotifyDisconnect nd,
85                                      void *cb_cls);
86
87
88 /**
89  * shutdown the given peer
90  * @param p the peer
91  */
92
93 void
94 GNUNET_TRANSPORT_TESTING_stop_peer (struct PeerContext *pc);
95
96
97 /**
98  * Connect the given peers and call the callback when both peers report the
99  * inbound connection. Remarks: start_peer's notify_connect callback can be called
100  * before.
101  * @param p1 peer 1
102  * @param p2 peer 2
103  * @param cb the callback to call
104  * @param cb_cls callback cls
105  * @return a connect request handle
106  */
107 GNUNET_TRANSPORT_TESTING_ConnectRequest
108 GNUNET_TRANSPORT_TESTING_connect_peers (struct PeerContext *p1,
109                                         struct PeerContext *p2,
110                                         GNUNET_TRANSPORT_TESTING_connect_cb cb,
111                                         void *cls);
112
113 /**
114  * Cancel the request to connect two peers
115  * Tou MUST cancel the request if you stop the peers before the peers connected succesfully
116  * @param cc a connect request handle
117  */
118 void
119 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (void *cc);
120
121 /*
122  * Some utility functions
123  */
124
125 /**
126  * this function takes the filename (e.g. argv[0), removes a "lt-"-prefix and
127  * if existing ".exe"-prefix and adds the peer-number
128  * @param file filename of the test, e.g. argv[0]
129  * @param cfgname where to write the result
130  * @param count peer number
131  */
132 void
133 GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, char **cfgname,
134                                           int count);
135
136 void
137 GNUNET_TRANSPORT_TESTING_get_test_plugin (const char * executable, const char * testname, char **pluginname);
138
139 void
140 GNUNET_TRANSPORT_TESTING_get_test_sourcename (const char * file, char **testname);
141
142 /* end of transport_testing.h */