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.
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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @file fs/fs_publish_ksk.c
23 * @brief publish a URI under a keyword in GNUnet
24 * @see https://gnunet.org/encoding and #2564
25 * @author Krista Bennett
26 * @author Christian Grothoff
30 #include "gnunet_constants.h"
31 #include "gnunet_signatures.h"
32 #include "gnunet_util_lib.h"
33 #include "gnunet_fs_service.h"
36 #include "fs_publish_ublock.h"
39 * Context for the KSK publication.
41 struct GNUNET_FS_PublishKskContext
46 struct GNUNET_FS_Uri *ksk_uri;
51 struct GNUNET_FS_Uri *uri;
56 struct GNUNET_CONTAINER_MetaData *meta;
61 struct GNUNET_FS_Handle *h;
64 * UBlock publishing operation that is active.
66 struct GNUNET_FS_PublishUblockContext *uc;
69 * Handle to the datastore, NULL if we are just simulating.
71 struct GNUNET_DATASTORE_Handle *dsh;
76 struct GNUNET_SCHEDULER_Task *ksk_task;
79 * Function to call once we're done.
81 GNUNET_FS_PublishContinuation cont;
89 * When should the KBlocks expire?
91 struct GNUNET_FS_BlockOptions bo;
96 enum GNUNET_FS_PublishOptions options;
99 * Keyword that we are currently processing.
106 * Continuation of #GNUNET_FS_publish_ksk() that performs
107 * the actual publishing operation (iterating over all
110 * @param cls closure of type `struct PublishKskContext *`
113 publish_ksk_cont (void *cls);
117 * Function called by the datastore API with
118 * the result from the PUT request.
120 * @param cls closure of type `struct GNUNET_FS_PublishKskContext *`
121 * @param msg error message (or NULL)
124 kb_put_cont (void *cls,
127 struct GNUNET_FS_PublishKskContext *pkc = cls;
132 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
133 "KBlock PUT operation failed: %s\n", msg);
134 pkc->cont (pkc->cont_cls, NULL, msg);
135 GNUNET_FS_publish_ksk_cancel (pkc);
138 pkc->ksk_task = GNUNET_SCHEDULER_add_now (&publish_ksk_cont, pkc);
143 * Continuation of #GNUNET_FS_publish_ksk() that performs the actual
144 * publishing operation (iterating over all of the keywords).
146 * @param cls closure of type `struct GNUNET_FS_PublishKskContext *`
149 publish_ksk_cont (void *cls)
151 struct GNUNET_FS_PublishKskContext *pkc = cls;
154 pkc->ksk_task = NULL;
155 if ((pkc->i == pkc->ksk_uri->data.ksk.keywordCount) ||
158 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
159 "KSK PUT operation complete\n");
160 pkc->cont (pkc->cont_cls, pkc->ksk_uri,
162 GNUNET_FS_publish_ksk_cancel (pkc);
165 keyword = pkc->ksk_uri->data.ksk.keywords[pkc->i++];
166 pkc->uc = GNUNET_FS_publish_ublock_ (pkc->h,
168 keyword + 1 /* skip '+' */,
170 GNUNET_CRYPTO_ecdsa_key_get_anonymous (),
180 * Publish a CHK under various keywords on GNUnet.
182 * @param h handle to the file sharing subsystem
183 * @param ksk_uri keywords to use
184 * @param meta metadata to use
185 * @param uri URI to refer to in the KBlock
186 * @param bo per-block options
187 * @param options publication options
188 * @param cont continuation
189 * @param cont_cls closure for cont
190 * @return NULL on error ('cont' will still be called)
192 struct GNUNET_FS_PublishKskContext *
193 GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
194 const struct GNUNET_FS_Uri *ksk_uri,
195 const struct GNUNET_CONTAINER_MetaData *meta,
196 const struct GNUNET_FS_Uri *uri,
197 const struct GNUNET_FS_BlockOptions *bo,
198 enum GNUNET_FS_PublishOptions options,
199 GNUNET_FS_PublishContinuation cont, void *cont_cls)
201 struct GNUNET_FS_PublishKskContext *pkc;
203 GNUNET_assert (NULL != uri);
204 pkc = GNUNET_new (struct GNUNET_FS_PublishKskContext);
207 pkc->options = options;
209 pkc->cont_cls = cont_cls;
210 pkc->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
211 if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY))
213 pkc->dsh = GNUNET_DATASTORE_connect (h->cfg);
214 if (NULL == pkc->dsh)
218 _ ("Could not connect to datastore."));
223 pkc->uri = GNUNET_FS_uri_dup (uri);
224 pkc->ksk_uri = GNUNET_FS_uri_dup (ksk_uri);
225 pkc->ksk_task = GNUNET_SCHEDULER_add_now (&publish_ksk_cont, pkc);
231 * Abort the KSK publishing operation.
233 * @param pkc context of the operation to abort.
236 GNUNET_FS_publish_ksk_cancel (struct GNUNET_FS_PublishKskContext *pkc)
238 if (NULL != pkc->ksk_task)
240 GNUNET_SCHEDULER_cancel (pkc->ksk_task);
241 pkc->ksk_task = NULL;
245 GNUNET_FS_publish_ublock_cancel_ (pkc->uc);
248 if (NULL != pkc->dsh)
250 GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
253 GNUNET_CONTAINER_meta_data_destroy (pkc->meta);
254 GNUNET_FS_uri_destroy (pkc->ksk_uri);
255 GNUNET_FS_uri_destroy (pkc->uri);
260 /* end of fs_publish_ksk.c */