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