GNUnet  0.19.5
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_error_codes.h"
31 #include "gnunet_util_lib.h"
32 #include "gnunet_constants.h"
33 #include "gnunet_arm_service.h"
34 #include "gnunet_signatures.h"
35 #include "gnunet_gns_service.h"
37 #include "namestore.h"
38 
39 
40 #define LOG(kind, ...) GNUNET_log_from (kind, "namestore-api", __VA_ARGS__)
41 
46 #define NAMESTORE_DELAY_TOLERANCE GNUNET_TIME_UNIT_MINUTES
47 
53 {
58 
63 
68 
73 
77  void *cont_cls;
78 
83 
88 
92  void *proc_cls;
93 
98 
103 
109 
114 
118  uint32_t op_id;
119 };
120 
121 
126 {
131 
136 
141 
146 
151 
156 
161 
165  void *proc_cls;
166 
171 
176 
182 
187 
191  uint32_t op_id;
192 };
193 
194 
199 {
204 
209 
214 
219 
224 
229 
234 
239 
244 
248  uint32_t last_op_id_used;
249 };
250 
251 
257 static void
259 
260 
268 static struct GNUNET_NAMESTORE_QueueEntry *
269 find_qe (struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
270 {
272 
273  for (qe = h->op_head; qe != NULL; qe = qe->next)
274  if (qe->op_id == rid)
275  return qe;
276  return NULL;
277 }
278 
279 
287 static struct GNUNET_NAMESTORE_ZoneIterator *
288 find_zi (struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
289 {
291 
292  for (ze = h->z_head; ze != NULL; ze = ze->next)
293  if (ze->op_id == rid)
294  return ze;
295  return NULL;
296 }
297 
298 
304 static void
306 {
307  struct GNUNET_NAMESTORE_Handle *h = qe->h;
308 
309  GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, qe);
310  if (NULL != qe->env)
312  if (NULL != qe->timeout_task)
313  GNUNET_SCHEDULER_cancel (qe->timeout_task);
314  GNUNET_free (qe);
315 }
316 
317 
323 static void
325 {
326  struct GNUNET_NAMESTORE_Handle *h = ze->h;
327 
328  GNUNET_CONTAINER_DLL_remove (h->z_head, h->z_tail, ze);
329  if (NULL != ze->env)
330  GNUNET_MQ_discard (ze->env);
331  GNUNET_free (ze);
332 }
333 
334 
344 static int
345 check_rd (size_t rd_len, const void *rd_buf, unsigned int rd_count)
346 {
348 
349  if (GNUNET_OK !=
351  {
352  GNUNET_break (0);
353  return GNUNET_SYSERR;
354  }
355  return GNUNET_OK;
356 }
357 
365 static void
367  const struct RecordStoreResponseMessage *msg)
368 {
369  struct GNUNET_NAMESTORE_Handle *h = cls;
371  enum GNUNET_ErrorCode res;
372 
373  qe = find_qe (h, ntohl (msg->gns_header.r_id));
374  res = ntohl (msg->ec);
376  "Received RECORD_STORE_RESPONSE with result %d\n",
377  res);
378  if (NULL == qe)
379  return;
380  if (NULL != qe->cont)
381  qe->cont (qe->cont_cls, res);
382  free_qe (qe);
383 }
384 
385 
394 static int
396 {
397  const char *name;
398  size_t exp_msg_len;
399  size_t msg_len;
400  size_t name_len;
401  size_t rd_len;
402  size_t key_len;
403 
404  (void) cls;
405  rd_len = ntohs (msg->rd_len);
406  msg_len = ntohs (msg->gns_header.header.size);
407  name_len = ntohs (msg->name_len);
408  key_len = ntohs (msg->key_len);
409  exp_msg_len = sizeof(*msg) + name_len + rd_len + key_len;
410  if (0 != ntohs (msg->reserved))
411  {
412  GNUNET_break (0);
413  return GNUNET_SYSERR;
414  }
415  if (msg_len != exp_msg_len)
416  {
417  GNUNET_break (0);
418  return GNUNET_SYSERR;
419  }
420  name = (const char *) &msg[1] + key_len;
421  if ((name_len > 0) && ('\0' != name[name_len - 1]))
422  {
423  GNUNET_break (0);
424  return GNUNET_SYSERR;
425  }
426  if (GNUNET_NO == ntohs (msg->found))
427  {
428  if (0 != ntohs (msg->rd_count))
429  {
430  GNUNET_break (0);
431  return GNUNET_SYSERR;
432  }
433  return GNUNET_OK;
434  }
435  return check_rd (rd_len, &name[name_len], ntohs (msg->rd_count));
436 }
437 
438 
446 static void
448 {
449  struct GNUNET_NAMESTORE_Handle *h = cls;
451  struct GNUNET_IDENTITY_PrivateKey private_key;
452  const char *name;
453  const char *rd_tmp;
454  size_t name_len;
455  size_t rd_len;
456  size_t key_len;
457  size_t kbytes_read;
458  unsigned int rd_count;
459  int16_t found = (int16_t) ntohs (msg->found);
460 
461  LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_LOOKUP_RESULT (found=%i)\n",
462  found);
463  qe = find_qe (h, ntohl (msg->gns_header.r_id));
464  if (NULL == qe)
465  return;
466  rd_len = ntohs (msg->rd_len);
467  rd_count = ntohs (msg->rd_count);
468  name_len = ntohs (msg->name_len);
469  key_len = ntohs (msg->key_len);
472  key_len,
473  &private_key,
474  &kbytes_read));
475  GNUNET_assert (kbytes_read == key_len);
476  name = (const char *) &msg[1] + key_len;
477  if (GNUNET_NO == found)
478  {
479  /* label was not in namestore */
480  if (NULL != qe->proc)
481  qe->proc (qe->proc_cls, &private_key, name, 0, NULL);
482  free_qe (qe);
483  return;
484  }
485  if (GNUNET_SYSERR == found)
486  {
487  if (NULL != qe->error_cb)
488  qe->error_cb (qe->error_cb_cls);
489  free_qe (qe);
490  return;
491  }
492 
493  rd_tmp = &name[name_len];
494  {
496 
497  GNUNET_assert (
498  GNUNET_OK ==
500  if (0 == name_len)
501  name = NULL;
502  if (NULL != qe->proc)
503  qe->proc (qe->proc_cls,
504  &private_key,
505  name,
506  rd_count,
507  (rd_count > 0) ? rd : NULL);
508  }
509  free_qe (qe);
510 }
511 
512 
521 static int
522 check_record_result (void *cls, const struct RecordResultMessage *msg)
523 {
524  const char *name;
525  size_t msg_len;
526  size_t name_len;
527  size_t rd_len;
528  size_t key_len;
529 
530  (void) cls;
531  rd_len = ntohs (msg->rd_len);
532  msg_len = ntohs (msg->gns_header.header.size);
533  key_len = ntohs (msg->key_len);
534  name_len = ntohs (msg->name_len);
535  if (msg_len != sizeof(struct RecordResultMessage) + key_len + name_len
536  + rd_len)
537  {
538  GNUNET_break (0);
539  return GNUNET_SYSERR;
540  }
541  name = (const char *) &msg[1] + key_len;
542  if ((0 == name_len) || ('\0' != name[name_len - 1]))
543  {
544  GNUNET_break (0);
545  return GNUNET_SYSERR;
546  }
547  if (0 == key_len)
548  {
549  GNUNET_break (0);
550  return GNUNET_SYSERR;
551  }
552  return check_rd (rd_len, &name[name_len], ntohs (msg->rd_count));
553 }
554 
555 
563 static void
564 handle_record_result (void *cls, const struct RecordResultMessage *msg)
565 {
566  struct GNUNET_NAMESTORE_Handle *h = cls;
569  struct GNUNET_IDENTITY_PrivateKey private_key;
570  const char *name;
571  const char *rd_tmp;
572  size_t name_len;
573  size_t rd_len;
574  size_t key_len;
575  size_t kbytes_read;
576  unsigned int rd_count;
577 
578  LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_RESULT\n");
579  rd_len = ntohs (msg->rd_len);
580  rd_count = ntohs (msg->rd_count);
581  name_len = ntohs (msg->name_len);
582  key_len = ntohs (msg->key_len);
583  ze = find_zi (h, ntohl (msg->gns_header.r_id));
584  qe = find_qe (h, ntohl (msg->gns_header.r_id));
585  if ((NULL == ze) && (NULL == qe))
586  return; /* rid not found */
587  if ((NULL != ze) && (NULL != qe))
588  {
589  GNUNET_break (0); /* rid ambiguous */
590  force_reconnect (h);
591  return;
592  }
593  name = (const char *) &msg[1] + key_len;
596  key_len,
597  &private_key,
598  &kbytes_read));
599  GNUNET_assert (kbytes_read == key_len);
600  rd_tmp = &name[name_len];
601  {
603 
604  GNUNET_assert (
605  GNUNET_OK ==
607  if (0 == name_len)
608  name = NULL;
609  if (NULL != qe)
610  {
611  if (NULL != qe->proc)
612  qe->proc (qe->proc_cls,
613  &private_key,
614  name,
615  rd_count,
616  (rd_count > 0) ? rd : NULL);
617  free_qe (qe);
618  return;
619  }
620  if (NULL != ze)
621  {
622  // Store them here because a callback could free ze
625  void *proc_cls = ze->proc_cls;
626  proc = ze->proc;
627  proc2 = ze->proc2;
628  if (NULL != proc)
629  proc (proc_cls, &private_key, name, rd_count, rd);
630  if (NULL != proc2)
631  proc2 (proc_cls, &private_key, name,
633  return;
634  }
635  }
636  GNUNET_assert (0);
637 }
638 
639 
647 static void
649 {
650  struct GNUNET_NAMESTORE_Handle *h = cls;
653 
654  LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_RESULT_END\n");
655  ze = find_zi (h, ntohl (msg->r_id));
656  qe = find_qe (h, ntohl (msg->r_id));
657  if ((NULL == ze) && (NULL == qe))
658  return; /* rid not found */
659  if ((NULL != ze) && (NULL != qe))
660  {
661  GNUNET_break (0); /* rid ambiguous */
662  force_reconnect (h);
663  return;
664  }
665  LOG (GNUNET_ERROR_TYPE_DEBUG, "Zone iteration completed!\n");
666  if (NULL == ze)
667  {
668  GNUNET_break (0);
669  force_reconnect (h);
670  return;
671  }
672  if (NULL != ze->finish_cb)
673  ze->finish_cb (ze->finish_cb_cls);
674  free_ze (ze);
675 }
676 
677 static void
679  const struct TxControlResultMessage *msg)
680 {
681  struct GNUNET_NAMESTORE_Handle *h = cls;
683  enum GNUNET_ErrorCode res;
684 
685  qe = find_qe (h, ntohl (msg->gns_header.r_id));
686  res = ntohs (msg->ec);
688  "Received TX_CONTROL_RESULT with result %d\n",
689  res);
690  if (NULL == qe)
691  return;
692  if (NULL != qe->cont)
693  qe->cont (qe->cont_cls, res);
694  free_qe (qe);
695 }
696 
705 static int
707  const struct ZoneToNameResponseMessage *msg)
708 {
709  size_t name_len;
710  size_t rd_ser_len;
711  size_t key_len;
712  const char *name_tmp;
713 
714  (void) cls;
715  if (GNUNET_EC_NONE != ntohl (msg->ec))
716  return GNUNET_OK;
717  key_len = ntohs (msg->key_len);
718  name_len = ntohs (msg->name_len);
719  rd_ser_len = ntohs (msg->rd_len);
720  if (ntohs (msg->gns_header.header.size) !=
721  sizeof(struct ZoneToNameResponseMessage) + key_len + name_len
722  + rd_ser_len)
723  {
724  GNUNET_break (0);
725  return GNUNET_SYSERR;
726  }
727  name_tmp = (const char *) &msg[1] + key_len;
728  if ((name_len > 0) && ('\0' != name_tmp[name_len - 1]))
729  {
730  GNUNET_break (0);
731  return GNUNET_SYSERR;
732  }
733  return check_rd (rd_ser_len, &name_tmp[name_len], ntohs (msg->rd_count));
734 }
735 
736 
744 static void
746  const struct ZoneToNameResponseMessage *msg)
747 {
748  struct GNUNET_NAMESTORE_Handle *h = cls;
751  enum GNUNET_ErrorCode res;
752  size_t name_len;
753  size_t rd_ser_len;
754  unsigned int rd_count;
755  const char *name_tmp;
756  const char *rd_tmp;
757  size_t key_len;
758  size_t kbytes_read;
759 
760  LOG (GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_TO_NAME_RESPONSE\n");
761  qe = find_qe (h, ntohl (msg->gns_header.r_id));
762  if (NULL == qe)
763  {
765  "Response queue already gone...\n");
766  return;
767  }
768  res = ntohl (msg->ec);
769  key_len = ntohs (msg->key_len);
772  key_len,
773  &zone,
774  &kbytes_read));
775  GNUNET_assert (kbytes_read == key_len);
776  switch (res)
777  {
778  break;
779 
782  "Namestore has no result for zone to name mapping \n");
783  if (NULL != qe->proc)
784  qe->proc (qe->proc_cls, &zone, NULL, 0, NULL);
785  free_qe (qe);
786  return;
787 
788  case GNUNET_EC_NONE:
790  "Namestore has result for zone to name mapping \n");
791  name_len = ntohs (msg->name_len);
792  rd_count = ntohs (msg->rd_count);
793  rd_ser_len = ntohs (msg->rd_len);
794  name_tmp = (const char *) &msg[1] + key_len;
795  rd_tmp = &name_tmp[name_len];
796  {
798 
801  rd_tmp,
802  rd_count,
803  rd));
804  /* normal end, call continuation with result */
805  if (NULL != qe->proc)
806  qe->proc (qe->proc_cls, &zone, name_tmp, rd_count, rd);
807  /* return is important here: break would call continuation with error! */
808  free_qe (qe);
809  return;
810  }
811 
812  default:
814  "An error occurred during zone to name operation: %s\n",
816  break;
817  }
818  /* error case, call continuation with error */
819  if (NULL != qe->error_cb)
820  qe->error_cb (qe->error_cb_cls);
821  free_qe (qe);
822 }
823 
824 
833 static void
834 mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
835 {
836  struct GNUNET_NAMESTORE_Handle *h = cls;
837 
838  (void) error;
839  force_reconnect (h);
840 }
841 
842 
848 static void
850 {
852  { GNUNET_MQ_hd_fixed_size (record_store_response,
855  h),
856  GNUNET_MQ_hd_var_size (zone_to_name_response,
859  h),
860  GNUNET_MQ_hd_var_size (record_result,
862  struct RecordResultMessage,
863  h),
864  GNUNET_MQ_hd_fixed_size (record_result_end,
867  h),
868  GNUNET_MQ_hd_var_size (lookup_result,
871  h),
872  GNUNET_MQ_hd_fixed_size (tx_control_result,
874  struct TxControlResultMessage,
875  h),
879 
880  GNUNET_assert (NULL == h->mq);
881  h->mq =
883  if (NULL == h->mq)
884  return;
885  /* re-transmit pending requests that waited for a reconnect... */
886  for (it = h->z_head; NULL != it; it = it->next)
887  {
888  GNUNET_MQ_send (h->mq, it->env);
889  it->env = NULL;
890  }
891  for (qe = h->op_head; NULL != qe; qe = qe->next)
892  {
893  GNUNET_MQ_send (h->mq, qe->env);
894  qe->env = NULL;
895  }
896 }
897 
898 
904 static void
905 reconnect_task (void *cls)
906 {
907  struct GNUNET_NAMESTORE_Handle *h = cls;
908 
909  h->reconnect_task = NULL;
910  reconnect (h);
911 }
912 
913 
919 static void
921 {
924 
926  h->mq = NULL;
927  while (NULL != (ze = h->z_head))
928  {
929  if (NULL != ze->error_cb)
930  ze->error_cb (ze->error_cb_cls);
931  free_ze (ze);
932  }
933  while (NULL != (qe = h->op_head))
934  {
935  if (NULL != qe->error_cb)
936  qe->error_cb (qe->error_cb_cls);
937  if (NULL != qe->cont)
938  qe->cont (qe->cont_cls,
940  free_qe (qe);
941  }
942 
943  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting to namestore\n");
944  h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
945  h->reconnect_task =
946  GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect_task, h);
947 }
948 
949 
956 static uint32_t
958 {
959  return h->last_op_id_used++;
960 }
961 
962 
971 {
972  struct GNUNET_NAMESTORE_Handle *h;
973 
975  h->cfg = cfg;
976  reconnect (h);
977  if (NULL == h->mq)
978  {
979  GNUNET_free (h);
980  return NULL;
981  }
982  return h;
983 }
984 
985 
992 void
994 {
997 
998  LOG (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
999  GNUNET_break (NULL == h->op_head);
1000  while (NULL != (q = h->op_head))
1001  {
1002  GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, q);
1003  GNUNET_free (q);
1004  }
1005  GNUNET_break (NULL == h->z_head);
1006  while (NULL != (z = h->z_head))
1007  {
1008  GNUNET_CONTAINER_DLL_remove (h->z_head, h->z_tail, z);
1009  GNUNET_free (z);
1010  }
1011  if (NULL != h->mq)
1012  {
1013  GNUNET_MQ_destroy (h->mq);
1014  h->mq = NULL;
1015  }
1016  if (NULL != h->reconnect_task)
1017  {
1019  h->reconnect_task = NULL;
1020  }
1021  GNUNET_free (h);
1022 }
1023 
1024 
1031 static void
1032 warn_delay (void *cls)
1033 {
1034  struct GNUNET_NAMESTORE_QueueEntry *qe = cls;
1035 
1036  qe->timeout_task = NULL;
1038  "Did not receive response from namestore after %s!\n",
1040  GNUNET_YES));
1041  if (NULL != qe->cont)
1042  {
1044  qe->cont = NULL;
1045  }
1047 }
1048 
1049 
1052  struct GNUNET_NAMESTORE_Handle *h,
1053  const struct GNUNET_IDENTITY_PrivateKey *pkey,
1054  const char *label,
1055  unsigned int rd_count,
1056  const struct GNUNET_GNSRECORD_Data *rd,
1058  void *cont_cls)
1059 {
1060  struct GNUNET_NAMESTORE_RecordInfo ri;
1061  unsigned int rds_sent;
1062  ri.a_label = label;
1063  ri.a_rd_count = rd_count;
1064  ri.a_rd = (struct GNUNET_GNSRECORD_Data *) rd;
1065  return GNUNET_NAMESTORE_records_store2 (h, pkey, 1, &ri, &rds_sent,
1066  cont, cont_cls);
1067 }
1068 
1071  struct GNUNET_NAMESTORE_Handle *h,
1072  const struct GNUNET_IDENTITY_PrivateKey *pkey,
1073  unsigned int rd_set_count,
1074  const struct GNUNET_NAMESTORE_RecordInfo *record_info,
1075  unsigned int *rds_sent,
1077  void *cont_cls)
1078 {
1080  struct GNUNET_MQ_Envelope *env;
1081  const char *label;
1082  unsigned int rd_count;
1083  const struct GNUNET_GNSRECORD_Data *rd;
1084  char *name_tmp;
1085  char *rd_ser;
1086  ssize_t rd_ser_len[rd_set_count];
1087  size_t name_len;
1088  uint32_t rid;
1089  struct RecordStoreMessage *msg;
1090  struct RecordSet *rd_set;
1091  ssize_t sret;
1092  int i;
1093  size_t rd_set_len = 0;
1094  size_t key_len = 0;
1095  size_t max_len;
1097  max_len = UINT16_MAX - key_len - sizeof (struct RecordStoreMessage);
1098 
1099  *rds_sent = 0;
1100  for (i = 0; i < rd_set_count; i++)
1101  {
1102  label = record_info[i].a_label;
1103  rd_count = record_info[i].a_rd_count;
1104  rd = record_info[i].a_rd;
1105  name_len = strlen (label) + 1;
1106  if (name_len > MAX_NAME_LEN)
1107  {
1108  GNUNET_break (0);
1109  *rds_sent = 0;
1110  return NULL;
1111  }
1112  rd_ser_len[i] = GNUNET_GNSRECORD_records_get_size (rd_count, rd);
1113  if (rd_ser_len[i] < 0)
1114  {
1115  GNUNET_break (0);
1116  *rds_sent = 0;
1117  return NULL;
1118  }
1119  if (rd_ser_len[i] > max_len)
1120  {
1121  GNUNET_break (0);
1122  *rds_sent = 0;
1123  return NULL;
1124  }
1125  if ((rd_set_len + sizeof (struct RecordSet) + name_len + rd_ser_len[i]) >
1126  max_len)
1127  break;
1128  rd_set_len += sizeof (struct RecordSet) + name_len + rd_ser_len[i];
1129  }
1130  *rds_sent = i;
1132  "Sending %u of %u records!\n", *rds_sent, rd_set_count);
1133  rid = get_op_id (h);
1135  qe->h = h;
1136  qe->cont = cont;
1137  qe->cont_cls = cont_cls;
1138  qe->op_id = rid;
1139  GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1140  /* setup msg */
1142  key_len + rd_set_len,
1144  GNUNET_assert (NULL != msg);
1145  GNUNET_assert (NULL != env);
1146  msg->gns_header.r_id = htonl (rid);
1147  msg->key_len = htons (key_len);
1148  msg->rd_set_count = htons ((uint16_t) (*rds_sent));
1150  &msg[1],
1151  key_len);
1152  rd_set = (struct RecordSet*) (((char*) &msg[1]) + key_len);
1153  for (int i = 0; i < *rds_sent; i++)
1154  {
1155  label = record_info[i].a_label;
1156  rd = record_info[i].a_rd;
1157  name_len = strlen (label) + 1;
1158  rd_set->name_len = htons (name_len);
1159  rd_set->rd_count = htons (record_info[i].a_rd_count);
1160  rd_set->rd_len = htons (rd_ser_len[i]);
1161  rd_set->reserved = ntohs (0);
1162  name_tmp = (char *) &rd_set[1];
1163  GNUNET_memcpy (name_tmp, label, name_len);
1164  rd_ser = &name_tmp[name_len];
1165  sret = GNUNET_GNSRECORD_records_serialize (record_info[i].a_rd_count,
1166  rd, rd_ser_len[i], rd_ser);
1167  if ((0 > sret) || (sret != rd_ser_len[i]))
1168  {
1169  GNUNET_break (0);
1170  GNUNET_free (env);
1171  return NULL;
1172  }
1173  // Point to next RecordSet
1174  rd_set = (struct RecordSet*) &name_tmp[name_len + rd_ser_len[i]];
1175  }
1177  "Sending NAMESTORE_RECORD_STORE message for name %u record sets\n",
1178  *rds_sent);
1179  qe->timeout_task =
1181  if (NULL == h->mq)
1182  {
1183  qe->env = env;
1185  "Delaying NAMESTORE_RECORD_STORE message as namestore is not ready!\n");
1186  }
1187  else
1188  {
1189  GNUNET_MQ_send (h->mq, env);
1190  }
1191  return qe;
1192 }
1193 
1194 
1195 static struct GNUNET_NAMESTORE_QueueEntry *
1197  struct GNUNET_NAMESTORE_Handle *h,
1198  const struct GNUNET_IDENTITY_PrivateKey *pkey,
1199  const char *label,
1201  void *error_cb_cls,
1203  void *rm_cls,
1204  int is_edit_request,
1206 {
1208  struct GNUNET_MQ_Envelope *env;
1209  struct LabelLookupMessage *msg;
1210  size_t label_len;
1211  size_t key_len;
1212 
1213  if (1 == (label_len = strlen (label) + 1))
1214  {
1215  GNUNET_break (0);
1216  return NULL;
1217  }
1218 
1220  qe->h = h;
1221  qe->error_cb = error_cb;
1222  qe->error_cb_cls = error_cb_cls;
1223  qe->proc = rm;
1224  qe->proc_cls = rm_cls;
1225  qe->op_id = get_op_id (h);
1226  GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1227 
1230  label_len + key_len,
1232  msg->gns_header.r_id = htonl (qe->op_id);
1234  &msg[1],
1235  key_len);
1236 
1237  msg->key_len = htons (key_len);
1238  msg->is_edit_request = htons (is_edit_request);
1239  msg->label_len = htons (label_len);
1240  msg->filter = htons (filter);
1241  GNUNET_memcpy (((char*) &msg[1]) + key_len, label, label_len);
1242  if (NULL == h->mq)
1243  qe->env = env;
1244  else
1245  GNUNET_MQ_send (h->mq, env);
1246  return qe;
1247 }
1248 
1251  struct GNUNET_NAMESTORE_Handle *h,
1252  const struct GNUNET_IDENTITY_PrivateKey *pkey,
1253  const char *label,
1255  void *error_cb_cls,
1257  void *rm_cls)
1258 {
1259  return records_lookup (h, pkey, label,
1262 
1263 }
1264 
1267  struct GNUNET_NAMESTORE_Handle *h,
1268  const struct GNUNET_IDENTITY_PrivateKey *pkey,
1269  const char *label,
1271  void *error_cb_cls,
1273  void *rm_cls,
1275 {
1276  return records_lookup (h, pkey, label,
1278  rm, rm_cls, GNUNET_NO, filter);
1279 
1280 }
1281 
1282 
1285  struct GNUNET_NAMESTORE_Handle *h,
1286  const struct GNUNET_IDENTITY_PrivateKey *pkey,
1287  const char *label,
1289  void *error_cb_cls,
1291  void *rm_cls)
1292 {
1293  return records_lookup (h, pkey, label,
1296 }
1297 
1300  struct GNUNET_NAMESTORE_Handle *h,
1301  const struct GNUNET_IDENTITY_PrivateKey *zone,
1302  const struct GNUNET_IDENTITY_PublicKey *value_zone,
1304  void *error_cb_cls,
1306  void *proc_cls)
1307 {
1309  struct GNUNET_MQ_Envelope *env;
1310  struct ZoneToNameMessage *msg;
1311  uint32_t rid;
1312  size_t key_len;
1313  ssize_t pkey_len;
1314 
1315  rid = get_op_id (h);
1317  qe->h = h;
1318  qe->error_cb = error_cb;
1319  qe->error_cb_cls = error_cb_cls;
1320  qe->proc = proc;
1321  qe->proc_cls = proc_cls;
1322  qe->op_id = rid;
1323  GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1324 
1329  msg->gns_header.r_id = htonl (rid);
1330  msg->key_len = htons (key_len);
1331  msg->pkey_len = htons (pkey_len);
1334  (char*) &msg[1] + key_len,
1335  pkey_len);
1336  if (NULL == h->mq)
1337  qe->env = env;
1338  else
1339  GNUNET_MQ_send (h->mq, env);
1340  return qe;
1341 }
1342 
1343 
1346  struct GNUNET_NAMESTORE_Handle *h,
1347  const struct GNUNET_IDENTITY_PrivateKey *zone,
1349  void *error_cb_cls,
1351  void *proc_cls,
1353  void *finish_cb_cls)
1354 {
1355  struct GNUNET_NAMESTORE_ZoneIterator *it;
1356  struct GNUNET_MQ_Envelope *env;
1358  uint32_t rid;
1359  size_t key_len = 0;
1360 
1361  LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_START message\n");
1362  rid = get_op_id (h);
1364  it->h = h;
1365  it->error_cb = error_cb;
1366  it->error_cb_cls = error_cb_cls;
1367  it->finish_cb = finish_cb;
1368  it->finish_cb_cls = finish_cb_cls;
1369  it->proc = proc;
1370  it->proc_cls = proc_cls;
1371  it->op_id = rid;
1372  if (NULL != zone)
1373  {
1374  it->zone = *zone;
1376  }
1377  GNUNET_CONTAINER_DLL_insert_tail (h->z_head, h->z_tail, it);
1379  key_len,
1381  msg->gns_header.r_id = htonl (rid);
1382  msg->key_len = htons (key_len);
1383  if (NULL != zone)
1385  if (NULL == h->mq)
1386  it->env = env;
1387  else
1388  GNUNET_MQ_send (h->mq, env);
1389  return it;
1390 }
1391 
1394  struct GNUNET_NAMESTORE_Handle *h,
1395  const struct GNUNET_IDENTITY_PrivateKey *zone,
1397  void *error_cb_cls,
1399  void *proc_cls,
1401  void *finish_cb_cls,
1403 {
1404  struct GNUNET_NAMESTORE_ZoneIterator *it;
1405  struct GNUNET_MQ_Envelope *env;
1407  uint32_t rid;
1408  size_t key_len = 0;
1409 
1410  LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_START message\n");
1411  rid = get_op_id (h);
1413  it->h = h;
1414  it->error_cb = error_cb;
1415  it->error_cb_cls = error_cb_cls;
1416  it->finish_cb = finish_cb;
1417  it->finish_cb_cls = finish_cb_cls;
1418  it->proc2 = proc;
1419  it->proc_cls = proc_cls;
1420  it->op_id = rid;
1421  if (NULL != zone)
1422  {
1423  it->zone = *zone;
1425  }
1426  GNUNET_CONTAINER_DLL_insert_tail (h->z_head, h->z_tail, it);
1428  key_len,
1430  msg->gns_header.r_id = htonl (rid);
1431  msg->key_len = htons (key_len);
1432  msg->filter = htons ((uint16_t) filter);
1433  if (NULL != zone)
1435  if (NULL == h->mq)
1436  it->env = env;
1437  else
1438  GNUNET_MQ_send (h->mq, env);
1439  return it;
1440 }
1441 
1442 
1443 void
1445  uint64_t limit)
1446 {
1447  struct GNUNET_NAMESTORE_Handle *h = it->h;
1448  struct ZoneIterationNextMessage *msg;
1449  struct GNUNET_MQ_Envelope *env;
1450 
1452  "Sending ZONE_ITERATION_NEXT message with limit %llu\n",
1453  (unsigned long long) limit);
1455  msg->gns_header.r_id = htonl (it->op_id);
1456  msg->limit = GNUNET_htonll (limit);
1457  GNUNET_MQ_send (h->mq, env);
1458 }
1459 
1460 
1466 void
1468 {
1469  struct GNUNET_NAMESTORE_Handle *h = it->h;
1470  struct GNUNET_MQ_Envelope *env;
1471  struct ZoneIterationStopMessage *msg;
1472 
1473  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_STOP message\n");
1474  if (NULL != h->mq)
1475  {
1476  env =
1478  msg->gns_header.r_id = htonl (it->op_id);
1479  GNUNET_MQ_send (h->mq, env);
1480  }
1481  free_ze (it);
1482 }
1483 
1484 
1491 void
1493 {
1494  free_qe (qe);
1495 }
1496 
1501 static struct GNUNET_NAMESTORE_QueueEntry *
1504  void *cont_cls,
1505  enum GNUNET_NAMESTORE_TxControl ctrl)
1506 {
1508  struct GNUNET_MQ_Envelope *env;
1509  struct TxControlMessage *msg;
1510  uint32_t rid;
1511 
1512  rid = get_op_id (h);
1514  qe->h = h;
1515  qe->cont = cont;
1516  qe->cont_cls = cont_cls;
1517  qe->op_id = rid;
1518  GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1519 
1521  msg->gns_header.r_id = htonl (rid);
1522  msg->control = htons (ctrl);
1523  if (NULL == h->mq)
1524  qe->env = env;
1525  else
1526  GNUNET_MQ_send (h->mq, env);
1527  return qe;
1528  GNUNET_break (0);
1529  return NULL;
1530 }
1531 
1535  void *cont_cls)
1536 {
1539 }
1540 
1544  cont,
1545  void *cont_cls)
1546 {
1549 }
1550 
1551 
1555  cont,
1556  void *cont_cls)
1557 {
1560 }
1561 
1562 
1563 /* end of namestore_api.c */
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
const char * GNUNET_ErrorCode_get_hint(enum GNUNET_ErrorCode ec)
Returns a hint for a given error code.
GNUNET_ErrorCode
Taler error codes.
@ GNUNET_EC_NAMESTORE_UNKNOWN
Unknown namestore error.
@ GNUNET_EC_NAMESTORE_NO_RESULTS
No results given.
@ GNUNET_EC_NONE
No error (success).
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static void error_cb(void *cls)
Function called if lookup fails.
Definition: gnunet-abd.c:479
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static int res
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
static char * pkey
Public key of the zone to look in, in ASCII.
static char * zone
Name of the zone being managed.
static unsigned int rd_count
Number of records for currently parsed set.
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
static struct GNUNET_REVOCATION_Query * q
Handle for revocation query.
static struct GNUNET_CONTAINER_BloomFilter * filter
Bloomfilter to quickly tell if we don't have the content.
API to the GNS service.
API that can be used to store naming information on a GNUnet node;.
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:1057
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
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.
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.
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.
GNUNET_GNSRECORD_Filter
Filter for GNUNET_GNSRECORD_normalize_record_set().
@ GNUNET_GNSRECORD_FILTER_NONE
No filter flags set.
ssize_t GNUNET_IDENTITY_write_public_key_to_buffer(const struct GNUNET_IDENTITY_PublicKey *key, void *buffer, size_t len)
Writes a GNUNET_IDENTITY_PublicKey to a compact buffer.
Definition: identity_api.c:890
ssize_t GNUNET_IDENTITY_public_key_get_length(const struct GNUNET_IDENTITY_PublicKey *key)
Get the compacted length of a GNUNET_IDENTITY_PublicKey.
Definition: identity_api.c:830
ssize_t GNUNET_IDENTITY_write_private_key_to_buffer(const struct GNUNET_IDENTITY_PrivateKey *key, void *buffer, size_t len)
Writes a GNUNET_IDENTITY_PrivateKey to a compact buffer.
Definition: identity_api.c:933
ssize_t GNUNET_IDENTITY_private_key_get_length(const struct GNUNET_IDENTITY_PrivateKey *key)
Get the compacted length of a GNUNET_IDENTITY_PrivateKey.
Definition: identity_api.c:809
enum GNUNET_GenericReturnValue GNUNET_IDENTITY_read_private_key_from_buffer(const void *buffer, size_t len, struct GNUNET_IDENTITY_PrivateKey *key, size_t *kb_read)
Reads a GNUNET_IDENTITY_PrivateKey from a compact buffer.
Definition: identity_api.c:908
#define GNUNET_log(kind,...)
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:37
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_MQ_Error
Error codes for the queue.
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:304
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition: mq.c:285
#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:62
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:77
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:683
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_lookup2(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *pkey, const char *label, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor rm, void *rm_cls, enum GNUNET_GNSRECORD_Filter filter)
Lookup an item in the namestore with GNSRECORD filter.
void(* GNUNET_NAMESTORE_ContinuationWithStatus)(void *cls, enum GNUNET_ErrorCode ec)
Continuation called to notify client about result of the operation.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_transaction_rollback(struct GNUNET_NAMESTORE_Handle *h, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls)
Begin rollback all actions in a transaction.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_store2(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *pkey, unsigned int rd_set_count, const struct GNUNET_NAMESTORE_RecordInfo *record_info, unsigned int *rds_sent, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls)
Store one or more record sets in the namestore.
void GNUNET_NAMESTORE_disconnect(struct GNUNET_NAMESTORE_Handle *h)
Disconnect from the namestore service (and free associated resources).
struct GNUNET_NAMESTORE_ZoneIterator * GNUNET_NAMESTORE_zone_iteration_start(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *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)
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_lookup(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *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.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_transaction_begin(struct GNUNET_NAMESTORE_Handle *h, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls)
New API draft.
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.
void GNUNET_NAMESTORE_cancel(struct GNUNET_NAMESTORE_QueueEntry *qe)
Cancel a namestore operation.
void(* GNUNET_NAMESTORE_RecordSetMonitor)(void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, struct GNUNET_TIME_Absolute expiry)
Process a record set that was stored in the namestore.
struct GNUNET_NAMESTORE_ZoneIterator * GNUNET_NAMESTORE_zone_iteration_start2(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *zone, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordSetMonitor proc, void *proc_cls, GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls, enum GNUNET_GNSRECORD_Filter filter)
Starts a new zone iteration (used to periodically PUT all of our records into our DHT).
GNUNET_NAMESTORE_TxControl
Transaction control types.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_store(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *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.
void(* GNUNET_NAMESTORE_RecordMonitor)(void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Process a record that was stored in 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_QueueEntry * GNUNET_NAMESTORE_transaction_commit(struct GNUNET_NAMESTORE_Handle *h, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls)
Commit a namestore transaction.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_zone_to_name(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *zone, const struct GNUNET_IDENTITY_PublicKey *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.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_edit(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *pkey, const char *label, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor rm, void *rm_cls)
void GNUNET_NAMESTORE_zone_iteration_stop(struct GNUNET_NAMESTORE_ZoneIterator *it)
Stops iteration and releases the namestore handle for further calls.
@ GNUNET_NAMESTORE_TX_COMMIT
@ GNUNET_NAMESTORE_TX_ROLLBACK
@ GNUNET_NAMESTORE_TX_BEGIN
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT_END
Service to client: end of list of results.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_TX_CONTROL_RESULT
Return status message for control message.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT
Service to client: here is a (plaintext) record you requested.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE
Service to client: result of zone-to-name lookup.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE
Service to client: result of store operation.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT
Client to service: next record(s) in iteration please.
#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_STOP
Client to service: stop iterating.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE
Service to client: lookup label.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE
Client to service: store records (as authority)
#define GNUNET_MESSAGE_TYPE_NAMESTORE_TX_CONTROL
Message type for Begin, Commit or Rollback.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME
Client to service: "reverse" lookup for zone name based on zone key.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP
Client to service: lookup label.
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975
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:1272
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:737
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:569
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
#define MAX_NAME_LEN
Maximum length of any name, including 0-termination.
Definition: namecache.h:33
common internal definitions for namestore service
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.
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.
static struct GNUNET_NAMESTORE_QueueEntry * find_qe(struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
Find the queue entry that matches the rid.
#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:46
static struct GNUNET_NAMESTORE_QueueEntry * records_lookup(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *pkey, const char *label, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor rm, void *rm_cls, int is_edit_request, enum GNUNET_GNSRECORD_Filter filter)
static void free_qe(struct GNUNET_NAMESTORE_QueueEntry *qe)
Free qe.
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.
static void handle_tx_control_result(void *cls, const struct TxControlResultMessage *msg)
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...
static int check_record_result(void *cls, const struct RecordResultMessage *msg)
Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT.
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.
static void free_ze(struct GNUNET_NAMESTORE_ZoneIterator *ze)
Free ze.
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...
static int check_rd(size_t rd_len, const void *rd_buf, unsigned int rd_count)
Check that rd_buf of length rd_len contains rd_count records.
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.
static struct GNUNET_NAMESTORE_QueueEntry * send_transaction_control_msg(struct GNUNET_NAMESTORE_Handle *h, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls, enum GNUNET_NAMESTORE_TxControl ctrl)
New API draft.
static void handle_lookup_result(void *cls, const struct LabelLookupResponseMessage *msg)
Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE.
static void reconnect(struct GNUNET_NAMESTORE_Handle *h)
Reconnect to namestore service.
static void force_reconnect(struct GNUNET_NAMESTORE_Handle *h)
Disconnect from service and then reconnect.
#define LOG(kind,...)
Definition: namestore_api.c:40
static struct GNUNET_NAMESTORE_ZoneIterator * find_zi(struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
Find the zone iteration entry that matches the rid.
static uint32_t get_op_id(struct GNUNET_NAMESTORE_Handle *h)
Get a fresh operation id to distinguish between namestore requests.
static void handle_record_result(void *cls, const struct RecordResultMessage *msg)
Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT.
static void reconnect_task(void *cls)
Re-establish the connection to the service.
const char * name
struct GNUNET_MQ_Handle * mq
Our connection to the ARM service.
Definition: arm_api.c:107
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
Definition: arm_api.c:112
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the reconnect task (if any).
Definition: arm_api.c:147
struct GNUNET_DATASTORE_Handle * h
Handle to the master context.
struct GNUNET_MQ_Envelope * env
Envelope of the request to transmit, NULL after transmission.
struct GNUNET_DATASTORE_QueueEntry * next
This is a linked list.
GNUNET_DATASTORE_ContinuationWithStatus cont
Function to call after transmission of the request.
void * cont_cls
Closure for cont.
A private key for an identity as per LSD0001.
An identity key as per LSD0001.
Handle to a message queue.
Definition: mq.c:87
Message handler for a specific message type.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
Connection to the NAMESTORE service.
uint32_t last_op_id_used
The last operation id used for a NAMESTORE operation.
struct GNUNET_NAMESTORE_ZoneIterator * z_head
Head of pending namestore zone iterator entries.
struct GNUNET_NAMESTORE_QueueEntry * op_tail
Tail of pending namestore queue entries.
struct GNUNET_SCHEDULER_Task * reconnect_task
Reconnect task.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
struct GNUNET_NAMESTORE_QueueEntry * op_head
Head of pending namestore queue entries.
struct GNUNET_TIME_Relative reconnect_delay
Delay introduced before we reconnect.
struct GNUNET_NAMESTORE_ZoneIterator * z_tail
Tail of pending namestore zone iterator entries.
int reconnect
Should we reconnect to service due to some serious error?
struct GNUNET_MQ_Handle * mq
Connection to the service (if available).
Generic namestore message with op id.
Definition: namestore.h:41
An QueueEntry used to store information for a pending NAMESTORE record operation.
Definition: namestore_api.c:53
struct GNUNET_MQ_Envelope * env
Envelope of the message to send to the service, if not yet sent.
struct GNUNET_NAMESTORE_QueueEntry * prev
Kept in a DLL.
Definition: namestore_api.c:62
uint32_t op_id
The operation id this zone iteration operation has.
void * error_cb_cls
Closure for error_cb.
GNUNET_NAMESTORE_RecordMonitor proc
Function to call with the records we get back; or NULL.
Definition: namestore_api.c:82
struct GNUNET_NAMESTORE_QueueEntry * next
Kept in a DLL.
Definition: namestore_api.c:57
struct GNUNET_NAMESTORE_Handle * h
Main handle to access the namestore.
Definition: namestore_api.c:67
GNUNET_NAMESTORE_ContinuationWithStatus cont
Continuation to call.
Definition: namestore_api.c:72
GNUNET_NAMESTORE_RecordSetMonitor proc2
Function to call with the records we get back; or NULL.
Definition: namestore_api.c:87
struct GNUNET_SCHEDULER_Task * timeout_task
Task scheduled to warn us if the namestore is way too slow.
void * cont_cls
Closure for cont.
Definition: namestore_api.c:77
void * proc_cls
Closure for proc.
Definition: namestore_api.c:92
GNUNET_SCHEDULER_TaskCallback error_cb
Function to call on errors.
Definition: namestore_api.c:97
A struct for record bulk import.
struct GNUNET_GNSRECORD_Data * a_rd
Handle for a zone iterator operation.
void * finish_cb_cls
Closure for error_cb.
void * error_cb_cls
Closure for error_cb.
struct GNUNET_NAMESTORE_ZoneIterator * next
Kept in a DLL.
GNUNET_NAMESTORE_RecordSetMonitor proc2
The continuation to call with the results.
struct GNUNET_NAMESTORE_Handle * h
Main handle to access the namestore.
void * proc_cls
Closure for proc.
uint32_t op_id
The operation id this zone iteration operation has.
struct GNUNET_IDENTITY_PrivateKey zone
Private key of the zone.
GNUNET_NAMESTORE_RecordMonitor proc
The continuation to call with the results.
GNUNET_SCHEDULER_TaskCallback error_cb
Function to call on errors.
struct GNUNET_MQ_Envelope * env
Envelope of the message to send to the service, if not yet sent.
GNUNET_SCHEDULER_TaskCallback finish_cb
Function to call on completion.
struct GNUNET_NAMESTORE_ZoneIterator * prev
Kept in a DLL.
Entry in list of pending tasks.
Definition: scheduler.c:136
Time for relative time used by GNUnet, in microseconds.
Lookup a label.
Definition: namestore.h:132
uint16_t key_len
Length of the zone key.
Definition: namestore.h:156
uint16_t is_edit_request
GNUNET_YES if this lookup corresponds to an edit request.
Definition: namestore.h:146
uint16_t label_len
Length of the name.
Definition: namestore.h:141
Record is returned from the namestore (as authority).
Definition: namestore.h:292
uint16_t rd_len
Length of serialized record data.
Definition: namestore.h:64
uint16_t rd_count
Number of records contained.
Definition: namestore.h:69
uint16_t reserved
Reserved for alignment.
Definition: namestore.h:74
uint16_t name_len
Name length.
Definition: namestore.h:59
Store a record to the namestore (as authority).
Definition: namestore.h:87
uint16_t rd_set_count
Number of record sets.
Definition: namestore.h:96
Response to a record storage request.
Definition: namestore.h:114
Send a transaction control message.
Definition: namestore.h:335
Result of a transaction control message.
Definition: namestore.h:357
Ask for next result of zone iteration for the given operation.
Definition: namestore.h:460
Start a zone iteration for the given zone.
Definition: namestore.h:433
uint16_t key_len
Length of the zone key.
Definition: namestore.h:448
Stop zone iteration for the given operation.
Definition: namestore.h:479
Lookup a name for a zone hash.
Definition: namestore.h:218
uint16_t pkey_len
Length of the public value zone key.
Definition: namestore.h:232
uint16_t key_len
Length of the zone key.
Definition: namestore.h:227
Respone for zone to name lookup.
Definition: namestore.h:246