transport-testing.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2006, 2009, 2015, 2016 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-testing.h
  18. * @brief testing lib for transport service
  19. * @author Matthias Wachs
  20. * @author Christian Grothoff
  21. */
  22. #ifndef TRANSPORT_TESTING_H
  23. #define TRANSPORT_TESTING_H
  24. #include "platform.h"
  25. #include "gnunet_util_lib.h"
  26. #include "gnunet_hello_lib.h"
  27. #include "gnunet_transport_service.h"
  28. #include "gnunet_transport_hello_service.h"
  29. #include "gnunet_transport_manipulation_service.h"
  30. #include "gnunet_testing_lib.h"
  31. /* ************* Basic functions for starting/stopping/connecting *********** */
  32. /**
  33. * Context for a single peer
  34. */
  35. struct GNUNET_TRANSPORT_TESTING_PeerContext;
  36. /**
  37. * Definition for a transport testing handle
  38. */
  39. struct GNUNET_TRANSPORT_TESTING_Handle;
  40. /**
  41. * Context for a single peer
  42. */
  43. struct GNUNET_TRANSPORT_TESTING_PeerContext
  44. {
  45. /**
  46. * Next element in the DLL
  47. */
  48. struct GNUNET_TRANSPORT_TESTING_PeerContext *next;
  49. /**
  50. * Previous element in the DLL
  51. */
  52. struct GNUNET_TRANSPORT_TESTING_PeerContext *prev;
  53. /**
  54. * Transport testing handle this peer belongs to
  55. */
  56. struct GNUNET_TRANSPORT_TESTING_Handle *tth;
  57. /**
  58. * Peer's configuration
  59. */
  60. struct GNUNET_CONFIGURATION_Handle *cfg;
  61. /**
  62. * Peer's transport service handle
  63. */
  64. struct GNUNET_TRANSPORT_CoreHandle *th;
  65. /**
  66. * Peer's transport service manipulation handle
  67. */
  68. struct GNUNET_TRANSPORT_ManipulationHandle *tmh;
  69. /**
  70. * Peer's ATS handle.
  71. */
  72. struct GNUNET_ATS_ConnectivityHandle *ats;
  73. /**
  74. * Peer's transport get hello handle to retrieve peer's HELLO message
  75. */
  76. struct GNUNET_TRANSPORT_HelloGetHandle *ghh;
  77. /**
  78. * Peer's testing handle
  79. */
  80. struct GNUNET_TESTING_Peer *peer;
  81. /**
  82. * Peer identity
  83. */
  84. struct GNUNET_PeerIdentity id;
  85. /**
  86. * Handle for the peer's ARM process
  87. */
  88. struct GNUNET_OS_Process *arm_proc;
  89. /**
  90. * Receive callback
  91. */
  92. struct GNUNET_MQ_MessageHandler *handlers;
  93. /**
  94. * Notify connect callback
  95. */
  96. GNUNET_TRANSPORT_NotifyConnect nc;
  97. /**
  98. * Notify disconnect callback
  99. */
  100. GNUNET_TRANSPORT_NotifyDisconnect nd;
  101. /**
  102. * Startup completed callback
  103. */
  104. GNUNET_SCHEDULER_TaskCallback start_cb;
  105. /**
  106. * Peers HELLO Message
  107. */
  108. struct GNUNET_HELLO_Message *hello;
  109. /**
  110. * Closure for the @a nc and @a nd callbacks
  111. */
  112. void *cb_cls;
  113. /**
  114. * Closure for @e start_cb.
  115. */
  116. void *start_cb_cls;
  117. /**
  118. * An unique number to identify the peer
  119. */
  120. unsigned int no;
  121. };
  122. /**
  123. * Handle for a request to connect two peers.
  124. */
  125. struct GNUNET_TRANSPORT_TESTING_ConnectRequest
  126. {
  127. /**
  128. * Kept in a DLL.
  129. */
  130. struct GNUNET_TRANSPORT_TESTING_ConnectRequest *next;
  131. /**
  132. * Kept in a DLL.
  133. */
  134. struct GNUNET_TRANSPORT_TESTING_ConnectRequest *prev;
  135. /**
  136. * Peer we want to connect.
  137. */
  138. struct GNUNET_TRANSPORT_TESTING_PeerContext *p1;
  139. /**
  140. * Peer we want to connect.
  141. */
  142. struct GNUNET_TRANSPORT_TESTING_PeerContext *p2;
  143. /**
  144. * Task by which we accomplish the connection.
  145. */
  146. struct GNUNET_SCHEDULER_Task *tct;
  147. /**
  148. * Handle by which we ask ATS to faciliate the connection.
  149. */
  150. struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh;
  151. /**
  152. * Handle by which we inform the peer about the HELLO of
  153. * the other peer.
  154. */
  155. struct GNUNET_TRANSPORT_OfferHelloHandle *oh;
  156. /**
  157. * Function to call upon completion.
  158. */
  159. GNUNET_SCHEDULER_TaskCallback cb;
  160. /**
  161. * Closure for @e cb.
  162. */
  163. void *cb_cls;
  164. /**
  165. * Message queue for sending from @a p1 to @a p2.
  166. */
  167. struct GNUNET_MQ_Handle *mq;
  168. /**
  169. * Set if peer1 says the connection is up to peer2.
  170. */
  171. int p1_c;
  172. /**
  173. * Set if peer2 says the connection is up to peer1.
  174. */
  175. int p2_c;
  176. /**
  177. * #GNUNET_YES if both @e p1_c and @e p2_c are #GNUNET_YES.
  178. */
  179. int connected;
  180. };
  181. /**
  182. * Handle for a test run.
  183. */
  184. struct GNUNET_TRANSPORT_TESTING_Handle
  185. {
  186. /**
  187. * Testing library system handle
  188. */
  189. struct GNUNET_TESTING_System *tl_system;
  190. /**
  191. * head DLL of connect contexts
  192. */
  193. struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc_head;
  194. /**
  195. * head DLL of connect contexts
  196. */
  197. struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc_tail;
  198. /**
  199. * head DLL of peers
  200. */
  201. struct GNUNET_TRANSPORT_TESTING_PeerContext *p_head;
  202. /**
  203. * tail DLL of peers
  204. */
  205. struct GNUNET_TRANSPORT_TESTING_PeerContext *p_tail;
  206. };
  207. /**
  208. * Initialize the transport testing
  209. *
  210. * @return transport testing handle
  211. */
  212. struct GNUNET_TRANSPORT_TESTING_Handle *
  213. GNUNET_TRANSPORT_TESTING_init (void);
  214. /**
  215. * Clean up the transport testing
  216. *
  217. * @param tth transport testing handle
  218. */
  219. void
  220. GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_Handle *tth);
  221. /**
  222. * Start a peer with the given configuration
  223. *
  224. * @param tth the testing handle
  225. * @param cfgname configuration file
  226. * @param peer_id the peer_id
  227. * @param handlers functions for receiving messages
  228. * @param nc connect callback
  229. * @param nd disconnect callback
  230. * @param cb_cls closure for @a nc and @a nd callback
  231. * @param start_cb start callback
  232. * @param start_cb_cls closure for @a start_cb
  233. * @return the peer context
  234. */
  235. struct GNUNET_TRANSPORT_TESTING_PeerContext *
  236. GNUNET_TRANSPORT_TESTING_start_peer (
  237. struct GNUNET_TRANSPORT_TESTING_Handle *tth,
  238. const char *cfgname,
  239. int peer_id,
  240. const struct GNUNET_MQ_MessageHandler *handlers,
  241. GNUNET_TRANSPORT_NotifyConnect nc,
  242. GNUNET_TRANSPORT_NotifyDisconnect nd,
  243. void *cb_cls,
  244. GNUNET_SCHEDULER_TaskCallback start_cb,
  245. void *start_cb_cls);
  246. /**
  247. * Shutdown the given peer
  248. *
  249. * @param p the peer
  250. */
  251. void
  252. GNUNET_TRANSPORT_TESTING_stop_peer (
  253. struct GNUNET_TRANSPORT_TESTING_PeerContext *pc);
  254. /**
  255. * Stops and restarts the given peer, sleeping (!) for 5s in between.
  256. *
  257. * @param p the peer
  258. * @param restart_cb restart callback
  259. * @param restart_cb_cls callback closure
  260. * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR
  261. */
  262. int
  263. GNUNET_TRANSPORT_TESTING_restart_peer (
  264. struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
  265. GNUNET_SCHEDULER_TaskCallback restart_cb,
  266. void *restart_cb_cls);
  267. /**
  268. * Connect the given peers and call the callback when both peers
  269. * report the inbound connection. Remarks: start_peer's notify_connect
  270. * callback can be called before.
  271. *
  272. * @param p1 peer 1
  273. * @param p2 peer 2
  274. * @param cb the callback to call when both peers notified that they are
  275. * connected
  276. * @param cls callback cls
  277. * @return a connect request handle
  278. */
  279. struct GNUNET_TRANSPORT_TESTING_ConnectRequest *
  280. GNUNET_TRANSPORT_TESTING_connect_peers (
  281. struct GNUNET_TRANSPORT_TESTING_PeerContext *p1,
  282. struct GNUNET_TRANSPORT_TESTING_PeerContext *p2,
  283. GNUNET_SCHEDULER_TaskCallback cb,
  284. void *cls);
  285. /**
  286. * Cancel the request to connect two peers. You MUST cancel the
  287. * request if you stop the peers before the peers connected
  288. * succesfully.
  289. *
  290. * @param cc a connect request handle
  291. */
  292. void
  293. GNUNET_TRANSPORT_TESTING_connect_peers_cancel (
  294. struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc);
  295. /**
  296. * Function called on matching connect requests.
  297. *
  298. * @param cls closure
  299. * @param cc request matching the query
  300. */
  301. typedef void (*GNUNET_TRANSPORT_TESTING_ConnectContextCallback) (
  302. void *cls,
  303. struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc);
  304. /**
  305. * Find any connecting context matching the given pair of peers.
  306. *
  307. * @param p1 first peer
  308. * @param p2 second peer
  309. * @param cb function to call
  310. * @param cb_cls closure for @a cb
  311. */
  312. void
  313. GNUNET_TRANSPORT_TESTING_find_connecting_context (
  314. struct GNUNET_TRANSPORT_TESTING_PeerContext *p1,
  315. struct GNUNET_TRANSPORT_TESTING_PeerContext *p2,
  316. GNUNET_TRANSPORT_TESTING_ConnectContextCallback cb,
  317. void *cb_cls);
  318. /* ********************** high-level process functions *************** */
  319. /**
  320. * Function called once the peers have been launched and
  321. * connected by #GNUNET_TRANSPORT_TESTING_connect_check().
  322. *
  323. * @param cls closure
  324. * @param num_peers size of the @a p array
  325. * @param p the peers that were launched
  326. */
  327. typedef void (*GNUNET_TRANSPORT_TESTING_ConnectContinuation) (
  328. void *cls,
  329. unsigned int num_peers,
  330. struct GNUNET_TRANSPORT_TESTING_PeerContext *p[]);
  331. /**
  332. * Internal data structure.
  333. */
  334. struct GNUNET_TRANSPORT_TESTING_ConnectRequestList;
  335. /**
  336. * Internal data structure.
  337. */
  338. struct GNUNET_TRANSPORT_TESTING_InternalPeerContext;
  339. GNUNET_NETWORK_STRUCT_BEGIN
  340. struct GNUNET_TRANSPORT_TESTING_TestMessage
  341. {
  342. /**
  343. * Type is (usually) #GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE.
  344. */
  345. struct GNUNET_MessageHeader header;
  346. /**
  347. * Monotonically increasing counter throughout the test.
  348. */
  349. uint32_t num GNUNET_PACKED;
  350. };
  351. GNUNET_NETWORK_STRUCT_END
  352. /**
  353. * Function called by the transport for each received message.
  354. *
  355. * @param cls closure
  356. * @param receiver receiver of the message
  357. * @param sender sender of the message
  358. * @param message the message
  359. */
  360. typedef void (*GNUNET_TRANSPORT_TESTING_ReceiveCallback) (
  361. void *cls,
  362. struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
  363. const struct GNUNET_PeerIdentity *sender,
  364. const struct GNUNET_TRANSPORT_TESTING_TestMessage *message);
  365. /**
  366. * Function called to notify transport users that another
  367. * peer connected to us.
  368. *
  369. * @param cls closure
  370. * @param me peer experiencing the event
  371. * @param other peer that connected to @a me
  372. */
  373. typedef void (*GNUNET_TRANSPORT_TESTING_NotifyConnect) (
  374. void *cls,
  375. struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
  376. const struct GNUNET_PeerIdentity *other);
  377. /**
  378. * Function called to notify transport users that another
  379. * peer disconnected from us.
  380. *
  381. * @param cls closure
  382. * @param me peer experiencing the event
  383. * @param other peer that disconnected from @a me
  384. */
  385. typedef void (*GNUNET_TRANSPORT_TESTING_NotifyDisconnect) (
  386. void *cls,
  387. struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
  388. const struct GNUNET_PeerIdentity *other);
  389. /**
  390. * Closure that must be passed to
  391. * #GNUNET_TRANSPORT_TESTING_connect_check.
  392. */
  393. struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext
  394. {
  395. /**
  396. * How should we continue after the connect?
  397. */
  398. GNUNET_SCHEDULER_TaskCallback connect_continuation;
  399. /**
  400. * Closure for @e connect_continuation.
  401. */
  402. void *connect_continuation_cls;
  403. /**
  404. * Which configuration file should we pass to the
  405. * #GNUNET_PROGRAM_run() of the testcase?
  406. */
  407. const char *config_file;
  408. /**
  409. * Receiver argument to give for peers we start.
  410. */
  411. GNUNET_TRANSPORT_TESTING_ReceiveCallback rec;
  412. /**
  413. * Notify connect argument to give for peers we start.
  414. */
  415. GNUNET_TRANSPORT_TESTING_NotifyConnect nc;
  416. /**
  417. * Notify disconnect argument to give for peers we start.
  418. */
  419. GNUNET_TRANSPORT_TESTING_NotifyDisconnect nd;
  420. /**
  421. * Closure for @e rec, @e nc and @e nd.
  422. */
  423. void *cls;
  424. /**
  425. * Custom task to run on shutdown.
  426. */
  427. GNUNET_SCHEDULER_TaskCallback shutdown_task;
  428. /**
  429. * Closure for @e shutdown_task.
  430. */
  431. void *shutdown_task_cls;
  432. /**
  433. * Custom task to run after peers were started but before we try to
  434. * connect them. If this function is set, we wait ONE second after
  435. * running this function until we continue with connecting the
  436. * peers.
  437. */
  438. GNUNET_SCHEDULER_TaskCallback pre_connect_task;
  439. /**
  440. * Closure for @e shutdown_task.
  441. */
  442. void *pre_connect_task_cls;
  443. /**
  444. * When should the testcase time out?
  445. */
  446. struct GNUNET_TIME_Relative timeout;
  447. /**
  448. * Should we try to create connections in both directions?
  449. */
  450. int bi_directional;
  451. /* ******* fields set by #GNUNET_TRANSPORT_TESTING_connect_check **** */
  452. /**
  453. * Number of peers involved in the test.
  454. */
  455. unsigned int num_peers;
  456. /**
  457. * Configuration files we have, array with @e num_peers entries.
  458. */
  459. char **cfg_files;
  460. /**
  461. * Array with @e num_peers entries.
  462. */
  463. struct GNUNET_TRANSPORT_TESTING_PeerContext **p;
  464. /**
  465. * Name of the plugin.
  466. */
  467. const char *test_plugin;
  468. /**
  469. * Name of the testcase.
  470. */
  471. const char *test_name;
  472. /**
  473. * Configuration object for the testcase.
  474. */
  475. const struct GNUNET_CONFIGURATION_Handle *cfg;
  476. /**
  477. * Main testing handle.
  478. */
  479. struct GNUNET_TRANSPORT_TESTING_Handle *tth;
  480. /**
  481. * Result from the main function, set to #GNUNET_OK on success.
  482. * Clients should set to #GNUNET_SYSERR to indicate test failure.
  483. */
  484. int global_ret;
  485. /**
  486. * Generator for the `num` field in test messages. Incremented each
  487. * time #GNUNET_TRANSPORT_TESTING_simple_send or
  488. * #GNUNET_TRANSPORT_TESTING_large_send are used to transmit a
  489. * message.
  490. */
  491. uint32_t send_num_gen;
  492. /* ******* internal state, clients should not mess with this **** */
  493. /**
  494. * Task run on timeout.
  495. */
  496. struct GNUNET_SCHEDULER_Task *timeout_task;
  497. /**
  498. * Task run to connect peers.
  499. */
  500. struct GNUNET_SCHEDULER_Task *connect_task;
  501. /**
  502. * Number of peers that have been started.
  503. */
  504. unsigned int started;
  505. /**
  506. * DLL of active connect requests.
  507. */
  508. struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl_head;
  509. /**
  510. * DLL of active connect requests.
  511. */
  512. struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl_tail;
  513. /**
  514. * Array with @e num_peers entries.
  515. */
  516. struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ip;
  517. };
  518. /**
  519. * Find peer by peer ID.
  520. *
  521. * @param ccc context to search
  522. * @param peer peer to look for
  523. * @return NULL if @a peer was not found
  524. */
  525. struct GNUNET_TRANSPORT_TESTING_PeerContext *
  526. GNUNET_TRANSPORT_TESTING_find_peer (
  527. struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc,
  528. const struct GNUNET_PeerIdentity *peer);
  529. /**
  530. * Common implementation of the #GNUNET_TRANSPORT_TESTING_CheckCallback.
  531. * Starts and connects the two peers, then invokes the
  532. * `connect_continuation` from @a cls. Sets up a timeout to
  533. * abort the test, and a shutdown handler to clean up properly
  534. * on exit.
  535. *
  536. * @param cls closure of type `struct
  537. * GNUNET_TRANSPORT_TESTING_ConnectCheckContext`
  538. * @param tth_ initialized testing handle
  539. * @param test_plugin_ name of the plugin
  540. * @param test_name_ name of the test
  541. * @param num_peers number of entries in the @a cfg_file array
  542. * @param cfg_files array of names of configuration files for the peers
  543. * @return #GNUNET_SYSERR on error
  544. */
  545. int
  546. GNUNET_TRANSPORT_TESTING_connect_check (
  547. void *cls,
  548. struct GNUNET_TRANSPORT_TESTING_Handle *tth_,
  549. const char *test_plugin_,
  550. const char *test_name_,
  551. unsigned int num_peers,
  552. char *cfg_files[]);
  553. /**
  554. * Main function of a testcase. Called with the initial setup data
  555. * for the test as derived from the source name and the binary name.
  556. *
  557. * @param cls closure
  558. * @param tth_ initialized testing handle
  559. * @param test_plugin_ name of the plugin
  560. * @param test_name_ name of the test
  561. * @param num_peers number of entries in the @a cfg_file array
  562. * @param cfg_files array of names of configuration files for the peers
  563. * @return #GNUNET_SYSERR on error
  564. */
  565. typedef int (*GNUNET_TRANSPORT_TESTING_CheckCallback) (
  566. void *cls,
  567. struct GNUNET_TRANSPORT_TESTING_Handle *tth_,
  568. const char *test_plugin_,
  569. const char *test_name_,
  570. unsigned int num_peers,
  571. char *cfg_files[]);
  572. /**
  573. * Setup testcase. Calls @a check with the data the test needs.
  574. *
  575. * @param argv0 binary name (argv[0])
  576. * @param filename source file name (__FILE__)
  577. * @param num_peers number of peers to start
  578. * @param check main function to run
  579. * @param check_cls closure for @a check
  580. * @return #GNUNET_OK on success
  581. */
  582. int
  583. GNUNET_TRANSPORT_TESTING_main_ (const char *argv0,
  584. const char *filename,
  585. unsigned int num_peers,
  586. GNUNET_TRANSPORT_TESTING_CheckCallback check,
  587. void *check_cls);
  588. /**
  589. * Setup testcase. Calls @a check with the data the test needs.
  590. *
  591. * @param num_peers number of peers to start
  592. * @param check main function to run
  593. * @param check_cls closure for @a check
  594. * @return #GNUNET_OK on success
  595. */
  596. #define GNUNET_TRANSPORT_TESTING_main(num_peers, check, check_cls) \
  597. GNUNET_TRANSPORT_TESTING_main_ (argv[0], \
  598. __FILE__, \
  599. num_peers, \
  600. check, \
  601. check_cls)
  602. /* ***************** Convenience functions for sending ********* */
  603. /**
  604. * Send a test message of type @a mtype and size @a msize from
  605. * peer @a sender to peer @a receiver. The peers should be
  606. * connected when this function is called.
  607. *
  608. * @param sender the sending peer
  609. * @param receiver the receiving peer
  610. * @param mtype message type to use
  611. * @param msize size of the message, at least `sizeof (struct
  612. * GNUNET_TRANSPORT_TESTING_TestMessage)`
  613. * @param num unique message number
  614. * @param cont continuation to call after transmission
  615. * @param cont_cls closure for @a cont
  616. * @return #GNUNET_OK if message was queued,
  617. * #GNUNET_NO if peers are not connected
  618. * #GNUNET_SYSERR if @a msize is illegal
  619. */
  620. int
  621. GNUNET_TRANSPORT_TESTING_send (
  622. struct GNUNET_TRANSPORT_TESTING_PeerContext *sender,
  623. struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
  624. uint16_t mtype,
  625. uint16_t msize,
  626. uint32_t num,
  627. GNUNET_SCHEDULER_TaskCallback cont,
  628. void *cont_cls);
  629. /**
  630. * Message type used by #GNUNET_TRANSPORT_TESTING_simple_send().
  631. */
  632. #define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE 12345
  633. /**
  634. * Alternative message type for tests.
  635. */
  636. #define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2 12346
  637. /**
  638. * Type of the closure argument to pass to
  639. * #GNUNET_TRANSPORT_TESTING_simple_send() and
  640. * #GNUNET_TRANSPORT_TESTING_large_send().
  641. */
  642. struct GNUNET_TRANSPORT_TESTING_SendClosure
  643. {
  644. /**
  645. * Context for the transmission.
  646. */
  647. struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
  648. /**
  649. * Function that returns the desired message size. Overrides
  650. * the message size, can be NULL in which case the message
  651. * size is the default.
  652. */
  653. size_t (*get_size_cb) (unsigned int n);
  654. /**
  655. * Number of messages to be transmitted in a loop.
  656. * Use zero for "forever" (until external shutdown).
  657. */
  658. unsigned int num_messages;
  659. /**
  660. * Function to call after all transmissions, can be NULL.
  661. */
  662. GNUNET_SCHEDULER_TaskCallback cont;
  663. /**
  664. * Closure for @e cont.
  665. */
  666. void *cont_cls;
  667. };
  668. /**
  669. * Task that sends a minimalistic test message from the
  670. * first peer to the second peer.
  671. *
  672. * @param cls the `struct GNUNET_TRANSPORT_TESTING_SendClosure`
  673. * which should contain at least two peers, the first two
  674. * of which should be currently connected
  675. */
  676. void
  677. GNUNET_TRANSPORT_TESTING_simple_send (void *cls);
  678. /**
  679. * Size of a message sent with
  680. * #GNUNET_TRANSPORT_TESTING_large_send(). Big enough
  681. * to usually force defragmentation.
  682. */
  683. #define GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE 2600
  684. /**
  685. * Task that sends a large test message from the
  686. * first peer to the second peer.
  687. *
  688. * @param cls the `struct GNUNET_TRANSPORT_TESTING_SendClosure`
  689. * which should contain at least two peers, the first two
  690. * of which should be currently connected
  691. */
  692. void
  693. GNUNET_TRANSPORT_TESTING_large_send (void *cls);
  694. /* ********************** log-only convenience functions ************* */
  695. /**
  696. * Log a connect event.
  697. *
  698. * @param cls NULL
  699. * @param me peer that had the event
  700. * @param other peer that connected.
  701. */
  702. void
  703. GNUNET_TRANSPORT_TESTING_log_connect (
  704. void *cls,
  705. struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
  706. const struct GNUNET_PeerIdentity *other);
  707. /**
  708. * Log a disconnect event.
  709. *
  710. * @param cls NULL
  711. * @param me peer that had the event
  712. * @param other peer that disconnected.
  713. */
  714. void
  715. GNUNET_TRANSPORT_TESTING_log_disconnect (
  716. void *cls,
  717. struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
  718. const struct GNUNET_PeerIdentity *other);
  719. /* ********************** low-level filename functions *************** */
  720. /**
  721. * Extracts the test filename from an absolute file name and removes
  722. * the extension.
  723. *
  724. * @param file absolute file name
  725. * @return resulting test name
  726. */
  727. char *
  728. GNUNET_TRANSPORT_TESTING_get_test_name (const char *file);
  729. /**
  730. * This function takes the filename (e.g. argv[0), removes a "lt-"-prefix and
  731. * if existing ".exe"-prefix and adds the peer-number
  732. *
  733. * @param file filename of the test, e.g. argv[0]
  734. * @param count peer number
  735. * @return configuration name to use
  736. */
  737. char *
  738. GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, int count);
  739. /**
  740. * Extracts the plugin anme from an absolute file name and the test name
  741. * @param file absolute file name
  742. * @param test test name
  743. * @return the plugin name
  744. */
  745. char *
  746. GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *executable,
  747. const char *testname);
  748. /**
  749. * Extracts the filename from an absolute file name and removes the
  750. * extenstion
  751. *
  752. * @param file absolute file name
  753. * @return the source name
  754. */
  755. char *
  756. GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file);
  757. #endif
  758. /* end of transport_testing.h */