transport-testing-communicator.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2019 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/transport-testing-communicator.h
  18. * @brief functions and structures related to testing-tng
  19. * @author Christian Grothoff
  20. * @author Julius Bünger
  21. */
  22. #include "platform.h"
  23. #include "gnunet_util_lib.h"
  24. #include "gnunet_ats_transport_service.h"
  25. #include "transport.h"
  26. /**
  27. * @brief Queue of a communicator and some context
  28. */
  29. struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue;
  30. /**
  31. * @brief Handle/Context to a single transmission
  32. */
  33. struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission;
  34. /**
  35. * @brief Function signature for callbacks that are called when new
  36. * backchannel message arrived
  37. *
  38. * @param cls Closure
  39. * @param msg Backchannel message
  40. * @param pid Target peer
  41. */
  42. typedef struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *
  43. (*GNUNET_TRANSPORT_TESTING_BackchannelCallback)(void *cls,
  44. struct GNUNET_MessageHeader *msg,
  45. struct GNUNET_PeerIdentity *pid);
  46. /**
  47. * @brief Function signature for callbacks that are called when new
  48. * communicators become available
  49. *
  50. * @param cls Closure
  51. * @param tc_h Communicator handle
  52. * @param cc Characteristics of communicator
  53. * @param address_prefix Prefix of the address
  54. */
  55. typedef void
  56. (*GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback)(void *cls,
  57. struct
  58. GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
  59. *tc_h,
  60. enum
  61. GNUNET_TRANSPORT_CommunicatorCharacteristics
  62. cc,
  63. char *address_prefix);
  64. /**
  65. * @brief Receive information about the address of a communicator.
  66. *
  67. * @param cls Closure
  68. * @param tc_h Communicator handle
  69. * @param address Address represented as string
  70. * @param expiration Expiration
  71. * @param aid Aid
  72. * @param nt Network Type
  73. */
  74. typedef void
  75. (*GNUNET_TRANSPORT_TESTING_AddAddressCallback)(void *cls,
  76. struct
  77. GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
  78. *tc_h,
  79. const char *address,
  80. struct GNUNET_TIME_Relative
  81. expiration,
  82. uint32_t aid,
  83. enum GNUNET_NetworkType nt);
  84. /**
  85. * @brief Get informed about the success of a queue request.
  86. *
  87. * @param cls Closure
  88. * @param tc_h Communicator handle
  89. * @param will_try #GNUNET_YES if communicator will try to create queue
  90. */
  91. typedef void
  92. (*GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback)(void *cls,
  93. struct
  94. GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
  95. *tc_h,
  96. int will_try);
  97. /**
  98. * @brief Handle opening of queue
  99. *
  100. * @param cls Closure
  101. * @param tc_h Communicator handle
  102. * @param tc_queue Handle to newly opened queue
  103. */
  104. typedef void
  105. (*GNUNET_TRANSPORT_TESTING_AddQueueCallback)(void *cls,
  106. struct
  107. GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
  108. *tc_h,
  109. struct
  110. GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue
  111. *tc_queue,
  112. size_t mtu);
  113. /**
  114. * @brief Handle an incoming message
  115. *
  116. * @param cls Closure
  117. * @param tc_h Handle to the receiving communicator
  118. * @param msg Received message
  119. */
  120. typedef void
  121. (*GNUNET_TRANSPORT_TESTING_IncomingMessageCallback)(void *cls,
  122. struct
  123. GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
  124. *tc_h,
  125. const char*payload,
  126. size_t payload_len);
  127. /**
  128. * @brief Handle to a transport communicator
  129. */
  130. struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
  131. {
  132. /**
  133. * Clients
  134. */
  135. struct MyClient *client_head;
  136. struct MyClient *client_tail;
  137. /**
  138. * @brief Handle to the client
  139. */
  140. struct GNUNET_MQ_Handle *c_mq;
  141. /**
  142. * @brief Handle to the configuration
  143. */
  144. struct GNUNET_CONFIGURATION_Handle *cfg;
  145. /**
  146. * @brief File name of configuration file
  147. */
  148. char *cfg_filename;
  149. struct GNUNET_PeerIdentity peer_id;
  150. /**
  151. * @brief Handle to the transport service
  152. */
  153. struct GNUNET_SERVICE_Handle *tsh;
  154. /**
  155. * @brief Task that will be run on shutdown to stop and clean transport
  156. * service
  157. */
  158. struct GNUNET_SCHEDULER_Task *ts_shutdown_task;
  159. /**
  160. * @brief Process of the communicator
  161. */
  162. struct GNUNET_OS_Process *c_proc;
  163. /**
  164. * NAT process
  165. */
  166. struct GNUNET_OS_Process *nat_proc;
  167. /**
  168. * resolver service process
  169. */
  170. struct GNUNET_OS_Process *resolver_proc;
  171. /**
  172. * statistics service process
  173. */
  174. struct GNUNET_OS_Process *stat_proc;
  175. /**
  176. * peerstore service process
  177. */
  178. struct GNUNET_OS_Process *ps_proc;
  179. /**
  180. * @brief Task that will be run on shutdown to stop and clean communicator
  181. */
  182. struct GNUNET_SCHEDULER_Task *c_shutdown_task;
  183. /**
  184. * @brief Characteristics of the communicator
  185. */
  186. enum GNUNET_TRANSPORT_CommunicatorCharacteristics c_characteristics;
  187. /**
  188. * @brief Specifies supported addresses
  189. */
  190. char *c_addr_prefix;
  191. /**
  192. * @brief Specifies supported addresses
  193. */
  194. char *c_address;
  195. /**
  196. * @brief Head of the DLL of queues associated with this communicator
  197. */
  198. struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *queue_head;
  199. /**
  200. * @brief Tail of the DLL of queues associated with this communicator
  201. */
  202. struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *queue_tail;
  203. /* Callbacks + Closures */
  204. /**
  205. * @brief Callback called when a new communicator connects
  206. */
  207. GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback
  208. communicator_available_cb;
  209. /**
  210. * @brief Callback called when a new communicator connects
  211. */
  212. GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb;
  213. /**
  214. * @brief Callback called when a new communicator connects
  215. */
  216. GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback queue_create_reply_cb;
  217. /**
  218. * @brief Callback called when a new communicator connects
  219. */
  220. GNUNET_TRANSPORT_TESTING_AddQueueCallback add_queue_cb;
  221. /**
  222. * @brief Callback called when a new communicator connects
  223. */
  224. GNUNET_TRANSPORT_TESTING_IncomingMessageCallback incoming_msg_cb;
  225. /**
  226. * @brief Backchannel callback
  227. */
  228. GNUNET_TRANSPORT_TESTING_BackchannelCallback bc_cb;
  229. /**
  230. * Our service handle
  231. */
  232. struct GNUNET_SERVICE_Handle *sh;
  233. /**
  234. * @brief Closure to the callback
  235. */
  236. void *cb_cls;
  237. /**
  238. * Backchannel supported
  239. */
  240. int bc_enabled;
  241. };
  242. /**
  243. * @brief Start communicator part of transport service and communicator
  244. *
  245. * @param service_name Name of the service
  246. * @param cfg Configuration handle
  247. * @param communicator_available Callback that is called when a new
  248. * communicator becomes available
  249. * @param add_address_cb Callback handling new addresses
  250. * @param queue_create_reply_cb Callback handling success of queue requests
  251. * @param add_queue_cb Callback handling freshly created queues
  252. * @param incoming_message_cb Callback handling incoming messages
  253. * @param cb_cls Closure to @p communicator_available
  254. *
  255. * @return Handle to the communicator duo
  256. */
  257. struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *
  258. GNUNET_TRANSPORT_TESTING_transport_communicator_service_start (
  259. const char *service_name,
  260. const char *binary_name,
  261. const char *cfg_filename,
  262. const struct GNUNET_PeerIdentity *peer_id,
  263. GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback
  264. communicator_available_cb,
  265. GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb,
  266. GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback queue_create_reply_cb,
  267. GNUNET_TRANSPORT_TESTING_AddQueueCallback add_queue_cb,
  268. GNUNET_TRANSPORT_TESTING_IncomingMessageCallback incoming_message_cb,
  269. GNUNET_TRANSPORT_TESTING_BackchannelCallback bc_cb,
  270. void *cb_cls);
  271. void
  272. GNUNET_TRANSPORT_TESTING_transport_communicator_service_stop (
  273. struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h);
  274. /**
  275. * @brief Instruct communicator to open a queue
  276. *
  277. * @param tc_h Handle to communicator which shall open queue
  278. * @param peer_id Towards which peer
  279. * @param address For which address
  280. */
  281. void
  282. GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue (struct
  283. GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
  284. *tc_h,
  285. const struct
  286. GNUNET_PeerIdentity
  287. *peer_id,
  288. const char *address);
  289. /**
  290. * @brief Instruct communicator to send data
  291. *
  292. * @param tc_queue The queue to use for sending
  293. * @param cont function to call when done sending
  294. * @param cont_cls closure for @a cont
  295. * @param payload Data to send
  296. * @param payload_size Size of the @a payload
  297. */
  298. void
  299. GNUNET_TRANSPORT_TESTING_transport_communicator_send (struct
  300. GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
  301. *tc_h,
  302. GNUNET_SCHEDULER_TaskCallback
  303. cont,
  304. void *cont_cls,
  305. const void *payload,
  306. size_t payload_size);