2 This file is part of GNUnet.
3 Copyright (C) 2009, 2010, 2012, 2013 GNUnet e.V.
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.
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.
17 * @file fs/fs_publish_ksk.c
18 * @brief publish a URI under a keyword in GNUnet
19 * @see https://gnunet.org/encoding and #2564
20 * @author Krista Bennett
21 * @author Christian Grothoff
25 #include "gnunet_constants.h"
26 #include "gnunet_signatures.h"
27 #include "gnunet_util_lib.h"
28 #include "gnunet_fs_service.h"
31 #include "fs_publish_ublock.h"
34 * Context for the KSK publication.
36 struct GNUNET_FS_PublishKskContext
42 struct GNUNET_FS_Uri *ksk_uri;
47 struct GNUNET_FS_Uri *uri;
52 struct GNUNET_CONTAINER_MetaData *meta;
57 struct GNUNET_FS_Handle *h;
60 * UBlock publishing operation that is active.
62 struct GNUNET_FS_PublishUblockContext *uc;
65 * Handle to the datastore, NULL if we are just simulating.
67 struct GNUNET_DATASTORE_Handle *dsh;
72 struct GNUNET_SCHEDULER_Task * ksk_task;
75 * Function to call once we're done.
77 GNUNET_FS_PublishContinuation cont;
85 * When should the KBlocks expire?
87 struct GNUNET_FS_BlockOptions bo;
92 enum GNUNET_FS_PublishOptions options;
95 * Keyword that we are currently processing.
103 * Continuation of #GNUNET_FS_publish_ksk() that performs
104 * the actual publishing operation (iterating over all
107 * @param cls closure of type `struct PublishKskContext *`
110 publish_ksk_cont (void *cls);
114 * Function called by the datastore API with
115 * the result from the PUT request.
117 * @param cls closure of type `struct GNUNET_FS_PublishKskContext *`
118 * @param msg error message (or NULL)
121 kb_put_cont (void *cls,
124 struct GNUNET_FS_PublishKskContext *pkc = cls;
129 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
130 "KBlock PUT operation failed: %s\n", msg);
131 pkc->cont (pkc->cont_cls, NULL, msg);
132 GNUNET_FS_publish_ksk_cancel (pkc);
135 pkc->ksk_task = GNUNET_SCHEDULER_add_now (&publish_ksk_cont, pkc);
140 * Continuation of #GNUNET_FS_publish_ksk() that performs the actual
141 * publishing operation (iterating over all of the keywords).
143 * @param cls closure of type `struct GNUNET_FS_PublishKskContext *`
146 publish_ksk_cont (void *cls)
148 struct GNUNET_FS_PublishKskContext *pkc = cls;
151 pkc->ksk_task = NULL;
152 if ( (pkc->i == pkc->ksk_uri->data.ksk.keywordCount) ||
155 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
156 "KSK PUT operation complete\n");
157 pkc->cont (pkc->cont_cls, pkc->ksk_uri,
159 GNUNET_FS_publish_ksk_cancel (pkc);
162 keyword = pkc->ksk_uri->data.ksk.keywords[pkc->i++];
163 pkc->uc = GNUNET_FS_publish_ublock_ (pkc->h,
165 keyword + 1 /* skip '+' */,
167 GNUNET_CRYPTO_ecdsa_key_get_anonymous (),
177 * Publish a CHK under various keywords on GNUnet.
179 * @param h handle to the file sharing subsystem
180 * @param ksk_uri keywords to use
181 * @param meta metadata to use
182 * @param uri URI to refer to in the KBlock
183 * @param bo per-block options
184 * @param options publication options
185 * @param cont continuation
186 * @param cont_cls closure for cont
187 * @return NULL on error ('cont' will still be called)
189 struct GNUNET_FS_PublishKskContext *
190 GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
191 const struct GNUNET_FS_Uri *ksk_uri,
192 const struct GNUNET_CONTAINER_MetaData *meta,
193 const struct GNUNET_FS_Uri *uri,
194 const struct GNUNET_FS_BlockOptions *bo,
195 enum GNUNET_FS_PublishOptions options,
196 GNUNET_FS_PublishContinuation cont, void *cont_cls)
198 struct GNUNET_FS_PublishKskContext *pkc;
200 GNUNET_assert (NULL != uri);
201 pkc = GNUNET_new (struct GNUNET_FS_PublishKskContext);
204 pkc->options = options;
206 pkc->cont_cls = cont_cls;
207 pkc->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
208 if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY))
210 pkc->dsh = GNUNET_DATASTORE_connect (h->cfg);
211 if (NULL == pkc->dsh)
215 _("Could not connect to datastore."));
220 pkc->uri = GNUNET_FS_uri_dup (uri);
221 pkc->ksk_uri = GNUNET_FS_uri_dup (ksk_uri);
222 pkc->ksk_task = GNUNET_SCHEDULER_add_now (&publish_ksk_cont, pkc);
228 * Abort the KSK publishing operation.
230 * @param pkc context of the operation to abort.
233 GNUNET_FS_publish_ksk_cancel (struct GNUNET_FS_PublishKskContext *pkc)
235 if (NULL != pkc->ksk_task)
237 GNUNET_SCHEDULER_cancel (pkc->ksk_task);
238 pkc->ksk_task = NULL;
242 GNUNET_FS_publish_ublock_cancel_ (pkc->uc);
245 if (NULL != pkc->dsh)
247 GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
250 GNUNET_CONTAINER_meta_data_destroy (pkc->meta);
251 GNUNET_FS_uri_destroy (pkc->ksk_uri);
252 GNUNET_FS_uri_destroy (pkc->uri);
257 /* end of fs_publish_ksk.c */