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.
 
 
 
 

1286 lines
40 KiB

  1. /*
  2. * This file is part of GNUnet
  3. * Copyright (C) 2013 GNUnet e.V.
  4. *
  5. * GNUnet is free software: you can redistribute it and/or modify it
  6. * under the terms of the GNU Affero General Public License as published
  7. * by the Free Software Foundation, either version 3 of the License,
  8. * or (at your option) any later version.
  9. *
  10. * GNUnet is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. SPDX-License-Identifier: AGPL3.0-or-later
  18. */
  19. /**
  20. * @file psycstore/psycstore_api.c
  21. * @brief API to interact with the PSYCstore service
  22. * @author Gabor X Toth
  23. * @author Christian Grothoff
  24. */
  25. #include <inttypes.h>
  26. #include "platform.h"
  27. #include "gnunet_util_lib.h"
  28. #include "gnunet_constants.h"
  29. #include "gnunet_protocols.h"
  30. #include "gnunet_psycstore_service.h"
  31. #include "gnunet_multicast_service.h"
  32. #include "psycstore.h"
  33. #define LOG(kind,...) GNUNET_log_from (kind, "psycstore-api",__VA_ARGS__)
  34. /**
  35. * Handle for an operation with the PSYCstore service.
  36. */
  37. struct GNUNET_PSYCSTORE_OperationHandle
  38. {
  39. /**
  40. * Main PSYCstore handle.
  41. */
  42. struct GNUNET_PSYCSTORE_Handle *h;
  43. /**
  44. * Data callbacks.
  45. */
  46. union {
  47. GNUNET_PSYCSTORE_FragmentCallback fragment_cb;
  48. GNUNET_PSYCSTORE_CountersCallback counters_cb;
  49. GNUNET_PSYCSTORE_StateCallback state_cb;
  50. };
  51. /**
  52. * Closure for callbacks.
  53. */
  54. void *cls;
  55. /**
  56. * Message envelope.
  57. */
  58. struct GNUNET_MQ_Envelope *env;
  59. /**
  60. * Operation ID.
  61. */
  62. uint64_t op_id;
  63. };
  64. /**
  65. * Handle for the service.
  66. */
  67. struct GNUNET_PSYCSTORE_Handle
  68. {
  69. /**
  70. * Configuration to use.
  71. */
  72. const struct GNUNET_CONFIGURATION_Handle *cfg;
  73. /**
  74. * Client connection.
  75. */
  76. struct GNUNET_MQ_Handle *mq;
  77. /**
  78. * Async operations.
  79. */
  80. struct GNUNET_OP_Handle *op;
  81. /**
  82. * Task doing exponential back-off trying to reconnect.
  83. */
  84. struct GNUNET_SCHEDULER_Task *reconnect_task;
  85. /**
  86. * Delay for next connect retry.
  87. */
  88. struct GNUNET_TIME_Relative reconnect_delay;
  89. GNUNET_PSYCSTORE_FragmentCallback *fragment_cb;
  90. GNUNET_PSYCSTORE_CountersCallback *counters_cb;
  91. GNUNET_PSYCSTORE_StateCallback *state_cb;
  92. /**
  93. * Closure for callbacks.
  94. */
  95. void *cb_cls;
  96. };
  97. static int
  98. check_result_code (void *cls, const struct OperationResult *opres)
  99. {
  100. uint16_t size = ntohs (opres->header.size);
  101. const char *str = (const char *) &opres[1];
  102. if ( (sizeof (*opres) < size) &&
  103. ('\0' != str[size - sizeof (*opres) - 1]) )
  104. {
  105. GNUNET_break (0);
  106. return GNUNET_SYSERR;
  107. }
  108. return GNUNET_OK;
  109. }
  110. static void
  111. handle_result_code (void *cls, const struct OperationResult *opres)
  112. {
  113. struct GNUNET_PSYCSTORE_Handle *h = cls;
  114. struct GNUNET_PSYCSTORE_OperationHandle *op = NULL;
  115. uint16_t size = ntohs (opres->header.size);
  116. const char *
  117. str = (sizeof (*opres) < size) ? (const char *) &opres[1] : "";
  118. if (GNUNET_YES == GNUNET_OP_result (h->op, GNUNET_ntohll (opres->op_id),
  119. GNUNET_ntohll (opres->result_code) + INT64_MIN,
  120. str, size - sizeof (*opres), (void **) &op))
  121. {
  122. LOG (GNUNET_ERROR_TYPE_DEBUG,
  123. "handle_result_code: Received result message with OP ID: %" PRIu64 "\n",
  124. GNUNET_ntohll (opres->op_id));
  125. GNUNET_free (op);
  126. }
  127. else
  128. {
  129. LOG (GNUNET_ERROR_TYPE_DEBUG,
  130. "handle_result_code: No callback registered for OP ID %" PRIu64 ".\n",
  131. GNUNET_ntohll (opres->op_id));
  132. }
  133. h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS;
  134. }
  135. static void
  136. handle_result_counters (void *cls, const struct CountersResult *cres)
  137. {
  138. struct GNUNET_PSYCSTORE_Handle *h = cls;
  139. struct GNUNET_PSYCSTORE_OperationHandle *op = NULL;
  140. if (GNUNET_YES == GNUNET_OP_get (h->op, GNUNET_ntohll (cres->op_id),
  141. NULL, NULL, (void **) &op))
  142. {
  143. GNUNET_assert (NULL != op);
  144. if (NULL != op->counters_cb)
  145. {
  146. op->counters_cb (op->cls,
  147. ntohl (cres->result_code),
  148. GNUNET_ntohll (cres->max_fragment_id),
  149. GNUNET_ntohll (cres->max_message_id),
  150. GNUNET_ntohll (cres->max_group_generation),
  151. GNUNET_ntohll (cres->max_state_message_id));
  152. }
  153. GNUNET_OP_remove (h->op, GNUNET_ntohll (cres->op_id));
  154. GNUNET_free (op);
  155. }
  156. else
  157. {
  158. LOG (GNUNET_ERROR_TYPE_DEBUG,
  159. "handle_result_counters: No callback registered for OP ID %" PRIu64 ".\n",
  160. GNUNET_ntohll (cres->op_id));
  161. }
  162. h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS;
  163. }
  164. static int
  165. check_result_fragment (void *cls, const struct FragmentResult *fres)
  166. {
  167. uint16_t size = ntohs (fres->header.size);
  168. struct GNUNET_MULTICAST_MessageHeader *mmsg =
  169. (struct GNUNET_MULTICAST_MessageHeader *) &fres[1];
  170. if (sizeof (*fres) + sizeof (*mmsg) < size
  171. && sizeof (*fres) + ntohs (mmsg->header.size) != size)
  172. {
  173. LOG (GNUNET_ERROR_TYPE_ERROR,
  174. "check_result_fragment: Received message with invalid length %lu bytes.\n",
  175. size, sizeof (*fres));
  176. GNUNET_break (0);
  177. return GNUNET_SYSERR;
  178. }
  179. return GNUNET_OK;
  180. }
  181. static void
  182. handle_result_fragment (void *cls, const struct FragmentResult *fres)
  183. {
  184. struct GNUNET_PSYCSTORE_Handle *h = cls;
  185. struct GNUNET_PSYCSTORE_OperationHandle *op = NULL;
  186. if (GNUNET_YES == GNUNET_OP_get (h->op, GNUNET_ntohll (fres->op_id),
  187. NULL, NULL, (void **) &op))
  188. {
  189. GNUNET_assert (NULL != op);
  190. if (NULL != op->fragment_cb)
  191. op->fragment_cb (op->cls,
  192. (struct GNUNET_MULTICAST_MessageHeader *) &fres[1],
  193. ntohl (fres->psycstore_flags));
  194. //GNUNET_OP_remove (h->op, GNUNET_ntohll (fres->op_id));
  195. //GNUNET_free (op);
  196. }
  197. else
  198. {
  199. LOG (GNUNET_ERROR_TYPE_DEBUG,
  200. "handle_result_fragment: No callback registered for OP ID %" PRIu64 ".\n",
  201. GNUNET_ntohll (fres->op_id));
  202. }
  203. h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS;
  204. }
  205. static int
  206. check_result_state (void *cls, const struct StateResult *sres)
  207. {
  208. const char *name = (const char *) &sres[1];
  209. uint16_t size = ntohs (sres->header.size);
  210. uint16_t name_size = ntohs (sres->name_size);
  211. if (name_size <= 2
  212. || size - sizeof (*sres) < name_size
  213. || '\0' != name[name_size - 1])
  214. {
  215. LOG (GNUNET_ERROR_TYPE_ERROR,
  216. "check_result_state: Received state result message with invalid name.\n");
  217. GNUNET_break (0);
  218. return GNUNET_SYSERR;
  219. }
  220. return GNUNET_OK;
  221. }
  222. static void
  223. handle_result_state (void *cls, const struct StateResult *sres)
  224. {
  225. struct GNUNET_PSYCSTORE_Handle *h = cls;
  226. struct GNUNET_PSYCSTORE_OperationHandle *op = NULL;
  227. const char *name = (const char *) &sres[1];
  228. uint16_t name_size = ntohs (sres->name_size);
  229. if (GNUNET_YES == GNUNET_OP_get (h->op, GNUNET_ntohll (sres->op_id),
  230. NULL, NULL, (void **) &op))
  231. {
  232. GNUNET_assert (NULL != op);
  233. if (NULL != op->state_cb)
  234. op->state_cb (op->cls, name, (char *) &sres[1] + name_size,
  235. ntohs (sres->header.size) - sizeof (*sres) - name_size);
  236. //GNUNET_OP_remove (h->op, GNUNET_ntohll (sres->op_id));
  237. //GNUNET_free (op);
  238. }
  239. else
  240. {
  241. LOG (GNUNET_ERROR_TYPE_DEBUG,
  242. "handle_result_state: No callback registered for OP ID %" PRIu64 ".\n",
  243. GNUNET_ntohll (sres->op_id));
  244. }
  245. h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS;
  246. }
  247. static void
  248. reconnect (void *cls);
  249. /**
  250. * Client disconnected from service.
  251. *
  252. * Reconnect after backoff period.=
  253. */
  254. static void
  255. disconnected (void *cls, enum GNUNET_MQ_Error error)
  256. {
  257. struct GNUNET_PSYCSTORE_Handle *h = cls;
  258. LOG (GNUNET_ERROR_TYPE_DEBUG,
  259. "Origin client disconnected (%d), re-connecting\n",
  260. (int) error);
  261. if (NULL != h->mq)
  262. {
  263. GNUNET_MQ_destroy (h->mq);
  264. GNUNET_OP_destroy (h->op);
  265. h->mq = NULL;
  266. h->op = NULL;
  267. }
  268. h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->reconnect_delay,
  269. &reconnect, h);
  270. h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
  271. }
  272. static void
  273. do_connect (struct GNUNET_PSYCSTORE_Handle *h)
  274. {
  275. LOG (GNUNET_ERROR_TYPE_DEBUG,
  276. "Connecting to PSYCstore service.\n");
  277. struct GNUNET_MQ_MessageHandler handlers[] = {
  278. GNUNET_MQ_hd_var_size (result_code,
  279. GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_CODE,
  280. struct OperationResult,
  281. h),
  282. GNUNET_MQ_hd_fixed_size (result_counters,
  283. GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS,
  284. struct CountersResult,
  285. h),
  286. GNUNET_MQ_hd_var_size (result_fragment,
  287. GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_FRAGMENT,
  288. struct FragmentResult,
  289. h),
  290. GNUNET_MQ_hd_var_size (result_state,
  291. GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_STATE,
  292. struct StateResult,
  293. h),
  294. GNUNET_MQ_handler_end ()
  295. };
  296. h->op = GNUNET_OP_create ();
  297. GNUNET_assert (NULL == h->mq);
  298. h->mq = GNUNET_CLIENT_connect (h->cfg, "psycstore",
  299. handlers, disconnected, h);
  300. GNUNET_assert (NULL != h->mq);
  301. }
  302. /**
  303. * Try again to connect to the PSYCstore service.
  304. *
  305. * @param cls Handle to the PSYCstore service.
  306. */
  307. static void
  308. reconnect (void *cls)
  309. {
  310. struct GNUNET_PSYCSTORE_Handle *h = cls;
  311. h->reconnect_task = NULL;
  312. do_connect (cls);
  313. }
  314. /**
  315. * Connect to the PSYCstore service.
  316. *
  317. * @param cfg The configuration to use
  318. * @return Handle to use
  319. */
  320. struct GNUNET_PSYCSTORE_Handle *
  321. GNUNET_PSYCSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
  322. {
  323. struct GNUNET_PSYCSTORE_Handle *h
  324. = GNUNET_new (struct GNUNET_PSYCSTORE_Handle);
  325. h->cfg = cfg;
  326. h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS;
  327. do_connect (h);
  328. return h;
  329. }
  330. /**
  331. * Disconnect from PSYCstore service
  332. *
  333. * @param h Handle to destroy
  334. */
  335. void
  336. GNUNET_PSYCSTORE_disconnect (struct GNUNET_PSYCSTORE_Handle *h)
  337. {
  338. GNUNET_assert (NULL != h);
  339. if (h->reconnect_task != NULL)
  340. {
  341. GNUNET_SCHEDULER_cancel (h->reconnect_task);
  342. h->reconnect_task = NULL;
  343. }
  344. if (NULL != h->mq)
  345. {
  346. // FIXME: free data structures for pending operations
  347. GNUNET_MQ_destroy (h->mq);
  348. h->mq = NULL;
  349. }
  350. GNUNET_free (h);
  351. }
  352. /**
  353. * Message sent notification.
  354. *
  355. * Remove invalidated envelope pointer.
  356. */
  357. static void
  358. message_sent (void *cls)
  359. {
  360. struct GNUNET_PSYCSTORE_OperationHandle *op = cls;
  361. op->env = NULL;
  362. }
  363. /**
  364. * Create a new operation.
  365. */
  366. static struct GNUNET_PSYCSTORE_OperationHandle *
  367. op_create (struct GNUNET_PSYCSTORE_Handle *h,
  368. struct GNUNET_OP_Handle *hop,
  369. GNUNET_PSYCSTORE_ResultCallback result_cb,
  370. void *cls)
  371. {
  372. struct GNUNET_PSYCSTORE_OperationHandle *
  373. op = GNUNET_malloc (sizeof (*op));
  374. op->h = h;
  375. op->op_id = GNUNET_OP_add (hop,
  376. (GNUNET_ResultCallback) result_cb,
  377. cls, op);
  378. return op;
  379. }
  380. /**
  381. * Send a message associated with an operation.
  382. *
  383. * @param h
  384. * PSYCstore handle.
  385. * @param op
  386. * Operation handle.
  387. * @param env
  388. * Message envelope to send.
  389. * @param[out] op_id
  390. * Operation ID to write in network byte order. NULL if not needed.
  391. *
  392. * @return Operation handle.
  393. *
  394. */
  395. static struct GNUNET_PSYCSTORE_OperationHandle *
  396. op_send (struct GNUNET_PSYCSTORE_Handle *h,
  397. struct GNUNET_PSYCSTORE_OperationHandle *op,
  398. struct GNUNET_MQ_Envelope *env,
  399. uint64_t *op_id)
  400. {
  401. op->env = env;
  402. if (NULL != op_id)
  403. *op_id = GNUNET_htonll (op->op_id);
  404. GNUNET_MQ_notify_sent (env, message_sent, op);
  405. GNUNET_MQ_send (h->mq, env);
  406. return op;
  407. }
  408. /**
  409. * Cancel a PSYCstore operation. Note that the operation MAY still
  410. * be executed; this merely cancels the continuation; if the request
  411. * was already transmitted, the service may still choose to complete
  412. * the operation.
  413. *
  414. * @param op Operation to cancel.
  415. *
  416. * @return #GNUNET_YES if message was not sent yet and got discarded,
  417. * #GNUNET_NO if it was already sent, and only the callbacks got cancelled.
  418. */
  419. int
  420. GNUNET_PSYCSTORE_operation_cancel (struct GNUNET_PSYCSTORE_OperationHandle *op)
  421. {
  422. struct GNUNET_PSYCSTORE_Handle *h = op->h;
  423. int ret = GNUNET_NO;
  424. if (NULL != op->env)
  425. {
  426. GNUNET_MQ_send_cancel (op->env);
  427. ret = GNUNET_YES;
  428. }
  429. GNUNET_OP_remove (h->op, op->op_id);
  430. GNUNET_free (op);
  431. return ret;
  432. }
  433. /**
  434. * Store join/leave events for a PSYC channel in order to be able to answer
  435. * membership test queries later.
  436. *
  437. * @param h
  438. * Handle for the PSYCstore.
  439. * @param channel_key
  440. * The channel where the event happened.
  441. * @param slave_key
  442. * Public key of joining/leaving slave.
  443. * @param did_join
  444. * #GNUNET_YES on join, #GNUNET_NO on part.
  445. * @param announced_at
  446. * ID of the message that announced the membership change.
  447. * @param effective_since
  448. * Message ID this membership change is in effect since.
  449. * For joins it is <= announced_at, for parts it is always 0.
  450. * @param group_generation
  451. * In case of a part, the last group generation the slave has access to.
  452. * It has relevance when a larger message have fragments with different
  453. * group generations.
  454. * @param result_cb
  455. * Callback to call with the result of the storage operation.
  456. * @param cls
  457. * Closure for the callback.
  458. *
  459. * @return Operation handle that can be used to cancel the operation.
  460. */
  461. struct GNUNET_PSYCSTORE_OperationHandle *
  462. GNUNET_PSYCSTORE_membership_store (struct GNUNET_PSYCSTORE_Handle *h,
  463. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  464. const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
  465. int did_join,
  466. uint64_t announced_at,
  467. uint64_t effective_since,
  468. uint64_t group_generation,
  469. GNUNET_PSYCSTORE_ResultCallback result_cb,
  470. void *cls)
  471. {
  472. GNUNET_assert (NULL != h);
  473. GNUNET_assert (NULL != channel_key);
  474. GNUNET_assert (NULL != slave_key);
  475. GNUNET_assert (GNUNET_YES == did_join || GNUNET_NO == did_join);
  476. GNUNET_assert (did_join
  477. ? effective_since <= announced_at
  478. : effective_since == 0);
  479. struct MembershipStoreRequest *req;
  480. struct GNUNET_MQ_Envelope *
  481. env = GNUNET_MQ_msg (req, GNUNET_MESSAGE_TYPE_PSYCSTORE_MEMBERSHIP_STORE);
  482. req->channel_key = *channel_key;
  483. req->slave_key = *slave_key;
  484. req->did_join = did_join;
  485. req->announced_at = GNUNET_htonll (announced_at);
  486. req->effective_since = GNUNET_htonll (effective_since);
  487. req->group_generation = GNUNET_htonll (group_generation);
  488. return
  489. op_send (h, op_create (h, h->op, result_cb, cls),
  490. env, &req->op_id);
  491. }
  492. /**
  493. * Test if a member was admitted to the channel at the given message ID.
  494. *
  495. * This is useful when relaying and replaying messages to check if a particular
  496. * slave has access to the message fragment with a given group generation. It
  497. * is also used when handling join requests to determine whether the slave is
  498. * currently admitted to the channel.
  499. *
  500. * @param h
  501. * Handle for the PSYCstore.
  502. * @param channel_key
  503. * The channel we are interested in.
  504. * @param slave_key
  505. * Public key of slave whose membership to check.
  506. * @param message_id
  507. * Message ID for which to do the membership test.
  508. * @param group_generation
  509. * Group generation of the fragment of the message to test.
  510. * It has relevance if the message consists of multiple fragments with
  511. * different group generations.
  512. * @param result_cb
  513. * Callback to call with the test result.
  514. * @param cls
  515. * Closure for the callback.
  516. *
  517. * @return Operation handle that can be used to cancel the operation.
  518. */
  519. struct GNUNET_PSYCSTORE_OperationHandle *
  520. GNUNET_PSYCSTORE_membership_test (struct GNUNET_PSYCSTORE_Handle *h,
  521. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  522. const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
  523. uint64_t message_id,
  524. uint64_t group_generation,
  525. GNUNET_PSYCSTORE_ResultCallback result_cb,
  526. void *cls)
  527. {
  528. struct MembershipTestRequest *req;
  529. struct GNUNET_MQ_Envelope *
  530. env = GNUNET_MQ_msg (req, GNUNET_MESSAGE_TYPE_PSYCSTORE_MEMBERSHIP_TEST);
  531. req->channel_key = *channel_key;
  532. req->slave_key = *slave_key;
  533. req->message_id = GNUNET_htonll (message_id);
  534. req->group_generation = GNUNET_htonll (group_generation);
  535. return
  536. op_send (h, op_create (h, h->op, result_cb, cls),
  537. env, &req->op_id);
  538. }
  539. /**
  540. * Store a message fragment sent to a channel.
  541. *
  542. * @param h Handle for the PSYCstore.
  543. * @param channel_key The channel the message belongs to.
  544. * @param message Message to store.
  545. * @param psycstore_flags Flags indicating whether the PSYC message contains
  546. * state modifiers.
  547. * @param result_cb Callback to call with the result of the operation.
  548. * @param cls Closure for the callback.
  549. *
  550. * @return Handle that can be used to cancel the operation.
  551. */
  552. struct GNUNET_PSYCSTORE_OperationHandle *
  553. GNUNET_PSYCSTORE_fragment_store (struct GNUNET_PSYCSTORE_Handle *h,
  554. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  555. const struct GNUNET_MULTICAST_MessageHeader *msg,
  556. enum GNUNET_PSYCSTORE_MessageFlags psycstore_flags,
  557. GNUNET_PSYCSTORE_ResultCallback result_cb,
  558. void *cls)
  559. {
  560. uint16_t size = ntohs (msg->header.size);
  561. struct FragmentStoreRequest *req;
  562. struct GNUNET_MQ_Envelope *
  563. env = GNUNET_MQ_msg_extra (req, size,
  564. GNUNET_MESSAGE_TYPE_PSYCSTORE_FRAGMENT_STORE);
  565. req->channel_key = *channel_key;
  566. req->psycstore_flags = htonl (psycstore_flags);
  567. GNUNET_memcpy (&req[1], msg, size);
  568. return
  569. op_send (h, op_create (h, h->op, result_cb, cls),
  570. env, &req->op_id);
  571. }
  572. /**
  573. * Retrieve message fragments by fragment ID range.
  574. *
  575. * @param h
  576. * Handle for the PSYCstore.
  577. * @param channel_key
  578. * The channel we are interested in.
  579. * @param slave_key
  580. * The slave requesting the fragment. If not NULL, a membership test is
  581. * performed first and the fragment is only returned if the slave has
  582. * access to it.
  583. * @param first_fragment_id
  584. * First fragment ID to retrieve.
  585. * Use 0 to get the latest message fragment.
  586. * @param last_fragment_id
  587. * Last consecutive fragment ID to retrieve.
  588. * Use 0 to get the latest message fragment.
  589. * @param fragment_limit
  590. * Maximum number of fragments to retrieve.
  591. * @param fragment_cb
  592. * Callback to call with the retrieved fragments.
  593. * @param result_cb
  594. * Callback to call with the result of the operation.
  595. * @param cls
  596. * Closure for the callbacks.
  597. *
  598. * @return Handle that can be used to cancel the operation.
  599. */
  600. struct GNUNET_PSYCSTORE_OperationHandle *
  601. GNUNET_PSYCSTORE_fragment_get (struct GNUNET_PSYCSTORE_Handle *h,
  602. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  603. const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
  604. uint64_t first_fragment_id,
  605. uint64_t last_fragment_id,
  606. GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
  607. GNUNET_PSYCSTORE_ResultCallback result_cb,
  608. void *cls)
  609. {
  610. struct FragmentGetRequest *req;
  611. struct GNUNET_MQ_Envelope *
  612. env = GNUNET_MQ_msg (req, GNUNET_MESSAGE_TYPE_PSYCSTORE_FRAGMENT_GET);
  613. req->channel_key = *channel_key;
  614. req->first_fragment_id = GNUNET_htonll (first_fragment_id);
  615. req->last_fragment_id = GNUNET_htonll (last_fragment_id);
  616. if (NULL != slave_key)
  617. {
  618. req->slave_key = *slave_key;
  619. req->do_membership_test = GNUNET_YES;
  620. }
  621. struct GNUNET_PSYCSTORE_OperationHandle *
  622. op = op_create (h, h->op, result_cb, cls);
  623. op->fragment_cb = fragment_cb;
  624. op->cls = cls;
  625. return op_send (h, op, env, &req->op_id);
  626. }
  627. /**
  628. * Retrieve latest message fragments.
  629. *
  630. * @param h
  631. * Handle for the PSYCstore.
  632. * @param channel_key
  633. * The channel we are interested in.
  634. * @param slave_key
  635. * The slave requesting the fragment. If not NULL, a membership test is
  636. * performed first and the fragment is only returned if the slave has
  637. * access to it.
  638. * @param first_fragment_id
  639. * First fragment ID to retrieve.
  640. * Use 0 to get the latest message fragment.
  641. * @param last_fragment_id
  642. * Last consecutive fragment ID to retrieve.
  643. * Use 0 to get the latest message fragment.
  644. * @param fragment_limit
  645. * Maximum number of fragments to retrieve.
  646. * @param fragment_cb
  647. * Callback to call with the retrieved fragments.
  648. * @param result_cb
  649. * Callback to call with the result of the operation.
  650. * @param cls
  651. * Closure for the callbacks.
  652. *
  653. * @return Handle that can be used to cancel the operation.
  654. */
  655. struct GNUNET_PSYCSTORE_OperationHandle *
  656. GNUNET_PSYCSTORE_fragment_get_latest (struct GNUNET_PSYCSTORE_Handle *h,
  657. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  658. const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
  659. uint64_t fragment_limit,
  660. GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
  661. GNUNET_PSYCSTORE_ResultCallback result_cb,
  662. void *cls)
  663. {
  664. struct FragmentGetRequest *req;
  665. struct GNUNET_MQ_Envelope *
  666. env = GNUNET_MQ_msg (req, GNUNET_MESSAGE_TYPE_PSYCSTORE_FRAGMENT_GET);
  667. req->channel_key = *channel_key;
  668. req->fragment_limit = GNUNET_ntohll (fragment_limit);
  669. if (NULL != slave_key)
  670. {
  671. req->slave_key = *slave_key;
  672. req->do_membership_test = GNUNET_YES;
  673. }
  674. struct GNUNET_PSYCSTORE_OperationHandle *
  675. op = op_create (h, h->op, result_cb, cls);
  676. op->fragment_cb = fragment_cb;
  677. op->cls = cls;
  678. return op_send (h, op, env, &req->op_id);
  679. }
  680. /**
  681. * Retrieve all fragments of messages in a message ID range.
  682. *
  683. * @param h
  684. * Handle for the PSYCstore.
  685. * @param channel_key
  686. * The channel we are interested in.
  687. * @param slave_key
  688. * The slave requesting the message.
  689. * If not NULL, a membership test is performed first
  690. * and the message is only returned if the slave has access to it.
  691. * @param first_message_id
  692. * First message ID to retrieve.
  693. * @param last_message_id
  694. * Last consecutive message ID to retrieve.
  695. * @param fragment_limit
  696. * Maximum number of fragments to retrieve.
  697. * @param method_prefix
  698. * Retrieve only messages with a matching method prefix.
  699. * @todo Implement method_prefix query.
  700. * @param fragment_cb
  701. * Callback to call with the retrieved fragments.
  702. * @param result_cb
  703. * Callback to call with the result of the operation.
  704. * @param cls
  705. * Closure for the callbacks.
  706. *
  707. * @return Handle that can be used to cancel the operation.
  708. */
  709. struct GNUNET_PSYCSTORE_OperationHandle *
  710. GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h,
  711. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  712. const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
  713. uint64_t first_message_id,
  714. uint64_t last_message_id,
  715. uint64_t fragment_limit,
  716. const char *method_prefix,
  717. GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
  718. GNUNET_PSYCSTORE_ResultCallback result_cb,
  719. void *cls)
  720. {
  721. struct MessageGetRequest *req;
  722. if (NULL == method_prefix)
  723. method_prefix = "";
  724. uint16_t method_size = strnlen (method_prefix,
  725. GNUNET_MAX_MESSAGE_SIZE
  726. - sizeof (*req)) + 1;
  727. struct GNUNET_MQ_Envelope *
  728. env = GNUNET_MQ_msg_extra (req, method_size,
  729. GNUNET_MESSAGE_TYPE_PSYCSTORE_MESSAGE_GET);
  730. req->channel_key = *channel_key;
  731. req->first_message_id = GNUNET_htonll (first_message_id);
  732. req->last_message_id = GNUNET_htonll (last_message_id);
  733. req->fragment_limit = GNUNET_htonll (fragment_limit);
  734. if (NULL != slave_key)
  735. {
  736. req->slave_key = *slave_key;
  737. req->do_membership_test = GNUNET_YES;
  738. }
  739. GNUNET_memcpy (&req[1], method_prefix, method_size);
  740. ((char *) &req[1])[method_size - 1] = '\0';
  741. struct GNUNET_PSYCSTORE_OperationHandle *
  742. op = op_create (h, h->op, result_cb, cls);
  743. op->fragment_cb = fragment_cb;
  744. op->cls = cls;
  745. return op_send (h, op, env, &req->op_id);
  746. }
  747. /**
  748. * Retrieve all fragments of the latest messages.
  749. *
  750. * @param h
  751. * Handle for the PSYCstore.
  752. * @param channel_key
  753. * The channel we are interested in.
  754. * @param slave_key
  755. * The slave requesting the message.
  756. * If not NULL, a membership test is performed first
  757. * and the message is only returned if the slave has access to it.
  758. * @param message_limit
  759. * Maximum number of messages to retrieve.
  760. * @param method_prefix
  761. * Retrieve only messages with a matching method prefix.
  762. * @todo Implement method_prefix query.
  763. * @param fragment_cb
  764. * Callback to call with the retrieved fragments.
  765. * @param result_cb
  766. * Callback to call with the result of the operation.
  767. * @param cls
  768. * Closure for the callbacks.
  769. *
  770. * @return Handle that can be used to cancel the operation.
  771. */
  772. struct GNUNET_PSYCSTORE_OperationHandle *
  773. GNUNET_PSYCSTORE_message_get_latest (struct GNUNET_PSYCSTORE_Handle *h,
  774. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  775. const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
  776. uint64_t message_limit,
  777. const char *method_prefix,
  778. GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
  779. GNUNET_PSYCSTORE_ResultCallback result_cb,
  780. void *cls)
  781. {
  782. struct MessageGetRequest *req;
  783. if (NULL == method_prefix)
  784. method_prefix = "";
  785. uint16_t method_size = strnlen (method_prefix,
  786. GNUNET_MAX_MESSAGE_SIZE
  787. - sizeof (*req)) + 1;
  788. GNUNET_assert ('\0' == method_prefix[method_size - 1]);
  789. struct GNUNET_MQ_Envelope *
  790. env = GNUNET_MQ_msg_extra (req, method_size,
  791. GNUNET_MESSAGE_TYPE_PSYCSTORE_MESSAGE_GET);
  792. req->channel_key = *channel_key;
  793. req->message_limit = GNUNET_ntohll (message_limit);
  794. if (NULL != slave_key)
  795. {
  796. req->slave_key = *slave_key;
  797. req->do_membership_test = GNUNET_YES;
  798. }
  799. GNUNET_memcpy (&req[1], method_prefix, method_size);
  800. struct GNUNET_PSYCSTORE_OperationHandle *
  801. op = op_create (h, h->op, result_cb, cls);
  802. op->fragment_cb = fragment_cb;
  803. op->cls = cls;
  804. return op_send (h, op, env, &req->op_id);
  805. }
  806. /**
  807. * Retrieve a fragment of message specified by its message ID and fragment
  808. * offset.
  809. *
  810. * @param h
  811. * Handle for the PSYCstore.
  812. * @param channel_key
  813. * The channel we are interested in.
  814. * @param slave_key
  815. * The slave requesting the message fragment. If not NULL, a membership
  816. * test is performed first and the message fragment is only returned
  817. * if the slave has access to it.
  818. * @param message_id
  819. * Message ID to retrieve. Use 0 to get the latest message.
  820. * @param fragment_offset
  821. * Offset of the fragment to retrieve.
  822. * @param fragment_cb
  823. * Callback to call with the retrieved fragments.
  824. * @param result_cb
  825. * Callback to call with the result of the operation.
  826. * @param cls
  827. * Closure for the callbacks.
  828. *
  829. * @return Handle that can be used to cancel the operation.
  830. */
  831. struct GNUNET_PSYCSTORE_OperationHandle *
  832. GNUNET_PSYCSTORE_message_get_fragment (struct GNUNET_PSYCSTORE_Handle *h,
  833. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  834. const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
  835. uint64_t message_id,
  836. uint64_t fragment_offset,
  837. GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
  838. GNUNET_PSYCSTORE_ResultCallback result_cb,
  839. void *cls)
  840. {
  841. struct MessageGetFragmentRequest *req;
  842. struct GNUNET_MQ_Envelope *
  843. env = GNUNET_MQ_msg (req, GNUNET_MESSAGE_TYPE_PSYCSTORE_MESSAGE_GET_FRAGMENT);
  844. req->channel_key = *channel_key;
  845. req->message_id = GNUNET_htonll (message_id);
  846. req->fragment_offset = GNUNET_htonll (fragment_offset);
  847. if (NULL != slave_key)
  848. {
  849. req->slave_key = *slave_key;
  850. req->do_membership_test = GNUNET_YES;
  851. }
  852. struct GNUNET_PSYCSTORE_OperationHandle *
  853. op = op_create (h, h->op, result_cb, cls);
  854. op->fragment_cb = fragment_cb;
  855. op->cls = cls;
  856. return op_send (h, op, env, &req->op_id);
  857. }
  858. /**
  859. * Retrieve latest values of counters for a channel master.
  860. *
  861. * The current value of counters are needed when a channel master is restarted,
  862. * so that it can continue incrementing the counters from their last value.
  863. *
  864. * @param h
  865. * Handle for the PSYCstore.
  866. * @param channel_key
  867. * Public key that identifies the channel.
  868. * @param ccb
  869. * Callback to call with the result.
  870. * @param ccb_cls
  871. * Closure for the @a ccb callback.
  872. *
  873. * @return Handle that can be used to cancel the operation.
  874. */
  875. struct GNUNET_PSYCSTORE_OperationHandle *
  876. GNUNET_PSYCSTORE_counters_get (struct GNUNET_PSYCSTORE_Handle *h,
  877. struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  878. GNUNET_PSYCSTORE_CountersCallback counters_cb,
  879. void *cls)
  880. {
  881. struct OperationRequest *req;
  882. struct GNUNET_MQ_Envelope *
  883. env = GNUNET_MQ_msg (req, GNUNET_MESSAGE_TYPE_PSYCSTORE_COUNTERS_GET);
  884. req->channel_key = *channel_key;
  885. struct GNUNET_PSYCSTORE_OperationHandle *
  886. op = op_create (h, h->op, NULL, NULL);
  887. op->counters_cb = counters_cb;
  888. op->cls = cls;
  889. return op_send (h, op, env, &req->op_id);
  890. }
  891. /**
  892. * Apply modifiers of a message to the current channel state.
  893. *
  894. * An error is returned if there are missing messages containing state
  895. * operations before the current one.
  896. *
  897. * @param h
  898. * Handle for the PSYCstore.
  899. * @param channel_key
  900. * The channel we are interested in.
  901. * @param message_id
  902. * ID of the message that contains the @a modifiers.
  903. * @param state_delta
  904. * Value of the _state_delta PSYC header variable of the message.
  905. * @param result_cb
  906. * Callback to call with the result of the operation.
  907. * @param cls
  908. * Closure for @a result_cb.
  909. *
  910. * @return Handle that can be used to cancel the operation.
  911. */
  912. struct GNUNET_PSYCSTORE_OperationHandle *
  913. GNUNET_PSYCSTORE_state_modify (struct GNUNET_PSYCSTORE_Handle *h,
  914. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  915. uint64_t message_id,
  916. uint64_t state_delta,
  917. GNUNET_PSYCSTORE_ResultCallback result_cb,
  918. void *cls)
  919. {
  920. struct StateModifyRequest *req;
  921. struct GNUNET_MQ_Envelope *
  922. env = GNUNET_MQ_msg (req, GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_MODIFY);
  923. req->channel_key = *channel_key;
  924. req->message_id = GNUNET_htonll (message_id);
  925. req->state_delta = GNUNET_htonll (state_delta);
  926. return op_send (h, op_create (h, h->op, result_cb, cls),
  927. env, &req->op_id);
  928. }
  929. struct StateSyncClosure
  930. {
  931. GNUNET_PSYCSTORE_ResultCallback result_cb;
  932. void *cls;
  933. uint8_t last;
  934. };
  935. static void
  936. state_sync_result (void *cls, int64_t result,
  937. const char *err_msg, uint16_t err_msg_size)
  938. {
  939. struct StateSyncClosure *ssc = cls;
  940. if (GNUNET_OK != result || ssc->last)
  941. ssc->result_cb (ssc->cls, result, err_msg, err_msg_size);
  942. GNUNET_free (ssc);
  943. }
  944. /**
  945. * Store synchronized state.
  946. *
  947. * @param h
  948. * Handle for the PSYCstore.
  949. * @param channel_key
  950. * The channel we are interested in.
  951. * @param max_state_message_id
  952. * ID of the last stateful message before @a state_hash_message_id.
  953. * @param state_hash_message_id
  954. * ID of the message that contains the state_hash PSYC header variable.
  955. * @param modifier_count
  956. * Number of elements in the @a modifiers array.
  957. * @param modifiers
  958. * Full state to store.
  959. * @param result_cb
  960. * Callback to call with the result of the operation.
  961. * @param cls
  962. * Closure for the callback.
  963. *
  964. * @return Handle that can be used to cancel the operation.
  965. */
  966. struct GNUNET_PSYCSTORE_OperationHandle *
  967. GNUNET_PSYCSTORE_state_sync (struct GNUNET_PSYCSTORE_Handle *h,
  968. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  969. uint64_t max_state_message_id,
  970. uint64_t state_hash_message_id,
  971. size_t modifier_count,
  972. const struct GNUNET_PSYC_Modifier *modifiers,
  973. GNUNET_PSYCSTORE_ResultCallback result_cb,
  974. void *cls)
  975. {
  976. struct GNUNET_PSYCSTORE_OperationHandle *op = NULL;
  977. size_t i;
  978. for (i = 0; i < modifier_count; i++) {
  979. struct StateSyncRequest *req;
  980. uint16_t name_size = strlen (modifiers[i].name) + 1;
  981. struct GNUNET_MQ_Envelope *
  982. env = GNUNET_MQ_msg_extra (req,
  983. sizeof (*req) + name_size + modifiers[i].value_size,
  984. GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_SYNC);
  985. req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_SYNC);
  986. req->header.size = htons (sizeof (*req) + name_size
  987. + modifiers[i].value_size);
  988. req->channel_key = *channel_key;
  989. req->max_state_message_id = GNUNET_htonll (max_state_message_id);
  990. req->state_hash_message_id = GNUNET_htonll (state_hash_message_id);
  991. req->name_size = htons (name_size);
  992. req->flags
  993. = (0 == i)
  994. ? STATE_OP_FIRST
  995. : (modifier_count - 1 == i)
  996. ? STATE_OP_LAST
  997. : 0;
  998. GNUNET_memcpy (&req[1], modifiers[i].name, name_size);
  999. GNUNET_memcpy ((char *) &req[1] + name_size, modifiers[i].value, modifiers[i].value_size);
  1000. struct StateSyncClosure *ssc = GNUNET_malloc (sizeof (*ssc));
  1001. ssc->last = (req->flags & STATE_OP_LAST);
  1002. ssc->result_cb = result_cb;
  1003. ssc->cls = cls;
  1004. op_send (h, op_create (h, h->op, state_sync_result, ssc),
  1005. env, &req->op_id);
  1006. }
  1007. // FIXME: only one operation is returned,
  1008. // add pointers to other operations and make all cancellable.
  1009. return op;
  1010. }
  1011. /**
  1012. * Reset the state of a channel.
  1013. *
  1014. * Delete all state variables stored for the given channel.
  1015. *
  1016. * @param h
  1017. * Handle for the PSYCstore.
  1018. * @param channel_key
  1019. * The channel we are interested in.
  1020. * @param result_cb
  1021. * Callback to call with the result of the operation.
  1022. * @param cls
  1023. * Closure for the callback.
  1024. *
  1025. * @return Handle that can be used to cancel the operation.
  1026. */
  1027. struct GNUNET_PSYCSTORE_OperationHandle *
  1028. GNUNET_PSYCSTORE_state_reset (struct GNUNET_PSYCSTORE_Handle *h,
  1029. const struct GNUNET_CRYPTO_EddsaPublicKey
  1030. *channel_key,
  1031. GNUNET_PSYCSTORE_ResultCallback result_cb,
  1032. void *cls)
  1033. {
  1034. struct OperationRequest *req;
  1035. struct GNUNET_MQ_Envelope *
  1036. env = GNUNET_MQ_msg (req, GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_RESET);
  1037. req->channel_key = *channel_key;
  1038. return
  1039. op_send (h, op_create (h, h->op, result_cb, cls),
  1040. env, &req->op_id);
  1041. }
  1042. /**
  1043. * Update signed values of state variables in the state store.
  1044. *
  1045. * @param h
  1046. * Handle for the PSYCstore.
  1047. * @param channel_key
  1048. * The channel we are interested in.
  1049. * @param message_id
  1050. * Message ID that contained the state @a hash.
  1051. * @param hash
  1052. * Hash of the serialized full state.
  1053. * @param result_cb
  1054. * Callback to call with the result of the operation.
  1055. * @param cls
  1056. * Closure for the callback.
  1057. */
  1058. struct GNUNET_PSYCSTORE_OperationHandle *
  1059. GNUNET_PSYCSTORE_state_hash_update (struct GNUNET_PSYCSTORE_Handle *h,
  1060. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  1061. uint64_t message_id,
  1062. const struct GNUNET_HashCode *hash,
  1063. GNUNET_PSYCSTORE_ResultCallback result_cb,
  1064. void *cls)
  1065. {
  1066. struct StateHashUpdateRequest *req;
  1067. struct GNUNET_MQ_Envelope *
  1068. env = GNUNET_MQ_msg (req, GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_HASH_UPDATE);
  1069. req->channel_key = *channel_key;
  1070. req->hash = *hash;
  1071. return
  1072. op_send (h, op_create (h, h->op, result_cb, cls),
  1073. env, &req->op_id);
  1074. }
  1075. /**
  1076. * Retrieve the best matching state variable.
  1077. *
  1078. * @param h
  1079. * Handle for the PSYCstore.
  1080. * @param channel_key
  1081. * The channel we are interested in.
  1082. * @param name
  1083. * Name of variable to match, the returned variable might be less specific.
  1084. * @param state_cb
  1085. * Callback to return the matching state variable.
  1086. * @param result_cb
  1087. * Callback to call with the result of the operation.
  1088. * @param cls
  1089. * Closure for the callbacks.
  1090. *
  1091. * @return Handle that can be used to cancel the operation.
  1092. */
  1093. struct GNUNET_PSYCSTORE_OperationHandle *
  1094. GNUNET_PSYCSTORE_state_get (struct GNUNET_PSYCSTORE_Handle *h,
  1095. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  1096. const char *name,
  1097. GNUNET_PSYCSTORE_StateCallback state_cb,
  1098. GNUNET_PSYCSTORE_ResultCallback result_cb,
  1099. void *cls)
  1100. {
  1101. size_t name_size = strlen (name) + 1;
  1102. struct OperationRequest *req;
  1103. struct GNUNET_MQ_Envelope *
  1104. env = GNUNET_MQ_msg_extra (req, name_size,
  1105. GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_GET);
  1106. req->channel_key = *channel_key;
  1107. GNUNET_memcpy (&req[1], name, name_size);
  1108. struct GNUNET_PSYCSTORE_OperationHandle *
  1109. op = op_create (h, h->op, result_cb, cls);
  1110. op->state_cb = state_cb;
  1111. op->cls = cls;
  1112. return op_send (h, op, env, &req->op_id);
  1113. }
  1114. /**
  1115. * Retrieve all state variables for a channel with the given prefix.
  1116. *
  1117. * @param h
  1118. * Handle for the PSYCstore.
  1119. * @param channel_key
  1120. * The channel we are interested in.
  1121. * @param name_prefix
  1122. * Prefix of state variable names to match.
  1123. * @param state_cb
  1124. * Callback to return matching state variables.
  1125. * @param result_cb
  1126. * Callback to call with the result of the operation.
  1127. * @param cls
  1128. * Closure for the callbacks.
  1129. *
  1130. * @return Handle that can be used to cancel the operation.
  1131. */
  1132. struct GNUNET_PSYCSTORE_OperationHandle *
  1133. GNUNET_PSYCSTORE_state_get_prefix (struct GNUNET_PSYCSTORE_Handle *h,
  1134. const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
  1135. const char *name_prefix,
  1136. GNUNET_PSYCSTORE_StateCallback state_cb,
  1137. GNUNET_PSYCSTORE_ResultCallback result_cb,
  1138. void *cls)
  1139. {
  1140. size_t name_size = strlen (name_prefix) + 1;
  1141. struct OperationRequest *req;
  1142. struct GNUNET_MQ_Envelope *
  1143. env = GNUNET_MQ_msg_extra (req, name_size,
  1144. GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_GET_PREFIX);
  1145. req->channel_key = *channel_key;
  1146. GNUNET_memcpy (&req[1], name_prefix, name_size);
  1147. struct GNUNET_PSYCSTORE_OperationHandle *
  1148. op = op_create (h, h->op, result_cb, cls);
  1149. op->state_cb = state_cb;
  1150. op->cls = cls;
  1151. return op_send (h, op, env, &req->op_id);
  1152. }
  1153. /* end of psycstore_api.c */