GNUnet  0.17.6
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 
142 static void
143 publish_ksk_cont (void *cls)
144 {
145  struct GNUNET_FS_PublishKskContext *pkc = cls;
146  const char *keyword;
147 
148  pkc->ksk_task = NULL;
149  if ((pkc->i == pkc->ksk_uri->data.ksk.keywordCount) ||
150  (NULL == pkc->dsh))
151  {
153  "KSK PUT operation complete\n");
154  pkc->cont (pkc->cont_cls, pkc->ksk_uri,
155  NULL);
157  return;
158  }
159  keyword = pkc->ksk_uri->data.ksk.keywords[pkc->i++];
160  pkc->uc = GNUNET_FS_publish_ublock_ (pkc->h,
161  pkc->dsh,
162  keyword + 1 /* skip '+' */,
163  NULL,
165  pkc->meta,
166  pkc->uri,
167  &pkc->bo,
168  pkc->options,
169  &kb_put_cont, pkc);
170 }
171 
172 
188  const struct GNUNET_FS_Uri *ksk_uri,
189  const struct GNUNET_CONTAINER_MetaData *meta,
190  const struct GNUNET_FS_Uri *uri,
191  const struct GNUNET_FS_BlockOptions *bo,
194 {
195  struct GNUNET_FS_PublishKskContext *pkc;
196 
197  GNUNET_assert (NULL != uri);
199  pkc->h = h;
200  pkc->bo = *bo;
201  pkc->options = options;
202  pkc->cont = cont;
203  pkc->cont_cls = cont_cls;
206  {
207  pkc->dsh = GNUNET_DATASTORE_connect (h->cfg);
208  if (NULL == pkc->dsh)
209  {
210  cont (cont_cls,
211  NULL,
212  _ ("Could not connect to datastore."));
213  GNUNET_free (pkc);
214  return NULL;
215  }
216  }
217  pkc->uri = GNUNET_FS_uri_dup (uri);
220  return pkc;
221 }
222 
223 
229 void
231 {
232  if (NULL != pkc->ksk_task)
233  {
235  pkc->ksk_task = NULL;
236  }
237  if (NULL != pkc->uc)
238  {
240  pkc->uc = NULL;
241  }
242  if (NULL != pkc->dsh)
243  {
245  pkc->dsh = NULL;
246  }
249  GNUNET_FS_uri_destroy (pkc->uri);
250  GNUNET_free (pkc);
251 }
252 
253 
254 /* 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_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.
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_BlockOptions bo
Options we set for published blocks.
static struct GNUNET_CONTAINER_MetaData * meta
Meta-data provided via command-line option.
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:481
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.
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.
GNUNET_FS_PublishOptions
Options for publishing.
void GNUNET_FS_uri_destroy(struct GNUNET_FS_Uri *uri)
Free URI.
Definition: fs_uri.c:684
struct GNUNET_FS_Uri * GNUNET_FS_uri_dup(const struct GNUNET_FS_Uri *uri)
Duplicate URI.
Definition: fs_uri.c:1003
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.
@ GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY
Simulate publishing.
#define GNUNET_log(kind,...)
@ GNUNET_NO
Definition: gnunet_common.h:98
#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.
void GNUNET_CONTAINER_meta_data_destroy(struct GNUNET_CONTAINER_MetaData *md)
Free meta data.
struct GNUNET_CONTAINER_MetaData * GNUNET_CONTAINER_meta_data_duplicate(const struct GNUNET_CONTAINER_MetaData *md)
Duplicate a MetaData token.
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:1281
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:957
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
Definition: arm_api.c:112
Meta data to associate with a file, directory or namespace.
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:1069
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.
struct GNUNET_CONTAINER_MetaData * meta
Metadata to use.
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?
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:166
struct GNUNET_FS_Uri::@13::@14 ksk
union GNUNET_FS_Uri::@13 data
Entry in list of pending tasks.
Definition: scheduler.c:135