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 
46 
50  struct GNUNET_FS_Uri *uri;
51 
56 
61 
66 
71 
76 
81 
85  void *cont_cls;
86 
91 
96 
100  unsigned int i;
101 };
102 
103 
111 static void
112 publish_ksk_cont(void *cls);
113 
114 
122 static void
123 kb_put_cont(void *cls,
124  const char *msg)
125 {
126  struct GNUNET_FS_PublishKskContext *pkc = cls;
127 
128  pkc->uc = NULL;
129  if (NULL != msg)
130  {
132  "KBlock PUT operation failed: %s\n", msg);
133  pkc->cont(pkc->cont_cls, NULL, msg);
135  return;
136  }
138 }
139 
140 
147 static void
149 {
150  struct GNUNET_FS_PublishKskContext *pkc = cls;
151  const char *keyword;
152 
153  pkc->ksk_task = NULL;
154  if ((pkc->i == pkc->ksk_uri->data.ksk.keywordCount) ||
155  (NULL == pkc->dsh))
156  {
158  "KSK PUT operation complete\n");
159  pkc->cont(pkc->cont_cls, pkc->ksk_uri,
160  NULL);
162  return;
163  }
164  keyword = pkc->ksk_uri->data.ksk.keywords[pkc->i++];
165  pkc->uc = GNUNET_FS_publish_ublock_(pkc->h,
166  pkc->dsh,
167  keyword + 1 /* skip '+' */,
168  NULL,
170  pkc->meta,
171  pkc->uri,
172  &pkc->bo,
173  pkc->options,
174  &kb_put_cont, pkc);
175 }
176 
177 
193  const struct GNUNET_FS_Uri *ksk_uri,
194  const struct GNUNET_CONTAINER_MetaData *meta,
195  const struct GNUNET_FS_Uri *uri,
196  const struct GNUNET_FS_BlockOptions *bo,
199 {
200  struct GNUNET_FS_PublishKskContext *pkc;
201 
202  GNUNET_assert(NULL != uri);
204  pkc->h = h;
205  pkc->bo = *bo;
206  pkc->options = options;
207  pkc->cont = cont;
208  pkc->cont_cls = cont_cls;
210  if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY))
211  {
212  pkc->dsh = GNUNET_DATASTORE_connect(h->cfg);
213  if (NULL == pkc->dsh)
214  {
215  cont(cont_cls,
216  NULL,
217  _("Could not connect to datastore."));
218  GNUNET_free(pkc);
219  return NULL;
220  }
221  }
222  pkc->uri = GNUNET_FS_uri_dup(uri);
223  pkc->ksk_uri = GNUNET_FS_uri_dup(ksk_uri);
225  return pkc;
226 }
227 
228 
234 void
236 {
237  if (NULL != pkc->ksk_task)
238  {
240  pkc->ksk_task = NULL;
241  }
242  if (NULL != pkc->uc)
243  {
245  pkc->uc = NULL;
246  }
247  if (NULL != pkc->dsh)
248  {
250  pkc->dsh = NULL;
251  }
255  GNUNET_free(pkc);
256 }
257 
258 
259 /* 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:1056
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:995
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_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:1264
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:675
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:162
Handle to the datastore service.
#define GNUNET_log(kind,...)
Entry in list of pending tasks.
Definition: scheduler.c:131
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:956
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:1060
void * cont_cls
Closure for cont.