GNUnet  0.11.x
namestore_api.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2010-2013, 2016 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 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
29 #include "platform.h"
30 #include "gnunet_util_lib.h"
31 #include "gnunet_crypto_lib.h"
32 #include "gnunet_constants.h"
33 #include "gnunet_dnsparser_lib.h"
34 #include "gnunet_arm_service.h"
35 #include "gnunet_signatures.h"
36 #include "gnunet_gns_service.h"
38 #include "namestore.h"
39 
40 
41 #define LOG(kind, ...) GNUNET_log_from (kind, "namestore-api", __VA_ARGS__)
42 
47 #define NAMESTORE_DELAY_TOLERANCE GNUNET_TIME_UNIT_MINUTES
48 
54 {
59 
64 
69 
74 
78  void *cont_cls;
79 
84 
88  void *proc_cls;
89 
94 
98  void *error_cb_cls;
99 
105 
110 
114  uint32_t op_id;
115 };
116 
117 
122 {
127 
132 
137 
142 
147 
152 
156  void *proc_cls;
157 
162 
167 
173 
178 
182  uint32_t op_id;
183 };
184 
185 
190 {
195 
200 
205 
210 
215 
220 
225 
229  struct GNUNET_TIME_Relative reconnect_delay;
230 
235 
239  uint32_t last_op_id_used;
240 };
241 
242 
248 static void
250 
251 
259 static struct GNUNET_NAMESTORE_QueueEntry *
260 find_qe (struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
261 {
263 
264  for (qe = h->op_head; qe != NULL; qe = qe->next)
265  if (qe->op_id == rid)
266  return qe;
267  return NULL;
268 }
269 
270 
278 static struct GNUNET_NAMESTORE_ZoneIterator *
279 find_zi (struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
280 {
282 
283  for (ze = h->z_head; ze != NULL; ze = ze->next)
284  if (ze->op_id == rid)
285  return ze;
286  return NULL;
287 }
288 
289 
295 static void
297 {
298  struct GNUNET_NAMESTORE_Handle *h = qe->h;
299 
301  if (NULL != qe->env)
302  GNUNET_MQ_discard (qe->env);
303  if (NULL != qe->timeout_task)
305  GNUNET_free (qe);
306 }
307 
308 
314 static void
316 {
317  struct GNUNET_NAMESTORE_Handle *h = ze->h;
318 
320  if (NULL != ze->env)
321  GNUNET_MQ_discard (ze->env);
322  GNUNET_free (ze);
323 }
324 
325 
335 static int
336 check_rd (size_t rd_len, const void *rd_buf, unsigned int rd_count)
337 {
338  struct GNUNET_GNSRECORD_Data rd[rd_count];
339 
340  if (GNUNET_OK !=
341  GNUNET_GNSRECORD_records_deserialize (rd_len, rd_buf, rd_count, rd))
342  {
343  GNUNET_break (0);
344  return GNUNET_SYSERR;
345  }
346  return GNUNET_OK;
347 }
348 
349 
357 static void
359  const struct RecordStoreResponseMessage *msg)
360 {
361  struct GNUNET_NAMESTORE_Handle *h = cls;
363  int res;
364  const char *emsg;
365 
366  qe = find_qe (h, ntohl (msg->gns_header.r_id));
367  res = ntohl (msg->op_result);
369  "Received RECORD_STORE_RESPONSE with result %d\n",
370  res);
371  /* TODO: add actual error message from namestore to response... */
372  if (GNUNET_SYSERR == res)
373  emsg = _ ("Namestore failed to store record\n");
374  else
375  emsg = NULL;
376  if (NULL == qe)
377  return;
378  if (NULL != qe->cont)
379  qe->cont (qe->cont_cls, res, emsg);
380  free_qe (qe);
381 }
382 
383 
392 static int
394 {
395  const char *name;
396  size_t exp_msg_len;
397  size_t msg_len;
398  size_t name_len;
399  size_t rd_len;
400 
401  (void) cls;
402  rd_len = ntohs (msg->rd_len);
403  msg_len = ntohs (msg->gns_header.header.size);
404  name_len = ntohs (msg->name_len);
405  exp_msg_len = sizeof(*msg) + name_len + rd_len;
406  if (msg_len != exp_msg_len)
407  {
408  GNUNET_break (0);
409  return GNUNET_SYSERR;
410  }
411  name = (const char *) &msg[1];
412  if ((name_len > 0) && ('\0' != name[name_len - 1]))
413  {
414  GNUNET_break (0);
415  return GNUNET_SYSERR;
416  }
417  if (GNUNET_NO == ntohs (msg->found))
418  {
419  if (0 != ntohs (msg->rd_count))
420  {
421  GNUNET_break (0);
422  return GNUNET_SYSERR;
423  }
424  return GNUNET_OK;
425  }
426  return check_rd (rd_len, &name[name_len], ntohs (msg->rd_count));
427 }
428 
429 
437 static void
439 {
440  struct GNUNET_NAMESTORE_Handle *h = cls;
442  const char *name;
443  const char *rd_tmp;
444  size_t name_len;
445  size_t rd_len;
446  unsigned int rd_count;
447 
448  LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_LOOKUP_RESULT\n");
449  qe = find_qe (h, ntohl (msg->gns_header.r_id));
450  if (NULL == qe)
451  return;
452  rd_len = ntohs (msg->rd_len);
453  rd_count = ntohs (msg->rd_count);
454  name_len = ntohs (msg->name_len);
455  name = (const char *) &msg[1];
456  if (GNUNET_NO == ntohs (msg->found))
457  {
458  /* label was not in namestore */
459  if (NULL != qe->proc)
460  qe->proc (qe->proc_cls, &msg->private_key, name, 0, NULL);
461  free_qe (qe);
462  return;
463  }
464 
465  rd_tmp = &name[name_len];
466  {
467  struct GNUNET_GNSRECORD_Data rd[rd_count];
468 
469  GNUNET_assert (
470  GNUNET_OK ==
471  GNUNET_GNSRECORD_records_deserialize (rd_len, rd_tmp, rd_count, rd));
472  if (0 == name_len)
473  name = NULL;
474  if (NULL != qe->proc)
475  qe->proc (qe->proc_cls,
476  &msg->private_key,
477  name,
478  rd_count,
479  (rd_count > 0) ? rd : NULL);
480  }
481  free_qe (qe);
482 }
483 
484 
493 static int
494 check_record_result (void *cls, const struct RecordResultMessage *msg)
495 {
496  static struct GNUNET_CRYPTO_EcdsaPrivateKey priv_dummy;
497  const char *name;
498  size_t msg_len;
499  size_t name_len;
500  size_t rd_len;
501 
502  (void) cls;
503  rd_len = ntohs (msg->rd_len);
504  msg_len = ntohs (msg->gns_header.header.size);
505  name_len = ntohs (msg->name_len);
506  if (0 != ntohs (msg->reserved))
507  {
508  GNUNET_break (0);
509  return GNUNET_SYSERR;
510  }
511  if (msg_len != sizeof(struct RecordResultMessage) + name_len + rd_len)
512  {
513  GNUNET_break (0);
514  return GNUNET_SYSERR;
515  }
516  name = (const char *) &msg[1];
517  if ((0 == name_len) || ('\0' != name[name_len - 1]))
518  {
519  GNUNET_break (0);
520  return GNUNET_SYSERR;
521  }
522  if (0 == GNUNET_memcmp (&msg->private_key, &priv_dummy))
523  {
524  GNUNET_break (0);
525  return GNUNET_SYSERR;
526  }
527  return check_rd (rd_len, &name[name_len], ntohs (msg->rd_count));
528 }
529 
530 
538 static void
539 handle_record_result (void *cls, const struct RecordResultMessage *msg)
540 {
541  struct GNUNET_NAMESTORE_Handle *h = cls;
544  const char *name;
545  const char *rd_tmp;
546  size_t name_len;
547  size_t rd_len;
548  unsigned int rd_count;
549 
550  LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_RESULT\n");
551  rd_len = ntohs (msg->rd_len);
552  rd_count = ntohs (msg->rd_count);
553  name_len = ntohs (msg->name_len);
554  ze = find_zi (h, ntohl (msg->gns_header.r_id));
555  qe = find_qe (h, ntohl (msg->gns_header.r_id));
556  if ((NULL == ze) && (NULL == qe))
557  return; /* rid not found */
558  if ((NULL != ze) && (NULL != qe))
559  {
560  GNUNET_break (0); /* rid ambigous */
561  force_reconnect (h);
562  return;
563  }
564  name = (const char *) &msg[1];
565  rd_tmp = &name[name_len];
566  {
567  struct GNUNET_GNSRECORD_Data rd[rd_count];
568 
569  GNUNET_assert (
570  GNUNET_OK ==
571  GNUNET_GNSRECORD_records_deserialize (rd_len, rd_tmp, rd_count, rd));
572  if (0 == name_len)
573  name = NULL;
574  if (NULL != qe)
575  {
576  if (NULL != qe->proc)
577  qe->proc (qe->proc_cls,
578  &msg->private_key,
579  name,
580  rd_count,
581  (rd_count > 0) ? rd : NULL);
582  free_qe (qe);
583  return;
584  }
585  if (NULL != ze)
586  {
587  if (NULL != ze->proc)
588  ze->proc (ze->proc_cls, &msg->private_key, name, rd_count, rd);
589  return;
590  }
591  }
592  GNUNET_assert (0);
593 }
594 
595 
603 static void
605 {
606  struct GNUNET_NAMESTORE_Handle *h = cls;
609 
610  LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_RESULT_END\n");
611  ze = find_zi (h, ntohl (msg->r_id));
612  qe = find_qe (h, ntohl (msg->r_id));
613  if ((NULL == ze) && (NULL == qe))
614  return; /* rid not found */
615  if ((NULL != ze) && (NULL != qe))
616  {
617  GNUNET_break (0); /* rid ambigous */
618  force_reconnect (h);
619  return;
620  }
621  LOG (GNUNET_ERROR_TYPE_DEBUG, "Zone iteration completed!\n");
622  if (NULL == ze)
623  {
624  GNUNET_break (0);
625  force_reconnect (h);
626  return;
627  }
628  if (NULL != ze->finish_cb)
629  ze->finish_cb (ze->finish_cb_cls);
630  free_ze (ze);
631 }
632 
633 
642 static int
644  const struct ZoneToNameResponseMessage *msg)
645 {
646  size_t name_len;
647  size_t rd_ser_len;
648  const char *name_tmp;
649 
650  (void) cls;
651  if (GNUNET_OK != ntohs (msg->res))
652  return GNUNET_OK;
653  name_len = ntohs (msg->name_len);
654  rd_ser_len = ntohs (msg->rd_len);
655  if (ntohs (msg->gns_header.header.size) !=
656  sizeof(struct ZoneToNameResponseMessage) + name_len + rd_ser_len)
657  {
658  GNUNET_break (0);
659  return GNUNET_SYSERR;
660  }
661  name_tmp = (const char *) &msg[1];
662  if ((name_len > 0) && ('\0' != name_tmp[name_len - 1]))
663  {
664  GNUNET_break (0);
665  return GNUNET_SYSERR;
666  }
667  return check_rd (rd_ser_len, &name_tmp[name_len], ntohs (msg->rd_count));
668 }
669 
670 
678 static void
680  const struct ZoneToNameResponseMessage *msg)
681 {
682  struct GNUNET_NAMESTORE_Handle *h = cls;
684  int res;
685  size_t name_len;
686  size_t rd_ser_len;
687  unsigned int rd_count;
688  const char *name_tmp;
689  const char *rd_tmp;
690 
691  LOG (GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_TO_NAME_RESPONSE\n");
692  qe = find_qe (h, ntohl (msg->gns_header.r_id));
693  res = ntohs (msg->res);
694  switch (res)
695  {
696  case GNUNET_SYSERR:
698  "An error occurred during zone to name operation\n");
699  break;
700 
701  case GNUNET_NO:
703  "Namestore has no result for zone to name mapping \n");
704  if (NULL != qe->proc)
705  qe->proc (qe->proc_cls, &msg->zone, NULL, 0, NULL);
706  free_qe (qe);
707  return;
708 
709  case GNUNET_YES:
711  "Namestore has result for zone to name mapping \n");
712  name_len = ntohs (msg->name_len);
713  rd_count = ntohs (msg->rd_count);
714  rd_ser_len = ntohs (msg->rd_len);
715  name_tmp = (const char *) &msg[1];
716  rd_tmp = &name_tmp[name_len];
717  {
718  struct GNUNET_GNSRECORD_Data rd[rd_count];
719 
722  rd_tmp,
723  rd_count,
724  rd));
725  /* normal end, call continuation with result */
726  if (NULL != qe->proc)
727  qe->proc (qe->proc_cls, &msg->zone, name_tmp, rd_count, rd);
728  /* return is important here: break would call continuation with error! */
729  free_qe (qe);
730  return;
731  }
732 
733  default:
734  GNUNET_break (0);
735  force_reconnect (h);
736  return;
737  }
738  /* error case, call continuation with error */
739  if (NULL != qe->error_cb)
740  qe->error_cb (qe->error_cb_cls);
741  free_qe (qe);
742 }
743 
744 
753 static void
754 mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
755 {
756  struct GNUNET_NAMESTORE_Handle *h = cls;
757 
758  (void) error;
759  force_reconnect (h);
760 }
761 
762 
768 static void
770 {
771  struct GNUNET_MQ_MessageHandler handlers[] =
772  { GNUNET_MQ_hd_fixed_size (record_store_response,
775  h),
776  GNUNET_MQ_hd_var_size (zone_to_name_response,
779  h),
780  GNUNET_MQ_hd_var_size (record_result,
782  struct RecordResultMessage,
783  h),
784  GNUNET_MQ_hd_fixed_size (record_result_end,
787  h),
788  GNUNET_MQ_hd_var_size (lookup_result,
791  h),
795 
796  GNUNET_assert (NULL == h->mq);
797  h->mq =
798  GNUNET_CLIENT_connect (h->cfg, "namestore", handlers, &mq_error_handler, h);
799  if (NULL == h->mq)
800  return;
801  /* re-transmit pending requests that waited for a reconnect... */
802  for (it = h->z_head; NULL != it; it = it->next)
803  {
804  GNUNET_MQ_send (h->mq, it->env);
805  it->env = NULL;
806  }
807  for (qe = h->op_head; NULL != qe; qe = qe->next)
808  {
809  GNUNET_MQ_send (h->mq, qe->env);
810  qe->env = NULL;
811  }
812 }
813 
814 
820 static void
821 reconnect_task (void *cls)
822 {
823  struct GNUNET_NAMESTORE_Handle *h = cls;
824 
825  h->reconnect_task = NULL;
826  reconnect (h);
827 }
828 
829 
835 static void
837 {
840 
841  GNUNET_MQ_destroy (h->mq);
842  h->mq = NULL;
843  while (NULL != (ze = h->z_head))
844  {
845  if (NULL != ze->error_cb)
846  ze->error_cb (ze->error_cb_cls);
847  free_ze (ze);
848  }
849  while (NULL != (qe = h->op_head))
850  {
851  if (NULL != qe->error_cb)
852  qe->error_cb (qe->error_cb_cls);
853  if (NULL != qe->cont)
854  qe->cont (qe->cont_cls,
856  "failure in communication with namestore service");
857  free_qe (qe);
858  }
859 
860  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting to namestore\n");
862  h->reconnect_task =
864 }
865 
866 
873 static uint32_t
875 {
876  return h->last_op_id_used++;
877 }
878 
879 
888 {
889  struct GNUNET_NAMESTORE_Handle *h;
890 
891  h = GNUNET_new (struct GNUNET_NAMESTORE_Handle);
892  h->cfg = cfg;
893  reconnect (h);
894  if (NULL == h->mq)
895  {
896  GNUNET_free (h);
897  return NULL;
898  }
899  return h;
900 }
901 
902 
909 void
911 {
914 
915  LOG (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
916  GNUNET_break (NULL == h->op_head);
917  while (NULL != (q = h->op_head))
918  {
920  GNUNET_free (q);
921  }
922  GNUNET_break (NULL == h->z_head);
923  while (NULL != (z = h->z_head))
924  {
926  GNUNET_free (z);
927  }
928  if (NULL != h->mq)
929  {
930  GNUNET_MQ_destroy (h->mq);
931  h->mq = NULL;
932  }
933  if (NULL != h->reconnect_task)
934  {
936  h->reconnect_task = NULL;
937  }
938  GNUNET_free (h);
939 }
940 
941 
948 static void
949 warn_delay (void *cls)
950 {
951  struct GNUNET_NAMESTORE_QueueEntry *qe = cls;
952 
953  qe->timeout_task = NULL;
955  "Did not receive response from namestore after %s!\n",
957  GNUNET_YES));
958  if (NULL != qe->cont)
959  {
960  qe->cont (qe->cont_cls, GNUNET_SYSERR, "timeout");
961  qe->cont = NULL;
962  }
964 }
965 
966 
983  struct GNUNET_NAMESTORE_Handle *h,
984  const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
985  const char *label,
986  unsigned int rd_count,
987  const struct GNUNET_GNSRECORD_Data *rd,
989  void *cont_cls)
990 {
992  struct GNUNET_MQ_Envelope *env;
993  char *name_tmp;
994  char *rd_ser;
995  ssize_t rd_ser_len;
996  size_t name_len;
997  uint32_t rid;
998  struct RecordStoreMessage *msg;
999  ssize_t sret;
1000 
1001  name_len = strlen (label) + 1;
1002  if (name_len > MAX_NAME_LEN)
1003  {
1004  GNUNET_break (0);
1005  return NULL;
1006  }
1007  rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count, rd);
1008  if (rd_ser_len < 0)
1009  {
1010  GNUNET_break (0);
1011  return NULL;
1012  }
1013  if (rd_ser_len > UINT16_MAX)
1014  {
1015  GNUNET_break (0);
1016  return NULL;
1017  }
1018  rid = get_op_id (h);
1020  qe->h = h;
1021  qe->cont = cont;
1022  qe->cont_cls = cont_cls;
1023  qe->op_id = rid;
1025 
1026  /* setup msg */
1027  env = GNUNET_MQ_msg_extra (msg,
1028  name_len + rd_ser_len,
1030  msg->gns_header.r_id = htonl (rid);
1031  msg->name_len = htons (name_len);
1032  msg->rd_count = htons (rd_count);
1033  msg->rd_len = htons (rd_ser_len);
1034  msg->reserved = htons (0);
1035  msg->private_key = *pkey;
1036 
1037  name_tmp = (char *) &msg[1];
1038  GNUNET_memcpy (name_tmp, label, name_len);
1039  rd_ser = &name_tmp[name_len];
1040  sret = GNUNET_GNSRECORD_records_serialize (rd_count, rd, rd_ser_len, rd_ser);
1041  if ((0 > sret) || (sret != rd_ser_len))
1042  {
1043  GNUNET_break (0);
1044  GNUNET_free (env);
1045  return NULL;
1046  }
1047  GNUNET_assert (rd_ser_len == sret);
1049  "Sending NAMESTORE_RECORD_STORE message for name `%s' with %u records\n",
1050  label,
1051  rd_count);
1052  qe->timeout_task =
1054  if (NULL == h->mq)
1055  {
1056  qe->env = env;
1058  "Delaying NAMESTORE_RECORD_STORE message as namestore is not ready!\n");
1059  }
1060  else
1061  {
1062  GNUNET_MQ_send (h->mq, env);
1063  }
1064  return qe;
1065 }
1066 
1067 
1082  struct GNUNET_NAMESTORE_Handle *h,
1083  const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
1084  const char *label,
1086  void *error_cb_cls,
1088  void *rm_cls)
1089 {
1091  struct GNUNET_MQ_Envelope *env;
1092  struct LabelLookupMessage *msg;
1093  size_t label_len;
1094 
1095  if (1 == (label_len = strlen (label) + 1))
1096  {
1097  GNUNET_break (0);
1098  return NULL;
1099  }
1100 
1102  qe->h = h;
1103  qe->error_cb = error_cb;
1104  qe->error_cb_cls = error_cb_cls;
1105  qe->proc = rm;
1106  qe->proc_cls = rm_cls;
1107  qe->op_id = get_op_id (h);
1109 
1110  env = GNUNET_MQ_msg_extra (msg,
1111  label_len,
1113  msg->gns_header.r_id = htonl (qe->op_id);
1114  msg->zone = *pkey;
1115  msg->label_len = htonl (label_len);
1116  GNUNET_memcpy (&msg[1], label, label_len);
1117  if (NULL == h->mq)
1118  qe->env = env;
1119  else
1120  GNUNET_MQ_send (h->mq, env);
1121  return qe;
1122 }
1123 
1124 
1142  struct GNUNET_NAMESTORE_Handle *h,
1143  const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
1144  const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone,
1146  void *error_cb_cls,
1148  void *proc_cls)
1149 {
1151  struct GNUNET_MQ_Envelope *env;
1152  struct ZoneToNameMessage *msg;
1153  uint32_t rid;
1154 
1155  rid = get_op_id (h);
1157  qe->h = h;
1158  qe->error_cb = error_cb;
1159  qe->error_cb_cls = error_cb_cls;
1160  qe->proc = proc;
1161  qe->proc_cls = proc_cls;
1162  qe->op_id = rid;
1164 
1166  msg->gns_header.r_id = htonl (rid);
1167  msg->zone = *zone;
1168  msg->value_zone = *value_zone;
1169  if (NULL == h->mq)
1170  qe->env = env;
1171  else
1172  GNUNET_MQ_send (h->mq, env);
1173  return qe;
1174 }
1175 
1176 
1198  struct GNUNET_NAMESTORE_Handle *h,
1199  const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
1201  void *error_cb_cls,
1203  void *proc_cls,
1205  void *finish_cb_cls)
1206 {
1207  struct GNUNET_NAMESTORE_ZoneIterator *it;
1208  struct GNUNET_MQ_Envelope *env;
1210  uint32_t rid;
1211 
1212  LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_START message\n");
1213  rid = get_op_id (h);
1215  it->h = h;
1216  it->error_cb = error_cb;
1217  it->error_cb_cls = error_cb_cls;
1218  it->finish_cb = finish_cb;
1219  it->finish_cb_cls = finish_cb_cls;
1220  it->proc = proc;
1221  it->proc_cls = proc_cls;
1222  it->op_id = rid;
1223  if (NULL != zone)
1224  it->zone = *zone;
1227  msg->gns_header.r_id = htonl (rid);
1228  if (NULL != zone)
1229  msg->zone = *zone;
1230  if (NULL == h->mq)
1231  it->env = env;
1232  else
1233  GNUNET_MQ_send (h->mq, env);
1234  return it;
1235 }
1236 
1237 
1246 void
1248  uint64_t limit)
1249 {
1250  struct GNUNET_NAMESTORE_Handle *h = it->h;
1251  struct ZoneIterationNextMessage *msg;
1252  struct GNUNET_MQ_Envelope *env;
1253 
1255  "Sending ZONE_ITERATION_NEXT message with limit %llu\n",
1256  (unsigned long long) limit);
1258  msg->gns_header.r_id = htonl (it->op_id);
1259  msg->limit = GNUNET_htonll (limit);
1260  GNUNET_MQ_send (h->mq, env);
1261 }
1262 
1263 
1269 void
1271 {
1272  struct GNUNET_NAMESTORE_Handle *h = it->h;
1273  struct GNUNET_MQ_Envelope *env;
1274  struct ZoneIterationStopMessage *msg;
1275 
1276  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_STOP message\n");
1277  if (NULL != h->mq)
1278  {
1279  env =
1281  msg->gns_header.r_id = htonl (it->op_id);
1282  GNUNET_MQ_send (h->mq, env);
1283  }
1284  free_ze (it);
1285 }
1286 
1287 
1294 void
1296 {
1297  free_qe (qe);
1298 }
1299 
1300 
1301 /* end of namestore_api.c */
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_NAMESTORE_Handle * h
Main handle to access the namestore.
Definition: namestore_api.c:68
struct GNUNET_NAMESTORE_Header gns_header
Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE.
Definition: namestore.h:110
struct GNUNET_NAMESTORE_Header gns_header
Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE.
Definition: namestore.h:63
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
GNUNET_SCHEDULER_TaskCallback error_cb
Function to call on errors.
GNUNET_NETWORK_STRUCT_END ssize_t GNUNET_GNSRECORD_records_get_size(unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Calculate how many bytes we will need to serialize the given records.
struct GNUNET_MQ_Envelope * env
Envelope of the message to send to the service, if not yet sent.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
void(* GNUNET_NAMESTORE_ContinuationWithStatus)(void *cls, int32_t success, const char *emsg)
Continuation called to notify client about result of the operation.
uint32_t label_len
Length of the name.
Definition: namestore.h:132
static char * pkey
Public key of the zone to look in, in ASCII.
static void handle_lookup_result(void *cls, const struct LabelLookupResponseMessage *msg)
Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE
Service to client: result of zone-to-name lookup.
GNUNET_SCHEDULER_TaskCallback finish_cb
Function to call on completion.
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:1063
static int check_zone_to_name_response(void *cls, const struct ZoneToNameResponseMessage *msg)
Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE.
GNUNET_NAMESTORE_RecordMonitor proc
Function to call with the records we get back; or NULL.
Definition: namestore_api.c:83
Ask for next result of zone iteration for the given operation.
Definition: namestore.h:362
uint16_t rd_len
Length of serialized record data.
Definition: namestore.h:163
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_lookup(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, const char *label, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor rm, void *rm_cls)
Lookup an item in the namestore.
GNUNET_MQ_Error
Error codes for the queue.
ssize_t GNUNET_GNSRECORD_records_serialize(unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, size_t dest_size, char *dest)
Serialize the given records to the given destination buffer.
struct GNUNET_NAMESTORE_ZoneIterator * GNUNET_NAMESTORE_zone_iteration_start(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor proc, void *proc_cls, GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls)
Starts a new zone iteration (used to periodically PUT all of our records into our DHT)...
GNUNET_NAMESTORE_RecordMonitor proc
The continuation to call with the results.
uint16_t reserved
always zero (for alignment)
Definition: namestore.h:281
uint32_t r_id
Request ID in NBO.
Definition: namestore.h:51
uint16_t rd_count
Number of records contained.
Definition: namestore.h:168
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
GNUNET_SCHEDULER_TaskCallback error_cb
Function to call on errors.
Definition: namestore_api.c:93
struct GNUNET_NAMESTORE_QueueEntry * prev
Kept in a DLL.
Definition: namestore_api.c:63
uint32_t op_id
The operation id this zone iteration operation has.
Start a zone iteration for the given zone.
Definition: namestore.h:345
void * proc_cls
Closure for proc.
struct GNUNET_NAMESTORE_Header gns_header
Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME.
Definition: namestore.h:196
uint16_t name_len
Length of the name.
Definition: namestore.h:223
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
void(* GNUNET_NAMESTORE_RecordMonitor)(void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Process a record that was stored in the namestore.
static void handle_record_store_response(void *cls, const struct RecordStoreResponseMessage *msg)
Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
int16_t res
result in NBO: GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error ...
Definition: namestore.h:239
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void GNUNET_NAMESTORE_zone_iterator_next(struct GNUNET_NAMESTORE_ZoneIterator *it, uint64_t limit)
Calls the record processor specified in GNUNET_NAMESTORE_zone_iteration_start for the next record...
static void handle_record_result_end(void *cls, const struct GNUNET_NAMESTORE_Header *msg)
Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT_END.
Private ECC key encoded for transmission.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT_END
Service to client: end of list of results.
int GNUNET_GNSRECORD_records_deserialize(size_t len, const char *src, unsigned int rd_count, struct GNUNET_GNSRECORD_Data *dest)
Deserialize the given records to the given destination.
void * error_cb_cls
Closure for error_cb.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP
Client to service: lookup label.
void * proc_cls
Closure for proc.
Definition: namestore_api.c:88
void * error_cb_cls
Closure for error_cb.
Definition: namestore_api.c:98
#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP
Client to service: stop iterating.
uint16_t reserved
always zero (for alignment)
Definition: namestore.h:88
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
uint32_t last_op_id_used
The last operation id used for a NAMESTORE operation.
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
static int check_record_result(void *cls, const struct RecordResultMessage *msg)
Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT.
void GNUNET_NAMESTORE_cancel(struct GNUNET_NAMESTORE_QueueEntry *qe)
Cancel a namestore operation.
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
static void free_ze(struct GNUNET_NAMESTORE_ZoneIterator *ze)
Free ze.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_store(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls)
Store an item in the namestore.
uint16_t name_len
Name length.
Definition: namestore.h:266
common internal definitions for namestore service
static char * zone
Name of the zone we manage.
uint16_t rd_count
Number of records contained.
Definition: namestore.h:233
int32_t op_result
GNUNET_SYSERR on failure, GNUNET_OK on success
Definition: namestore.h:115
struct GNUNET_MessageHeader header
header.type will be GNUNET_MESSAGE_TYPE_NAMESTORE_* header.size will be message size ...
Definition: namestore.h:46
struct GNUNET_CRYPTO_EcdsaPrivateKey private_key
The private key of the authority.
Definition: namestore.h:286
void GNUNET_NAMESTORE_disconnect(struct GNUNET_NAMESTORE_Handle *h)
Disconnect from the namestore service (and free associated resources).
cryptographic primitives for GNUnet
struct GNUNET_CRYPTO_EcdsaPublicKey value_zone
The public key of the target zone.
Definition: namestore.h:206
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
Handle for a zone iterator operation.
struct GNUNET_NAMESTORE_QueueEntry * next
Kept in a DLL.
Definition: namestore_api.c:58
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1269
struct GNUNET_TIME_Relative reconnect_delay
Delay introduced before we reconnect.
static int check_rd(size_t rd_len, const void *rd_buf, unsigned int rd_count)
Check that rd_buf of lenght rd_len contains rd_count records.
uint16_t rd_len
Length of serialized record data.
Definition: namestore.h:78
uint16_t rd_count
Number of records contained.
Definition: namestore.h:276
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE
Client to service: store records (as authority)
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
static void handle_record_result(void *cls, const struct RecordResultMessage *msg)
Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT.
Connection to the NAMESTORE service.
struct GNUNET_MQ_Handle * mq
Connection to the service (if available).
static void force_reconnect(struct GNUNET_NAMESTORE_Handle *h)
Disconnect from service and then reconnect.
static struct GNUNET_NAMESTORE_ZoneIterator * find_zi(struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
Find the zone iteration entry that matches the rid.
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:702
#define NAMESTORE_DELAY_TOLERANCE
We grant the namestore up to 1 minute of latency, if it is slower than that, store queries will fail...
Definition: namestore_api.c:47
Stop zone iteration for the given operation.
Definition: namestore.h:381
uint16_t name_len
Name length.
Definition: namestore.h:73
struct GNUNET_MQ_Envelope * env
Envelope of the message to send to the service, if not yet sent.
uint16_t name_len
Name length.
Definition: namestore.h:158
void GNUNET_NAMESTORE_zone_iteration_stop(struct GNUNET_NAMESTORE_ZoneIterator *it)
Stops iteration and releases the namestore handle for further calls.
struct GNUNET_NAMESTORE_Header gns_header
Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START.
Definition: namestore.h:350
Message handler for a specific message type.
static int res
static void warn_delay(void *cls)
Task launched to warn the user that the namestore is excessively slow and that a query was thus dropp...
uint16_t rd_count
Number of records contained.
Definition: namestore.h:83
static struct GNUNET_REVOCATION_Query * q
Handle for revocation query.
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition: mq.c:323
#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME
Client to service: "reverse" lookup for zone name based on zone key.
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:36
struct GNUNET_NAMESTORE_QueueEntry * op_tail
Tail of pending namestore queue entries.
struct GNUNET_NAMESTORE_ZoneIterator * next
Kept in a DLL.
struct GNUNET_CRYPTO_EcdsaPrivateKey zone
The private key of the zone that contained the name.
Definition: namestore.h:244
#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START
Client to service: please start iteration; receives "GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPON...
#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT
Client to service: next record(s) in iteration please.
An QueueEntry used to store information for a pending NAMESTORE record operation. ...
Definition: namestore_api.c:53
struct GNUNET_NAMESTORE_Handle * h
Main handle to access the namestore.
struct GNUNET_NAMESTORE_Handle * GNUNET_NAMESTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the connection with the NAMESTORE service.
struct GNUNET_NAMESTORE_ZoneIterator * prev
Kept in a DLL.
uint32_t op_id
The operation id this zone iteration operation has.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
uint16_t found
Was the label found in the database?? GNUNET_YES or GNUNET_NO.
Definition: namestore.h:174
uint16_t rd_len
Length of serialized record data.
Definition: namestore.h:271
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
GNUNET_NAMESTORE_ContinuationWithStatus cont
Continuation to call.
Definition: namestore_api.c:73
static void reconnect(struct GNUNET_NAMESTORE_Handle *h)
Reconnect to namestore service.
struct GNUNET_NAMESTORE_Header gns_header
Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT.
Definition: namestore.h:261
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
static void free_qe(struct GNUNET_NAMESTORE_QueueEntry *qe)
Free qe.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE
Service to client: lookup label.
int reconnect
Should we reconnect to service due to some serious error?
#define LOG(kind,...)
Definition: namestore_api.c:41
Handle to a message queue.
Definition: mq.c:85
struct GNUNET_NAMESTORE_Header gns_header
Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE.
Definition: namestore.h:218
struct GNUNET_CRYPTO_EcdsaPrivateKey private_key
The private key of the authority.
Definition: namestore.h:93
void * finish_cb_cls
Closure for error_cb.
Store a record to the namestore (as authority).
Definition: namestore.h:58
Respone for zone to name lookup.
Definition: namestore.h:213
void * cont_cls
Closure for cont.
Definition: namestore_api.c:78
struct GNUNET_CRYPTO_EcdsaPrivateKey zone
The private key of the zone to look up in.
Definition: namestore.h:201
struct GNUNET_NAMESTORE_Header gns_header
Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE.
Definition: namestore.h:153
configuration data
Definition: configuration.c:84
const char * name
Response to a record storage request.
Definition: namestore.h:105
struct GNUNET_NAMESTORE_QueueEntry * op_head
Head of pending namestore queue entries.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
struct GNUNET_NAMESTORE_ZoneIterator * z_head
Head of pending namestore zone iterator entries.
#define MAX_NAME_LEN
Maximum length of any name, including 0-termination.
Definition: namecache.h:33
static uint32_t get_op_id(struct GNUNET_NAMESTORE_Handle *h)
Get a fresh operation id to distinguish between namestore requests.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_zone_to_name(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor proc, void *proc_cls)
Look for an existing PKEY delegation record for a given public key.
#define GNUNET_log(kind,...)
struct GNUNET_CRYPTO_EcdsaPrivateKey private_key
The private key of the authority.
Definition: namestore.h:179
Entry in list of pending tasks.
Definition: scheduler.c:134
Generic namestore message with op id.
Definition: namestore.h:40
static void handle_zone_to_name_response(void *cls, const struct ZoneToNameResponseMessage *msg)
Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE.
struct GNUNET_SCHEDULER_Task * timeout_task
Task scheduled to warn us if the namestore is way too slow.
uint16_t rd_len
Length of serialized record data.
Definition: namestore.h:228
struct GNUNET_NAMESTORE_Header gns_header
Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP.
Definition: namestore.h:127
Lookup a name for a zone hash.
Definition: namestore.h:191
Lookup a label.
Definition: namestore.h:122
struct GNUNET_SCHEDULER_Task * reconnect_task
Reconnect task.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:837
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:355
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT
Service to client: here is a (plaintext) record you requested.
struct GNUNET_NAMESTORE_ZoneIterator * z_tail
Tail of pending namestore zone iterator entries.
Record is returned from the namestore (as authority).
Definition: namestore.h:256
uint64_t limit
Number of records to return to the iterator in one shot (before GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_IT...
Definition: namestore.h:374
static struct GNUNET_NAMESTORE_QueueEntry * find_qe(struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
Find the queue entry that matches the rid.
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
struct GNUNET_CRYPTO_EcdsaPrivateKey zone
Zone key.
Definition: namestore.h:355
struct GNUNET_NAMESTORE_Header gns_header
Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT.
Definition: namestore.h:367
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
struct GNUNET_NAMESTORE_Header gns_header
Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP.
Definition: namestore.h:386
Lookup a label.
Definition: namestore.h:148
static int check_lookup_result(void *cls, const struct LabelLookupResponseMessage *msg)
Check validity of an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE.
struct GNUNET_CRYPTO_EcdsaPrivateKey zone
The private key of the zone to look up in.
Definition: namestore.h:137
static void reconnect_task(void *cls)
Re-establish the connection to the service.
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE
Service to client: result of store operation.
struct GNUNET_CRYPTO_EcdsaPrivateKey zone
Private key of the zone.