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.
 
 
 
 

384 lines
11 KiB

  1. /*
  2. This file is part of GNUnet
  3. Copyright (C) 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. * Plugin API for the PSYCstore database backend
  21. *
  22. * @defgroup psycstore-plugin PSYC Store plugin API
  23. * Plugin API for the PSYC Store database backend
  24. * @{
  25. */
  26. #ifndef GNUNET_PSYCSTORE_PLUGIN_H
  27. #define GNUNET_PSYCSTORE_PLUGIN_H
  28. #include "gnunet_util_lib.h"
  29. #include "gnunet_psycstore_service.h"
  30. #ifdef __cplusplus
  31. extern "C"
  32. {
  33. #if 0 /* keep Emacsens' auto-indent happy */
  34. }
  35. #endif
  36. #endif
  37. /**
  38. * Struct returned by the initialization function of the plugin.
  39. */
  40. struct GNUNET_PSYCSTORE_PluginFunctions
  41. {
  42. /**
  43. * Closure to pass to all plugin functions.
  44. */
  45. void *cls;
  46. /**
  47. * Store join/leave events for a PSYC channel in order to be able to answer
  48. * membership test queries later.
  49. *
  50. * @see GNUNET_PSYCSTORE_membership_store()
  51. *
  52. * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  53. */
  54. int
  55. (*membership_store) (void *cls,
  56. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  57. const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
  58. int did_join,
  59. uint64_t announced_at,
  60. uint64_t effective_since,
  61. uint64_t group_generation);
  62. /**
  63. * Test if a member was admitted to the channel at the given message ID.
  64. *
  65. * @see GNUNET_PSYCSTORE_membership_test()
  66. *
  67. * @return #GNUNET_YES if the member was admitted, #GNUNET_NO if not,
  68. * #GNUNET_SYSERR if there was en error.
  69. */
  70. int
  71. (*membership_test) (void *cls,
  72. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  73. const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
  74. uint64_t message_id);
  75. /**
  76. * Store a message fragment sent to a channel.
  77. *
  78. * @see GNUNET_PSYCSTORE_fragment_store()
  79. *
  80. * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  81. */
  82. int
  83. (*fragment_store) (void *cls,
  84. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  85. const struct GNUNET_MULTICAST_MessageHeader *message,
  86. uint32_t psycstore_flags);
  87. /**
  88. * Set additional flags for a given message.
  89. *
  90. * They are OR'd with any existing flags set.
  91. *
  92. * @param cls Closure.
  93. * @param channel_key Public key of the channel.
  94. * @param message_id ID of the message.
  95. * @param psycstore_flags OR'd GNUNET_PSYCSTORE_MessageFlags.
  96. *
  97. * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  98. */
  99. int
  100. (*message_add_flags) (void *cls,
  101. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  102. uint64_t message_id,
  103. uint32_t psycstore_flags);
  104. /**
  105. * Retrieve a message fragment range by fragment ID.
  106. *
  107. * @see GNUNET_PSYCSTORE_fragment_get()
  108. *
  109. * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  110. */
  111. int
  112. (*fragment_get) (void *cls,
  113. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  114. uint64_t first_fragment_id,
  115. uint64_t last_fragment_id,
  116. uint64_t *returned_fragments,
  117. GNUNET_PSYCSTORE_FragmentCallback cb,
  118. void *cb_cls);
  119. /**
  120. * Retrieve latest message fragments.
  121. *
  122. * @see GNUNET_PSYCSTORE_fragment_get()
  123. *
  124. * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  125. */
  126. int
  127. (*fragment_get_latest) (void *cls,
  128. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  129. uint64_t fragment_limit,
  130. uint64_t *returned_fragments,
  131. GNUNET_PSYCSTORE_FragmentCallback cb,
  132. void *cb_cls);
  133. /**
  134. * Retrieve all fragments of a message ID range.
  135. *
  136. * @see GNUNET_PSYCSTORE_message_get()
  137. *
  138. * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  139. */
  140. int
  141. (*message_get) (void *cls,
  142. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  143. uint64_t first_fragment_id,
  144. uint64_t last_fragment_id,
  145. uint64_t fragment_limit,
  146. uint64_t *returned_fragments,
  147. GNUNET_PSYCSTORE_FragmentCallback cb,
  148. void *cb_cls);
  149. /**
  150. * Retrieve all fragments of the latest messages.
  151. *
  152. * @see GNUNET_PSYCSTORE_message_get()
  153. *
  154. * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  155. */
  156. int
  157. (*message_get_latest) (void *cls,
  158. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  159. uint64_t fragment_limit,
  160. uint64_t *returned_fragments,
  161. GNUNET_PSYCSTORE_FragmentCallback cb,
  162. void *cb_cls);
  163. /**
  164. * Retrieve a fragment of message specified by its message ID and fragment
  165. * offset.
  166. *
  167. * @see GNUNET_PSYCSTORE_message_get_fragment()
  168. *
  169. * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  170. */
  171. int
  172. (*message_get_fragment) (void *cls,
  173. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  174. uint64_t message_id,
  175. uint64_t fragment_offset,
  176. GNUNET_PSYCSTORE_FragmentCallback cb,
  177. void *cb_cls);
  178. /**
  179. * Retrieve the max. values of message counters for a channel.
  180. *
  181. * @see GNUNET_PSYCSTORE_counters_get()
  182. *
  183. * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  184. */
  185. int
  186. (*counters_message_get) (void *cls,
  187. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  188. uint64_t *max_fragment_id,
  189. uint64_t *max_message_id,
  190. uint64_t *max_group_generation);
  191. /**
  192. * Retrieve the max. values of state counters for a channel.
  193. *
  194. * @see GNUNET_PSYCSTORE_counters_get()
  195. *
  196. * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  197. */
  198. int
  199. (*counters_state_get) (void *cls,
  200. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  201. uint64_t *max_state_message_id);
  202. /**
  203. * Begin modifying current state.
  204. *
  205. * @see GNUNET_PSYCSTORE_state_modify()
  206. *
  207. * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  208. */
  209. int
  210. (*state_modify_begin) (void *cls,
  211. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  212. uint64_t message_id, uint64_t state_delta);
  213. /**
  214. * Set the current value of a state variable.
  215. *
  216. * The state modification process is started with state_modify_begin(),
  217. * which is followed by one or more calls to this function,
  218. * and finished with state_modify_end().
  219. *
  220. * @see GNUNET_PSYCSTORE_state_modify()
  221. *
  222. * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  223. */
  224. int
  225. (*state_modify_op) (void *cls,
  226. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  227. enum GNUNET_PSYC_Operator op,
  228. const char *name, const void *value, size_t value_size);
  229. /**
  230. * End modifying current state.
  231. *
  232. * @see GNUNET_PSYCSTORE_state_modify()
  233. *
  234. * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  235. */
  236. int
  237. (*state_modify_end) (void *cls,
  238. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  239. uint64_t message_id);
  240. /**
  241. * Begin synchronizing state.
  242. *
  243. * @see GNUNET_PSYCSTORE_state_sync()
  244. *
  245. * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  246. */
  247. int
  248. (*state_sync_begin) (void *cls,
  249. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key);
  250. /**
  251. * Assign value of a state variable while synchronizing state.
  252. *
  253. * The state synchronization process is started with state_sync_begin(),
  254. * which is followed by one or more calls to this function,
  255. * and finished using state_sync_end().
  256. *
  257. * @see GNUNET_PSYCSTORE_state_sync()
  258. *
  259. * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  260. */
  261. int
  262. (*state_sync_assign) (void *cls,
  263. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  264. const char *name, const void *value, size_t value_size);
  265. /**
  266. * End synchronizing state.
  267. *
  268. * @see GNUNET_PSYCSTORE_state_sync()
  269. *
  270. * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  271. */
  272. int
  273. (*state_sync_end) (void *cls,
  274. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  275. uint64_t max_state_message_id,
  276. uint64_t state_hash_message_id);
  277. /**
  278. * Reset the state of a channel.
  279. *
  280. * Delete all state variables stored for the given channel.
  281. *
  282. * @see GNUNET_PSYCSTORE_state_reset()
  283. *
  284. * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  285. */
  286. int
  287. (*state_reset) (void *cls,
  288. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key);
  289. /**
  290. * Update signed state values from the current ones.
  291. *
  292. * Sets value_signed = value_current for each variable for the given channel.
  293. */
  294. int
  295. (*state_update_signed) (void *cls,
  296. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key);
  297. /**
  298. * Retrieve a state variable by name (exact match).
  299. *
  300. * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  301. */
  302. int
  303. (*state_get) (void *cls,
  304. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  305. const char *name,
  306. GNUNET_PSYCSTORE_StateCallback cb,
  307. void *cb_cls);
  308. /**
  309. * Retrieve all state variables for a channel with the given prefix.
  310. *
  311. * @see GNUNET_PSYCSTORE_state_get_prefix()
  312. *
  313. * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  314. */
  315. int
  316. (*state_get_prefix) (void *cls,
  317. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  318. const char *name,
  319. GNUNET_PSYCSTORE_StateCallback cb,
  320. void *cb_cls);
  321. /**
  322. * Retrieve all signed state variables for a channel.
  323. *
  324. * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  325. */
  326. int
  327. (*state_get_signed) (void *cls,
  328. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  329. GNUNET_PSYCSTORE_StateCallback cb,
  330. void *cb_cls);
  331. };
  332. #if 0 /* keep Emacsens' auto-indent happy */
  333. {
  334. #endif
  335. #ifdef __cplusplus
  336. }
  337. #endif
  338. #endif
  339. /** @} */ /* end of group */