rehash-api.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  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 int
  122. check_client_result(void *cls, const struct REHASH_ResultMessage *msg)
  123. {
  124. if (ntohl(msg->output_length) == ntohs(msg->header.size) - sizeof(*msg))
  125. return GNUNET_OK;
  126. else
  127. return GNUNET_SYSERR;
  128. };
  129. static void
  130. handle_client_result(void *cls, const struct REHASH_ResultMessage *msg)
  131. {
  132. /* TODO call callbacks */
  133. GNUNET_assert (0);
  134. };
  135. static void
  136. handle_put_done (void *cls, const struct REHASH_PutStatusMessage *msg)
  137. {
  138. struct REHASH_Handle *h;
  139. struct REHASH_StoreContext *ctx;
  140. REHASH_StoreContinuation cont;
  141. void *cont_cls;
  142. void *put_cls;
  143. uint32_t flags;
  144. flags = ntohl(msg->flags);
  145. /* Detect unsupported required flags.
  146. TODO don't abort. */
  147. GNUNET_assert (0 == ((flags & 0xffff) & ~(REHASH_PUT_COMPLETED)));
  148. /* flags > 0xffff don't have to be recognised. */
  149. if (! (flags & REHASH_PUT_COMPLETED))
  150. /* nothing interesting happened */
  151. return;
  152. h = cls;
  153. ctx = GNUNET_MQ_assoc_get (h->mq, msg->request_id);
  154. /* TODO handle this case gracefully */
  155. GNUNET_assert (ctx != NULL);
  156. /* TODO strictly speaking this acces can be a strict-aliasing
  157. violation */
  158. GNUNET_assert (ctx->type == CONTEXT_PUT_SENT);
  159. cont = ctx->cont;
  160. cont_cls = ctx->cls;
  161. /* First free the structure, then call the callback.
  162. That way misuse of a completed query in the callback
  163. will be caught with segfaults (probabilistically) */
  164. ctx->type = CONTEXT_PUT_COMPLETED;
  165. REHASH_store_abort (ctx);
  166. cont (cont_cls);
  167. }
  168. static void
  169. mq_error_handler (void *h, enum GNUNET_MQ_Error e)
  170. {
  171. /* FIXME! */
  172. GNUNET_assert (0);
  173. }
  174. int
  175. REHASH_connected (struct REHASH_Handle *h)
  176. {
  177. GNUNET_assert (h != NULL);
  178. if (h->mq != NULL)
  179. return GNUNET_YES;
  180. return GNUNET_NO;
  181. }
  182. /**
  183. * Call when connected successfully
  184. * to handle backlog due to an offline rehash service.
  185. */
  186. static void
  187. when_successfully_connected (struct REHASH_Handle *handle)
  188. {
  189. struct GNUNET_SCHEDULER_Task *reconnect_task;
  190. /* Handle backlog */
  191. process_query_queue (handle);
  192. process_store_queue (handle);
  193. handle->retry_time = GNUNET_TIME_relative_get_zero_ ();
  194. if (reconnect_task = handle->reconnect_task) {
  195. handle->reconnect_task = NULL;
  196. GNUNET_SCHEDULER_cancel (reconnect_task);
  197. }
  198. }
  199. /**
  200. * Try to connect to the rehash service.
  201. * If successful, cancel the reconnect_task (if any)
  202. * if any and perform backlog.
  203. */
  204. static int
  205. try_connect (struct REHASH_Handle *handle)
  206. {
  207. struct GNUNET_MQ_MessageHandler handlers[] = {
  208. GNUNET_MQ_hd_var_size (client_result,
  209. GNUNET_MESSAGE_TYPE_REHASH_CLIENT_RESULT,
  210. struct REHASH_ResultMessage,
  211. handle),
  212. GNUNET_MQ_hd_fixed_size (put_done,
  213. GNUNET_MESSAGE_TYPE_REHASH_PUT_DONE,
  214. struct REHASH_PutStatusMessage,
  215. handle),
  216. GNUNET_MQ_handler_end ()
  217. };
  218. if (NULL != handle->mq) {
  219. GNUNET_assert (handle->reconnect_task == NULL);
  220. return GNUNET_YES;
  221. }
  222. handle->mq = GNUNET_CLIENT_connect (handle->cfg,
  223. "rehash",
  224. handlers,
  225. &mq_error_handler,
  226. handle);
  227. if (handle->mq != NULL)
  228. {
  229. when_successfully_connected (handle);
  230. return GNUNET_YES;
  231. }
  232. else
  233. return GNUNET_NO;
  234. }
  235. /** The reconnect task */
  236. static void
  237. retry_connect_repeatedly (void *cls)
  238. {
  239. struct REHASH_Handle *handle;
  240. handle = cls;
  241. /* No reason for cancelling ourself! */
  242. /* TODO: should we free ourselves? */
  243. handle->reconnect_task = NULL;
  244. if (GNUNET_YES == try_connect (handle))
  245. /* success! */
  246. return;
  247. /* Increase back-off and try again later */
  248. handle->retry_time = GNUNET_TIME_STD_BACKOFF (handle->retry_time);
  249. handle->reconnect_task
  250. = GNUNET_SCHEDULER_add_delayed (handle->retry_time,
  251. &retry_connect_repeatedly,
  252. handle);
  253. }
  254. void
  255. REHASH_retry_connect (struct REHASH_Handle *handle)
  256. {
  257. GNUNET_assert (handle != NULL);
  258. try_connect (handle);
  259. }
  260. struct REHASH_Handle *
  261. REHASH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
  262. {
  263. struct REHASH_Handle *handle;
  264. handle = GNUNET_new (struct REHASH_Handle);
  265. *handle = (struct REHASH_Handle) { };
  266. handle->cfg = cfg;
  267. retry_connect_repeatedly (handle);
  268. return handle;
  269. }
  270. void
  271. REHASH_disconnect (struct REHASH_Handle *h)
  272. {
  273. if (h->reconnect_task)
  274. GNUNET_SCHEDULER_cancel (h->reconnect_task);
  275. /* TODO memory for GNUNET_Configuration */
  276. /* TODO delete outstanding requests */
  277. if (h->mq)
  278. GNUNET_MQ_destroy (h->mq);
  279. GNUNET_free (h);
  280. }
  281. void
  282. REHASH_store_abort (struct REHASH_StoreContext *cls)
  283. {
  284. GNUNET_assert (cls != NULL);
  285. switch (cls->type)
  286. {
  287. case CONTEXT_PUT_QUEUED:
  288. /* Not yet communicated to the rehash service,
  289. so simply remove from the queue and free
  290. associated memory. */
  291. GNUNET_CONTAINER_DLL_remove (cls->h->store_queue_head,
  292. cls->h->store_queue_tail, cls);
  293. GNUNET_assert (cls->ev != NULL);
  294. GNUNET_assert (cls->msg != NULL);
  295. GNUNET_free (cls->ev);
  296. /* cls->msg is a part of cls->ev (TODO verify),
  297. so don't deallocate that */
  298. break;
  299. case CONTEXT_PUT_SENT:
  300. /* The store request has already been send
  301. TODO if that's the case, how could the store
  302. be removed from the list? */
  303. GNUNET_CONTAINER_DLL_remove (cls->h->store_queue_head,
  304. cls->h->store_queue_tail, cls);
  305. /* These should not be used if CONTEXT_PUT_SENT. */
  306. GNUNET_assert (cls->ev == NULL);
  307. GNUNET_assert (cls->msg == NULL);
  308. GNUNET_assert (cls->prev == NULL);
  309. GNUNET_assert (cls->next == NULL);
  310. /* No use after free! */
  311. GNUNET_MQ_assoc_remove (cls->h->mq, cls->request_id);
  312. /* TODO inform rehash service we aren't interested anymore */
  313. break;
  314. case CONTEXT_PUT_COMPLETED:
  315. GNUNET_assert (cls->ev == NULL);
  316. GNUNET_assert (cls->msg == NULL);
  317. GNUNET_assert (cls->prev == NULL);
  318. GNUNET_assert (cls->next == NULL);
  319. /* No use after free / no leaking memory! */
  320. /* The rehash service won't recognise the request_id
  321. anymore. */
  322. /* TODO: abort / completed races */
  323. GNUNET_MQ_assoc_remove (cls->h->mq, cls->request_id);
  324. break;
  325. case CONTEXT_PUT_FREED:
  326. /* Warning: this case cannot always be detected!
  327. Strictly speaking, this is caught by the ‘default’
  328. case as well, but this is more informative. */
  329. GNUNET_assert (0 && "tried to abort a freed store context");
  330. break;
  331. default:
  332. GNUNET_assert (0 && "invalid cls->type");
  333. }
  334. cls->type = CONTEXT_PUT_FREED;
  335. GNUNET_free (cls);
  336. }
  337. /* TODO perhaps less copy-pasting is possible?
  338. Let's wait with that until everything is implemented,
  339. perhaps by then there will be divergence. */
  340. void
  341. REHASH_query_abort (struct REHASH_QueryContext *cls)
  342. {
  343. GNUNET_assert (cls != NULL);
  344. switch (cls->type)
  345. {
  346. case CONTEXT_QUERY_QUEUED:
  347. /* Not yet communicated to the rehash service,
  348. so simply remove from the queue and free
  349. associated memory. */
  350. GNUNET_CONTAINER_DLL_remove (cls->h->query_queue_head,
  351. cls->h->query_queue_tail, cls);
  352. GNUNET_assert (cls->ev != NULL);
  353. GNUNET_assert (cls->msg != NULL);
  354. GNUNET_free (cls->ev);
  355. /* cls->msg is a part of cls->ev (TODO verify),
  356. so don't deallocate that */
  357. GNUNET_free (cls);
  358. break;
  359. case CONTEXT_QUERY_SENT:
  360. /* The store request has already been send */
  361. GNUNET_CONTAINER_DLL_remove (cls->h->query_queue_head,
  362. cls->h->query_queue_tail, cls);
  363. /* These should not be used if CONTEXT_PUT_SENT. */
  364. GNUNET_assert (cls->ev == NULL);
  365. GNUNET_assert (cls->msg == NULL);
  366. GNUNET_assert (cls->prev == NULL);
  367. GNUNET_assert (cls->next == NULL);
  368. /* No use after free! */
  369. GNUNET_MQ_assoc_remove (cls->h->mq, cls->request_id);
  370. /* TODO inform rehash service we aren't interested anymore */
  371. break;
  372. default:
  373. GNUNET_assert (0 && "invalid cls->type");
  374. }
  375. }
  376. /**
  377. * Insert @a q into the queue
  378. *
  379. * q->request_id and q->next should not be set
  380. *
  381. * @param h handle to the rehash service
  382. * @param q query to queue
  383. */
  384. static void
  385. queue_query (struct REHASH_Handle *h, struct REHASH_QueryContext *q)
  386. {
  387. GNUNET_assert (q->type == CONTEXT_QUERY_QUEUE_ME);
  388. GNUNET_assert (q->ev != NULL);
  389. GNUNET_assert (q->msg != NULL);
  390. GNUNET_assert (q->prev == NULL);
  391. GNUNET_assert (q->next == NULL);
  392. GNUNET_assert (q->h == h);
  393. q->type = CONTEXT_QUERY_QUEUED;
  394. GNUNET_CONTAINER_DLL_insert (h->query_queue_head, h->query_queue_tail, q);
  395. }
  396. /**
  397. * Insert @a q into the queue
  398. *
  399. * q->request_id and q->next should not be set
  400. *
  401. * @param h handle to the rehash service
  402. * @param q query to queue
  403. */
  404. static void
  405. queue_store (struct REHASH_Handle *h, struct REHASH_StoreContext *q)
  406. {
  407. GNUNET_assert (q->type == CONTEXT_PUT_QUEUE_ME);
  408. GNUNET_assert (q->ev != NULL);
  409. GNUNET_assert (q->msg != NULL);
  410. GNUNET_assert (q->prev == NULL);
  411. GNUNET_assert (q->next == NULL);
  412. GNUNET_assert (q->h == h);
  413. q->type = CONTEXT_PUT_QUEUED;
  414. GNUNET_CONTAINER_DLL_insert (h->store_queue_head, h->store_queue_tail, q);
  415. }
  416. /* TODO call these two functions */
  417. /**
  418. * Remove entries from the query queue and try to send
  419. * them to the rehash service. q->request_id and
  420. * q->msg->request are not expected to be set.
  421. *
  422. * @param h handle to the rehash service
  423. */
  424. static void
  425. process_query_queue (struct REHASH_Handle *h)
  426. {
  427. struct REHASH_QueryContext *current;
  428. struct REHASH_QueryContext *next;
  429. struct GNUNET_MQ_Envelope *ev;
  430. struct REHASH_GetMessage *msg;
  431. if (h->mq == NULL)
  432. /* rehash service is offline */
  433. return;
  434. current = h->query_queue_head;
  435. while (current != NULL)
  436. {
  437. GNUNET_assert
  438. (current->type == CONTEXT_QUERY_QUEUED);
  439. current->request_id = GNUNET_MQ_assoc_add (h->mq, current);
  440. current->msg->request_id = current->request_id;
  441. GNUNET_MQ_send (h->mq, current->ev);
  442. /* These shouldn't be used anymore
  443. (TODO does GNUNET_MQ_send deallocate?) */
  444. current->ev = NULL;
  445. current->msg = NULL;
  446. next = current->next;
  447. /* likewise */
  448. current->prev = NULL;
  449. current->next = NULL;
  450. current->type = CONTEXT_QUERY_SENT;
  451. current = next;
  452. }
  453. h->query_queue_head = NULL;
  454. h->query_queue_tail = NULL;
  455. }
  456. /**
  457. * Remove entries from the store queue and try to send
  458. * them to the rehash service. q->request_id and
  459. * q->msg->request are not expected to be set.
  460. *
  461. * @param h handle to the rehash service
  462. */
  463. static void
  464. process_store_queue (struct REHASH_Handle *h)
  465. {
  466. /* See process_query_queue */
  467. struct REHASH_StoreContext *current;
  468. struct REHASH_StoreContext *next;
  469. struct GNUNET_MQ_Envelope *ev;
  470. if (h->mq == NULL)
  471. return;
  472. current = h->store_queue_head;
  473. while (current != NULL)
  474. {
  475. GNUNET_assert
  476. (current->type == CONTEXT_PUT_QUEUED);
  477. current->request_id = GNUNET_MQ_assoc_add (h->mq, current);
  478. current->msg->request_id = current->request_id;
  479. GNUNET_MQ_send (h->mq, current->ev);
  480. current->ev = NULL;
  481. current->msg = NULL;
  482. next = current->next;
  483. current->prev = NULL;
  484. current->next = NULL;
  485. current->type = CONTEXT_PUT_SENT;
  486. current = next;
  487. }
  488. h->store_queue_head = NULL;
  489. h->store_queue_tail = NULL;
  490. }
  491. struct REHASH_QueryContext *
  492. REHASH_query_start (struct REHASH_Handle *h,
  493. enum GNUNET_FS_SearchOptions options,
  494. uint32_t anonymity,
  495. enum REHASH_Hash_Type in_type,
  496. enum REHASH_Hash_Type out_type,
  497. const char *input,
  498. size_t input_length,
  499. REHASH_QueryContinuation cont,
  500. void *cls)
  501. {
  502. /* TODO stub */
  503. struct REHASH_QueryContext *ret;
  504. char *msg_input;
  505. /* TODO proper error messages, less magic */
  506. /* Prevent buffer overflows! */
  507. GNUNET_assert (input_length <= 64);
  508. ret = GNUNET_new (struct REHASH_QueryContext);
  509. *ret = (struct REHASH_QueryContext) {};
  510. ret->type = CONTEXT_QUERY_QUEUE_ME;
  511. /* TODO clobber ret->request_id */
  512. ret->cont = cont;
  513. ret->cls = cls;
  514. /* TODO some refcounting mechanism */
  515. ret->h = h;
  516. ret->ev = GNUNET_MQ_msg_extra (ret->msg, input_length, GNUNET_MESSAGE_TYPE_REHASH_CLIENT_GET);
  517. /* TODO clobber ret->msg->request_id */
  518. ret->msg->options = htonl (options);
  519. ret->msg->anonymity_level = htonl (anonymity);
  520. /* FIXME! */
  521. ret->msg->in_type = htonl (out_type);
  522. ret->msg->out_type = htonl (out_type);
  523. ret->msg->input_length = htonl ((uint32_t) input_length);
  524. msg_input = (char *) &ret->msg[1];
  525. memcpy (msg_input, input, input_length);
  526. queue_query (h, ret);
  527. process_query_queue (h);
  528. return ret;
  529. }
  530. struct REHASH_StoreContext *
  531. REHASH_store_start (struct REHASH_Handle *h,
  532. const struct GNUNET_FS_BlockOptions *options,
  533. enum REHASH_Hash_Type in_type,
  534. enum REHASH_Hash_Type out_type,
  535. const char *input,
  536. size_t input_length,
  537. const char *output,
  538. size_t output_length,
  539. REHASH_StoreContinuation cont,
  540. void *cls)
  541. {
  542. struct REHASH_StoreContext *ret;
  543. /* TODO proper error messages, less magic */
  544. /* Prevent buffer overflows! */
  545. GNUNET_assert (input_length <= 64);
  546. GNUNET_assert (output_length <= 64);
  547. ret = GNUNET_new (struct REHASH_StoreContext);
  548. *ret = (struct REHASH_StoreContext) {};
  549. ret->type = CONTEXT_PUT_QUEUE_ME;
  550. /* TODO clobber ret->request_id for debugging */
  551. ret->cont = cont;
  552. ret->cls = cls;
  553. ret->h = h;
  554. ret->ev = GNUNET_MQ_msg_extra
  555. (ret->msg, input_length + output_length,
  556. GNUNET_MESSAGE_TYPE_REHASH_CLIENT_PUT);
  557. ret->msg->header.size
  558. = htons (sizeof(*ret->msg) + input_length + output_length);
  559. /* TODO clobber msg->request_id */
  560. ret->msg->expiration_time = GNUNET_TIME_absolute_hton (options->expiration_time);
  561. ret->msg->anonymity_level = htonl (options->anonymity_level);
  562. ret->msg->content_priority = htonl (options->content_priority);
  563. ret->msg->replication_level = htonl (options->replication_level);
  564. ret->msg->in_type = htonl (in_type);
  565. ret->msg->in_type = htonl (out_type);
  566. ret->msg->input_length = htonl ((uint32_t) input_length);
  567. ret->msg->output_length = htonl ((uint32_t) output_length);
  568. /* Include input / output */
  569. memcpy(&ret->msg[1], input, input_length);
  570. memcpy(input_length + (char *) &ret->msg[1], output, output_length);
  571. /* FIXME include input / output */
  572. /* TODO maybe send directly if service is online */
  573. queue_store (h, ret);
  574. process_store_queue (h);
  575. /* TODO: check memory allocation / freeing */
  576. /* TODO: progress / abort / ... */
  577. return ret;
  578. }