test_plugin_transport.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  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, "Plugin did not remove %u addresses \n",
  135. c);
  136. ok = 1;
  137. }
  138. GNUNET_free(libname);
  139. libname = NULL;
  140. GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
  141. stats = NULL;
  142. if (NULL != suid_helper)
  143. {
  144. GNUNET_HELPER_stop (suid_helper, GNUNET_NO);
  145. suid_helper = NULL;
  146. }
  147. }
  148. static void
  149. end_badly (void *cls)
  150. {
  151. struct AddressWrapper *w;
  152. int c = 0;
  153. timeout_endbadly = NULL;
  154. if (NULL != timeout_wait)
  155. {
  156. GNUNET_SCHEDULER_cancel (timeout_wait);
  157. timeout_wait = NULL;
  158. }
  159. if (pretty_printers_running > 0)
  160. {
  161. timeout_endbadly = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
  162. &end_badly, &ok);
  163. GNUNET_log(GNUNET_ERROR_TYPE_INFO,
  164. "Have pending calls to pretty_printer ... deferring shutdown\n");
  165. return;
  166. }
  167. if (NULL != cls)
  168. {
  169. GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
  170. "Test took too long to execute, timeout .... \n");
  171. }
  172. if (NULL != libname)
  173. {
  174. if (NULL != api)
  175. GNUNET_PLUGIN_unload (libname, api);
  176. GNUNET_free(libname);
  177. libname = NULL;
  178. }
  179. while (NULL != head)
  180. {
  181. w = head;
  182. GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove address `%s'\n",
  183. w->addrstring);
  184. GNUNET_CONTAINER_DLL_remove(head, tail, w);
  185. c++;
  186. GNUNET_HELLO_address_free(w->address);
  187. if (NULL != w->test_task)
  188. GNUNET_SCHEDULER_cancel (w->test_task);
  189. GNUNET_free(w->addrstring);
  190. GNUNET_free(w);
  191. }
  192. if (c > 0)
  193. {
  194. GNUNET_break(0);
  195. GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove %u addresses\n",
  196. c);
  197. }
  198. if (NULL != stats)
  199. {
  200. GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
  201. stats = NULL;
  202. }
  203. if (NULL != suid_helper)
  204. {
  205. GNUNET_HELPER_stop (suid_helper, GNUNET_NO);
  206. suid_helper = NULL;
  207. }
  208. ok = 1;
  209. }
  210. static void
  211. wait_end (void *cls)
  212. {
  213. timeout_wait = NULL;
  214. if (0 == addresses_reported)
  215. GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
  216. "Plugin did not report any addresses, could not check address conversion functions\n");
  217. end ();
  218. }
  219. static void
  220. end_badly_now ()
  221. {
  222. if (NULL != timeout_wait)
  223. {
  224. GNUNET_SCHEDULER_cancel (timeout_wait);
  225. timeout_wait = NULL;
  226. }
  227. if (NULL != timeout_endbadly)
  228. {
  229. GNUNET_SCHEDULER_cancel (timeout_endbadly);
  230. timeout_endbadly = NULL;
  231. }
  232. timeout_endbadly = GNUNET_SCHEDULER_add_now (&end_badly, NULL );
  233. }
  234. static struct GNUNET_TIME_Relative
  235. env_receive (void *cls,
  236. const struct GNUNET_HELLO_Address *address,
  237. struct GNUNET_ATS_Session *session,
  238. const struct GNUNET_MessageHeader *message)
  239. {
  240. /* do nothing */
  241. return GNUNET_TIME_relative_get_zero_ ();
  242. }
  243. static int got_reply;
  244. /**
  245. * Take the given address and append it to the set of results sent back to
  246. * the client.
  247. *
  248. * @param cls closure
  249. * @param address the address to print
  250. * @param res result code
  251. */
  252. static void
  253. address_pretty_printer_cb (void *cls, const char *address, int res)
  254. {
  255. if (NULL != address)
  256. {
  257. got_reply = GNUNET_YES;
  258. GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Pretty address : `%s'\n", address);
  259. pretty_printers_running--;
  260. }
  261. else
  262. {
  263. if (GNUNET_NO == got_reply)
  264. {
  265. pretty_printers_running--;
  266. GNUNET_break(0);
  267. end_badly_now ();
  268. }
  269. }
  270. }
  271. static void
  272. test_addr_string (void *cls)
  273. {
  274. struct AddressWrapper *w = cls;
  275. void *s2a;
  276. size_t s2a_len;
  277. w->test_task = NULL;
  278. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  279. "Testing: address_to_string \n");
  280. w->addrstring = GNUNET_strdup (api->address_to_string (api,
  281. w->address->address,
  282. w->address->address_length));
  283. if (NULL == w->addrstring)
  284. {
  285. GNUNET_break(0);
  286. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  287. "Plugin cannot convert address to string!\n");
  288. end_badly_now ();
  289. return;
  290. }
  291. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  292. "Plugin added address `%s'\n",
  293. w->addrstring);
  294. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  295. "Testing address_to_string: OK\n");
  296. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  297. "Testing: string_to_address \n");
  298. s2a = NULL;
  299. s2a_len = 0;
  300. if ((GNUNET_OK !=
  301. api->string_to_address (api, w->addrstring,
  302. strlen (w->addrstring) + 1,
  303. &s2a, &s2a_len)) ||
  304. (NULL == s2a))
  305. {
  306. GNUNET_break(0);
  307. GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
  308. "Plugin cannot convert string to address!\n");
  309. end_badly_now ();
  310. return;
  311. }
  312. /*
  313. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  314. "Plugin creates `%s' %u\n",api->address_to_string (api, s2a, s2a_len), s2a_len);
  315. int c1;
  316. for (c1 = 0; c1 < s2a_len; c1++ )
  317. fprintf (stderr, "%u == %u\n", ((char *) s2a)[c1], ((char *) w->addr)[c1]);
  318. */
  319. if (s2a_len != w->address->address_length)
  320. {
  321. GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
  322. "Plugin creates different address length when converting address->string->address: %u != %u\n",
  323. (unsigned int) w->address->address_length,
  324. (unsigned int) s2a_len);
  325. }
  326. else if (0 != memcmp (s2a, w->address->address, s2a_len))
  327. {
  328. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  329. "Plugin creates different address length when converting back and forth %i!\n",
  330. memcmp (s2a,
  331. w->address->address,
  332. s2a_len));
  333. }
  334. else
  335. {
  336. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  337. "Testing string_to_address: OK\n");
  338. }
  339. GNUNET_free(s2a);
  340. pretty_printers_running++;
  341. api->address_pretty_printer (api->cls,
  342. w->address->transport_name,
  343. w->address->address,
  344. w->address->address_length,
  345. GNUNET_YES,
  346. GNUNET_TIME_UNIT_MINUTES,
  347. &address_pretty_printer_cb, w);
  348. if (GNUNET_OK !=
  349. api->check_address (api->cls,
  350. w->address->address,
  351. w->address->address_length))
  352. {
  353. GNUNET_break (0);
  354. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  355. "Plugin refuses added address!\n");
  356. end_badly_now ();
  357. return;
  358. }
  359. if (NULL != timeout_wait)
  360. {
  361. GNUNET_SCHEDULER_cancel (timeout_wait);
  362. timeout_wait = NULL;
  363. }
  364. timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL);
  365. }
  366. static void
  367. env_notify_address (void *cls,
  368. int add_remove,
  369. const struct GNUNET_HELLO_Address *address)
  370. {
  371. struct AddressWrapper *w;
  372. struct AddressWrapper *wtmp;
  373. if (GNUNET_YES == add_remove)
  374. {
  375. addresses_reported++;
  376. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  377. "Adding address of length %u\n",
  378. (unsigned int) address->address_length);
  379. for (wtmp = head; NULL != wtmp; wtmp = wtmp->next)
  380. {
  381. if ((address->address_length == wtmp->address->address_length) &&
  382. (0 == memcmp (address->address, wtmp->address->address, address->address_length)))
  383. {
  384. GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
  385. "Duplicate address notification .... \n");
  386. return;
  387. }
  388. }
  389. w = GNUNET_new (struct AddressWrapper);
  390. w->address = GNUNET_HELLO_address_copy (address);
  391. GNUNET_CONTAINER_DLL_insert (head, tail, w);
  392. got_reply = GNUNET_NO;
  393. w->test_task = GNUNET_SCHEDULER_add_now (&test_addr_string,
  394. w);
  395. return;
  396. }
  397. if (GNUNET_NO == add_remove)
  398. {
  399. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  400. "Removing address of length %u\n",
  401. (unsigned int) address->address_length);
  402. w = head;
  403. while (NULL != w)
  404. {
  405. if ((address->address_length == w->address->address_length) &&
  406. (0 == memcmp (w->address->address, address->address, address->address_length)))
  407. {
  408. break;
  409. }
  410. w = w->next;
  411. }
  412. if (w == NULL)
  413. {
  414. GNUNET_break(0);
  415. GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
  416. "Plugin removes address never added!\n");
  417. end_badly_now ();
  418. return;
  419. }
  420. GNUNET_CONTAINER_DLL_remove(head, tail, w);
  421. GNUNET_HELLO_address_free (w->address);
  422. GNUNET_free(w->addrstring);
  423. GNUNET_free(w);
  424. return;
  425. }
  426. GNUNET_break(0);
  427. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  428. "Invalid operation: %u\n",
  429. add_remove);
  430. end_badly_now ();
  431. }
  432. static enum GNUNET_NetworkType
  433. env_get_address_type (void *cls,
  434. const struct sockaddr *addr,
  435. size_t addrlen)
  436. {
  437. return GNUNET_NT_LOOPBACK;
  438. }
  439. static const struct GNUNET_MessageHeader *
  440. env_get_our_hello ()
  441. {
  442. return (const struct GNUNET_MessageHeader *) hello;
  443. }
  444. static void
  445. env_session_end (void *cls,
  446. const struct GNUNET_HELLO_Address *address,
  447. struct GNUNET_ATS_Session *session)
  448. {
  449. }
  450. static void
  451. env_update_distance (void *cls,
  452. const struct GNUNET_HELLO_Address *address,
  453. uint32_t distance)
  454. {
  455. }
  456. static void
  457. setup_plugin_environment ()
  458. {
  459. env.cfg = cfg;
  460. env.cls = &env;
  461. env.my_identity = &my_identity;
  462. env.max_connections = max_connect_per_transport;
  463. env.stats = stats;
  464. env.receive = &env_receive;
  465. env.notify_address = &env_notify_address;
  466. env.get_address_type = &env_get_address_type;
  467. env.update_address_distance = &env_update_distance;
  468. env.get_our_hello = &env_get_our_hello;
  469. env.session_end = &env_session_end;
  470. }
  471. static int
  472. handle_helper_message (void *cls,
  473. const struct GNUNET_MessageHeader *hdr)
  474. {
  475. return GNUNET_OK;
  476. }
  477. /**
  478. * Runs the test.
  479. *
  480. * @param cls closure
  481. * @param c configuration to use
  482. */
  483. static void
  484. run (void *cls,
  485. char * const *args,
  486. const char *cfgfile,
  487. const struct GNUNET_CONFIGURATION_Handle *c)
  488. {
  489. char * const *argv = cls;
  490. unsigned long long tneigh;
  491. char *keyfile;
  492. char *plugin;
  493. char *sep;
  494. timeout_endbadly = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
  495. &end_badly,
  496. &ok);
  497. cfg = c;
  498. /* parse configuration */
  499. if ( (GNUNET_OK !=
  500. GNUNET_CONFIGURATION_get_value_number (c,
  501. "TRANSPORT",
  502. "NEIGHBOUR_LIMIT",
  503. &tneigh)) ||
  504. (GNUNET_OK !=
  505. GNUNET_CONFIGURATION_get_value_filename (c,
  506. "PEER",
  507. "PRIVATE_KEY",
  508. &keyfile)))
  509. {
  510. GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
  511. "Transport service is lacking key configuration settings. Exiting.\n");
  512. return;
  513. }
  514. if (NULL == (stats = GNUNET_STATISTICS_create ("transport",
  515. cfg)))
  516. {
  517. GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
  518. "Could not create statistics. Exiting.\n");
  519. GNUNET_free(keyfile);
  520. end_badly_now ();
  521. return;
  522. }
  523. if (GNUNET_OK != GNUNET_DISK_file_test (HOSTKEY_FILE))
  524. {
  525. GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
  526. "Hostkey `%s' missing. Exiting.\n",
  527. HOSTKEY_FILE);
  528. GNUNET_free(keyfile);
  529. end_badly_now ();
  530. return;
  531. }
  532. if (GNUNET_OK !=
  533. GNUNET_DISK_directory_create_for_file (keyfile))
  534. {
  535. GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
  536. "Could not create a directory for hostkey `%s'. Exiting.\n",
  537. keyfile);
  538. GNUNET_free(keyfile);
  539. end_badly_now ();
  540. return;
  541. }
  542. if (GNUNET_OK !=
  543. GNUNET_DISK_file_copy (HOSTKEY_FILE,
  544. keyfile))
  545. {
  546. GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
  547. "Could not copy hostkey `%s' to destination `%s'. Exiting.\n",
  548. HOSTKEY_FILE,
  549. keyfile);
  550. GNUNET_free(keyfile);
  551. end_badly_now ();
  552. return;
  553. }
  554. max_connect_per_transport = (uint32_t) tneigh;
  555. my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile);
  556. GNUNET_free(keyfile);
  557. if (NULL == my_private_key)
  558. {
  559. GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
  560. "Could not access hostkey. Exiting.\n");
  561. end_badly_now ();
  562. return;
  563. }
  564. GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_identity.public_key);
  565. hello = GNUNET_HELLO_create (&my_identity.public_key, NULL, NULL, GNUNET_NO);
  566. /* load plugins... */
  567. setup_plugin_environment ();
  568. GNUNET_assert(strlen (argv[0]) > strlen ("test_plugin_"));
  569. plugin = strstr (argv[0], "test_plugin_");
  570. sep = strrchr (argv[0], '.');
  571. if (NULL == plugin)
  572. {
  573. GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Not a valid test name\n");
  574. end_badly_now ();
  575. return;
  576. }
  577. plugin += strlen ("test_plugin_");
  578. if (NULL != sep)
  579. sep[0] = '\0';
  580. /* Hack for WLAN: start a second helper */
  581. if (0 == strcmp (plugin, "wlan"))
  582. {
  583. char * helper_argv[3];
  584. helper_argv[0] = (char *) "gnunet-helper-transport-wlan-dummy";
  585. helper_argv[1] = (char *) "2";
  586. helper_argv[2] = NULL;
  587. suid_helper = GNUNET_HELPER_start (GNUNET_NO,
  588. "gnunet-helper-transport-wlan-dummy", helper_argv,
  589. &handle_helper_message, NULL, NULL );
  590. }
  591. /* Loading plugin */
  592. GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Loading transport plugin %s\n", plugin);
  593. GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", plugin);
  594. api = GNUNET_PLUGIN_load (libname, &env);
  595. if (NULL == api)
  596. {
  597. GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
  598. "Failed to load transport plugin for %s\n", plugin);
  599. end_badly_now ();
  600. return;
  601. }
  602. timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL );
  603. /* Check if all functions are implemented */
  604. if (NULL == api->address_pretty_printer)
  605. {
  606. GNUNET_break(0);
  607. end_badly_now ();
  608. return;
  609. }
  610. if (NULL == api->address_to_string)
  611. {
  612. GNUNET_break(0);
  613. end_badly_now ();
  614. return;
  615. }
  616. GNUNET_assert(NULL != api->check_address);
  617. if (NULL == api->check_address)
  618. {
  619. GNUNET_break(0);
  620. end_badly_now ();
  621. return;
  622. }
  623. GNUNET_assert(NULL != api->disconnect_peer);
  624. if (NULL == api->disconnect_peer)
  625. {
  626. GNUNET_break(0);
  627. end_badly_now ();
  628. return;
  629. }
  630. GNUNET_assert(NULL != api->get_session);
  631. if (NULL == api->get_session)
  632. {
  633. GNUNET_break(0);
  634. end_badly_now ();
  635. return;
  636. }
  637. if (NULL == api->address_pretty_printer)
  638. {
  639. GNUNET_break(0);
  640. end_badly_now ();
  641. return;
  642. }
  643. if (NULL == api->string_to_address)
  644. {
  645. GNUNET_break(0);
  646. end_badly_now ();
  647. return;
  648. }
  649. }
  650. /**
  651. * The main function for the test
  652. *
  653. * @param argc number of arguments from the command line
  654. * @param argv command line arguments
  655. * @return 0 ok, 1 on error
  656. */
  657. int
  658. main (int argc,
  659. char * const *argv)
  660. {
  661. static struct GNUNET_GETOPT_CommandLineOption options[] = {
  662. GNUNET_GETOPT_OPTION_END
  663. };
  664. int ret;
  665. char * const argv_prog[] = {
  666. "test_plugin_transport",
  667. "-c",
  668. "test_plugin_transport_data.conf",
  669. NULL
  670. };
  671. GNUNET_log_setup ("test-plugin-transport",
  672. "WARNING",
  673. NULL);
  674. GNUNET_DISK_purge_cfg_dir ("test_plugin_transport_data.conf",
  675. "GNUNET_TEST_HOME");
  676. ok = 1; /* set to fail */
  677. ret =
  678. (GNUNET_OK
  679. == GNUNET_PROGRAM_run (3, argv_prog, "test-plugin-transport",
  680. "testcase", options, &run, (void *) argv)) ? ok : 1;
  681. GNUNET_DISK_purge_cfg_dir ("test_plugin_transport_data.conf",
  682. "GNUNET_TEST_HOME");
  683. return ret;
  684. }
  685. /* end of test_plugin_transport.c */