GNUnet  0.10.x
fs_publish_ksk.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2009, 2010, 2012, 2013 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 
29 #include "platform.h"
30 #include "gnunet_constants.h"
31 #include "gnunet_signatures.h"
32 #include "gnunet_util_lib.h"
33 #include "gnunet_fs_service.h"
34 #include "fs_api.h"
35 #include "fs_tree.h"
36 #include "fs_publish_ublock.h"
37 
42 {
43 
48 
52  struct GNUNET_FS_Uri *uri;
53 
58 
63 
68 
73 
78 
83 
87  void *cont_cls;
88 
93 
98 
102  unsigned int i;
103 
104 };
105 
106 
114 static void
115 publish_ksk_cont (void *cls);
116 
117 
125 static void
126 kb_put_cont (void *cls,
127  const char *msg)
128 {
129  struct GNUNET_FS_PublishKskContext *pkc = cls;
130 
131  pkc->uc = NULL;
132  if (NULL != msg)
133  {
135  "KBlock PUT operation failed: %s\n", msg);
136  pkc->cont (pkc->cont_cls, NULL, msg);
138  return;
139  }
141 }
142 
143 
150 static void
151 publish_ksk_cont (void *cls)
152 {
153  struct GNUNET_FS_PublishKskContext *pkc = cls;
154  const char *keyword;
155 
156  pkc->ksk_task = NULL;
157  if ( (pkc->i == pkc->ksk_uri->data.ksk.keywordCount) ||
158  (NULL == pkc->dsh) )
159  {
161  "KSK PUT operation complete\n");
162  pkc->cont (pkc->cont_cls, pkc->ksk_uri,
163  NULL);
165  return;
166  }
167  keyword = pkc->ksk_uri->data.ksk.keywords[pkc->i++];
168  pkc->uc = GNUNET_FS_publish_ublock_ (pkc->h,
169  pkc->dsh,
170  keyword + 1 /* skip '+' */,
171  NULL,
173  pkc->meta,
174  pkc->uri,
175  &pkc->bo,
176  pkc->options,
177  &kb_put_cont, pkc);
178 }
179 
180 
196  const struct GNUNET_FS_Uri *ksk_uri,
197  const struct GNUNET_CONTAINER_MetaData *meta,
198  const struct GNUNET_FS_Uri *uri,
199  const struct GNUNET_FS_BlockOptions *bo,
202 {
203  struct GNUNET_FS_PublishKskContext *pkc;
204 
205  GNUNET_assert (NULL != uri);
207  pkc->h = h;
208  pkc->bo = *bo;
209  pkc->options = options;
210  pkc->cont = cont;
211  pkc->cont_cls = cont_cls;
213  if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY))
214  {
215  pkc->dsh = GNUNET_DATASTORE_connect (h->cfg);
216  if (NULL == pkc->dsh)
217  {
218  cont (cont_cls,
219  NULL,
220  _("Could not connect to datastore."));
221  GNUNET_free (pkc);
222  return NULL;
223  }
224  }
225  pkc->uri = GNUNET_FS_uri_dup (uri);
226  pkc->ksk_uri = GNUNET_FS_uri_dup (ksk_uri);
228  return pkc;
229 }
230 
231 
237 void
239 {
240  if (NULL != pkc->ksk_task)
241  {
243  pkc->ksk_task = NULL;
244  }
245  if (NULL != pkc->uc)
246  {
248  pkc->uc = NULL;
249  }
250  if (NULL != pkc->dsh)
251  {
253  pkc->dsh = NULL;
254  }
257  GNUNET_FS_uri_destroy (pkc->uri);
258  GNUNET_free (pkc);
259 }
260 
261 
262 /* end of fs_publish_ksk.c */
const struct GNUNET_CRYPTO_EcdsaPrivateKey * GNUNET_CRYPTO_ecdsa_key_get_anonymous(void)
Get the shared private key we use for anonymous users.
Definition: crypto_ecc.c:814
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_CONTAINER_MetaData * meta
Metadata to use.
unsigned int i
Keyword that we are currently processing.
Master context for most FS operations.
Definition: fs_api.h:1087
void GNUNET_FS_publish_ksk_cancel(struct GNUNET_FS_PublishKskContext *pkc)
Abort the KSK publishing operation.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:81
static void kb_put_cont(void *cls, const char *msg)
Function called by the datastore API with the result from the PUT request.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_FS_Uri * GNUNET_FS_uri_dup(const struct GNUNET_FS_Uri *uri)
Duplicate URI.
Definition: fs_uri.c:988
GNUNET_FS_PublishContinuation cont
Function to call once we&#39;re done.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
struct GNUNET_FS_PublishKskContext * GNUNET_FS_publish_ksk(struct GNUNET_FS_Handle *h, const struct GNUNET_FS_Uri *ksk_uri, const struct GNUNET_CONTAINER_MetaData *meta, const struct GNUNET_FS_Uri *uri, const struct GNUNET_FS_BlockOptions *bo, enum GNUNET_FS_PublishOptions options, GNUNET_FS_PublishContinuation cont, void *cont_cls)
Publish a CHK under various keywords on GNUnet.
struct GNUNET_DATASTORE_Handle * dsh
Handle to the datastore, NULL if we are just simulating.
struct GNUNET_SCHEDULER_Task * ksk_task
Current task.
Meta data to associate with a file, directory or namespace.
struct GNUNET_FS_Uri::@16::@17 ksk
struct GNUNET_FS_PublishUblockContext * uc
UBlock publishing operation that is active.
struct GNUNET_FS_Uri * uri
URI to publish.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1273
union GNUNET_FS_Uri::@16 data
void(* GNUNET_FS_PublishContinuation)(void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
Signature of a function called as the continuation of a KBlock or SBlock publication.
void GNUNET_CONTAINER_meta_data_destroy(struct GNUNET_CONTAINER_MetaData *md)
Free meta data.
GNUNET_FS_PublishOptions
Options for publishing.
Context for the KSK publication.
void GNUNET_FS_uri_destroy(struct GNUNET_FS_Uri *uri)
Free URI.
Definition: fs_uri.c:670
void GNUNET_FS_publish_ublock_cancel_(struct GNUNET_FS_PublishUblockContext *uc)
Abort UBlock publishing operation.
enum GNUNET_FS_PublishOptions options
Options to use.
struct GNUNET_FS_Handle * h
Global FS context.
struct GNUNET_FS_PublishUblockContext * GNUNET_FS_publish_ublock_(struct GNUNET_FS_Handle *h, struct GNUNET_DATASTORE_Handle *dsh, const char *label, const char *ulabel, const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, const struct GNUNET_CONTAINER_MetaData *meta, const struct GNUNET_FS_Uri *uri, const struct GNUNET_FS_BlockOptions *bo, enum GNUNET_FS_PublishOptions options, GNUNET_FS_UBlockContinuation cont, void *cont_cls)
Publish a UBlock.
Settings for publishing a block (which may of course also apply to an entire directory or file)...
static void publish_ksk_cont(void *cls)
Continuation of GNUNET_FS_publish_ksk() that performs the actual publishing operation (iterating over...
shared definitions for the FS library
void GNUNET_DATASTORE_disconnect(struct GNUNET_DATASTORE_Handle *h, int drop)
Disconnect from the datastore service (and free associated resources).
Context for &#39;ublock_put_cont&#39;.
A Universal Resource Identifier (URI), opaque.
Definition: fs_api.h:168
Handle to the datastore service.
#define GNUNET_log(kind,...)
Entry in list of pending tasks.
Definition: scheduler.c:134
struct GNUNET_DATASTORE_Handle * GNUNET_DATASTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the datastore service.
struct GNUNET_FS_Uri * ksk_uri
Keywords to use.
#define GNUNET_free(ptr)
Wrapper around free.
Merkle-tree-ish-CHK file encoding for GNUnet.
struct GNUNET_FS_BlockOptions bo
When should the KBlocks expire?
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
publish a UBLOCK in GNUnet
struct GNUNET_CONTAINER_MetaData * GNUNET_CONTAINER_meta_data_duplicate(const struct GNUNET_CONTAINER_MetaData *md)
Duplicate a MetaData token.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: fs_api.h:1092
void * cont_cls
Closure for cont.