gnunet_testbed_service.h 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738
  1. /*
  2. This file is part of GNUnet
  3. Copyright (C) 2008--2013 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. * @author Christian Grothoff
  18. *
  19. * @file
  20. * API for writing tests and creating large-scale emulation testbeds for GNUnet.
  21. *
  22. * @defgroup testbed Testbed service
  23. * Writing tests and creating large-scale emulation testbeds for GNUnet.
  24. *
  25. * @see [Documentation](https://gnunet.org/gnunet-testbed-subsystem)
  26. *
  27. * @{
  28. */
  29. #ifndef GNUNET_TESTBED_SERVICE_H
  30. #define GNUNET_TESTBED_SERVICE_H
  31. #include "gnunet_util_lib.h"
  32. #include "gnunet_testing_lib.h"
  33. #ifdef __cplusplus
  34. extern "C"
  35. {
  36. #if 0 /* keep Emacsens' auto-indent happy */
  37. }
  38. #endif
  39. #endif
  40. /**
  41. * Opaque handle to a host running experiments managed by the testbed framework.
  42. * The master process must be able to SSH to this host without password (via
  43. * ssh-agent).
  44. */
  45. struct GNUNET_TESTBED_Host;
  46. /**
  47. * Opaque handle to a peer controlled by the testbed framework. A peer runs
  48. * at a particular host.
  49. */
  50. struct GNUNET_TESTBED_Peer;
  51. /**
  52. * Opaque handle to an abstract operation to be executed by the testbed framework.
  53. */
  54. struct GNUNET_TESTBED_Operation;
  55. /**
  56. * Handle to interact with a GNUnet testbed controller. Each
  57. * controller has at least one master handle which is created when the
  58. * controller is created; this master handle interacts with the
  59. * controller process, destroying it destroys the controller (by
  60. * closing stdin of the controller process). Additionally,
  61. * controllers can interact with each other (in a P2P fashion); those
  62. * links are established via TCP/IP on the controller's service port.
  63. */
  64. struct GNUNET_TESTBED_Controller;
  65. /**
  66. * Create a host to run peers and controllers on.
  67. *
  68. * @param hostname name of the host, use "NULL" for localhost
  69. * @param username username to use for the login; may be NULL
  70. * @param cfg the configuration to use as a template while starting a controller
  71. * on this host. Operation queue sizes specific to a host are also
  72. * read from this configuration handle
  73. * @param port port number to use for ssh; use 0 to let ssh decide
  74. * @return handle to the host, NULL on error
  75. */
  76. struct GNUNET_TESTBED_Host *
  77. GNUNET_TESTBED_host_create (const char *hostname,
  78. const char *username,
  79. const struct GNUNET_CONFIGURATION_Handle *cfg,
  80. uint16_t port);
  81. /**
  82. * Create a host to run peers and controllers on. This function is used
  83. * if a peer learns about a host via IPC between controllers (and thus
  84. * some higher-level controller has already determined the unique IDs).
  85. *
  86. * @param id global host ID assigned to the host; 0 is
  87. * reserved to always mean 'localhost'
  88. * @param hostname name of the host, use "NULL" for localhost
  89. * @param username username to use for the login; may be NULL
  90. * @param cfg the configuration to use as a template while starting a controller
  91. * on this host. Operation queue sizes specific to a host are also
  92. * read from this configuration handle
  93. * @param port port number to use for ssh; use 0 to let ssh decide
  94. * @return handle to the host, NULL on error
  95. */
  96. struct GNUNET_TESTBED_Host *
  97. GNUNET_TESTBED_host_create_with_id (uint32_t id,
  98. const char *hostname,
  99. const char *username,
  100. const struct GNUNET_CONFIGURATION_Handle
  101. *cfg,
  102. uint16_t port);
  103. /**
  104. * Load a set of hosts from a configuration file. The hostfile format is
  105. * specified at https://gnunet.org/content/hosts-file-format
  106. *
  107. * @param filename file with the host specification
  108. * @param cfg the configuration to use as a template while starting a controller
  109. * on any of the loaded hosts. Operation queue sizes specific to a host
  110. * are also read from this configuration handle
  111. * @param hosts set to the hosts found in the file; caller must free this if
  112. * number of hosts returned is greater than 0
  113. * @return number of hosts returned in 'hosts', 0 on error
  114. */
  115. unsigned int
  116. GNUNET_TESTBED_hosts_load_from_file (const char *filename,
  117. const struct GNUNET_CONFIGURATION_Handle
  118. *cfg,
  119. struct GNUNET_TESTBED_Host ***hosts);
  120. /**
  121. * Loads the set of host allocated by the LoadLeveler Job Scheduler. This
  122. * function is only available when compiled with support for LoadLeveler and is
  123. * used for running on the SuperMUC
  124. *
  125. * @param cfg the configuration to use as a template while starting a controller
  126. * on any of the loaded hosts. Operation queue sizes specific to a host
  127. * are also read from this configuration handle
  128. * @param hosts set to the hosts found in the file; caller must free this if
  129. * number of hosts returned is greater than 0
  130. * @return number of hosts returned in 'hosts', 0 on error
  131. */
  132. unsigned int
  133. GNUNET_TESTBED_hosts_load_from_loadleveler (const struct
  134. GNUNET_CONFIGURATION_Handle *cfg,
  135. struct GNUNET_TESTBED_Host
  136. ***hosts);
  137. /**
  138. * Destroy a host handle. Must only be called once everything
  139. * running on that host has been stopped.
  140. *
  141. * @param host handle to destroy
  142. */
  143. void
  144. GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host);
  145. /**
  146. * The handle for whether a host is habitable or not
  147. */
  148. struct GNUNET_TESTBED_HostHabitableCheckHandle;
  149. /**
  150. * Callbacks of this type are called by GNUNET_TESTBED_is_host_habitable to
  151. * inform whether the given host is habitable or not. The Handle returned by
  152. * GNUNET_TESTBED_is_host_habitable() is invalid after this callback is called
  153. *
  154. * @param cls the closure given to GNUNET_TESTBED_is_host_habitable()
  155. * @param host the host whose status is being reported; will be NULL if the host
  156. * given to GNUNET_TESTBED_is_host_habitable() is NULL
  157. * @param status GNUNET_YES if it is habitable; GNUNET_NO if not
  158. */
  159. typedef void
  160. (*GNUNET_TESTBED_HostHabitableCallback) (void *cls,
  161. const struct GNUNET_TESTBED_Host *host,
  162. int status);
  163. /**
  164. * Checks whether a host can be used to start testbed service
  165. *
  166. * @param host the host to check
  167. * @param config the configuration handle to lookup the path of the testbed
  168. * helper
  169. * @param cb the callback to call to inform about habitability of the given host
  170. * @param cb_cls the closure for the callback
  171. * @return NULL upon any error or a handle which can be passed to
  172. * GNUNET_TESTBED_is_host_habitable_cancel()
  173. */
  174. struct GNUNET_TESTBED_HostHabitableCheckHandle *
  175. GNUNET_TESTBED_is_host_habitable (const struct GNUNET_TESTBED_Host *host,
  176. const struct GNUNET_CONFIGURATION_Handle
  177. *config,
  178. GNUNET_TESTBED_HostHabitableCallback cb,
  179. void *cb_cls);
  180. /**
  181. * Function to cancel a request started using GNUNET_TESTBED_is_host_habitable()
  182. *
  183. * @param handle the habitability check handle
  184. */
  185. void
  186. GNUNET_TESTBED_is_host_habitable_cancel (struct
  187. GNUNET_TESTBED_HostHabitableCheckHandle
  188. *handle);
  189. /**
  190. * Obtain the host's hostname.
  191. *
  192. * @param host handle to the host, NULL means 'localhost'
  193. * @return hostname of the host
  194. */
  195. const char *
  196. GNUNET_TESTBED_host_get_hostname (const struct GNUNET_TESTBED_Host *host);
  197. /**
  198. * Enumeration with (at most 64) possible event types that
  199. * can be monitored using the testbed framework.
  200. */
  201. enum GNUNET_TESTBED_EventType
  202. {
  203. /**
  204. * A peer has been started.
  205. */
  206. GNUNET_TESTBED_ET_PEER_START = 0,
  207. /**
  208. * A peer has been stopped.
  209. */
  210. GNUNET_TESTBED_ET_PEER_STOP = 1,
  211. /**
  212. * A connection between two peers was established.
  213. */
  214. GNUNET_TESTBED_ET_CONNECT = 2,
  215. /**
  216. * A connection between two peers was torn down.
  217. */
  218. GNUNET_TESTBED_ET_DISCONNECT = 3,
  219. /**
  220. * A requested testbed operation has been completed.
  221. */
  222. GNUNET_TESTBED_ET_OPERATION_FINISHED = 4,
  223. };
  224. /**
  225. * Types of information that can be requested about a peer.
  226. */
  227. enum GNUNET_TESTBED_PeerInformationType
  228. {
  229. /**
  230. * Special value (not valid for requesting information)
  231. * that is used in the event struct if a 'generic' pointer
  232. * is returned (for other operations not related to this
  233. * enumeration).
  234. */
  235. GNUNET_TESTBED_PIT_GENERIC = 0,
  236. /**
  237. * What configuration is the peer using? Returns a 'const struct
  238. * GNUNET_CONFIGURATION_Handle *'. Valid until
  239. * 'GNUNET_TESTNIG_operation_done' is called. However, the
  240. * values may be inaccurate if the peer is reconfigured in
  241. * the meantime.
  242. */
  243. GNUNET_TESTBED_PIT_CONFIGURATION,
  244. /**
  245. * What is the identity of the peer? Returns a
  246. * 'const struct GNUNET_PeerIdentity *'. Valid until
  247. * 'GNUNET_TESTNIG_operation_done' is called.
  248. */
  249. GNUNET_TESTBED_PIT_IDENTITY
  250. };
  251. /**
  252. * Argument to GNUNET_TESTBED_ControllerCallback with details about
  253. * the event.
  254. */
  255. struct GNUNET_TESTBED_EventInformation
  256. {
  257. /**
  258. * Type of the event.
  259. */
  260. enum GNUNET_TESTBED_EventType type;
  261. /**
  262. * Handle for the corresponding operation that generated this event
  263. */
  264. struct GNUNET_TESTBED_Operation *op;
  265. /**
  266. * Closure given while creating the above operation
  267. */
  268. void *op_cls;
  269. /**
  270. * Details about the event.
  271. */
  272. union
  273. {
  274. /**
  275. * Details about peer start event.
  276. */
  277. struct
  278. {
  279. /**
  280. * Handle for the host where the peer
  281. * was started.
  282. */
  283. struct GNUNET_TESTBED_Host *host;
  284. /**
  285. * Handle for the peer that was started.
  286. */
  287. struct GNUNET_TESTBED_Peer *peer;
  288. } peer_start;
  289. /**
  290. * Details about peer stop event.
  291. */
  292. struct
  293. {
  294. /**
  295. * Handle for the peer that was started.
  296. */
  297. struct GNUNET_TESTBED_Peer *peer;
  298. } peer_stop;
  299. /**
  300. * Details about connect event.
  301. */
  302. struct
  303. {
  304. /**
  305. * Handle for one of the connected peers.
  306. */
  307. struct GNUNET_TESTBED_Peer *peer1;
  308. /**
  309. * Handle for one of the connected peers.
  310. */
  311. struct GNUNET_TESTBED_Peer *peer2;
  312. } peer_connect;
  313. /**
  314. * Details about disconnect event.
  315. */
  316. struct
  317. {
  318. /**
  319. * Handle for one of the disconnected peers.
  320. */
  321. struct GNUNET_TESTBED_Peer *peer1;
  322. /**
  323. * Handle for one of the disconnected peers.
  324. */
  325. struct GNUNET_TESTBED_Peer *peer2;
  326. } peer_disconnect;
  327. /**
  328. * Details about an operation finished event.
  329. */
  330. struct
  331. {
  332. /**
  333. * Error message for the operation, NULL on success.
  334. */
  335. const char *emsg;
  336. /**
  337. * No result (NULL pointer) or generic result
  338. * (whatever the GNUNET_TESTBED_ConnectAdapter returned).
  339. */
  340. void *generic;
  341. } operation_finished;
  342. } details;
  343. };
  344. /**
  345. * Signature of the event handler function called by the
  346. * respective event controller.
  347. *
  348. * @param cls closure
  349. * @param event information about the event
  350. */
  351. typedef void
  352. (*GNUNET_TESTBED_ControllerCallback)(void *cls,
  353. const struct GNUNET_TESTBED_EventInformation *event);
  354. /**
  355. * Opaque Handle for Controller process
  356. */
  357. struct GNUNET_TESTBED_ControllerProc;
  358. /**
  359. * Callback to signal successfull startup of the controller process
  360. *
  361. * @param cls the closure from GNUNET_TESTBED_controller_start()
  362. * @param cfg the configuration with which the controller has been started;
  363. * NULL if status is not #GNUNET_OK
  364. * @param status #GNUNET_OK if the startup is successfull; #GNUNET_SYSERR if not,
  365. * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
  366. */
  367. typedef void
  368. (*GNUNET_TESTBED_ControllerStatusCallback) (void *cls,
  369. const struct GNUNET_CONFIGURATION_Handle *cfg,
  370. int status);
  371. /**
  372. * Starts a controller process at the given host. The given host's configuration
  373. * is used as a Template configuration to use for the remote controller; the
  374. * remote controller will be started with a slightly modified configuration
  375. * (port numbers, unix domain sockets and service home values are changed as per
  376. * TESTING library on the remote host). The modified configuration replaces the
  377. * host's existing configuration before signalling success through the
  378. * GNUNET_TESTBED_ControllerStatusCallback()
  379. *
  380. * @param trusted_ip the ip address of the controller which will be set as TRUSTED
  381. * HOST(all connections form this ip are permitted by the testbed) when
  382. * starting testbed controller at host. This can either be a single ip
  383. * address or a network address in CIDR notation.
  384. * @param host the host where the controller has to be started. CANNOT be NULL.
  385. * @param cb function called when the controller is successfully started or
  386. * dies unexpectedly; GNUNET_TESTBED_controller_stop shouldn't be
  387. * called if cb is called with GNUNET_SYSERR as status. Will never be
  388. * called in the same task as 'GNUNET_TESTBED_controller_start'
  389. * (synchronous errors will be signalled by returning NULL). This
  390. * parameter cannot be NULL.
  391. * @param cls closure for above callbacks
  392. * @return the controller process handle, NULL on errors
  393. */
  394. struct GNUNET_TESTBED_ControllerProc *
  395. GNUNET_TESTBED_controller_start (const char *trusted_ip,
  396. struct GNUNET_TESTBED_Host *host,
  397. GNUNET_TESTBED_ControllerStatusCallback cb,
  398. void *cls);
  399. /**
  400. * Stop the controller process (also will terminate all peers and controllers
  401. * dependent on this controller). This function blocks until the testbed has
  402. * been fully terminated (!). The controller status cb from
  403. * GNUNET_TESTBED_controller_start() will not be called.
  404. *
  405. * @param cproc the controller process handle
  406. */
  407. void
  408. GNUNET_TESTBED_controller_stop (struct GNUNET_TESTBED_ControllerProc *cproc);
  409. /**
  410. * Connect to a controller process. The configuration to use for the connection
  411. * is retrieved from the given host where a controller is started using
  412. * GNUNET_TESTBED_controller_start().
  413. *
  414. * @param host host to run the controller on; This should be the same host if
  415. * the controller was previously started with
  416. * GNUNET_TESTBED_controller_start()
  417. * @param event_mask bit mask with set of events to call 'cc' for;
  418. * or-ed values of "1LL" shifted by the
  419. * respective 'enum GNUNET_TESTBED_EventType'
  420. * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) | ...")
  421. * @param cc controller callback to invoke on events
  422. * @param cc_cls closure for cc
  423. * @return handle to the controller
  424. */
  425. struct GNUNET_TESTBED_Controller *
  426. GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host,
  427. uint64_t event_mask,
  428. GNUNET_TESTBED_ControllerCallback cc,
  429. void *cc_cls);
  430. /**
  431. * Stop the given controller (also will terminate all peers and
  432. * controllers dependent on this controller). This function
  433. * blocks until the testbed has been fully terminated (!).
  434. *
  435. * @param c handle to controller to stop
  436. */
  437. void
  438. GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *c);
  439. /**
  440. * Opaque handle for host registration
  441. */
  442. struct GNUNET_TESTBED_HostRegistrationHandle;
  443. /**
  444. * Callback which will be called to after a host registration succeeded or failed
  445. *
  446. * @param cls the closure
  447. * @param emsg the error message; NULL if host registration is successful
  448. */
  449. typedef void
  450. (* GNUNET_TESTBED_HostRegistrationCompletion) (void *cls,
  451. const char *emsg);
  452. /**
  453. * Register a host with the controller. This makes the controller aware of the
  454. * host. A host should be registered at the controller before starting a
  455. * sub-controller on that host using GNUNET_TESTBED_controller_link().
  456. *
  457. * @param controller the controller handle
  458. * @param host the host to register
  459. * @param cc the completion callback to call to inform the status of
  460. * registration. After calling this callback the registration handle
  461. * will be invalid. Cannot be NULL
  462. * @param cc_cls the closure for the cc
  463. * @return handle to the host registration which can be used to cancel the
  464. * registration; NULL if another registration handle is present and
  465. * is not cancelled
  466. */
  467. struct GNUNET_TESTBED_HostRegistrationHandle *
  468. GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller,
  469. struct GNUNET_TESTBED_Host *host,
  470. GNUNET_TESTBED_HostRegistrationCompletion cc,
  471. void *cc_cls);
  472. /**
  473. * Cancel the pending registration. Note that the registration message will
  474. * already be queued to be sent to the service, cancellation has only the
  475. * effect that the registration completion callback for the registration is
  476. * never called and from our perspective the host is not registered until the
  477. * completion callback is called.
  478. *
  479. * @param handle the registration handle to cancel
  480. */
  481. void
  482. GNUNET_TESTBED_cancel_registration (struct GNUNET_TESTBED_HostRegistrationHandle
  483. *handle);
  484. /**
  485. * Callback to be called when an operation is completed
  486. *
  487. * @param cls the callback closure from functions generating an operation
  488. * @param op the operation that has been finished
  489. * @param emsg error message in case the operation has failed; will be NULL if
  490. * operation has executed successfully.
  491. */
  492. typedef void
  493. (*GNUNET_TESTBED_OperationCompletionCallback) (void *cls,
  494. struct GNUNET_TESTBED_Operation *op,
  495. const char *emsg);
  496. /**
  497. * Create a link from slave controller to delegated controller. Whenever the
  498. * master controller is asked to start a peer at the delegated controller the
  499. * request will be routed towards slave controller (if a route exists). The
  500. * slave controller will then route it to the delegated controller. The
  501. * configuration of the delegated controller is given and is used to either
  502. * create the delegated controller or to connect to an existing controller. Note
  503. * that while starting the delegated controller the configuration will be
  504. * modified to accommodate available free ports. the 'is_subordinate' specifies
  505. * if the given delegated controller should be started and managed by the slave
  506. * controller, or if the delegated controller already has a master and the slave
  507. * controller connects to it as a non master controller. The success or failure
  508. * of this operation will be signalled through the
  509. * GNUNET_TESTBED_ControllerCallback() with an event of type
  510. * #GNUNET_TESTBED_ET_OPERATION_FINISHED
  511. *
  512. * @param op_cls the operation closure for the event which is generated to
  513. * signal success or failure of this operation
  514. * @param master handle to the master controller who creates the association
  515. * @param delegated_host requests to which host should be delegated; cannot be NULL
  516. * @param slave_host which host is used to run the slave controller; use NULL to
  517. * make the master controller connect to the delegated host
  518. * @param is_subordinate #GNUNET_YES if the controller at delegated_host should
  519. * be started by the slave controller; #GNUNET_NO if the slave
  520. * controller has to connect to the already started delegated
  521. * controller via TCP/IP
  522. * @return the operation handle
  523. */
  524. struct GNUNET_TESTBED_Operation *
  525. GNUNET_TESTBED_controller_link (void *op_cls,
  526. struct GNUNET_TESTBED_Controller *master,
  527. struct GNUNET_TESTBED_Host *delegated_host,
  528. struct GNUNET_TESTBED_Host *slave_host,
  529. int is_subordinate);
  530. /**
  531. * Function to acquire the configuration of a running slave controller. The
  532. * completion of the operation is signalled through the controller_cb from
  533. * GNUNET_TESTBED_controller_connect(). If the operation is successful the
  534. * handle to the configuration is available in the generic pointer of
  535. * operation_finished field of `struct GNUNET_TESTBED_EventInformation`.
  536. *
  537. * @param op_cls the closure for the operation
  538. * @param master the handle to master controller
  539. * @param slave_host the host where the slave controller is running; the handle
  540. * to the slave_host should remain valid until this operation is
  541. * cancelled or marked as finished
  542. * @return the operation handle; NULL if the slave_host is not registered at
  543. * master
  544. */
  545. struct GNUNET_TESTBED_Operation *
  546. GNUNET_TESTBED_get_slave_config (void *op_cls,
  547. struct GNUNET_TESTBED_Controller *master,
  548. struct GNUNET_TESTBED_Host *slave_host);
  549. /**
  550. * Functions of this signature are called when a peer has been successfully
  551. * created
  552. *
  553. * @param cls the closure from GNUNET_TESTBED_peer_create()
  554. * @param peer the handle for the created peer; NULL on any error during
  555. * creation
  556. * @param emsg NULL if peer is not NULL; else MAY contain the error description
  557. */
  558. typedef void
  559. (*GNUNET_TESTBED_PeerCreateCallback) (void *cls,
  560. struct GNUNET_TESTBED_Peer *peer,
  561. const char *emsg);
  562. /**
  563. * Create the given peer at the specified host using the given
  564. * controller. If the given controller is not running on the target
  565. * host, it should find or create a controller at the target host and
  566. * delegate creating the peer. Explicit delegation paths can be setup
  567. * using 'GNUNET_TESTBED_controller_link'. If no explicit delegation
  568. * path exists, a direct link with a subordinate controller is setup
  569. * for the first delegated peer to a particular host; the subordinate
  570. * controller is then destroyed once the last peer that was delegated
  571. * to the remote host is stopped.
  572. *
  573. * Creating the peer only creates the handle to manipulate and further
  574. * configure the peer; use #GNUNET_TESTBED_peer_start and
  575. * #GNUNET_TESTBED_peer_stop to actually start/stop the peer's
  576. * processes.
  577. *
  578. * Note that the given configuration will be adjusted by the
  579. * controller to avoid port/path conflicts with other peers.
  580. * The "final" configuration can be obtained using
  581. * #GNUNET_TESTBED_peer_get_information.
  582. *
  583. * @param controller controller process to use
  584. * @param host host to run the peer on; cannot be NULL
  585. * @param cfg Template configuration to use for the peer. Should exist until
  586. * operation is cancelled or GNUNET_TESTBED_operation_done() is called
  587. * @param cb the callback to call when the peer has been created
  588. * @param cls the closure to the above callback
  589. * @return the operation handle
  590. */
  591. struct GNUNET_TESTBED_Operation *
  592. GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller,
  593. struct GNUNET_TESTBED_Host *host,
  594. const struct GNUNET_CONFIGURATION_Handle *cfg,
  595. GNUNET_TESTBED_PeerCreateCallback cb,
  596. void *cls);
  597. /**
  598. * Functions of this signature are called when a peer has been successfully
  599. * started or stopped.
  600. *
  601. * @param cls the closure from GNUNET_TESTBED_peer_start/stop()
  602. * @param emsg NULL on success; otherwise an error description
  603. */
  604. typedef void
  605. (*GNUNET_TESTBED_PeerChurnCallback) (void *cls,
  606. const char *emsg);
  607. /**
  608. * Start the given peer.
  609. *
  610. * @param op_cls the closure for this operation; will be set in the event
  611. * information
  612. * @param peer peer to start
  613. * @param pcc function to call upon completion
  614. * @param pcc_cls closure for 'pcc'
  615. * @return handle to the operation
  616. */
  617. struct GNUNET_TESTBED_Operation *
  618. GNUNET_TESTBED_peer_start (void *op_cls,
  619. struct GNUNET_TESTBED_Peer *peer,
  620. GNUNET_TESTBED_PeerChurnCallback pcc,
  621. void *pcc_cls);
  622. /**
  623. * Stop the given peer. The handle remains valid (use
  624. * #GNUNET_TESTBED_peer_destroy to fully clean up the
  625. * state of the peer).
  626. *
  627. * @param op_cls the closure for this operation; will be set in the event
  628. * information
  629. * @param peer peer to stop
  630. * @param pcc function to call upon completion
  631. * @param pcc_cls closure for 'pcc'
  632. * @return handle to the operation
  633. */
  634. struct GNUNET_TESTBED_Operation *
  635. GNUNET_TESTBED_peer_stop (void *op_cls,
  636. struct GNUNET_TESTBED_Peer *peer,
  637. GNUNET_TESTBED_PeerChurnCallback pcc,
  638. void *pcc_cls);
  639. /**
  640. * Data returned from GNUNET_TESTBED_peer_get_information
  641. */
  642. struct GNUNET_TESTBED_PeerInformation
  643. {
  644. /**
  645. * Peer information type; captures which of the types
  646. * in the 'op_result' is actually in use.
  647. */
  648. enum GNUNET_TESTBED_PeerInformationType pit;
  649. /**
  650. * The result of the get information operation; Choose according to the pit
  651. */
  652. union
  653. {
  654. /**
  655. * The configuration of the peer
  656. */
  657. struct GNUNET_CONFIGURATION_Handle *cfg;
  658. /**
  659. * The identity of the peer
  660. */
  661. struct GNUNET_PeerIdentity *id;
  662. } result;
  663. };
  664. /**
  665. * Callback to be called when the requested peer information is available
  666. * The peer information in the callback is valid until the operation 'op' is canceled.
  667. *
  668. * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information()
  669. * @param op the operation this callback corresponds to
  670. * @param pinfo the result; will be NULL if the operation has failed
  671. * @param emsg error message if the operation has failed; will be NULL if the
  672. * operation is successfull
  673. */
  674. typedef void
  675. (*GNUNET_TESTBED_PeerInfoCallback) (void *cb_cls,
  676. struct GNUNET_TESTBED_Operation *op,
  677. const struct GNUNET_TESTBED_PeerInformation *pinfo,
  678. const char *emsg);
  679. /**
  680. * Request information about a peer. The controller callback will not be called
  681. * with event type #GNUNET_TESTBED_ET_OPERATION_FINISHED when result for this
  682. * operation is available. Instead, the GNUNET_TESTBED_PeerInfoCallback() will
  683. * be called.
  684. * The peer information in the callback is valid until the operation is canceled.
  685. *
  686. * @param peer peer to request information about
  687. * @param pit desired information
  688. * @param cb the convenience callback to be called when results for this
  689. * operation are available
  690. * @param cb_cls the closure for @a cb
  691. * @return handle to the operation
  692. */
  693. struct GNUNET_TESTBED_Operation *
  694. GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer,
  695. enum GNUNET_TESTBED_PeerInformationType
  696. pit,
  697. GNUNET_TESTBED_PeerInfoCallback cb,
  698. void *cb_cls);
  699. /**
  700. * Change @a peer configuration. Ports and paths cannot be changed this
  701. * way.
  702. *
  703. * @param peer peer to change configuration for
  704. * @param cfg new configuration
  705. * @return handle to the operation
  706. */
  707. struct GNUNET_TESTBED_Operation *
  708. GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer,
  709. const struct GNUNET_CONFIGURATION_Handle *cfg);
  710. /**
  711. * Destroy the given peer; the peer should have been
  712. * stopped first (if it was started).
  713. *
  714. * @param peer peer to stop
  715. * @return handle to the operation
  716. */
  717. struct GNUNET_TESTBED_Operation *
  718. GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer);
  719. /**
  720. * Start or stop given service at a peer. This should not be called to
  721. * start/stop the peer's ARM service. Use GNUNET_TESTBED_peer_start(),
  722. * GNUNET_TESTBED_peer_stop() for starting/stopping peer's ARM service. Success
  723. * or failure of the generated operation is signalled through the controller
  724. * event callback and/or operation completion callback.
  725. *
  726. * @param op_cls the closure for the operation
  727. * @param peer the peer whose service is to be started/stopped
  728. * @param service_name the name of the service
  729. * @param cb the operation completion callback
  730. * @param cb_cls the closure for @a cb
  731. * @param start 1 to start the service; 0 to stop the service
  732. * @return an operation handle; NULL upon error (peer not running)
  733. */
  734. struct GNUNET_TESTBED_Operation *
  735. GNUNET_TESTBED_peer_manage_service (void *op_cls,
  736. struct GNUNET_TESTBED_Peer *peer,
  737. const char *service_name,
  738. GNUNET_TESTBED_OperationCompletionCallback cb,
  739. void *cb_cls,
  740. unsigned int start);
  741. /**
  742. * Stops and destroys all peers. Is equivalent of calling
  743. * GNUNET_TESTBED_peer_stop() and GNUNET_TESTBED_peer_destroy() on all peers,
  744. * except that the peer stop event and operation finished event corresponding to
  745. * the respective functions are not generated. This function should be called
  746. * when there are no other pending operations. If there are pending operations,
  747. * it will return NULL
  748. *
  749. * @param c the controller to send this message to
  750. * @param op_cls closure for the operation
  751. * @param cb the callback to call when all peers are stopped and destroyed
  752. * @param cb_cls the closure for the callback
  753. * @return operation handle on success; NULL if any pending operations are
  754. * present
  755. */
  756. struct GNUNET_TESTBED_Operation *
  757. GNUNET_TESTBED_shutdown_peers (struct GNUNET_TESTBED_Controller *c,
  758. void *op_cls,
  759. GNUNET_TESTBED_OperationCompletionCallback cb,
  760. void *cb_cls);
  761. /**
  762. * Options for peer connections.
  763. */
  764. enum GNUNET_TESTBED_ConnectOption
  765. {
  766. /**
  767. * No option (not valid as an argument).
  768. */
  769. GNUNET_TESTBED_CO_NONE = 0,
  770. /**
  771. * Allow or disallow a connection between the specified peers.
  772. * Followed by #GNUNET_NO (int) if a connection is disallowed
  773. * or #GNUNET_YES if a connection is allowed. Note that the
  774. * default (all connections allowed or disallowed) is
  775. * specified in the configuration of the controller.
  776. */
  777. GNUNET_TESTBED_CO_ALLOW = 1,
  778. /**
  779. * FIXME: add (and implement) options to limit connection to
  780. * particular transports, force simulation of particular latencies
  781. * or message loss rates, or set bandwidth limitations.
  782. */
  783. };
  784. /**
  785. * Manipulate the P2P underlay topology by configuring a link
  786. * between two peers.
  787. *
  788. * @param op_cls closure argument to give with the operation event
  789. * @param p1 first peer
  790. * @param p2 second peer
  791. * @param co option to change
  792. * @param ap option-specific values
  793. * @return handle to the operation, NULL if configuring the link at this
  794. * time is not allowed
  795. */
  796. struct GNUNET_TESTBED_Operation *
  797. GNUNET_TESTBED_underlay_configure_link_va (void *op_cls,
  798. struct GNUNET_TESTBED_Peer *p1,
  799. struct GNUNET_TESTBED_Peer *p2,
  800. enum GNUNET_TESTBED_ConnectOption co,
  801. va_list ap);
  802. /**
  803. * Manipulate the P2P underlay topology by configuring a link
  804. * between two peers.
  805. *
  806. * @param op_cls closure argument to give with the operation event
  807. * @param p1 first peer
  808. * @param p2 second peer
  809. * @param co option to change
  810. * @param ... option-specific values
  811. * @return handle to the operation, NULL if configuring the link at this
  812. * time is not allowed
  813. */
  814. struct GNUNET_TESTBED_Operation *
  815. GNUNET_TESTBED_underlay_configure_link (void *op_cls,
  816. struct GNUNET_TESTBED_Peer *p1,
  817. struct GNUNET_TESTBED_Peer *p2,
  818. enum GNUNET_TESTBED_ConnectOption co, ...);
  819. /**
  820. * Topologies and topology options supported for testbeds. Options should always
  821. * end with #GNUNET_TESTBED_TOPOLOGY_OPTION_END
  822. */
  823. enum GNUNET_TESTBED_TopologyOption
  824. {
  825. /**
  826. * A clique (everyone connected to everyone else). No options. If there are N
  827. * peers this topology results in (N * (N -1)) connections.
  828. */
  829. GNUNET_TESTBED_TOPOLOGY_CLIQUE,
  830. /**
  831. * Small-world network (2d torus plus random links). Followed
  832. * by the number of random links to add (unsigned int).
  833. */
  834. GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD,
  835. /**
  836. * Small-world network (ring plus random links). Followed
  837. * by the number of random links to add (unsigned int).
  838. */
  839. GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING,
  840. /**
  841. * Ring topology. No options.
  842. */
  843. GNUNET_TESTBED_TOPOLOGY_RING,
  844. /**
  845. * Star topology. No options.
  846. */
  847. GNUNET_TESTBED_TOPOLOGY_STAR,
  848. /**
  849. * 2-d torus. No options.
  850. */
  851. GNUNET_TESTBED_TOPOLOGY_2D_TORUS,
  852. /**
  853. * Random graph. Followed by the number of random links to be established
  854. * (unsigned int)
  855. */
  856. GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI,
  857. /**
  858. * Certain percentage of peers are unable to communicate directly
  859. * replicating NAT conditions. Followed by the fraction of
  860. * NAT'ed peers (float).
  861. */
  862. GNUNET_TESTBED_TOPOLOGY_INTERNAT,
  863. /**
  864. * Scale free topology. It is generated according to the method described in
  865. * "Emergence of Scaling in Random Networks." Science 286, 509-512, 1999.
  866. *
  867. * This options takes two arguments in the following order: an uint16_t to
  868. * determine the maximum number of edges a peer is permitted to have while
  869. * generating scale free topology, a good value for this argument is 70; and
  870. * an uint8_t to determine the number of edges to be established when adding a
  871. * new node to the scale free network, a good value for this argument is 4.
  872. */
  873. GNUNET_TESTBED_TOPOLOGY_SCALE_FREE,
  874. /**
  875. * Straight line topology. No options.
  876. */
  877. GNUNET_TESTBED_TOPOLOGY_LINE,
  878. /**
  879. * Read a topology from a given file. Followed by the name of the file (const char *).
  880. */
  881. GNUNET_TESTBED_TOPOLOGY_FROM_FILE,
  882. /**
  883. * All peers are disconnected. No options.
  884. */
  885. GNUNET_TESTBED_TOPOLOGY_NONE,
  886. /**
  887. * The options should always end with this
  888. */
  889. GNUNET_TESTBED_TOPOLOGY_OPTION_END,
  890. /* The following are not topologies but influence how the topology has to be
  891. setup. These options should follow the topology specific options (if
  892. required by the chosen topology). Note that these should be given before
  893. GNUNET_TESTBED_TOPOLOGY_OPTION_END */
  894. /**
  895. * How many times should the failed overlay connect operations be retried
  896. * before giving up. The default if this option is not specified is to retry
  897. * 3 times. This option takes and unsigned integer as a parameter. Use this
  898. * option with parameter 0 to disable retrying of failed overlay connect
  899. * operations.
  900. */
  901. GNUNET_TESTBED_TOPOLOGY_RETRY_CNT
  902. };
  903. /**
  904. * Configure overall network topology to have a particular shape.
  905. *
  906. * @param op_cls closure argument to give with the operation event
  907. * @param num_peers number of peers in 'peers'
  908. * @param peers array of 'num_peers' with the peers to configure
  909. * @param topo desired underlay topology to use
  910. * @param ap topology-specific options
  911. * @return handle to the operation, NULL if configuring the topology
  912. * is not allowed at this time
  913. */
  914. struct GNUNET_TESTBED_Operation *
  915. GNUNET_TESTBED_underlay_configure_topology_va (void *op_cls,
  916. unsigned int num_peers,
  917. struct GNUNET_TESTBED_Peer **peers,
  918. enum GNUNET_TESTBED_TopologyOption topo,
  919. va_list ap);
  920. /**
  921. * Configure overall network topology to have a particular shape.
  922. *
  923. * @param op_cls closure argument to give with the operation event
  924. * @param num_peers number of peers in 'peers'
  925. * @param peers array of 'num_peers' with the peers to configure
  926. * @param topo desired underlay topology to use
  927. * @param ... topology-specific options
  928. * @return handle to the operation, NULL if configuring the topology
  929. * is not allowed at this time
  930. */
  931. struct GNUNET_TESTBED_Operation *
  932. GNUNET_TESTBED_underlay_configure_topology (void *op_cls,
  933. unsigned int num_peers,
  934. struct GNUNET_TESTBED_Peer **peers,
  935. enum GNUNET_TESTBED_TopologyOption topo,
  936. ...);
  937. /**
  938. * Both peers must have been started before calling this function.
  939. * This function then obtains a HELLO from @a p1, gives it to @a p2
  940. * and asks @a p2 to connect to @a p1.
  941. *
  942. * @param op_cls closure argument to give with the operation event
  943. * @param cb the callback to call when this operation has finished
  944. * @param cb_cls the closure for @a cb
  945. * @param p1 first peer
  946. * @param p2 second peer
  947. * @return handle to the operation, NULL if connecting these two
  948. * peers is fundamentally not possible at this time (peers
  949. * not running or underlay disallows)
  950. */
  951. struct GNUNET_TESTBED_Operation *
  952. GNUNET_TESTBED_overlay_connect (void *op_cls,
  953. GNUNET_TESTBED_OperationCompletionCallback cb,
  954. void *cb_cls,
  955. struct GNUNET_TESTBED_Peer *p1,
  956. struct GNUNET_TESTBED_Peer *p2);
  957. /**
  958. * Callbacks of this type are called when topology configuration is completed
  959. *
  960. * @param cls the operation closure given to
  961. * GNUNET_TESTBED_overlay_configure_topology_va() and
  962. * GNUNET_TESTBED_overlay_configure() calls
  963. * @param nsuccess the number of successful overlay connects
  964. * @param nfailures the number of overlay connects which failed
  965. */
  966. typedef void (*GNUNET_TESTBED_TopologyCompletionCallback) (void *cls,
  967. unsigned int nsuccess,
  968. unsigned int nfailures);
  969. /**
  970. * All peers must have been started before calling this function.
  971. * This function then connects the given peers in the P2P overlay
  972. * using the given topology.
  973. *
  974. * @param op_cls closure argument to give with the peer connect operation events
  975. * generated through this function
  976. * @param num_peers number of peers in 'peers'
  977. * @param peers array of 'num_peers' with the peers to configure
  978. * @param max_connections the maximums number of overlay connections that will
  979. * be made to achieve the given topology
  980. * @param comp_cb the completion callback to call when the topology generation
  981. * is completed
  982. * @param comp_cb_cls closure for the @a comp_cb
  983. * @param topo desired underlay topology to use
  984. * @param va topology-specific options
  985. * @return handle to the operation, NULL if connecting these
  986. * peers is fundamentally not possible at this time (peers
  987. * not running or underlay disallows) or if num_peers is less than 2
  988. */
  989. struct GNUNET_TESTBED_Operation *
  990. GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
  991. unsigned int num_peers,
  992. struct GNUNET_TESTBED_Peer **peers,
  993. unsigned int *max_connections,
  994. GNUNET_TESTBED_TopologyCompletionCallback
  995. comp_cb,
  996. void *comp_cb_cls,
  997. enum GNUNET_TESTBED_TopologyOption topo,
  998. va_list va);
  999. /**
  1000. * All peers must have been started before calling this function.
  1001. * This function then connects the given peers in the P2P overlay
  1002. * using the given topology.
  1003. *
  1004. * @param op_cls closure argument to give with the peer connect operation events
  1005. * generated through this function
  1006. * @param num_peers number of peers in 'peers'
  1007. * @param peers array of 'num_peers' with the peers to configure
  1008. * @param max_connections the maximums number of overlay connections that will
  1009. * be made to achieve the given topology
  1010. * @param comp_cb the completion callback to call when the topology generation
  1011. * is completed
  1012. * @param comp_cb_cls closure for the above completion callback
  1013. * @param topo desired underlay topology to use
  1014. * @param ... topology-specific options
  1015. * @return handle to the operation, NULL if connecting these
  1016. * peers is fundamentally not possible at this time (peers
  1017. * not running or underlay disallows) or if num_peers is less than 2
  1018. */
  1019. struct GNUNET_TESTBED_Operation *
  1020. GNUNET_TESTBED_overlay_configure_topology (void *op_cls,
  1021. unsigned int num_peers,
  1022. struct GNUNET_TESTBED_Peer **peers,
  1023. unsigned int *max_connections,
  1024. GNUNET_TESTBED_TopologyCompletionCallback
  1025. comp_cb,
  1026. void *comp_cb_cls,
  1027. enum GNUNET_TESTBED_TopologyOption topo,
  1028. ...);
  1029. /**
  1030. * Ask the testbed controller to write the current overlay topology to
  1031. * a file. Naturally, the file will only contain a snapshot as the
  1032. * topology may evolve all the time.
  1033. * FIXME: needs continuation!?
  1034. *
  1035. * @param controller overlay controller to inspect
  1036. * @param filename name of the file the topology should
  1037. * be written to.
  1038. */
  1039. void
  1040. GNUNET_TESTBED_overlay_write_topology_to_file (struct GNUNET_TESTBED_Controller *controller,
  1041. const char *filename);
  1042. /**
  1043. * Adapter function called to establish a connection to
  1044. * a service.
  1045. *
  1046. * @param cls closure
  1047. * @param cfg configuration of the peer to connect to; will be available until
  1048. * GNUNET_TESTBED_operation_done() is called on the operation returned
  1049. * from GNUNET_TESTBED_service_connect()
  1050. * @return service handle to return in 'op_result', NULL on error
  1051. */
  1052. typedef void *
  1053. (*GNUNET_TESTBED_ConnectAdapter)(void *cls,
  1054. const struct GNUNET_CONFIGURATION_Handle *cfg);
  1055. /**
  1056. * Adapter function called to destroy a connection to
  1057. * a service.
  1058. *
  1059. * @param cls closure
  1060. * @param op_result service handle returned from the connect adapter
  1061. */
  1062. typedef void
  1063. (*GNUNET_TESTBED_DisconnectAdapter)(void *cls,
  1064. void *op_result);
  1065. /**
  1066. * Callback to be called when a service connect operation is completed
  1067. *
  1068. * @param cls the callback closure from functions generating an operation
  1069. * @param op the operation that has been finished
  1070. * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter()
  1071. * @param emsg error message in case the operation has failed; will be NULL if
  1072. * operation has executed successfully.
  1073. */
  1074. typedef void
  1075. (*GNUNET_TESTBED_ServiceConnectCompletionCallback) (void *cls,
  1076. struct GNUNET_TESTBED_Operation *op,
  1077. void *ca_result,
  1078. const char *emsg );
  1079. /**
  1080. * Connect to a service offered by the given peer. Will ensure that
  1081. * the request is queued to not overwhelm our ability to create and
  1082. * maintain connections with other systems. The actual service
  1083. * handle is then returned via the 'op_result' member in the event
  1084. * callback. The @a ca callback is used to create the connection
  1085. * when the time is right; the @a da callback will be used to
  1086. * destroy the connection (upon #GNUNET_TESTBED_operation_done).
  1087. * #GNUNET_TESTBED_operation_done can be used to abort this
  1088. * operation until the event callback has been called.
  1089. *
  1090. * @param op_cls closure to pass in operation event // FIXME: didn't we say we'd no longer use the global callback for these? -CG
  1091. * @param peer peer that runs the service
  1092. * @param service_name name of the service to connect to
  1093. * @param cb the callback to call when this operation is ready (that is,
  1094. * right after the connect adapter returns)
  1095. * @param cb_cls closure for @a cb
  1096. * @param ca helper function to establish the connection
  1097. * @param da helper function to close the connection
  1098. * @param cada_cls closure for @a ca and @a da
  1099. * @return handle for the operation
  1100. */
  1101. struct GNUNET_TESTBED_Operation *
  1102. GNUNET_TESTBED_service_connect (void *op_cls,
  1103. struct GNUNET_TESTBED_Peer *peer,
  1104. const char *service_name,
  1105. GNUNET_TESTBED_ServiceConnectCompletionCallback cb,
  1106. void *cb_cls,
  1107. GNUNET_TESTBED_ConnectAdapter ca,
  1108. GNUNET_TESTBED_DisconnectAdapter da,
  1109. void *cada_cls);
  1110. /**
  1111. * This function is used to signal that the event information (struct
  1112. * GNUNET_TESTBED_EventInformation) from an operation has been fully processed
  1113. * i.e. if the event callback is ever called for this operation. If the event
  1114. * callback for this operation has not yet been called, calling this function
  1115. * cancels the operation, frees its resources and ensures the no event is
  1116. * generated with respect to this operation. Note that however cancelling an
  1117. * operation does NOT guarantee that the operation will be fully undone (or that
  1118. * nothing ever happened).
  1119. *
  1120. * This function MUST be called for every operation to fully remove the
  1121. * operation from the operation queue. After calling this function, if
  1122. * operation is completed and its event information is of type
  1123. * GNUNET_TESTBED_ET_OPERATION_FINISHED, the 'op_result' becomes invalid (!).
  1124. * If the operation is generated from GNUNET_TESTBED_service_connect() then
  1125. * calling this function on such as operation calls the disconnect adapter if
  1126. * the connect adapter was ever called.
  1127. *
  1128. * @param operation operation to signal completion or cancellation
  1129. */
  1130. void
  1131. GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation);
  1132. /**
  1133. * Callback function to process statistic values from all peers.
  1134. *
  1135. * @param cls closure
  1136. * @param peer the peer the statistic belong to
  1137. * @param subsystem name of subsystem that created the statistic
  1138. * @param name the name of the datum
  1139. * @param value the current value
  1140. * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
  1141. * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
  1142. */
  1143. typedef int
  1144. (*GNUNET_TESTBED_StatisticsIterator) (void *cls,
  1145. const struct GNUNET_TESTBED_Peer *peer,
  1146. const char *subsystem,
  1147. const char *name,
  1148. uint64_t value,
  1149. int is_persistent);
  1150. /**
  1151. * Convenience method that iterates over all (running) peers
  1152. * and retrieves all statistics from each peer.
  1153. *
  1154. * @param num_peers number of peers to iterate over
  1155. * @param peers array of peers to iterate over
  1156. * @param subsystem limit to the specified subsystem, NULL for all subsystems
  1157. * @param name name of the statistic value, NULL for all values
  1158. * @param proc processing function for each statistic retrieved
  1159. * @param cont continuation to call once call is completed. The completion of this
  1160. * operation is *ONLY* signalled through this callback -- no
  1161. * GNUNET_TESTBED_ET_OPERATION_FINISHED is generated
  1162. * @param cls closure to pass to proc and cont
  1163. * @return operation handle to cancel the operation
  1164. */
  1165. struct GNUNET_TESTBED_Operation *
  1166. GNUNET_TESTBED_get_statistics (unsigned int num_peers,
  1167. struct GNUNET_TESTBED_Peer **peers,
  1168. const char *subsystem, const char *name,
  1169. GNUNET_TESTBED_StatisticsIterator proc,
  1170. GNUNET_TESTBED_OperationCompletionCallback cont,
  1171. void *cls);
  1172. /**
  1173. * Return the index of the peer inside of the total peer array,
  1174. * aka. the peer's "unique ID".
  1175. *
  1176. * @param peer Peer handle.
  1177. *
  1178. * @return The peer's unique ID.
  1179. */
  1180. uint32_t
  1181. GNUNET_TESTBED_get_index (const struct GNUNET_TESTBED_Peer *peer);
  1182. /**
  1183. * Handle for testbed run helper funtions
  1184. */
  1185. struct GNUNET_TESTBED_RunHandle;
  1186. /**
  1187. * Signature of a main function for a testcase.
  1188. *
  1189. * @param cls closure
  1190. * @param h the run handle
  1191. * @param num_peers number of peers in 'peers'
  1192. * @param peers handle to peers run in the testbed. NULL upon timeout (see
  1193. * GNUNET_TESTBED_test_run()).
  1194. * @param links_succeeded the number of overlay link connection attempts that
  1195. * succeeded
  1196. * @param links_failed the number of overlay link connection attempts that
  1197. * failed
  1198. * @see GNUNET_TESTBED_test_run()
  1199. */
  1200. typedef void
  1201. (*GNUNET_TESTBED_TestMaster)(void *cls,
  1202. struct GNUNET_TESTBED_RunHandle *h,
  1203. unsigned int num_peers,
  1204. struct GNUNET_TESTBED_Peer **peers,
  1205. unsigned int links_succeeded,
  1206. unsigned int links_failed);
  1207. /**
  1208. * Convenience method for running a testbed with
  1209. * a single call. Underlay and overlay topology
  1210. * are configured using the "UNDERLAY" and "OVERLAY"
  1211. * options in the "[testbed]" section of the configuration\
  1212. * (with possible options given in "UNDERLAY_XXX" and/or
  1213. * "OVERLAY_XXX").
  1214. *
  1215. * The test_master callback will be called once the testbed setup is finished or
  1216. * upon a timeout. This timeout is given through the configuration file by
  1217. * setting the option "SETUP_TIMEOUT" in "[TESTBED]" section.
  1218. *
  1219. * The testbed is to be terminated using a call to
  1220. * "GNUNET_SCHEDULER_shutdown".
  1221. *
  1222. * @param host_filename name of the file with the 'hosts', NULL
  1223. * to run everything on 'localhost'
  1224. * @param cfg configuration to use (for testbed, controller and peers)
  1225. * @param num_peers number of peers to start; FIXME: maybe put that ALSO into
  1226. * cfg?; should be greater than 0
  1227. * @param event_mask bit mask with set of events to call 'cc' for;
  1228. * or-ed values of "1LL" shifted by the
  1229. * respective 'enum GNUNET_TESTBED_EventType'
  1230. * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...")
  1231. * @param cc controller callback to invoke on events; This callback is called
  1232. * for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't
  1233. * set in the event_mask as this is the only way get access to the
  1234. * handle of each peer
  1235. * @param cc_cls closure for cc
  1236. * @param test_master this callback will be called once the test is ready or
  1237. * upon timeout
  1238. * @param test_master_cls closure for 'test_master'.
  1239. */
  1240. void
  1241. GNUNET_TESTBED_run (const char *host_filename,
  1242. const struct GNUNET_CONFIGURATION_Handle *cfg,
  1243. unsigned int num_peers,
  1244. uint64_t event_mask,
  1245. GNUNET_TESTBED_ControllerCallback cc,
  1246. void *cc_cls,
  1247. GNUNET_TESTBED_TestMaster test_master,
  1248. void *test_master_cls);
  1249. /**
  1250. * Convenience method for running a "simple" test on the local system
  1251. * with a single call from 'main'. Underlay and overlay topology are
  1252. * configured using the "UNDERLAY" and "OVERLAY" options in the
  1253. * "[TESTBED]" section of the configuration (with possible options
  1254. * given in "UNDERLAY_XXX" and/or "OVERLAY_XXX").
  1255. *
  1256. * The test_master callback will be called once the testbed setup is finished or
  1257. * upon a timeout. This timeout is given through the configuration file by
  1258. * setting the option "SETUP_TIMEOUT" in "[TESTBED]" section.
  1259. *
  1260. * The test is to be terminated using a call to
  1261. * "GNUNET_SCHEDULER_shutdown". If starting the test fails,
  1262. * the program is stopped without 'master' ever being run.
  1263. *
  1264. * NOTE: this function should be called from 'main', NOT from
  1265. * within a GNUNET_SCHEDULER-loop. This function will initialze
  1266. * the scheduler loop, the testbed and then pass control to
  1267. * 'master'.
  1268. *
  1269. * @param testname name of the testcase (to configure logging, etc.)
  1270. * @param cfg_filename configuration filename to use
  1271. * (for testbed, controller and peers)
  1272. * @param num_peers number of peers to start; should be greter than 0
  1273. * @param event_mask bit mask with set of events to call 'cc' for;
  1274. * or-ed values of "1LL" shifted by the
  1275. * respective 'enum GNUNET_TESTBED_EventType'
  1276. * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...")
  1277. * @param cc controller callback to invoke on events; This callback is called
  1278. * for all peer start events even if #GNUNET_TESTBED_ET_PEER_START isn't
  1279. * set in the event_mask as this is the only way get access to the
  1280. * handle of each peer
  1281. * @param cc_cls closure for @a cc
  1282. * @param test_master this callback will be called once the test is ready or
  1283. * upon timeout
  1284. * @param test_master_cls closure for @a test_master.
  1285. * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
  1286. */
  1287. int
  1288. GNUNET_TESTBED_test_run (const char *testname,
  1289. const char *cfg_filename,
  1290. unsigned int num_peers,
  1291. uint64_t event_mask,
  1292. GNUNET_TESTBED_ControllerCallback cc,
  1293. void *cc_cls,
  1294. GNUNET_TESTBED_TestMaster test_master,
  1295. void *test_master_cls);
  1296. /**
  1297. * Obtain handle to the master controller from a testbed run. The handle
  1298. * returned should not be disconnected.
  1299. *
  1300. * @param h the testbed run handle
  1301. * @return handle to the master controller
  1302. */
  1303. struct GNUNET_TESTBED_Controller *
  1304. GNUNET_TESTBED_run_get_controller_handle (struct GNUNET_TESTBED_RunHandle *h);
  1305. /**
  1306. * Opaque handle for barrier
  1307. */
  1308. struct GNUNET_TESTBED_Barrier;
  1309. /**
  1310. * Status of a barrier
  1311. */
  1312. enum GNUNET_TESTBED_BarrierStatus
  1313. {
  1314. /**
  1315. * Barrier initialised successfully
  1316. */
  1317. GNUNET_TESTBED_BARRIERSTATUS_INITIALISED = 1,
  1318. /**
  1319. * Barrier is crossed
  1320. */
  1321. GNUNET_TESTBED_BARRIERSTATUS_CROSSED,
  1322. /**
  1323. * Error status
  1324. */
  1325. GNUNET_TESTBED_BARRIERSTATUS_ERROR,
  1326. };
  1327. /**
  1328. * Functions of this type are to be given as callback argument to
  1329. * GNUNET_TESTBED_barrier_init(). The callback will be called when status
  1330. * information is available for the barrier.
  1331. *
  1332. * @param cls the closure given to GNUNET_TESTBED_barrier_init()
  1333. * @param name the name of the barrier
  1334. * @param barrier the barrier handle
  1335. * @param status status of the barrier. The barrier is removed once it has been
  1336. * crossed or an error occurs while processing it. Therefore it is
  1337. * invalid to call GNUNET_TESTBED_barrier_cancel() on a crossed or
  1338. * errored barrier.
  1339. * @param emsg if the status were to be #GNUNET_SYSERR, this parameter has the
  1340. * error messsage
  1341. */
  1342. typedef void
  1343. (*GNUNET_TESTBED_barrier_status_cb) (void *cls,
  1344. const char *name,
  1345. struct GNUNET_TESTBED_Barrier *barrier,
  1346. enum GNUNET_TESTBED_BarrierStatus status,
  1347. const char *emsg);
  1348. /**
  1349. * Initialise a barrier and call the given callback when the required percentage
  1350. * of peers (quorum) reach the barrier.
  1351. *
  1352. * @param controller the handle to the controller
  1353. * @param name identification name of the barrier
  1354. * @param quorum the percentage of peers that is required to reach the barrier.
  1355. * Peers signal reaching a barrier by calling
  1356. * GNUNET_TESTBED_barrier_reached().
  1357. * @param cb the callback to call when the barrier is reached or upon error.
  1358. * Cannot be NULL.
  1359. * @param cb_cls closure for @a cb
  1360. * @return barrier handle
  1361. */
  1362. struct GNUNET_TESTBED_Barrier *
  1363. GNUNET_TESTBED_barrier_init (struct GNUNET_TESTBED_Controller *controller,
  1364. const char *name,
  1365. unsigned int quorum,
  1366. GNUNET_TESTBED_barrier_status_cb cb,
  1367. void *cb_cls);
  1368. /**
  1369. * Cancel a barrier.
  1370. *
  1371. * @param barrier the barrier handle
  1372. */
  1373. void
  1374. GNUNET_TESTBED_barrier_cancel (struct GNUNET_TESTBED_Barrier *barrier);
  1375. /**
  1376. * Opaque handle for barrier wait
  1377. */
  1378. struct GNUNET_TESTBED_BarrierWaitHandle;
  1379. /**
  1380. * Functions of this type are to be given as acallback argumetn to
  1381. * GNUNET_TESTBED_barrier_wait(). The callback will be called when the barrier
  1382. * corresponding given in GNUNET_TESTBED_barrier_wait() is crossed or cancelled.
  1383. *
  1384. * @param cls closure pointer given to GNUNET_TESTBED_barrier_wait()
  1385. * @param name the barrier name
  1386. * @param status #GNUNET_SYSERR in case of error while waiting for the barrier;
  1387. * #GNUNET_OK if the barrier is crossed
  1388. */
  1389. typedef void
  1390. (*GNUNET_TESTBED_barrier_wait_cb) (void *cls,
  1391. const char *name,
  1392. int status);
  1393. /**
  1394. * Wait for a barrier to be crossed. This function should be called by the
  1395. * peers which have been started by the testbed. If the peer is not started by
  1396. * testbed this function may return error
  1397. *
  1398. * @param name the name of the barrier
  1399. * @param cb the barrier wait callback
  1400. * @param cls the closure for the above callback
  1401. * @return barrier wait handle which can be used to cancel the waiting at
  1402. * anytime before the callback is called. NULL upon error.
  1403. */
  1404. struct GNUNET_TESTBED_BarrierWaitHandle *
  1405. GNUNET_TESTBED_barrier_wait (const char *name,
  1406. GNUNET_TESTBED_barrier_wait_cb cb,
  1407. void *cls);
  1408. /**
  1409. * Cancel a barrier wait handle. Should not be called in or after the callback
  1410. * given to GNUNET_TESTBED_barrier_wait() has been called.
  1411. *
  1412. * @param h the barrier wait handle
  1413. */
  1414. void
  1415. GNUNET_TESTBED_barrier_wait_cancel (struct GNUNET_TESTBED_BarrierWaitHandle *h);
  1416. /**
  1417. * Model for configuring underlay links of a peer
  1418. * @ingroup underlay
  1419. */
  1420. struct GNUNET_TESTBED_UnderlayLinkModel;
  1421. /**
  1422. * The type of GNUNET_TESTBED_UnderlayLinkModel
  1423. * @ingroup underlay
  1424. */
  1425. enum GNUNET_TESTBED_UnderlayLinkModelType
  1426. {
  1427. /**
  1428. * The model is based on white listing of peers to which underlay connections
  1429. * are permitted. Underlay connections to all other peers will not be
  1430. * permitted.
  1431. */
  1432. GNUNET_TESTBED_UNDERLAYLINKMODELTYPE_BLACKLIST,
  1433. /**
  1434. * The model is based on black listing of peers to which underlay connections
  1435. * are not permitted. Underlay connections to all other peers will be
  1436. * permitted
  1437. */
  1438. GNUNET_TESTBED_UNDERLAYLINKMODELTYPE_WHITELIST
  1439. };
  1440. /**
  1441. * Create a GNUNET_TESTBED_UnderlayLinkModel for the given peer. A peer can
  1442. * have ONLY ONE model and it can be either a blacklist or whitelist based one.
  1443. *
  1444. * @ingroup underlay
  1445. * @param peer the peer for which the model has to be created
  1446. * @param type the type of the model
  1447. * @return the model
  1448. */
  1449. struct GNUNET_TESTBED_UnderlayLinkModel *
  1450. GNUNET_TESTBED_underlaylinkmodel_create (struct GNUNET_TESTBED_Peer *peer,
  1451. enum GNUNET_TESTBED_UnderlayLinkModelType type);
  1452. /**
  1453. * Add a peer to the given model. Underlay connections to the given peer will
  1454. * be permitted if the model is whitelist based; otherwise they will not be
  1455. * permitted.
  1456. *
  1457. * @ingroup underlay
  1458. * @param model the model
  1459. * @param peer the peer to add
  1460. */
  1461. void
  1462. GNUNET_TESTBED_underlaylinkmodel_add_peer (struct GNUNET_TESTBED_UnderlayLinkModel *model,
  1463. struct GNUNET_TESTBED_Peer *peer);
  1464. /**
  1465. * Set the metrics for a link to the given peer in the underlay model. The link
  1466. * SHOULD be permittable according to the given model.
  1467. *
  1468. * @ingroup underlay
  1469. * @param model the model
  1470. * @param peer the other end peer of the link
  1471. * @param latency latency of the link in microseconds
  1472. * @param loss data loss of the link expressed as a percentage
  1473. * @param bandwidth bandwidth of the link in kilobytes per second [kB/s]
  1474. */
  1475. void
  1476. GNUNET_TESTBED_underlaylinkmodel_set_link (struct GNUNET_TESTBED_UnderlayLinkModel *model,
  1477. struct GNUNET_TESTBED_Peer *peer,
  1478. uint32_t latency,
  1479. uint32_t loss,
  1480. uint32_t bandwidth);
  1481. /**
  1482. * Commit the model. The model is freed in this function(!).
  1483. *
  1484. * @ingroup underlay
  1485. * @param model the model to commit
  1486. */
  1487. void
  1488. GNUNET_TESTBED_underlaylinkmodel_commit (struct GNUNET_TESTBED_UnderlayLinkModel *model);
  1489. /**
  1490. * Free the resources of the model. Use this function only if the model has not
  1491. * be committed and has to be unallocated. The peer can then have another model
  1492. * created.
  1493. *
  1494. * @ingroup underlay
  1495. * @param model the model to unallocate
  1496. */
  1497. void
  1498. GNUNET_TESTBED_underlaylinkmodel_free (struct GNUNET_TESTBED_UnderlayLinkModel *model);
  1499. #if 0 /* keep Emacsens' auto-indent happy */
  1500. {
  1501. #endif
  1502. #ifdef __cplusplus
  1503. }
  1504. #endif
  1505. #endif
  1506. /** @} */ /* end of group */