test_plugin_transport.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2009, 2018 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your 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. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @file transport/test_plugin_transport.c
  18. * @brief testcase for transport_api.c
  19. * @author Sailor Siraj
  20. * @author Christian Grothoff
  21. */
  22. #include "platform.h"
  23. #include "gnunet_util_lib.h"
  24. #include "gnunet_hello_lib.h"
  25. #include "gnunet_peerinfo_service.h"
  26. #include "gnunet_statistics_service.h"
  27. #include "gnunet_protocols.h"
  28. #include "gnunet_transport_plugin.h"
  29. #include "transport.h"
  30. /**
  31. * How long until we give up on transmitting the message?
  32. */
  33. #define WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
  34. #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
  35. #define HOSTKEY_FILE "test_plugin_hostkey.ecc"
  36. /**
  37. * Our public key.
  38. */
  39. static struct GNUNET_PeerIdentity my_identity;
  40. /**
  41. * Our private key.
  42. */
  43. static struct GNUNET_CRYPTO_EddsaPrivateKey my_private_key;
  44. /**
  45. * Our configuration.
  46. */
  47. const struct GNUNET_CONFIGURATION_Handle *cfg;
  48. /**
  49. * Our configuration.
  50. */
  51. struct GNUNET_STATISTICS_Handle *stats;
  52. /**
  53. * Our HELLO
  54. */
  55. struct GNUNET_HELLO_Message *hello;
  56. /**
  57. * Number of neighbours we'd like to have.
  58. */
  59. static uint32_t max_connect_per_transport;
  60. /**
  61. * Environment for this plugin.
  62. */
  63. struct GNUNET_TRANSPORT_PluginEnvironment env;
  64. /**
  65. * handle for the api provided by this plugin
  66. */
  67. struct GNUNET_TRANSPORT_PluginFunctions *api;
  68. /**
  69. * Helper handler
  70. */
  71. struct GNUNET_HELPER_Handle *suid_helper;
  72. /**
  73. * Timeout task
  74. */
  75. static struct GNUNET_SCHEDULER_Task *timeout_endbadly;
  76. /**
  77. * Timeout task
  78. */
  79. static struct GNUNET_SCHEDULER_Task *timeout_wait;
  80. /**
  81. * Library name
  82. */
  83. static char *libname;
  84. /**
  85. * Plugin addresses head
  86. */
  87. struct AddressWrapper *head;
  88. /**
  89. * Plugin addresses tail
  90. */
  91. struct AddressWrapper *tail;
  92. unsigned int addresses_reported;
  93. unsigned int pretty_printers_running;
  94. /**
  95. * Did the test pass or fail?
  96. */
  97. static int ok;
  98. struct AddressWrapper
  99. {
  100. struct AddressWrapper *next;
  101. struct AddressWrapper *prev;
  102. struct GNUNET_HELLO_Address *address;
  103. char *addrstring;
  104. struct GNUNET_SCHEDULER_Task *test_task;
  105. };
  106. static void
  107. end ()
  108. {
  109. struct AddressWrapper *w;
  110. int c = 0;
  111. ok = 0;
  112. if (NULL != timeout_endbadly)
  113. {
  114. GNUNET_SCHEDULER_cancel (timeout_endbadly);
  115. timeout_endbadly = NULL;
  116. }
  117. if (NULL != api)
  118. GNUNET_PLUGIN_unload (libname, api);
  119. while (NULL != head)
  120. {
  121. w = head;
  122. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  123. "Plugin did not remove address `%s'\n",
  124. w->addrstring);
  125. GNUNET_CONTAINER_DLL_remove (head, tail, w);
  126. c++;
  127. GNUNET_HELLO_address_free (w->address);
  128. GNUNET_free (w->addrstring);
  129. GNUNET_free (w);
  130. }
  131. if (c > 0)
  132. {
  133. GNUNET_break (0);
  134. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  135. "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)
  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)
  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 GNUNET_ATS_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. {
  275. struct AddressWrapper *w = cls;
  276. void *s2a;
  277. size_t s2a_len;
  278. w->test_task = NULL;
  279. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  280. "Testing: address_to_string \n");
  281. w->addrstring = GNUNET_strdup (api->address_to_string (api,
  282. w->address->address,
  283. w->address->
  284. 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. */if (s2a_len != w->address->address_length)
  321. {
  322. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  323. "Plugin creates different address length when converting address->string->address: %u != %u\n",
  324. (unsigned int) w->address->address_length,
  325. (unsigned int) 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,
  332. w->address->address,
  333. s2a_len));
  334. }
  335. else
  336. {
  337. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  338. "Testing string_to_address: OK\n");
  339. }
  340. GNUNET_free (s2a);
  341. pretty_printers_running++;
  342. api->address_pretty_printer (api->cls,
  343. w->address->transport_name,
  344. w->address->address,
  345. w->address->address_length,
  346. GNUNET_YES,
  347. GNUNET_TIME_UNIT_MINUTES,
  348. &address_pretty_printer_cb, w);
  349. if (GNUNET_OK !=
  350. api->check_address (api->cls,
  351. w->address->address,
  352. w->address->address_length))
  353. {
  354. GNUNET_break (0);
  355. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  356. "Plugin refuses added address!\n");
  357. end_badly_now ();
  358. return;
  359. }
  360. if (NULL != timeout_wait)
  361. {
  362. GNUNET_SCHEDULER_cancel (timeout_wait);
  363. timeout_wait = NULL;
  364. }
  365. timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL);
  366. }
  367. static void
  368. env_notify_address (void *cls,
  369. int add_remove,
  370. const struct GNUNET_HELLO_Address *address)
  371. {
  372. struct AddressWrapper *w;
  373. struct AddressWrapper *wtmp;
  374. if (GNUNET_YES == add_remove)
  375. {
  376. addresses_reported++;
  377. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  378. "Adding address of length %u\n",
  379. (unsigned int) address->address_length);
  380. for (wtmp = head; NULL != wtmp; wtmp = wtmp->next)
  381. {
  382. if ((address->address_length == wtmp->address->address_length) &&
  383. (0 == memcmp (address->address, wtmp->address->address,
  384. address->address_length)))
  385. {
  386. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  387. "Duplicate address notification .... \n");
  388. return;
  389. }
  390. }
  391. w = GNUNET_new (struct AddressWrapper);
  392. w->address = GNUNET_HELLO_address_copy (address);
  393. GNUNET_CONTAINER_DLL_insert (head, tail, w);
  394. got_reply = GNUNET_NO;
  395. w->test_task = GNUNET_SCHEDULER_add_now (&test_addr_string,
  396. w);
  397. return;
  398. }
  399. if (GNUNET_NO == add_remove)
  400. {
  401. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  402. "Removing address of length %u\n",
  403. (unsigned int) address->address_length);
  404. w = head;
  405. while (NULL != w)
  406. {
  407. if ((address->address_length == w->address->address_length) &&
  408. (0 == memcmp (w->address->address, address->address,
  409. address->address_length)))
  410. {
  411. break;
  412. }
  413. w = w->next;
  414. }
  415. if (w == NULL)
  416. {
  417. GNUNET_break (0);
  418. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  419. "Plugin removes address never added!\n");
  420. end_badly_now ();
  421. return;
  422. }
  423. GNUNET_CONTAINER_DLL_remove (head, tail, w);
  424. GNUNET_HELLO_address_free (w->address);
  425. GNUNET_free (w->addrstring);
  426. GNUNET_free (w);
  427. return;
  428. }
  429. GNUNET_break (0);
  430. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  431. "Invalid operation: %u\n",
  432. add_remove);
  433. end_badly_now ();
  434. }
  435. static enum GNUNET_NetworkType
  436. env_get_address_type (void *cls,
  437. const struct sockaddr *addr,
  438. size_t addrlen)
  439. {
  440. return GNUNET_NT_LOOPBACK;
  441. }
  442. static const struct GNUNET_MessageHeader *
  443. env_get_our_hello ()
  444. {
  445. return (const struct GNUNET_MessageHeader *) hello;
  446. }
  447. static void
  448. env_session_end (void *cls,
  449. const struct GNUNET_HELLO_Address *address,
  450. struct GNUNET_ATS_Session *session)
  451. {
  452. }
  453. static void
  454. env_update_distance (void *cls,
  455. const struct GNUNET_HELLO_Address *address,
  456. uint32_t distance)
  457. {
  458. }
  459. static void
  460. setup_plugin_environment ()
  461. {
  462. env.cfg = cfg;
  463. env.cls = &env;
  464. env.my_identity = &my_identity;
  465. env.max_connections = max_connect_per_transport;
  466. env.stats = stats;
  467. env.receive = &env_receive;
  468. env.notify_address = &env_notify_address;
  469. env.get_address_type = &env_get_address_type;
  470. env.update_address_distance = &env_update_distance;
  471. env.get_our_hello = &env_get_our_hello;
  472. env.session_end = &env_session_end;
  473. }
  474. static int
  475. handle_helper_message (void *cls,
  476. const struct GNUNET_MessageHeader *hdr)
  477. {
  478. return GNUNET_OK;
  479. }
  480. /**
  481. * Runs the test.
  482. *
  483. * @param cls closure
  484. * @param c configuration to use
  485. */
  486. static void
  487. run (void *cls,
  488. char *const *args,
  489. const char *cfgfile,
  490. const struct GNUNET_CONFIGURATION_Handle *c)
  491. {
  492. char *const *argv = cls;
  493. unsigned long long tneigh;
  494. char *keyfile;
  495. char *plugin;
  496. char *sep;
  497. timeout_endbadly = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
  498. &end_badly,
  499. &ok);
  500. cfg = c;
  501. /* parse configuration */
  502. if ((GNUNET_OK !=
  503. GNUNET_CONFIGURATION_get_value_number (c,
  504. "TRANSPORT",
  505. "NEIGHBOUR_LIMIT",
  506. &tneigh)) ||
  507. (GNUNET_OK !=
  508. GNUNET_CONFIGURATION_get_value_filename (c,
  509. "PEER",
  510. "PRIVATE_KEY",
  511. &keyfile)))
  512. {
  513. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  514. "Transport service is lacking key configuration settings. Exiting.\n");
  515. return;
  516. }
  517. if (NULL == (stats = GNUNET_STATISTICS_create ("transport",
  518. cfg)))
  519. {
  520. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  521. "Could not create statistics. Exiting.\n");
  522. GNUNET_free (keyfile);
  523. end_badly_now ();
  524. return;
  525. }
  526. if (GNUNET_OK != GNUNET_DISK_file_test (HOSTKEY_FILE))
  527. {
  528. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  529. "Hostkey `%s' missing. Exiting.\n",
  530. HOSTKEY_FILE);
  531. GNUNET_free (keyfile);
  532. end_badly_now ();
  533. return;
  534. }
  535. if (GNUNET_OK !=
  536. GNUNET_DISK_directory_create_for_file (keyfile))
  537. {
  538. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  539. "Could not create a directory for hostkey `%s'. Exiting.\n",
  540. keyfile);
  541. GNUNET_free (keyfile);
  542. end_badly_now ();
  543. return;
  544. }
  545. if (GNUNET_OK !=
  546. GNUNET_DISK_file_copy (HOSTKEY_FILE,
  547. keyfile))
  548. {
  549. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  550. "Could not copy hostkey `%s' to destination `%s'. Exiting.\n",
  551. HOSTKEY_FILE,
  552. keyfile);
  553. GNUNET_free (keyfile);
  554. end_badly_now ();
  555. return;
  556. }
  557. max_connect_per_transport = (uint32_t) tneigh;
  558. if (GNUNET_SYSERR ==
  559. GNUNET_CRYPTO_eddsa_key_from_file (keyfile,
  560. GNUNET_YES,
  561. &my_private_key))
  562. {
  563. GNUNET_free (keyfile);
  564. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  565. "Could not access hostkey. Exiting.\n");
  566. end_badly_now ();
  567. return;
  568. }
  569. GNUNET_free (keyfile);
  570. GNUNET_CRYPTO_eddsa_key_get_public (&my_private_key,
  571. &my_identity.public_key);
  572. hello = GNUNET_HELLO_create (&my_identity.public_key, NULL, NULL, GNUNET_NO);
  573. /* load plugins... */
  574. setup_plugin_environment ();
  575. GNUNET_assert (strlen (argv[0]) > strlen ("test_plugin_"));
  576. plugin = strstr (argv[0], "test_plugin_");
  577. sep = strrchr (argv[0], '.');
  578. if (NULL == plugin)
  579. {
  580. GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Not a valid test name\n");
  581. end_badly_now ();
  582. return;
  583. }
  584. plugin += strlen ("test_plugin_");
  585. if (NULL != sep)
  586. sep[0] = '\0';
  587. /* Hack for WLAN: start a second helper */
  588. if (0 == strcmp (plugin, "wlan"))
  589. {
  590. char *helper_argv[3];
  591. helper_argv[0] = (char *) "gnunet-helper-transport-wlan-dummy";
  592. helper_argv[1] = (char *) "2";
  593. helper_argv[2] = NULL;
  594. suid_helper = GNUNET_HELPER_start (GNUNET_NO,
  595. "gnunet-helper-transport-wlan-dummy",
  596. helper_argv,
  597. &handle_helper_message, NULL, NULL);
  598. }
  599. /* Loading plugin */
  600. GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Loading transport plugin %s\n", plugin);
  601. GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", plugin);
  602. api = GNUNET_PLUGIN_load (libname, &env);
  603. if (NULL == api)
  604. {
  605. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  606. "Failed to load transport plugin for %s\n", plugin);
  607. end_badly_now ();
  608. return;
  609. }
  610. timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL);
  611. /* Check if all functions are implemented */
  612. if (NULL == api->address_pretty_printer)
  613. {
  614. GNUNET_break (0);
  615. end_badly_now ();
  616. return;
  617. }
  618. if (NULL == api->address_to_string)
  619. {
  620. GNUNET_break (0);
  621. end_badly_now ();
  622. return;
  623. }
  624. GNUNET_assert (NULL != api->check_address);
  625. if (NULL == api->check_address)
  626. {
  627. GNUNET_break (0);
  628. end_badly_now ();
  629. return;
  630. }
  631. GNUNET_assert (NULL != api->disconnect_peer);
  632. if (NULL == api->disconnect_peer)
  633. {
  634. GNUNET_break (0);
  635. end_badly_now ();
  636. return;
  637. }
  638. GNUNET_assert (NULL != api->get_session);
  639. if (NULL == api->get_session)
  640. {
  641. GNUNET_break (0);
  642. end_badly_now ();
  643. return;
  644. }
  645. if (NULL == api->address_pretty_printer)
  646. {
  647. GNUNET_break (0);
  648. end_badly_now ();
  649. return;
  650. }
  651. if (NULL == api->string_to_address)
  652. {
  653. GNUNET_break (0);
  654. end_badly_now ();
  655. return;
  656. }
  657. }
  658. /**
  659. * The main function for the test
  660. *
  661. * @param argc number of arguments from the command line
  662. * @param argv command line arguments
  663. * @return 0 ok, 1 on error
  664. */
  665. int
  666. main (int argc,
  667. char *const *argv)
  668. {
  669. static struct GNUNET_GETOPT_CommandLineOption options[] = {
  670. GNUNET_GETOPT_OPTION_END
  671. };
  672. int ret;
  673. char *const argv_prog[] = {
  674. "test_plugin_transport",
  675. "-c",
  676. "test_plugin_transport_data.conf",
  677. NULL
  678. };
  679. GNUNET_log_setup ("test-plugin-transport",
  680. "WARNING",
  681. NULL);
  682. GNUNET_DISK_purge_cfg_dir ("test_plugin_transport_data.conf",
  683. "GNUNET_TEST_HOME");
  684. ok = 1; /* set to fail */
  685. ret =
  686. (GNUNET_OK
  687. == GNUNET_PROGRAM_run (3, argv_prog, "test-plugin-transport",
  688. "testcase", options, &run, (void *) argv)) ? ok : 1;
  689. GNUNET_DISK_purge_cfg_dir ("test_plugin_transport_data.conf",
  690. "GNUNET_TEST_HOME");
  691. return ret;
  692. }
  693. /* end of test_plugin_transport.c */