testbed_api_peers.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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. * @file testbed/testbed_api_peers.h
  18. * @brief internal API to access the 'peers' subsystem
  19. * @author Christian Grothoff
  20. * @author Sree Harsha Totakura
  21. */
  22. #ifndef NEW_TESTING_API_PEERS_H
  23. #define NEW_TESTING_API_PEERS_H
  24. #include "gnunet_testbed_service.h"
  25. #include "gnunet_helper_lib.h"
  26. /**
  27. * Enumeration of possible states a peer could be in
  28. */
  29. enum PeerState
  30. {
  31. /**
  32. * State to signify that this peer is invalid
  33. */
  34. TESTBED_PS_INVALID,
  35. /**
  36. * The peer has been created
  37. */
  38. TESTBED_PS_CREATED,
  39. /**
  40. * The peer is running
  41. */
  42. TESTBED_PS_STARTED,
  43. /**
  44. * The peer is stopped
  45. */
  46. TESTBED_PS_STOPPED,
  47. };
  48. /**
  49. * A peer controlled by the testing framework. A peer runs
  50. * at a particular host.
  51. */
  52. struct GNUNET_TESTBED_Peer
  53. {
  54. /**
  55. * peer list DLL
  56. */
  57. struct GNUNET_TESTBED_Peer *next;
  58. /**
  59. * peer list DLL
  60. */
  61. struct GNUNET_TESTBED_Peer *prev;
  62. /**
  63. * Our controller context (not necessarily the controller
  64. * that is responsible for starting/running the peer!).
  65. */
  66. struct GNUNET_TESTBED_Controller *controller;
  67. /**
  68. * Which host does this peer run on?
  69. */
  70. struct GNUNET_TESTBED_Host *host;
  71. /**
  72. * Globally unique ID of the peer.
  73. */
  74. uint32_t unique_id;
  75. /**
  76. * Peer's state
  77. */
  78. enum PeerState state;
  79. /**
  80. * Has an underlay model already set for this peer?
  81. */
  82. uint8_t underlay_model_exists;
  83. };
  84. /**
  85. * Data for the OperationType OP_PEER_CREATE
  86. */
  87. struct PeerCreateData
  88. {
  89. /**
  90. * The host where the peer has to be created
  91. */
  92. struct GNUNET_TESTBED_Host *host;
  93. /**
  94. * The template configuration of the peer
  95. */
  96. const struct GNUNET_CONFIGURATION_Handle *cfg;
  97. /**
  98. * The call back to call when we receive peer create success message
  99. */
  100. GNUNET_TESTBED_PeerCreateCallback cb;
  101. /**
  102. * The closure for the above callback
  103. */
  104. void *cls;
  105. /**
  106. * The peer structure to return when we get success message
  107. */
  108. struct GNUNET_TESTBED_Peer *peer;
  109. };
  110. /**
  111. * Data for OperationType OP_PEER_START and OP_PEER_STOP
  112. */
  113. struct PeerEventData
  114. {
  115. /**
  116. * The handle of the peer to start
  117. */
  118. struct GNUNET_TESTBED_Peer *peer;
  119. /**
  120. * The Peer churn callback to call when this operation is completed
  121. */
  122. GNUNET_TESTBED_PeerChurnCallback pcc;
  123. /**
  124. * Closure for the above callback
  125. */
  126. void *pcc_cls;
  127. };
  128. /**
  129. * Data for the OperationType OP_PEER_DESTROY;
  130. */
  131. struct PeerDestroyData
  132. {
  133. /**
  134. * The peer structure
  135. */
  136. struct GNUNET_TESTBED_Peer *peer;
  137. //PEERDESTROYDATA
  138. };
  139. /**
  140. * Data for the OperationType OP_PEER_INFO
  141. */
  142. struct PeerInfoData
  143. {
  144. /**
  145. * The peer whose information has been requested
  146. */
  147. struct GNUNET_TESTBED_Peer *peer;
  148. /**
  149. * The Peer info callback to call when this operation has completed
  150. */
  151. GNUNET_TESTBED_PeerInfoCallback cb;
  152. /**
  153. * The closure for peer info callback
  154. */
  155. void *cb_cls;
  156. /**
  157. * The type of peer information requested
  158. */
  159. enum GNUNET_TESTBED_PeerInformationType pit;
  160. };
  161. /**
  162. * Data for the operations of type OP_PEER_RECONFIGURE
  163. */
  164. struct PeerReconfigureData
  165. {
  166. /**
  167. * The peer whose information has been requested
  168. */
  169. struct GNUNET_TESTBED_Peer *peer;
  170. /**
  171. * The serialized new configuration template
  172. */
  173. char *config;
  174. /**
  175. * the size of the serialized configuration
  176. */
  177. uint16_t cfg_size;
  178. };
  179. /**
  180. * Data structure for OperationType OP_OVERLAY_CONNECT
  181. */
  182. struct OverlayConnectData
  183. {
  184. /**
  185. * Peer A to connect to peer B
  186. */
  187. struct GNUNET_TESTBED_Peer *p1;
  188. /**
  189. * Peer B
  190. */
  191. struct GNUNET_TESTBED_Peer *p2;
  192. /**
  193. * The operation completion callback to call once this operation is done
  194. */
  195. GNUNET_TESTBED_OperationCompletionCallback cb;
  196. /**
  197. * The closure for the above callback
  198. */
  199. void *cb_cls;
  200. /**
  201. * OperationContext for forwarded operations generated when peer1's controller doesn't have the
  202. * configuration of peer2's controller for linking laterally to attemp an
  203. * overlay connection between peer 1 and peer 2.
  204. */
  205. struct OperationContext *sub_opc;
  206. };
  207. struct ManageServiceData {
  208. GNUNET_TESTBED_OperationCompletionCallback cb;
  209. void *cb_cls;
  210. struct GNUNET_TESTBED_Peer *peer;
  211. char *service_name;
  212. unsigned int start;
  213. uint16_t msize;
  214. };
  215. /**
  216. * Generate PeerGetConfigurationMessage
  217. *
  218. * @param peer_id the id of the peer whose information we have to get
  219. * @param operation_id the ip of the operation that should be represented in
  220. * the message
  221. * @return the PeerGetConfigurationMessage
  222. */
  223. struct GNUNET_TESTBED_PeerGetConfigurationMessage *
  224. GNUNET_TESTBED_generate_peergetconfig_msg_ (uint32_t peer_id,
  225. uint64_t operation_id);
  226. /**
  227. * Adds a peer to the peer list
  228. *
  229. * @param peer the peer to add to the peer list
  230. */
  231. void
  232. GNUNET_TESTBED_peer_register_ (struct GNUNET_TESTBED_Peer *peer);
  233. /**
  234. * Removes a peer from the peer list
  235. *
  236. * @param peer the peer to remove
  237. */
  238. void
  239. GNUNET_TESTBED_peer_deregister_ (struct GNUNET_TESTBED_Peer *peer);
  240. /**
  241. * Frees all peers
  242. */
  243. void
  244. GNUNET_TESTBED_cleanup_peers_ (void);
  245. #endif
  246. /* end of testbed_api_peers.h */