rehash-api.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. /* rehash --- a decentralised hash<->hash store
  2. Copyright © 2020 Maxime Devos <maxime.devos@student.kuleuven.be>
  3. This file is part of rehash.
  4. rehash is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or (at
  7. your option) any later version.
  8. rehash 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
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with rehash. If not, see <http://www.gnu.org/licenses/>. */
  14. /**
  15. * @brief Client-side API to the rehash service
  16. * @author Maxime Devos
  17. */
  18. #include "platform.h"
  19. #include <stdio.h>
  20. #include <gnunet/gnunet_service_lib.h>
  21. #include <gnunet/gnunet_dht_service.h>
  22. #include <gnunet/gnunet_mq_lib.h>
  23. #include "rehash_service.h"
  24. #include "extra_gnunet_protocols.h"
  25. #include "rehash.h"
  26. /**
  27. * Type of operation in progress
  28. */
  29. enum ContextType
  30. {
  31. /* to be inserted into the queue
  32. (not visible to the API user) */
  33. CONTEXT_QUERY_QUEUE_ME,
  34. /* to be sent to rehash service */
  35. CONTEXT_QUERY_QUEUED,
  36. /* sent to rehash service, awaiting replies */
  37. CONTEXT_QUERY_SENT,
  38. /* to be inserted into the queue
  39. (not visible to the API user) */
  40. CONTEXT_PUT_QUEUE_ME,
  41. /* does not have request id,
  42. is (or is about to be) in the store queue */
  43. CONTEXT_PUT_QUEUED,
  44. /* has a request_id, is not in the store queue */
  45. CONTEXT_PUT_SENT,
  46. /* the rehash service considers the insertion
  47. to be completed! (Not visible to the API
  48. user, as the context will be freed immediately
  49. with REHASH_store_abort) */
  50. CONTEXT_PUT_COMPLETED,
  51. /* the context has been freed (e.g. by abortion).
  52. Should never be encountered in practice. */
  53. CONTEXT_PUT_FREED,
  54. };
  55. struct REHASH_QueryContext
  56. {
  57. enum ContextType type;
  58. /* if CONTEXT_QUERY_SENT */
  59. uint32_t request_id;
  60. /* always */
  61. REHASH_QueryContinuation cont;
  62. /* always (NULL can be ok) */
  63. void *cls;
  64. /* if CONTEXT_QUERY_QUEUED */
  65. struct REHASH_QueryContext *prev;
  66. /* if CONTEXT_QUERY_QUEUED */
  67. struct REHASH_QueryContext *next;
  68. /* if CONTEXT_QUERY_QUEUE_ME or CONTEXT_QUERY_QUEUED*/
  69. struct GNUNET_MQ_Envelope *ev;
  70. /* if CONTEXT_QUERY_QUEUE_ME or CONTEXT_QUERY_QUEUED */
  71. struct REHASH_GetMessage *msg;
  72. /* always */
  73. struct REHASH_Handle *h;
  74. };
  75. struct REHASH_StoreContext
  76. {
  77. enum ContextType type;
  78. /* if CONTEXT_PUT_SENT */
  79. uint32_t request_id;
  80. /* always */
  81. REHASH_StoreContinuation cont;
  82. /* always */
  83. void *cls;
  84. /* if CONTEXT_PUT_QUEUED */
  85. struct REHASH_StoreContext *prev;
  86. /* if CONTEXT_PUT_QUEUED */
  87. struct REHASH_StoreContext *next;
  88. /* if CONTEXT_PUT_QUEUE_ME or CONTEXT_PUT_QUEUED */
  89. struct GNUNET_MQ_Envelope *ev;
  90. /* if CONTEXT_PUT_QUEUE_ME or CONTEXT_PUT_QUEUED */
  91. struct REHASH_PutMessage *msg;
  92. /* always */
  93. struct REHASH_Handle *h;
  94. };
  95. struct REHASH_Handle
  96. {
  97. const struct GNUNET_CONFIGURATION_Handle *cfg;
  98. struct GNUNET_MQ_Handle *mq;
  99. /* FIXME: GNUNET_MQ_assoc_add panics on request_id wrap-around */
  100. /* Linked list of queries not yet sent to the rehash service,
  101. in need of a request_id (CONTEXT_QUERY_QUEUED) */
  102. struct REHASH_QueryContext *query_queue_head;
  103. struct REHASH_QueryContext *query_queue_tail;
  104. /* Likewise (CONTEXT_PUT_QUEUED) */
  105. struct REHASH_StoreContext *store_queue_head;
  106. struct REHASH_StoreContext *store_queue_tail;
  107. /**
  108. * Exponential back-off for trying to reconnect.
  109. */
  110. struct GNUNET_TIME_Relative retry_time;
  111. /*
  112. * Task for automatically reconnecting.
  113. * NULL if no such task is scheduled.
  114. */
  115. struct GNUNET_SCHEDULER_Task *reconnect_task;
  116. };
  117. static void
  118. process_store_queue (struct REHASH_Handle *h);
  119. static void
  120. process_query_queue (struct REHASH_Handle *h);
  121. static void
  122. retry_connect_repeatedly (void *cls);
  123. static int
  124. check_client_result(void *cls, const struct REHASH_ResultMessage *msg)
  125. {
  126. if (ntohl(msg->output_length) == ntohs(msg->header.size) - sizeof(*msg))
  127. return GNUNET_OK;
  128. else
  129. return GNUNET_SYSERR;
  130. };
  131. static void
  132. handle_client_result(void *cls, const struct REHASH_ResultMessage *msg)
  133. {
  134. /* TODO call callbacks */
  135. GNUNET_assert (0);
  136. };
  137. static void
  138. handle_put_done (void *cls, const struct REHASH_PutStatusMessage *msg)
  139. {
  140. struct REHASH_Handle *h;
  141. struct REHASH_StoreContext *ctx;
  142. REHASH_StoreContinuation cont;
  143. void *cont_cls;
  144. void *put_cls;
  145. uint32_t flags;
  146. flags = ntohl(msg->flags);
  147. /* Detect unsupported required flags.
  148. TODO don't abort. */
  149. GNUNET_assert (0 == ((flags & 0xffff) & ~(REHASH_PUT_COMPLETED)));
  150. /* flags > 0xffff don't have to be recognised. */
  151. if (! (flags & REHASH_PUT_COMPLETED))
  152. /* nothing interesting happened */
  153. return;
  154. h = cls;
  155. ctx = GNUNET_MQ_assoc_get (h->mq, msg->request_id);
  156. /* TODO handle this case gracefully */
  157. GNUNET_assert (ctx != NULL);
  158. /* TODO strictly speaking this acces can be a strict-aliasing
  159. violation */
  160. GNUNET_assert (ctx->type == CONTEXT_PUT_SENT);
  161. cont = ctx->cont;
  162. cont_cls = ctx->cls;
  163. /* First free the structure, then call the callback.
  164. That way misuse of a completed query in the callback
  165. will be caught with segfaults (probabilistically) */
  166. ctx->type = CONTEXT_PUT_COMPLETED;
  167. REHASH_store_abort (ctx);
  168. cont (cont_cls);
  169. }
  170. static void
  171. mq_error_handler (void *h, enum GNUNET_MQ_Error e)
  172. {
  173. GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
  174. "Connection to rehash service lost. Trying to reconnect\n");
  175. struct REHASH_Handle *handle = h;
  176. struct GNUNET_MQ_Handle *mq = handle->mq;
  177. /* FIXME investigate why this happens */
  178. GNUNET_assert (e == GNUNET_MQ_ERROR_READ);
  179. /* FIXME handle other cases as well */
  180. GNUNET_assert (handle->reconnect_task == NULL);
  181. handle->mq = NULL;
  182. GNUNET_MQ_destroy (mq);
  183. retry_connect_repeatedly (handle);
  184. }
  185. int
  186. REHASH_connected (struct REHASH_Handle *h)
  187. {
  188. GNUNET_assert (h != NULL);
  189. if (h->mq != NULL)
  190. return GNUNET_YES;
  191. return GNUNET_NO;
  192. }
  193. /**
  194. * Call when connected successfully
  195. * to handle backlog due to an offline rehash service.
  196. */
  197. static void
  198. when_successfully_connected (struct REHASH_Handle *handle)
  199. {
  200. struct GNUNET_SCHEDULER_Task *reconnect_task;
  201. /* Handle backlog */
  202. /* FIXME stores and queries will need to be sent again */
  203. process_query_queue (handle);
  204. process_store_queue (handle);
  205. handle->retry_time = GNUNET_TIME_relative_get_zero_ ();
  206. if (reconnect_task = handle->reconnect_task) {
  207. handle->reconnect_task = NULL;
  208. GNUNET_SCHEDULER_cancel (reconnect_task);
  209. }
  210. }
  211. /**
  212. * Try to connect to the rehash service.
  213. * If successful, cancel the reconnect_task (if any)
  214. * if any and perform backlog.
  215. */
  216. static int
  217. try_connect (struct REHASH_Handle *handle)
  218. {
  219. struct GNUNET_MQ_MessageHandler handlers[] = {
  220. GNUNET_MQ_hd_var_size (client_result,
  221. GNUNET_MESSAGE_TYPE_REHASH_CLIENT_RESULT,
  222. struct REHASH_ResultMessage,
  223. handle),
  224. GNUNET_MQ_hd_fixed_size (put_done,
  225. GNUNET_MESSAGE_TYPE_REHASH_PUT_DONE,
  226. struct REHASH_PutStatusMessage,
  227. handle),
  228. GNUNET_MQ_handler_end ()
  229. };
  230. if (NULL != handle->mq) {
  231. GNUNET_assert (handle->reconnect_task == NULL);
  232. return GNUNET_YES;
  233. }
  234. handle->mq = GNUNET_CLIENT_connect (handle->cfg,
  235. "rehash",
  236. handlers,
  237. &mq_error_handler,
  238. handle);
  239. if (handle->mq != NULL)
  240. {
  241. when_successfully_connected (handle);
  242. return GNUNET_YES;
  243. }
  244. else
  245. return GNUNET_NO;
  246. }
  247. /** The reconnect task */
  248. static void
  249. retry_connect_repeatedly (void *cls)
  250. {
  251. struct REHASH_Handle *handle;
  252. handle = cls;
  253. /* No reason for cancelling ourself! */
  254. /* TODO: should we free ourselves? */
  255. handle->reconnect_task = NULL;
  256. if (GNUNET_YES == try_connect (handle))
  257. /* success! */
  258. return;
  259. /* Increase back-off and try again later */
  260. handle->retry_time = GNUNET_TIME_STD_BACKOFF (handle->retry_time);
  261. handle->reconnect_task
  262. = GNUNET_SCHEDULER_add_delayed (handle->retry_time,
  263. &retry_connect_repeatedly,
  264. handle);
  265. }
  266. void
  267. REHASH_retry_connect (struct REHASH_Handle *handle)
  268. {
  269. GNUNET_assert (handle != NULL);
  270. try_connect (handle);
  271. }
  272. struct REHASH_Handle *
  273. REHASH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
  274. {
  275. struct REHASH_Handle *handle;
  276. handle = GNUNET_new (struct REHASH_Handle);
  277. *handle = (struct REHASH_Handle) { };
  278. handle->cfg = cfg;
  279. retry_connect_repeatedly (handle);
  280. return handle;
  281. }
  282. void
  283. REHASH_disconnect (struct REHASH_Handle *h)
  284. {
  285. if (h->reconnect_task)
  286. GNUNET_SCHEDULER_cancel (h->reconnect_task);
  287. /* TODO memory for GNUNET_Configuration */
  288. /* TODO delete outstanding requests */
  289. if (h->mq)
  290. GNUNET_MQ_destroy (h->mq);
  291. GNUNET_free (h);
  292. }
  293. void
  294. REHASH_store_abort (struct REHASH_StoreContext *cls)
  295. {
  296. GNUNET_assert (cls != NULL);
  297. switch (cls->type)
  298. {
  299. case CONTEXT_PUT_QUEUED:
  300. /* Not yet communicated to the rehash service,
  301. so simply remove from the queue and free
  302. associated memory. */
  303. GNUNET_CONTAINER_DLL_remove (cls->h->store_queue_head,
  304. cls->h->store_queue_tail, cls);
  305. GNUNET_assert (cls->ev != NULL);
  306. GNUNET_assert (cls->msg != NULL);
  307. GNUNET_free (cls->ev);
  308. /* cls->msg is a part of cls->ev (TODO verify),
  309. so don't deallocate that */
  310. break;
  311. case CONTEXT_PUT_SENT:
  312. /* The store request has already been send */
  313. /* These should not be used if CONTEXT_PUT_SENT. */
  314. GNUNET_assert (cls->ev == NULL);
  315. GNUNET_assert (cls->msg == NULL);
  316. GNUNET_assert (cls->prev == NULL);
  317. GNUNET_assert (cls->next == NULL);
  318. /* No use after free! */
  319. GNUNET_MQ_assoc_remove (cls->h->mq, cls->request_id);
  320. /* TODO inform rehash service we aren't interested anymore */
  321. break;
  322. case CONTEXT_PUT_COMPLETED:
  323. GNUNET_assert (cls->ev == NULL);
  324. GNUNET_assert (cls->msg == NULL);
  325. GNUNET_assert (cls->prev == NULL);
  326. GNUNET_assert (cls->next == NULL);
  327. /* No use after free / no leaking memory! */
  328. /* The rehash service won't recognise the request_id
  329. anymore. */
  330. /* TODO: abort / completed races */
  331. GNUNET_MQ_assoc_remove (cls->h->mq, cls->request_id);
  332. break;
  333. case CONTEXT_PUT_FREED:
  334. /* Warning: this case cannot always be detected!
  335. Strictly speaking, this is caught by the ‘default’
  336. case as well, but this is more informative. */
  337. GNUNET_assert (0 && "tried to abort a freed store context");
  338. break;
  339. default:
  340. GNUNET_assert (0 && "invalid cls->type");
  341. }
  342. cls->type = CONTEXT_PUT_FREED;
  343. GNUNET_free (cls);
  344. }
  345. /* TODO perhaps less copy-pasting is possible?
  346. Let's wait with that until everything is implemented,
  347. perhaps by then there will be divergence. */
  348. void
  349. REHASH_query_abort (struct REHASH_QueryContext *cls)
  350. {
  351. GNUNET_assert (cls != NULL);
  352. switch (cls->type)
  353. {
  354. case CONTEXT_QUERY_QUEUED:
  355. /* Not yet communicated to the rehash service,
  356. so simply remove from the queue and free
  357. associated memory. */
  358. GNUNET_CONTAINER_DLL_remove (cls->h->query_queue_head,
  359. cls->h->query_queue_tail, cls);
  360. GNUNET_assert (cls->ev != NULL);
  361. GNUNET_assert (cls->msg != NULL);
  362. GNUNET_free (cls->ev);
  363. /* cls->msg is a part of cls->ev (TODO verify),
  364. so don't deallocate that */
  365. GNUNET_free (cls);
  366. break;
  367. case CONTEXT_QUERY_SENT:
  368. /* The store request has already been send,
  369. so it cannot be removed from the query queue */
  370. /* These should not be used if CONTEXT_PUT_SENT. */
  371. GNUNET_assert (cls->ev == NULL);
  372. GNUNET_assert (cls->msg == NULL);
  373. GNUNET_assert (cls->prev == NULL);
  374. GNUNET_assert (cls->next == NULL);
  375. /* No use after free! */
  376. GNUNET_MQ_assoc_remove (cls->h->mq, cls->request_id);
  377. /* TODO inform rehash service we aren't interested anymore */
  378. break;
  379. default:
  380. GNUNET_assert (0 && "invalid cls->type");
  381. }
  382. }
  383. /**
  384. * Insert @a q into the queue
  385. *
  386. * q->request_id and q->next should not be set
  387. *
  388. * @param h handle to the rehash service
  389. * @param q query to queue
  390. */
  391. static void
  392. queue_query (struct REHASH_Handle *h, struct REHASH_QueryContext *q)
  393. {
  394. GNUNET_assert (q->type == CONTEXT_QUERY_QUEUE_ME);
  395. GNUNET_assert (q->ev != NULL);
  396. GNUNET_assert (q->msg != NULL);
  397. GNUNET_assert (q->prev == NULL);
  398. GNUNET_assert (q->next == NULL);
  399. GNUNET_assert (q->h == h);
  400. q->type = CONTEXT_QUERY_QUEUED;
  401. GNUNET_CONTAINER_DLL_insert (h->query_queue_head, h->query_queue_tail, q);
  402. }
  403. /**
  404. * Insert @a q into the queue
  405. *
  406. * q->request_id and q->next should not be set
  407. *
  408. * @param h handle to the rehash service
  409. * @param q query to queue
  410. */
  411. static void
  412. queue_store (struct REHASH_Handle *h, struct REHASH_StoreContext *q)
  413. {
  414. GNUNET_assert (q->type == CONTEXT_PUT_QUEUE_ME);
  415. GNUNET_assert (q->ev != NULL);
  416. GNUNET_assert (q->msg != NULL);
  417. GNUNET_assert (q->prev == NULL);
  418. GNUNET_assert (q->next == NULL);
  419. GNUNET_assert (q->h == h);
  420. q->type = CONTEXT_PUT_QUEUED;
  421. GNUNET_CONTAINER_DLL_insert (h->store_queue_head, h->store_queue_tail, q);
  422. }
  423. /* TODO call these two functions */
  424. /**
  425. * Remove entries from the query queue and try to send
  426. * them to the rehash service. q->request_id and
  427. * q->msg->request are not expected to be set.
  428. *
  429. * @param h handle to the rehash service
  430. */
  431. static void
  432. process_query_queue (struct REHASH_Handle *h)
  433. {
  434. struct REHASH_QueryContext *current;
  435. struct REHASH_QueryContext *next;
  436. struct GNUNET_MQ_Envelope *ev;
  437. struct REHASH_GetMessage *msg;
  438. if (h->mq == NULL)
  439. /* rehash service is offline */
  440. return;
  441. current = h->query_queue_head;
  442. while (current != NULL)
  443. {
  444. GNUNET_assert
  445. (current->type == CONTEXT_QUERY_QUEUED);
  446. current->request_id = GNUNET_MQ_assoc_add (h->mq, current);
  447. current->msg->request_id = current->request_id;
  448. GNUNET_MQ_send (h->mq, current->ev);
  449. /* These shouldn't be used anymore
  450. (TODO does GNUNET_MQ_send deallocate?) */
  451. current->ev = NULL;
  452. current->msg = NULL;
  453. next = current->next;
  454. /* likewise */
  455. current->prev = NULL;
  456. current->next = NULL;
  457. current->type = CONTEXT_QUERY_SENT;
  458. current = next;
  459. }
  460. h->query_queue_head = NULL;
  461. h->query_queue_tail = NULL;
  462. }
  463. /**
  464. * Remove entries from the store queue and try to send
  465. * them to the rehash service. q->request_id and
  466. * q->msg->request are not expected to be set.
  467. *
  468. * @param h handle to the rehash service
  469. */
  470. static void
  471. process_store_queue (struct REHASH_Handle *h)
  472. {
  473. /* See process_query_queue */
  474. struct REHASH_StoreContext *current;
  475. struct REHASH_StoreContext *next;
  476. struct GNUNET_MQ_Envelope *ev;
  477. if (h->mq == NULL)
  478. return;
  479. current = h->store_queue_head;
  480. while (current != NULL)
  481. {
  482. GNUNET_assert
  483. (current->type == CONTEXT_PUT_QUEUED);
  484. current->request_id = GNUNET_MQ_assoc_add (h->mq, current);
  485. current->msg->request_id = current->request_id;
  486. GNUNET_MQ_send (h->mq, current->ev);
  487. current->ev = NULL;
  488. current->msg = NULL;
  489. next = current->next;
  490. current->prev = NULL;
  491. current->next = NULL;
  492. current->type = CONTEXT_PUT_SENT;
  493. current = next;
  494. }
  495. h->store_queue_head = NULL;
  496. h->store_queue_tail = NULL;
  497. }
  498. struct REHASH_QueryContext *
  499. REHASH_query_start (struct REHASH_Handle *h,
  500. enum GNUNET_FS_SearchOptions options,
  501. uint32_t anonymity,
  502. enum REHASH_Hash_Type in_type,
  503. enum REHASH_Hash_Type out_type,
  504. const char *input,
  505. size_t input_length,
  506. REHASH_QueryContinuation cont,
  507. void *cls)
  508. {
  509. /* TODO stub */
  510. struct REHASH_QueryContext *ret;
  511. char *msg_input;
  512. /* TODO proper error messages, less magic */
  513. /* Prevent buffer overflows! */
  514. GNUNET_assert (input_length <= 64);
  515. ret = GNUNET_new (struct REHASH_QueryContext);
  516. *ret = (struct REHASH_QueryContext) {};
  517. ret->type = CONTEXT_QUERY_QUEUE_ME;
  518. /* TODO clobber ret->request_id */
  519. ret->cont = cont;
  520. ret->cls = cls;
  521. /* TODO some refcounting mechanism */
  522. ret->h = h;
  523. ret->ev = GNUNET_MQ_msg_extra (ret->msg, input_length, GNUNET_MESSAGE_TYPE_REHASH_CLIENT_GET);
  524. /* TODO clobber ret->msg->request_id */
  525. ret->msg->options = htonl (options);
  526. ret->msg->anonymity_level = htonl (anonymity);
  527. /* FIXME! */
  528. ret->msg->in_type = htonl (out_type);
  529. ret->msg->out_type = htonl (out_type);
  530. ret->msg->input_length = htonl ((uint32_t) input_length);
  531. msg_input = (char *) &ret->msg[1];
  532. memcpy (msg_input, input, input_length);
  533. queue_query (h, ret);
  534. process_query_queue (h);
  535. return ret;
  536. }
  537. struct REHASH_StoreContext *
  538. REHASH_store_start (struct REHASH_Handle *h,
  539. const struct GNUNET_FS_BlockOptions *options,
  540. enum REHASH_Hash_Type in_type,
  541. enum REHASH_Hash_Type out_type,
  542. const char *input,
  543. size_t input_length,
  544. const char *output,
  545. size_t output_length,
  546. REHASH_StoreContinuation cont,
  547. void *cls)
  548. {
  549. struct REHASH_StoreContext *ret;
  550. /* TODO proper error messages, less magic */
  551. /* Prevent buffer overflows! */
  552. GNUNET_assert (input_length <= 64);
  553. GNUNET_assert (output_length <= 64);
  554. ret = GNUNET_new (struct REHASH_StoreContext);
  555. *ret = (struct REHASH_StoreContext) {};
  556. ret->type = CONTEXT_PUT_QUEUE_ME;
  557. /* TODO clobber ret->request_id for debugging */
  558. ret->cont = cont;
  559. ret->cls = cls;
  560. ret->h = h;
  561. ret->ev = GNUNET_MQ_msg_extra
  562. (ret->msg, input_length + output_length,
  563. GNUNET_MESSAGE_TYPE_REHASH_CLIENT_PUT);
  564. ret->msg->header.size
  565. = htons (sizeof(*ret->msg) + input_length + output_length);
  566. /* TODO clobber msg->request_id */
  567. ret->msg->expiration_time = GNUNET_TIME_absolute_hton (options->expiration_time);
  568. ret->msg->anonymity_level = htonl (options->anonymity_level);
  569. ret->msg->content_priority = htonl (options->content_priority);
  570. ret->msg->replication_level = htonl (options->replication_level);
  571. ret->msg->in_type = htonl (in_type);
  572. ret->msg->in_type = htonl (out_type);
  573. ret->msg->input_length = htonl ((uint32_t) input_length);
  574. ret->msg->output_length = htonl ((uint32_t) output_length);
  575. /* Include input / output */
  576. memcpy(&ret->msg[1], input, input_length);
  577. memcpy(input_length + (char *) &ret->msg[1], output, output_length);
  578. /* FIXME include input / output */
  579. /* TODO maybe send directly if service is online */
  580. queue_store (h, ret);
  581. process_store_queue (h);
  582. /* TODO: check memory allocation / freeing */
  583. /* TODO: progress / abort / ... */
  584. return ret;
  585. }