GNUnet  0.11.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 {
47 
51  struct GNUNET_FS_Uri *uri;
52 
57 
62 
67 
72 
77 
82 
86  void *cont_cls;
87 
92 
97 
101  unsigned int i;
102 };
103 
104 
112 static void
113 publish_ksk_cont (void *cls);
114 
115 
123 static void
124 kb_put_cont (void *cls,
125  const char *msg)
126 {
127  struct GNUNET_FS_PublishKskContext *pkc = cls;
128 
129  pkc->uc = NULL;
130  if (NULL != msg)
131  {
133  "KBlock PUT operation failed: %s\n", msg);
134  pkc->cont (pkc->cont_cls, NULL, msg);
136  return;
137  }
139 }
140 
141 
148 static void
149 publish_ksk_cont (void *cls)
150 {
151  struct GNUNET_FS_PublishKskContext *pkc = cls;
152  const char *keyword;
153 
154  pkc->ksk_task = NULL;
155  if ((pkc->i == pkc->ksk_uri->data.ksk.keywordCount) ||
156  (NULL == pkc->dsh))
157  {
159  "KSK PUT operation complete\n");
160  pkc->cont (pkc->cont_cls, pkc->ksk_uri,
161  NULL);
163  return;
164  }
165  keyword = pkc->ksk_uri->data.ksk.keywords[pkc->i++];
166  pkc->uc = GNUNET_FS_publish_ublock_ (pkc->h,
167  pkc->dsh,
168  keyword + 1 /* skip '+' */,
169  NULL,
171  pkc->meta,
172  pkc->uri,
173  &pkc->bo,
174  pkc->options,
175  &kb_put_cont, pkc);
176 }
177 
178 
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,
200 {
201  struct GNUNET_FS_PublishKskContext *pkc;
202 
203  GNUNET_assert (NULL != uri);
205  pkc->h = h;
206  pkc->bo = *bo;
207  pkc->options = options;
208  pkc->cont = cont;
209  pkc->cont_cls = cont_cls;
211  if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY))
212  {
213  pkc->dsh = GNUNET_DATASTORE_connect (h->cfg);
214  if (NULL == pkc->dsh)
215  {
216  cont (cont_cls,
217  NULL,
218  _ ("Could not connect to datastore."));
219  GNUNET_free (pkc);
220  return NULL;
221  }
222  }
223  pkc->uri = GNUNET_FS_uri_dup (uri);
224  pkc->ksk_uri = GNUNET_FS_uri_dup (ksk_uri);
226  return pkc;
227 }
228 
229 
235 void
237 {
238  if (NULL != pkc->ksk_task)
239  {
241  pkc->ksk_task = NULL;
242  }
243  if (NULL != pkc->uc)
244  {
246  pkc->uc = NULL;
247  }
248  if (NULL != pkc->dsh)
249  {
251  pkc->dsh = NULL;
252  }
255  GNUNET_FS_uri_destroy (pkc->uri);
256  GNUNET_free (pkc);
257 }
258 
259 
260 /* 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:812
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:1068
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:78
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:998
GNUNET_FS_PublishContinuation cont
Function to call once we&#39;re done.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
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_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:1280
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:678
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...
union GNUNET_FS_Uri::@13 data
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:165
Handle to the datastore service.
struct GNUNET_FS_Uri::@13::@14 ksk
#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:966
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:1073
void * cont_cls
Closure for cont.