transport-testing.h 23 KB

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