GNUnet  0.19.2
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  if (NULL != ze->proc)
623  ze->proc (ze->proc_cls, &private_key, name, rd_count, rd);
624  if (NULL != ze->proc2)
625  ze->proc2 (ze->proc_cls, &private_key, name,
627  return;
628  }
629  }
630  GNUNET_assert (0);
631 }
632 
633 
641 static void
643 {
644  struct GNUNET_NAMESTORE_Handle *h = cls;
647 
648  LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_RESULT_END\n");
649  ze = find_zi (h, ntohl (msg->r_id));
650  qe = find_qe (h, ntohl (msg->r_id));
651  if ((NULL == ze) && (NULL == qe))
652  return; /* rid not found */
653  if ((NULL != ze) && (NULL != qe))
654  {
655  GNUNET_break (0); /* rid ambiguous */
656  force_reconnect (h);
657  return;
658  }
659  LOG (GNUNET_ERROR_TYPE_DEBUG, "Zone iteration completed!\n");
660  if (NULL == ze)
661  {
662  GNUNET_break (0);
663  force_reconnect (h);
664  return;
665  }
666  if (NULL != ze->finish_cb)
667  ze->finish_cb (ze->finish_cb_cls);
668  free_ze (ze);
669 }
670 
671 static void
673  const struct TxControlResultMessage *msg)
674 {
675  struct GNUNET_NAMESTORE_Handle *h = cls;
677  enum GNUNET_ErrorCode res;
678 
679  qe = find_qe (h, ntohl (msg->gns_header.r_id));
680  res = ntohs (msg->ec);
682  "Received TX_CONTROL_RESULT with result %d\n",
683  res);
684  if (NULL == qe)
685  return;
686  if (NULL != qe->cont)
687  qe->cont (qe->cont_cls, res);
688  free_qe (qe);
689 }
690 
699 static int
701  const struct ZoneToNameResponseMessage *msg)
702 {
703  size_t name_len;
704  size_t rd_ser_len;
705  size_t key_len;
706  const char *name_tmp;
707 
708  (void) cls;
709  if (GNUNET_EC_NONE != ntohl (msg->ec))
710  return GNUNET_OK;
711  key_len = ntohs (msg->key_len);
712  name_len = ntohs (msg->name_len);
713  rd_ser_len = ntohs (msg->rd_len);
714  if (ntohs (msg->gns_header.header.size) !=
715  sizeof(struct ZoneToNameResponseMessage) + key_len + name_len
716  + rd_ser_len)
717  {
718  GNUNET_break (0);
719  return GNUNET_SYSERR;
720  }
721  name_tmp = (const char *) &msg[1] + key_len;
722  if ((name_len > 0) && ('\0' != name_tmp[name_len - 1]))
723  {
724  GNUNET_break (0);
725  return GNUNET_SYSERR;
726  }
727  return check_rd (rd_ser_len, &name_tmp[name_len], ntohs (msg->rd_count));
728 }
729 
730 
738 static void
740  const struct ZoneToNameResponseMessage *msg)
741 {
742  struct GNUNET_NAMESTORE_Handle *h = cls;
745  enum GNUNET_ErrorCode res;
746  size_t name_len;
747  size_t rd_ser_len;
748  unsigned int rd_count;
749  const char *name_tmp;
750  const char *rd_tmp;
751  size_t key_len;
752  size_t kbytes_read;
753 
754  LOG (GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_TO_NAME_RESPONSE\n");
755  qe = find_qe (h, ntohl (msg->gns_header.r_id));
756  if (NULL == qe)
757  {
759  "Response queue already gone...\n");
760  return;
761  }
762  res = ntohl (msg->ec);
763  key_len = ntohs (msg->key_len);
766  key_len,
767  &zone,
768  &kbytes_read));
769  GNUNET_assert (kbytes_read == key_len);
770  switch (res)
771  {
772  break;
773 
776  "Namestore has no result for zone to name mapping \n");
777  if (NULL != qe->proc)
778  qe->proc (qe->proc_cls, &zone, NULL, 0, NULL);
779  free_qe (qe);
780  return;
781 
782  case GNUNET_EC_NONE:
784  "Namestore has result for zone to name mapping \n");
785  name_len = ntohs (msg->name_len);
786  rd_count = ntohs (msg->rd_count);
787  rd_ser_len = ntohs (msg->rd_len);
788  name_tmp = (const char *) &msg[1] + key_len;
789  rd_tmp = &name_tmp[name_len];
790  {
792 
795  rd_tmp,
796  rd_count,
797  rd));
798  /* normal end, call continuation with result */
799  if (NULL != qe->proc)
800  qe->proc (qe->proc_cls, &zone, name_tmp, rd_count, rd);
801  /* return is important here: break would call continuation with error! */
802  free_qe (qe);
803  return;
804  }
805 
806  default:
808  "An error occurred during zone to name operation: %s\n",
810  break;
811  }
812  /* error case, call continuation with error */
813  if (NULL != qe->error_cb)
814  qe->error_cb (qe->error_cb_cls);
815  free_qe (qe);
816 }
817 
818 
827 static void
828 mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
829 {
830  struct GNUNET_NAMESTORE_Handle *h = cls;
831 
832  (void) error;
833  force_reconnect (h);
834 }
835 
836 
842 static void
844 {
846  { GNUNET_MQ_hd_fixed_size (record_store_response,
849  h),
850  GNUNET_MQ_hd_var_size (zone_to_name_response,
853  h),
854  GNUNET_MQ_hd_var_size (record_result,
856  struct RecordResultMessage,
857  h),
858  GNUNET_MQ_hd_fixed_size (record_result_end,
861  h),
862  GNUNET_MQ_hd_var_size (lookup_result,
865  h),
866  GNUNET_MQ_hd_fixed_size (tx_control_result,
868  struct TxControlResultMessage,
869  h),
873 
874  GNUNET_assert (NULL == h->mq);
875  h->mq =
877  if (NULL == h->mq)
878  return;
879  /* re-transmit pending requests that waited for a reconnect... */
880  for (it = h->z_head; NULL != it; it = it->next)
881  {
882  GNUNET_MQ_send (h->mq, it->env);
883  it->env = NULL;
884  }
885  for (qe = h->op_head; NULL != qe; qe = qe->next)
886  {
887  GNUNET_MQ_send (h->mq, qe->env);
888  qe->env = NULL;
889  }
890 }
891 
892 
898 static void
899 reconnect_task (void *cls)
900 {
901  struct GNUNET_NAMESTORE_Handle *h = cls;
902 
903  h->reconnect_task = NULL;
904  reconnect (h);
905 }
906 
907 
913 static void
915 {
918 
920  h->mq = NULL;
921  while (NULL != (ze = h->z_head))
922  {
923  if (NULL != ze->error_cb)
924  ze->error_cb (ze->error_cb_cls);
925  free_ze (ze);
926  }
927  while (NULL != (qe = h->op_head))
928  {
929  if (NULL != qe->error_cb)
930  qe->error_cb (qe->error_cb_cls);
931  if (NULL != qe->cont)
932  qe->cont (qe->cont_cls,
934  free_qe (qe);
935  }
936 
937  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting to namestore\n");
938  h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
939  h->reconnect_task =
940  GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect_task, h);
941 }
942 
943 
950 static uint32_t
952 {
953  return h->last_op_id_used++;
954 }
955 
956 
965 {
966  struct GNUNET_NAMESTORE_Handle *h;
967 
969  h->cfg = cfg;
970  reconnect (h);
971  if (NULL == h->mq)
972  {
973  GNUNET_free (h);
974  return NULL;
975  }
976  return h;
977 }
978 
979 
986 void
988 {
991 
992  LOG (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
993  GNUNET_break (NULL == h->op_head);
994  while (NULL != (q = h->op_head))
995  {
996  GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, q);
997  GNUNET_free (q);
998  }
999  GNUNET_break (NULL == h->z_head);
1000  while (NULL != (z = h->z_head))
1001  {
1002  GNUNET_CONTAINER_DLL_remove (h->z_head, h->z_tail, z);
1003  GNUNET_free (z);
1004  }
1005  if (NULL != h->mq)
1006  {
1007  GNUNET_MQ_destroy (h->mq);
1008  h->mq = NULL;
1009  }
1010  if (NULL != h->reconnect_task)
1011  {
1013  h->reconnect_task = NULL;
1014  }
1015  GNUNET_free (h);
1016 }
1017 
1018 
1025 static void
1026 warn_delay (void *cls)
1027 {
1028  struct GNUNET_NAMESTORE_QueueEntry *qe = cls;
1029 
1030  qe->timeout_task = NULL;
1032  "Did not receive response from namestore after %s!\n",
1034  GNUNET_YES));
1035  if (NULL != qe->cont)
1036  {
1038  qe->cont = NULL;
1039  }
1041 }
1042 
1043 
1046  struct GNUNET_NAMESTORE_Handle *h,
1047  const struct GNUNET_IDENTITY_PrivateKey *pkey,
1048  const char *label,
1049  unsigned int rd_count,
1050  const struct GNUNET_GNSRECORD_Data *rd,
1052  void *cont_cls)
1053 {
1054  struct GNUNET_NAMESTORE_RecordInfo ri;
1055  unsigned int rds_sent;
1056  ri.a_label = label;
1057  ri.a_rd_count = rd_count;
1058  ri.a_rd = (struct GNUNET_GNSRECORD_Data *) rd;
1059  return GNUNET_NAMESTORE_records_store2 (h, pkey, 1, &ri, &rds_sent,
1060  cont, cont_cls);
1061 }
1062 
1065  struct GNUNET_NAMESTORE_Handle *h,
1066  const struct GNUNET_IDENTITY_PrivateKey *pkey,
1067  unsigned int rd_set_count,
1068  const struct GNUNET_NAMESTORE_RecordInfo *record_info,
1069  unsigned int *rds_sent,
1071  void *cont_cls)
1072 {
1074  struct GNUNET_MQ_Envelope *env;
1075  const char *label;
1076  unsigned int rd_count;
1077  const struct GNUNET_GNSRECORD_Data *rd;
1078  char *name_tmp;
1079  char *rd_ser;
1080  ssize_t rd_ser_len[rd_set_count];
1081  size_t name_len;
1082  uint32_t rid;
1083  struct RecordStoreMessage *msg;
1084  struct RecordSet *rd_set;
1085  ssize_t sret;
1086  int i;
1087  size_t rd_set_len = 0;
1088  size_t key_len = 0;
1089  size_t max_len;
1091  max_len = UINT16_MAX - key_len - sizeof (struct RecordStoreMessage);
1092 
1093  *rds_sent = 0;
1094  for (i = 0; i < rd_set_count; i++)
1095  {
1096  label = record_info[i].a_label;
1097  rd_count = record_info[i].a_rd_count;
1098  rd = record_info[i].a_rd;
1099  name_len = strlen (label) + 1;
1100  if (name_len > MAX_NAME_LEN)
1101  {
1102  GNUNET_break (0);
1103  *rds_sent = 0;
1104  return NULL;
1105  }
1106  rd_ser_len[i] = GNUNET_GNSRECORD_records_get_size (rd_count, rd);
1107  if (rd_ser_len[i] < 0)
1108  {
1109  GNUNET_break (0);
1110  *rds_sent = 0;
1111  return NULL;
1112  }
1113  if (rd_ser_len[i] > max_len)
1114  {
1115  GNUNET_break (0);
1116  *rds_sent = 0;
1117  return NULL;
1118  }
1119  if ((rd_set_len + sizeof (struct RecordSet) + name_len + rd_ser_len[i]) >
1120  max_len)
1121  break;
1122  rd_set_len += sizeof (struct RecordSet) + name_len + rd_ser_len[i];
1123  }
1124  *rds_sent = i;
1126  "Sending %u of %u records!\n", *rds_sent, rd_set_count);
1127  rid = get_op_id (h);
1129  qe->h = h;
1130  qe->cont = cont;
1131  qe->cont_cls = cont_cls;
1132  qe->op_id = rid;
1133  GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1134  /* setup msg */
1136  key_len + rd_set_len,
1138  GNUNET_assert (NULL != msg);
1139  GNUNET_assert (NULL != env);
1140  msg->gns_header.r_id = htonl (rid);
1141  msg->key_len = htons (key_len);
1142  msg->rd_set_count = htons ((uint16_t) (*rds_sent));
1144  &msg[1],
1145  key_len);
1146  rd_set = (struct RecordSet*) (((char*) &msg[1]) + key_len);
1147  for (int i = 0; i < *rds_sent; i++)
1148  {
1149  label = record_info[i].a_label;
1150  rd = record_info[i].a_rd;
1151  name_len = strlen (label) + 1;
1152  rd_set->name_len = htons (name_len);
1153  rd_set->rd_count = htons (record_info[i].a_rd_count);
1154  rd_set->rd_len = htons (rd_ser_len[i]);
1155  rd_set->reserved = ntohs (0);
1156  name_tmp = (char *) &rd_set[1];
1157  GNUNET_memcpy (name_tmp, label, name_len);
1158  rd_ser = &name_tmp[name_len];
1159  sret = GNUNET_GNSRECORD_records_serialize (record_info[i].a_rd_count,
1160  rd, rd_ser_len[i], rd_ser);
1161  if ((0 > sret) || (sret != rd_ser_len[i]))
1162  {
1163  GNUNET_break (0);
1164  GNUNET_free (env);
1165  return NULL;
1166  }
1167  // Point to next RecordSet
1168  rd_set = (struct RecordSet*) &name_tmp[name_len + rd_ser_len[i]];
1169  }
1171  "Sending NAMESTORE_RECORD_STORE message for name %u record sets\n",
1172  *rds_sent);
1173  qe->timeout_task =
1175  if (NULL == h->mq)
1176  {
1177  qe->env = env;
1179  "Delaying NAMESTORE_RECORD_STORE message as namestore is not ready!\n");
1180  }
1181  else
1182  {
1183  GNUNET_MQ_send (h->mq, env);
1184  }
1185  return qe;
1186 }
1187 
1188 
1189 static struct GNUNET_NAMESTORE_QueueEntry *
1191  struct GNUNET_NAMESTORE_Handle *h,
1192  const struct GNUNET_IDENTITY_PrivateKey *pkey,
1193  const char *label,
1195  void *error_cb_cls,
1197  void *rm_cls,
1198  int is_edit_request,
1200 {
1202  struct GNUNET_MQ_Envelope *env;
1203  struct LabelLookupMessage *msg;
1204  size_t label_len;
1205  size_t key_len;
1206 
1207  if (1 == (label_len = strlen (label) + 1))
1208  {
1209  GNUNET_break (0);
1210  return NULL;
1211  }
1212 
1214  qe->h = h;
1215  qe->error_cb = error_cb;
1216  qe->error_cb_cls = error_cb_cls;
1217  qe->proc = rm;
1218  qe->proc_cls = rm_cls;
1219  qe->op_id = get_op_id (h);
1220  GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1221 
1224  label_len + key_len,
1226  msg->gns_header.r_id = htonl (qe->op_id);
1228  &msg[1],
1229  key_len);
1230 
1231  msg->key_len = htons (key_len);
1232  msg->is_edit_request = htons (is_edit_request);
1233  msg->label_len = htons (label_len);
1234  msg->filter = htons (filter);
1235  GNUNET_memcpy (((char*) &msg[1]) + key_len, label, label_len);
1236  if (NULL == h->mq)
1237  qe->env = env;
1238  else
1239  GNUNET_MQ_send (h->mq, env);
1240  return qe;
1241 }
1242 
1245  struct GNUNET_NAMESTORE_Handle *h,
1246  const struct GNUNET_IDENTITY_PrivateKey *pkey,
1247  const char *label,
1249  void *error_cb_cls,
1251  void *rm_cls)
1252 {
1253  return records_lookup (h, pkey, label,
1256 
1257 }
1258 
1261  struct GNUNET_NAMESTORE_Handle *h,
1262  const struct GNUNET_IDENTITY_PrivateKey *pkey,
1263  const char *label,
1265  void *error_cb_cls,
1267  void *rm_cls,
1269 {
1270  return records_lookup (h, pkey, label,
1272  rm, rm_cls, GNUNET_NO, filter);
1273 
1274 }
1275 
1276 
1279  struct GNUNET_NAMESTORE_Handle *h,
1280  const struct GNUNET_IDENTITY_PrivateKey *pkey,
1281  const char *label,
1283  void *error_cb_cls,
1285  void *rm_cls)
1286 {
1287  return records_lookup (h, pkey, label,
1290 }
1291 
1294  struct GNUNET_NAMESTORE_Handle *h,
1295  const struct GNUNET_IDENTITY_PrivateKey *zone,
1296  const struct GNUNET_IDENTITY_PublicKey *value_zone,
1298  void *error_cb_cls,
1300  void *proc_cls)
1301 {
1303  struct GNUNET_MQ_Envelope *env;
1304  struct ZoneToNameMessage *msg;
1305  uint32_t rid;
1306  size_t key_len;
1307  ssize_t pkey_len;
1308 
1309  rid = get_op_id (h);
1311  qe->h = h;
1312  qe->error_cb = error_cb;
1313  qe->error_cb_cls = error_cb_cls;
1314  qe->proc = proc;
1315  qe->proc_cls = proc_cls;
1316  qe->op_id = rid;
1317  GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1318 
1323  msg->gns_header.r_id = htonl (rid);
1324  msg->key_len = htons (key_len);
1325  msg->pkey_len = htons (pkey_len);
1328  (char*) &msg[1] + key_len,
1329  pkey_len);
1330  if (NULL == h->mq)
1331  qe->env = env;
1332  else
1333  GNUNET_MQ_send (h->mq, env);
1334  return qe;
1335 }
1336 
1337 
1340  struct GNUNET_NAMESTORE_Handle *h,
1341  const struct GNUNET_IDENTITY_PrivateKey *zone,
1343  void *error_cb_cls,
1345  void *proc_cls,
1347  void *finish_cb_cls)
1348 {
1349  struct GNUNET_NAMESTORE_ZoneIterator *it;
1350  struct GNUNET_MQ_Envelope *env;
1352  uint32_t rid;
1353  size_t key_len = 0;
1354 
1355  LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_START message\n");
1356  rid = get_op_id (h);
1358  it->h = h;
1359  it->error_cb = error_cb;
1360  it->error_cb_cls = error_cb_cls;
1361  it->finish_cb = finish_cb;
1362  it->finish_cb_cls = finish_cb_cls;
1363  it->proc = proc;
1364  it->proc_cls = proc_cls;
1365  it->op_id = rid;
1366  if (NULL != zone)
1367  {
1368  it->zone = *zone;
1370  }
1371  GNUNET_CONTAINER_DLL_insert_tail (h->z_head, h->z_tail, it);
1373  key_len,
1375  msg->gns_header.r_id = htonl (rid);
1376  msg->key_len = htons (key_len);
1377  if (NULL != zone)
1379  if (NULL == h->mq)
1380  it->env = env;
1381  else
1382  GNUNET_MQ_send (h->mq, env);
1383  return it;
1384 }
1385 
1388  struct GNUNET_NAMESTORE_Handle *h,
1389  const struct GNUNET_IDENTITY_PrivateKey *zone,
1391  void *error_cb_cls,
1393  void *proc_cls,
1395  void *finish_cb_cls,
1397 {
1398  struct GNUNET_NAMESTORE_ZoneIterator *it;
1399  struct GNUNET_MQ_Envelope *env;
1401  uint32_t rid;
1402  size_t key_len = 0;
1403 
1404  LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_START message\n");
1405  rid = get_op_id (h);
1407  it->h = h;
1408  it->error_cb = error_cb;
1409  it->error_cb_cls = error_cb_cls;
1410  it->finish_cb = finish_cb;
1411  it->finish_cb_cls = finish_cb_cls;
1412  it->proc2 = proc;
1413  it->proc_cls = proc_cls;
1414  it->op_id = rid;
1415  if (NULL != zone)
1416  {
1417  it->zone = *zone;
1419  }
1420  GNUNET_CONTAINER_DLL_insert_tail (h->z_head, h->z_tail, it);
1422  key_len,
1424  msg->gns_header.r_id = htonl (rid);
1425  msg->key_len = htons (key_len);
1426  msg->filter = htons ((uint16_t) filter);
1427  if (NULL != zone)
1429  if (NULL == h->mq)
1430  it->env = env;
1431  else
1432  GNUNET_MQ_send (h->mq, env);
1433  return it;
1434 }
1435 
1436 
1437 void
1439  uint64_t limit)
1440 {
1441  struct GNUNET_NAMESTORE_Handle *h = it->h;
1442  struct ZoneIterationNextMessage *msg;
1443  struct GNUNET_MQ_Envelope *env;
1444 
1446  "Sending ZONE_ITERATION_NEXT message with limit %llu\n",
1447  (unsigned long long) limit);
1449  msg->gns_header.r_id = htonl (it->op_id);
1450  msg->limit = GNUNET_htonll (limit);
1451  GNUNET_MQ_send (h->mq, env);
1452 }
1453 
1454 
1460 void
1462 {
1463  struct GNUNET_NAMESTORE_Handle *h = it->h;
1464  struct GNUNET_MQ_Envelope *env;
1465  struct ZoneIterationStopMessage *msg;
1466 
1467  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_STOP message\n");
1468  if (NULL != h->mq)
1469  {
1470  env =
1472  msg->gns_header.r_id = htonl (it->op_id);
1473  GNUNET_MQ_send (h->mq, env);
1474  }
1475  free_ze (it);
1476 }
1477 
1478 
1485 void
1487 {
1488  free_qe (qe);
1489 }
1490 
1495 static struct GNUNET_NAMESTORE_QueueEntry *
1498  void *cont_cls,
1499  enum GNUNET_NAMESTORE_TxControl ctrl)
1500 {
1502  struct GNUNET_MQ_Envelope *env;
1503  struct TxControlMessage *msg;
1504  uint32_t rid;
1505 
1506  rid = get_op_id (h);
1508  qe->h = h;
1509  qe->cont = cont;
1510  qe->cont_cls = cont_cls;
1511  qe->op_id = rid;
1512  GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1513 
1515  msg->gns_header.r_id = htonl (rid);
1516  msg->control = htons (ctrl);
1517  if (NULL == h->mq)
1518  qe->env = env;
1519  else
1520  GNUNET_MQ_send (h->mq, env);
1521  return qe;
1522  GNUNET_break (0);
1523  return NULL;
1524 }
1525 
1529  void *cont_cls)
1530 {
1533 }
1534 
1538  cont,
1539  void *cont_cls)
1540 {
1543 }
1544 
1545 
1549  cont,
1550  void *cont_cls)
1551 {
1554 }
1555 
1556 
1557 /* 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:944
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:1241
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