diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-04-14 09:51:33 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-04-14 10:01:24 +0200 |
commit | 48b97768c64eb4e2695756b44e95eedacdf21c02 (patch) | |
tree | 366c65e27fe09d8cffd1cea3b4ae1e736274b7fa /src/reclaim | |
parent | eb2d072aa1096c9d77cbfde239a1004cab642e64 (diff) | |
download | gnunet-48b97768c64eb4e2695756b44e95eedacdf21c02.tar.gz gnunet-48b97768c64eb4e2695756b44e95eedacdf21c02.zip |
RECLAIM: remove sqlite plugin; housekeeping
Diffstat (limited to 'src/reclaim')
-rw-r--r-- | src/reclaim/Makefile.am | 17 | ||||
-rw-r--r-- | src/reclaim/plugin_reclaim_sqlite.c | 736 | ||||
-rw-r--r-- | src/reclaim/reclaim.conf | 4 | ||||
-rw-r--r-- | src/reclaim/reclaim_api.c | 501 |
4 files changed, 195 insertions, 1063 deletions
diff --git a/src/reclaim/Makefile.am b/src/reclaim/Makefile.am index 7e8686734..67d640357 100644 --- a/src/reclaim/Makefile.am +++ b/src/reclaim/Makefile.am | |||
@@ -12,9 +12,6 @@ if USE_COVERAGE | |||
12 | XLIB = -lgcov | 12 | XLIB = -lgcov |
13 | endif | 13 | endif |
14 | 14 | ||
15 | if HAVE_SQLITE | ||
16 | SQLITE_PLUGIN = libgnunet_plugin_reclaim_sqlite.la | ||
17 | endif | ||
18 | 15 | ||
19 | if HAVE_MHD | 16 | if HAVE_MHD |
20 | if HAVE_JSON | 17 | if HAVE_JSON |
@@ -41,7 +38,6 @@ lib_LTLIBRARIES = \ | |||
41 | libgnunetreclaim.la | 38 | libgnunetreclaim.la |
42 | plugin_LTLIBRARIES = \ | 39 | plugin_LTLIBRARIES = \ |
43 | libgnunet_plugin_gnsrecord_reclaim.la \ | 40 | libgnunet_plugin_gnsrecord_reclaim.la \ |
44 | $(SQLITE_PLUGIN) \ | ||
45 | $(REST_PLUGIN) | 41 | $(REST_PLUGIN) |
46 | 42 | ||
47 | bin_PROGRAMS = \ | 43 | bin_PROGRAMS = \ |
@@ -93,19 +89,6 @@ libgnunet_plugin_gnsrecord_reclaim_la_LIBADD = \ | |||
93 | libgnunet_plugin_gnsrecord_reclaim_la_LDFLAGS = \ | 89 | libgnunet_plugin_gnsrecord_reclaim_la_LDFLAGS = \ |
94 | $(GN_PLUGIN_LDFLAGS) | 90 | $(GN_PLUGIN_LDFLAGS) |
95 | 91 | ||
96 | libgnunet_plugin_reclaim_sqlite_la_SOURCES = \ | ||
97 | plugin_reclaim_sqlite.c | ||
98 | libgnunet_plugin_reclaim_sqlite_la_LIBADD = \ | ||
99 | libgnunetreclaim.la \ | ||
100 | $(top_builddir)/src/sq/libgnunetsq.la \ | ||
101 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | ||
102 | $(top_builddir)/src/reclaim-attribute/libgnunetreclaimattribute.la \ | ||
103 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) -lsqlite3 \ | ||
104 | $(LTLIBINTL) | ||
105 | libgnunet_plugin_reclaim_sqlite_la_LDFLAGS = \ | ||
106 | $(GN_PLUGIN_LDFLAGS) | ||
107 | |||
108 | |||
109 | 92 | ||
110 | gnunet_service_reclaim_SOURCES = \ | 93 | gnunet_service_reclaim_SOURCES = \ |
111 | gnunet-service-reclaim.c \ | 94 | gnunet-service-reclaim.c \ |
diff --git a/src/reclaim/plugin_reclaim_sqlite.c b/src/reclaim/plugin_reclaim_sqlite.c deleted file mode 100644 index f6e1436cc..000000000 --- a/src/reclaim/plugin_reclaim_sqlite.c +++ /dev/null | |||
@@ -1,736 +0,0 @@ | |||
1 | /* | ||
2 | * This file is part of GNUnet | ||
3 | * Copyright (C) 2009-2017 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 | |||
21 | /** | ||
22 | * @file reclaim/plugin_reclaim_sqlite.c | ||
23 | * @brief sqlite-based idp backend | ||
24 | * @author Martin Schanzenbach | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_reclaim_service.h" | ||
29 | #include "gnunet_reclaim_plugin.h" | ||
30 | #include "gnunet_reclaim_attribute_lib.h" | ||
31 | #include "gnunet_sq_lib.h" | ||
32 | #include <sqlite3.h> | ||
33 | |||
34 | /** | ||
35 | * After how many ms "busy" should a DB operation fail for good? A | ||
36 | * low value makes sure that we are more responsive to requests | ||
37 | * (especially PUTs). A high value guarantees a higher success rate | ||
38 | * (SELECTs in iterate can take several seconds despite LIMIT=1). | ||
39 | * | ||
40 | * The default value of 1s should ensure that users do not experience | ||
41 | * huge latencies while at the same time allowing operations to | ||
42 | * succeed with reasonable probability. | ||
43 | */ | ||
44 | #define BUSY_TIMEOUT_MS 1000 | ||
45 | |||
46 | |||
47 | /** | ||
48 | * Log an error message at log-level 'level' that indicates | ||
49 | * a failure of the command 'cmd' on file 'filename' | ||
50 | * with the message given by strerror(errno). | ||
51 | */ | ||
52 | #define LOG_SQLITE(db, level, cmd) do { GNUNET_log_from (level, "reclaim", _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db->dbh)); } while(0) | ||
53 | |||
54 | #define LOG(kind,...) GNUNET_log_from (kind, "reclaim-sqlite", __VA_ARGS__) | ||
55 | |||
56 | |||
57 | /** | ||
58 | * Context for all functions in this plugin. | ||
59 | */ | ||
60 | struct Plugin | ||
61 | { | ||
62 | |||
63 | const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
64 | |||
65 | /** | ||
66 | * Database filename. | ||
67 | */ | ||
68 | char *fn; | ||
69 | |||
70 | /** | ||
71 | * Native SQLite database handle. | ||
72 | */ | ||
73 | sqlite3 *dbh; | ||
74 | |||
75 | /** | ||
76 | * Precompiled SQL to store ticket. | ||
77 | */ | ||
78 | sqlite3_stmt *store_ticket; | ||
79 | |||
80 | /** | ||
81 | * Precompiled SQL to delete existing ticket. | ||
82 | */ | ||
83 | sqlite3_stmt *delete_ticket; | ||
84 | |||
85 | /** | ||
86 | * Precompiled SQL to iterate tickets. | ||
87 | */ | ||
88 | sqlite3_stmt *iterate_tickets; | ||
89 | |||
90 | /** | ||
91 | * Precompiled SQL to get ticket attributes. | ||
92 | */ | ||
93 | sqlite3_stmt *get_ticket_attrs; | ||
94 | |||
95 | /** | ||
96 | * Precompiled SQL to iterate tickets by audience. | ||
97 | */ | ||
98 | sqlite3_stmt *iterate_tickets_by_audience; | ||
99 | }; | ||
100 | |||
101 | |||
102 | /** | ||
103 | * @brief Prepare a SQL statement | ||
104 | * | ||
105 | * @param dbh handle to the database | ||
106 | * @param zSql SQL statement, UTF-8 encoded | ||
107 | * @param ppStmt set to the prepared statement | ||
108 | * @return 0 on success | ||
109 | */ | ||
110 | static int | ||
111 | sq_prepare (sqlite3 *dbh, | ||
112 | const char *zSql, | ||
113 | sqlite3_stmt **ppStmt) | ||
114 | { | ||
115 | char *dummy; | ||
116 | int result; | ||
117 | |||
118 | result = | ||
119 | sqlite3_prepare_v2 (dbh, | ||
120 | zSql, | ||
121 | strlen (zSql), | ||
122 | ppStmt, | ||
123 | (const char **) &dummy); | ||
124 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
125 | "Prepared `%s' / %p: %d\n", | ||
126 | zSql, | ||
127 | *ppStmt, | ||
128 | result); | ||
129 | return result; | ||
130 | } | ||
131 | |||
132 | /** | ||
133 | * Create our database indices. | ||
134 | * | ||
135 | * @param dbh handle to the database | ||
136 | */ | ||
137 | static void | ||
138 | create_indices (sqlite3 * dbh) | ||
139 | { | ||
140 | /* create indices */ | ||
141 | if ( (SQLITE_OK != | ||
142 | sqlite3_exec (dbh, | ||
143 | "CREATE INDEX IF NOT EXISTS identity_reverse ON identity001tickets (identity,audience)", | ||
144 | NULL, NULL, NULL)) || | ||
145 | (SQLITE_OK != | ||
146 | sqlite3_exec (dbh, | ||
147 | "CREATE INDEX IF NOT EXISTS it_iter ON identity001tickets (rnd)", | ||
148 | NULL, NULL, NULL)) ) | ||
149 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
150 | "Failed to create indices: %s\n", | ||
151 | sqlite3_errmsg (dbh)); | ||
152 | } | ||
153 | |||
154 | |||
155 | |||
156 | #if 0 | ||
157 | #define CHECK(a) GNUNET_break(a) | ||
158 | #define ENULL NULL | ||
159 | #else | ||
160 | #define ENULL &e | ||
161 | #define ENULL_DEFINED 1 | ||
162 | #define CHECK(a) if (! (a)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "%s\n", e); sqlite3_free(e); } | ||
163 | #endif | ||
164 | |||
165 | |||
166 | /** | ||
167 | * Initialize the database connections and associated | ||
168 | * data structures (create tables and indices | ||
169 | * as needed as well). | ||
170 | * | ||
171 | * @param plugin the plugin context (state for this module) | ||
172 | * @return #GNUNET_OK on success | ||
173 | */ | ||
174 | static int | ||
175 | database_setup (struct Plugin *plugin) | ||
176 | { | ||
177 | sqlite3_stmt *stmt; | ||
178 | char *afsdir; | ||
179 | #if ENULL_DEFINED | ||
180 | char *e; | ||
181 | #endif | ||
182 | |||
183 | if (GNUNET_OK != | ||
184 | GNUNET_CONFIGURATION_get_value_filename (plugin->cfg, | ||
185 | "reclaim-sqlite", | ||
186 | "FILENAME", | ||
187 | &afsdir)) | ||
188 | { | ||
189 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | ||
190 | "reclaim-sqlite", | ||
191 | "FILENAME"); | ||
192 | return GNUNET_SYSERR; | ||
193 | } | ||
194 | if (GNUNET_OK != | ||
195 | GNUNET_DISK_file_test (afsdir)) | ||
196 | { | ||
197 | if (GNUNET_OK != | ||
198 | GNUNET_DISK_directory_create_for_file (afsdir)) | ||
199 | { | ||
200 | GNUNET_break (0); | ||
201 | GNUNET_free (afsdir); | ||
202 | return GNUNET_SYSERR; | ||
203 | } | ||
204 | } | ||
205 | /* afsdir should be UTF-8-encoded. If it isn't, it's a bug */ | ||
206 | plugin->fn = afsdir; | ||
207 | |||
208 | /* Open database and precompile statements */ | ||
209 | if (sqlite3_open (plugin->fn, &plugin->dbh) != SQLITE_OK) | ||
210 | { | ||
211 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
212 | _("Unable to initialize SQLite: %s.\n"), | ||
213 | sqlite3_errmsg (plugin->dbh)); | ||
214 | return GNUNET_SYSERR; | ||
215 | } | ||
216 | CHECK (SQLITE_OK == | ||
217 | sqlite3_exec (plugin->dbh, | ||
218 | "PRAGMA temp_store=MEMORY", NULL, NULL, | ||
219 | ENULL)); | ||
220 | CHECK (SQLITE_OK == | ||
221 | sqlite3_exec (plugin->dbh, | ||
222 | "PRAGMA synchronous=NORMAL", NULL, NULL, | ||
223 | ENULL)); | ||
224 | CHECK (SQLITE_OK == | ||
225 | sqlite3_exec (plugin->dbh, | ||
226 | "PRAGMA legacy_file_format=OFF", NULL, NULL, | ||
227 | ENULL)); | ||
228 | CHECK (SQLITE_OK == | ||
229 | sqlite3_exec (plugin->dbh, | ||
230 | "PRAGMA auto_vacuum=INCREMENTAL", NULL, | ||
231 | NULL, ENULL)); | ||
232 | CHECK (SQLITE_OK == | ||
233 | sqlite3_exec (plugin->dbh, | ||
234 | "PRAGMA encoding=\"UTF-8\"", NULL, | ||
235 | NULL, ENULL)); | ||
236 | CHECK (SQLITE_OK == | ||
237 | sqlite3_exec (plugin->dbh, | ||
238 | "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL, | ||
239 | ENULL)); | ||
240 | CHECK (SQLITE_OK == | ||
241 | sqlite3_exec (plugin->dbh, | ||
242 | "PRAGMA page_size=4092", NULL, NULL, | ||
243 | ENULL)); | ||
244 | |||
245 | CHECK (SQLITE_OK == | ||
246 | sqlite3_busy_timeout (plugin->dbh, | ||
247 | BUSY_TIMEOUT_MS)); | ||
248 | |||
249 | |||
250 | /* Create table */ | ||
251 | CHECK (SQLITE_OK == | ||
252 | sq_prepare (plugin->dbh, | ||
253 | "SELECT 1 FROM sqlite_master WHERE tbl_name = 'identity001tickets'", | ||
254 | &stmt)); | ||
255 | if ((sqlite3_step (stmt) == SQLITE_DONE) && | ||
256 | (sqlite3_exec | ||
257 | (plugin->dbh, | ||
258 | "CREATE TABLE identity001tickets (" | ||
259 | " identity BLOB NOT NULL DEFAULT ''," | ||
260 | " audience BLOB NOT NULL DEFAULT ''," | ||
261 | " rnd INT8 NOT NULL DEFAULT ''," | ||
262 | " attributes BLOB NOT NULL DEFAULT ''" | ||
263 | ")", | ||
264 | NULL, NULL, NULL) != SQLITE_OK)) | ||
265 | { | ||
266 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, | ||
267 | "sqlite3_exec"); | ||
268 | sqlite3_finalize (stmt); | ||
269 | return GNUNET_SYSERR; | ||
270 | } | ||
271 | sqlite3_finalize (stmt); | ||
272 | |||
273 | create_indices (plugin->dbh); | ||
274 | |||
275 | if ( (SQLITE_OK != | ||
276 | sq_prepare (plugin->dbh, | ||
277 | "INSERT INTO identity001tickets (identity, audience, rnd, attributes)" | ||
278 | " VALUES (?, ?, ?, ?)", | ||
279 | &plugin->store_ticket)) || | ||
280 | (SQLITE_OK != | ||
281 | sq_prepare (plugin->dbh, | ||
282 | "DELETE FROM identity001tickets WHERE identity=? AND rnd=?", | ||
283 | &plugin->delete_ticket)) || | ||
284 | (SQLITE_OK != | ||
285 | sq_prepare (plugin->dbh, | ||
286 | "SELECT identity,audience,rnd,attributes" | ||
287 | " FROM identity001tickets WHERE identity=? AND rnd=?", | ||
288 | &plugin->get_ticket_attrs)) || | ||
289 | (SQLITE_OK != | ||
290 | sq_prepare (plugin->dbh, | ||
291 | "SELECT identity,audience,rnd,attributes" | ||
292 | " FROM identity001tickets WHERE identity=?" | ||
293 | " ORDER BY rnd LIMIT 1 OFFSET ?", | ||
294 | &plugin->iterate_tickets)) || | ||
295 | (SQLITE_OK != | ||
296 | sq_prepare (plugin->dbh, | ||
297 | "SELECT identity,audience,rnd,attributes" | ||
298 | " FROM identity001tickets WHERE audience=?" | ||
299 | " ORDER BY rnd LIMIT 1 OFFSET ?", | ||
300 | &plugin->iterate_tickets_by_audience)) ) | ||
301 | { | ||
302 | LOG_SQLITE (plugin, | ||
303 | GNUNET_ERROR_TYPE_ERROR, | ||
304 | "precompiling"); | ||
305 | return GNUNET_SYSERR; | ||
306 | } | ||
307 | return GNUNET_OK; | ||
308 | } | ||
309 | |||
310 | |||
311 | /** | ||
312 | * Shutdown database connection and associate data | ||
313 | * structures. | ||
314 | * @param plugin the plugin context (state for this module) | ||
315 | */ | ||
316 | static void | ||
317 | database_shutdown (struct Plugin *plugin) | ||
318 | { | ||
319 | int result; | ||
320 | sqlite3_stmt *stmt; | ||
321 | |||
322 | if (NULL != plugin->store_ticket) | ||
323 | sqlite3_finalize (plugin->store_ticket); | ||
324 | if (NULL != plugin->delete_ticket) | ||
325 | sqlite3_finalize (plugin->delete_ticket); | ||
326 | if (NULL != plugin->iterate_tickets) | ||
327 | sqlite3_finalize (plugin->iterate_tickets); | ||
328 | if (NULL != plugin->iterate_tickets_by_audience) | ||
329 | sqlite3_finalize (plugin->iterate_tickets_by_audience); | ||
330 | if (NULL != plugin->get_ticket_attrs) | ||
331 | sqlite3_finalize (plugin->get_ticket_attrs); | ||
332 | result = sqlite3_close (plugin->dbh); | ||
333 | if (result == SQLITE_BUSY) | ||
334 | { | ||
335 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
336 | _("Tried to close sqlite without finalizing all prepared statements.\n")); | ||
337 | stmt = sqlite3_next_stmt (plugin->dbh, | ||
338 | NULL); | ||
339 | while (NULL != stmt) | ||
340 | { | ||
341 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | ||
342 | "sqlite", | ||
343 | "Closing statement %p\n", | ||
344 | stmt); | ||
345 | result = sqlite3_finalize (stmt); | ||
346 | if (result != SQLITE_OK) | ||
347 | GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, | ||
348 | "sqlite", | ||
349 | "Failed to close statement %p: %d\n", | ||
350 | stmt, | ||
351 | result); | ||
352 | stmt = sqlite3_next_stmt (plugin->dbh, | ||
353 | NULL); | ||
354 | } | ||
355 | result = sqlite3_close (plugin->dbh); | ||
356 | } | ||
357 | if (SQLITE_OK != result) | ||
358 | LOG_SQLITE (plugin, | ||
359 | GNUNET_ERROR_TYPE_ERROR, | ||
360 | "sqlite3_close"); | ||
361 | |||
362 | GNUNET_free_non_null (plugin->fn); | ||
363 | } | ||
364 | |||
365 | |||
366 | /** | ||
367 | * Store a ticket in the database. | ||
368 | * | ||
369 | * @param cls closure (internal context for the plugin) | ||
370 | * @param ticket the ticket to persist | ||
371 | * @param attrs the attributes associated with the ticket | ||
372 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | ||
373 | */ | ||
374 | static int | ||
375 | reclaim_sqlite_store_ticket (void *cls, | ||
376 | const struct GNUNET_RECLAIM_Ticket *ticket, | ||
377 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs) | ||
378 | { | ||
379 | struct Plugin *plugin = cls; | ||
380 | size_t attrs_len; | ||
381 | char *attrs_ser; | ||
382 | int n; | ||
383 | |||
384 | { | ||
385 | /* First delete duplicates */ | ||
386 | struct GNUNET_SQ_QueryParam dparams[] = { | ||
387 | GNUNET_SQ_query_param_auto_from_type (&ticket->identity), | ||
388 | GNUNET_SQ_query_param_uint64 (&ticket->rnd), | ||
389 | GNUNET_SQ_query_param_end | ||
390 | }; | ||
391 | if (GNUNET_OK != | ||
392 | GNUNET_SQ_bind (plugin->delete_ticket, | ||
393 | dparams)) | ||
394 | { | ||
395 | LOG_SQLITE (plugin, | ||
396 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
397 | "sqlite3_bind_XXXX"); | ||
398 | GNUNET_SQ_reset (plugin->dbh, | ||
399 | plugin->delete_ticket); | ||
400 | return GNUNET_SYSERR; | ||
401 | } | ||
402 | n = sqlite3_step (plugin->delete_ticket); | ||
403 | GNUNET_SQ_reset (plugin->dbh, | ||
404 | plugin->delete_ticket); | ||
405 | |||
406 | attrs_len = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (attrs); | ||
407 | attrs_ser = GNUNET_malloc (attrs_len); | ||
408 | GNUNET_RECLAIM_ATTRIBUTE_list_serialize (attrs, | ||
409 | attrs_ser); | ||
410 | struct GNUNET_SQ_QueryParam sparams[] = { | ||
411 | GNUNET_SQ_query_param_auto_from_type (&ticket->identity), | ||
412 | GNUNET_SQ_query_param_auto_from_type (&ticket->audience), | ||
413 | GNUNET_SQ_query_param_uint64 (&ticket->rnd), | ||
414 | GNUNET_SQ_query_param_fixed_size (attrs_ser, attrs_len), | ||
415 | GNUNET_SQ_query_param_end | ||
416 | }; | ||
417 | |||
418 | if (GNUNET_OK != | ||
419 | GNUNET_SQ_bind (plugin->store_ticket, | ||
420 | sparams)) | ||
421 | { | ||
422 | LOG_SQLITE (plugin, | ||
423 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
424 | "sqlite3_bind_XXXX"); | ||
425 | GNUNET_SQ_reset (plugin->dbh, | ||
426 | plugin->store_ticket); | ||
427 | return GNUNET_SYSERR; | ||
428 | } | ||
429 | n = sqlite3_step (plugin->store_ticket); | ||
430 | GNUNET_SQ_reset (plugin->dbh, | ||
431 | plugin->store_ticket); | ||
432 | GNUNET_free (attrs_ser); | ||
433 | } | ||
434 | switch (n) | ||
435 | { | ||
436 | case SQLITE_DONE: | ||
437 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | ||
438 | "sqlite", | ||
439 | "Ticket stored\n"); | ||
440 | return GNUNET_OK; | ||
441 | case SQLITE_BUSY: | ||
442 | LOG_SQLITE (plugin, | ||
443 | GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | ||
444 | "sqlite3_step"); | ||
445 | return GNUNET_NO; | ||
446 | default: | ||
447 | LOG_SQLITE (plugin, | ||
448 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
449 | "sqlite3_step"); | ||
450 | return GNUNET_SYSERR; | ||
451 | } | ||
452 | } | ||
453 | |||
454 | |||
455 | /** | ||
456 | * Store a ticket in the database. | ||
457 | * | ||
458 | * @param cls closure (internal context for the plugin) | ||
459 | * @param ticket the ticket to delete | ||
460 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | ||
461 | */ | ||
462 | static int | ||
463 | reclaim_sqlite_delete_ticket (void *cls, | ||
464 | const struct GNUNET_RECLAIM_Ticket *ticket) | ||
465 | { | ||
466 | struct Plugin *plugin = cls; | ||
467 | int n; | ||
468 | |||
469 | { | ||
470 | struct GNUNET_SQ_QueryParam sparams[] = { | ||
471 | GNUNET_SQ_query_param_auto_from_type (&ticket->identity), | ||
472 | GNUNET_SQ_query_param_uint64 (&ticket->rnd), | ||
473 | GNUNET_SQ_query_param_end | ||
474 | }; | ||
475 | |||
476 | if (GNUNET_OK != | ||
477 | GNUNET_SQ_bind (plugin->delete_ticket, | ||
478 | sparams)) | ||
479 | { | ||
480 | LOG_SQLITE (plugin, | ||
481 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
482 | "sqlite3_bind_XXXX"); | ||
483 | GNUNET_SQ_reset (plugin->dbh, | ||
484 | plugin->store_ticket); | ||
485 | return GNUNET_SYSERR; | ||
486 | } | ||
487 | n = sqlite3_step (plugin->delete_ticket); | ||
488 | GNUNET_SQ_reset (plugin->dbh, | ||
489 | plugin->delete_ticket); | ||
490 | } | ||
491 | switch (n) | ||
492 | { | ||
493 | case SQLITE_DONE: | ||
494 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | ||
495 | "sqlite", | ||
496 | "Ticket deleted\n"); | ||
497 | return GNUNET_OK; | ||
498 | case SQLITE_BUSY: | ||
499 | LOG_SQLITE (plugin, | ||
500 | GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | ||
501 | "sqlite3_step"); | ||
502 | return GNUNET_NO; | ||
503 | default: | ||
504 | LOG_SQLITE (plugin, | ||
505 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
506 | "sqlite3_step"); | ||
507 | return GNUNET_SYSERR; | ||
508 | } | ||
509 | } | ||
510 | |||
511 | |||
512 | /** | ||
513 | * The given 'sqlite' statement has been prepared to be run. | ||
514 | * It will return a record which should be given to the iterator. | ||
515 | * Runs the statement and parses the returned record. | ||
516 | * | ||
517 | * @param plugin plugin context | ||
518 | * @param stmt to run (and then clean up) | ||
519 | * @param iter iterator to call with the result | ||
520 | * @param iter_cls closure for @a iter | ||
521 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error | ||
522 | */ | ||
523 | static int | ||
524 | get_ticket_and_call_iterator (struct Plugin *plugin, | ||
525 | sqlite3_stmt *stmt, | ||
526 | GNUNET_RECLAIM_TicketIterator iter, | ||
527 | void *iter_cls) | ||
528 | { | ||
529 | struct GNUNET_RECLAIM_Ticket ticket; | ||
530 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs; | ||
531 | int ret; | ||
532 | int sret; | ||
533 | size_t attrs_len; | ||
534 | char *attrs_ser; | ||
535 | |||
536 | ret = GNUNET_NO; | ||
537 | if (SQLITE_ROW == (sret = sqlite3_step (stmt))) | ||
538 | { | ||
539 | struct GNUNET_SQ_ResultSpec rs[] = { | ||
540 | GNUNET_SQ_result_spec_auto_from_type (&ticket.identity), | ||
541 | GNUNET_SQ_result_spec_auto_from_type (&ticket.audience), | ||
542 | GNUNET_SQ_result_spec_uint64 (&ticket.rnd), | ||
543 | GNUNET_SQ_result_spec_variable_size ((void**)&attrs_ser, | ||
544 | &attrs_len), | ||
545 | GNUNET_SQ_result_spec_end | ||
546 | |||
547 | }; | ||
548 | ret = GNUNET_SQ_extract_result (stmt, | ||
549 | rs); | ||
550 | if (GNUNET_OK != ret) | ||
551 | { | ||
552 | GNUNET_break (0); | ||
553 | ret = GNUNET_SYSERR; | ||
554 | } | ||
555 | else | ||
556 | { | ||
557 | attrs = GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (attrs_ser, | ||
558 | attrs_len); | ||
559 | if (NULL != iter) | ||
560 | iter (iter_cls, | ||
561 | &ticket, | ||
562 | attrs); | ||
563 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy (attrs); | ||
564 | ret = GNUNET_YES; | ||
565 | } | ||
566 | GNUNET_SQ_cleanup_result (rs); | ||
567 | } | ||
568 | else | ||
569 | { | ||
570 | if (SQLITE_DONE != sret) | ||
571 | LOG_SQLITE (plugin, | ||
572 | GNUNET_ERROR_TYPE_ERROR, | ||
573 | "sqlite_step"); | ||
574 | } | ||
575 | GNUNET_SQ_reset (plugin->dbh, | ||
576 | stmt); | ||
577 | return ret; | ||
578 | } | ||
579 | |||
580 | |||
581 | /** | ||
582 | * Lookup tickets in the datastore. | ||
583 | * | ||
584 | * @param cls closure (internal context for the plugin) | ||
585 | * @param ticket the ticket to retrieve attributes for | ||
586 | * @param iter function to call with the result | ||
587 | * @param iter_cls closure for @a iter | ||
588 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | ||
589 | */ | ||
590 | static int | ||
591 | reclaim_sqlite_ticket_get_attrs (void *cls, | ||
592 | const struct GNUNET_RECLAIM_Ticket *ticket, | ||
593 | GNUNET_RECLAIM_TicketIterator iter, | ||
594 | void *iter_cls) | ||
595 | { | ||
596 | struct Plugin *plugin = cls; | ||
597 | struct GNUNET_SQ_QueryParam params[] = { | ||
598 | GNUNET_SQ_query_param_auto_from_type (&ticket->identity), | ||
599 | GNUNET_SQ_query_param_uint64 (&ticket->rnd), | ||
600 | GNUNET_SQ_query_param_end | ||
601 | }; | ||
602 | |||
603 | if (GNUNET_OK != | ||
604 | GNUNET_SQ_bind (plugin->get_ticket_attrs, | ||
605 | params)) | ||
606 | { | ||
607 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
608 | "sqlite3_bind_XXXX"); | ||
609 | GNUNET_SQ_reset (plugin->dbh, | ||
610 | plugin->get_ticket_attrs); | ||
611 | return GNUNET_SYSERR; | ||
612 | } | ||
613 | return get_ticket_and_call_iterator (plugin, | ||
614 | plugin->get_ticket_attrs, | ||
615 | iter, | ||
616 | iter_cls); | ||
617 | } | ||
618 | |||
619 | |||
620 | /** | ||
621 | * Iterate over the results for a particular key and zone in the | ||
622 | * datastore. Will return at most one result to the iterator. | ||
623 | * | ||
624 | * @param cls closure (internal context for the plugin) | ||
625 | * @param identity the issuing identity or audience (depending on audience switch) | ||
626 | * @param audience GNUNET_YES if identity is audience | ||
627 | * @param offset offset in the list of all matching records | ||
628 | * @param iter function to call with the result | ||
629 | * @param iter_cls closure for @a iter | ||
630 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error | ||
631 | */ | ||
632 | static int | ||
633 | reclaim_sqlite_iterate_tickets (void *cls, | ||
634 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | ||
635 | int audience, | ||
636 | uint64_t offset, | ||
637 | GNUNET_RECLAIM_TicketIterator iter, | ||
638 | void *iter_cls) | ||
639 | { | ||
640 | struct Plugin *plugin = cls; | ||
641 | sqlite3_stmt *stmt; | ||
642 | int err; | ||
643 | |||
644 | if (NULL == identity) | ||
645 | { | ||
646 | GNUNET_break (0); | ||
647 | return GNUNET_SYSERR; | ||
648 | } | ||
649 | struct GNUNET_SQ_QueryParam params[] = { | ||
650 | GNUNET_SQ_query_param_auto_from_type (identity), | ||
651 | GNUNET_SQ_query_param_uint64 (&offset), | ||
652 | GNUNET_SQ_query_param_end | ||
653 | }; | ||
654 | if (GNUNET_YES == audience) | ||
655 | { | ||
656 | stmt = plugin->iterate_tickets_by_audience; | ||
657 | err = GNUNET_SQ_bind (stmt, | ||
658 | params); | ||
659 | } | ||
660 | else | ||
661 | { | ||
662 | stmt = plugin->iterate_tickets; | ||
663 | err = GNUNET_SQ_bind (stmt, | ||
664 | params); | ||
665 | } | ||
666 | if (GNUNET_OK != err) | ||
667 | { | ||
668 | LOG_SQLITE (plugin, | ||
669 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
670 | "sqlite3_bind_XXXX"); | ||
671 | GNUNET_SQ_reset (plugin->dbh, | ||
672 | stmt); | ||
673 | return GNUNET_SYSERR; | ||
674 | } | ||
675 | return get_ticket_and_call_iterator (plugin, | ||
676 | stmt, | ||
677 | iter, | ||
678 | iter_cls); | ||
679 | } | ||
680 | |||
681 | |||
682 | /** | ||
683 | * Entry point for the plugin. | ||
684 | * | ||
685 | * @param cls the "struct GNUNET_RECLAIM_PluginEnvironment*" | ||
686 | * @return NULL on error, otherwise the plugin context | ||
687 | */ | ||
688 | void * | ||
689 | libgnunet_plugin_reclaim_sqlite_init (void *cls) | ||
690 | { | ||
691 | static struct Plugin plugin; | ||
692 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | ||
693 | struct GNUNET_RECLAIM_PluginFunctions *api; | ||
694 | |||
695 | if (NULL != plugin.cfg) | ||
696 | return NULL; /* can only initialize once! */ | ||
697 | memset (&plugin, 0, sizeof (struct Plugin)); | ||
698 | plugin.cfg = cfg; | ||
699 | if (GNUNET_OK != database_setup (&plugin)) | ||
700 | { | ||
701 | database_shutdown (&plugin); | ||
702 | return NULL; | ||
703 | } | ||
704 | api = GNUNET_new (struct GNUNET_RECLAIM_PluginFunctions); | ||
705 | api->cls = &plugin; | ||
706 | api->store_ticket = &reclaim_sqlite_store_ticket; | ||
707 | api->delete_ticket = &reclaim_sqlite_delete_ticket; | ||
708 | api->iterate_tickets = &reclaim_sqlite_iterate_tickets; | ||
709 | api->get_ticket_attributes = &reclaim_sqlite_ticket_get_attrs; | ||
710 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
711 | _("Sqlite database running\n")); | ||
712 | return api; | ||
713 | } | ||
714 | |||
715 | |||
716 | /** | ||
717 | * Exit point from the plugin. | ||
718 | * | ||
719 | * @param cls the plugin context (as returned by "init") | ||
720 | * @return always NULL | ||
721 | */ | ||
722 | void * | ||
723 | libgnunet_plugin_reclaim_sqlite_done (void *cls) | ||
724 | { | ||
725 | struct GNUNET_RECLAIM_PluginFunctions *api = cls; | ||
726 | struct Plugin *plugin = api->cls; | ||
727 | |||
728 | database_shutdown (plugin); | ||
729 | plugin->cfg = NULL; | ||
730 | GNUNET_free (api); | ||
731 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
732 | "sqlite plugin is finished\n"); | ||
733 | return NULL; | ||
734 | } | ||
735 | |||
736 | /* end of plugin_reclaim_sqlite.c */ | ||
diff --git a/src/reclaim/reclaim.conf b/src/reclaim/reclaim.conf index 5073199ca..605a63d5e 100644 --- a/src/reclaim/reclaim.conf +++ b/src/reclaim/reclaim.conf | |||
@@ -10,7 +10,6 @@ UNIXPATH = $GNUNET_USER_RUNTIME_DIR/gnunet-service-reclaim.sock | |||
10 | UNIX_MATCH_UID = NO | 10 | UNIX_MATCH_UID = NO |
11 | UNIX_MATCH_GID = YES | 11 | UNIX_MATCH_GID = YES |
12 | TOKEN_EXPIRATION_INTERVAL = 30 m | 12 | TOKEN_EXPIRATION_INTERVAL = 30 m |
13 | DATABASE = sqlite | ||
14 | 13 | ||
15 | [reclaim-rest-plugin] | 14 | [reclaim-rest-plugin] |
16 | #ADDRESS = https://identity.gnu:8000#/login | 15 | #ADDRESS = https://identity.gnu:8000#/login |
@@ -18,6 +17,3 @@ ADDRESS = https://ui.reclaim/#/login | |||
18 | PSW = secret | 17 | PSW = secret |
19 | JWT_SECRET = secret | 18 | JWT_SECRET = secret |
20 | EXPIRATION_TIME = 1d | 19 | EXPIRATION_TIME = 1d |
21 | |||
22 | [reclaim-sqlite] | ||
23 | FILENAME = $GNUNET_DATA_HOME/reclaim/sqlite.db | ||
diff --git a/src/reclaim/reclaim_api.c b/src/reclaim/reclaim_api.c index dd6a249b5..0edae76c2 100644 --- a/src/reclaim/reclaim_api.c +++ b/src/reclaim/reclaim_api.c | |||
@@ -24,15 +24,17 @@ | |||
24 | * @author Martin Schanzenbach | 24 | * @author Martin Schanzenbach |
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | |||
27 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
29 | |||
28 | #include "gnunet_constants.h" | 30 | #include "gnunet_constants.h" |
29 | #include "gnunet_protocols.h" | ||
30 | #include "gnunet_mq_lib.h" | 31 | #include "gnunet_mq_lib.h" |
31 | #include "gnunet_reclaim_service.h" | 32 | #include "gnunet_protocols.h" |
32 | #include "gnunet_reclaim_attribute_lib.h" | 33 | #include "gnunet_reclaim_attribute_lib.h" |
34 | #include "gnunet_reclaim_service.h" | ||
33 | #include "reclaim.h" | 35 | #include "reclaim.h" |
34 | 36 | ||
35 | #define LOG(kind,...) GNUNET_log_from (kind, "reclaim-api",__VA_ARGS__) | 37 | #define LOG(kind, ...) GNUNET_log_from (kind, "reclaim-api", __VA_ARGS__) |
36 | 38 | ||
37 | 39 | ||
38 | /** | 40 | /** |
@@ -96,9 +98,9 @@ struct GNUNET_RECLAIM_Operation | |||
96 | * Closure for @e cont or @e cb. | 98 | * Closure for @e cont or @e cb. |
97 | */ | 99 | */ |
98 | void *cls; | 100 | void *cls; |
99 | |||
100 | }; | 101 | }; |
101 | 102 | ||
103 | |||
102 | /** | 104 | /** |
103 | * Handle for a ticket iterator operation | 105 | * Handle for a ticket iterator operation |
104 | */ | 106 | */ |
@@ -126,7 +128,7 @@ struct GNUNET_RECLAIM_TicketIterator | |||
126 | GNUNET_SCHEDULER_TaskCallback finish_cb; | 128 | GNUNET_SCHEDULER_TaskCallback finish_cb; |
127 | 129 | ||
128 | /** | 130 | /** |
129 | * Closure for @e error_cb. | 131 | * Closure for @e finish_cb. |
130 | */ | 132 | */ |
131 | void *finish_cb_cls; | 133 | void *finish_cb_cls; |
132 | 134 | ||
@@ -160,7 +162,6 @@ struct GNUNET_RECLAIM_TicketIterator | |||
160 | * The operation id this zone iteration operation has | 162 | * The operation id this zone iteration operation has |
161 | */ | 163 | */ |
162 | uint32_t r_id; | 164 | uint32_t r_id; |
163 | |||
164 | }; | 165 | }; |
165 | 166 | ||
166 | 167 | ||
@@ -181,7 +182,7 @@ struct GNUNET_RECLAIM_AttributeIterator | |||
181 | struct GNUNET_RECLAIM_AttributeIterator *prev; | 182 | struct GNUNET_RECLAIM_AttributeIterator *prev; |
182 | 183 | ||
183 | /** | 184 | /** |
184 | * Main handle to access the idp. | 185 | * Main handle to access the service. |
185 | */ | 186 | */ |
186 | struct GNUNET_RECLAIM_Handle *h; | 187 | struct GNUNET_RECLAIM_Handle *h; |
187 | 188 | ||
@@ -191,7 +192,7 @@ struct GNUNET_RECLAIM_AttributeIterator | |||
191 | GNUNET_SCHEDULER_TaskCallback finish_cb; | 192 | GNUNET_SCHEDULER_TaskCallback finish_cb; |
192 | 193 | ||
193 | /** | 194 | /** |
194 | * Closure for @e error_cb. | 195 | * Closure for @e finish_cb. |
195 | */ | 196 | */ |
196 | void *finish_cb_cls; | 197 | void *finish_cb_cls; |
197 | 198 | ||
@@ -230,12 +231,11 @@ struct GNUNET_RECLAIM_AttributeIterator | |||
230 | * The operation id this zone iteration operation has | 231 | * The operation id this zone iteration operation has |
231 | */ | 232 | */ |
232 | uint32_t r_id; | 233 | uint32_t r_id; |
233 | |||
234 | }; | 234 | }; |
235 | 235 | ||
236 | 236 | ||
237 | /** | 237 | /** |
238 | * Handle for the service. | 238 | * Handle to the service. |
239 | */ | 239 | */ |
240 | struct GNUNET_RECLAIM_Handle | 240 | struct GNUNET_RECLAIM_Handle |
241 | { | 241 | { |
@@ -284,7 +284,6 @@ struct GNUNET_RECLAIM_Handle | |||
284 | */ | 284 | */ |
285 | struct GNUNET_RECLAIM_TicketIterator *ticket_it_tail; | 285 | struct GNUNET_RECLAIM_TicketIterator *ticket_it_tail; |
286 | 286 | ||
287 | |||
288 | /** | 287 | /** |
289 | * Currently pending transmission request, or NULL for none. | 288 | * Currently pending transmission request, or NULL for none. |
290 | */ | 289 | */ |
@@ -293,7 +292,7 @@ struct GNUNET_RECLAIM_Handle | |||
293 | /** | 292 | /** |
294 | * Task doing exponential back-off trying to reconnect. | 293 | * Task doing exponential back-off trying to reconnect. |
295 | */ | 294 | */ |
296 | struct GNUNET_SCHEDULER_Task * reconnect_task; | 295 | struct GNUNET_SCHEDULER_Task *reconnect_task; |
297 | 296 | ||
298 | /** | 297 | /** |
299 | * Time for next connect retry. | 298 | * Time for next connect retry. |
@@ -314,9 +313,9 @@ struct GNUNET_RECLAIM_Handle | |||
314 | * Are we polling for incoming messages right now? | 313 | * Are we polling for incoming messages right now? |
315 | */ | 314 | */ |
316 | int in_receive; | 315 | int in_receive; |
317 | |||
318 | }; | 316 | }; |
319 | 317 | ||
318 | |||
320 | /** | 319 | /** |
321 | * Try again to connect to the service. | 320 | * Try again to connect to the service. |
322 | * | 321 | * |
@@ -325,6 +324,7 @@ struct GNUNET_RECLAIM_Handle | |||
325 | static void | 324 | static void |
326 | reconnect (struct GNUNET_RECLAIM_Handle *h); | 325 | reconnect (struct GNUNET_RECLAIM_Handle *h); |
327 | 326 | ||
327 | |||
328 | /** | 328 | /** |
329 | * Reconnect | 329 | * Reconnect |
330 | * | 330 | * |
@@ -350,14 +350,13 @@ force_reconnect (struct GNUNET_RECLAIM_Handle *handle) | |||
350 | { | 350 | { |
351 | GNUNET_MQ_destroy (handle->mq); | 351 | GNUNET_MQ_destroy (handle->mq); |
352 | handle->mq = NULL; | 352 | handle->mq = NULL; |
353 | handle->reconnect_backoff | 353 | handle->reconnect_backoff = |
354 | = GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff); | 354 | GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff); |
355 | handle->reconnect_task | 355 | handle->reconnect_task = GNUNET_SCHEDULER_add_delayed ( |
356 | = GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff, | 356 | handle->reconnect_backoff, &reconnect_task, handle); |
357 | &reconnect_task, | ||
358 | handle); | ||
359 | } | 357 | } |
360 | 358 | ||
359 | |||
361 | /** | 360 | /** |
362 | * Free @a it. | 361 | * Free @a it. |
363 | * | 362 | * |
@@ -368,22 +367,25 @@ free_it (struct GNUNET_RECLAIM_AttributeIterator *it) | |||
368 | { | 367 | { |
369 | struct GNUNET_RECLAIM_Handle *h = it->h; | 368 | struct GNUNET_RECLAIM_Handle *h = it->h; |
370 | 369 | ||
371 | GNUNET_CONTAINER_DLL_remove (h->it_head, | 370 | GNUNET_CONTAINER_DLL_remove (h->it_head, h->it_tail, it); |
372 | h->it_tail, | ||
373 | it); | ||
374 | if (NULL != it->env) | 371 | if (NULL != it->env) |
375 | GNUNET_MQ_discard (it->env); | 372 | GNUNET_MQ_discard (it->env); |
376 | GNUNET_free (it); | 373 | GNUNET_free (it); |
377 | } | 374 | } |
378 | 375 | ||
376 | /** | ||
377 | * Free @a op | ||
378 | * | ||
379 | * @param op the operation to free | ||
380 | */ | ||
379 | static void | 381 | static void |
380 | free_op (struct GNUNET_RECLAIM_Operation* op) | 382 | free_op (struct GNUNET_RECLAIM_Operation *op) |
381 | { | 383 | { |
382 | if (NULL == op) | 384 | if (NULL == op) |
383 | return; | 385 | return; |
384 | if (NULL != op->env) | 386 | if (NULL != op->env) |
385 | GNUNET_MQ_discard (op->env); | 387 | GNUNET_MQ_discard (op->env); |
386 | GNUNET_free(op); | 388 | GNUNET_free (op); |
387 | } | 389 | } |
388 | 390 | ||
389 | 391 | ||
@@ -396,13 +398,13 @@ free_op (struct GNUNET_RECLAIM_Operation* op) | |||
396 | * @param error error code | 398 | * @param error error code |
397 | */ | 399 | */ |
398 | static void | 400 | static void |
399 | mq_error_handler (void *cls, | 401 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
400 | enum GNUNET_MQ_Error error) | ||
401 | { | 402 | { |
402 | struct GNUNET_RECLAIM_Handle *handle = cls; | 403 | struct GNUNET_RECLAIM_Handle *handle = cls; |
403 | force_reconnect (handle); | 404 | force_reconnect (handle); |
404 | } | 405 | } |
405 | 406 | ||
407 | |||
406 | /** | 408 | /** |
407 | * Handle an incoming message of type | 409 | * Handle an incoming message of type |
408 | * #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE | 410 | * #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE |
@@ -412,7 +414,7 @@ mq_error_handler (void *cls, | |||
412 | */ | 414 | */ |
413 | static void | 415 | static void |
414 | handle_attribute_store_response (void *cls, | 416 | handle_attribute_store_response (void *cls, |
415 | const struct AttributeStoreResultMessage *msg) | 417 | const struct AttributeStoreResultMessage *msg) |
416 | { | 418 | { |
417 | struct GNUNET_RECLAIM_Handle *h = cls; | 419 | struct GNUNET_RECLAIM_Handle *h = cls; |
418 | struct GNUNET_RECLAIM_Operation *op; | 420 | struct GNUNET_RECLAIM_Operation *op; |
@@ -428,23 +430,17 @@ handle_attribute_store_response (void *cls, | |||
428 | 430 | ||
429 | res = ntohl (msg->op_result); | 431 | res = ntohl (msg->op_result); |
430 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 432 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
431 | "Received ATTRIBUTE_STORE_RESPONSE with result %d\n", | 433 | "Received ATTRIBUTE_STORE_RESPONSE with result %d\n", res); |
432 | res); | ||
433 | 434 | ||
434 | /* TODO: add actual error message to response... */ | 435 | /* TODO: add actual error message to response... */ |
435 | if (GNUNET_SYSERR == res) | 436 | if (GNUNET_SYSERR == res) |
436 | emsg = _("failed to store record\n"); | 437 | emsg = _ ("failed to store record\n"); |
437 | else | 438 | else |
438 | emsg = NULL; | 439 | emsg = NULL; |
439 | if (NULL != op->as_cb) | 440 | if (NULL != op->as_cb) |
440 | op->as_cb (op->cls, | 441 | op->as_cb (op->cls, res, emsg); |
441 | res, | 442 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); |
442 | emsg); | ||
443 | GNUNET_CONTAINER_DLL_remove (h->op_head, | ||
444 | h->op_tail, | ||
445 | op); | ||
446 | free_op (op); | 443 | free_op (op); |
447 | |||
448 | } | 444 | } |
449 | 445 | ||
450 | 446 | ||
@@ -465,8 +461,7 @@ check_consume_ticket_result (void *cls, | |||
465 | 461 | ||
466 | msg_len = ntohs (msg->header.size); | 462 | msg_len = ntohs (msg->header.size); |
467 | attrs_len = ntohs (msg->attrs_len); | 463 | attrs_len = ntohs (msg->attrs_len); |
468 | if (msg_len != sizeof (struct ConsumeTicketResultMessage) + attrs_len) | 464 | if (msg_len != sizeof (struct ConsumeTicketResultMessage) + attrs_len) { |
469 | { | ||
470 | GNUNET_break (0); | 465 | GNUNET_break (0); |
471 | return GNUNET_SYSERR; | 466 | return GNUNET_SYSERR; |
472 | } | 467 | } |
@@ -491,8 +486,7 @@ handle_consume_ticket_result (void *cls, | |||
491 | uint32_t r_id = ntohl (msg->id); | 486 | uint32_t r_id = ntohl (msg->id); |
492 | 487 | ||
493 | attrs_len = ntohs (msg->attrs_len); | 488 | attrs_len = ntohs (msg->attrs_len); |
494 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 489 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing attribute result.\n"); |
495 | "Processing attribute result.\n"); | ||
496 | 490 | ||
497 | 491 | ||
498 | for (op = h->op_head; NULL != op; op = op->next) | 492 | for (op = h->op_head; NULL != op; op = op->next) |
@@ -504,33 +498,20 @@ handle_consume_ticket_result (void *cls, | |||
504 | { | 498 | { |
505 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs; | 499 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs; |
506 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; | 500 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; |
507 | attrs = GNUNET_RECLAIM_ATTRIBUTE_list_deserialize ((char*)&msg[1], | 501 | attrs = |
508 | attrs_len); | 502 | GNUNET_RECLAIM_ATTRIBUTE_list_deserialize ((char *)&msg[1], attrs_len); |
509 | if (NULL != op->ar_cb) | 503 | if (NULL != op->ar_cb) { |
510 | { | 504 | if (NULL == attrs) { |
511 | if (NULL == attrs) | 505 | op->ar_cb (op->cls, &msg->identity, NULL); |
512 | { | 506 | } else { |
513 | op->ar_cb (op->cls, | ||
514 | &msg->identity, | ||
515 | NULL); | ||
516 | } | ||
517 | else | ||
518 | { | ||
519 | for (le = attrs->list_head; NULL != le; le = le->next) | 507 | for (le = attrs->list_head; NULL != le; le = le->next) |
520 | op->ar_cb (op->cls, | 508 | op->ar_cb (op->cls, &msg->identity, le->claim); |
521 | &msg->identity, | ||
522 | le->claim); | ||
523 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy (attrs); | 509 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy (attrs); |
524 | } | 510 | } |
525 | } | 511 | } |
526 | if (NULL != op) | 512 | if (NULL != op) { |
527 | { | 513 | op->ar_cb (op->cls, NULL, NULL); |
528 | op->ar_cb (op->cls, | 514 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); |
529 | NULL, | ||
530 | NULL); | ||
531 | GNUNET_CONTAINER_DLL_remove (h->op_head, | ||
532 | h->op_tail, | ||
533 | op); | ||
534 | free_op (op); | 515 | free_op (op); |
535 | } | 516 | } |
536 | return; | 517 | return; |
@@ -548,16 +529,14 @@ handle_consume_ticket_result (void *cls, | |||
548 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 529 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
549 | */ | 530 | */ |
550 | static int | 531 | static int |
551 | check_attribute_result (void *cls, | 532 | check_attribute_result (void *cls, const struct AttributeResultMessage *msg) |
552 | const struct AttributeResultMessage *msg) | ||
553 | { | 533 | { |
554 | size_t msg_len; | 534 | size_t msg_len; |
555 | size_t attr_len; | 535 | size_t attr_len; |
556 | 536 | ||
557 | msg_len = ntohs (msg->header.size); | 537 | msg_len = ntohs (msg->header.size); |
558 | attr_len = ntohs (msg->attr_len); | 538 | attr_len = ntohs (msg->attr_len); |
559 | if (msg_len != sizeof (struct AttributeResultMessage) + attr_len) | 539 | if (msg_len != sizeof (struct AttributeResultMessage) + attr_len) { |
560 | { | ||
561 | GNUNET_break (0); | 540 | GNUNET_break (0); |
562 | return GNUNET_SYSERR; | 541 | return GNUNET_SYSERR; |
563 | } | 542 | } |
@@ -573,8 +552,7 @@ check_attribute_result (void *cls, | |||
573 | * @param msg the message we received | 552 | * @param msg the message we received |
574 | */ | 553 | */ |
575 | static void | 554 | static void |
576 | handle_attribute_result (void *cls, | 555 | handle_attribute_result (void *cls, const struct AttributeResultMessage *msg) |
577 | const struct AttributeResultMessage *msg) | ||
578 | { | 556 | { |
579 | static struct GNUNET_CRYPTO_EcdsaPrivateKey identity_dummy; | 557 | static struct GNUNET_CRYPTO_EcdsaPrivateKey identity_dummy; |
580 | struct GNUNET_RECLAIM_Handle *h = cls; | 558 | struct GNUNET_RECLAIM_Handle *h = cls; |
@@ -584,8 +562,7 @@ handle_attribute_result (void *cls, | |||
584 | uint32_t r_id = ntohl (msg->id); | 562 | uint32_t r_id = ntohl (msg->id); |
585 | 563 | ||
586 | attr_len = ntohs (msg->attr_len); | 564 | attr_len = ntohs (msg->attr_len); |
587 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 565 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing attribute result.\n"); |
588 | "Processing attribute result.\n"); | ||
589 | 566 | ||
590 | 567 | ||
591 | for (it = h->it_head; NULL != it; it = it->next) | 568 | for (it = h->it_head; NULL != it; it = it->next) |
@@ -597,54 +574,36 @@ handle_attribute_result (void *cls, | |||
597 | if ((NULL == it) && (NULL == op)) | 574 | if ((NULL == it) && (NULL == op)) |
598 | return; | 575 | return; |
599 | 576 | ||
600 | if ( (0 == (memcmp (&msg->identity, | 577 | if ((0 == |
601 | &identity_dummy, | 578 | (memcmp (&msg->identity, &identity_dummy, sizeof (identity_dummy))))) { |
602 | sizeof (identity_dummy)))) ) | 579 | if ((NULL == it) && (NULL == op)) { |
603 | { | ||
604 | if ((NULL == it) && (NULL == op)) | ||
605 | { | ||
606 | GNUNET_break (0); | 580 | GNUNET_break (0); |
607 | force_reconnect (h); | 581 | force_reconnect (h); |
608 | return; | 582 | return; |
609 | } | 583 | } |
610 | if (NULL != it) | 584 | if (NULL != it) { |
611 | { | ||
612 | if (NULL != it->finish_cb) | 585 | if (NULL != it->finish_cb) |
613 | it->finish_cb (it->finish_cb_cls); | 586 | it->finish_cb (it->finish_cb_cls); |
614 | free_it (it); | 587 | free_it (it); |
615 | } | 588 | } |
616 | if (NULL != op) | 589 | if (NULL != op) { |
617 | { | ||
618 | if (NULL != op->ar_cb) | 590 | if (NULL != op->ar_cb) |
619 | op->ar_cb (op->cls, | 591 | op->ar_cb (op->cls, NULL, NULL); |
620 | NULL, | 592 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); |
621 | NULL); | ||
622 | GNUNET_CONTAINER_DLL_remove (h->op_head, | ||
623 | h->op_tail, | ||
624 | op); | ||
625 | free_op (op); | 593 | free_op (op); |
626 | |||
627 | } | 594 | } |
628 | return; | 595 | return; |
629 | } | 596 | } |
630 | 597 | ||
631 | { | 598 | { |
632 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; | 599 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; |
633 | attr = GNUNET_RECLAIM_ATTRIBUTE_deserialize ((char*)&msg[1], | 600 | attr = GNUNET_RECLAIM_ATTRIBUTE_deserialize ((char *)&msg[1], attr_len); |
634 | attr_len); | 601 | if (NULL != it) { |
635 | if (NULL != it) | ||
636 | { | ||
637 | if (NULL != it->proc) | 602 | if (NULL != it->proc) |
638 | it->proc (it->proc_cls, | 603 | it->proc (it->proc_cls, &msg->identity, attr); |
639 | &msg->identity, | 604 | } else if (NULL != op) { |
640 | attr); | ||
641 | } else if (NULL != op) | ||
642 | { | ||
643 | if (NULL != op->ar_cb) | 605 | if (NULL != op->ar_cb) |
644 | op->ar_cb (op->cls, | 606 | op->ar_cb (op->cls, &msg->identity, attr); |
645 | &msg->identity, | ||
646 | attr); | ||
647 | |||
648 | } | 607 | } |
649 | GNUNET_free (attr); | 608 | GNUNET_free (attr); |
650 | return; | 609 | return; |
@@ -661,14 +620,12 @@ handle_attribute_result (void *cls, | |||
661 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 620 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
662 | */ | 621 | */ |
663 | static int | 622 | static int |
664 | check_ticket_result (void *cls, | 623 | check_ticket_result (void *cls, const struct TicketResultMessage *msg) |
665 | const struct TicketResultMessage *msg) | ||
666 | { | 624 | { |
667 | size_t msg_len; | 625 | size_t msg_len; |
668 | 626 | ||
669 | msg_len = ntohs (msg->header.size); | 627 | msg_len = ntohs (msg->header.size); |
670 | if (msg_len < sizeof (struct TicketResultMessage)) | 628 | if (msg_len < sizeof (struct TicketResultMessage)) { |
671 | { | ||
672 | GNUNET_break (0); | 629 | GNUNET_break (0); |
673 | return GNUNET_SYSERR; | 630 | return GNUNET_SYSERR; |
674 | } | 631 | } |
@@ -676,7 +633,6 @@ check_ticket_result (void *cls, | |||
676 | } | 633 | } |
677 | 634 | ||
678 | 635 | ||
679 | |||
680 | /** | 636 | /** |
681 | * Handle an incoming message of type | 637 | * Handle an incoming message of type |
682 | * #GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT | 638 | * #GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT |
@@ -685,8 +641,7 @@ check_ticket_result (void *cls, | |||
685 | * @param msg the message we received | 641 | * @param msg the message we received |
686 | */ | 642 | */ |
687 | static void | 643 | static void |
688 | handle_ticket_result (void *cls, | 644 | handle_ticket_result (void *cls, const struct TicketResultMessage *msg) |
689 | const struct TicketResultMessage *msg) | ||
690 | { | 645 | { |
691 | struct GNUNET_RECLAIM_Handle *handle = cls; | 646 | struct GNUNET_RECLAIM_Handle *handle = cls; |
692 | struct GNUNET_RECLAIM_Operation *op; | 647 | struct GNUNET_RECLAIM_Operation *op; |
@@ -704,13 +659,9 @@ handle_ticket_result (void *cls, | |||
704 | if ((NULL == op) && (NULL == it)) | 659 | if ((NULL == op) && (NULL == it)) |
705 | return; | 660 | return; |
706 | msg_len = ntohs (msg->header.size); | 661 | msg_len = ntohs (msg->header.size); |
707 | if (NULL != op) | 662 | if (NULL != op) { |
708 | { | 663 | GNUNET_CONTAINER_DLL_remove (handle->op_head, handle->op_tail, op); |
709 | GNUNET_CONTAINER_DLL_remove (handle->op_head, | 664 | if (msg_len == sizeof (struct TicketResultMessage)) { |
710 | handle->op_tail, | ||
711 | op); | ||
712 | if (msg_len == sizeof (struct TicketResultMessage)) | ||
713 | { | ||
714 | if (NULL != op->tr_cb) | 665 | if (NULL != op->tr_cb) |
715 | op->tr_cb (op->cls, NULL); | 666 | op->tr_cb (op->cls, NULL); |
716 | } else { | 667 | } else { |
@@ -721,12 +672,10 @@ handle_ticket_result (void *cls, | |||
721 | free_op (op); | 672 | free_op (op); |
722 | return; | 673 | return; |
723 | } else if (NULL != it) { | 674 | } else if (NULL != it) { |
724 | if (msg_len == sizeof (struct TicketResultMessage)) | 675 | if (msg_len == sizeof (struct TicketResultMessage)) { |
725 | { | ||
726 | if (NULL != it->tr_cb) | 676 | if (NULL != it->tr_cb) |
727 | GNUNET_CONTAINER_DLL_remove (handle->ticket_it_head, | 677 | GNUNET_CONTAINER_DLL_remove (handle->ticket_it_head, |
728 | handle->ticket_it_tail, | 678 | handle->ticket_it_tail, it); |
729 | it); | ||
730 | it->finish_cb (it->finish_cb_cls); | 679 | it->finish_cb (it->finish_cb_cls); |
731 | GNUNET_free (it); | 680 | GNUNET_free (it); |
732 | } else { | 681 | } else { |
@@ -756,8 +705,7 @@ handle_revoke_ticket_result (void *cls, | |||
756 | uint32_t r_id = ntohl (msg->id); | 705 | uint32_t r_id = ntohl (msg->id); |
757 | int32_t success; | 706 | int32_t success; |
758 | 707 | ||
759 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 708 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing revocation result.\n"); |
760 | "Processing revocation result.\n"); | ||
761 | 709 | ||
762 | 710 | ||
763 | for (op = h->op_head; NULL != op; op = op->next) | 711 | for (op = h->op_head; NULL != op; op = op->next) |
@@ -767,15 +715,10 @@ handle_revoke_ticket_result (void *cls, | |||
767 | return; | 715 | return; |
768 | success = ntohl (msg->success); | 716 | success = ntohl (msg->success); |
769 | { | 717 | { |
770 | if (NULL != op->rvk_cb) | 718 | if (NULL != op->rvk_cb) { |
771 | { | 719 | op->rvk_cb (op->cls, success, NULL); |
772 | op->rvk_cb (op->cls, | ||
773 | success, | ||
774 | NULL); | ||
775 | } | 720 | } |
776 | GNUNET_CONTAINER_DLL_remove (h->op_head, | 721 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); |
777 | h->op_tail, | ||
778 | op); | ||
779 | free_op (op); | 722 | free_op (op); |
780 | return; | 723 | return; |
781 | } | 724 | } |
@@ -783,7 +726,6 @@ handle_revoke_ticket_result (void *cls, | |||
783 | } | 726 | } |
784 | 727 | ||
785 | 728 | ||
786 | |||
787 | /** | 729 | /** |
788 | * Try again to connect to the service. | 730 | * Try again to connect to the service. |
789 | * | 731 | * |
@@ -793,44 +735,34 @@ static void | |||
793 | reconnect (struct GNUNET_RECLAIM_Handle *h) | 735 | reconnect (struct GNUNET_RECLAIM_Handle *h) |
794 | { | 736 | { |
795 | struct GNUNET_MQ_MessageHandler handlers[] = { | 737 | struct GNUNET_MQ_MessageHandler handlers[] = { |
796 | GNUNET_MQ_hd_fixed_size (attribute_store_response, | 738 | GNUNET_MQ_hd_fixed_size ( |
797 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE_RESPONSE, | 739 | attribute_store_response, |
798 | struct AttributeStoreResultMessage, | 740 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE_RESPONSE, |
799 | h), | 741 | struct AttributeStoreResultMessage, h), |
800 | GNUNET_MQ_hd_var_size (attribute_result, | 742 | GNUNET_MQ_hd_var_size (attribute_result, |
801 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT, | 743 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT, |
802 | struct AttributeResultMessage, | 744 | struct AttributeResultMessage, h), |
803 | h), | 745 | GNUNET_MQ_hd_var_size (ticket_result, |
804 | GNUNET_MQ_hd_var_size (ticket_result, | 746 | GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT, |
805 | GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT, | 747 | struct TicketResultMessage, h), |
806 | struct TicketResultMessage, | 748 | GNUNET_MQ_hd_var_size (consume_ticket_result, |
807 | h), | 749 | GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT, |
808 | GNUNET_MQ_hd_var_size (consume_ticket_result, | 750 | struct ConsumeTicketResultMessage, h), |
809 | GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT, | 751 | GNUNET_MQ_hd_fixed_size (revoke_ticket_result, |
810 | struct ConsumeTicketResultMessage, | 752 | GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT, |
811 | h), | 753 | struct RevokeTicketResultMessage, h), |
812 | GNUNET_MQ_hd_fixed_size (revoke_ticket_result, | 754 | GNUNET_MQ_handler_end ()}; |
813 | GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT, | ||
814 | struct RevokeTicketResultMessage, | ||
815 | h), | ||
816 | GNUNET_MQ_handler_end () | ||
817 | }; | ||
818 | struct GNUNET_RECLAIM_Operation *op; | 755 | struct GNUNET_RECLAIM_Operation *op; |
819 | 756 | ||
820 | GNUNET_assert (NULL == h->mq); | 757 | GNUNET_assert (NULL == h->mq); |
821 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 758 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to reclaim service.\n"); |
822 | "Connecting to reclaim service.\n"); | ||
823 | 759 | ||
824 | h->mq = GNUNET_CLIENT_connect (h->cfg, | 760 | h->mq = |
825 | "reclaim", | 761 | GNUNET_CLIENT_connect (h->cfg, "reclaim", handlers, &mq_error_handler, h); |
826 | handlers, | ||
827 | &mq_error_handler, | ||
828 | h); | ||
829 | if (NULL == h->mq) | 762 | if (NULL == h->mq) |
830 | return; | 763 | return; |
831 | for (op = h->op_head; NULL != op; op = op->next) | 764 | for (op = h->op_head; NULL != op; op = op->next) |
832 | GNUNET_MQ_send_copy (h->mq, | 765 | GNUNET_MQ_send_copy (h->mq, op->env); |
833 | op->env); | ||
834 | } | 766 | } |
835 | 767 | ||
836 | 768 | ||
@@ -848,8 +780,7 @@ GNUNET_RECLAIM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
848 | h = GNUNET_new (struct GNUNET_RECLAIM_Handle); | 780 | h = GNUNET_new (struct GNUNET_RECLAIM_Handle); |
849 | h->cfg = cfg; | 781 | h->cfg = cfg; |
850 | reconnect (h); | 782 | reconnect (h); |
851 | if (NULL == h->mq) | 783 | if (NULL == h->mq) { |
852 | { | ||
853 | GNUNET_free (h); | 784 | GNUNET_free (h); |
854 | return NULL; | 785 | return NULL; |
855 | } | 786 | } |
@@ -870,9 +801,7 @@ GNUNET_RECLAIM_cancel (struct GNUNET_RECLAIM_Operation *op) | |||
870 | { | 801 | { |
871 | struct GNUNET_RECLAIM_Handle *h = op->h; | 802 | struct GNUNET_RECLAIM_Handle *h = op->h; |
872 | 803 | ||
873 | GNUNET_CONTAINER_DLL_remove (h->op_head, | 804 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); |
874 | h->op_tail, | ||
875 | op); | ||
876 | free_op (op); | 805 | free_op (op); |
877 | } | 806 | } |
878 | 807 | ||
@@ -886,13 +815,11 @@ void | |||
886 | GNUNET_RECLAIM_disconnect (struct GNUNET_RECLAIM_Handle *h) | 815 | GNUNET_RECLAIM_disconnect (struct GNUNET_RECLAIM_Handle *h) |
887 | { | 816 | { |
888 | GNUNET_assert (NULL != h); | 817 | GNUNET_assert (NULL != h); |
889 | if (NULL != h->mq) | 818 | if (NULL != h->mq) { |
890 | { | ||
891 | GNUNET_MQ_destroy (h->mq); | 819 | GNUNET_MQ_destroy (h->mq); |
892 | h->mq = NULL; | 820 | h->mq = NULL; |
893 | } | 821 | } |
894 | if (NULL != h->reconnect_task) | 822 | if (NULL != h->reconnect_task) { |
895 | { | ||
896 | GNUNET_SCHEDULER_cancel (h->reconnect_task); | 823 | GNUNET_SCHEDULER_cancel (h->reconnect_task); |
897 | h->reconnect_task = NULL; | 824 | h->reconnect_task = NULL; |
898 | } | 825 | } |
@@ -904,7 +831,7 @@ GNUNET_RECLAIM_disconnect (struct GNUNET_RECLAIM_Handle *h) | |||
904 | * Store an attribute. If the attribute is already present, | 831 | * Store an attribute. If the attribute is already present, |
905 | * it is replaced with the new attribute. | 832 | * it is replaced with the new attribute. |
906 | * | 833 | * |
907 | * @param h handle to the reclaim | 834 | * @param h handle to the re:claimID service |
908 | * @param pkey private key of the identity | 835 | * @param pkey private key of the identity |
909 | * @param attr the attribute value | 836 | * @param attr the attribute value |
910 | * @param exp_interval the relative expiration interval for the attribute | 837 | * @param exp_interval the relative expiration interval for the attribute |
@@ -913,12 +840,12 @@ GNUNET_RECLAIM_disconnect (struct GNUNET_RECLAIM_Handle *h) | |||
913 | * @return handle to abort the request | 840 | * @return handle to abort the request |
914 | */ | 841 | */ |
915 | struct GNUNET_RECLAIM_Operation * | 842 | struct GNUNET_RECLAIM_Operation * |
916 | GNUNET_RECLAIM_attribute_store (struct GNUNET_RECLAIM_Handle *h, | 843 | GNUNET_RECLAIM_attribute_store ( |
917 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | 844 | struct GNUNET_RECLAIM_Handle *h, |
918 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, | 845 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, |
919 | const struct GNUNET_TIME_Relative *exp_interval, | 846 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, |
920 | GNUNET_RECLAIM_ContinuationWithStatus cont, | 847 | const struct GNUNET_TIME_Relative *exp_interval, |
921 | void *cont_cls) | 848 | GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls) |
922 | { | 849 | { |
923 | struct GNUNET_RECLAIM_Operation *op; | 850 | struct GNUNET_RECLAIM_Operation *op; |
924 | struct AttributeStoreMessage *sam; | 851 | struct AttributeStoreMessage *sam; |
@@ -929,26 +856,20 @@ GNUNET_RECLAIM_attribute_store (struct GNUNET_RECLAIM_Handle *h, | |||
929 | op->as_cb = cont; | 856 | op->as_cb = cont; |
930 | op->cls = cont_cls; | 857 | op->cls = cont_cls; |
931 | op->r_id = h->r_id_gen++; | 858 | op->r_id = h->r_id_gen++; |
932 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, | 859 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); |
933 | h->op_tail, | ||
934 | op); | ||
935 | attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (attr); | 860 | attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (attr); |
936 | op->env = GNUNET_MQ_msg_extra (sam, | 861 | op->env = GNUNET_MQ_msg_extra (sam, attr_len, |
937 | attr_len, | ||
938 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE); | 862 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE); |
939 | sam->identity = *pkey; | 863 | sam->identity = *pkey; |
940 | sam->id = htonl (op->r_id); | 864 | sam->id = htonl (op->r_id); |
941 | sam->exp = GNUNET_htonll (exp_interval->rel_value_us); | 865 | sam->exp = GNUNET_htonll (exp_interval->rel_value_us); |
942 | 866 | ||
943 | GNUNET_RECLAIM_ATTRIBUTE_serialize (attr, | 867 | GNUNET_RECLAIM_ATTRIBUTE_serialize (attr, (char *)&sam[1]); |
944 | (char*)&sam[1]); | ||
945 | 868 | ||
946 | sam->attr_len = htons (attr_len); | 869 | sam->attr_len = htons (attr_len); |
947 | if (NULL != h->mq) | 870 | if (NULL != h->mq) |
948 | GNUNET_MQ_send_copy (h->mq, | 871 | GNUNET_MQ_send_copy (h->mq, op->env); |
949 | op->env); | ||
950 | return op; | 872 | return op; |
951 | |||
952 | } | 873 | } |
953 | 874 | ||
954 | 875 | ||
@@ -964,28 +885,25 @@ GNUNET_RECLAIM_attribute_store (struct GNUNET_RECLAIM_Handle *h, | |||
964 | * On normal completion, @a finish_cb proc will be | 885 | * On normal completion, @a finish_cb proc will be |
965 | * invoked. | 886 | * invoked. |
966 | * | 887 | * |
967 | * @param h handle to the idp | 888 | * @param h Handle to the re:claimID service |
968 | * @param identity identity to access | 889 | * @param identity Identity to iterate over |
969 | * @param error_cb function to call on error (i.e. disconnect), | 890 | * @param error_cb Function to call on error (i.e. disconnect), |
970 | * the handle is afterwards invalid | 891 | * the handle is afterwards invalid |
971 | * @param error_cb_cls closure for @a error_cb | 892 | * @param error_cb_cls Closure for @a error_cb |
972 | * @param proc function to call on each attribute; it | 893 | * @param proc Function to call on each attribute |
973 | * will be called repeatedly with a value (if available) | 894 | * @param proc_cls Closure for @a proc |
974 | * @param proc_cls closure for @a proc | 895 | * @param finish_cb Function to call on completion |
975 | * @param finish_cb function to call on completion | ||
976 | * the handle is afterwards invalid | 896 | * the handle is afterwards invalid |
977 | * @param finish_cb_cls closure for @a finish_cb | 897 | * @param finish_cb_cls Closure for @a finish_cb |
978 | * @return an iterator handle to use for iteration | 898 | * @return an iterator Handle to use for iteration |
979 | */ | 899 | */ |
980 | struct GNUNET_RECLAIM_AttributeIterator * | 900 | struct GNUNET_RECLAIM_AttributeIterator * |
981 | GNUNET_RECLAIM_get_attributes_start (struct GNUNET_RECLAIM_Handle *h, | 901 | GNUNET_RECLAIM_get_attributes_start ( |
982 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 902 | struct GNUNET_RECLAIM_Handle *h, |
983 | GNUNET_SCHEDULER_TaskCallback error_cb, | 903 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
984 | void *error_cb_cls, | 904 | GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, |
985 | GNUNET_RECLAIM_AttributeResult proc, | 905 | GNUNET_RECLAIM_AttributeResult proc, void *proc_cls, |
986 | void *proc_cls, | 906 | GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls) |
987 | GNUNET_SCHEDULER_TaskCallback finish_cb, | ||
988 | void *finish_cb_cls) | ||
989 | { | 907 | { |
990 | struct GNUNET_RECLAIM_AttributeIterator *it; | 908 | struct GNUNET_RECLAIM_AttributeIterator *it; |
991 | struct GNUNET_MQ_Envelope *env; | 909 | struct GNUNET_MQ_Envelope *env; |
@@ -1003,9 +921,7 @@ GNUNET_RECLAIM_get_attributes_start (struct GNUNET_RECLAIM_Handle *h, | |||
1003 | it->proc_cls = proc_cls; | 921 | it->proc_cls = proc_cls; |
1004 | it->r_id = rid; | 922 | it->r_id = rid; |
1005 | it->identity = *identity; | 923 | it->identity = *identity; |
1006 | GNUNET_CONTAINER_DLL_insert_tail (h->it_head, | 924 | GNUNET_CONTAINER_DLL_insert_tail (h->it_head, h->it_tail, it); |
1007 | h->it_tail, | ||
1008 | it); | ||
1009 | env = GNUNET_MQ_msg (msg, | 925 | env = GNUNET_MQ_msg (msg, |
1010 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START); | 926 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START); |
1011 | msg->id = htonl (rid); | 927 | msg->id = htonl (rid); |
@@ -1013,8 +929,7 @@ GNUNET_RECLAIM_get_attributes_start (struct GNUNET_RECLAIM_Handle *h, | |||
1013 | if (NULL == h->mq) | 929 | if (NULL == h->mq) |
1014 | it->env = env; | 930 | it->env = env; |
1015 | else | 931 | else |
1016 | GNUNET_MQ_send (h->mq, | 932 | GNUNET_MQ_send (h->mq, env); |
1017 | env); | ||
1018 | return it; | 933 | return it; |
1019 | } | 934 | } |
1020 | 935 | ||
@@ -1032,16 +947,15 @@ GNUNET_RECLAIM_get_attributes_next (struct GNUNET_RECLAIM_AttributeIterator *it) | |||
1032 | struct AttributeIterationNextMessage *msg; | 947 | struct AttributeIterationNextMessage *msg; |
1033 | struct GNUNET_MQ_Envelope *env; | 948 | struct GNUNET_MQ_Envelope *env; |
1034 | 949 | ||
1035 | env = GNUNET_MQ_msg (msg, | 950 | env = |
1036 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_NEXT); | 951 | GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_NEXT); |
1037 | msg->id = htonl (it->r_id); | 952 | msg->id = htonl (it->r_id); |
1038 | GNUNET_MQ_send (h->mq, | 953 | GNUNET_MQ_send (h->mq, env); |
1039 | env); | ||
1040 | } | 954 | } |
1041 | 955 | ||
1042 | 956 | ||
1043 | /** | 957 | /** |
1044 | * Stops iteration and releases the idp handle for further calls. Must | 958 | * Stops iteration and releases the handle for further calls. Must |
1045 | * be called on any iteration that has not yet completed prior to calling | 959 | * be called on any iteration that has not yet completed prior to calling |
1046 | * #GNUNET_RECLAIM_disconnect. | 960 | * #GNUNET_RECLAIM_disconnect. |
1047 | * | 961 | * |
@@ -1054,38 +968,36 @@ GNUNET_RECLAIM_get_attributes_stop (struct GNUNET_RECLAIM_AttributeIterator *it) | |||
1054 | struct GNUNET_MQ_Envelope *env; | 968 | struct GNUNET_MQ_Envelope *env; |
1055 | struct AttributeIterationStopMessage *msg; | 969 | struct AttributeIterationStopMessage *msg; |
1056 | 970 | ||
1057 | if (NULL != h->mq) | 971 | if (NULL != h->mq) { |
1058 | { | ||
1059 | env = GNUNET_MQ_msg (msg, | 972 | env = GNUNET_MQ_msg (msg, |
1060 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_STOP); | 973 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_STOP); |
1061 | msg->id = htonl (it->r_id); | 974 | msg->id = htonl (it->r_id); |
1062 | GNUNET_MQ_send (h->mq, | 975 | GNUNET_MQ_send (h->mq, env); |
1063 | env); | ||
1064 | } | 976 | } |
1065 | free_it (it); | 977 | free_it (it); |
1066 | } | 978 | } |
1067 | 979 | ||
1068 | 980 | ||
1069 | /** TODO | 981 | /** |
1070 | * Issues a ticket to another identity. The identity may use | 982 | * Issues a ticket to another relying party. The identity may use |
1071 | * @GNUNET_RECLAIM_authorization_ticket_consume to consume the ticket | 983 | * @GNUNET_RECLAIM_ticket_consume to consume the ticket |
1072 | * and retrieve the attributes specified in the AttributeList. | 984 | * and retrieve the attributes specified in the attribute list. |
1073 | * | 985 | * |
1074 | * @param h the reclaim to use | 986 | * @param h the reclaim to use |
1075 | * @param iss the issuing identity | 987 | * @param iss the issuing identity (= the user) |
1076 | * @param rp the subject of the ticket (the relying party) | 988 | * @param rp the subject of the ticket (= the relying party) |
1077 | * @param attrs the attributes that the relying party is given access to | 989 | * @param attrs the attributes that the relying party is given access to |
1078 | * @param cb the callback | 990 | * @param cb the callback |
1079 | * @param cb_cls the callback closure | 991 | * @param cb_cls the callback closure |
1080 | * @return handle to abort the operation | 992 | * @return handle to abort the operation |
1081 | */ | 993 | */ |
1082 | struct GNUNET_RECLAIM_Operation * | 994 | struct GNUNET_RECLAIM_Operation * |
1083 | GNUNET_RECLAIM_ticket_issue (struct GNUNET_RECLAIM_Handle *h, | 995 | GNUNET_RECLAIM_ticket_issue ( |
1084 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss, | 996 | struct GNUNET_RECLAIM_Handle *h, |
1085 | const struct GNUNET_CRYPTO_EcdsaPublicKey *rp, | 997 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss, |
1086 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, | 998 | const struct GNUNET_CRYPTO_EcdsaPublicKey *rp, |
1087 | GNUNET_RECLAIM_TicketCallback cb, | 999 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, |
1088 | void *cb_cls) | 1000 | GNUNET_RECLAIM_TicketCallback cb, void *cb_cls) |
1089 | { | 1001 | { |
1090 | struct GNUNET_RECLAIM_Operation *op; | 1002 | struct GNUNET_RECLAIM_Operation *op; |
1091 | struct IssueTicketMessage *tim; | 1003 | struct IssueTicketMessage *tim; |
@@ -1096,44 +1008,41 @@ GNUNET_RECLAIM_ticket_issue (struct GNUNET_RECLAIM_Handle *h, | |||
1096 | op->tr_cb = cb; | 1008 | op->tr_cb = cb; |
1097 | op->cls = cb_cls; | 1009 | op->cls = cb_cls; |
1098 | op->r_id = h->r_id_gen++; | 1010 | op->r_id = h->r_id_gen++; |
1099 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, | 1011 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); |
1100 | h->op_tail, | ||
1101 | op); | ||
1102 | attr_len = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (attrs); | 1012 | attr_len = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (attrs); |
1103 | op->env = GNUNET_MQ_msg_extra (tim, | 1013 | op->env = GNUNET_MQ_msg_extra (tim, attr_len, |
1104 | attr_len, | ||
1105 | GNUNET_MESSAGE_TYPE_RECLAIM_ISSUE_TICKET); | 1014 | GNUNET_MESSAGE_TYPE_RECLAIM_ISSUE_TICKET); |
1106 | tim->identity = *iss; | 1015 | tim->identity = *iss; |
1107 | tim->rp = *rp; | 1016 | tim->rp = *rp; |
1108 | tim->id = htonl (op->r_id); | 1017 | tim->id = htonl (op->r_id); |
1109 | 1018 | ||
1110 | GNUNET_RECLAIM_ATTRIBUTE_list_serialize (attrs, | 1019 | GNUNET_RECLAIM_ATTRIBUTE_list_serialize (attrs, (char *)&tim[1]); |
1111 | (char*)&tim[1]); | ||
1112 | 1020 | ||
1113 | tim->attr_len = htons (attr_len); | 1021 | tim->attr_len = htons (attr_len); |
1114 | if (NULL != h->mq) | 1022 | if (NULL != h->mq) |
1115 | GNUNET_MQ_send_copy (h->mq, | 1023 | GNUNET_MQ_send_copy (h->mq, op->env); |
1116 | op->env); | ||
1117 | return op; | 1024 | return op; |
1118 | } | 1025 | } |
1119 | 1026 | ||
1027 | |||
1120 | /** | 1028 | /** |
1121 | * Consumes an issued ticket. The ticket is persisted | 1029 | * Consumes an issued ticket. The ticket is persisted |
1122 | * and used to retrieve identity information from the issuer | 1030 | * and used to retrieve identity information from the issuer |
1123 | * | 1031 | * |
1124 | * @param h the reclaim to use | 1032 | * @param h the reclaim to use |
1125 | * @param identity the identity that is the subject of the issued ticket (the relying party) | 1033 | * @param identity the identity that is the subject of the issued ticket (the |
1034 | * relying party) | ||
1126 | * @param ticket the issued ticket to consume | 1035 | * @param ticket the issued ticket to consume |
1127 | * @param cb the callback to call | 1036 | * @param cb the callback to call |
1128 | * @param cb_cls the callback closure | 1037 | * @param cb_cls the callback closure |
1129 | * @return handle to abort the operation | 1038 | * @return handle to abort the operation |
1130 | */ | 1039 | */ |
1131 | struct GNUNET_RECLAIM_Operation * | 1040 | struct GNUNET_RECLAIM_Operation * |
1132 | GNUNET_RECLAIM_ticket_consume (struct GNUNET_RECLAIM_Handle *h, | 1041 | GNUNET_RECLAIM_ticket_consume ( |
1133 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 1042 | struct GNUNET_RECLAIM_Handle *h, |
1134 | const struct GNUNET_RECLAIM_Ticket *ticket, | 1043 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
1135 | GNUNET_RECLAIM_AttributeResult cb, | 1044 | const struct GNUNET_RECLAIM_Ticket *ticket, |
1136 | void *cb_cls) | 1045 | GNUNET_RECLAIM_AttributeResult cb, void *cb_cls) |
1137 | { | 1046 | { |
1138 | struct GNUNET_RECLAIM_Operation *op; | 1047 | struct GNUNET_RECLAIM_Operation *op; |
1139 | struct ConsumeTicketMessage *ctm; | 1048 | struct ConsumeTicketMessage *ctm; |
@@ -1143,24 +1052,19 @@ GNUNET_RECLAIM_ticket_consume (struct GNUNET_RECLAIM_Handle *h, | |||
1143 | op->ar_cb = cb; | 1052 | op->ar_cb = cb; |
1144 | op->cls = cb_cls; | 1053 | op->cls = cb_cls; |
1145 | op->r_id = h->r_id_gen++; | 1054 | op->r_id = h->r_id_gen++; |
1146 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, | 1055 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); |
1147 | h->op_tail, | 1056 | op->env = |
1148 | op); | 1057 | GNUNET_MQ_msg_extra (ctm, sizeof (const struct GNUNET_RECLAIM_Ticket), |
1149 | op->env = GNUNET_MQ_msg_extra (ctm, | 1058 | GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET); |
1150 | sizeof (const struct GNUNET_RECLAIM_Ticket), | ||
1151 | GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET); | ||
1152 | ctm->identity = *identity; | 1059 | ctm->identity = *identity; |
1153 | ctm->id = htonl (op->r_id); | 1060 | ctm->id = htonl (op->r_id); |
1154 | 1061 | ||
1155 | GNUNET_memcpy ((char*)&ctm[1], | 1062 | GNUNET_memcpy ((char *)&ctm[1], ticket, |
1156 | ticket, | ||
1157 | sizeof (const struct GNUNET_RECLAIM_Ticket)); | 1063 | sizeof (const struct GNUNET_RECLAIM_Ticket)); |
1158 | 1064 | ||
1159 | if (NULL != h->mq) | 1065 | if (NULL != h->mq) |
1160 | GNUNET_MQ_send_copy (h->mq, | 1066 | GNUNET_MQ_send_copy (h->mq, op->env); |
1161 | op->env); | ||
1162 | return op; | 1067 | return op; |
1163 | |||
1164 | } | 1068 | } |
1165 | 1069 | ||
1166 | 1070 | ||
@@ -1182,14 +1086,12 @@ GNUNET_RECLAIM_ticket_consume (struct GNUNET_RECLAIM_Handle *h, | |||
1182 | * @return an iterator handle to use for iteration | 1086 | * @return an iterator handle to use for iteration |
1183 | */ | 1087 | */ |
1184 | struct GNUNET_RECLAIM_TicketIterator * | 1088 | struct GNUNET_RECLAIM_TicketIterator * |
1185 | GNUNET_RECLAIM_ticket_iteration_start (struct GNUNET_RECLAIM_Handle *h, | 1089 | GNUNET_RECLAIM_ticket_iteration_start ( |
1186 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 1090 | struct GNUNET_RECLAIM_Handle *h, |
1187 | GNUNET_SCHEDULER_TaskCallback error_cb, | 1091 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
1188 | void *error_cb_cls, | 1092 | GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, |
1189 | GNUNET_RECLAIM_TicketCallback proc, | 1093 | GNUNET_RECLAIM_TicketCallback proc, void *proc_cls, |
1190 | void *proc_cls, | 1094 | GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls) |
1191 | GNUNET_SCHEDULER_TaskCallback finish_cb, | ||
1192 | void *finish_cb_cls) | ||
1193 | { | 1095 | { |
1194 | struct GNUNET_RECLAIM_TicketIterator *it; | 1096 | struct GNUNET_RECLAIM_TicketIterator *it; |
1195 | struct GNUNET_MQ_Envelope *env; | 1097 | struct GNUNET_MQ_Envelope *env; |
@@ -1206,26 +1108,21 @@ GNUNET_RECLAIM_ticket_iteration_start (struct GNUNET_RECLAIM_Handle *h, | |||
1206 | it->tr_cb = proc; | 1108 | it->tr_cb = proc; |
1207 | it->cls = proc_cls; | 1109 | it->cls = proc_cls; |
1208 | it->r_id = rid; | 1110 | it->r_id = rid; |
1209 | GNUNET_CONTAINER_DLL_insert_tail (h->ticket_it_head, | 1111 | GNUNET_CONTAINER_DLL_insert_tail (h->ticket_it_head, h->ticket_it_tail, it); |
1210 | h->ticket_it_tail, | 1112 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_START); |
1211 | it); | ||
1212 | env = GNUNET_MQ_msg (msg, | ||
1213 | GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_START); | ||
1214 | msg->id = htonl (rid); | 1113 | msg->id = htonl (rid); |
1215 | msg->identity = *identity; | 1114 | msg->identity = *identity; |
1216 | if (NULL == h->mq) | 1115 | if (NULL == h->mq) |
1217 | it->env = env; | 1116 | it->env = env; |
1218 | else | 1117 | else |
1219 | GNUNET_MQ_send (h->mq, | 1118 | GNUNET_MQ_send (h->mq, env); |
1220 | env); | ||
1221 | return it; | 1119 | return it; |
1222 | |||
1223 | } | 1120 | } |
1224 | 1121 | ||
1225 | 1122 | ||
1226 | /** | 1123 | /** |
1227 | * Calls the record processor specified in #GNUNET_RECLAIM_ticket_iteration_start | 1124 | * Calls the ticket processor specified in |
1228 | * for the next record. | 1125 | * #GNUNET_RECLAIM_ticket_iteration_start for the next record. |
1229 | * | 1126 | * |
1230 | * @param it the iterator | 1127 | * @param it the iterator |
1231 | */ | 1128 | */ |
@@ -1236,16 +1133,14 @@ GNUNET_RECLAIM_ticket_iteration_next (struct GNUNET_RECLAIM_TicketIterator *it) | |||
1236 | struct TicketIterationNextMessage *msg; | 1133 | struct TicketIterationNextMessage *msg; |
1237 | struct GNUNET_MQ_Envelope *env; | 1134 | struct GNUNET_MQ_Envelope *env; |
1238 | 1135 | ||
1239 | env = GNUNET_MQ_msg (msg, | 1136 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_NEXT); |
1240 | GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_NEXT); | ||
1241 | msg->id = htonl (it->r_id); | 1137 | msg->id = htonl (it->r_id); |
1242 | GNUNET_MQ_send (h->mq, | 1138 | GNUNET_MQ_send (h->mq, env); |
1243 | env); | ||
1244 | } | 1139 | } |
1245 | 1140 | ||
1246 | 1141 | ||
1247 | /** | 1142 | /** |
1248 | * Stops iteration and releases the idp handle for further calls. Must | 1143 | * Stops iteration and releases the handle for further calls. Must |
1249 | * be called on any iteration that has not yet completed prior to calling | 1144 | * be called on any iteration that has not yet completed prior to calling |
1250 | * #GNUNET_RECLAIM_disconnect. | 1145 | * #GNUNET_RECLAIM_disconnect. |
1251 | * | 1146 | * |
@@ -1258,22 +1153,23 @@ GNUNET_RECLAIM_ticket_iteration_stop (struct GNUNET_RECLAIM_TicketIterator *it) | |||
1258 | struct GNUNET_MQ_Envelope *env; | 1153 | struct GNUNET_MQ_Envelope *env; |
1259 | struct TicketIterationStopMessage *msg; | 1154 | struct TicketIterationStopMessage *msg; |
1260 | 1155 | ||
1261 | if (NULL != h->mq) | 1156 | if (NULL != h->mq) { |
1262 | { | 1157 | env = |
1263 | env = GNUNET_MQ_msg (msg, | 1158 | GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_STOP); |
1264 | GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_STOP); | ||
1265 | msg->id = htonl (it->r_id); | 1159 | msg->id = htonl (it->r_id); |
1266 | GNUNET_MQ_send (h->mq, | 1160 | GNUNET_MQ_send (h->mq, env); |
1267 | env); | ||
1268 | } | 1161 | } |
1269 | GNUNET_free (it); | 1162 | GNUNET_free (it); |
1270 | } | 1163 | } |
1271 | 1164 | ||
1165 | |||
1272 | /** | 1166 | /** |
1273 | * Revoked an issued ticket. The relying party will be unable to retrieve | 1167 | * Revoked an issued ticket. The relying party will be unable to retrieve |
1274 | * updated attributes. | 1168 | * attributes. Other issued tickets remain unaffected. |
1169 | * This includes tickets issued to other relying parties as well as to | ||
1170 | * other tickets issued to the audience specified in this ticket. | ||
1275 | * | 1171 | * |
1276 | * @param h the reclaim to use | 1172 | * @param h the identity provider to use |
1277 | * @param identity the issuing identity | 1173 | * @param identity the issuing identity |
1278 | * @param ticket the ticket to revoke | 1174 | * @param ticket the ticket to revoke |
1279 | * @param cb the callback | 1175 | * @param cb the callback |
@@ -1281,11 +1177,11 @@ GNUNET_RECLAIM_ticket_iteration_stop (struct GNUNET_RECLAIM_TicketIterator *it) | |||
1281 | * @return handle to abort the operation | 1177 | * @return handle to abort the operation |
1282 | */ | 1178 | */ |
1283 | struct GNUNET_RECLAIM_Operation * | 1179 | struct GNUNET_RECLAIM_Operation * |
1284 | GNUNET_RECLAIM_ticket_revoke (struct GNUNET_RECLAIM_Handle *h, | 1180 | GNUNET_RECLAIM_ticket_revoke ( |
1285 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 1181 | struct GNUNET_RECLAIM_Handle *h, |
1286 | const struct GNUNET_RECLAIM_Ticket *ticket, | 1182 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
1287 | GNUNET_RECLAIM_ContinuationWithStatus cb, | 1183 | const struct GNUNET_RECLAIM_Ticket *ticket, |
1288 | void *cb_cls) | 1184 | GNUNET_RECLAIM_ContinuationWithStatus cb, void *cb_cls) |
1289 | { | 1185 | { |
1290 | struct GNUNET_RECLAIM_Operation *op; | 1186 | struct GNUNET_RECLAIM_Operation *op; |
1291 | struct RevokeTicketMessage *msg; | 1187 | struct RevokeTicketMessage *msg; |
@@ -1297,25 +1193,18 @@ GNUNET_RECLAIM_ticket_revoke (struct GNUNET_RECLAIM_Handle *h, | |||
1297 | op->rvk_cb = cb; | 1193 | op->rvk_cb = cb; |
1298 | op->cls = cb_cls; | 1194 | op->cls = cb_cls; |
1299 | op->r_id = rid; | 1195 | op->r_id = rid; |
1300 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, | 1196 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); |
1301 | h->op_tail, | 1197 | op->env = GNUNET_MQ_msg_extra (msg, sizeof (struct GNUNET_RECLAIM_Ticket), |
1302 | op); | 1198 | GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET); |
1303 | op->env = GNUNET_MQ_msg_extra (msg, | ||
1304 | sizeof (struct GNUNET_RECLAIM_Ticket), | ||
1305 | GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET); | ||
1306 | msg->id = htonl (rid); | 1199 | msg->id = htonl (rid); |
1307 | msg->identity = *identity; | 1200 | msg->identity = *identity; |
1308 | GNUNET_memcpy (&msg[1], | 1201 | GNUNET_memcpy (&msg[1], ticket, sizeof (struct GNUNET_RECLAIM_Ticket)); |
1309 | ticket, | ||
1310 | sizeof (struct GNUNET_RECLAIM_Ticket)); | ||
1311 | if (NULL != h->mq) { | 1202 | if (NULL != h->mq) { |
1312 | GNUNET_MQ_send (h->mq, | 1203 | GNUNET_MQ_send (h->mq, op->env); |
1313 | op->env); | ||
1314 | op->env = NULL; | 1204 | op->env = NULL; |
1315 | } | 1205 | } |
1316 | return op; | 1206 | return op; |
1317 | } | 1207 | } |
1318 | 1208 | ||
1319 | 1209 | ||
1320 | |||
1321 | /* end of reclaim_api.c */ | 1210 | /* end of reclaim_api.c */ |