You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

279 lines
7.2 KiB

  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2012, 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 Gabor X Toth
  18. *
  19. * @file
  20. * PSYC message utilities; receiving/transmitting/logging PSYC messages
  21. *
  22. * @defgroup psyc-util-message PSYC Utilities library: Messages
  23. * Receiving, transmitting, logging PSYC messages.
  24. * @{
  25. */
  26. #ifndef GNUNET_PSYC_MESSAGE_H
  27. #define GNUNET_PSYC_MESSAGE_H
  28. #ifdef __cplusplus
  29. extern "C"
  30. {
  31. #if 0 /* keep Emacsens' auto-indent happy */
  32. }
  33. #endif
  34. #endif
  35. #include "gnunet_util_lib.h"
  36. #include "gnunet_psyc_util_lib.h"
  37. #include "gnunet_psyc_service.h"
  38. /**
  39. * Create a PSYC message.
  40. *
  41. * @param method_name
  42. * PSYC method for the message.
  43. * @param env
  44. * Environment for the message.
  45. * @param data
  46. * Data payload for the message.
  47. * @param data_size
  48. * Size of @a data.
  49. *
  50. * @return Message header with size information,
  51. * followed by the message parts.
  52. *
  53. * FIXME: arg order
  54. */
  55. struct GNUNET_PSYC_Message *
  56. GNUNET_PSYC_message_create (const char *method_name,
  57. const struct GNUNET_PSYC_Environment *env,
  58. const void *data,
  59. size_t data_size);
  60. /**
  61. * Parse PSYC message.
  62. *
  63. * @param msg
  64. * The PSYC message to parse.
  65. * @param env
  66. * The environment for the message with a list of modifiers.
  67. * @param[out] method_name
  68. * Pointer to the method name inside @a pmsg.
  69. * @param[out] data
  70. * Pointer to data inside @a pmsg.
  71. * @param[out] data_size
  72. * Size of @data is written here.
  73. *
  74. * @return #GNUNET_OK on success,
  75. * #GNUNET_SYSERR on parse error.
  76. *
  77. * FIXME: arg order
  78. */
  79. int
  80. GNUNET_PSYC_message_parse (const struct GNUNET_PSYC_MessageHeader *msg,
  81. const char **method_name,
  82. struct GNUNET_PSYC_Environment *env,
  83. const void **data,
  84. uint16_t *data_size);
  85. void
  86. GNUNET_PSYC_log_message (enum GNUNET_ErrorType kind,
  87. const struct GNUNET_MessageHeader *msg);
  88. struct GNUNET_PSYC_TransmitHandle;
  89. /**
  90. * Create a transmission handle.
  91. */
  92. struct GNUNET_PSYC_TransmitHandle *
  93. GNUNET_PSYC_transmit_create (struct GNUNET_MQ_Handle *mq);
  94. /**
  95. * Destroy a transmission handle.
  96. */
  97. void
  98. GNUNET_PSYC_transmit_destroy (struct GNUNET_PSYC_TransmitHandle *tmit);
  99. /**
  100. * Transmit a message.
  101. *
  102. * @param tmit
  103. * Transmission handle.
  104. * @param method_name
  105. * Which method should be invoked.
  106. * @param env
  107. * Environment for the message.
  108. * Should stay available until the first call to notify_data.
  109. * Can be NULL if there are no modifiers or @a notify_mod is
  110. * provided instead.
  111. * @param notify_mod
  112. * Function to call to obtain modifiers.
  113. * Can be NULL if there are no modifiers or @a env is provided instead.
  114. * @param notify_data
  115. * Function to call to obtain fragments of the data.
  116. * @param notify_cls
  117. * Closure for @a notify_mod and @a notify_data.
  118. * @param flags
  119. * Flags for the message being transmitted.
  120. *
  121. * @return #GNUNET_OK if the transmission was started.
  122. * #GNUNET_SYSERR if another transmission is already going on.
  123. */
  124. int
  125. GNUNET_PSYC_transmit_message (struct GNUNET_PSYC_TransmitHandle *tmit,
  126. const char *method_name,
  127. const struct GNUNET_PSYC_Environment *env,
  128. GNUNET_PSYC_TransmitNotifyModifier notify_mod,
  129. GNUNET_PSYC_TransmitNotifyData notify_data,
  130. void *notify_cls,
  131. uint32_t flags);
  132. /**
  133. * Resume transmission.
  134. *
  135. * @param tmit Transmission handle.
  136. */
  137. void
  138. GNUNET_PSYC_transmit_resume (struct GNUNET_PSYC_TransmitHandle *tmit);
  139. /**
  140. * Abort transmission request.
  141. *
  142. * @param tmit Transmission handle.
  143. */
  144. void
  145. GNUNET_PSYC_transmit_cancel (struct GNUNET_PSYC_TransmitHandle *tmit);
  146. /**
  147. * Got acknowledgement of a transmitted message part, continue transmission.
  148. *
  149. * @param tmit Transmission handle.
  150. */
  151. void
  152. GNUNET_PSYC_transmit_got_ack (struct GNUNET_PSYC_TransmitHandle *tmit);
  153. struct GNUNET_PSYC_ReceiveHandle;
  154. /**
  155. * Create handle for receiving messages.
  156. */
  157. struct GNUNET_PSYC_ReceiveHandle *
  158. GNUNET_PSYC_receive_create (GNUNET_PSYC_MessageCallback message_cb,
  159. GNUNET_PSYC_MessagePartCallback message_part_cb,
  160. void *cb_cls);
  161. /**
  162. * Destroy handle for receiving messages.
  163. */
  164. void
  165. GNUNET_PSYC_receive_destroy (struct GNUNET_PSYC_ReceiveHandle *recv);
  166. /**
  167. * Reset stored data related to the last received message.
  168. */
  169. void
  170. GNUNET_PSYC_receive_reset (struct GNUNET_PSYC_ReceiveHandle *recv);
  171. /**
  172. * Handle incoming PSYC message.
  173. *
  174. * @param recv
  175. * Receive handle.
  176. * @param msg
  177. * The message.
  178. *
  179. * @return #GNUNET_OK on success,
  180. * #GNUNET_SYSERR on receive error.
  181. */
  182. int
  183. GNUNET_PSYC_receive_message (struct GNUNET_PSYC_ReceiveHandle *recv,
  184. const struct GNUNET_PSYC_MessageHeader *msg);
  185. /**
  186. * Check if @a data contains a series of valid message parts.
  187. *
  188. * @param data_size
  189. * Size of @a data.
  190. * @param data
  191. * Data.
  192. * @param[out] first_ptype
  193. * Type of first message part.
  194. * @param[out] last_ptype
  195. * Type of last message part.
  196. *
  197. * @return Number of message parts found in @a data.
  198. * or GNUNET_SYSERR if the message contains invalid parts.
  199. */
  200. int
  201. GNUNET_PSYC_receive_check_parts (uint16_t data_size, const char *data,
  202. uint16_t *first_ptype, uint16_t *last_ptype);
  203. /**
  204. * Initialize PSYC message header.
  205. */
  206. void
  207. GNUNET_PSYC_message_header_init (struct GNUNET_PSYC_MessageHeader *pmsg,
  208. const struct GNUNET_MULTICAST_MessageHeader *mmsg,
  209. uint32_t flags);
  210. /**
  211. * Create a new PSYC message header from a multicast message for sending it to clients.
  212. */
  213. struct GNUNET_PSYC_MessageHeader *
  214. GNUNET_PSYC_message_header_create (const struct GNUNET_MULTICAST_MessageHeader *mmsg,
  215. uint32_t flags);
  216. /**
  217. * Create a new PSYC message header from a PSYC message.
  218. */
  219. struct GNUNET_PSYC_MessageHeader *
  220. GNUNET_PSYC_message_header_create_from_psyc (const struct GNUNET_PSYC_Message *msg);
  221. #if 0 /* keep Emacsens' auto-indent happy */
  222. {
  223. #endif
  224. #ifdef __cplusplus
  225. }
  226. #endif
  227. /* ifndef GNUNET_PSYC_MESSAGE_H */
  228. #endif
  229. /** @} */ /* end of group */