summaryrefslogtreecommitdiff
path: root/src/transport/test_plugin_transport.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/test_plugin_transport.c')
-rw-r--r--src/transport/test_plugin_transport.c826
1 files changed, 416 insertions, 410 deletions
diff --git a/src/transport/test_plugin_transport.c b/src/transport/test_plugin_transport.c
index 686938afc..ceb4333ac 100644
--- a/src/transport/test_plugin_transport.c
+++ b/src/transport/test_plugin_transport.c
@@ -36,8 +36,8 @@
36/** 36/**
37 * How long until we give up on transmitting the message? 37 * How long until we give up on transmitting the message?
38 */ 38 */
39#define WAIT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) 39#define WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
40#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) 40#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
41 41
42#define HOSTKEY_FILE "test_plugin_hostkey.ecc" 42#define HOSTKEY_FILE "test_plugin_hostkey.ecc"
43 43
@@ -89,12 +89,12 @@ struct GNUNET_HELPER_Handle *suid_helper;
89/** 89/**
90 * Timeout task 90 * Timeout task
91 */ 91 */
92static struct GNUNET_SCHEDULER_Task * timeout_endbadly; 92static struct GNUNET_SCHEDULER_Task *timeout_endbadly;
93 93
94/** 94/**
95 * Timeout task 95 * Timeout task
96 */ 96 */
97static struct GNUNET_SCHEDULER_Task * timeout_wait; 97static struct GNUNET_SCHEDULER_Task *timeout_wait;
98 98
99/** 99/**
100 * Library name 100 * Library name
@@ -120,7 +120,8 @@ unsigned int pretty_printers_running;
120 */ 120 */
121static int ok; 121static int ok;
122 122
123struct AddressWrapper { 123struct AddressWrapper
124{
124 struct AddressWrapper *next; 125 struct AddressWrapper *next;
125 126
126 struct AddressWrapper *prev; 127 struct AddressWrapper *prev;
@@ -134,7 +135,7 @@ struct AddressWrapper {
134 135
135 136
136static void 137static void
137end() 138end ()
138{ 139{
139 struct AddressWrapper *w; 140 struct AddressWrapper *w;
140 int c = 0; 141 int c = 0;
@@ -142,153 +143,154 @@ end()
142 ok = 0; 143 ok = 0;
143 144
144 if (NULL != timeout_endbadly) 145 if (NULL != timeout_endbadly)
145 { 146 {
146 GNUNET_SCHEDULER_cancel(timeout_endbadly); 147 GNUNET_SCHEDULER_cancel (timeout_endbadly);
147 timeout_endbadly = NULL; 148 timeout_endbadly = NULL;
148 } 149 }
149 if (NULL != api) 150 if (NULL != api)
150 GNUNET_PLUGIN_unload(libname, api); 151 GNUNET_PLUGIN_unload (libname, api);
151 152
152 while (NULL != head) 153 while (NULL != head)
153 { 154 {
154 w = head; 155 w = head;
155 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 156 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
156 "Plugin did not remove address `%s'\n", 157 "Plugin did not remove address `%s'\n",
157 w->addrstring); 158 w->addrstring);
158 GNUNET_CONTAINER_DLL_remove(head, tail, w); 159 GNUNET_CONTAINER_DLL_remove (head, tail, w);
159 c++; 160 c++;
160 GNUNET_HELLO_address_free(w->address); 161 GNUNET_HELLO_address_free (w->address);
161 GNUNET_free(w->addrstring); 162 GNUNET_free (w->addrstring);
162 GNUNET_free(w); 163 GNUNET_free (w);
163 } 164 }
164 if (c > 0) 165 if (c > 0)
165 { 166 {
166 GNUNET_break(0); 167 GNUNET_break (0);
167 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove %u addresses \n", 168 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
168 c); 169 "Plugin did not remove %u addresses \n",
169 ok = 1; 170 c);
170 } 171 ok = 1;
171 172 }
172 GNUNET_free(libname); 173
174 GNUNET_free (libname);
173 libname = NULL; 175 libname = NULL;
174 GNUNET_STATISTICS_destroy(stats, GNUNET_NO); 176 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
175 stats = NULL; 177 stats = NULL;
176 178
177 if (NULL != suid_helper) 179 if (NULL != suid_helper)
178 { 180 {
179 GNUNET_HELPER_stop(suid_helper, GNUNET_NO); 181 GNUNET_HELPER_stop (suid_helper, GNUNET_NO);
180 suid_helper = NULL; 182 suid_helper = NULL;
181 } 183 }
182} 184}
183 185
184 186
185static void 187static void
186end_badly(void *cls) 188end_badly (void *cls)
187{ 189{
188 struct AddressWrapper *w; 190 struct AddressWrapper *w;
189 int c = 0; 191 int c = 0;
190 192
191 timeout_endbadly = NULL; 193 timeout_endbadly = NULL;
192 if (NULL != timeout_wait) 194 if (NULL != timeout_wait)
193 { 195 {
194 GNUNET_SCHEDULER_cancel(timeout_wait); 196 GNUNET_SCHEDULER_cancel (timeout_wait);
195 timeout_wait = NULL; 197 timeout_wait = NULL;
196 } 198 }
197 199
198 if (pretty_printers_running > 0) 200 if (pretty_printers_running > 0)
199 { 201 {
200 timeout_endbadly = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, 202 timeout_endbadly = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
201 &end_badly, &ok); 203 &end_badly, &ok);
202 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 204 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
203 "Have pending calls to pretty_printer ... deferring shutdown\n"); 205 "Have pending calls to pretty_printer ... deferring shutdown\n");
204 return; 206 return;
205 } 207 }
206 208
207 if (NULL != cls) 209 if (NULL != cls)
208 { 210 {
209 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 211 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
210 "Test took too long to execute, timeout .... \n"); 212 "Test took too long to execute, timeout .... \n");
211 } 213 }
212 214
213 if (NULL != libname) 215 if (NULL != libname)
214 { 216 {
215 if (NULL != api) 217 if (NULL != api)
216 GNUNET_PLUGIN_unload(libname, api); 218 GNUNET_PLUGIN_unload (libname, api);
217 GNUNET_free(libname); 219 GNUNET_free (libname);
218 libname = NULL; 220 libname = NULL;
219 } 221 }
220 222
221 while (NULL != head) 223 while (NULL != head)
222 { 224 {
223 w = head; 225 w = head;
224 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove address `%s'\n", 226 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove address `%s'\n",
225 w->addrstring); 227 w->addrstring);
226 GNUNET_CONTAINER_DLL_remove(head, tail, w); 228 GNUNET_CONTAINER_DLL_remove (head, tail, w);
227 c++; 229 c++;
228 GNUNET_HELLO_address_free(w->address); 230 GNUNET_HELLO_address_free (w->address);
229 if (NULL != w->test_task) 231 if (NULL != w->test_task)
230 GNUNET_SCHEDULER_cancel(w->test_task); 232 GNUNET_SCHEDULER_cancel (w->test_task);
231 GNUNET_free(w->addrstring); 233 GNUNET_free (w->addrstring);
232 GNUNET_free(w); 234 GNUNET_free (w);
233 } 235 }
234 if (c > 0) 236 if (c > 0)
235 { 237 {
236 GNUNET_break(0); 238 GNUNET_break (0);
237 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove %u addresses\n", 239 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove %u addresses\n",
238 c); 240 c);
239 } 241 }
240 242
241 if (NULL != stats) 243 if (NULL != stats)
242 { 244 {
243 GNUNET_STATISTICS_destroy(stats, GNUNET_NO); 245 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
244 stats = NULL; 246 stats = NULL;
245 } 247 }
246 248
247 if (NULL != suid_helper) 249 if (NULL != suid_helper)
248 { 250 {
249 GNUNET_HELPER_stop(suid_helper, GNUNET_NO); 251 GNUNET_HELPER_stop (suid_helper, GNUNET_NO);
250 suid_helper = NULL; 252 suid_helper = NULL;
251 } 253 }
252 254
253 ok = 1; 255 ok = 1;
254} 256}
255 257
256static void 258static void
257wait_end(void *cls) 259wait_end (void *cls)
258{ 260{
259 timeout_wait = NULL; 261 timeout_wait = NULL;
260 if (0 == addresses_reported) 262 if (0 == addresses_reported)
261 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 263 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
262 "Plugin did not report any addresses, could not check address conversion functions\n"); 264 "Plugin did not report any addresses, could not check address conversion functions\n");
263 end(); 265 end ();
264} 266}
265 267
266 268
267static void 269static void
268end_badly_now() 270end_badly_now ()
269{ 271{
270 if (NULL != timeout_wait) 272 if (NULL != timeout_wait)
271 { 273 {
272 GNUNET_SCHEDULER_cancel(timeout_wait); 274 GNUNET_SCHEDULER_cancel (timeout_wait);
273 timeout_wait = NULL; 275 timeout_wait = NULL;
274 } 276 }
275 if (NULL != timeout_endbadly) 277 if (NULL != timeout_endbadly)
276 { 278 {
277 GNUNET_SCHEDULER_cancel(timeout_endbadly); 279 GNUNET_SCHEDULER_cancel (timeout_endbadly);
278 timeout_endbadly = NULL; 280 timeout_endbadly = NULL;
279 } 281 }
280 timeout_endbadly = GNUNET_SCHEDULER_add_now(&end_badly, NULL); 282 timeout_endbadly = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
281} 283}
282 284
283 285
284static struct GNUNET_TIME_Relative 286static struct GNUNET_TIME_Relative
285env_receive(void *cls, 287env_receive (void *cls,
286 const struct GNUNET_HELLO_Address *address, 288 const struct GNUNET_HELLO_Address *address,
287 struct GNUNET_ATS_Session *session, 289 struct GNUNET_ATS_Session *session,
288 const struct GNUNET_MessageHeader *message) 290 const struct GNUNET_MessageHeader *message)
289{ 291{
290 /* do nothing */ 292 /* do nothing */
291 return GNUNET_TIME_relative_get_zero_(); 293 return GNUNET_TIME_relative_get_zero_ ();
292} 294}
293 295
294static int got_reply; 296static int got_reply;
@@ -303,28 +305,28 @@ static int got_reply;
303 * @param res result code 305 * @param res result code
304 */ 306 */
305static void 307static void
306address_pretty_printer_cb(void *cls, const char *address, int res) 308address_pretty_printer_cb (void *cls, const char *address, int res)
307{ 309{
308 if (NULL != address) 310 if (NULL != address)
309 { 311 {
310 got_reply = GNUNET_YES; 312 got_reply = GNUNET_YES;
311 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Pretty address : `%s'\n", address); 313 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Pretty address : `%s'\n", address);
312 pretty_printers_running--; 314 pretty_printers_running--;
313 } 315 }
314 else 316 else
317 {
318 if (GNUNET_NO == got_reply)
315 { 319 {
316 if (GNUNET_NO == got_reply) 320 pretty_printers_running--;
317 { 321 GNUNET_break (0);
318 pretty_printers_running--; 322 end_badly_now ();
319 GNUNET_break(0);
320 end_badly_now();
321 }
322 } 323 }
324 }
323} 325}
324 326
325 327
326static void 328static void
327test_addr_string(void *cls) 329test_addr_string (void *cls)
328{ 330{
329 struct AddressWrapper *w = cls; 331 struct AddressWrapper *w = cls;
330 void *s2a; 332 void *s2a;
@@ -332,40 +334,41 @@ test_addr_string(void *cls)
332 334
333 w->test_task = NULL; 335 w->test_task = NULL;
334 336
335 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 337 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
336 "Testing: address_to_string \n"); 338 "Testing: address_to_string \n");
337 w->addrstring = GNUNET_strdup(api->address_to_string(api, 339 w->addrstring = GNUNET_strdup (api->address_to_string (api,
338 w->address->address, 340 w->address->address,
339 w->address->address_length)); 341 w->address->
342 address_length));
340 if (NULL == w->addrstring) 343 if (NULL == w->addrstring)
341 { 344 {
342 GNUNET_break(0); 345 GNUNET_break (0);
343 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 346 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
344 "Plugin cannot convert address to string!\n"); 347 "Plugin cannot convert address to string!\n");
345 end_badly_now(); 348 end_badly_now ();
346 return; 349 return;
347 } 350 }
348 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 351 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
349 "Plugin added address `%s'\n", 352 "Plugin added address `%s'\n",
350 w->addrstring); 353 w->addrstring);
351 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 354 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
352 "Testing address_to_string: OK\n"); 355 "Testing address_to_string: OK\n");
353 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 356 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
354 "Testing: string_to_address \n"); 357 "Testing: string_to_address \n");
355 s2a = NULL; 358 s2a = NULL;
356 s2a_len = 0; 359 s2a_len = 0;
357 if ((GNUNET_OK != 360 if ((GNUNET_OK !=
358 api->string_to_address(api, w->addrstring, 361 api->string_to_address (api, w->addrstring,
359 strlen(w->addrstring) + 1, 362 strlen (w->addrstring) + 1,
360 &s2a, &s2a_len)) || 363 &s2a, &s2a_len)) ||
361 (NULL == s2a)) 364 (NULL == s2a))
362 { 365 {
363 GNUNET_break(0); 366 GNUNET_break (0);
364 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 367 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
365 "Plugin cannot convert string to address!\n"); 368 "Plugin cannot convert string to address!\n");
366 end_badly_now(); 369 end_badly_now ();
367 return; 370 return;
368 } 371 }
369 372
370 /* 373 /*
371 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 374 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -376,164 +379,166 @@ test_addr_string(void *cls)
376 fprintf (stderr, "%u == %u\n", ((char *) s2a)[c1], ((char *) w->addr)[c1]); 379 fprintf (stderr, "%u == %u\n", ((char *) s2a)[c1], ((char *) w->addr)[c1]);
377 */ 380 */
378 if (s2a_len != w->address->address_length) 381 if (s2a_len != w->address->address_length)
379 { 382 {
380 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 383 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
381 "Plugin creates different address length when converting address->string->address: %u != %u\n", 384 "Plugin creates different address length when converting address->string->address: %u != %u\n",
382 (unsigned int)w->address->address_length, 385 (unsigned int) w->address->address_length,
383 (unsigned int)s2a_len); 386 (unsigned int) s2a_len);
384 } 387 }
385 else if (0 != memcmp(s2a, w->address->address, s2a_len)) 388 else if (0 != memcmp (s2a, w->address->address, s2a_len))
386 { 389 {
387 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 390 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
388 "Plugin creates different address length when converting back and forth %i!\n", 391 "Plugin creates different address length when converting back and forth %i!\n",
389 memcmp(s2a, 392 memcmp (s2a,
390 w->address->address, 393 w->address->address,
391 s2a_len)); 394 s2a_len));
392 } 395 }
393 else 396 else
394 { 397 {
395 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 398 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
396 "Testing string_to_address: OK\n"); 399 "Testing string_to_address: OK\n");
397 } 400 }
398 GNUNET_free(s2a); 401 GNUNET_free (s2a);
399 402
400 pretty_printers_running++; 403 pretty_printers_running++;
401 api->address_pretty_printer(api->cls, 404 api->address_pretty_printer (api->cls,
402 w->address->transport_name, 405 w->address->transport_name,
403 w->address->address, 406 w->address->address,
404 w->address->address_length, 407 w->address->address_length,
405 GNUNET_YES, 408 GNUNET_YES,
406 GNUNET_TIME_UNIT_MINUTES, 409 GNUNET_TIME_UNIT_MINUTES,
407 &address_pretty_printer_cb, w); 410 &address_pretty_printer_cb, w);
408 411
409 if (GNUNET_OK != 412 if (GNUNET_OK !=
410 api->check_address(api->cls, 413 api->check_address (api->cls,
411 w->address->address, 414 w->address->address,
412 w->address->address_length)) 415 w->address->address_length))
413 { 416 {
414 GNUNET_break(0); 417 GNUNET_break (0);
415 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 418 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
416 "Plugin refuses added address!\n"); 419 "Plugin refuses added address!\n");
417 end_badly_now(); 420 end_badly_now ();
418 return; 421 return;
419 } 422 }
420 if (NULL != timeout_wait) 423 if (NULL != timeout_wait)
421 { 424 {
422 GNUNET_SCHEDULER_cancel(timeout_wait); 425 GNUNET_SCHEDULER_cancel (timeout_wait);
423 timeout_wait = NULL; 426 timeout_wait = NULL;
424 } 427 }
425 timeout_wait = GNUNET_SCHEDULER_add_delayed(WAIT, &wait_end, NULL); 428 timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL);
426} 429}
427 430
428 431
429static void 432static void
430env_notify_address(void *cls, 433env_notify_address (void *cls,
431 int add_remove, 434 int add_remove,
432 const struct GNUNET_HELLO_Address *address) 435 const struct GNUNET_HELLO_Address *address)
433{ 436{
434 struct AddressWrapper *w; 437 struct AddressWrapper *w;
435 struct AddressWrapper *wtmp; 438 struct AddressWrapper *wtmp;
436 439
437 if (GNUNET_YES == add_remove) 440 if (GNUNET_YES == add_remove)
438 { 441 {
439 addresses_reported++; 442 addresses_reported++;
440 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 443 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
441 "Adding address of length %u\n", 444 "Adding address of length %u\n",
442 (unsigned int)address->address_length); 445 (unsigned int) address->address_length);
443 446
444 for (wtmp = head; NULL != wtmp; wtmp = wtmp->next) 447 for (wtmp = head; NULL != wtmp; wtmp = wtmp->next)
445 { 448 {
446 if ((address->address_length == wtmp->address->address_length) && 449 if ((address->address_length == wtmp->address->address_length) &&
447 (0 == memcmp(address->address, wtmp->address->address, address->address_length))) 450 (0 == memcmp (address->address, wtmp->address->address,
448 { 451 address->address_length)))
449 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 452 {
450 "Duplicate address notification .... \n"); 453 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
451 return; 454 "Duplicate address notification .... \n");
452 } 455 return;
453 } 456 }
454 457 }
455 w = GNUNET_new(struct AddressWrapper); 458
456 w->address = GNUNET_HELLO_address_copy(address); 459 w = GNUNET_new (struct AddressWrapper);
457 GNUNET_CONTAINER_DLL_insert(head, tail, w); 460 w->address = GNUNET_HELLO_address_copy (address);
458 got_reply = GNUNET_NO; 461 GNUNET_CONTAINER_DLL_insert (head, tail, w);
459 w->test_task = GNUNET_SCHEDULER_add_now(&test_addr_string, 462 got_reply = GNUNET_NO;
460 w); 463 w->test_task = GNUNET_SCHEDULER_add_now (&test_addr_string,
461 return; 464 w);
462 } 465 return;
466 }
463 467
464 if (GNUNET_NO == add_remove) 468 if (GNUNET_NO == add_remove)
465 { 469 {
466 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 470 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
467 "Removing address of length %u\n", 471 "Removing address of length %u\n",
468 (unsigned int)address->address_length); 472 (unsigned int) address->address_length);
469 w = head; 473 w = head;
470 while (NULL != w) 474 while (NULL != w)
471 { 475 {
472 if ((address->address_length == w->address->address_length) && 476 if ((address->address_length == w->address->address_length) &&
473 (0 == memcmp(w->address->address, address->address, address->address_length))) 477 (0 == memcmp (w->address->address, address->address,
474 { 478 address->address_length)))
475 break; 479 {
476 } 480 break;
477 w = w->next; 481 }
478 } 482 w = w->next;
479 483 }
480 if (w == NULL) 484
481 { 485 if (w == NULL)
482 GNUNET_break(0); 486 {
483 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 487 GNUNET_break (0);
484 "Plugin removes address never added!\n"); 488 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
485 end_badly_now(); 489 "Plugin removes address never added!\n");
486 return; 490 end_badly_now ();
487 }
488
489 GNUNET_CONTAINER_DLL_remove(head, tail, w);
490 GNUNET_HELLO_address_free(w->address);
491 GNUNET_free(w->addrstring);
492 GNUNET_free(w);
493 return; 491 return;
494 } 492 }
495 GNUNET_break(0); 493
496 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 494 GNUNET_CONTAINER_DLL_remove (head, tail, w);
497 "Invalid operation: %u\n", 495 GNUNET_HELLO_address_free (w->address);
498 add_remove); 496 GNUNET_free (w->addrstring);
499 end_badly_now(); 497 GNUNET_free (w);
498 return;
499 }
500 GNUNET_break (0);
501 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
502 "Invalid operation: %u\n",
503 add_remove);
504 end_badly_now ();
500} 505}
501 506
502 507
503static enum GNUNET_NetworkType 508static enum GNUNET_NetworkType
504env_get_address_type(void *cls, 509env_get_address_type (void *cls,
505 const struct sockaddr *addr, 510 const struct sockaddr *addr,
506 size_t addrlen) 511 size_t addrlen)
507{ 512{
508 return GNUNET_NT_LOOPBACK; 513 return GNUNET_NT_LOOPBACK;
509} 514}
510 515
511 516
512static const struct GNUNET_MessageHeader * 517static const struct GNUNET_MessageHeader *
513env_get_our_hello() 518env_get_our_hello ()
514{ 519{
515 return (const struct GNUNET_MessageHeader *)hello; 520 return (const struct GNUNET_MessageHeader *) hello;
516} 521}
517 522
518 523
519static void 524static void
520env_session_end(void *cls, 525env_session_end (void *cls,
521 const struct GNUNET_HELLO_Address *address, 526 const struct GNUNET_HELLO_Address *address,
522 struct GNUNET_ATS_Session *session) 527 struct GNUNET_ATS_Session *session)
523{ 528{
524} 529}
525 530
526 531
527static void 532static void
528env_update_distance(void *cls, 533env_update_distance (void *cls,
529 const struct GNUNET_HELLO_Address *address, 534 const struct GNUNET_HELLO_Address *address,
530 uint32_t distance) 535 uint32_t distance)
531{ 536{
532} 537}
533 538
534 539
535static void 540static void
536setup_plugin_environment() 541setup_plugin_environment ()
537{ 542{
538 env.cfg = cfg; 543 env.cfg = cfg;
539 env.cls = &env; 544 env.cls = &env;
@@ -550,8 +555,8 @@ setup_plugin_environment()
550 555
551 556
552static int 557static int
553handle_helper_message(void *cls, 558handle_helper_message (void *cls,
554 const struct GNUNET_MessageHeader *hdr) 559 const struct GNUNET_MessageHeader *hdr)
555{ 560{
556 return GNUNET_OK; 561 return GNUNET_OK;
557} 562}
@@ -564,184 +569,185 @@ handle_helper_message(void *cls,
564 * @param c configuration to use 569 * @param c configuration to use
565 */ 570 */
566static void 571static void
567run(void *cls, 572run (void *cls,
568 char * const *args, 573 char *const *args,
569 const char *cfgfile, 574 const char *cfgfile,
570 const struct GNUNET_CONFIGURATION_Handle *c) 575 const struct GNUNET_CONFIGURATION_Handle *c)
571{ 576{
572 char * const *argv = cls; 577 char *const *argv = cls;
573 unsigned long long tneigh; 578 unsigned long long tneigh;
574 char *keyfile; 579 char *keyfile;
575 char *plugin; 580 char *plugin;
576 char *sep; 581 char *sep;
577 582
578 timeout_endbadly = GNUNET_SCHEDULER_add_delayed(TIMEOUT, 583 timeout_endbadly = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
579 &end_badly, 584 &end_badly,
580 &ok); 585 &ok);
581 cfg = c; 586 cfg = c;
582 /* parse configuration */ 587 /* parse configuration */
583 if ((GNUNET_OK != 588 if ((GNUNET_OK !=
584 GNUNET_CONFIGURATION_get_value_number(c, 589 GNUNET_CONFIGURATION_get_value_number (c,
585 "TRANSPORT", 590 "TRANSPORT",
586 "NEIGHBOUR_LIMIT", 591 "NEIGHBOUR_LIMIT",
587 &tneigh)) || 592 &tneigh)) ||
588 (GNUNET_OK != 593 (GNUNET_OK !=
589 GNUNET_CONFIGURATION_get_value_filename(c, 594 GNUNET_CONFIGURATION_get_value_filename (c,
590 "PEER", 595 "PEER",
591 "PRIVATE_KEY", 596 "PRIVATE_KEY",
592 &keyfile))) 597 &keyfile)))
593 { 598 {
594 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 599 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
595 "Transport service is lacking key configuration settings. Exiting.\n"); 600 "Transport service is lacking key configuration settings. Exiting.\n");
596 return; 601 return;
597 } 602 }
598 603
599 if (NULL == (stats = GNUNET_STATISTICS_create("transport", 604 if (NULL == (stats = GNUNET_STATISTICS_create ("transport",
600 cfg))) 605 cfg)))
601 { 606 {
602 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 607 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
603 "Could not create statistics. Exiting.\n"); 608 "Could not create statistics. Exiting.\n");
604 GNUNET_free(keyfile); 609 GNUNET_free (keyfile);
605 end_badly_now(); 610 end_badly_now ();
606 return; 611 return;
607 } 612 }
608 613
609 if (GNUNET_OK != GNUNET_DISK_file_test(HOSTKEY_FILE)) 614 if (GNUNET_OK != GNUNET_DISK_file_test (HOSTKEY_FILE))
610 { 615 {
611 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 616 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
612 "Hostkey `%s' missing. Exiting.\n", 617 "Hostkey `%s' missing. Exiting.\n",
613 HOSTKEY_FILE); 618 HOSTKEY_FILE);
614 GNUNET_free(keyfile); 619 GNUNET_free (keyfile);
615 end_badly_now(); 620 end_badly_now ();
616 return; 621 return;
617 } 622 }
618 623
619 if (GNUNET_OK != 624 if (GNUNET_OK !=
620 GNUNET_DISK_directory_create_for_file(keyfile)) 625 GNUNET_DISK_directory_create_for_file (keyfile))
621 { 626 {
622 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 627 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
623 "Could not create a directory for hostkey `%s'. Exiting.\n", 628 "Could not create a directory for hostkey `%s'. Exiting.\n",
624 keyfile); 629 keyfile);
625 GNUNET_free(keyfile); 630 GNUNET_free (keyfile);
626 end_badly_now(); 631 end_badly_now ();
627 return; 632 return;
628 } 633 }
629 634
630 if (GNUNET_OK != 635 if (GNUNET_OK !=
631 GNUNET_DISK_file_copy(HOSTKEY_FILE, 636 GNUNET_DISK_file_copy (HOSTKEY_FILE,
632 keyfile)) 637 keyfile))
633 { 638 {
634 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 639 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
635 "Could not copy hostkey `%s' to destination `%s'. Exiting.\n", 640 "Could not copy hostkey `%s' to destination `%s'. Exiting.\n",
636 HOSTKEY_FILE, 641 HOSTKEY_FILE,
637 keyfile); 642 keyfile);
638 GNUNET_free(keyfile); 643 GNUNET_free (keyfile);
639 end_badly_now(); 644 end_badly_now ();
640 return; 645 return;
641 } 646 }
642 647
643 max_connect_per_transport = (uint32_t)tneigh; 648 max_connect_per_transport = (uint32_t) tneigh;
644 my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_file(keyfile); 649 my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile);
645 GNUNET_free(keyfile); 650 GNUNET_free (keyfile);
646 if (NULL == my_private_key) 651 if (NULL == my_private_key)
647 { 652 {
648 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 653 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
649 "Could not access hostkey. Exiting.\n"); 654 "Could not access hostkey. Exiting.\n");
650 end_badly_now(); 655 end_badly_now ();
651 return; 656 return;
652 } 657 }
653 GNUNET_CRYPTO_eddsa_key_get_public(my_private_key, &my_identity.public_key); 658 GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_identity.public_key);
654 659
655 hello = GNUNET_HELLO_create(&my_identity.public_key, NULL, NULL, GNUNET_NO); 660 hello = GNUNET_HELLO_create (&my_identity.public_key, NULL, NULL, GNUNET_NO);
656 661
657 /* load plugins... */ 662 /* load plugins... */
658 setup_plugin_environment(); 663 setup_plugin_environment ();
659 664
660 GNUNET_assert(strlen(argv[0]) > strlen("test_plugin_")); 665 GNUNET_assert (strlen (argv[0]) > strlen ("test_plugin_"));
661 plugin = strstr(argv[0], "test_plugin_"); 666 plugin = strstr (argv[0], "test_plugin_");
662 sep = strrchr(argv[0], '.'); 667 sep = strrchr (argv[0], '.');
663 if (NULL == plugin) 668 if (NULL == plugin)
664 { 669 {
665 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Not a valid test name\n"); 670 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Not a valid test name\n");
666 end_badly_now(); 671 end_badly_now ();
667 return; 672 return;
668 } 673 }
669 plugin += strlen("test_plugin_"); 674 plugin += strlen ("test_plugin_");
670 if (NULL != sep) 675 if (NULL != sep)
671 sep[0] = '\0'; 676 sep[0] = '\0';
672 677
673 /* Hack for WLAN: start a second helper */ 678 /* Hack for WLAN: start a second helper */
674 if (0 == strcmp(plugin, "wlan")) 679 if (0 == strcmp (plugin, "wlan"))
675 { 680 {
676 char * helper_argv[3]; 681 char *helper_argv[3];
677 helper_argv[0] = (char *)"gnunet-helper-transport-wlan-dummy"; 682 helper_argv[0] = (char *) "gnunet-helper-transport-wlan-dummy";
678 helper_argv[1] = (char *)"2"; 683 helper_argv[1] = (char *) "2";
679 helper_argv[2] = NULL; 684 helper_argv[2] = NULL;
680 suid_helper = GNUNET_HELPER_start(GNUNET_NO, 685 suid_helper = GNUNET_HELPER_start (GNUNET_NO,
681 "gnunet-helper-transport-wlan-dummy", helper_argv, 686 "gnunet-helper-transport-wlan-dummy",
682 &handle_helper_message, NULL, NULL); 687 helper_argv,
683 } 688 &handle_helper_message, NULL, NULL);
689 }
684 690
685 /* Loading plugin */ 691 /* Loading plugin */
686 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Loading transport plugin %s\n", plugin); 692 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Loading transport plugin %s\n", plugin);
687 GNUNET_asprintf(&libname, "libgnunet_plugin_transport_%s", plugin); 693 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", plugin);
688 api = GNUNET_PLUGIN_load(libname, &env); 694 api = GNUNET_PLUGIN_load (libname, &env);
689 if (NULL == api) 695 if (NULL == api)
690 { 696 {
691 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 697 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
692 "Failed to load transport plugin for %s\n", plugin); 698 "Failed to load transport plugin for %s\n", plugin);
693 end_badly_now(); 699 end_badly_now ();
694 return; 700 return;
695 } 701 }
696 702
697 timeout_wait = GNUNET_SCHEDULER_add_delayed(WAIT, &wait_end, NULL); 703 timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL);
698 704
699 /* Check if all functions are implemented */ 705 /* Check if all functions are implemented */
700 if (NULL == api->address_pretty_printer) 706 if (NULL == api->address_pretty_printer)
701 { 707 {
702 GNUNET_break(0); 708 GNUNET_break (0);
703 end_badly_now(); 709 end_badly_now ();
704 return; 710 return;
705 } 711 }
706 if (NULL == api->address_to_string) 712 if (NULL == api->address_to_string)
707 { 713 {
708 GNUNET_break(0); 714 GNUNET_break (0);
709 end_badly_now(); 715 end_badly_now ();
710 return; 716 return;
711 } 717 }
712 GNUNET_assert(NULL != api->check_address); 718 GNUNET_assert (NULL != api->check_address);
713 if (NULL == api->check_address) 719 if (NULL == api->check_address)
714 { 720 {
715 GNUNET_break(0); 721 GNUNET_break (0);
716 end_badly_now(); 722 end_badly_now ();
717 return; 723 return;
718 } 724 }
719 GNUNET_assert(NULL != api->disconnect_peer); 725 GNUNET_assert (NULL != api->disconnect_peer);
720 if (NULL == api->disconnect_peer) 726 if (NULL == api->disconnect_peer)
721 { 727 {
722 GNUNET_break(0); 728 GNUNET_break (0);
723 end_badly_now(); 729 end_badly_now ();
724 return; 730 return;
725 } 731 }
726 GNUNET_assert(NULL != api->get_session); 732 GNUNET_assert (NULL != api->get_session);
727 if (NULL == api->get_session) 733 if (NULL == api->get_session)
728 { 734 {
729 GNUNET_break(0); 735 GNUNET_break (0);
730 end_badly_now(); 736 end_badly_now ();
731 return; 737 return;
732 } 738 }
733 if (NULL == api->address_pretty_printer) 739 if (NULL == api->address_pretty_printer)
734 { 740 {
735 GNUNET_break(0); 741 GNUNET_break (0);
736 end_badly_now(); 742 end_badly_now ();
737 return; 743 return;
738 } 744 }
739 if (NULL == api->string_to_address) 745 if (NULL == api->string_to_address)
740 { 746 {
741 GNUNET_break(0); 747 GNUNET_break (0);
742 end_badly_now(); 748 end_badly_now ();
743 return; 749 return;
744 } 750 }
745} 751}
746 752
747 753
@@ -753,32 +759,32 @@ run(void *cls,
753 * @return 0 ok, 1 on error 759 * @return 0 ok, 1 on error
754 */ 760 */
755int 761int
756main(int argc, 762main (int argc,
757 char * const *argv) 763 char *const *argv)
758{ 764{
759 static struct GNUNET_GETOPT_CommandLineOption options[] = { 765 static struct GNUNET_GETOPT_CommandLineOption options[] = {
760 GNUNET_GETOPT_OPTION_END 766 GNUNET_GETOPT_OPTION_END
761 }; 767 };
762 int ret; 768 int ret;
763 char * const argv_prog[] = { 769 char *const argv_prog[] = {
764 "test_plugin_transport", 770 "test_plugin_transport",
765 "-c", 771 "-c",
766 "test_plugin_transport_data.conf", 772 "test_plugin_transport_data.conf",
767 NULL 773 NULL
768 }; 774 };
769 775
770 GNUNET_log_setup("test-plugin-transport", 776 GNUNET_log_setup ("test-plugin-transport",
771 "WARNING", 777 "WARNING",
772 NULL); 778 NULL);
773 GNUNET_DISK_purge_cfg_dir("test_plugin_transport_data.conf", 779 GNUNET_DISK_purge_cfg_dir ("test_plugin_transport_data.conf",
774 "GNUNET_TEST_HOME"); 780 "GNUNET_TEST_HOME");
775 ok = 1; /* set to fail */ 781 ok = 1; /* set to fail */
776 ret = 782 ret =
777 (GNUNET_OK 783 (GNUNET_OK
778 == GNUNET_PROGRAM_run(3, argv_prog, "test-plugin-transport", 784 == GNUNET_PROGRAM_run (3, argv_prog, "test-plugin-transport",
779 "testcase", options, &run, (void *)argv)) ? ok : 1; 785 "testcase", options, &run, (void *) argv)) ? ok : 1;
780 GNUNET_DISK_purge_cfg_dir("test_plugin_transport_data.conf", 786 GNUNET_DISK_purge_cfg_dir ("test_plugin_transport_data.conf",
781 "GNUNET_TEST_HOME"); 787 "GNUNET_TEST_HOME");
782 return ret; 788 return ret;
783} 789}
784 790