gnunet_psyc_util_lib.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2012, 2013 Christian Grothoff (and other contributing authors)
  4. GNUnet is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published
  6. by the Free Software Foundation; either version 3, or (at your
  7. 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. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNUnet; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. */
  17. /**
  18. * @author Gabor X Toth
  19. *
  20. * @file
  21. * PSYC utilities; receiving/transmitting/logging PSYC messages
  22. *
  23. * @defgroup psyc-util PSYC Utilities library
  24. * Receiving, transmitting, logging PSYC messages.
  25. * @{
  26. */
  27. #ifndef GNUNET_PSYC_UTIL_LIB_H
  28. #define GNUNET_PSYC_UTIL_LIB_H
  29. #ifdef __cplusplus
  30. extern "C"
  31. {
  32. #if 0 /* keep Emacsens' auto-indent happy */
  33. }
  34. #endif
  35. #endif
  36. #include "gnunet_util_lib.h"
  37. #include "gnunet_env_lib.h"
  38. #include "gnunet_psyc_service.h"
  39. /**
  40. * Create a PSYC message.
  41. *
  42. * @param method_name
  43. * PSYC method for the message.
  44. * @param env
  45. * Environment for the message.
  46. * @param data
  47. * Data payload for the message.
  48. * @param data_size
  49. * Size of @a data.
  50. *
  51. * @return Message header with size information,
  52. * followed by the message parts.
  53. */
  54. struct GNUNET_PSYC_Message *
  55. GNUNET_PSYC_message_create (const char *method_name,
  56. const struct GNUNET_ENV_Environment *env,
  57. const void *data,
  58. size_t data_size);
  59. /**
  60. * Parse PSYC message.
  61. *
  62. * @param msg
  63. * The PSYC message to parse.
  64. * @param env
  65. * The environment for the message with a list of modifiers.
  66. * @param[out] method_name
  67. * Pointer to the method name inside @a pmsg.
  68. * @param[out] data
  69. * Pointer to data inside @a pmsg.
  70. * @param[out] data_size
  71. * Size of @data is written here.
  72. *
  73. * @return #GNUNET_OK on success,
  74. * #GNUNET_SYSERR on parse error.
  75. */
  76. int
  77. GNUNET_PSYC_message_parse (const struct GNUNET_PSYC_MessageHeader *msg,
  78. const char **method_name,
  79. struct GNUNET_ENV_Environment *env,
  80. const void **data,
  81. uint16_t *data_size);
  82. void
  83. GNUNET_PSYC_log_message (enum GNUNET_ErrorType kind,
  84. const struct GNUNET_MessageHeader *msg);
  85. int
  86. GNUNET_PSYC_check_message_parts (uint16_t data_size, const char *data,
  87. uint16_t *first_ptype, uint16_t *last_ptype);
  88. struct GNUNET_PSYC_TransmitHandle;
  89. /**
  90. * Create a transmission handle.
  91. */
  92. struct GNUNET_PSYC_TransmitHandle *
  93. GNUNET_PSYC_transmit_create ();
  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_ENV_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 Receive handle.
  175. * @param msg The message.
  176. *
  177. * @return #GNUNET_OK on success,
  178. * #GNUNET_SYSERR on receive error.
  179. */
  180. int
  181. GNUNET_PSYC_receive_message (struct GNUNET_PSYC_ReceiveHandle *recv,
  182. const struct GNUNET_PSYC_MessageHeader *msg);
  183. /**
  184. * Check if @a data contains a series of valid message parts.
  185. *
  186. * @param data_size Size of @a data.
  187. * @param data Data.
  188. * @param[out] first_ptype Type of first message part.
  189. * @param[out] last_ptype Type of last message part.
  190. *
  191. * @return Number of message parts found in @a data.
  192. * or GNUNET_SYSERR if the message contains invalid parts.
  193. */
  194. int
  195. GNUNET_PSYC_receive_check_parts (uint16_t data_size, const char *data,
  196. uint16_t *first_ptype, uint16_t *last_ptype);
  197. /**
  198. * Initialize PSYC message header.
  199. */
  200. void
  201. GNUNET_PSYC_message_header_init (struct GNUNET_PSYC_MessageHeader *pmsg,
  202. const struct GNUNET_MULTICAST_MessageHeader *mmsg,
  203. uint32_t flags);
  204. /**
  205. * Create a new PSYC message header from a multicast message for sending it to clients.
  206. */
  207. struct GNUNET_PSYC_MessageHeader *
  208. GNUNET_PSYC_message_header_create (const struct GNUNET_MULTICAST_MessageHeader *mmsg,
  209. uint32_t flags);
  210. /**
  211. * Create a new PSYC message header from a PSYC message.
  212. */
  213. struct GNUNET_PSYC_MessageHeader *
  214. GNUNET_PSYC_message_header_create_from_psyc (const struct GNUNET_PSYC_Message *msg);
  215. #if 0 /* keep Emacsens' auto-indent happy */
  216. {
  217. #endif
  218. #ifdef __cplusplus
  219. }
  220. #endif
  221. /* ifndef GNUNET_PSYC_UTIL_LIB_H */
  222. #endif
  223. /** @} */ /* end of group */