aboutsummaryrefslogtreecommitdiff
path: root/src/reclaim/gnunet-service-reclaim_tickets.h
blob: 1c7214d4216fbeebcf26ed7ae925646adc88144b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/*
   This file is part of GNUnet.
   Copyright (C) 2012-2015 GNUnet e.V.

   GNUnet is free software: you can redistribute it and/or modify it
   under the terms of the GNU Affero General Public License as published
   by the Free Software Foundation, either version 3 of the License,
   or (at your option) any later version.

   GNUnet is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Affero General Public License for more details.

   You should have received a copy of the GNU Affero General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.

   SPDX-License-Identifier: AGPL3.0-or-later
 */

/**
 * @author Martin Schanzenbach
 * @file src/reclaim/gnunet-service-reclaim_tickets.h
 * @brief reclaim tickets
 *
 */

#ifndef GNUNET_SERVICE_RECLAIM_TICKETS_H
#define GNUNET_SERVICE_RECLAIM_TICKETS_H

#include "platform.h"

#include "gnunet_util_lib.h"

#include "gnunet_constants.h"
#include "gnunet_gns_service.h"
#include "gnunet_gnsrecord_lib.h"
#include "gnunet_protocols.h"
#include "gnunet_reclaim_lib.h"
#include "gnunet_reclaim_service.h"
#include "gnunet_signatures.h"
#include "gnunet_statistics_service.h"
#include "reclaim.h"

/**
 * Ticket iterator
 */
struct RECLAIM_TICKETS_Iterator;


/**
 * Handle to a consume operation
 */
struct RECLAIM_TICKETS_ConsumeHandle;


/**
 * Ticket revocation request handle
 */
struct RECLAIM_TICKETS_RevokeHandle;


/**
 * List of tickets
 */
struct TicketRecordsEntry
{
  /**
   * DLL
   */
  struct TicketRecordsEntry *next;

  /**
   * DLL
   */
  struct TicketRecordsEntry *prev;

  /**
   * Record count
   */
  unsigned int rd_count;

  /**
   * Data
   */
  char *data;

  /**
   * Data size
   */
  size_t data_size;

  /**
   * Label
   */
  char *label;
};


/**
 * Continuation called with ticket.
 *
 * @param cls closure
 * @param ticket the ticket
 */
typedef void (*RECLAIM_TICKETS_TicketIter) (
  void *cls,
  struct GNUNET_RECLAIM_Ticket *ticket);


/**
 * Continuation called with ticket.
 *
 * @param cls closure
 * @param ticket the ticket
 * @param success #GNUNET_SYSERR on failure (including timeout/queue
 * drop/failure to validate) #GNUNET_OK on success
 * @param emsg NULL on success, otherwise an error message
 */
typedef void (*RECLAIM_TICKETS_TicketResult) (
  void *cls,
  struct GNUNET_RECLAIM_Ticket *ticket,
  int32_t success,
  const char *emsg);


/**
 * Consume callback.
 *
 * @param cls closure
 * @param identity the issuer of the ticket/attributes
 * @param l attribute list retrieved through ticket
 * @param success GNUNET_OK on success
 * @param emsg error message (NULL on success)
 */
typedef void (*RECLAIM_TICKETS_ConsumeCallback) (
  void *cls,
  const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
  const struct GNUNET_RECLAIM_AttributeList *attributes,
  const struct GNUNET_RECLAIM_AttestationList *attestations,
  int32_t success,
  const char *emsg);


/**
 * Revocation callback.
 *
 * @param cls closure
 * @param success GNUNET_OK on success
 */
typedef void (*RECLAIM_TICKETS_RevokeCallback) (void *cls, int32_t success);


/**
 * Revoke a ticket.
 * We start by looking up attribute references in order
 * to change attribute IDs.
 *
 * @param ticket ticket to revoke
 * @param identity private key of issuer
 * @param cb revocation status callback
 * @param cb_cls callback closure
 * @return handle to the operation
 */
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);


/**
 * Cancel a revocation.
 *
 * @param rh handle to the operation
 */
void
RECLAIM_TICKETS_revoke_cancel (struct RECLAIM_TICKETS_RevokeHandle *rh);


/**
 * Consume a ticket.
 * We first looking attribute references under the label
 * ticket.rnd in GNS.
 *
 * @param id the audience of the ticket
 * @param ticket the ticket to consume
 * @param cb callback to call with attributes of ticket
 * @param cb_cls callback closure
 * @return handle to the operation
 */
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);


/**
 * Cancel a consume operation
 *
 * @param cth the operation to cancel
 */
void
RECLAIM_TICKETS_consume_cancel (struct RECLAIM_TICKETS_ConsumeHandle *cth);


/**
 * Issue a new reclaim ticket, thereby authorizing
 * the audience to access the set of provided attributes.
 *
 * @param identity the issuer
 * @param attrs the attributes to share
 * @param audience the audience to share the attributes with
 * @param cb the callback to call with the ticket result
 * @param cb_cls the callback closure
 * FIXME: Return handle??
 */
void
RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
                       const struct GNUNET_RECLAIM_AttributeList *attrs,
                       const struct GNUNET_CRYPTO_EcdsaPublicKey *audience,
                       RECLAIM_TICKETS_TicketResult cb,
                       void *cb_cls);


/**
 * Continue ticket iteration
 *
 * @param iter the iteration to continue
 */
void
RECLAIM_TICKETS_iteration_next (struct RECLAIM_TICKETS_Iterator *iter);


/**
 * Stop a running ticket iteration
 *
 * @param iter iteration to cancel
 */
void
RECLAIM_TICKETS_iteration_stop (struct RECLAIM_TICKETS_Iterator *iter);


/**
 * Iterate over all tickets issued by an identity
 *
 * @param identity the issuing identity
 * @param cb ticket callback function
 * @param cb_cls callback closure
 * @return a handle to the iteration
 */
struct RECLAIM_TICKETS_Iterator *
RECLAIM_TICKETS_iteration_start (
  const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
  RECLAIM_TICKETS_TicketIter cb,
  void *cb_cls);


/**
 * Initialize tickets component
 *
 * @param c the configuration
 * @return GNUNET_SYSERR on error
 */
int
RECLAIM_TICKETS_init (const struct GNUNET_CONFIGURATION_Handle *c);


/**
 * Close handles and clean up.
 * FIXME: cancel all pending operations (gns, ns etc)
 */
void
RECLAIM_TICKETS_deinit (void);

#endif