summaryrefslogtreecommitdiff
path: root/src/fs/fs_publish_ksk.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/fs_publish_ksk.c')
-rw-r--r--src/fs/fs_publish_ksk.c151
1 files changed, 74 insertions, 77 deletions
diff --git a/src/fs/fs_publish_ksk.c b/src/fs/fs_publish_ksk.c
index e7f6408fd..151b8256c 100644
--- a/src/fs/fs_publish_ksk.c
+++ b/src/fs/fs_publish_ksk.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file fs/fs_publish_ksk.c 22 * @file fs/fs_publish_ksk.c
@@ -38,9 +38,7 @@
38/** 38/**
39 * Context for the KSK publication. 39 * Context for the KSK publication.
40 */ 40 */
41struct GNUNET_FS_PublishKskContext 41struct GNUNET_FS_PublishKskContext {
42{
43
44 /** 42 /**
45 * Keywords to use. 43 * Keywords to use.
46 */ 44 */
@@ -100,7 +98,6 @@ struct GNUNET_FS_PublishKskContext
100 * Keyword that we are currently processing. 98 * Keyword that we are currently processing.
101 */ 99 */
102 unsigned int i; 100 unsigned int i;
103
104}; 101};
105 102
106 103
@@ -112,7 +109,7 @@ struct GNUNET_FS_PublishKskContext
112 * @param cls closure of type `struct PublishKskContext *` 109 * @param cls closure of type `struct PublishKskContext *`
113 */ 110 */
114static void 111static void
115publish_ksk_cont (void *cls); 112publish_ksk_cont(void *cls);
116 113
117 114
118/** 115/**
@@ -123,21 +120,21 @@ publish_ksk_cont (void *cls);
123 * @param msg error message (or NULL) 120 * @param msg error message (or NULL)
124 */ 121 */
125static void 122static void
126kb_put_cont (void *cls, 123kb_put_cont(void *cls,
127 const char *msg) 124 const char *msg)
128{ 125{
129 struct GNUNET_FS_PublishKskContext *pkc = cls; 126 struct GNUNET_FS_PublishKskContext *pkc = cls;
130 127
131 pkc->uc = NULL; 128 pkc->uc = NULL;
132 if (NULL != msg) 129 if (NULL != msg)
133 { 130 {
134 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 131 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
135 "KBlock PUT operation failed: %s\n", msg); 132 "KBlock PUT operation failed: %s\n", msg);
136 pkc->cont (pkc->cont_cls, NULL, msg); 133 pkc->cont(pkc->cont_cls, NULL, msg);
137 GNUNET_FS_publish_ksk_cancel (pkc); 134 GNUNET_FS_publish_ksk_cancel(pkc);
138 return; 135 return;
139 } 136 }
140 pkc->ksk_task = GNUNET_SCHEDULER_add_now (&publish_ksk_cont, pkc); 137 pkc->ksk_task = GNUNET_SCHEDULER_add_now(&publish_ksk_cont, pkc);
141} 138}
142 139
143 140
@@ -148,33 +145,33 @@ kb_put_cont (void *cls,
148 * @param cls closure of type `struct GNUNET_FS_PublishKskContext *` 145 * @param cls closure of type `struct GNUNET_FS_PublishKskContext *`
149 */ 146 */
150static void 147static void
151publish_ksk_cont (void *cls) 148publish_ksk_cont(void *cls)
152{ 149{
153 struct GNUNET_FS_PublishKskContext *pkc = cls; 150 struct GNUNET_FS_PublishKskContext *pkc = cls;
154 const char *keyword; 151 const char *keyword;
155 152
156 pkc->ksk_task = NULL; 153 pkc->ksk_task = NULL;
157 if ( (pkc->i == pkc->ksk_uri->data.ksk.keywordCount) || 154 if ((pkc->i == pkc->ksk_uri->data.ksk.keywordCount) ||
158 (NULL == pkc->dsh) ) 155 (NULL == pkc->dsh))
159 { 156 {
160 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 157 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
161 "KSK PUT operation complete\n"); 158 "KSK PUT operation complete\n");
162 pkc->cont (pkc->cont_cls, pkc->ksk_uri, 159 pkc->cont(pkc->cont_cls, pkc->ksk_uri,
163 NULL); 160 NULL);
164 GNUNET_FS_publish_ksk_cancel (pkc); 161 GNUNET_FS_publish_ksk_cancel(pkc);
165 return; 162 return;
166 } 163 }
167 keyword = pkc->ksk_uri->data.ksk.keywords[pkc->i++]; 164 keyword = pkc->ksk_uri->data.ksk.keywords[pkc->i++];
168 pkc->uc = GNUNET_FS_publish_ublock_ (pkc->h, 165 pkc->uc = GNUNET_FS_publish_ublock_(pkc->h,
169 pkc->dsh, 166 pkc->dsh,
170 keyword + 1 /* skip '+' */, 167 keyword + 1 /* skip '+' */,
171 NULL, 168 NULL,
172 GNUNET_CRYPTO_ecdsa_key_get_anonymous (), 169 GNUNET_CRYPTO_ecdsa_key_get_anonymous(),
173 pkc->meta, 170 pkc->meta,
174 pkc->uri, 171 pkc->uri,
175 &pkc->bo, 172 &pkc->bo,
176 pkc->options, 173 pkc->options,
177 &kb_put_cont, pkc); 174 &kb_put_cont, pkc);
178} 175}
179 176
180 177
@@ -192,39 +189,39 @@ publish_ksk_cont (void *cls)
192 * @return NULL on error ('cont' will still be called) 189 * @return NULL on error ('cont' will still be called)
193 */ 190 */
194struct GNUNET_FS_PublishKskContext * 191struct GNUNET_FS_PublishKskContext *
195GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h, 192GNUNET_FS_publish_ksk(struct GNUNET_FS_Handle *h,
196 const struct GNUNET_FS_Uri *ksk_uri, 193 const struct GNUNET_FS_Uri *ksk_uri,
197 const struct GNUNET_CONTAINER_MetaData *meta, 194 const struct GNUNET_CONTAINER_MetaData *meta,
198 const struct GNUNET_FS_Uri *uri, 195 const struct GNUNET_FS_Uri *uri,
199 const struct GNUNET_FS_BlockOptions *bo, 196 const struct GNUNET_FS_BlockOptions *bo,
200 enum GNUNET_FS_PublishOptions options, 197 enum GNUNET_FS_PublishOptions options,
201 GNUNET_FS_PublishContinuation cont, void *cont_cls) 198 GNUNET_FS_PublishContinuation cont, void *cont_cls)
202{ 199{
203 struct GNUNET_FS_PublishKskContext *pkc; 200 struct GNUNET_FS_PublishKskContext *pkc;
204 201
205 GNUNET_assert (NULL != uri); 202 GNUNET_assert(NULL != uri);
206 pkc = GNUNET_new (struct GNUNET_FS_PublishKskContext); 203 pkc = GNUNET_new(struct GNUNET_FS_PublishKskContext);
207 pkc->h = h; 204 pkc->h = h;
208 pkc->bo = *bo; 205 pkc->bo = *bo;
209 pkc->options = options; 206 pkc->options = options;
210 pkc->cont = cont; 207 pkc->cont = cont;
211 pkc->cont_cls = cont_cls; 208 pkc->cont_cls = cont_cls;
212 pkc->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); 209 pkc->meta = GNUNET_CONTAINER_meta_data_duplicate(meta);
213 if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) 210 if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY))
214 {
215 pkc->dsh = GNUNET_DATASTORE_connect (h->cfg);
216 if (NULL == pkc->dsh)
217 { 211 {
218 cont (cont_cls, 212 pkc->dsh = GNUNET_DATASTORE_connect(h->cfg);
219 NULL, 213 if (NULL == pkc->dsh)
220 _("Could not connect to datastore.")); 214 {
221 GNUNET_free (pkc); 215 cont(cont_cls,
222 return NULL; 216 NULL,
217 _("Could not connect to datastore."));
218 GNUNET_free(pkc);
219 return NULL;
220 }
223 } 221 }
224 } 222 pkc->uri = GNUNET_FS_uri_dup(uri);
225 pkc->uri = GNUNET_FS_uri_dup (uri); 223 pkc->ksk_uri = GNUNET_FS_uri_dup(ksk_uri);
226 pkc->ksk_uri = GNUNET_FS_uri_dup (ksk_uri); 224 pkc->ksk_task = GNUNET_SCHEDULER_add_now(&publish_ksk_cont, pkc);
227 pkc->ksk_task = GNUNET_SCHEDULER_add_now (&publish_ksk_cont, pkc);
228 return pkc; 225 return pkc;
229} 226}
230 227
@@ -235,27 +232,27 @@ GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
235 * @param pkc context of the operation to abort. 232 * @param pkc context of the operation to abort.
236 */ 233 */
237void 234void
238GNUNET_FS_publish_ksk_cancel (struct GNUNET_FS_PublishKskContext *pkc) 235GNUNET_FS_publish_ksk_cancel(struct GNUNET_FS_PublishKskContext *pkc)
239{ 236{
240 if (NULL != pkc->ksk_task) 237 if (NULL != pkc->ksk_task)
241 { 238 {
242 GNUNET_SCHEDULER_cancel (pkc->ksk_task); 239 GNUNET_SCHEDULER_cancel(pkc->ksk_task);
243 pkc->ksk_task = NULL; 240 pkc->ksk_task = NULL;
244 } 241 }
245 if (NULL != pkc->uc) 242 if (NULL != pkc->uc)
246 { 243 {
247 GNUNET_FS_publish_ublock_cancel_ (pkc->uc); 244 GNUNET_FS_publish_ublock_cancel_(pkc->uc);
248 pkc->uc = NULL; 245 pkc->uc = NULL;
249 } 246 }
250 if (NULL != pkc->dsh) 247 if (NULL != pkc->dsh)
251 { 248 {
252 GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO); 249 GNUNET_DATASTORE_disconnect(pkc->dsh, GNUNET_NO);
253 pkc->dsh = NULL; 250 pkc->dsh = NULL;
254 } 251 }
255 GNUNET_CONTAINER_meta_data_destroy (pkc->meta); 252 GNUNET_CONTAINER_meta_data_destroy(pkc->meta);
256 GNUNET_FS_uri_destroy (pkc->ksk_uri); 253 GNUNET_FS_uri_destroy(pkc->ksk_uri);
257 GNUNET_FS_uri_destroy (pkc->uri); 254 GNUNET_FS_uri_destroy(pkc->uri);
258 GNUNET_free (pkc); 255 GNUNET_free(pkc);
259} 256}
260 257
261 258