namestore_api.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2010-2013, 2016 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. * @file namestore/namestore_api.c
  18. * @brief API to access the NAMESTORE service
  19. * @author Martin Schanzenbach
  20. * @author Matthias Wachs
  21. * @author Christian Grothoff
  22. */
  23. #include "platform.h"
  24. #include "gnunet_util_lib.h"
  25. #include "gnunet_crypto_lib.h"
  26. #include "gnunet_constants.h"
  27. #include "gnunet_dnsparser_lib.h"
  28. #include "gnunet_arm_service.h"
  29. #include "gnunet_signatures.h"
  30. #include "gnunet_gns_service.h"
  31. #include "gnunet_namestore_service.h"
  32. #include "namestore.h"
  33. #define LOG(kind, ...) GNUNET_log_from (kind, "namestore-api", __VA_ARGS__)
  34. /**
  35. * We grant the namestore up to 1 minute of latency, if it is slower than
  36. * that, store queries will fail.
  37. */
  38. #define NAMESTORE_DELAY_TOLERANCE GNUNET_TIME_UNIT_MINUTES
  39. /**
  40. * An QueueEntry used to store information for a pending
  41. * NAMESTORE record operation
  42. */
  43. struct GNUNET_NAMESTORE_QueueEntry
  44. {
  45. /**
  46. * Kept in a DLL.
  47. */
  48. struct GNUNET_NAMESTORE_QueueEntry *next;
  49. /**
  50. * Kept in a DLL.
  51. */
  52. struct GNUNET_NAMESTORE_QueueEntry *prev;
  53. /**
  54. * Main handle to access the namestore.
  55. */
  56. struct GNUNET_NAMESTORE_Handle *h;
  57. /**
  58. * Continuation to call
  59. */
  60. GNUNET_NAMESTORE_ContinuationWithStatus cont;
  61. /**
  62. * Closure for @e cont.
  63. */
  64. void *cont_cls;
  65. /**
  66. * Function to call with the records we get back; or NULL.
  67. */
  68. GNUNET_NAMESTORE_RecordMonitor proc;
  69. /**
  70. * Closure for @e proc.
  71. */
  72. void *proc_cls;
  73. /**
  74. * Function to call on errors.
  75. */
  76. GNUNET_SCHEDULER_TaskCallback error_cb;
  77. /**
  78. * Closure for @e error_cb.
  79. */
  80. void *error_cb_cls;
  81. /**
  82. * Envelope of the message to send to the service, if not yet
  83. * sent.
  84. */
  85. struct GNUNET_MQ_Envelope *env;
  86. /**
  87. * Task scheduled to warn us if the namestore is way too slow.
  88. */
  89. struct GNUNET_SCHEDULER_Task *timeout_task;
  90. /**
  91. * The operation id this zone iteration operation has
  92. */
  93. uint32_t op_id;
  94. };
  95. /**
  96. * Handle for a zone iterator operation
  97. */
  98. struct GNUNET_NAMESTORE_ZoneIterator
  99. {
  100. /**
  101. * Kept in a DLL.
  102. */
  103. struct GNUNET_NAMESTORE_ZoneIterator *next;
  104. /**
  105. * Kept in a DLL.
  106. */
  107. struct GNUNET_NAMESTORE_ZoneIterator *prev;
  108. /**
  109. * Main handle to access the namestore.
  110. */
  111. struct GNUNET_NAMESTORE_Handle *h;
  112. /**
  113. * Function to call on completion.
  114. */
  115. GNUNET_SCHEDULER_TaskCallback finish_cb;
  116. /**
  117. * Closure for @e error_cb.
  118. */
  119. void *finish_cb_cls;
  120. /**
  121. * The continuation to call with the results
  122. */
  123. GNUNET_NAMESTORE_RecordMonitor proc;
  124. /**
  125. * Closure for @e proc.
  126. */
  127. void *proc_cls;
  128. /**
  129. * Function to call on errors.
  130. */
  131. GNUNET_SCHEDULER_TaskCallback error_cb;
  132. /**
  133. * Closure for @e error_cb.
  134. */
  135. void *error_cb_cls;
  136. /**
  137. * Envelope of the message to send to the service, if not yet
  138. * sent.
  139. */
  140. struct GNUNET_MQ_Envelope *env;
  141. /**
  142. * Private key of the zone.
  143. */
  144. struct GNUNET_IDENTITY_PrivateKey zone;
  145. /**
  146. * The operation id this zone iteration operation has
  147. */
  148. uint32_t op_id;
  149. };
  150. /**
  151. * Connection to the NAMESTORE service.
  152. */
  153. struct GNUNET_NAMESTORE_Handle
  154. {
  155. /**
  156. * Configuration to use.
  157. */
  158. const struct GNUNET_CONFIGURATION_Handle *cfg;
  159. /**
  160. * Connection to the service (if available).
  161. */
  162. struct GNUNET_MQ_Handle *mq;
  163. /**
  164. * Head of pending namestore queue entries
  165. */
  166. struct GNUNET_NAMESTORE_QueueEntry *op_head;
  167. /**
  168. * Tail of pending namestore queue entries
  169. */
  170. struct GNUNET_NAMESTORE_QueueEntry *op_tail;
  171. /**
  172. * Head of pending namestore zone iterator entries
  173. */
  174. struct GNUNET_NAMESTORE_ZoneIterator *z_head;
  175. /**
  176. * Tail of pending namestore zone iterator entries
  177. */
  178. struct GNUNET_NAMESTORE_ZoneIterator *z_tail;
  179. /**
  180. * Reconnect task
  181. */
  182. struct GNUNET_SCHEDULER_Task *reconnect_task;
  183. /**
  184. * Delay introduced before we reconnect.
  185. */
  186. struct GNUNET_TIME_Relative reconnect_delay;
  187. /**
  188. * Should we reconnect to service due to some serious error?
  189. */
  190. int reconnect;
  191. /**
  192. * The last operation id used for a NAMESTORE operation
  193. */
  194. uint32_t last_op_id_used;
  195. };
  196. /**
  197. * Disconnect from service and then reconnect.
  198. *
  199. * @param h our handle
  200. */
  201. static void
  202. force_reconnect (struct GNUNET_NAMESTORE_Handle *h);
  203. /**
  204. * Find the queue entry that matches the @a rid
  205. *
  206. * @param h namestore handle
  207. * @param rid id to look up
  208. * @return NULL if @a rid was not found
  209. */
  210. static struct GNUNET_NAMESTORE_QueueEntry *
  211. find_qe (struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
  212. {
  213. struct GNUNET_NAMESTORE_QueueEntry *qe;
  214. for (qe = h->op_head; qe != NULL; qe = qe->next)
  215. if (qe->op_id == rid)
  216. return qe;
  217. return NULL;
  218. }
  219. /**
  220. * Find the zone iteration entry that matches the @a rid
  221. *
  222. * @param h namestore handle
  223. * @param rid id to look up
  224. * @return NULL if @a rid was not found
  225. */
  226. static struct GNUNET_NAMESTORE_ZoneIterator *
  227. find_zi (struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
  228. {
  229. struct GNUNET_NAMESTORE_ZoneIterator *ze;
  230. for (ze = h->z_head; ze != NULL; ze = ze->next)
  231. if (ze->op_id == rid)
  232. return ze;
  233. return NULL;
  234. }
  235. /**
  236. * Free @a qe.
  237. *
  238. * @param qe entry to free
  239. */
  240. static void
  241. free_qe (struct GNUNET_NAMESTORE_QueueEntry *qe)
  242. {
  243. struct GNUNET_NAMESTORE_Handle *h = qe->h;
  244. GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, qe);
  245. if (NULL != qe->env)
  246. GNUNET_MQ_discard (qe->env);
  247. if (NULL != qe->timeout_task)
  248. GNUNET_SCHEDULER_cancel (qe->timeout_task);
  249. GNUNET_free (qe);
  250. }
  251. /**
  252. * Free @a ze.
  253. *
  254. * @param ze entry to free
  255. */
  256. static void
  257. free_ze (struct GNUNET_NAMESTORE_ZoneIterator *ze)
  258. {
  259. struct GNUNET_NAMESTORE_Handle *h = ze->h;
  260. GNUNET_CONTAINER_DLL_remove (h->z_head, h->z_tail, ze);
  261. if (NULL != ze->env)
  262. GNUNET_MQ_discard (ze->env);
  263. GNUNET_free (ze);
  264. }
  265. /**
  266. * Check that @a rd_buf of length @a rd_len contains
  267. * @a rd_count records.
  268. *
  269. * @param rd_len length of @a rd_buf
  270. * @param rd_buf buffer with serialized records
  271. * @param rd_count number of records expected
  272. * @return #GNUNET_OK if @a rd_buf is well-formed
  273. */
  274. static int
  275. check_rd (size_t rd_len, const void *rd_buf, unsigned int rd_count)
  276. {
  277. struct GNUNET_GNSRECORD_Data rd[rd_count];
  278. if (GNUNET_OK !=
  279. GNUNET_GNSRECORD_records_deserialize (rd_len, rd_buf, rd_count, rd))
  280. {
  281. GNUNET_break (0);
  282. return GNUNET_SYSERR;
  283. }
  284. return GNUNET_OK;
  285. }
  286. /**
  287. * Handle an incoming message of type
  288. * #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE
  289. *
  290. * @param cls
  291. * @param msg the message we received
  292. */
  293. static void
  294. handle_record_store_response (void *cls,
  295. const struct RecordStoreResponseMessage *msg)
  296. {
  297. struct GNUNET_NAMESTORE_Handle *h = cls;
  298. struct GNUNET_NAMESTORE_QueueEntry *qe;
  299. int res;
  300. const char *emsg;
  301. qe = find_qe (h, ntohl (msg->gns_header.r_id));
  302. res = ntohl (msg->op_result);
  303. LOG (GNUNET_ERROR_TYPE_DEBUG,
  304. "Received RECORD_STORE_RESPONSE with result %d\n",
  305. res);
  306. /* TODO: add actual error message from namestore to response... */
  307. if (GNUNET_SYSERR == res)
  308. emsg = _ ("Namestore failed to store record\n");
  309. else
  310. emsg = NULL;
  311. if (NULL == qe)
  312. return;
  313. if (NULL != qe->cont)
  314. qe->cont (qe->cont_cls, res, emsg);
  315. free_qe (qe);
  316. }
  317. /**
  318. * Check validity of an incoming message of type
  319. * #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE
  320. *
  321. * @param cls
  322. * @param msg the message we received
  323. * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
  324. */
  325. static int
  326. check_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg)
  327. {
  328. const char *name;
  329. size_t exp_msg_len;
  330. size_t msg_len;
  331. size_t name_len;
  332. size_t rd_len;
  333. (void) cls;
  334. rd_len = ntohs (msg->rd_len);
  335. msg_len = ntohs (msg->gns_header.header.size);
  336. name_len = ntohs (msg->name_len);
  337. exp_msg_len = sizeof(*msg) + name_len + rd_len;
  338. if (msg_len != exp_msg_len)
  339. {
  340. GNUNET_break (0);
  341. return GNUNET_SYSERR;
  342. }
  343. name = (const char *) &msg[1];
  344. if ((name_len > 0) && ('\0' != name[name_len - 1]))
  345. {
  346. GNUNET_break (0);
  347. return GNUNET_SYSERR;
  348. }
  349. if (GNUNET_NO == ntohs (msg->found))
  350. {
  351. if (0 != ntohs (msg->rd_count))
  352. {
  353. GNUNET_break (0);
  354. return GNUNET_SYSERR;
  355. }
  356. return GNUNET_OK;
  357. }
  358. return check_rd (rd_len, &name[name_len], ntohs (msg->rd_count));
  359. }
  360. /**
  361. * Handle an incoming message of type
  362. * #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE
  363. *
  364. * @param cls
  365. * @param msg the message we received
  366. */
  367. static void
  368. handle_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg)
  369. {
  370. struct GNUNET_NAMESTORE_Handle *h = cls;
  371. struct GNUNET_NAMESTORE_QueueEntry *qe;
  372. const char *name;
  373. const char *rd_tmp;
  374. size_t name_len;
  375. size_t rd_len;
  376. unsigned int rd_count;
  377. LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_LOOKUP_RESULT\n");
  378. qe = find_qe (h, ntohl (msg->gns_header.r_id));
  379. if (NULL == qe)
  380. return;
  381. rd_len = ntohs (msg->rd_len);
  382. rd_count = ntohs (msg->rd_count);
  383. name_len = ntohs (msg->name_len);
  384. name = (const char *) &msg[1];
  385. if (GNUNET_NO == ntohs (msg->found))
  386. {
  387. /* label was not in namestore */
  388. if (NULL != qe->proc)
  389. qe->proc (qe->proc_cls, &msg->private_key, name, 0, NULL);
  390. free_qe (qe);
  391. return;
  392. }
  393. rd_tmp = &name[name_len];
  394. {
  395. struct GNUNET_GNSRECORD_Data rd[rd_count];
  396. GNUNET_assert (
  397. GNUNET_OK ==
  398. GNUNET_GNSRECORD_records_deserialize (rd_len, rd_tmp, rd_count, rd));
  399. if (0 == name_len)
  400. name = NULL;
  401. if (NULL != qe->proc)
  402. qe->proc (qe->proc_cls,
  403. &msg->private_key,
  404. name,
  405. rd_count,
  406. (rd_count > 0) ? rd : NULL);
  407. }
  408. free_qe (qe);
  409. }
  410. /**
  411. * Handle an incoming message of type
  412. * #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT
  413. *
  414. * @param cls
  415. * @param msg the message we received
  416. * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
  417. */
  418. static int
  419. check_record_result (void *cls, const struct RecordResultMessage *msg)
  420. {
  421. static struct GNUNET_IDENTITY_PrivateKey priv_dummy;
  422. const char *name;
  423. size_t msg_len;
  424. size_t name_len;
  425. size_t rd_len;
  426. (void) cls;
  427. rd_len = ntohs (msg->rd_len);
  428. msg_len = ntohs (msg->gns_header.header.size);
  429. name_len = ntohs (msg->name_len);
  430. if (0 != ntohs (msg->reserved))
  431. {
  432. GNUNET_break (0);
  433. return GNUNET_SYSERR;
  434. }
  435. if (msg_len != sizeof(struct RecordResultMessage) + name_len + rd_len)
  436. {
  437. GNUNET_break (0);
  438. return GNUNET_SYSERR;
  439. }
  440. name = (const char *) &msg[1];
  441. if ((0 == name_len) || ('\0' != name[name_len - 1]))
  442. {
  443. GNUNET_break (0);
  444. return GNUNET_SYSERR;
  445. }
  446. if (0 == GNUNET_memcmp (&msg->private_key, &priv_dummy))
  447. {
  448. GNUNET_break (0);
  449. return GNUNET_SYSERR;
  450. }
  451. return check_rd (rd_len, &name[name_len], ntohs (msg->rd_count));
  452. }
  453. /**
  454. * Handle an incoming message of type
  455. * #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT
  456. *
  457. * @param cls
  458. * @param msg the message we received
  459. */
  460. static void
  461. handle_record_result (void *cls, const struct RecordResultMessage *msg)
  462. {
  463. struct GNUNET_NAMESTORE_Handle *h = cls;
  464. struct GNUNET_NAMESTORE_QueueEntry *qe;
  465. struct GNUNET_NAMESTORE_ZoneIterator *ze;
  466. const char *name;
  467. const char *rd_tmp;
  468. size_t name_len;
  469. size_t rd_len;
  470. unsigned int rd_count;
  471. LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_RESULT\n");
  472. rd_len = ntohs (msg->rd_len);
  473. rd_count = ntohs (msg->rd_count);
  474. name_len = ntohs (msg->name_len);
  475. ze = find_zi (h, ntohl (msg->gns_header.r_id));
  476. qe = find_qe (h, ntohl (msg->gns_header.r_id));
  477. if ((NULL == ze) && (NULL == qe))
  478. return; /* rid not found */
  479. if ((NULL != ze) && (NULL != qe))
  480. {
  481. GNUNET_break (0); /* rid ambiguous */
  482. force_reconnect (h);
  483. return;
  484. }
  485. name = (const char *) &msg[1];
  486. rd_tmp = &name[name_len];
  487. {
  488. struct GNUNET_GNSRECORD_Data rd[rd_count];
  489. GNUNET_assert (
  490. GNUNET_OK ==
  491. GNUNET_GNSRECORD_records_deserialize (rd_len, rd_tmp, rd_count, rd));
  492. if (0 == name_len)
  493. name = NULL;
  494. if (NULL != qe)
  495. {
  496. if (NULL != qe->proc)
  497. qe->proc (qe->proc_cls,
  498. &msg->private_key,
  499. name,
  500. rd_count,
  501. (rd_count > 0) ? rd : NULL);
  502. free_qe (qe);
  503. return;
  504. }
  505. if (NULL != ze)
  506. {
  507. if (NULL != ze->proc)
  508. ze->proc (ze->proc_cls, &msg->private_key, name, rd_count, rd);
  509. return;
  510. }
  511. }
  512. GNUNET_assert (0);
  513. }
  514. /**
  515. * Handle an incoming message of type
  516. * #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT_END
  517. *
  518. * @param cls
  519. * @param msg the message we received
  520. */
  521. static void
  522. handle_record_result_end (void *cls, const struct GNUNET_NAMESTORE_Header *msg)
  523. {
  524. struct GNUNET_NAMESTORE_Handle *h = cls;
  525. struct GNUNET_NAMESTORE_QueueEntry *qe;
  526. struct GNUNET_NAMESTORE_ZoneIterator *ze;
  527. LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_RESULT_END\n");
  528. ze = find_zi (h, ntohl (msg->r_id));
  529. qe = find_qe (h, ntohl (msg->r_id));
  530. if ((NULL == ze) && (NULL == qe))
  531. return; /* rid not found */
  532. if ((NULL != ze) && (NULL != qe))
  533. {
  534. GNUNET_break (0); /* rid ambiguous */
  535. force_reconnect (h);
  536. return;
  537. }
  538. LOG (GNUNET_ERROR_TYPE_DEBUG, "Zone iteration completed!\n");
  539. if (NULL == ze)
  540. {
  541. GNUNET_break (0);
  542. force_reconnect (h);
  543. return;
  544. }
  545. if (NULL != ze->finish_cb)
  546. ze->finish_cb (ze->finish_cb_cls);
  547. free_ze (ze);
  548. }
  549. /**
  550. * Handle an incoming message of type
  551. * #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE.
  552. *
  553. * @param qe the respective entry in the message queue
  554. * @param msg the message we received
  555. * @return #GNUNET_OK on success, #GNUNET_SYSERR if message malformed
  556. */
  557. static int
  558. check_zone_to_name_response (void *cls,
  559. const struct ZoneToNameResponseMessage *msg)
  560. {
  561. size_t name_len;
  562. size_t rd_ser_len;
  563. const char *name_tmp;
  564. (void) cls;
  565. if (GNUNET_OK != ntohs (msg->res))
  566. return GNUNET_OK;
  567. name_len = ntohs (msg->name_len);
  568. rd_ser_len = ntohs (msg->rd_len);
  569. if (ntohs (msg->gns_header.header.size) !=
  570. sizeof(struct ZoneToNameResponseMessage) + name_len + rd_ser_len)
  571. {
  572. GNUNET_break (0);
  573. return GNUNET_SYSERR;
  574. }
  575. name_tmp = (const char *) &msg[1];
  576. if ((name_len > 0) && ('\0' != name_tmp[name_len - 1]))
  577. {
  578. GNUNET_break (0);
  579. return GNUNET_SYSERR;
  580. }
  581. return check_rd (rd_ser_len, &name_tmp[name_len], ntohs (msg->rd_count));
  582. }
  583. /**
  584. * Handle an incoming message of type
  585. * #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE.
  586. *
  587. * @param cls
  588. * @param msg the message we received
  589. */
  590. static void
  591. handle_zone_to_name_response (void *cls,
  592. const struct ZoneToNameResponseMessage *msg)
  593. {
  594. struct GNUNET_NAMESTORE_Handle *h = cls;
  595. struct GNUNET_NAMESTORE_QueueEntry *qe;
  596. int res;
  597. size_t name_len;
  598. size_t rd_ser_len;
  599. unsigned int rd_count;
  600. const char *name_tmp;
  601. const char *rd_tmp;
  602. LOG (GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_TO_NAME_RESPONSE\n");
  603. qe = find_qe (h, ntohl (msg->gns_header.r_id));
  604. if (NULL == qe)
  605. {
  606. LOG (GNUNET_ERROR_TYPE_WARNING,
  607. "Response queue already gone...\n");
  608. return;
  609. }
  610. res = ntohs (msg->res);
  611. switch (res)
  612. {
  613. case GNUNET_SYSERR:
  614. LOG (GNUNET_ERROR_TYPE_DEBUG,
  615. "An error occurred during zone to name operation\n");
  616. break;
  617. case GNUNET_NO:
  618. LOG (GNUNET_ERROR_TYPE_DEBUG,
  619. "Namestore has no result for zone to name mapping \n");
  620. if (NULL != qe->proc)
  621. qe->proc (qe->proc_cls, &msg->zone, NULL, 0, NULL);
  622. free_qe (qe);
  623. return;
  624. case GNUNET_YES:
  625. LOG (GNUNET_ERROR_TYPE_DEBUG,
  626. "Namestore has result for zone to name mapping \n");
  627. name_len = ntohs (msg->name_len);
  628. rd_count = ntohs (msg->rd_count);
  629. rd_ser_len = ntohs (msg->rd_len);
  630. name_tmp = (const char *) &msg[1];
  631. rd_tmp = &name_tmp[name_len];
  632. {
  633. struct GNUNET_GNSRECORD_Data rd[rd_count];
  634. GNUNET_assert (GNUNET_OK ==
  635. GNUNET_GNSRECORD_records_deserialize (rd_ser_len,
  636. rd_tmp,
  637. rd_count,
  638. rd));
  639. /* normal end, call continuation with result */
  640. if (NULL != qe->proc)
  641. qe->proc (qe->proc_cls, &msg->zone, name_tmp, rd_count, rd);
  642. /* return is important here: break would call continuation with error! */
  643. free_qe (qe);
  644. return;
  645. }
  646. default:
  647. GNUNET_break (0);
  648. force_reconnect (h);
  649. return;
  650. }
  651. /* error case, call continuation with error */
  652. if (NULL != qe->error_cb)
  653. qe->error_cb (qe->error_cb_cls);
  654. free_qe (qe);
  655. }
  656. /**
  657. * Generic error handler, called with the appropriate error code and
  658. * the same closure specified at the creation of the message queue.
  659. * Not every message queue implementation supports an error handler.
  660. *
  661. * @param cls closure with the `struct GNUNET_NAMESTORE_Handle *`
  662. * @param error error code
  663. */
  664. static void
  665. mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
  666. {
  667. struct GNUNET_NAMESTORE_Handle *h = cls;
  668. (void) error;
  669. force_reconnect (h);
  670. }
  671. /**
  672. * Reconnect to namestore service.
  673. *
  674. * @param h the handle to the NAMESTORE service
  675. */
  676. static void
  677. reconnect (struct GNUNET_NAMESTORE_Handle *h)
  678. {
  679. struct GNUNET_MQ_MessageHandler handlers[] =
  680. { GNUNET_MQ_hd_fixed_size (record_store_response,
  681. GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE,
  682. struct RecordStoreResponseMessage,
  683. h),
  684. GNUNET_MQ_hd_var_size (zone_to_name_response,
  685. GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE,
  686. struct ZoneToNameResponseMessage,
  687. h),
  688. GNUNET_MQ_hd_var_size (record_result,
  689. GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT,
  690. struct RecordResultMessage,
  691. h),
  692. GNUNET_MQ_hd_fixed_size (record_result_end,
  693. GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT_END,
  694. struct GNUNET_NAMESTORE_Header,
  695. h),
  696. GNUNET_MQ_hd_var_size (lookup_result,
  697. GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE,
  698. struct LabelLookupResponseMessage,
  699. h),
  700. GNUNET_MQ_handler_end () };
  701. struct GNUNET_NAMESTORE_ZoneIterator *it;
  702. struct GNUNET_NAMESTORE_QueueEntry *qe;
  703. GNUNET_assert (NULL == h->mq);
  704. h->mq =
  705. GNUNET_CLIENT_connect (h->cfg, "namestore", handlers, &mq_error_handler, h);
  706. if (NULL == h->mq)
  707. return;
  708. /* re-transmit pending requests that waited for a reconnect... */
  709. for (it = h->z_head; NULL != it; it = it->next)
  710. {
  711. GNUNET_MQ_send (h->mq, it->env);
  712. it->env = NULL;
  713. }
  714. for (qe = h->op_head; NULL != qe; qe = qe->next)
  715. {
  716. GNUNET_MQ_send (h->mq, qe->env);
  717. qe->env = NULL;
  718. }
  719. }
  720. /**
  721. * Re-establish the connection to the service.
  722. *
  723. * @param cls handle to use to re-connect.
  724. */
  725. static void
  726. reconnect_task (void *cls)
  727. {
  728. struct GNUNET_NAMESTORE_Handle *h = cls;
  729. h->reconnect_task = NULL;
  730. reconnect (h);
  731. }
  732. /**
  733. * Disconnect from service and then reconnect.
  734. *
  735. * @param h our handle
  736. */
  737. static void
  738. force_reconnect (struct GNUNET_NAMESTORE_Handle *h)
  739. {
  740. struct GNUNET_NAMESTORE_ZoneIterator *ze;
  741. struct GNUNET_NAMESTORE_QueueEntry *qe;
  742. GNUNET_MQ_destroy (h->mq);
  743. h->mq = NULL;
  744. while (NULL != (ze = h->z_head))
  745. {
  746. if (NULL != ze->error_cb)
  747. ze->error_cb (ze->error_cb_cls);
  748. free_ze (ze);
  749. }
  750. while (NULL != (qe = h->op_head))
  751. {
  752. if (NULL != qe->error_cb)
  753. qe->error_cb (qe->error_cb_cls);
  754. if (NULL != qe->cont)
  755. qe->cont (qe->cont_cls,
  756. GNUNET_SYSERR,
  757. "failure in communication with namestore service");
  758. free_qe (qe);
  759. }
  760. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting to namestore\n");
  761. h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
  762. h->reconnect_task =
  763. GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect_task, h);
  764. }
  765. /**
  766. * Get a fresh operation id to distinguish between namestore requests
  767. *
  768. * @param h the namestore handle
  769. * @return next operation id to use
  770. */
  771. static uint32_t
  772. get_op_id (struct GNUNET_NAMESTORE_Handle *h)
  773. {
  774. return h->last_op_id_used++;
  775. }
  776. /**
  777. * Initialize the connection with the NAMESTORE service.
  778. *
  779. * @param cfg configuration to use
  780. * @return handle to the GNS service, or NULL on error
  781. */
  782. struct GNUNET_NAMESTORE_Handle *
  783. GNUNET_NAMESTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
  784. {
  785. struct GNUNET_NAMESTORE_Handle *h;
  786. h = GNUNET_new (struct GNUNET_NAMESTORE_Handle);
  787. h->cfg = cfg;
  788. reconnect (h);
  789. if (NULL == h->mq)
  790. {
  791. GNUNET_free (h);
  792. return NULL;
  793. }
  794. return h;
  795. }
  796. /**
  797. * Disconnect from the namestore service (and free associated
  798. * resources).
  799. *
  800. * @param h handle to the namestore
  801. */
  802. void
  803. GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h)
  804. {
  805. struct GNUNET_NAMESTORE_QueueEntry *q;
  806. struct GNUNET_NAMESTORE_ZoneIterator *z;
  807. LOG (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
  808. GNUNET_break (NULL == h->op_head);
  809. while (NULL != (q = h->op_head))
  810. {
  811. GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, q);
  812. GNUNET_free (q);
  813. }
  814. GNUNET_break (NULL == h->z_head);
  815. while (NULL != (z = h->z_head))
  816. {
  817. GNUNET_CONTAINER_DLL_remove (h->z_head, h->z_tail, z);
  818. GNUNET_free (z);
  819. }
  820. if (NULL != h->mq)
  821. {
  822. GNUNET_MQ_destroy (h->mq);
  823. h->mq = NULL;
  824. }
  825. if (NULL != h->reconnect_task)
  826. {
  827. GNUNET_SCHEDULER_cancel (h->reconnect_task);
  828. h->reconnect_task = NULL;
  829. }
  830. GNUNET_free (h);
  831. }
  832. /**
  833. * Task launched to warn the user that the namestore is
  834. * excessively slow and that a query was thus dropped.
  835. *
  836. * @param cls a `struct GNUNET_NAMESTORE_QueueEntry *`
  837. */
  838. static void
  839. warn_delay (void *cls)
  840. {
  841. struct GNUNET_NAMESTORE_QueueEntry *qe = cls;
  842. qe->timeout_task = NULL;
  843. LOG (GNUNET_ERROR_TYPE_WARNING,
  844. "Did not receive response from namestore after %s!\n",
  845. GNUNET_STRINGS_relative_time_to_string (NAMESTORE_DELAY_TOLERANCE,
  846. GNUNET_YES));
  847. if (NULL != qe->cont)
  848. {
  849. qe->cont (qe->cont_cls, GNUNET_SYSERR, "timeout");
  850. qe->cont = NULL;
  851. }
  852. GNUNET_NAMESTORE_cancel (qe);
  853. }
  854. /**
  855. * Store an item in the namestore. If the item is already present,
  856. * it is replaced with the new record. Use an empty array to
  857. * remove all records under the given name.
  858. *
  859. * @param h handle to the namestore
  860. * @param pkey private key of the zone
  861. * @param label name that is being mapped (at most 255 characters long)
  862. * @param rd_count number of records in the @a rd array
  863. * @param rd array of records with data to store
  864. * @param cont continuation to call when done
  865. * @param cont_cls closure for @a cont
  866. * @return handle to abort the request
  867. */
  868. struct GNUNET_NAMESTORE_QueueEntry *
  869. GNUNET_NAMESTORE_records_store (
  870. struct GNUNET_NAMESTORE_Handle *h,
  871. const struct GNUNET_IDENTITY_PrivateKey *pkey,
  872. const char *label,
  873. unsigned int rd_count,
  874. const struct GNUNET_GNSRECORD_Data *rd,
  875. GNUNET_NAMESTORE_ContinuationWithStatus cont,
  876. void *cont_cls)
  877. {
  878. struct GNUNET_NAMESTORE_QueueEntry *qe;
  879. struct GNUNET_MQ_Envelope *env;
  880. char *name_tmp;
  881. char *rd_ser;
  882. ssize_t rd_ser_len;
  883. size_t name_len;
  884. uint32_t rid;
  885. struct RecordStoreMessage *msg;
  886. ssize_t sret;
  887. name_len = strlen (label) + 1;
  888. if (name_len > MAX_NAME_LEN)
  889. {
  890. GNUNET_break (0);
  891. return NULL;
  892. }
  893. rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count, rd);
  894. if (rd_ser_len < 0)
  895. {
  896. GNUNET_break (0);
  897. return NULL;
  898. }
  899. if (rd_ser_len > UINT16_MAX)
  900. {
  901. GNUNET_break (0);
  902. return NULL;
  903. }
  904. rid = get_op_id (h);
  905. qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry);
  906. qe->h = h;
  907. qe->cont = cont;
  908. qe->cont_cls = cont_cls;
  909. qe->op_id = rid;
  910. GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
  911. /* setup msg */
  912. env = GNUNET_MQ_msg_extra (msg,
  913. name_len + rd_ser_len,
  914. GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE);
  915. msg->gns_header.r_id = htonl (rid);
  916. msg->name_len = htons (name_len);
  917. msg->rd_count = htons (rd_count);
  918. msg->rd_len = htons (rd_ser_len);
  919. msg->reserved = htons (0);
  920. msg->private_key = *pkey;
  921. name_tmp = (char *) &msg[1];
  922. GNUNET_memcpy (name_tmp, label, name_len);
  923. rd_ser = &name_tmp[name_len];
  924. sret = GNUNET_GNSRECORD_records_serialize (rd_count, rd, rd_ser_len, rd_ser);
  925. if ((0 > sret) || (sret != rd_ser_len))
  926. {
  927. GNUNET_break (0);
  928. GNUNET_free (env);
  929. return NULL;
  930. }
  931. GNUNET_assert (rd_ser_len == sret);
  932. LOG (GNUNET_ERROR_TYPE_DEBUG,
  933. "Sending NAMESTORE_RECORD_STORE message for name `%s' with %u records\n",
  934. label,
  935. rd_count);
  936. qe->timeout_task =
  937. GNUNET_SCHEDULER_add_delayed (NAMESTORE_DELAY_TOLERANCE, &warn_delay, qe);
  938. if (NULL == h->mq)
  939. {
  940. qe->env = env;
  941. LOG (GNUNET_ERROR_TYPE_WARNING,
  942. "Delaying NAMESTORE_RECORD_STORE message as namestore is not ready!\n");
  943. }
  944. else
  945. {
  946. GNUNET_MQ_send (h->mq, env);
  947. }
  948. return qe;
  949. }
  950. /**
  951. * Lookup an item in the namestore.
  952. *
  953. * @param h handle to the namestore
  954. * @param pkey private key of the zone
  955. * @param label name that is being mapped (at most 255 characters long)
  956. * @param error_cb function to call on error (i.e. disconnect)
  957. * @param error_cb_cls closure for @a error_cb
  958. * @param rm function to call with the result (with 0 records if we don't have that label)
  959. * @param rm_cls closure for @a rm
  960. * @return handle to abort the request
  961. */
  962. struct GNUNET_NAMESTORE_QueueEntry *
  963. GNUNET_NAMESTORE_records_lookup (
  964. struct GNUNET_NAMESTORE_Handle *h,
  965. const struct GNUNET_IDENTITY_PrivateKey *pkey,
  966. const char *label,
  967. GNUNET_SCHEDULER_TaskCallback error_cb,
  968. void *error_cb_cls,
  969. GNUNET_NAMESTORE_RecordMonitor rm,
  970. void *rm_cls)
  971. {
  972. struct GNUNET_NAMESTORE_QueueEntry *qe;
  973. struct GNUNET_MQ_Envelope *env;
  974. struct LabelLookupMessage *msg;
  975. size_t label_len;
  976. if (1 == (label_len = strlen (label) + 1))
  977. {
  978. GNUNET_break (0);
  979. return NULL;
  980. }
  981. qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry);
  982. qe->h = h;
  983. qe->error_cb = error_cb;
  984. qe->error_cb_cls = error_cb_cls;
  985. qe->proc = rm;
  986. qe->proc_cls = rm_cls;
  987. qe->op_id = get_op_id (h);
  988. GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
  989. env = GNUNET_MQ_msg_extra (msg,
  990. label_len,
  991. GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP);
  992. msg->gns_header.r_id = htonl (qe->op_id);
  993. msg->zone = *pkey;
  994. msg->label_len = htonl (label_len);
  995. GNUNET_memcpy (&msg[1], label, label_len);
  996. if (NULL == h->mq)
  997. qe->env = env;
  998. else
  999. GNUNET_MQ_send (h->mq, env);
  1000. return qe;
  1001. }
  1002. /**
  1003. * Look for an existing PKEY delegation record for a given public key.
  1004. * Returns at most one result to the processor.
  1005. *
  1006. * @param h handle to the namestore
  1007. * @param zone public key of the zone to look up in, never NULL
  1008. * @param value_zone public key of the target zone (value), never NULL
  1009. * @param error_cb function to call on error (i.e. disconnect)
  1010. * @param error_cb_cls closure for @a error_cb
  1011. * @param proc function to call on the matching records, or with
  1012. * NULL (rd_count == 0) if there are no matching records
  1013. * @param proc_cls closure for @a proc
  1014. * @return a handle that can be used to
  1015. * cancel
  1016. */
  1017. struct GNUNET_NAMESTORE_QueueEntry *
  1018. GNUNET_NAMESTORE_zone_to_name (
  1019. struct GNUNET_NAMESTORE_Handle *h,
  1020. const struct GNUNET_IDENTITY_PrivateKey *zone,
  1021. const struct GNUNET_IDENTITY_PublicKey *value_zone,
  1022. GNUNET_SCHEDULER_TaskCallback error_cb,
  1023. void *error_cb_cls,
  1024. GNUNET_NAMESTORE_RecordMonitor proc,
  1025. void *proc_cls)
  1026. {
  1027. struct GNUNET_NAMESTORE_QueueEntry *qe;
  1028. struct GNUNET_MQ_Envelope *env;
  1029. struct ZoneToNameMessage *msg;
  1030. uint32_t rid;
  1031. rid = get_op_id (h);
  1032. qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry);
  1033. qe->h = h;
  1034. qe->error_cb = error_cb;
  1035. qe->error_cb_cls = error_cb_cls;
  1036. qe->proc = proc;
  1037. qe->proc_cls = proc_cls;
  1038. qe->op_id = rid;
  1039. GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
  1040. env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME);
  1041. msg->gns_header.r_id = htonl (rid);
  1042. msg->zone = *zone;
  1043. msg->value_zone = *value_zone;
  1044. if (NULL == h->mq)
  1045. qe->env = env;
  1046. else
  1047. GNUNET_MQ_send (h->mq, env);
  1048. return qe;
  1049. }
  1050. /**
  1051. * Starts a new zone iteration (used to periodically PUT all of our
  1052. * records into our DHT). This MUST lock the struct GNUNET_NAMESTORE_Handle
  1053. * for any other calls than #GNUNET_NAMESTORE_zone_iterator_next and
  1054. * #GNUNET_NAMESTORE_zone_iteration_stop. @a proc will be called once
  1055. * immediately, and then again after
  1056. * #GNUNET_NAMESTORE_zone_iterator_next is invoked.
  1057. *
  1058. * @param h handle to the namestore
  1059. * @param zone zone to access, NULL for all zones
  1060. * @param error_cb function to call on error (i.e. disconnect)
  1061. * @param error_cb_cls closure for @a error_cb
  1062. * @param proc function to call on each name from the zone; it
  1063. * will be called repeatedly with a value (if available)
  1064. * @param proc_cls closure for @a proc
  1065. * @param finish_cb function to call on completion
  1066. * @param finish_cb_cls closure for @a finish_cb
  1067. * @return an iterator handle to use for iteration
  1068. */
  1069. struct GNUNET_NAMESTORE_ZoneIterator *
  1070. GNUNET_NAMESTORE_zone_iteration_start (
  1071. struct GNUNET_NAMESTORE_Handle *h,
  1072. const struct GNUNET_IDENTITY_PrivateKey *zone,
  1073. GNUNET_SCHEDULER_TaskCallback error_cb,
  1074. void *error_cb_cls,
  1075. GNUNET_NAMESTORE_RecordMonitor proc,
  1076. void *proc_cls,
  1077. GNUNET_SCHEDULER_TaskCallback finish_cb,
  1078. void *finish_cb_cls)
  1079. {
  1080. struct GNUNET_NAMESTORE_ZoneIterator *it;
  1081. struct GNUNET_MQ_Envelope *env;
  1082. struct ZoneIterationStartMessage *msg;
  1083. uint32_t rid;
  1084. LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_START message\n");
  1085. rid = get_op_id (h);
  1086. it = GNUNET_new (struct GNUNET_NAMESTORE_ZoneIterator);
  1087. it->h = h;
  1088. it->error_cb = error_cb;
  1089. it->error_cb_cls = error_cb_cls;
  1090. it->finish_cb = finish_cb;
  1091. it->finish_cb_cls = finish_cb_cls;
  1092. it->proc = proc;
  1093. it->proc_cls = proc_cls;
  1094. it->op_id = rid;
  1095. if (NULL != zone)
  1096. it->zone = *zone;
  1097. GNUNET_CONTAINER_DLL_insert_tail (h->z_head, h->z_tail, it);
  1098. env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START);
  1099. msg->gns_header.r_id = htonl (rid);
  1100. if (NULL != zone)
  1101. msg->zone = *zone;
  1102. if (NULL == h->mq)
  1103. it->env = env;
  1104. else
  1105. GNUNET_MQ_send (h->mq, env);
  1106. return it;
  1107. }
  1108. /**
  1109. * Calls the record processor specified in #GNUNET_NAMESTORE_zone_iteration_start
  1110. * for the next record.
  1111. *
  1112. * @param it the iterator
  1113. * @param limit number of records to return to the iterator in one shot
  1114. * (before #GNUNET_NAMESTORE_zone_iterator_next is to be called again)
  1115. */
  1116. void
  1117. GNUNET_NAMESTORE_zone_iterator_next (struct GNUNET_NAMESTORE_ZoneIterator *it,
  1118. uint64_t limit)
  1119. {
  1120. struct GNUNET_NAMESTORE_Handle *h = it->h;
  1121. struct ZoneIterationNextMessage *msg;
  1122. struct GNUNET_MQ_Envelope *env;
  1123. LOG (GNUNET_ERROR_TYPE_DEBUG,
  1124. "Sending ZONE_ITERATION_NEXT message with limit %llu\n",
  1125. (unsigned long long) limit);
  1126. env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT);
  1127. msg->gns_header.r_id = htonl (it->op_id);
  1128. msg->limit = GNUNET_htonll (limit);
  1129. GNUNET_MQ_send (h->mq, env);
  1130. }
  1131. /**
  1132. * Stops iteration and releases the namestore handle for further calls.
  1133. *
  1134. * @param it the iterator
  1135. */
  1136. void
  1137. GNUNET_NAMESTORE_zone_iteration_stop (struct GNUNET_NAMESTORE_ZoneIterator *it)
  1138. {
  1139. struct GNUNET_NAMESTORE_Handle *h = it->h;
  1140. struct GNUNET_MQ_Envelope *env;
  1141. struct ZoneIterationStopMessage *msg;
  1142. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_STOP message\n");
  1143. if (NULL != h->mq)
  1144. {
  1145. env =
  1146. GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP);
  1147. msg->gns_header.r_id = htonl (it->op_id);
  1148. GNUNET_MQ_send (h->mq, env);
  1149. }
  1150. free_ze (it);
  1151. }
  1152. /**
  1153. * Cancel a namestore operation. The final callback from the
  1154. * operation must not have been done yet.
  1155. *
  1156. * @param qe operation to cancel
  1157. */
  1158. void
  1159. GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe)
  1160. {
  1161. free_qe (qe);
  1162. }
  1163. /* end of namestore_api.c */