test_plugin_transport.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2009 Christian Grothoff (and other contributing authors)
  4. GNUnet is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published
  6. by the Free Software Foundation; either version 3, or (at your
  7. option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNUnet; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA.
  16. */
  17. /**
  18. * @file transport/test_plugin_transport.c
  19. * @brief testcase for transport_api.c
  20. * @author Sailor Siraj
  21. * @author Christian Grothoff
  22. */
  23. #include "platform.h"
  24. #include "gnunet_util_lib.h"
  25. #include "gnunet_hello_lib.h"
  26. #include "gnunet_peerinfo_service.h"
  27. #include "gnunet_statistics_service.h"
  28. #include "gnunet_protocols.h"
  29. #include "gnunet_transport_plugin.h"
  30. #include "transport.h"
  31. /**
  32. * How long until we give up on transmitting the message?
  33. */
  34. #define WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
  35. #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
  36. #define HOSTKEY_FILE "test_plugin_hostkey.ecc"
  37. /**
  38. * Our public key.
  39. */
  40. static struct GNUNET_PeerIdentity my_identity;
  41. /**
  42. * Our private key.
  43. */
  44. static struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key;
  45. /**
  46. * Our configuration.
  47. */
  48. const struct GNUNET_CONFIGURATION_Handle *cfg;
  49. /**
  50. * Our configuration.
  51. */
  52. struct GNUNET_STATISTICS_Handle *stats;
  53. /**
  54. * Our HELLO
  55. */
  56. struct GNUNET_HELLO_Message *hello;
  57. /**
  58. * Number of neighbours we'd like to have.
  59. */
  60. static uint32_t max_connect_per_transport;
  61. /**
  62. * Environment for this plugin.
  63. */
  64. struct GNUNET_TRANSPORT_PluginEnvironment env;
  65. /**
  66. *handle for the api provided by this plugin
  67. */
  68. struct GNUNET_TRANSPORT_PluginFunctions *api;
  69. /**
  70. * Helper handler
  71. */
  72. struct GNUNET_HELPER_Handle *suid_helper;
  73. /**
  74. * Timeout task
  75. */
  76. static struct GNUNET_SCHEDULER_Task * timeout_endbadly;
  77. /**
  78. * Timeout task
  79. */
  80. static struct GNUNET_SCHEDULER_Task * timeout_wait;
  81. /**
  82. * Library name
  83. */
  84. static char *libname;
  85. /**
  86. * Plugin addresses head
  87. */
  88. struct AddressWrapper *head;
  89. /**
  90. * Plugin addresses tail
  91. */
  92. struct AddressWrapper *tail;
  93. unsigned int addresses_reported;
  94. unsigned int pretty_printers_running;
  95. /**
  96. * Did the test pass or fail?
  97. */
  98. static int ok;
  99. struct AddressWrapper
  100. {
  101. struct AddressWrapper *next;
  102. struct AddressWrapper *prev;
  103. struct GNUNET_HELLO_Address *address;
  104. char *addrstring;
  105. struct GNUNET_SCHEDULER_Task *test_task;
  106. };
  107. static void
  108. end ()
  109. {
  110. struct AddressWrapper *w;
  111. int c = 0;
  112. ok = 0;
  113. if (NULL != timeout_endbadly)
  114. {
  115. GNUNET_SCHEDULER_cancel (timeout_endbadly);
  116. timeout_endbadly = NULL;
  117. }
  118. if (NULL != api)
  119. GNUNET_PLUGIN_unload (libname, api);
  120. while (NULL != head)
  121. {
  122. w = head;
  123. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  124. "Plugin did not remove address `%s'\n",
  125. w->addrstring);
  126. GNUNET_CONTAINER_DLL_remove(head, tail, w);
  127. c++;
  128. GNUNET_HELLO_address_free(w->address);
  129. GNUNET_free(w->addrstring);
  130. GNUNET_free(w);
  131. }
  132. if (c > 0)
  133. {
  134. GNUNET_break(0);
  135. GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove %u addresses \n",
  136. c);
  137. ok = 1;
  138. }
  139. GNUNET_free(libname);
  140. libname = NULL;
  141. GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
  142. stats = NULL;
  143. if (NULL != suid_helper)
  144. {
  145. GNUNET_HELPER_stop (suid_helper, GNUNET_NO);
  146. suid_helper = NULL;
  147. }
  148. }
  149. static void
  150. end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  151. {
  152. struct AddressWrapper *w;
  153. int c = 0;
  154. timeout_endbadly = NULL;
  155. if (NULL != timeout_wait)
  156. {
  157. GNUNET_SCHEDULER_cancel (timeout_wait);
  158. timeout_wait = NULL;
  159. }
  160. if (pretty_printers_running > 0)
  161. {
  162. timeout_endbadly = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
  163. &end_badly, &ok);
  164. GNUNET_log(GNUNET_ERROR_TYPE_INFO,
  165. "Have pending calls to pretty_printer ... deferring shutdown\n");
  166. return;
  167. }
  168. if (NULL != cls)
  169. {
  170. GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
  171. "Test took too long to execute, timeout .... \n");
  172. }
  173. if (NULL != libname)
  174. {
  175. if (NULL != api)
  176. GNUNET_PLUGIN_unload (libname, api);
  177. GNUNET_free(libname);
  178. libname = NULL;
  179. }
  180. while (NULL != head)
  181. {
  182. w = head;
  183. GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove address `%s'\n",
  184. w->addrstring);
  185. GNUNET_CONTAINER_DLL_remove(head, tail, w);
  186. c++;
  187. GNUNET_HELLO_address_free(w->address);
  188. if (NULL != w->test_task)
  189. GNUNET_SCHEDULER_cancel (w->test_task);
  190. GNUNET_free(w->addrstring);
  191. GNUNET_free(w);
  192. }
  193. if (c > 0)
  194. {
  195. GNUNET_break(0);
  196. GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove %u addresses\n",
  197. c);
  198. }
  199. if (NULL != stats)
  200. {
  201. GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
  202. stats = NULL;
  203. }
  204. if (NULL != suid_helper)
  205. {
  206. GNUNET_HELPER_stop (suid_helper, GNUNET_NO);
  207. suid_helper = NULL;
  208. }
  209. ok = 1;
  210. }
  211. static void
  212. wait_end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  213. {
  214. timeout_wait = NULL;
  215. if (0 == addresses_reported)
  216. GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
  217. "Plugin did not report any addresses, could not check address conversion functions\n");
  218. end ();
  219. }
  220. static void
  221. end_badly_now ()
  222. {
  223. if (NULL != timeout_wait)
  224. {
  225. GNUNET_SCHEDULER_cancel (timeout_wait);
  226. timeout_wait = NULL;
  227. }
  228. if (NULL != timeout_endbadly)
  229. {
  230. GNUNET_SCHEDULER_cancel (timeout_endbadly);
  231. timeout_endbadly = NULL;
  232. }
  233. timeout_endbadly = GNUNET_SCHEDULER_add_now (&end_badly, NULL );
  234. }
  235. static struct GNUNET_TIME_Relative
  236. env_receive (void *cls,
  237. const struct GNUNET_HELLO_Address *address,
  238. struct Session *session,
  239. const struct GNUNET_MessageHeader *message)
  240. {
  241. /* do nothing */
  242. return GNUNET_TIME_relative_get_zero_ ();
  243. }
  244. static int got_reply;
  245. /**
  246. * Take the given address and append it to the set of results sent back to
  247. * the client.
  248. *
  249. * @param cls closure
  250. * @param address the address to print
  251. * @param res result code
  252. */
  253. static void
  254. address_pretty_printer_cb (void *cls, const char *address, int res)
  255. {
  256. if (NULL != address)
  257. {
  258. got_reply = GNUNET_YES;
  259. GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Pretty address : `%s'\n", address);
  260. pretty_printers_running--;
  261. }
  262. else
  263. {
  264. if (GNUNET_NO == got_reply)
  265. {
  266. pretty_printers_running--;
  267. GNUNET_break(0);
  268. end_badly_now ();
  269. }
  270. }
  271. }
  272. static void
  273. test_addr_string (void *cls,
  274. const struct GNUNET_SCHEDULER_TaskContext *tc)
  275. {
  276. struct AddressWrapper *w = cls;
  277. void *s2a;
  278. size_t s2a_len;
  279. w->test_task = NULL;
  280. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  281. "Testing: address_to_string \n");
  282. w->addrstring = GNUNET_strdup (api->address_to_string (api,
  283. w->address->address,
  284. w->address->address_length));
  285. if (NULL == w->addrstring)
  286. {
  287. GNUNET_break(0);
  288. GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
  289. "Plugin cannot convert address to string!\n");
  290. end_badly_now ();
  291. return;
  292. }
  293. GNUNET_log(GNUNET_ERROR_TYPE_INFO,
  294. "Plugin added address `%s'\n",
  295. w->addrstring);
  296. GNUNET_log(GNUNET_ERROR_TYPE_INFO,
  297. "Testing address_to_string: OK\n");
  298. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  299. "Testing: string_to_address \n");
  300. s2a = NULL;
  301. s2a_len = 0;
  302. if ((GNUNET_OK !=
  303. api->string_to_address (api, w->addrstring,
  304. strlen (w->addrstring) + 1,
  305. &s2a, &s2a_len)) ||
  306. (NULL == s2a))
  307. {
  308. GNUNET_break(0);
  309. GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
  310. "Plugin cannot convert string to address!\n");
  311. end_badly_now ();
  312. return;
  313. }
  314. /*
  315. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  316. "Plugin creates `%s' %u\n",api->address_to_string (api, s2a, s2a_len), s2a_len);
  317. int c1;
  318. for (c1 = 0; c1 < s2a_len; c1++ )
  319. fprintf (stderr, "%u == %u\n", ((char *) s2a)[c1], ((char *) w->addr)[c1]);
  320. */
  321. if (s2a_len != w->address->address_length)
  322. {
  323. GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
  324. "Plugin creates different address length when converting address->string->address: %u != %u\n",
  325. w->address->address_length, s2a_len);
  326. }
  327. else if (0 != memcmp (s2a, w->address->address, s2a_len))
  328. {
  329. GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
  330. "Plugin creates different address length when converting back and forth %i!\n",
  331. memcmp (s2a, w->address->address, s2a_len));
  332. }
  333. else
  334. {
  335. GNUNET_log(GNUNET_ERROR_TYPE_INFO,
  336. "Testing string_to_address: OK\n");
  337. }
  338. GNUNET_free(s2a);
  339. pretty_printers_running++;
  340. api->address_pretty_printer (api->cls,
  341. w->address->transport_name,
  342. w->address->address,
  343. w->address->address_length,
  344. GNUNET_YES,
  345. GNUNET_TIME_UNIT_MINUTES,
  346. &address_pretty_printer_cb, w);
  347. if (GNUNET_OK !=
  348. api->check_address (api->cls, w->address->address, w->address->address_length))
  349. {
  350. GNUNET_break(0);
  351. GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin refuses added address!\n");
  352. end_badly_now ();
  353. return;
  354. }
  355. if (NULL != timeout_wait)
  356. {
  357. GNUNET_SCHEDULER_cancel (timeout_wait);
  358. timeout_wait = NULL;
  359. }
  360. timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL);
  361. }
  362. static void
  363. env_notify_address (void *cls,
  364. int add_remove,
  365. const struct GNUNET_HELLO_Address *address)
  366. {
  367. struct AddressWrapper *w;
  368. struct AddressWrapper *wtmp;
  369. if (GNUNET_YES == add_remove)
  370. {
  371. addresses_reported++;
  372. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  373. "Adding address of length %u\n",
  374. address->address_length);
  375. for (wtmp = head; NULL != wtmp; wtmp = wtmp->next)
  376. {
  377. if ((address->address_length == wtmp->address->address_length) &&
  378. (0 == memcmp (address->address, wtmp->address->address, address->address_length)))
  379. {
  380. GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
  381. "Duplicate address notification .... \n");
  382. return;
  383. }
  384. }
  385. w = GNUNET_new (struct AddressWrapper);
  386. w->address = GNUNET_HELLO_address_copy (address);
  387. GNUNET_CONTAINER_DLL_insert (head, tail, w);
  388. got_reply = GNUNET_NO;
  389. w->test_task = GNUNET_SCHEDULER_add_now (&test_addr_string,
  390. w);
  391. return;
  392. }
  393. if (GNUNET_NO == add_remove)
  394. {
  395. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  396. "Removing address of length %u\n",
  397. address->address_length);
  398. w = head;
  399. while (NULL != w)
  400. {
  401. if ((address->address_length == w->address->address_length) &&
  402. (0 == memcmp (w->address->address, address->address, address->address_length)))
  403. {
  404. break;
  405. }
  406. w = w->next;
  407. }
  408. if (w == NULL)
  409. {
  410. GNUNET_break(0);
  411. GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
  412. "Plugin removes address never added!\n");
  413. end_badly_now ();
  414. return;
  415. }
  416. GNUNET_CONTAINER_DLL_remove(head, tail, w);
  417. GNUNET_HELLO_address_free (w->address);
  418. GNUNET_free(w->addrstring);
  419. GNUNET_free(w);
  420. return;
  421. }
  422. GNUNET_break(0);
  423. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  424. "Invalid operation: %u\n",
  425. add_remove);
  426. end_badly_now ();
  427. }
  428. static enum GNUNET_ATS_Network_Type
  429. env_get_address_type (void *cls,
  430. const struct sockaddr *addr,
  431. size_t addrlen)
  432. {
  433. return GNUNET_ATS_NET_LOOPBACK;
  434. }
  435. static const struct GNUNET_MessageHeader *
  436. env_get_our_hello ()
  437. {
  438. return (const struct GNUNET_MessageHeader *) hello;
  439. }
  440. static void
  441. env_session_end (void *cls,
  442. const struct GNUNET_HELLO_Address *address,
  443. struct Session *session)
  444. {
  445. }
  446. static void
  447. env_update_distance (void *cls,
  448. const struct GNUNET_HELLO_Address *address,
  449. uint32_t distance)
  450. {
  451. }
  452. static void
  453. setup_plugin_environment ()
  454. {
  455. env.cfg = cfg;
  456. env.cls = &env;
  457. env.my_identity = &my_identity;
  458. env.max_connections = max_connect_per_transport;
  459. env.stats = stats;
  460. env.receive = &env_receive;
  461. env.notify_address = &env_notify_address;
  462. env.get_address_type = &env_get_address_type;
  463. env.update_address_distance = &env_update_distance;
  464. env.get_our_hello = &env_get_our_hello;
  465. env.session_end = &env_session_end;
  466. }
  467. static int
  468. handle_helper_message (void *cls, void *client,
  469. const struct GNUNET_MessageHeader *hdr)
  470. {
  471. return GNUNET_OK;
  472. }
  473. /**
  474. * Runs the test.
  475. *
  476. * @param cls closure
  477. * @param c configuration to use
  478. */
  479. static void
  480. run (void *cls, char * const *args, const char *cfgfile,
  481. const struct GNUNET_CONFIGURATION_Handle *c)
  482. {
  483. char * const *argv = cls;
  484. unsigned long long tneigh;
  485. char *keyfile;
  486. char *plugin;
  487. char *sep;
  488. timeout_endbadly = GNUNET_SCHEDULER_add_delayed (TIMEOUT, end_badly, &ok);
  489. cfg = c;
  490. /* parse configuration */
  491. if ((GNUNET_OK
  492. != GNUNET_CONFIGURATION_get_value_number (c, "TRANSPORT",
  493. "NEIGHBOUR_LIMIT", &tneigh))
  494. || (GNUNET_OK
  495. != GNUNET_CONFIGURATION_get_value_filename (c, "PEER", "PRIVATE_KEY",
  496. &keyfile)))
  497. {
  498. GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
  499. "Transport service is lacking key configuration settings. Exiting.\n");
  500. return;
  501. }
  502. if (NULL == (stats = GNUNET_STATISTICS_create ("transport", cfg)))
  503. {
  504. GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
  505. "Could not create statistics. Exiting.\n");
  506. GNUNET_free(keyfile);
  507. end_badly_now ();
  508. return;
  509. }
  510. if (GNUNET_OK != GNUNET_DISK_file_test (HOSTKEY_FILE))
  511. {
  512. GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Hostkey `%s' missing. Exiting.\n",
  513. HOSTKEY_FILE);
  514. GNUNET_free(keyfile);
  515. end_badly_now ();
  516. return;
  517. }
  518. if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (keyfile))
  519. {
  520. GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
  521. "Could not create a directory for hostkey `%s'. Exiting.\n", keyfile);
  522. GNUNET_free(keyfile);
  523. end_badly_now ();
  524. return;
  525. }
  526. if (GNUNET_OK != GNUNET_DISK_file_copy (HOSTKEY_FILE, keyfile))
  527. {
  528. GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
  529. "Could not copy hostkey `%s' to destination `%s'. Exiting.\n",
  530. HOSTKEY_FILE, keyfile);
  531. GNUNET_free(keyfile);
  532. end_badly_now ();
  533. return;
  534. }
  535. max_connect_per_transport = (uint32_t) tneigh;
  536. my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile);
  537. GNUNET_free(keyfile);
  538. if (NULL == my_private_key)
  539. {
  540. GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
  541. "Could not access hostkey. Exiting.\n");
  542. end_badly_now ();
  543. return;
  544. }
  545. GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_identity.public_key);
  546. hello = GNUNET_HELLO_create (&my_identity.public_key, NULL, NULL, GNUNET_NO);
  547. /* load plugins... */
  548. setup_plugin_environment ();
  549. GNUNET_assert(strlen (argv[0]) > strlen ("test_plugin_"));
  550. plugin = strstr (argv[0], "test_plugin_");
  551. sep = strrchr (argv[0], '.');
  552. if (NULL == plugin)
  553. {
  554. GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Not a valid test name\n");
  555. end_badly_now ();
  556. return;
  557. }
  558. plugin += strlen ("test_plugin_");
  559. if (NULL != sep)
  560. sep[0] = '\0';
  561. /* Hack for WLAN: start a second helper */
  562. if (0 == strcmp (plugin, "wlan"))
  563. {
  564. char * helper_argv[3];
  565. helper_argv[0] = (char *) "gnunet-helper-transport-wlan-dummy";
  566. helper_argv[1] = (char *) "2";
  567. helper_argv[2] = NULL;
  568. suid_helper = GNUNET_HELPER_start (GNUNET_NO,
  569. "gnunet-helper-transport-wlan-dummy", helper_argv,
  570. &handle_helper_message, NULL, NULL );
  571. }
  572. /* Loading plugin */
  573. GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Loading transport plugin %s\n", plugin);
  574. GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", plugin);
  575. api = GNUNET_PLUGIN_load (libname, &env);
  576. if (NULL == api)
  577. {
  578. GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
  579. "Failed to load transport plugin for %s\n", plugin);
  580. end_badly_now ();
  581. return;
  582. }
  583. timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL );
  584. /* Check if all functions are implemented */
  585. if (NULL == api->address_pretty_printer)
  586. {
  587. GNUNET_break(0);
  588. end_badly_now ();
  589. return;
  590. }
  591. if (NULL == api->address_to_string)
  592. {
  593. GNUNET_break(0);
  594. end_badly_now ();
  595. return;
  596. }
  597. GNUNET_assert(NULL != api->check_address);
  598. if (NULL == api->check_address)
  599. {
  600. GNUNET_break(0);
  601. end_badly_now ();
  602. return;
  603. }
  604. GNUNET_assert(NULL != api->disconnect_peer);
  605. if (NULL == api->disconnect_peer)
  606. {
  607. GNUNET_break(0);
  608. end_badly_now ();
  609. return;
  610. }
  611. GNUNET_assert(NULL != api->get_session);
  612. if (NULL == api->get_session)
  613. {
  614. GNUNET_break(0);
  615. end_badly_now ();
  616. return;
  617. }
  618. if (NULL == api->address_pretty_printer)
  619. {
  620. GNUNET_break(0);
  621. end_badly_now ();
  622. return;
  623. }
  624. if (NULL == api->string_to_address)
  625. {
  626. GNUNET_break(0);
  627. end_badly_now ();
  628. return;
  629. }
  630. }
  631. /**
  632. * The main function for the test
  633. *
  634. * @param argc number of arguments from the command line
  635. * @param argv command line arguments
  636. * @return 0 ok, 1 on error
  637. */
  638. int
  639. main (int argc, char * const *argv)
  640. {
  641. static struct GNUNET_GETOPT_CommandLineOption options[] = {
  642. GNUNET_GETOPT_OPTION_END };
  643. int ret;
  644. GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-plugin-transport");
  645. char * const argv_prog[] = { "test_plugin_transport", "-c",
  646. "test_plugin_transport_data.conf", NULL };
  647. GNUNET_log_setup ("test-plugin-transport", "WARNING", NULL );
  648. ok = 1; /* set to fail */
  649. ret =
  650. (GNUNET_OK
  651. == GNUNET_PROGRAM_run (3, argv_prog, "test-plugin-transport",
  652. "testcase", options, &run, (void *) argv)) ? ok : 1;
  653. GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-plugin-transport");
  654. return ret;
  655. }
  656. /* end of test_plugin_transport.c */