summaryrefslogtreecommitdiff
path: root/src/mesh/mesh_test_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesh/mesh_test_lib.c')
-rw-r--r--src/mesh/mesh_test_lib.c118
1 files changed, 59 insertions, 59 deletions
diff --git a/src/mesh/mesh_test_lib.c b/src/mesh/mesh_test_lib.c
index 3fa73df4d..663972cad 100644
--- a/src/mesh/mesh_test_lib.c
+++ b/src/mesh/mesh_test_lib.c
@@ -18,19 +18,19 @@
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20/** 20/**
21 * @file mesh/mesh_test_lib.c 21 * @file cadet/cadet_test_lib.c
22 * @author Bartlomiej Polot 22 * @author Bartlomiej Polot
23 * @brief library for writing MESH tests 23 * @brief library for writing CADET tests
24 */ 24 */
25#include "platform.h" 25#include "platform.h"
26#include "gnunet_util_lib.h" 26#include "gnunet_util_lib.h"
27#include "mesh_test_lib.h" 27#include "cadet_test_lib.h"
28#include "gnunet_mesh_service.h" 28#include "gnunet_cadet_service.h"
29 29
30/** 30/**
31 * Test context for a MESH Test. 31 * Test context for a CADET Test.
32 */ 32 */
33struct GNUNET_MESH_TEST_Context 33struct GNUNET_CADET_TEST_Context
34{ 34{
35 /** 35 /**
36 * Array of running peers. 36 * Array of running peers.
@@ -38,19 +38,19 @@ struct GNUNET_MESH_TEST_Context
38 struct GNUNET_TESTBED_Peer **peers; 38 struct GNUNET_TESTBED_Peer **peers;
39 39
40 /** 40 /**
41 * Array of handles to the MESH for each peer. 41 * Array of handles to the CADET for each peer.
42 */ 42 */
43 struct GNUNET_MESH_Handle **meshes; 43 struct GNUNET_CADET_Handle **cadetes;
44 44
45 /** 45 /**
46 * Operation associated with the connection to the MESH. 46 * Operation associated with the connection to the CADET.
47 */ 47 */
48 struct GNUNET_TESTBED_Operation **ops; 48 struct GNUNET_TESTBED_Operation **ops;
49 49
50 /** 50 /**
51 * Main function of the test to run once all MESHs are available. 51 * Main function of the test to run once all CADETs are available.
52 */ 52 */
53 GNUNET_MESH_TEST_AppMain app_main; 53 GNUNET_CADET_TEST_AppMain app_main;
54 54
55 /** 55 /**
56 * Closure for 'app_main'. 56 * Closure for 'app_main'.
@@ -65,17 +65,17 @@ struct GNUNET_MESH_TEST_Context
65 /** 65 /**
66 * Handler for incoming tunnels. 66 * Handler for incoming tunnels.
67 */ 67 */
68 GNUNET_MESH_InboundChannelNotificationHandler *new_channel; 68 GNUNET_CADET_InboundChannelNotificationHandler *new_channel;
69 69
70 /** 70 /**
71 * Cleaner for destroyed incoming tunnels. 71 * Cleaner for destroyed incoming tunnels.
72 */ 72 */
73 GNUNET_MESH_ChannelEndHandler *cleaner; 73 GNUNET_CADET_ChannelEndHandler *cleaner;
74 74
75 /** 75 /**
76 * Message handlers. 76 * Message handlers.
77 */ 77 */
78 struct GNUNET_MESH_MessageHandler* handlers; 78 struct GNUNET_CADET_MessageHandler* handlers;
79 79
80 /** 80 /**
81 * Application ports. 81 * Application ports.
@@ -86,9 +86,9 @@ struct GNUNET_MESH_TEST_Context
86 86
87 87
88/** 88/**
89 * Context for a mesh adapter callback. 89 * Context for a cadet adapter callback.
90 */ 90 */
91struct GNUNET_MESH_TEST_AdapterContext 91struct GNUNET_CADET_TEST_AdapterContext
92{ 92{
93 /** 93 /**
94 * Peer number for the particular peer. 94 * Peer number for the particular peer.
@@ -98,13 +98,13 @@ struct GNUNET_MESH_TEST_AdapterContext
98 /** 98 /**
99 * General context. 99 * General context.
100 */ 100 */
101 struct GNUNET_MESH_TEST_Context *ctx; 101 struct GNUNET_CADET_TEST_Context *ctx;
102}; 102};
103 103
104 104
105/** 105/**
106 * Adapter function called to establish a connection to 106 * Adapter function called to establish a connection to
107 * the MESH service. 107 * the CADET service.
108 * 108 *
109 * @param cls closure 109 * @param cls closure
110 * @param cfg configuration of the peer to connect to; will be available until 110 * @param cfg configuration of the peer to connect to; will be available until
@@ -113,14 +113,14 @@ struct GNUNET_MESH_TEST_AdapterContext
113 * @return service handle to return in 'op_result', NULL on error 113 * @return service handle to return in 'op_result', NULL on error
114 */ 114 */
115static void * 115static void *
116mesh_connect_adapter (void *cls, 116cadet_connect_adapter (void *cls,
117 const struct GNUNET_CONFIGURATION_Handle *cfg) 117 const struct GNUNET_CONFIGURATION_Handle *cfg)
118{ 118{
119 struct GNUNET_MESH_TEST_AdapterContext *actx = cls; 119 struct GNUNET_CADET_TEST_AdapterContext *actx = cls;
120 struct GNUNET_MESH_TEST_Context *ctx = actx->ctx; 120 struct GNUNET_CADET_TEST_Context *ctx = actx->ctx;
121 struct GNUNET_MESH_Handle *h; 121 struct GNUNET_CADET_Handle *h;
122 122
123 h = GNUNET_MESH_connect (cfg, 123 h = GNUNET_CADET_connect (cfg,
124 (void *) (long) actx->peer, 124 (void *) (long) actx->peer,
125 ctx->new_channel, 125 ctx->new_channel,
126 ctx->cleaner, 126 ctx->cleaner,
@@ -132,20 +132,20 @@ mesh_connect_adapter (void *cls,
132 132
133/** 133/**
134 * Adapter function called to destroy a connection to 134 * Adapter function called to destroy a connection to
135 * the MESH service. 135 * the CADET service.
136 * 136 *
137 * @param cls closure 137 * @param cls closure
138 * @param op_result service handle returned from the connect adapter 138 * @param op_result service handle returned from the connect adapter
139 */ 139 */
140static void 140static void
141mesh_disconnect_adapter (void *cls, 141cadet_disconnect_adapter (void *cls,
142 void *op_result) 142 void *op_result)
143{ 143{
144 struct GNUNET_MESH_Handle *mesh = op_result; 144 struct GNUNET_CADET_Handle *cadet = op_result;
145 struct GNUNET_MESH_TEST_AdapterContext *actx = cls; 145 struct GNUNET_CADET_TEST_AdapterContext *actx = cls;
146 146
147 GNUNET_free (actx); 147 GNUNET_free (actx);
148 GNUNET_MESH_disconnect (mesh); 148 GNUNET_CADET_disconnect (cadet);
149} 149}
150 150
151 151
@@ -155,22 +155,22 @@ mesh_disconnect_adapter (void *cls,
155 * @param cls The callback closure from functions generating an operation. 155 * @param cls The callback closure from functions generating an operation.
156 * @param op The operation that has been finished. 156 * @param op The operation that has been finished.
157 * @param ca_result The service handle returned from 157 * @param ca_result The service handle returned from
158 * GNUNET_TESTBED_ConnectAdapter() (mesh handle). 158 * GNUNET_TESTBED_ConnectAdapter() (cadet handle).
159 * @param emsg Error message in case the operation has failed. 159 * @param emsg Error message in case the operation has failed.
160 * NULL if operation has executed successfully. 160 * NULL if operation has executed successfully.
161 */ 161 */
162static void 162static void
163mesh_connect_cb (void *cls, 163cadet_connect_cb (void *cls,
164 struct GNUNET_TESTBED_Operation *op, 164 struct GNUNET_TESTBED_Operation *op,
165 void *ca_result, 165 void *ca_result,
166 const char *emsg) 166 const char *emsg)
167{ 167{
168 struct GNUNET_MESH_TEST_Context *ctx = cls; 168 struct GNUNET_CADET_TEST_Context *ctx = cls;
169 unsigned int i; 169 unsigned int i;
170 170
171 if (NULL != emsg) 171 if (NULL != emsg)
172 { 172 {
173 fprintf (stderr, "Failed to connect to MESH service: %s\n", 173 fprintf (stderr, "Failed to connect to CADET service: %s\n",
174 emsg); 174 emsg);
175 GNUNET_SCHEDULER_shutdown (); 175 GNUNET_SCHEDULER_shutdown ();
176 return; 176 return;
@@ -178,23 +178,23 @@ mesh_connect_cb (void *cls,
178 for (i = 0; i < ctx->num_peers; i++) 178 for (i = 0; i < ctx->num_peers; i++)
179 if (op == ctx->ops[i]) 179 if (op == ctx->ops[i])
180 { 180 {
181 ctx->meshes[i] = ca_result; 181 ctx->cadetes[i] = ca_result;
182 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "...mesh %u connected\n", i); 182 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "...cadet %u connected\n", i);
183 } 183 }
184 for (i = 0; i < ctx->num_peers; i++) 184 for (i = 0; i < ctx->num_peers; i++)
185 if (NULL == ctx->meshes[i]) 185 if (NULL == ctx->cadetes[i])
186 return; /* still some MESH connections missing */ 186 return; /* still some CADET connections missing */
187 /* all MESH connections ready! */ 187 /* all CADET connections ready! */
188 ctx->app_main (ctx->app_main_cls, 188 ctx->app_main (ctx->app_main_cls,
189 ctx, 189 ctx,
190 ctx->num_peers, 190 ctx->num_peers,
191 ctx->peers, 191 ctx->peers,
192 ctx->meshes); 192 ctx->cadetes);
193} 193}
194 194
195 195
196void 196void
197GNUNET_MESH_TEST_cleanup (struct GNUNET_MESH_TEST_Context *ctx) 197GNUNET_CADET_TEST_cleanup (struct GNUNET_CADET_TEST_Context *ctx)
198{ 198{
199 unsigned int i; 199 unsigned int i;
200 200
@@ -205,7 +205,7 @@ GNUNET_MESH_TEST_cleanup (struct GNUNET_MESH_TEST_Context *ctx)
205 ctx->ops[i] = NULL; 205 ctx->ops[i] = NULL;
206 } 206 }
207 GNUNET_free (ctx->ops); 207 GNUNET_free (ctx->ops);
208 GNUNET_free (ctx->meshes); 208 GNUNET_free (ctx->cadetes);
209 GNUNET_free (ctx); 209 GNUNET_free (ctx);
210 GNUNET_SCHEDULER_shutdown (); 210 GNUNET_SCHEDULER_shutdown ();
211} 211}
@@ -225,14 +225,14 @@ GNUNET_MESH_TEST_cleanup (struct GNUNET_MESH_TEST_Context *ctx)
225 * failed 225 * failed
226 */ 226 */
227static void 227static void
228mesh_test_run (void *cls, 228cadet_test_run (void *cls,
229 struct GNUNET_TESTBED_RunHandle *h, 229 struct GNUNET_TESTBED_RunHandle *h,
230 unsigned int num_peers, 230 unsigned int num_peers,
231 struct GNUNET_TESTBED_Peer **peers, 231 struct GNUNET_TESTBED_Peer **peers,
232 unsigned int links_succeeded, 232 unsigned int links_succeeded,
233 unsigned int links_failed) 233 unsigned int links_failed)
234{ 234{
235 struct GNUNET_MESH_TEST_Context *ctx = cls; 235 struct GNUNET_CADET_TEST_Context *ctx = cls;
236 unsigned int i; 236 unsigned int i;
237 237
238 if (num_peers != ctx->num_peers) 238 if (num_peers != ctx->num_peers)
@@ -244,18 +244,18 @@ mesh_test_run (void *cls,
244 ctx->peers = peers; 244 ctx->peers = peers;
245 for (i = 0; i < num_peers; i++) 245 for (i = 0; i < num_peers; i++)
246 { 246 {
247 struct GNUNET_MESH_TEST_AdapterContext *newctx; 247 struct GNUNET_CADET_TEST_AdapterContext *newctx;
248 newctx = GNUNET_new (struct GNUNET_MESH_TEST_AdapterContext); 248 newctx = GNUNET_new (struct GNUNET_CADET_TEST_AdapterContext);
249 newctx->peer = i; 249 newctx->peer = i;
250 newctx->ctx = ctx; 250 newctx->ctx = ctx;
251 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connecting to mesh %u\n", i); 251 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connecting to cadet %u\n", i);
252 ctx->ops[i] = GNUNET_TESTBED_service_connect (ctx, 252 ctx->ops[i] = GNUNET_TESTBED_service_connect (ctx,
253 peers[i], 253 peers[i],
254 "mesh", 254 "cadet",
255 &mesh_connect_cb, 255 &cadet_connect_cb,
256 ctx, 256 ctx,
257 &mesh_connect_adapter, 257 &cadet_connect_adapter,
258 &mesh_disconnect_adapter, 258 &cadet_disconnect_adapter,
259 newctx); 259 newctx);
260 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "op handle %p\n", ctx->ops[i]); 260 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "op handle %p\n", ctx->ops[i]);
261 } 261 }
@@ -263,22 +263,22 @@ mesh_test_run (void *cls,
263 263
264 264
265void 265void
266GNUNET_MESH_TEST_run (const char *testname, 266GNUNET_CADET_TEST_run (const char *testname,
267 const char *cfgname, 267 const char *cfgname,
268 unsigned int num_peers, 268 unsigned int num_peers,
269 GNUNET_MESH_TEST_AppMain tmain, 269 GNUNET_CADET_TEST_AppMain tmain,
270 void *tmain_cls, 270 void *tmain_cls,
271 GNUNET_MESH_InboundChannelNotificationHandler new_channel, 271 GNUNET_CADET_InboundChannelNotificationHandler new_channel,
272 GNUNET_MESH_ChannelEndHandler cleaner, 272 GNUNET_CADET_ChannelEndHandler cleaner,
273 struct GNUNET_MESH_MessageHandler* handlers, 273 struct GNUNET_CADET_MessageHandler* handlers,
274 const uint32_t *ports) 274 const uint32_t *ports)
275{ 275{
276 struct GNUNET_MESH_TEST_Context *ctx; 276 struct GNUNET_CADET_TEST_Context *ctx;
277 277
278 ctx = GNUNET_new (struct GNUNET_MESH_TEST_Context); 278 ctx = GNUNET_new (struct GNUNET_CADET_TEST_Context);
279 ctx->num_peers = num_peers; 279 ctx->num_peers = num_peers;
280 ctx->ops = GNUNET_malloc (num_peers * sizeof (struct GNUNET_TESTBED_Operation *)); 280 ctx->ops = GNUNET_malloc (num_peers * sizeof (struct GNUNET_TESTBED_Operation *));
281 ctx->meshes = GNUNET_malloc (num_peers * sizeof (struct GNUNET_MESH_Handle *)); 281 ctx->cadetes = GNUNET_malloc (num_peers * sizeof (struct GNUNET_CADET_Handle *));
282 ctx->app_main = tmain; 282 ctx->app_main = tmain;
283 ctx->app_main_cls = tmain_cls; 283 ctx->app_main_cls = tmain_cls;
284 ctx->new_channel = new_channel; 284 ctx->new_channel = new_channel;
@@ -289,7 +289,7 @@ GNUNET_MESH_TEST_run (const char *testname,
289 cfgname, 289 cfgname,
290 num_peers, 290 num_peers,
291 0LL, NULL, NULL, 291 0LL, NULL, NULL,
292 &mesh_test_run, ctx); 292 &cadet_test_run, ctx);
293} 293}
294 294
295/* end of mesh_test_lib.c */ 295/* end of cadet_test_lib.c */