GNUnet  0.20.0
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 
34 #include "gnunet_fs_service.h"
35 #include "fs_api.h"
36 #include "fs_tree.h"
37 #include "fs_publish_ublock.h"
38 
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 
113 static void
114 publish_ksk_cont (void *cls);
115 
116 
124 static void
125 kb_put_cont (void *cls,
126  const char *msg)
127 {
128  struct GNUNET_FS_PublishKskContext *pkc = cls;
129 
130  pkc->uc = NULL;
131  if (NULL != msg)
132  {
134  "KBlock PUT operation failed: %s\n", msg);
135  pkc->cont (pkc->cont_cls, NULL, msg);
137  return;
138  }
140 }
141 
142 
143 static void
144 publish_ksk_cont (void *cls)
145 {
146  struct GNUNET_FS_PublishKskContext *pkc = cls;
147  const char *keyword;
148 
149  pkc->ksk_task = NULL;
150  if ((pkc->i == pkc->ksk_uri->data.ksk.keywordCount) ||
151  (NULL == pkc->dsh))
152  {
154  "KSK PUT operation complete\n");
155  pkc->cont (pkc->cont_cls, pkc->ksk_uri,
156  NULL);
158  return;
159  }
160  keyword = pkc->ksk_uri->data.ksk.keywords[pkc->i++];
161  pkc->uc = GNUNET_FS_publish_ublock_ (pkc->h,
162  pkc->dsh,
163  keyword + 1 /* skip '+' */,
164  NULL,
166  pkc->meta,
167  pkc->uri,
168  &pkc->bo,
169  pkc->options,
170  &kb_put_cont, pkc);
171 }
172 
173 
189  const struct GNUNET_FS_Uri *ksk_uri,
190  const struct GNUNET_FS_MetaData *meta,
191  const struct GNUNET_FS_Uri *uri,
192  const struct GNUNET_FS_BlockOptions *bo,
195 {
196  struct GNUNET_FS_PublishKskContext *pkc;
197 
198  GNUNET_assert (NULL != uri);
200  pkc->h = h;
201  pkc->bo = *bo;
202  pkc->options = options;
203  pkc->cont = cont;
204  pkc->cont_cls = cont_cls;
207  {
208  pkc->dsh = GNUNET_DATASTORE_connect (h->cfg);
209  if (NULL == pkc->dsh)
210  {
211  cont (cont_cls,
212  NULL,
213  _ ("Could not connect to datastore."));
214  GNUNET_free (pkc);
215  return NULL;
216  }
217  }
218  pkc->uri = GNUNET_FS_uri_dup (uri);
221  return pkc;
222 }
223 
224 
230 void
232 {
233  if (NULL != pkc->ksk_task)
234  {
236  pkc->ksk_task = NULL;
237  }
238  if (NULL != pkc->uc)
239  {
241  pkc->uc = NULL;
242  }
243  if (NULL != pkc->dsh)
244  {
246  pkc->dsh = NULL;
247  }
250  GNUNET_FS_uri_destroy (pkc->uri);
251  GNUNET_free (pkc);
252 }
253 
254 
255 /* end of fs_publish_ksk.c */
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
shared definitions for the FS library
static void kb_put_cont(void *cls, const char *msg)
Function called by the datastore API with the result from the PUT request.
static void publish_ksk_cont(void *cls)
Continuation of GNUNET_FS_publish_ksk() that performs the actual publishing operation (iterating over...
void GNUNET_FS_publish_ublock_cancel_(struct GNUNET_FS_PublishUblockContext *uc)
Abort UBlock publishing operation.
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_FS_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.
publish a UBLOCK in GNUnet
Merkle-tree-ish-CHK file encoding for GNUnet.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static struct GNUNET_FS_Uri * uri
Value of URI provided on command-line (when not publishing a file but just creating UBlocks to refer ...
static struct GNUNET_FS_MetaData * meta
Meta-data provided via command-line option.
static struct GNUNET_FS_BlockOptions bo
Options we set for published blocks.
API for file sharing via GNUnet.
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:482
struct GNUNET_DATASTORE_Handle * GNUNET_DATASTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the datastore service.
void GNUNET_DATASTORE_disconnect(struct GNUNET_DATASTORE_Handle *h, int drop)
Disconnect from the datastore service (and free associated resources).
void GNUNET_FS_publish_ksk_cancel(struct GNUNET_FS_PublishKskContext *pkc)
Abort the KSK publishing operation.
GNUNET_FS_PublishOptions
Options for publishing.
void GNUNET_FS_uri_destroy(struct GNUNET_FS_Uri *uri)
Free URI.
Definition: fs_uri.c:677
struct GNUNET_FS_Uri * GNUNET_FS_uri_dup(const struct GNUNET_FS_Uri *uri)
Duplicate URI.
Definition: fs_uri.c:987
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.
struct GNUNET_FS_PublishKskContext * GNUNET_FS_publish_ksk(struct GNUNET_FS_Handle *h, const struct GNUNET_FS_Uri *ksk_uri, const struct GNUNET_FS_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.
@ GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY
Simulate publishing.
#define GNUNET_log(kind,...)
@ GNUNET_NO
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_FS_MetaData * GNUNET_FS_meta_data_duplicate(const struct GNUNET_FS_MetaData *md)
Duplicate a struct GNUNET_FS_MetaData.
Definition: meta_data.c:532
void GNUNET_FS_meta_data_destroy(struct GNUNET_FS_MetaData *md)
Free meta data.
Definition: meta_data.c:171
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:1299
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
Definition: arm_api.c:112
Handle to the datastore service.
Settings for publishing a block (which may of course also apply to an entire directory or file).
Master context for most FS operations.
Definition: fs_api.h:1070
Meta data to associate with a file, directory or namespace.
Definition: meta_data.c:97
Context for the KSK publication.
struct GNUNET_FS_Uri * uri
URI to publish.
struct GNUNET_FS_Uri * ksk_uri
Keywords to use.
struct GNUNET_DATASTORE_Handle * dsh
Handle to the datastore, NULL if we are just simulating.
struct GNUNET_FS_PublishUblockContext * uc
UBlock publishing operation that is active.
enum GNUNET_FS_PublishOptions options
Options to use.
struct GNUNET_SCHEDULER_Task * ksk_task
Current task.
struct GNUNET_FS_BlockOptions bo
When should the KBlocks expire?
struct GNUNET_FS_MetaData * meta
Metadata to use.
void * cont_cls
Closure for cont.
unsigned int i
Keyword that we are currently processing.
struct GNUNET_FS_Handle * h
Global FS context.
GNUNET_FS_PublishContinuation cont
Function to call once we're done.
Context for 'ublock_put_cont'.
A Universal Resource Identifier (URI), opaque.
Definition: fs_api.h:167
struct GNUNET_FS_Uri::@13::@14 ksk
union GNUNET_FS_Uri::@13 data
Entry in list of pending tasks.
Definition: scheduler.c:136