GNUnet  0.10.x
gnunet-service-reclaim_tickets.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2012-2015 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 
27 #include <inttypes.h>
29 
30 #define DEFAULT_TICKET_REFRESH_INTERVAL GNUNET_TIME_UNIT_HOURS
31 
32 struct ParallelLookup;
33 
34 
39 {
44 
49 
54 
59 };
60 
61 
63 {
67  struct GNUNET_RECLAIM_Ticket ticket;
68 
73 
78 
82  struct GNUNET_CRYPTO_EcdsaPublicKey identity_pub;
83 
88 
93 
98 
103 
107  struct GNUNET_TIME_Absolute lookup_start_time;
108 
113 
117  void *cb_cls;
118 };
119 
124 {
125  /* DLL */
127 
128  /* DLL */
130 
131  /* The GNS request */
133 
134  /* The handle the return to */
136 
140  struct GNUNET_TIME_Absolute lookup_start_time;
141 
142  /* The label to look up */
143  char *label;
144 };
145 
146 
151 {
156 
161 
165  struct GNUNET_RECLAIM_Ticket ticket;
166 
171 
176 
181 
185  void *cb_cls;
186 };
187 
192 {
197 
202 
206  void *cb_cls;
207 };
208 
209 
211 {
216 
221 
225  uint64_t old_id;
226 
230  uint64_t new_id;
231 };
232 
233 
238 {
243 
248 
252  void *cb_cls;
253 
257  struct GNUNET_RECLAIM_Ticket ticket;
258 
263 
268 
273 
278 
283 
287  unsigned int ticket_attrs;
288 
293 
298 };
299 
304 
305 /* Namestore handle */
307 
308 /* GNS handle */
309 static struct GNUNET_GNS_Handle *gns;
310 
311 /* Handle to the statistics service */
313 
314 static void
316 
317 static void
318 move_attrs_cont (void *cls)
319 {
320  move_attrs ((struct RECLAIM_TICKETS_RevokeHandle *) cls);
321 }
322 
328 static void
330 {
331  struct RevokedAttributeEntry *ae;
332  struct TicketRecordsEntry *le;
333  if (NULL != rh->ns_qe)
335  if (NULL != rh->ns_it)
337  while (NULL != (ae = rh->attrs_head))
338  {
340  GNUNET_free (ae);
341  }
342  while (NULL != (le = rh->tickets_to_update_head))
343  {
346  le);
347  if (NULL != le->data)
348  GNUNET_free (le->data);
349  if (NULL != le->label)
350  GNUNET_free (le->label);
351  GNUNET_free (le);
352  }
353  GNUNET_free (rh);
354 }
355 
356 static void
357 del_attr_finished (void *cls, int32_t success, const char *emsg)
358 {
359  struct RECLAIM_TICKETS_RevokeHandle *rvk = cls;
360  rvk->ns_qe = NULL;
361  if (GNUNET_SYSERR == success)
362  {
364  "Error removing attribute: %s\n",
365  emsg);
366  rvk->cb (rvk->cb_cls, GNUNET_SYSERR);
367  cleanup_rvk (rvk);
368  return;
369  }
370  rvk->move_attr = rvk->move_attr->next;
372 }
373 
374 static void
375 move_attr_finished (void *cls, int32_t success, const char *emsg)
376 {
377  struct RECLAIM_TICKETS_RevokeHandle *rvk = cls;
378  char *label;
379  rvk->ns_qe = NULL;
380  if (GNUNET_SYSERR == success)
381  {
382  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error moving attribute: %s\n", emsg);
383  rvk->cb (rvk->cb_cls, GNUNET_SYSERR);
384  cleanup_rvk (rvk);
385  return;
386  }
388  sizeof (uint64_t));
389  GNUNET_assert (NULL != label);
390  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing attribute %s\n", label);
392  &rvk->identity,
393  label,
394  0,
395  NULL,
397  rvk);
398  GNUNET_free (label);
399 }
400 
401 
402 static void
403 rvk_move_attr_cb (void *cls,
404  const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
405  const char *label,
406  unsigned int rd_count,
407  const struct GNUNET_GNSRECORD_Data *rd)
408 {
409  struct RECLAIM_TICKETS_RevokeHandle *rvk = cls;
411  struct GNUNET_GNSRECORD_Data new_rd;
412  struct RevokedAttributeEntry *le;
413  char *new_label;
414  char *attr_data;
415  rvk->ns_qe = NULL;
416  if (0 == rd_count)
417  {
419  "The attribute %s no longer exists!\n",
420  label);
421  le = rvk->move_attr;
422  rvk->move_attr = le->next;
424  GNUNET_free (le);
426  return;
427  }
429  rvk->move_attr->new_id =
431  new_rd = *rd;
434  "Attribute to update: Name=%s, ID=%" PRIu64 "\n",
435  claim->name,
436  claim->id);
437  claim->id = rvk->move_attr->new_id;
439  attr_data = GNUNET_malloc (rd->data_size);
440  new_rd.data_size = GNUNET_RECLAIM_ATTRIBUTE_serialize (claim, attr_data);
441  new_rd.data = attr_data;
443  sizeof (uint64_t));
444  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute %s\n", new_label);
446  &rvk->identity,
447  new_label,
448  1,
449  &new_rd,
451  rvk);
452  GNUNET_free (new_label);
453  GNUNET_free (claim);
454  GNUNET_free (attr_data);
455 }
456 
457 
458 static void
459 rvk_ticket_update (void *cls,
460  const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
461  const char *label,
462  unsigned int rd_count,
463  const struct GNUNET_GNSRECORD_Data *rd)
464 {
465  struct RECLAIM_TICKETS_RevokeHandle *rvk = cls;
466  struct TicketRecordsEntry *le;
467  struct RevokedAttributeEntry *ae;
468  int has_changed = GNUNET_NO;
469 
471  for (int i = 0; i < rd_count; i++)
472  {
473  if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type)
474  continue;
475  for (ae = rvk->attrs_head; NULL != ae; ae = ae->next)
476  {
477  if (0 != memcmp (rd[i].data, &ae->old_id, sizeof (uint64_t)))
478  continue;
479  has_changed = GNUNET_YES;
480  break;
481  }
482  if (GNUNET_YES == has_changed)
483  break;
484  }
485  if (GNUNET_YES == has_changed)
486  {
487  le = GNUNET_new (struct TicketRecordsEntry);
488  le->data_size = GNUNET_GNSRECORD_records_get_size (rd_count, rd);
489  le->data = GNUNET_malloc (le->data_size);
490  le->rd_count = rd_count;
491  le->label = GNUNET_strdup (label);
492  GNUNET_GNSRECORD_records_serialize (rd_count, rd, le->data_size, le->data);
495  le);
496  }
498 }
499 
500 
501 static void
502 process_tickets (void *cls);
503 
504 
505 static void
506 ticket_processed (void *cls, int32_t success, const char *emsg)
507 {
508  struct RECLAIM_TICKETS_RevokeHandle *rvk = cls;
509  rvk->ns_qe = NULL;
511 }
512 
513 static void
514 process_tickets (void *cls)
515 {
516  struct RECLAIM_TICKETS_RevokeHandle *rvk = cls;
517  struct TicketRecordsEntry *le;
518  struct RevokedAttributeEntry *ae;
519  if (NULL == rvk->tickets_to_update_head)
520  {
522  "Finished updatding tickets, success\n");
523  rvk->cb (rvk->cb_cls, GNUNET_OK);
524  cleanup_rvk (rvk);
525  return;
526  }
527  le = rvk->tickets_to_update_head;
530  le);
531  struct GNUNET_GNSRECORD_Data rd[le->rd_count];
533  le->data,
534  le->rd_count,
535  rd))
536  {
538  "Unable to deserialize ticket record(s)\n");
539  rvk->cb (rvk->cb_cls, GNUNET_SYSERR);
540  cleanup_rvk (rvk);
541  return;
542  }
543  for (int i = 0; i < le->rd_count; i++)
544  {
546  continue;
547  for (ae = rvk->attrs_head; NULL != ae; ae = ae->next)
548  {
549  if (0 != memcmp (rd[i].data, &ae->old_id, sizeof (uint64_t)))
550  continue;
551  rd[i].data = &ae->new_id;
552  }
553  }
555  &rvk->identity,
556  le->label,
557  le->rd_count,
558  rd,
560  rvk);
561  GNUNET_free (le->label);
562  GNUNET_free (le->data);
563  GNUNET_free (le);
564 }
565 
566 static void
568 {
569  struct RECLAIM_TICKETS_RevokeHandle *rvk = cls;
570  rvk->ns_it = NULL;
572 }
573 
574 
575 static void
576 rvk_ns_iter_err (void *cls)
577 {
578  struct RECLAIM_TICKETS_RevokeHandle *rvk = cls;
579  rvk->ns_it = NULL;
581  "Namestore error on revocation (id=%" PRIu64 "\n",
582  rvk->move_attr->old_id);
583  rvk->cb (rvk->cb_cls, GNUNET_SYSERR);
584  cleanup_rvk (rvk);
585 }
586 
587 
588 static void
589 rvk_ns_err (void *cls)
590 {
591  struct RECLAIM_TICKETS_RevokeHandle *rvk = cls;
592  rvk->ns_qe = NULL;
594  "Namestore error on revocation (id=%" PRIu64 "\n",
595  rvk->move_attr->old_id);
596  rvk->cb (rvk->cb_cls, GNUNET_SYSERR);
597  cleanup_rvk (rvk);
598 }
599 
600 
601 static void
603 {
604  char *label;
605 
606  if (NULL == rvk->move_attr)
607  {
608  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished moving attributes\n");
609  rvk->ns_it =
611  &rvk->identity,
613  rvk,
615  rvk,
617  rvk);
618  return;
619  }
621  sizeof (uint64_t));
622  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Moving attribute %s\n", label);
623 
625  &rvk->identity,
626  label,
627  &rvk_ns_err,
628  rvk,
630  rvk);
631  GNUNET_free (label);
632 }
633 
634 
635 static void
636 remove_ticket_cont (void *cls, int32_t success, const char *emsg)
637 {
638  struct RECLAIM_TICKETS_RevokeHandle *rvk = cls;
639  rvk->ns_qe = NULL;
640  if (GNUNET_SYSERR == success)
641  {
642  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", emsg);
643  rvk->cb (rvk->cb_cls, GNUNET_SYSERR);
644  cleanup_rvk (rvk);
645  return;
646  }
647  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleted ticket\n");
648  if (0 == rvk->ticket_attrs)
649  {
651  "No attributes to move... strange\n");
652  rvk->cb (rvk->cb_cls, GNUNET_OK);
653  cleanup_rvk (rvk);
654  return;
655  }
656  rvk->move_attr = rvk->attrs_head;
657  move_attrs (rvk);
658 }
659 
660 
661 static void
662 revoke_attrs_cb (void *cls,
663  const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
664  const char *label,
665  unsigned int rd_count,
666  const struct GNUNET_GNSRECORD_Data *rd)
667 
668 {
669  struct RECLAIM_TICKETS_RevokeHandle *rvk = cls;
670  struct RevokedAttributeEntry *le;
671  rvk->ns_qe = NULL;
672  for (int i = 0; i < rd_count; i++)
673  {
674  if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type)
675  continue;
676  le = GNUNET_new (struct RevokedAttributeEntry);
677  le->old_id = *((uint64_t *) rd[i].data);
679  rvk->ticket_attrs++;
680  }
681 
684  &rvk->identity,
685  label,
686  0,
687  NULL,
689  rvk);
690 }
691 
692 
693 static void
694 rvk_attrs_err_cb (void *cls)
695 {
696  struct RECLAIM_TICKETS_RevokeHandle *rvk = cls;
697  rvk->cb (rvk->cb_cls, GNUNET_SYSERR);
698  cleanup_rvk (rvk);
699 }
700 
701 
706  void *cb_cls)
707 {
708  struct RECLAIM_TICKETS_RevokeHandle *rvk;
709  char *label;
710 
712  rvk->cb = cb;
713  rvk->cb_cls = cb_cls;
714  rvk->identity = *identity;
715  rvk->ticket = *ticket;
718  label = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, sizeof (uint64_t));
719  GNUNET_assert (NULL != label);
721  identity,
722  label,
724  rvk,
726  rvk);
727  GNUNET_free (label);
728  return rvk;
729 }
730 
731 
732 void
734 {
735  cleanup_rvk (rh);
736 }
737 /*******************************
738  * Ticket consume
739  *******************************/
740 
745 static void
747 {
748  struct ParallelLookup *lu;
749  if (NULL != cth->lookup_request)
751  if (NULL != cth->kill_task)
753  while (NULL != (lu = cth->parallel_lookups_head))
754  {
755  if (NULL != lu->lookup_request)
760  lu);
761  GNUNET_free (lu);
762  }
763 
764  if (NULL != cth->attrs)
766  GNUNET_free (cth);
767 }
768 
769 
770 static void
772  uint32_t rd_count,
773  const struct GNUNET_GNSRECORD_Data *rd)
774 {
775  struct ParallelLookup *parallel_lookup = cls;
776  struct RECLAIM_TICKETS_ConsumeHandle *cth = parallel_lookup->handle;
779  "Parallel lookup finished (count=%u)\n",
780  rd_count);
781 
784  parallel_lookup);
785  GNUNET_free (parallel_lookup->label);
786 
788  "attribute_lookup_time_total",
790  parallel_lookup->lookup_start_time)
791  .rel_value_us,
792  GNUNET_YES);
793  GNUNET_STATISTICS_update (stats, "attribute_lookups_count", 1, GNUNET_YES);
794 
795 
796  GNUNET_free (parallel_lookup);
797  if (1 != rd_count)
798  GNUNET_break (0); // TODO
800  {
802  attr_le->claim =
805  cth->attrs->list_tail,
806  attr_le);
807  }
808  if (NULL != cth->parallel_lookups_head)
809  return; // Wait for more
810  /* Else we are done */
811 
812  cth->cb (cth->cb_cls, &cth->ticket.identity, cth->attrs, GNUNET_OK, NULL);
813  cleanup_cth (cth);
814 }
815 
816 
817 static void
819 {
820  struct RECLAIM_TICKETS_ConsumeHandle *cth = cls;
821  struct ParallelLookup *lu;
822  struct ParallelLookup *tmp;
823 
824  cth->kill_task = NULL;
825  for (lu = cth->parallel_lookups_head; NULL != lu;)
826  {
828  GNUNET_free (lu->label);
829  tmp = lu->next;
832  lu);
833  GNUNET_free (lu);
834  lu = tmp;
835  }
836  cth->cb (cth->cb_cls, NULL, NULL, GNUNET_SYSERR, "Aborted");
837 }
838 
839 
840 static void
841 lookup_authz_cb (void *cls,
842  uint32_t rd_count,
843  const struct GNUNET_GNSRECORD_Data *rd)
844 {
845  struct RECLAIM_TICKETS_ConsumeHandle *cth = cls;
846  struct ParallelLookup *parallel_lookup;
847  char *lbl;
848 
849  cth->lookup_request = NULL;
850 
852  "reclaim_authz_lookup_time_total",
854  cth->lookup_start_time)
855  .rel_value_us,
856  GNUNET_YES);
858  "reclaim_authz_lookups_count",
859  1,
860  GNUNET_YES);
861 
862  for (int i = 0; i < rd_count; i++)
863  {
864  if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type)
865  continue;
867  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attribute ref found %s\n", lbl);
868  parallel_lookup = GNUNET_new (struct ParallelLookup);
869  parallel_lookup->handle = cth;
870  parallel_lookup->label = lbl;
871  parallel_lookup->lookup_start_time = GNUNET_TIME_absolute_get ();
872  parallel_lookup->lookup_request =
873  GNUNET_GNS_lookup (gns,
874  lbl,
875  &cth->ticket.identity,
879  parallel_lookup);
882  parallel_lookup);
883  }
884  if (NULL != cth->parallel_lookups_head)
885  {
889  cth);
890  return;
891  }
892  cth->cb (cth->cb_cls, &cth->ticket.identity, cth->attrs, GNUNET_OK, NULL);
893  cleanup_cth (cth);
894 }
895 
896 
899  const struct GNUNET_RECLAIM_Ticket *ticket,
901  void *cb_cls)
902 {
903  struct RECLAIM_TICKETS_ConsumeHandle *cth;
904  char *label;
906 
907  cth->identity = *id;
910  cth->ticket = *ticket;
911  cth->cb = cb;
912  cth->cb_cls = cb_cls;
913  label =
914  GNUNET_STRINGS_data_to_string_alloc (&cth->ticket.rnd, sizeof (uint64_t));
916  "Looking for AuthZ info under %s\n",
917  label);
919  cth->lookup_request =
920  GNUNET_GNS_lookup (gns,
921  label,
922  &cth->ticket.identity,
926  cth);
927  GNUNET_free (label);
928  return cth;
929 }
930 
931 void
933 {
934  cleanup_cth (cth);
935  return;
936 }
937 
938 
939 /*******************************
940  * Ticket issue
941  *******************************/
942 
947 static void
949 {
950  if (NULL != handle->ns_qe)
951  GNUNET_NAMESTORE_cancel (handle->ns_qe);
952  GNUNET_free (handle);
953 }
954 
955 
956 static void
957 store_ticket_issue_cont (void *cls, int32_t success, const char *emsg)
958 {
959  struct TicketIssueHandle *handle = cls;
960 
961  handle->ns_qe = NULL;
962  if (GNUNET_SYSERR == success)
963  {
964  handle->cb (handle->cb_cls,
965  &handle->ticket,
967  "Error storing AuthZ ticket in GNS");
968  return;
969  }
970  handle->cb (handle->cb_cls, &handle->ticket, GNUNET_OK, NULL);
971  cleanup_issue_handle (handle);
972 }
973 
974 
975 static void
977 {
979  struct GNUNET_GNSRECORD_Data *attrs_record;
980  char *label;
981  size_t list_len = 1;
982  int i;
983 
984  for (le = ih->attrs->list_head; NULL != le; le = le->next)
985  list_len++;
986 
987  attrs_record =
988  GNUNET_malloc (list_len * sizeof (struct GNUNET_GNSRECORD_Data));
989  i = 0;
990  for (le = ih->attrs->list_head; NULL != le; le = le->next)
991  {
992  attrs_record[i].data = &le->claim->id;
993  attrs_record[i].data_size = sizeof (le->claim->id);
994  //FIXME: Should this be the attribute expiration time or ticket refresh intv
998  i++;
999  }
1000  attrs_record[i].data = &ih->ticket;
1001  attrs_record[i].data_size = sizeof (struct GNUNET_RECLAIM_Ticket);
1004  attrs_record[i].flags =
1006 
1007  label =
1008  GNUNET_STRINGS_data_to_string_alloc (&ih->ticket.rnd, sizeof (uint64_t));
1009  // Publish record
1011  &ih->identity,
1012  label,
1013  list_len,
1014  attrs_record,
1016  ih);
1017  GNUNET_free (attrs_record);
1018  GNUNET_free (label);
1019 }
1020 
1021 /*************************************************
1022  * Ticket iteration (finding a specific ticket)
1023  *************************************************/
1024 
1025 static void
1027 {
1028  struct TicketIssueHandle *tih = cls;
1029  tih->ns_it = NULL;
1030  tih->cb (tih->cb_cls,
1031  &tih->ticket,
1032  GNUNET_SYSERR,
1033  "Error storing AuthZ ticket in GNS");
1034  cleanup_issue_handle (tih);
1035 }
1036 
1037 static void
1039  const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
1040  const char *label,
1041  unsigned int rd_count,
1042  const struct GNUNET_GNSRECORD_Data *rd)
1043 {
1044  struct TicketIssueHandle *tih = cls;
1045  struct GNUNET_RECLAIM_Ticket *ticket = NULL;
1046 
1047  // figure out the number of requested attributes
1049  unsigned int attr_cnt = 0;
1050  for (le = tih->attrs->list_head; NULL != le; le = le->next)
1051  attr_cnt++;
1052 
1053  // ticket search
1054  unsigned int found_attrs_cnt = 0;
1055 
1056  for (int i = 0; i < rd_count; i++)
1057  {
1058  // found ticket
1059  if (GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET == rd[i].record_type)
1060  {
1061  ticket = (struct GNUNET_RECLAIM_Ticket *) rd[i].data;
1062  // cmp audience
1063  if (0 == memcmp (&tih->ticket.audience,
1064  &ticket->audience,
1065  sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
1066  {
1067  tih->ticket = *ticket;
1068  continue;
1069  }
1070  ticket = NULL;
1071  }
1072 
1073  // cmp requested attributes with ticket attributes
1074  if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type)
1075  continue;
1076  for (le = tih->attrs->list_head; NULL != le; le = le->next)
1077  {
1078  // cmp attr_ref id with requested attr id
1080  " %" PRIu64 "\n %" PRIu64 "\n",
1081  *((uint64_t *) rd[i].data),
1082  le->claim->id);
1083 
1084 
1085  if (0 == memcmp (rd[i].data, &le->claim->id, sizeof (uint64_t)))
1086  found_attrs_cnt++;
1087  }
1088  }
1089 
1090  if (attr_cnt == found_attrs_cnt && NULL != ticket)
1091  {
1093  tih->cb (tih->cb_cls, &tih->ticket, GNUNET_OK, NULL);
1094  cleanup_issue_handle (tih);
1095  return;
1096  }
1097 
1098  // ticket not found in current record
1100 }
1101 
1102 
1103 static void
1105 {
1106  struct TicketIssueHandle *tih = cls;
1108  tih->ticket.rnd =
1110  issue_ticket (tih);
1111 }
1112 
1113 void
1116  const struct GNUNET_CRYPTO_EcdsaPublicKey *audience,
1118  void *cb_cls)
1119 {
1120  struct TicketIssueHandle *tih;
1121  tih = GNUNET_new (struct TicketIssueHandle);
1122  tih->cb = cb;
1123  tih->cb_cls = cb_cls;
1125  tih->identity = *identity;
1126  tih->ticket.audience = *audience;
1127 
1128  // check whether the ticket has already been issued
1129  tih->ns_it =
1131  &tih->identity,
1133  tih,
1135  tih,
1137  tih);
1138 }
1139 
1140 /************************************
1141  * Ticket iteration
1142  ************************************/
1143 
1144 static void
1146 {
1147  if (NULL != iter->ns_it)
1149  GNUNET_free (iter);
1150 }
1151 
1152 
1153 static void
1155  const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
1156  const char *label,
1157  unsigned int rd_count,
1158  const struct GNUNET_GNSRECORD_Data *rd)
1159 {
1160  struct RECLAIM_TICKETS_Iterator *iter = cls;
1161 
1162  for (int i = 0; i < rd_count; i++)
1163  {
1164  if (GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET != rd[i].record_type)
1165  continue;
1166  iter->cb (iter->cb_cls, (struct GNUNET_RECLAIM_Ticket *) rd[i].data);
1167  return;
1168  }
1170 }
1171 
1172 
1173 static void
1175 {
1176  struct RECLAIM_TICKETS_Iterator *iter = cls;
1177  iter->ns_it = NULL;
1178  iter->cb (iter->cb_cls, NULL);
1179  cleanup_iter (iter);
1180 }
1181 
1182 
1183 static void
1185 {
1186  struct RECLAIM_TICKETS_Iterator *iter = cls;
1187  iter->ns_it = NULL;
1188  iter->cb (iter->cb_cls, NULL);
1189  cleanup_iter (iter);
1190 }
1191 
1192 
1193 void
1195 {
1197 }
1198 
1199 
1200 void
1202 {
1204  cleanup_iter (iter);
1205 }
1206 
1207 
1208 struct RECLAIM_TICKETS_Iterator *
1212  void *cb_cls)
1213 {
1214  struct RECLAIM_TICKETS_Iterator *iter;
1215 
1216  iter = GNUNET_new (struct RECLAIM_TICKETS_Iterator);
1217  iter->cb = cb;
1218  iter->cb_cls = cb_cls;
1219  iter->ns_it =
1221  identity,
1223  iter,
1225  iter,
1227  iter);
1228  return iter;
1229 }
1230 
1231 
1232 int
1234 {
1235  // Get ticket expiration time (relative) from config
1236  if (GNUNET_OK ==
1238  "reclaim",
1239  "TICKET_REFRESH_INTERVAL",
1241  {
1243  "Configured refresh interval for tickets: %s\n",
1245  GNUNET_YES));
1246  }
1247  else
1248  {
1250  }
1251  // Connect to identity and namestore services
1252  nsh = GNUNET_NAMESTORE_connect (c);
1253  if (NULL == nsh)
1254  {
1256  "error connecting to namestore");
1257  return GNUNET_SYSERR;
1258  }
1259  gns = GNUNET_GNS_connect (c);
1260  if (NULL == gns)
1261  {
1262  GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "error connecting to gns");
1263  return GNUNET_SYSERR;
1264  }
1265  stats = GNUNET_STATISTICS_create ("reclaim", c);
1266  return GNUNET_OK;
1267 }
1268 
1269 void
1271 {
1272  if (NULL != nsh)
1274  nsh = NULL;
1275  if (NULL != gns)
1276  GNUNET_GNS_disconnect (gns);
1277  gns = NULL;
1278  if (NULL != stats)
1279  {
1281  stats = NULL;
1282  }
1283 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
const char * name
The name of the attribute.
struct GNUNET_RECLAIM_ATTRIBUTE_Claim * claim
The attribute claim.
Connection to the GNS service.
Definition: gns_api.h:35
static void rvk_move_attr_cb(void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
static void filter_tickets_finished_cb(void *cls)
static void cleanup_iter(struct RECLAIM_TICKETS_Iterator *iter)
The authorization ticket.
static void abort_parallel_lookups(void *cls)
struct TicketReference * prev
DLL.
struct GNUNET_RECLAIM_Ticket ticket
Tickets.
struct GNUNET_NAMESTORE_QueueEntry * ns_qe
QueueEntry.
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.
int GNUNET_CONFIGURATION_get_value_time(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, struct GNUNET_TIME_Relative *time)
Get a configuration value that should be a relative time.
uint64_t rel_value_us
The actual value.
Ticket revocation request handle.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry * list_tail
List tail.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_lookup(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, const char *label, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor rm, void *rm_cls)
Lookup an item in the namestore.
static void issue_ticket(struct TicketIssueHandle *ih)
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Random on unsigned 64-bit values.
ssize_t GNUNET_GNSRECORD_records_serialize(unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, size_t dest_size, char *dest)
Serialize the given records to the given destination buffer.
struct GNUNET_NAMESTORE_ZoneIterator * GNUNET_NAMESTORE_zone_iteration_start(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor proc, void *proc_cls, GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls)
Starts a new zone iteration (used to periodically PUT all of our records into our DHT)...
static void move_attr_finished(void *cls, int32_t success, const char *emsg)
#define GNUNET_TIME_UNIT_MINUTES
One minute.
struct GNUNET_TIME_Absolute lookup_start_time
Lookup time.
static void ticket_processed(void *cls, int32_t success, const char *emsg)
struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList * attrs
Attributes.
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR
Record type for identity attributes (of RECLAIM).
static void process_parallel_lookup_result(void *cls, uint32_t rd_count, const struct GNUNET_GNSRECORD_Data *rd)
void RECLAIM_TICKETS_iteration_stop(struct RECLAIM_TICKETS_Iterator *iter)
static struct GNUNET_TIME_Relative ticket_refresh_interval
Ticket expiration interval.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint64_t new_id
New ID of the attribute.
static void move_attrs(struct RECLAIM_TICKETS_RevokeHandle *rh)
struct GNUNET_NAMESTORE_QueueEntry * ns_qe
QueueEntry.
static void store_ticket_issue_cont(void *cls, int32_t success, const char *emsg)
Handle to a lookup request.
Definition: gns_api.c:42
struct ParallelLookup * prev
static void rvk_ns_iter_err(void *cls)
struct GNUNET_RECLAIM_Ticket ticket
Ticket to issue.
struct RevokedAttributeEntry * attrs_tail
Revoked attributes.
struct GNUNET_CRYPTO_EcdsaPrivateKey identity
Audience Key.
#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF
Record type for reclaim records.
#define GNUNET_NO
Definition: gnunet_common.h:81
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
struct GNUNET_SCHEDULER_Task * kill_task
Kill task.
size_t data_size
Number of bytes in data.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct RECLAIM_TICKETS_ConsumeHandle * handle
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...
Private ECC key encoded for transmission.
void(* RECLAIM_TICKETS_TicketIter)(void *cls, struct GNUNET_RECLAIM_Ticket *ticket)
Continuation called with ticket.
struct RevokedAttributeEntry * next
DLL.
struct TicketReference * next
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.
struct GNUNET_GNS_LookupRequest * lookup_request
static void filter_tickets_error_cb(void *cls)
static void collect_tickets_cb(void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
struct RECLAIM_TICKETS_Iterator * RECLAIM_TICKETS_iteration_start(const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, RECLAIM_TICKETS_TicketIter cb, void *cb_cls)
Handle for the service.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
struct GNUNET_TIME_Absolute lookup_start_time
Lookup time.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static void revoke_attrs_cb(void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
void GNUNET_NAMESTORE_cancel(struct GNUNET_NAMESTORE_QueueEntry *qe)
Cancel a namestore operation.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_store(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls)
Store an item in the namestore.
static void del_attr_finished(void *cls, int32_t success, const char *emsg)
static char * zone
Name of the zone we manage.
void GNUNET_NAMESTORE_disconnect(struct GNUNET_NAMESTORE_Handle *h)
Disconnect from the namestore service (and free associated resources).
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
void GNUNET_RECLAIM_ATTRIBUTE_list_destroy(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs)
Destroy claim list.
struct RevokedAttributeEntry * move_attr
Current attribute to move.
Handle for a zone iterator operation.
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:1246
const void * data
Binary value stored in the DNS record.
RECLAIM_TICKETS_TicketIter cb
Iter callback.
Connection to the NAMESTORE service.
uint64_t expiration_time
Expiration time for the DNS record.
static void rvk_ticket_update_finished(void *cls)
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1273
unsigned int rd_count
Record count.
void GNUNET_GNS_disconnect(struct GNUNET_GNS_Handle *handle)
Shutdown connection with the GNS service.
Definition: gns_api.c:285
static void move_attrs_cont(void *cls)
static void collect_tickets_error_cb(void *cls)
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:727
static void cleanup_issue_handle(struct TicketIssueHandle *handle)
Cleanup ticket consume handle.
struct GNUNET_CRYPTO_EcdsaPrivateKey identity
Issuer Key.
struct TicketRecordsEntry * tickets_to_update_tail
Tickets to update.
void RECLAIM_TICKETS_iteration_next(struct RECLAIM_TICKETS_Iterator *iter)
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:439
void(* RECLAIM_TICKETS_ConsumeCallback)(void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *l, int32_t success, const char *emsg)
struct GNUNET_GNS_Handle * GNUNET_GNS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the connection with the GNS service.
Definition: gns_api.c:263
This is a private record of this peer and it should thus not be handed out to other peers...
RECLAIM_TICKETS_RevokeCallback cb
Callback.
static void rvk_attrs_err_cb(void *cls)
#define DEFAULT_TICKET_REFRESH_INTERVAL
static void cleanup_cth(struct RECLAIM_TICKETS_ConsumeHandle *cth)
Cleanup ticket consume handle.
void GNUNET_NAMESTORE_zone_iteration_stop(struct GNUNET_NAMESTORE_ZoneIterator *it)
Stops iteration and releases the namestore handle for further calls.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
struct RevokedAttributeEntry * attrs_head
Revoked attributes.
struct TicketRecordsEntry * tickets_to_update_head
Tickets to update.
struct GNUNET_NAMESTORE_ZoneIterator * ns_it
Namestore Iterator.
struct GNUNET_CRYPTO_EcdsaPublicKey identity
The ticket issuer (= the user)
static void cleanup_rvk(struct RECLAIM_TICKETS_RevokeHandle *rh)
Cleanup revoke handle.
void RECLAIM_TICKETS_consume_cancel(struct RECLAIM_TICKETS_ConsumeHandle *cth)
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList * attrs
Attributes.
void GNUNET_CRYPTO_ecdsa_key_get_public(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:241
struct ParallelLookup * next
An QueueEntry used to store information for a pending NAMESTORE record operation. ...
Definition: namestore_api.c:53
uint64_t rnd
The ticket random (NBO)
static struct GNUNET_NAMESTORE_Handle * nsh
struct GNUNET_NAMESTORE_Handle * GNUNET_NAMESTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the namestore service.
void RECLAIM_TICKETS_issue(const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, const struct GNUNET_CRYPTO_EcdsaPublicKey *audience, RECLAIM_TICKETS_TicketResult cb, void *cb_cls)
struct GNUNET_NAMESTORE_ZoneIterator * ns_it
Namestore queue entry.
struct GNUNET_GNS_LookupRequest * lookup_request
LookupRequest.
struct GNUNET_RECLAIM_Ticket ticket
Ticket.
struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList * attrs
Attributes to issue.
void RECLAIM_TICKETS_revoke_cancel(struct RECLAIM_TICKETS_RevokeHandle *rh)
void(* RECLAIM_TICKETS_TicketResult)(void *cls, struct GNUNET_RECLAIM_Ticket *ticket, int32_t success, const char *emsg)
Continuation called with ticket.
struct GNUNET_NAMESTORE_ZoneIterator * ns_it
Namestore iterator.
struct RevokedAttributeEntry * prev
DLL.
static void process_tickets(void *cls)
size_t GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size(const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
Get required size for serialization buffer.
uint32_t record_type
Type of the GNS/DNS record.
struct RECLAIM_TICKETS_RevokeHandle * RECLAIM_TICKETS_revoke(const struct GNUNET_RECLAIM_Ticket *ticket, const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, RECLAIM_TICKETS_RevokeCallback cb, void *cb_cls)
configuration data
Definition: configuration.c:85
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition: time.c:373
struct GNUNET_CRYPTO_EcdsaPublicKey audience
The ticket audience (= relying party)
RECLAIM_TICKETS_ConsumeCallback cb
Callback.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
void RECLAIM_TICKETS_deinit(void)
A list of GNUNET_RECLAIM_ATTRIBUTE_Claim structures.
static void remove_ticket_cont(void *cls, int32_t success, const char *emsg)
struct RECLAIM_TICKETS_ConsumeHandle * RECLAIM_TICKETS_consume(const struct GNUNET_CRYPTO_EcdsaPrivateKey *id, const struct GNUNET_RECLAIM_Ticket *ticket, RECLAIM_TICKETS_ConsumeCallback cb, void *cb_cls)
#define GNUNET_log(kind,...)
Entry in list of pending tasks.
Definition: scheduler.c:134
void * GNUNET_GNS_lookup_cancel(struct GNUNET_GNS_LookupRequest *lr)
Cancel pending lookup request.
Definition: gns_api.c:309
#define GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET
Record type for local ticket references.
Ticket issue request handle.
A reference to a ticket stored in GNS.
size_t GNUNET_RECLAIM_ATTRIBUTE_serialize(const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, char *result)
Serialize an attribute.
Time for absolute times used by GNUnet, in microseconds.
RECLAIM_TICKETS_TicketResult cb
Callback.
#define GNUNET_YES
Definition: gnunet_common.h:80
struct GNUNET_RECLAIM_ATTRIBUTE_Claim * claim
Claim to store.
Defaults, look in cache, then in DHT.
uint64_t old_id
Old ID of the attribute.
static void collect_tickets_finished_cb(void *cls)
struct GNUNET_RECLAIM_Ticket ticket
Ticket to issue.
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:988
enum GNUNET_GNSRECORD_Flags flags
Flags for the record.
This flag is currently unused; former RF_PENDING flag.
static void filter_tickets_cb(void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
struct GNUNET_GNS_LookupRequest * GNUNET_GNS_lookup(struct GNUNET_GNS_Handle *handle, const char *name, const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, uint32_t type, enum GNUNET_GNS_LocalOptions options, GNUNET_GNS_LookupResultProcessor proc, void *proc_cls)
Perform an asynchronous lookup operation on the GNS.
Definition: gns_api.c:337
uint32_t data
The data value.
struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry * next
DLL.
static size_t data_size
Number of bytes in data.
int RECLAIM_TICKETS_init(const struct GNUNET_CONFIGURATION_Handle *c)
struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList * GNUNET_RECLAIM_ATTRIBUTE_list_dup(const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs)
Make a (deep) copy of a claim list.
struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry * list_head
List head.
struct GNUNET_CRYPTO_EcdsaPrivateKey identity
Issuer Key.
static void rvk_ticket_update(void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
void(* RECLAIM_TICKETS_RevokeCallback)(void *cls, int32_t success)
struct ParallelLookup * parallel_lookups_tail
Lookup DLL.
static void lookup_authz_cb(void *cls, uint32_t rd_count, const struct GNUNET_GNSRECORD_Data *rd)
unsigned int ticket_attrs
Number of attributes in ticket.
static struct GNUNET_STATISTICS_Handle * stats
static struct GNUNET_GNS_Handle * gns
struct GNUNET_RECLAIM_ATTRIBUTE_Claim * GNUNET_RECLAIM_ATTRIBUTE_deserialize(const char *data, size_t data_size)
Deserialize an attribute.
static void rvk_ns_err(void *cls)
#define GNUNET_malloc(size)
Wrapper around malloc.
struct ParallelLookup * parallel_lookups_head
Lookup DLL.
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
Handle for a parallel GNS lookup job.
struct GNUNET_CRYPTO_EcdsaPublicKey identity_pub
Audience Key.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
High-quality operations are desired.