diff options
Diffstat (limited to 'src/transport/test_plugin_transport.c')
-rw-r--r-- | src/transport/test_plugin_transport.c | 621 |
1 files changed, 286 insertions, 335 deletions
diff --git a/src/transport/test_plugin_transport.c b/src/transport/test_plugin_transport.c index 6c81acb49..13920d6fe 100644 --- a/src/transport/test_plugin_transport.c +++ b/src/transport/test_plugin_transport.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2009 Christian Grothoff (and other contributing authors) | 3 | (C) 2009 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation; either version 3, or (at your |
8 | option) any later version. | 8 | option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 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 | 16 | along with GNUnet; see the file COPYING. If not, write to the |
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file transport/test_plugin_transport.c | 21 | * @file transport/test_plugin_transport.c |
22 | * @brief testcase for transport_api.c | 22 | * @brief testcase for transport_api.c |
@@ -120,21 +120,17 @@ unsigned int pretty_printers_running; | |||
120 | */ | 120 | */ |
121 | static int ok; | 121 | static int ok; |
122 | 122 | ||
123 | |||
124 | struct AddressWrapper | 123 | struct AddressWrapper |
125 | { | 124 | { |
126 | struct AddressWrapper *next; | 125 | struct AddressWrapper *next; |
127 | 126 | ||
128 | struct AddressWrapper *prev; | 127 | struct AddressWrapper *prev; |
129 | 128 | ||
130 | void *addr; | 129 | struct GNUNET_HELLO_Address *address; |
131 | |||
132 | size_t addrlen; | ||
133 | 130 | ||
134 | char *addrstring; | 131 | char *addrstring; |
135 | }; | 132 | }; |
136 | 133 | ||
137 | |||
138 | static void | 134 | static void |
139 | end () | 135 | end () |
140 | { | 136 | { |
@@ -144,33 +140,32 @@ end () | |||
144 | 140 | ||
145 | if (GNUNET_SCHEDULER_NO_TASK != timeout_endbadly) | 141 | if (GNUNET_SCHEDULER_NO_TASK != timeout_endbadly) |
146 | { | 142 | { |
147 | GNUNET_SCHEDULER_cancel (timeout_endbadly); | 143 | GNUNET_SCHEDULER_cancel (timeout_endbadly); |
148 | timeout_endbadly = GNUNET_SCHEDULER_NO_TASK; | 144 | timeout_endbadly = GNUNET_SCHEDULER_NO_TASK; |
149 | } | 145 | } |
150 | if (NULL != api) | 146 | if (NULL != api) |
151 | GNUNET_PLUGIN_unload (libname, api); | 147 | GNUNET_PLUGIN_unload (libname, api); |
152 | 148 | ||
153 | while (NULL != head) | 149 | while (NULL != head) |
154 | { | 150 | { |
155 | w = head; | 151 | w = head; |
156 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 152 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove address `%s'\n", |
157 | "Plugin did not remove address `%s'\n", w->addrstring); | 153 | w->addrstring); |
158 | GNUNET_CONTAINER_DLL_remove (head, tail, w); | 154 | GNUNET_CONTAINER_DLL_remove(head, tail, w); |
159 | c ++; | 155 | c++; |
160 | GNUNET_free (w->addr); | 156 | GNUNET_HELLO_address_free(w->address); |
161 | GNUNET_free (w->addrstring); | 157 | GNUNET_free(w->addrstring); |
162 | GNUNET_free (w); | 158 | GNUNET_free(w); |
163 | } | 159 | } |
164 | if (c > 0) | 160 | if (c > 0) |
165 | { | 161 | { |
166 | GNUNET_break (0); | 162 | GNUNET_break(0); |
167 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 163 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove %u addresses \n", |
168 | "Plugin did not remove %u addresses \n", c); | 164 | c); |
169 | ok = 1; | 165 | ok = 1; |
170 | } | 166 | } |
171 | 167 | ||
172 | 168 | GNUNET_free(libname); | |
173 | GNUNET_free (libname); | ||
174 | libname = NULL; | 169 | libname = NULL; |
175 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | 170 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); |
176 | stats = NULL; | 171 | stats = NULL; |
@@ -182,7 +177,6 @@ end () | |||
182 | } | 177 | } |
183 | } | 178 | } |
184 | 179 | ||
185 | |||
186 | static void | 180 | static void |
187 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 181 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
188 | { | 182 | { |
@@ -192,48 +186,49 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
192 | timeout_endbadly = GNUNET_SCHEDULER_NO_TASK; | 186 | timeout_endbadly = GNUNET_SCHEDULER_NO_TASK; |
193 | if (GNUNET_SCHEDULER_NO_TASK != timeout_wait) | 187 | if (GNUNET_SCHEDULER_NO_TASK != timeout_wait) |
194 | { | 188 | { |
195 | GNUNET_SCHEDULER_cancel (timeout_wait); | 189 | GNUNET_SCHEDULER_cancel (timeout_wait); |
196 | timeout_wait = GNUNET_SCHEDULER_NO_TASK; | 190 | timeout_wait = GNUNET_SCHEDULER_NO_TASK; |
197 | } | 191 | } |
198 | 192 | ||
199 | if (pretty_printers_running > 0) | 193 | if (pretty_printers_running > 0) |
200 | { | 194 | { |
201 | timeout_endbadly = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &end_badly, &ok); | 195 | timeout_endbadly = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
202 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 196 | &end_badly, &ok); |
203 | "Have pending calls to pretty_printer ... deferring shutdown\n"); | 197 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
204 | return; | 198 | "Have pending calls to pretty_printer ... deferring shutdown\n"); |
199 | return; | ||
205 | } | 200 | } |
206 | 201 | ||
207 | if (NULL != cls) | 202 | if (NULL != cls) |
208 | { | 203 | { |
209 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 204 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
210 | "Test took too long to execute, timeout .... \n"); | 205 | "Test took too long to execute, timeout .... \n"); |
211 | } | 206 | } |
212 | 207 | ||
213 | if (NULL != libname) | 208 | if (NULL != libname) |
214 | { | 209 | { |
215 | if (NULL != api) | 210 | if (NULL != api) |
216 | GNUNET_PLUGIN_unload (libname, api); | 211 | GNUNET_PLUGIN_unload (libname, api); |
217 | GNUNET_free (libname); | 212 | GNUNET_free(libname); |
218 | libname = NULL; | 213 | libname = NULL; |
219 | } | 214 | } |
220 | 215 | ||
221 | while (NULL != head) | 216 | while (NULL != head) |
222 | { | 217 | { |
223 | w = head; | 218 | w = head; |
224 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 219 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove address `%s'\n", |
225 | "Plugin did not remove address `%s'\n", w->addrstring); | 220 | w->addrstring); |
226 | GNUNET_CONTAINER_DLL_remove (head, tail, w); | 221 | GNUNET_CONTAINER_DLL_remove(head, tail, w); |
227 | c ++; | 222 | c++; |
228 | GNUNET_free (w->addr); | 223 | GNUNET_HELLO_address_free(w->address); |
229 | GNUNET_free (w->addrstring); | 224 | GNUNET_free(w->addrstring); |
230 | GNUNET_free (w); | 225 | GNUNET_free(w); |
231 | } | 226 | } |
232 | if (c > 0) | 227 | if (c > 0) |
233 | { | 228 | { |
234 | GNUNET_break (0); | 229 | GNUNET_break(0); |
235 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 230 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove %u addresses\n", |
236 | "Plugin did not remove %u addresses\n", c); | 231 | c); |
237 | } | 232 | } |
238 | 233 | ||
239 | if (NULL != stats) | 234 | if (NULL != stats) |
@@ -251,51 +246,44 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
251 | ok = 1; | 246 | ok = 1; |
252 | } | 247 | } |
253 | 248 | ||
254 | |||
255 | static void | 249 | static void |
256 | wait_end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 250 | wait_end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
257 | { | 251 | { |
258 | timeout_wait = GNUNET_SCHEDULER_NO_TASK; | 252 | timeout_wait = GNUNET_SCHEDULER_NO_TASK; |
259 | if (0 == addresses_reported) | 253 | if (0 == addresses_reported) |
260 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 254 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
261 | "Plugin did not report any addresses, could not check address conversion functions\n"); | 255 | "Plugin did not report any addresses, could not check address conversion functions\n"); |
262 | end (); | 256 | end (); |
263 | } | 257 | } |
264 | 258 | ||
265 | |||
266 | static void | 259 | static void |
267 | end_badly_now () | 260 | end_badly_now () |
268 | { | 261 | { |
269 | if (GNUNET_SCHEDULER_NO_TASK != timeout_wait) | 262 | if (GNUNET_SCHEDULER_NO_TASK != timeout_wait) |
270 | { | 263 | { |
271 | GNUNET_SCHEDULER_cancel (timeout_wait); | 264 | GNUNET_SCHEDULER_cancel (timeout_wait); |
272 | timeout_wait = GNUNET_SCHEDULER_NO_TASK; | 265 | timeout_wait = GNUNET_SCHEDULER_NO_TASK; |
273 | } | 266 | } |
274 | if (GNUNET_SCHEDULER_NO_TASK != timeout_endbadly) | 267 | if (GNUNET_SCHEDULER_NO_TASK != timeout_endbadly) |
275 | { | 268 | { |
276 | GNUNET_SCHEDULER_cancel (timeout_endbadly); | 269 | GNUNET_SCHEDULER_cancel (timeout_endbadly); |
277 | timeout_endbadly = GNUNET_SCHEDULER_NO_TASK; | 270 | timeout_endbadly = GNUNET_SCHEDULER_NO_TASK; |
278 | } | 271 | } |
279 | timeout_endbadly = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | 272 | timeout_endbadly = GNUNET_SCHEDULER_add_now (&end_badly, NULL ); |
280 | } | 273 | } |
281 | 274 | ||
282 | |||
283 | static struct GNUNET_TIME_Relative | 275 | static struct GNUNET_TIME_Relative |
284 | env_receive (void *cls, | 276 | env_receive (void *cls, |
285 | const struct GNUNET_PeerIdentity *peer, | 277 | const struct GNUNET_HELLO_Address *address, |
286 | const struct GNUNET_MessageHeader *message, | 278 | struct Session *session, |
287 | struct Session * session, | 279 | const struct GNUNET_MessageHeader *message) |
288 | const char *sender_address, | ||
289 | uint16_t sender_address_len) | ||
290 | { | 280 | { |
291 | /* do nothing */ | 281 | /* do nothing */ |
292 | return GNUNET_TIME_relative_get_zero_(); | 282 | return GNUNET_TIME_relative_get_zero_ (); |
293 | } | 283 | } |
294 | 284 | ||
295 | |||
296 | static int got_reply; | 285 | static int got_reply; |
297 | 286 | ||
298 | |||
299 | /** | 287 | /** |
300 | * Take the given address and append it to the set of results sent back to | 288 | * Take the given address and append it to the set of results sent back to |
301 | * the client. | 289 | * the client. |
@@ -309,28 +297,23 @@ address_pretty_printer_cb (void *cls, const char *buf) | |||
309 | if (NULL != buf) | 297 | if (NULL != buf) |
310 | { | 298 | { |
311 | got_reply = GNUNET_YES; | 299 | got_reply = GNUNET_YES; |
312 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 300 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Pretty address : `%s'\n", buf); |
313 | "Pretty address : `%s'\n", buf); | 301 | pretty_printers_running--; |
314 | pretty_printers_running --; | ||
315 | } | 302 | } |
316 | else | 303 | else |
317 | { | 304 | { |
318 | if (GNUNET_NO == got_reply) | 305 | if (GNUNET_NO == got_reply) |
319 | { | 306 | { |
320 | pretty_printers_running --; | 307 | pretty_printers_running--; |
321 | GNUNET_break (0); | 308 | GNUNET_break(0); |
322 | end_badly_now (); | 309 | end_badly_now (); |
323 | } | 310 | } |
324 | } | 311 | } |
325 | } | 312 | } |
326 | 313 | ||
327 | |||
328 | static void | 314 | static void |
329 | env_notify_address (void *cls, | 315 | env_notify_address (void *cls, int add_remove, |
330 | int add_remove, | 316 | const struct GNUNET_HELLO_Address *address) |
331 | const void *addr, | ||
332 | size_t addrlen, | ||
333 | const char *plugin) | ||
334 | { | 317 | { |
335 | struct AddressWrapper *w; | 318 | struct AddressWrapper *w; |
336 | struct AddressWrapper *wtmp; | 319 | struct AddressWrapper *wtmp; |
@@ -339,150 +322,145 @@ env_notify_address (void *cls, | |||
339 | 322 | ||
340 | if (GNUNET_YES == add_remove) | 323 | if (GNUNET_YES == add_remove) |
341 | { | 324 | { |
342 | addresses_reported ++; | 325 | addresses_reported++; |
343 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 326 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Adding address of length %u\n", |
344 | "Adding address of length %u\n", addrlen); | 327 | address->address_length); |
345 | 328 | ||
346 | for (wtmp = head; NULL != wtmp; wtmp = wtmp->next) | 329 | for (wtmp = head; NULL != wtmp; wtmp = wtmp->next) |
330 | { | ||
331 | if ((address->address_length == wtmp->address->address_length) && | ||
332 | (0 == memcmp (address->address, wtmp->address->address, address->address_length))) | ||
347 | { | 333 | { |
348 | if ((addrlen == wtmp->addrlen) && (0 == memcmp (addr, wtmp->addr, addrlen))) | 334 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
349 | { | 335 | "Duplicate address notification .... \n"); |
350 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 336 | return; |
351 | "Duplicate address notification .... \n"); | ||
352 | return; | ||
353 | } | ||
354 | } | ||
355 | |||
356 | w = GNUNET_new (struct AddressWrapper); | ||
357 | w->addr = GNUNET_malloc (addrlen); | ||
358 | w->addrlen = addrlen; | ||
359 | memcpy (w->addr, addr, addrlen); | ||
360 | GNUNET_CONTAINER_DLL_insert(head, tail, w); | ||
361 | got_reply = GNUNET_NO; | ||
362 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
363 | "Testing: address_to_string \n"); | ||
364 | w->addrstring = strdup (api->address_to_string (api, w->addr, w->addrlen)); | ||
365 | if (NULL == w->addrstring) | ||
366 | { | ||
367 | GNUNET_break (0); | ||
368 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
369 | "Plugin cannot convert address to string!\n"); | ||
370 | end_badly_now(); | ||
371 | return; | ||
372 | } | ||
373 | else | ||
374 | { | ||
375 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
376 | "Plugin added address `%s'\n", w->addrstring); | ||
377 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
378 | "Testing address_to_string: OK\n"); | ||
379 | } | ||
380 | |||
381 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
382 | "Testing: string_to_address \n"); | ||
383 | s2a = NULL; | ||
384 | s2a_len = 0; | ||
385 | if ((GNUNET_OK != api->string_to_address (api, w->addrstring, strlen (w->addrstring)+1, &s2a, &s2a_len)) || (NULL == s2a)) | ||
386 | { | ||
387 | GNUNET_break (0); | ||
388 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
389 | "Plugin cannot convert string to address!\n"); | ||
390 | end_badly_now(); | ||
391 | return; | ||
392 | } | ||
393 | |||
394 | /* | ||
395 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
396 | "Plugin creates `%s' %u\n",api->address_to_string (api, s2a, s2a_len), s2a_len); | ||
397 | |||
398 | int c1; | ||
399 | for (c1 = 0; c1 < s2a_len; c1++ ) | ||
400 | fprintf (stderr, "%u == %u\n", ((char *) s2a)[c1], ((char *) w->addr)[c1]); | ||
401 | */ | ||
402 | if (s2a_len != w->addrlen) | ||
403 | { | ||
404 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
405 | "Plugin creates different address length when converting address->string->address: %u != %u\n", w->addrlen, s2a_len); | ||
406 | } | ||
407 | else if (0 != memcmp (s2a, w->addr, s2a_len)) | ||
408 | { | ||
409 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
410 | "Plugin creates different address length when converting back and forth %i!\n", memcmp (s2a, w->addr, s2a_len)); | ||
411 | } | ||
412 | else | ||
413 | { | ||
414 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
415 | "Testing string_to_address: OK\n"); | ||
416 | } | ||
417 | GNUNET_free (s2a); | ||
418 | |||
419 | pretty_printers_running ++; | ||
420 | api->address_pretty_printer (api->cls, plugin, addr, addrlen, | ||
421 | GNUNET_YES, GNUNET_TIME_UNIT_MINUTES, | ||
422 | &address_pretty_printer_cb, | ||
423 | w); | ||
424 | |||
425 | if (GNUNET_OK != api->check_address (api->cls, w->addr, w->addrlen)) | ||
426 | { | ||
427 | GNUNET_break (0); | ||
428 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
429 | "Plugin refuses added address!\n"); | ||
430 | end_badly_now(); | ||
431 | return; | ||
432 | } | ||
433 | if (GNUNET_SCHEDULER_NO_TASK != timeout_wait) | ||
434 | { | ||
435 | GNUNET_SCHEDULER_cancel (timeout_wait); | ||
436 | timeout_wait = GNUNET_SCHEDULER_NO_TASK; | ||
437 | } | 337 | } |
338 | } | ||
339 | |||
340 | w = GNUNET_new (struct AddressWrapper); | ||
341 | w->address = GNUNET_HELLO_address_copy (address); | ||
342 | GNUNET_CONTAINER_DLL_insert(head, tail, w); | ||
343 | got_reply = GNUNET_NO; | ||
344 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Testing: address_to_string \n"); | ||
345 | w->addrstring = strdup ( | ||
346 | api->address_to_string (api, w->address->address, | ||
347 | w->address->address_length)); | ||
348 | if (NULL == w->addrstring) | ||
349 | { | ||
350 | GNUNET_break(0); | ||
351 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
352 | "Plugin cannot convert address to string!\n"); | ||
353 | end_badly_now (); | ||
354 | return; | ||
355 | } | ||
356 | else | ||
357 | { | ||
358 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Plugin added address `%s'\n", | ||
359 | w->addrstring); | ||
360 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Testing address_to_string: OK\n"); | ||
361 | } | ||
362 | |||
363 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Testing: string_to_address \n"); | ||
364 | s2a = NULL; | ||
365 | s2a_len = 0; | ||
366 | if ((GNUNET_OK | ||
367 | != api->string_to_address (api, w->addrstring, | ||
368 | strlen (w->addrstring) + 1, &s2a, &s2a_len)) || (NULL == s2a)) | ||
369 | { | ||
370 | GNUNET_break(0); | ||
371 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
372 | "Plugin cannot convert string to address!\n"); | ||
373 | end_badly_now (); | ||
374 | return; | ||
375 | } | ||
376 | |||
377 | /* | ||
378 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
379 | "Plugin creates `%s' %u\n",api->address_to_string (api, s2a, s2a_len), s2a_len); | ||
380 | |||
381 | int c1; | ||
382 | for (c1 = 0; c1 < s2a_len; c1++ ) | ||
383 | fprintf (stderr, "%u == %u\n", ((char *) s2a)[c1], ((char *) w->addr)[c1]); | ||
384 | */ | ||
385 | if (s2a_len != w->address->address_length) | ||
386 | { | ||
387 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
388 | "Plugin creates different address length when converting address->string->address: %u != %u\n", | ||
389 | w->address->address_length, s2a_len); | ||
390 | } | ||
391 | else if (0 != memcmp (s2a, w->address->address, s2a_len)) | ||
392 | { | ||
393 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
394 | "Plugin creates different address length when converting back and forth %i!\n", | ||
395 | memcmp (s2a, w->address->address, s2a_len)); | ||
396 | } | ||
397 | else | ||
398 | { | ||
399 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Testing string_to_address: OK\n"); | ||
400 | } | ||
401 | GNUNET_free(s2a); | ||
402 | |||
403 | pretty_printers_running++; | ||
404 | api->address_pretty_printer (api->cls, address->transport_name, address->address, address->address_length, GNUNET_YES, | ||
405 | GNUNET_TIME_UNIT_MINUTES, &address_pretty_printer_cb, w); | ||
406 | |||
407 | if (GNUNET_OK != api->check_address (api->cls, w->address->address, w->address->address_length)) | ||
408 | { | ||
409 | GNUNET_break(0); | ||
410 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin refuses added address!\n"); | ||
411 | end_badly_now (); | ||
412 | return; | ||
413 | } | ||
414 | if (GNUNET_SCHEDULER_NO_TASK != timeout_wait) | ||
415 | { | ||
416 | GNUNET_SCHEDULER_cancel (timeout_wait); | ||
417 | timeout_wait = GNUNET_SCHEDULER_NO_TASK; | ||
418 | } | ||
438 | 419 | ||
439 | timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL); | 420 | timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL ); |
440 | 421 | ||
441 | } | 422 | } |
442 | else if (GNUNET_NO == add_remove) | 423 | else if (GNUNET_NO == add_remove) |
443 | { | 424 | { |
444 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 425 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Removing address of length %u\n", |
445 | "Removing address of length %u\n", addrlen); | 426 | address->address_length); |
446 | 427 | ||
447 | w = head; | 428 | w = head; |
448 | while (NULL != w) | 429 | while (NULL != w) |
430 | { | ||
431 | if ((address->address_length == w->address->address_length) && | ||
432 | (0 == memcmp (w->address->address, address->address, address->address_length))) | ||
449 | { | 433 | { |
450 | if ((addrlen == w->addrlen) && (0 == memcmp (w->addr, addr, addrlen))) | 434 | break; |
451 | { | ||
452 | break; | ||
453 | } | ||
454 | w = w->next; | ||
455 | } | ||
456 | |||
457 | if (w == NULL) | ||
458 | { | ||
459 | GNUNET_break (0); | ||
460 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
461 | "Plugin removes address never added!\n"); | ||
462 | end_badly_now(); | ||
463 | return; | ||
464 | } | 435 | } |
436 | w = w->next; | ||
437 | } | ||
438 | |||
439 | if (w == NULL ) | ||
440 | { | ||
441 | GNUNET_break(0); | ||
442 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
443 | "Plugin removes address never added!\n"); | ||
444 | end_badly_now (); | ||
445 | return; | ||
446 | } | ||
465 | 447 | ||
466 | GNUNET_CONTAINER_DLL_remove (head, tail, w); | 448 | GNUNET_CONTAINER_DLL_remove(head, tail, w); |
467 | GNUNET_free (w->addr); | 449 | GNUNET_HELLO_address_free (w->address); |
468 | GNUNET_free (w->addrstring); | 450 | GNUNET_free(w->addrstring); |
469 | GNUNET_free (w); | 451 | GNUNET_free(w); |
470 | } | 452 | } |
471 | else | 453 | else |
472 | { | 454 | { |
473 | GNUNET_break (0); | 455 | GNUNET_break(0); |
474 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 456 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Invalid operation: %u\n", add_remove); |
475 | "Invalid operation: %u\n", add_remove); | 457 | end_badly_now (); |
476 | end_badly_now (); | 458 | return; |
477 | return; | ||
478 | } | 459 | } |
479 | } | 460 | } |
480 | 461 | ||
481 | |||
482 | static struct GNUNET_ATS_Information | 462 | static struct GNUNET_ATS_Information |
483 | env_get_address_type (void *cls, | 463 | env_get_address_type (void *cls, const struct sockaddr *addr, size_t addrlen) |
484 | const struct sockaddr *addr, | ||
485 | size_t addrlen) | ||
486 | { | 464 | { |
487 | struct GNUNET_ATS_Information ats; | 465 | struct GNUNET_ATS_Information ats; |
488 | ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); | 466 | ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); |
@@ -490,34 +468,27 @@ env_get_address_type (void *cls, | |||
490 | return ats; | 468 | return ats; |
491 | } | 469 | } |
492 | 470 | ||
493 | |||
494 | static const struct GNUNET_MessageHeader * | 471 | static const struct GNUNET_MessageHeader * |
495 | env_get_our_hello () | 472 | env_get_our_hello () |
496 | { | 473 | { |
497 | return (const struct GNUNET_MessageHeader *) hello; | 474 | return (const struct GNUNET_MessageHeader *) hello; |
498 | } | 475 | } |
499 | 476 | ||
500 | |||
501 | static void | 477 | static void |
502 | env_session_end (void *cls, | 478 | env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, |
503 | const struct GNUNET_PeerIdentity *peer, | 479 | struct Session * session) |
504 | struct Session * session) | ||
505 | { | 480 | { |
506 | } | 481 | } |
507 | 482 | ||
508 | |||
509 | static void | 483 | static void |
510 | env_update_metrics (void *cls, | 484 | env_update_metrics (void *cls, |
511 | const struct GNUNET_PeerIdentity *peer, | 485 | const struct GNUNET_HELLO_Address *address, |
512 | const void *address, | 486 | struct Session *session, |
513 | uint16_t address_len, | 487 | const struct GNUNET_ATS_Information *ats, |
514 | struct Session *session, | 488 | uint32_t ats_count) |
515 | const struct GNUNET_ATS_Information *ats, | ||
516 | uint32_t ats_count) | ||
517 | { | 489 | { |
518 | } | 490 | } |
519 | 491 | ||
520 | |||
521 | static void | 492 | static void |
522 | setup_plugin_environment () | 493 | setup_plugin_environment () |
523 | { | 494 | { |
@@ -534,15 +505,13 @@ setup_plugin_environment () | |||
534 | env.session_end = &env_session_end; | 505 | env.session_end = &env_session_end; |
535 | } | 506 | } |
536 | 507 | ||
537 | |||
538 | static int | 508 | static int |
539 | handle_helper_message (void *cls, void *client, | 509 | handle_helper_message (void *cls, void *client, |
540 | const struct GNUNET_MessageHeader *hdr) | 510 | const struct GNUNET_MessageHeader *hdr) |
541 | { | 511 | { |
542 | return GNUNET_OK; | 512 | return GNUNET_OK; |
543 | } | 513 | } |
544 | 514 | ||
545 | |||
546 | /** | 515 | /** |
547 | * Runs the test. | 516 | * Runs the test. |
548 | * | 517 | * |
@@ -550,10 +519,10 @@ handle_helper_message (void *cls, void *client, | |||
550 | * @param c configuration to use | 519 | * @param c configuration to use |
551 | */ | 520 | */ |
552 | static void | 521 | static void |
553 | run (void *cls, char *const *args, const char *cfgfile, | 522 | run (void *cls, char * const *args, const char *cfgfile, |
554 | const struct GNUNET_CONFIGURATION_Handle *c) | 523 | const struct GNUNET_CONFIGURATION_Handle *c) |
555 | { | 524 | { |
556 | char *const *argv = cls; | 525 | char * const *argv = cls; |
557 | unsigned long long tneigh; | 526 | unsigned long long tneigh; |
558 | char *keyfile; | 527 | char *keyfile; |
559 | char *plugin; | 528 | char *plugin; |
@@ -563,66 +532,62 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
563 | 532 | ||
564 | cfg = c; | 533 | cfg = c; |
565 | /* parse configuration */ | 534 | /* parse configuration */ |
566 | if ( (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (c, | 535 | if ((GNUNET_OK |
567 | "TRANSPORT", | 536 | != GNUNET_CONFIGURATION_get_value_number (c, "TRANSPORT", |
568 | "NEIGHBOUR_LIMIT", | 537 | "NEIGHBOUR_LIMIT", &tneigh)) |
569 | &tneigh)) || | 538 | || (GNUNET_OK |
570 | (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, | 539 | != GNUNET_CONFIGURATION_get_value_filename (c, "PEER", "PRIVATE_KEY", |
571 | "PEER", "PRIVATE_KEY", | 540 | &keyfile))) |
572 | &keyfile))) | 541 | { |
573 | { | 542 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
574 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 543 | "Transport service is lacking key configuration settings. Exiting.\n"); |
575 | "Transport service is lacking key configuration settings. Exiting.\n"); | ||
576 | return; | 544 | return; |
577 | } | 545 | } |
578 | 546 | ||
579 | if (NULL == (stats = GNUNET_STATISTICS_create ("transport", cfg))) | 547 | if (NULL == (stats = GNUNET_STATISTICS_create ("transport", cfg))) |
580 | { | 548 | { |
581 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 549 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
582 | "Could not create statistics. Exiting.\n"); | 550 | "Could not create statistics. Exiting.\n"); |
583 | GNUNET_free (keyfile); | 551 | GNUNET_free(keyfile); |
584 | end_badly_now (); | 552 | end_badly_now (); |
585 | return; | 553 | return; |
586 | } | 554 | } |
587 | 555 | ||
588 | if (GNUNET_OK != GNUNET_DISK_file_test (HOSTKEY_FILE)) | 556 | if (GNUNET_OK != GNUNET_DISK_file_test (HOSTKEY_FILE)) |
589 | { | 557 | { |
590 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 558 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Hostkey `%s' missing. Exiting.\n", |
591 | "Hostkey `%s' missing. Exiting.\n", | 559 | HOSTKEY_FILE); |
592 | HOSTKEY_FILE); | 560 | GNUNET_free(keyfile); |
593 | GNUNET_free (keyfile); | 561 | end_badly_now (); |
594 | end_badly_now (); | 562 | return; |
595 | return; | ||
596 | } | 563 | } |
597 | 564 | ||
598 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (keyfile)) | 565 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (keyfile)) |
599 | { | 566 | { |
600 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 567 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
601 | "Could not create a directory for hostkey `%s'. Exiting.\n", | 568 | "Could not create a directory for hostkey `%s'. Exiting.\n", keyfile); |
602 | keyfile); | 569 | GNUNET_free(keyfile); |
603 | GNUNET_free (keyfile); | 570 | end_badly_now (); |
604 | end_badly_now (); | 571 | return; |
605 | return; | ||
606 | } | 572 | } |
607 | 573 | ||
608 | if (GNUNET_OK != GNUNET_DISK_file_copy (HOSTKEY_FILE, keyfile)) | 574 | if (GNUNET_OK != GNUNET_DISK_file_copy (HOSTKEY_FILE, keyfile)) |
609 | { | 575 | { |
610 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 576 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
611 | "Could not copy hostkey `%s' to destination `%s'. Exiting.\n", | 577 | "Could not copy hostkey `%s' to destination `%s'. Exiting.\n", |
612 | HOSTKEY_FILE, keyfile); | 578 | HOSTKEY_FILE, keyfile); |
613 | GNUNET_free (keyfile); | 579 | GNUNET_free(keyfile); |
614 | end_badly_now (); | 580 | end_badly_now (); |
615 | return; | 581 | return; |
616 | } | 582 | } |
617 | 583 | ||
618 | |||
619 | max_connect_per_transport = (uint32_t) tneigh; | 584 | max_connect_per_transport = (uint32_t) tneigh; |
620 | my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile); | 585 | my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile); |
621 | GNUNET_free (keyfile); | 586 | GNUNET_free(keyfile); |
622 | if (NULL == my_private_key) | 587 | if (NULL == my_private_key) |
623 | { | 588 | { |
624 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 589 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
625 | "Could not access hostkey. Exiting.\n"); | 590 | "Could not access hostkey. Exiting.\n"); |
626 | end_badly_now (); | 591 | end_badly_now (); |
627 | return; | 592 | return; |
628 | } | 593 | } |
@@ -633,18 +598,18 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
633 | /* load plugins... */ | 598 | /* load plugins... */ |
634 | setup_plugin_environment (); | 599 | setup_plugin_environment (); |
635 | 600 | ||
636 | GNUNET_assert (strlen (argv[0]) > strlen ("test_plugin_")); | 601 | GNUNET_assert(strlen (argv[0]) > strlen ("test_plugin_")); |
637 | plugin = strstr(argv[0],"test_plugin_"); | 602 | plugin = strstr (argv[0], "test_plugin_"); |
638 | sep = strrchr(argv[0],'.'); | 603 | sep = strrchr (argv[0], '.'); |
639 | if (NULL == plugin) | 604 | if (NULL == plugin) |
640 | { | 605 | { |
641 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Not a valid test name\n"); | 606 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Not a valid test name\n"); |
642 | end_badly_now (); | 607 | end_badly_now (); |
643 | return; | 608 | return; |
644 | } | 609 | } |
645 | plugin += strlen ("test_plugin_"); | 610 | plugin += strlen ("test_plugin_"); |
646 | if (NULL != sep) | 611 | if (NULL != sep) |
647 | sep[0] = '\0'; | 612 | sep[0] = '\0'; |
648 | 613 | ||
649 | /* Hack for WLAN: start a second helper */ | 614 | /* Hack for WLAN: start a second helper */ |
650 | if (0 == strcmp (plugin, "wlan")) | 615 | if (0 == strcmp (plugin, "wlan")) |
@@ -654,77 +619,73 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
654 | helper_argv[1] = (char *) "2"; | 619 | helper_argv[1] = (char *) "2"; |
655 | helper_argv[2] = NULL; | 620 | helper_argv[2] = NULL; |
656 | suid_helper = GNUNET_HELPER_start (GNUNET_NO, | 621 | suid_helper = GNUNET_HELPER_start (GNUNET_NO, |
657 | "gnunet-helper-transport-wlan-dummy", | 622 | "gnunet-helper-transport-wlan-dummy", helper_argv, |
658 | helper_argv, | 623 | &handle_helper_message, NULL, NULL ); |
659 | &handle_helper_message, | ||
660 | NULL, | ||
661 | NULL); | ||
662 | } | 624 | } |
663 | 625 | ||
664 | /* Loading plugin */ | 626 | /* Loading plugin */ |
665 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Loading transport plugin %s\n", plugin); | 627 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Loading transport plugin %s\n", plugin); |
666 | GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", plugin); | 628 | GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", plugin); |
667 | api = GNUNET_PLUGIN_load (libname, &env); | 629 | api = GNUNET_PLUGIN_load (libname, &env); |
668 | if (api == NULL) | 630 | if (api == NULL ) |
669 | { | 631 | { |
670 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 632 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
671 | "Failed to load transport plugin for %s\n", plugin); | 633 | "Failed to load transport plugin for %s\n", plugin); |
672 | end_badly_now (); | 634 | end_badly_now (); |
673 | return; | 635 | return; |
674 | } | 636 | } |
675 | 637 | ||
676 | timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL); | 638 | timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL ); |
677 | 639 | ||
678 | /* Check if all functions are implemented */ | 640 | /* Check if all functions are implemented */ |
679 | if (NULL == api->address_pretty_printer) | 641 | if (NULL == api->address_pretty_printer) |
680 | { | 642 | { |
681 | GNUNET_break (0); | 643 | GNUNET_break(0); |
682 | end_badly_now (); | 644 | end_badly_now (); |
683 | return; | 645 | return; |
684 | } | 646 | } |
685 | if (NULL == api->address_to_string) | 647 | if (NULL == api->address_to_string) |
686 | { | 648 | { |
687 | GNUNET_break (0); | 649 | GNUNET_break(0); |
688 | end_badly_now (); | 650 | end_badly_now (); |
689 | return; | 651 | return; |
690 | } | 652 | } |
691 | GNUNET_assert (NULL != api->check_address); | 653 | GNUNET_assert(NULL != api->check_address); |
692 | if (NULL == api->check_address) | 654 | if (NULL == api->check_address) |
693 | { | 655 | { |
694 | GNUNET_break (0); | 656 | GNUNET_break(0); |
695 | end_badly_now (); | 657 | end_badly_now (); |
696 | return; | 658 | return; |
697 | } | 659 | } |
698 | GNUNET_assert (NULL != api->disconnect_peer); | 660 | GNUNET_assert(NULL != api->disconnect_peer); |
699 | if (NULL == api->disconnect_peer) | 661 | if (NULL == api->disconnect_peer) |
700 | { | 662 | { |
701 | GNUNET_break (0); | 663 | GNUNET_break(0); |
702 | end_badly_now (); | 664 | end_badly_now (); |
703 | return; | 665 | return; |
704 | } | 666 | } |
705 | GNUNET_assert (NULL != api->get_session); | 667 | GNUNET_assert(NULL != api->get_session); |
706 | if (NULL == api->get_session) | 668 | if (NULL == api->get_session) |
707 | { | 669 | { |
708 | GNUNET_break (0); | 670 | GNUNET_break(0); |
709 | end_badly_now (); | 671 | end_badly_now (); |
710 | return; | 672 | return; |
711 | } | 673 | } |
712 | if (NULL == api->address_pretty_printer) | 674 | if (NULL == api->address_pretty_printer) |
713 | { | 675 | { |
714 | GNUNET_break (0); | 676 | GNUNET_break(0); |
715 | end_badly_now (); | 677 | end_badly_now (); |
716 | return; | 678 | return; |
717 | } | 679 | } |
718 | if (NULL == api->string_to_address) | 680 | if (NULL == api->string_to_address) |
719 | { | 681 | { |
720 | GNUNET_break (0); | 682 | GNUNET_break(0); |
721 | end_badly_now (); | 683 | end_badly_now (); |
722 | return; | 684 | return; |
723 | } | 685 | } |
724 | 686 | ||
725 | } | 687 | } |
726 | 688 | ||
727 | |||
728 | /** | 689 | /** |
729 | * The main function for the test | 690 | * The main function for the test |
730 | * | 691 | * |
@@ -733,32 +694,22 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
733 | * @return 0 ok, 1 on error | 694 | * @return 0 ok, 1 on error |
734 | */ | 695 | */ |
735 | int | 696 | int |
736 | main (int argc, char *const *argv) | 697 | main (int argc, char * const *argv) |
737 | { | 698 | { |
738 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | 699 | static struct GNUNET_GETOPT_CommandLineOption options[] = { |
739 | GNUNET_GETOPT_OPTION_END | 700 | GNUNET_GETOPT_OPTION_END }; |
740 | }; | ||
741 | int ret; | 701 | int ret; |
742 | 702 | ||
743 | GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-plugin-transport"); | 703 | GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-plugin-transport"); |
744 | 704 | ||
745 | char *const argv_prog[] = { | 705 | char * const argv_prog[] = { "test_plugin_transport", "-c", |
746 | "test_plugin_transport", | 706 | "test_plugin_transport_data.conf", NULL }; |
747 | "-c", | 707 | GNUNET_log_setup ("test-plugin-transport", "WARNING", NULL ); |
748 | "test_plugin_transport_data.conf", | 708 | ok = 1; /* set to fail */ |
749 | NULL | 709 | ret = |
750 | }; | 710 | (GNUNET_OK |
751 | GNUNET_log_setup ("test-plugin-transport", | 711 | == GNUNET_PROGRAM_run (3, argv_prog, "test-plugin-transport", |
752 | "WARNING", | 712 | "testcase", options, &run, (void *) argv)) ? ok : 1; |
753 | NULL); | ||
754 | ok = 1; /* set to fail */ | ||
755 | ret = (GNUNET_OK == GNUNET_PROGRAM_run (3, | ||
756 | argv_prog, | ||
757 | "test-plugin-transport", | ||
758 | "testcase", | ||
759 | options, | ||
760 | &run, | ||
761 | (void *) argv)) ? ok : 1; | ||
762 | GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-plugin-transport"); | 713 | GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-plugin-transport"); |
763 | return ret; | 714 | return ret; |
764 | } | 715 | } |