diff options
Diffstat (limited to 'src/fs/fs_unindex.c')
-rw-r--r-- | src/fs/fs_unindex.c | 862 |
1 files changed, 432 insertions, 430 deletions
diff --git a/src/fs/fs_unindex.c b/src/fs/fs_unindex.c index b013902c9..be2dbbddd 100644 --- a/src/fs/fs_unindex.c +++ b/src/fs/fs_unindex.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_unindex.c | 22 | * @file fs/fs_unindex.c |
@@ -48,26 +48,26 @@ | |||
48 | * @return number of bytes copied to buf, 0 on error | 48 | * @return number of bytes copied to buf, 0 on error |
49 | */ | 49 | */ |
50 | static size_t | 50 | static size_t |
51 | unindex_reader (void *cls, | 51 | unindex_reader(void *cls, |
52 | uint64_t offset, | 52 | uint64_t offset, |
53 | size_t max, | 53 | size_t max, |
54 | void *buf, | 54 | void *buf, |
55 | char **emsg) | 55 | char **emsg) |
56 | { | 56 | { |
57 | struct GNUNET_FS_UnindexContext *uc = cls; | 57 | struct GNUNET_FS_UnindexContext *uc = cls; |
58 | size_t pt_size; | 58 | size_t pt_size; |
59 | 59 | ||
60 | pt_size = GNUNET_MIN (max, uc->file_size - offset); | 60 | pt_size = GNUNET_MIN(max, uc->file_size - offset); |
61 | if (offset != GNUNET_DISK_file_seek (uc->fh, offset, GNUNET_DISK_SEEK_SET)) | 61 | if (offset != GNUNET_DISK_file_seek(uc->fh, offset, GNUNET_DISK_SEEK_SET)) |
62 | { | 62 | { |
63 | *emsg = GNUNET_strdup (_("Failed to find given position in file")); | 63 | *emsg = GNUNET_strdup(_("Failed to find given position in file")); |
64 | return 0; | 64 | return 0; |
65 | } | 65 | } |
66 | if (pt_size != GNUNET_DISK_file_read (uc->fh, buf, pt_size)) | 66 | if (pt_size != GNUNET_DISK_file_read(uc->fh, buf, pt_size)) |
67 | { | 67 | { |
68 | *emsg = GNUNET_strdup (_("Failed to read file")); | 68 | *emsg = GNUNET_strdup(_("Failed to read file")); |
69 | return 0; | 69 | return 0; |
70 | } | 70 | } |
71 | return pt_size; | 71 | return pt_size; |
72 | } | 72 | } |
73 | 73 | ||
@@ -81,21 +81,21 @@ unindex_reader (void *cls, | |||
81 | * @param offset where we are in the file (for progress) | 81 | * @param offset where we are in the file (for progress) |
82 | */ | 82 | */ |
83 | void | 83 | void |
84 | GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi, | 84 | GNUNET_FS_unindex_make_status_(struct GNUNET_FS_ProgressInfo *pi, |
85 | struct GNUNET_FS_UnindexContext *uc, | 85 | struct GNUNET_FS_UnindexContext *uc, |
86 | uint64_t offset) | 86 | uint64_t offset) |
87 | { | 87 | { |
88 | pi->value.unindex.uc = uc; | 88 | pi->value.unindex.uc = uc; |
89 | pi->value.unindex.cctx = uc->client_info; | 89 | pi->value.unindex.cctx = uc->client_info; |
90 | pi->value.unindex.filename = uc->filename; | 90 | pi->value.unindex.filename = uc->filename; |
91 | pi->value.unindex.size = uc->file_size; | 91 | pi->value.unindex.size = uc->file_size; |
92 | pi->value.unindex.eta = | 92 | pi->value.unindex.eta = |
93 | GNUNET_TIME_calculate_eta (uc->start_time, offset, uc->file_size); | 93 | GNUNET_TIME_calculate_eta(uc->start_time, offset, uc->file_size); |
94 | pi->value.unindex.duration = | 94 | pi->value.unindex.duration = |
95 | GNUNET_TIME_absolute_get_duration (uc->start_time); | 95 | GNUNET_TIME_absolute_get_duration(uc->start_time); |
96 | pi->value.unindex.completed = offset; | 96 | pi->value.unindex.completed = offset; |
97 | pi->fsh = uc->h; | 97 | pi->fsh = uc->h; |
98 | uc->client_info = uc->h->upcb (uc->h->upcb_cls, pi); | 98 | uc->client_info = uc->h->upcb(uc->h->upcb_cls, pi); |
99 | } | 99 | } |
100 | 100 | ||
101 | 101 | ||
@@ -110,11 +110,11 @@ GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi, | |||
110 | * @param depth depth of the block in the tree, 0 for DBLOCK | 110 | * @param depth depth of the block in the tree, 0 for DBLOCK |
111 | */ | 111 | */ |
112 | static void | 112 | static void |
113 | unindex_progress (void *cls, | 113 | unindex_progress(void *cls, |
114 | uint64_t offset, | 114 | uint64_t offset, |
115 | const void *pt_block, | 115 | const void *pt_block, |
116 | size_t pt_size, | 116 | size_t pt_size, |
117 | unsigned int depth) | 117 | unsigned int depth) |
118 | { | 118 | { |
119 | struct GNUNET_FS_UnindexContext *uc = cls; | 119 | struct GNUNET_FS_UnindexContext *uc = cls; |
120 | struct GNUNET_FS_ProgressInfo pi; | 120 | struct GNUNET_FS_ProgressInfo pi; |
@@ -124,7 +124,7 @@ unindex_progress (void *cls, | |||
124 | pi.value.unindex.specifics.progress.offset = offset; | 124 | pi.value.unindex.specifics.progress.offset = offset; |
125 | pi.value.unindex.specifics.progress.data_len = pt_size; | 125 | pi.value.unindex.specifics.progress.data_len = pt_size; |
126 | pi.value.unindex.specifics.progress.depth = depth; | 126 | pi.value.unindex.specifics.progress.depth = depth; |
127 | GNUNET_FS_unindex_make_status_ (&pi, uc, offset); | 127 | GNUNET_FS_unindex_make_status_(&pi, uc, offset); |
128 | } | 128 | } |
129 | 129 | ||
130 | 130 | ||
@@ -135,14 +135,14 @@ unindex_progress (void *cls, | |||
135 | * @param uc context for the failed unindexing operation | 135 | * @param uc context for the failed unindexing operation |
136 | */ | 136 | */ |
137 | static void | 137 | static void |
138 | signal_unindex_error (struct GNUNET_FS_UnindexContext *uc) | 138 | signal_unindex_error(struct GNUNET_FS_UnindexContext *uc) |
139 | { | 139 | { |
140 | struct GNUNET_FS_ProgressInfo pi; | 140 | struct GNUNET_FS_ProgressInfo pi; |
141 | 141 | ||
142 | pi.status = GNUNET_FS_STATUS_UNINDEX_ERROR; | 142 | pi.status = GNUNET_FS_STATUS_UNINDEX_ERROR; |
143 | pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL; | 143 | pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL; |
144 | pi.value.unindex.specifics.error.message = uc->emsg; | 144 | pi.value.unindex.specifics.error.message = uc->emsg; |
145 | GNUNET_FS_unindex_make_status_ (&pi, uc, 0); | 145 | GNUNET_FS_unindex_make_status_(&pi, uc, 0); |
146 | } | 146 | } |
147 | 147 | ||
148 | 148 | ||
@@ -156,22 +156,22 @@ signal_unindex_error (struct GNUNET_FS_UnindexContext *uc) | |||
156 | * @param msg NULL on success, otherwise an error message | 156 | * @param msg NULL on success, otherwise an error message |
157 | */ | 157 | */ |
158 | static void | 158 | static void |
159 | process_cont (void *cls, | 159 | process_cont(void *cls, |
160 | int success, | 160 | int success, |
161 | struct GNUNET_TIME_Absolute min_expiration, | 161 | struct GNUNET_TIME_Absolute min_expiration, |
162 | const char *msg) | 162 | const char *msg) |
163 | { | 163 | { |
164 | struct GNUNET_FS_UnindexContext *uc = cls; | 164 | struct GNUNET_FS_UnindexContext *uc = cls; |
165 | 165 | ||
166 | if (success == GNUNET_SYSERR) | 166 | if (success == GNUNET_SYSERR) |
167 | { | 167 | { |
168 | uc->emsg = GNUNET_strdup (msg); | 168 | uc->emsg = GNUNET_strdup(msg); |
169 | signal_unindex_error (uc); | 169 | signal_unindex_error(uc); |
170 | return; | 170 | return; |
171 | } | 171 | } |
172 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 172 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
173 | "Datastore REMOVE operation succeeded\n"); | 173 | "Datastore REMOVE operation succeeded\n"); |
174 | GNUNET_FS_tree_encoder_next (uc->tc); | 174 | GNUNET_FS_tree_encoder_next(uc->tc); |
175 | } | 175 | } |
176 | 176 | ||
177 | 177 | ||
@@ -190,13 +190,13 @@ process_cont (void *cls, | |||
190 | * @param block_size size of block (in bytes) | 190 | * @param block_size size of block (in bytes) |
191 | */ | 191 | */ |
192 | static void | 192 | static void |
193 | unindex_process (void *cls, | 193 | unindex_process(void *cls, |
194 | const struct ContentHashKey *chk, | 194 | const struct ContentHashKey *chk, |
195 | uint64_t offset, | 195 | uint64_t offset, |
196 | unsigned int depth, | 196 | unsigned int depth, |
197 | enum GNUNET_BLOCK_Type type, | 197 | enum GNUNET_BLOCK_Type type, |
198 | const void *block, | 198 | const void *block, |
199 | uint16_t block_size) | 199 | uint16_t block_size) |
200 | { | 200 | { |
201 | struct GNUNET_FS_UnindexContext *uc = cls; | 201 | struct GNUNET_FS_UnindexContext *uc = cls; |
202 | uint32_t size; | 202 | uint32_t size; |
@@ -204,21 +204,21 @@ unindex_process (void *cls, | |||
204 | struct OnDemandBlock odb; | 204 | struct OnDemandBlock odb; |
205 | 205 | ||
206 | if (type != GNUNET_BLOCK_TYPE_FS_DBLOCK) | 206 | if (type != GNUNET_BLOCK_TYPE_FS_DBLOCK) |
207 | { | 207 | { |
208 | size = block_size; | 208 | size = block_size; |
209 | data = block; | 209 | data = block; |
210 | } | 210 | } |
211 | else /* on-demand encoded DBLOCK */ | 211 | else /* on-demand encoded DBLOCK */ |
212 | { | 212 | { |
213 | size = sizeof (struct OnDemandBlock); | 213 | size = sizeof(struct OnDemandBlock); |
214 | odb.offset = GNUNET_htonll (offset); | 214 | odb.offset = GNUNET_htonll(offset); |
215 | odb.file_id = uc->file_id; | 215 | odb.file_id = uc->file_id; |
216 | data = &odb; | 216 | data = &odb; |
217 | } | 217 | } |
218 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 218 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
219 | "Sending REMOVE request to DATASTORE service\n"); | 219 | "Sending REMOVE request to DATASTORE service\n"); |
220 | GNUNET_DATASTORE_remove (uc->dsh, &chk->query, size, data, -2, 1, | 220 | GNUNET_DATASTORE_remove(uc->dsh, &chk->query, size, data, -2, 1, |
221 | &process_cont, uc); | 221 | &process_cont, uc); |
222 | uc->chk = *chk; | 222 | uc->chk = *chk; |
223 | } | 223 | } |
224 | 224 | ||
@@ -231,24 +231,24 @@ unindex_process (void *cls, | |||
231 | * @param msg the response | 231 | * @param msg the response |
232 | */ | 232 | */ |
233 | static void | 233 | static void |
234 | handle_unindex_response (void *cls, | 234 | handle_unindex_response(void *cls, |
235 | const struct GNUNET_MessageHeader *msg) | 235 | const struct GNUNET_MessageHeader *msg) |
236 | { | 236 | { |
237 | struct GNUNET_FS_UnindexContext *uc = cls; | 237 | struct GNUNET_FS_UnindexContext *uc = cls; |
238 | struct GNUNET_FS_ProgressInfo pi; | 238 | struct GNUNET_FS_ProgressInfo pi; |
239 | 239 | ||
240 | if (NULL != uc->mq) | 240 | if (NULL != uc->mq) |
241 | { | 241 | { |
242 | GNUNET_MQ_destroy (uc->mq); | 242 | GNUNET_MQ_destroy(uc->mq); |
243 | uc->mq = NULL; | 243 | uc->mq = NULL; |
244 | } | 244 | } |
245 | uc->state = UNINDEX_STATE_COMPLETE; | 245 | uc->state = UNINDEX_STATE_COMPLETE; |
246 | pi.status = GNUNET_FS_STATUS_UNINDEX_COMPLETED; | 246 | pi.status = GNUNET_FS_STATUS_UNINDEX_COMPLETED; |
247 | pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO; | 247 | pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO; |
248 | GNUNET_FS_unindex_sync_ (uc); | 248 | GNUNET_FS_unindex_sync_(uc); |
249 | GNUNET_FS_unindex_make_status_ (&pi, | 249 | GNUNET_FS_unindex_make_status_(&pi, |
250 | uc, | 250 | uc, |
251 | uc->file_size); | 251 | uc->file_size); |
252 | } | 252 | } |
253 | 253 | ||
254 | 254 | ||
@@ -261,20 +261,20 @@ handle_unindex_response (void *cls, | |||
261 | * @param error error code | 261 | * @param error error code |
262 | */ | 262 | */ |
263 | static void | 263 | static void |
264 | unindex_mq_error_handler (void *cls, | 264 | unindex_mq_error_handler(void *cls, |
265 | enum GNUNET_MQ_Error error) | 265 | enum GNUNET_MQ_Error error) |
266 | { | 266 | { |
267 | struct GNUNET_FS_UnindexContext *uc = cls; | 267 | struct GNUNET_FS_UnindexContext *uc = cls; |
268 | 268 | ||
269 | if (NULL != uc->mq) | 269 | if (NULL != uc->mq) |
270 | { | 270 | { |
271 | GNUNET_MQ_destroy (uc->mq); | 271 | GNUNET_MQ_destroy(uc->mq); |
272 | uc->mq = NULL; | 272 | uc->mq = NULL; |
273 | } | 273 | } |
274 | uc->state = UNINDEX_STATE_ERROR; | 274 | uc->state = UNINDEX_STATE_ERROR; |
275 | uc->emsg = GNUNET_strdup (_("Error communicating with `fs' service.")); | 275 | uc->emsg = GNUNET_strdup(_("Error communicating with `fs' service.")); |
276 | GNUNET_FS_unindex_sync_ (uc); | 276 | GNUNET_FS_unindex_sync_(uc); |
277 | signal_unindex_error (uc); | 277 | signal_unindex_error(uc); |
278 | } | 278 | } |
279 | 279 | ||
280 | 280 | ||
@@ -286,56 +286,56 @@ unindex_mq_error_handler (void *cls, | |||
286 | * @param uc our unindexing context | 286 | * @param uc our unindexing context |
287 | */ | 287 | */ |
288 | static void | 288 | static void |
289 | unindex_finish (struct GNUNET_FS_UnindexContext *uc) | 289 | unindex_finish(struct GNUNET_FS_UnindexContext *uc) |
290 | { | 290 | { |
291 | struct GNUNET_MQ_MessageHandler handlers[] = { | 291 | struct GNUNET_MQ_MessageHandler handlers[] = { |
292 | GNUNET_MQ_hd_fixed_size (unindex_response, | 292 | GNUNET_MQ_hd_fixed_size(unindex_response, |
293 | GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK, | 293 | GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK, |
294 | struct GNUNET_MessageHeader, | 294 | struct GNUNET_MessageHeader, |
295 | uc), | 295 | uc), |
296 | GNUNET_MQ_handler_end () | 296 | GNUNET_MQ_handler_end() |
297 | }; | 297 | }; |
298 | char *emsg; | 298 | char *emsg; |
299 | struct GNUNET_MQ_Envelope *env; | 299 | struct GNUNET_MQ_Envelope *env; |
300 | struct UnindexMessage *req; | 300 | struct UnindexMessage *req; |
301 | 301 | ||
302 | /* generate final progress message */ | 302 | /* generate final progress message */ |
303 | unindex_progress (uc, | 303 | unindex_progress(uc, |
304 | uc->file_size, | 304 | uc->file_size, |
305 | NULL, | 305 | NULL, |
306 | 0, | 306 | 0, |
307 | 0); | 307 | 0); |
308 | GNUNET_FS_tree_encoder_finish (uc->tc, | 308 | GNUNET_FS_tree_encoder_finish(uc->tc, |
309 | &emsg); | 309 | &emsg); |
310 | uc->tc = NULL; | 310 | uc->tc = NULL; |
311 | GNUNET_DISK_file_close (uc->fh); | 311 | GNUNET_DISK_file_close(uc->fh); |
312 | uc->fh = NULL; | 312 | uc->fh = NULL; |
313 | GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO); | 313 | GNUNET_DATASTORE_disconnect(uc->dsh, GNUNET_NO); |
314 | uc->dsh = NULL; | 314 | uc->dsh = NULL; |
315 | uc->state = UNINDEX_STATE_FS_NOTIFY; | 315 | uc->state = UNINDEX_STATE_FS_NOTIFY; |
316 | GNUNET_FS_unindex_sync_ (uc); | 316 | GNUNET_FS_unindex_sync_(uc); |
317 | uc->mq = GNUNET_CLIENT_connect (uc->h->cfg, | 317 | uc->mq = GNUNET_CLIENT_connect(uc->h->cfg, |
318 | "fs", | 318 | "fs", |
319 | handlers, | 319 | handlers, |
320 | &unindex_mq_error_handler, | 320 | &unindex_mq_error_handler, |
321 | uc); | 321 | uc); |
322 | if (NULL == uc->mq) | 322 | if (NULL == uc->mq) |
323 | { | 323 | { |
324 | uc->state = UNINDEX_STATE_ERROR; | 324 | uc->state = UNINDEX_STATE_ERROR; |
325 | uc->emsg = | 325 | uc->emsg = |
326 | GNUNET_strdup (_("Failed to connect to FS service for unindexing.")); | 326 | GNUNET_strdup(_("Failed to connect to FS service for unindexing.")); |
327 | GNUNET_FS_unindex_sync_ (uc); | 327 | GNUNET_FS_unindex_sync_(uc); |
328 | signal_unindex_error (uc); | 328 | signal_unindex_error(uc); |
329 | return; | 329 | return; |
330 | } | 330 | } |
331 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 331 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
332 | "Sending UNINDEX message to FS service\n"); | 332 | "Sending UNINDEX message to FS service\n"); |
333 | env = GNUNET_MQ_msg (req, | 333 | env = GNUNET_MQ_msg(req, |
334 | GNUNET_MESSAGE_TYPE_FS_UNINDEX); | 334 | GNUNET_MESSAGE_TYPE_FS_UNINDEX); |
335 | req->reserved = 0; | 335 | req->reserved = 0; |
336 | req->file_id = uc->file_id; | 336 | req->file_id = uc->file_id; |
337 | GNUNET_MQ_send (uc->mq, | 337 | GNUNET_MQ_send(uc->mq, |
338 | env); | 338 | env); |
339 | } | 339 | } |
340 | 340 | ||
341 | 341 | ||
@@ -351,47 +351,49 @@ unindex_finish (struct GNUNET_FS_UnindexContext *uc) | |||
351 | * @param reason kind of progress we are making | 351 | * @param reason kind of progress we are making |
352 | */ | 352 | */ |
353 | static void | 353 | static void |
354 | unindex_directory_scan_cb (void *cls, | 354 | unindex_directory_scan_cb(void *cls, |
355 | const char *filename, | 355 | const char *filename, |
356 | int is_directory, | 356 | int is_directory, |
357 | enum GNUNET_FS_DirScannerProgressUpdateReason reason) | 357 | enum GNUNET_FS_DirScannerProgressUpdateReason reason) |
358 | { | 358 | { |
359 | struct GNUNET_FS_UnindexContext *uc = cls; | 359 | struct GNUNET_FS_UnindexContext *uc = cls; |
360 | static struct GNUNET_FS_ShareTreeItem * directory_scan_result; | 360 | static struct GNUNET_FS_ShareTreeItem * directory_scan_result; |
361 | 361 | ||
362 | switch (reason) | 362 | switch (reason) |
363 | { | 363 | { |
364 | case GNUNET_FS_DIRSCANNER_FINISHED: | 364 | case GNUNET_FS_DIRSCANNER_FINISHED: |
365 | directory_scan_result = GNUNET_FS_directory_scan_get_result (uc->dscan); | 365 | directory_scan_result = GNUNET_FS_directory_scan_get_result(uc->dscan); |
366 | uc->dscan = NULL; | 366 | uc->dscan = NULL; |
367 | if (NULL != directory_scan_result->ksk_uri) | 367 | if (NULL != directory_scan_result->ksk_uri) |
368 | { | 368 | { |
369 | uc->ksk_uri = GNUNET_FS_uri_dup (directory_scan_result->ksk_uri); | 369 | uc->ksk_uri = GNUNET_FS_uri_dup(directory_scan_result->ksk_uri); |
370 | uc->state = UNINDEX_STATE_DS_REMOVE_KBLOCKS; | 370 | uc->state = UNINDEX_STATE_DS_REMOVE_KBLOCKS; |
371 | GNUNET_FS_unindex_sync_ (uc); | 371 | GNUNET_FS_unindex_sync_(uc); |
372 | GNUNET_FS_unindex_do_remove_kblocks_ (uc); | 372 | GNUNET_FS_unindex_do_remove_kblocks_(uc); |
373 | } | 373 | } |
374 | else | 374 | else |
375 | { | 375 | { |
376 | uc->emsg = GNUNET_strdup (_("Failed to get KSKs from directory scan.")); | 376 | uc->emsg = GNUNET_strdup(_("Failed to get KSKs from directory scan.")); |
377 | GNUNET_FS_unindex_sync_ (uc); | 377 | GNUNET_FS_unindex_sync_(uc); |
378 | unindex_finish (uc); | 378 | unindex_finish(uc); |
379 | } | 379 | } |
380 | GNUNET_FS_share_tree_free (directory_scan_result); | 380 | GNUNET_FS_share_tree_free(directory_scan_result); |
381 | break; | 381 | break; |
382 | case GNUNET_FS_DIRSCANNER_INTERNAL_ERROR: | 382 | |
383 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 383 | case GNUNET_FS_DIRSCANNER_INTERNAL_ERROR: |
384 | _("Internal error scanning `%s'.\n"), | 384 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
385 | uc->filename); | 385 | _("Internal error scanning `%s'.\n"), |
386 | GNUNET_FS_directory_scan_abort (uc->dscan); | 386 | uc->filename); |
387 | uc->dscan = NULL; | 387 | GNUNET_FS_directory_scan_abort(uc->dscan); |
388 | uc->emsg = GNUNET_strdup (_("Failed to get KSKs from directory scan.")); | 388 | uc->dscan = NULL; |
389 | GNUNET_FS_unindex_sync_ (uc); | 389 | uc->emsg = GNUNET_strdup(_("Failed to get KSKs from directory scan.")); |
390 | unindex_finish (uc); | 390 | GNUNET_FS_unindex_sync_(uc); |
391 | break; | 391 | unindex_finish(uc); |
392 | default: | 392 | break; |
393 | break; | 393 | |
394 | } | 394 | default: |
395 | break; | ||
396 | } | ||
395 | } | 397 | } |
396 | 398 | ||
397 | 399 | ||
@@ -401,18 +403,18 @@ unindex_directory_scan_cb (void *cls, | |||
401 | * @param uc context for the unindex operation. | 403 | * @param uc context for the unindex operation. |
402 | */ | 404 | */ |
403 | void | 405 | void |
404 | GNUNET_FS_unindex_do_extract_keywords_ (struct GNUNET_FS_UnindexContext *uc) | 406 | GNUNET_FS_unindex_do_extract_keywords_(struct GNUNET_FS_UnindexContext *uc) |
405 | { | 407 | { |
406 | char *ex; | 408 | char *ex; |
407 | 409 | ||
408 | if (GNUNET_OK != | 410 | if (GNUNET_OK != |
409 | GNUNET_CONFIGURATION_get_value_string (uc->h->cfg, "FS", "EXTRACTORS", &ex)) | 411 | GNUNET_CONFIGURATION_get_value_string(uc->h->cfg, "FS", "EXTRACTORS", &ex)) |
410 | ex = NULL; | 412 | ex = NULL; |
411 | uc->dscan = GNUNET_FS_directory_scan_start (uc->filename, | 413 | uc->dscan = GNUNET_FS_directory_scan_start(uc->filename, |
412 | GNUNET_NO, ex, | 414 | GNUNET_NO, ex, |
413 | &unindex_directory_scan_cb, | 415 | &unindex_directory_scan_cb, |
414 | uc); | 416 | uc); |
415 | GNUNET_free_non_null (ex); | 417 | GNUNET_free_non_null(ex); |
416 | } | 418 | } |
417 | 419 | ||
418 | 420 | ||
@@ -430,20 +432,20 @@ GNUNET_FS_unindex_do_extract_keywords_ (struct GNUNET_FS_UnindexContext *uc) | |||
430 | * @param msg NULL on success, otherwise an error message | 432 | * @param msg NULL on success, otherwise an error message |
431 | */ | 433 | */ |
432 | static void | 434 | static void |
433 | continue_after_remove (void *cls, | 435 | continue_after_remove(void *cls, |
434 | int32_t success, | 436 | int32_t success, |
435 | struct GNUNET_TIME_Absolute min_expiration, | 437 | struct GNUNET_TIME_Absolute min_expiration, |
436 | const char *msg) | 438 | const char *msg) |
437 | { | 439 | { |
438 | struct GNUNET_FS_UnindexContext *uc = cls; | 440 | struct GNUNET_FS_UnindexContext *uc = cls; |
439 | 441 | ||
440 | uc->dqe = NULL; | 442 | uc->dqe = NULL; |
441 | if (success != GNUNET_YES) | 443 | if (success != GNUNET_YES) |
442 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 444 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
443 | _("Failed to remove UBlock: %s\n"), | 445 | _("Failed to remove UBlock: %s\n"), |
444 | msg); | 446 | msg); |
445 | uc->ksk_offset++; | 447 | uc->ksk_offset++; |
446 | GNUNET_FS_unindex_do_remove_kblocks_ (uc); | 448 | GNUNET_FS_unindex_do_remove_kblocks_(uc); |
447 | } | 449 | } |
448 | 450 | ||
449 | 451 | ||
@@ -470,16 +472,16 @@ continue_after_remove (void *cls, | |||
470 | * maybe 0 if no unique identifier is available | 472 | * maybe 0 if no unique identifier is available |
471 | */ | 473 | */ |
472 | static void | 474 | static void |
473 | process_kblock_for_unindex (void *cls, | 475 | process_kblock_for_unindex(void *cls, |
474 | const struct GNUNET_HashCode *key, | 476 | const struct GNUNET_HashCode *key, |
475 | size_t size, | 477 | size_t size, |
476 | const void *data, | 478 | const void *data, |
477 | enum GNUNET_BLOCK_Type type, | 479 | enum GNUNET_BLOCK_Type type, |
478 | uint32_t priority, | 480 | uint32_t priority, |
479 | uint32_t anonymity, | 481 | uint32_t anonymity, |
480 | uint32_t replication, | 482 | uint32_t replication, |
481 | struct GNUNET_TIME_Absolute expiration, | 483 | struct GNUNET_TIME_Absolute expiration, |
482 | uint64_t uid) | 484 | uint64_t uid) |
483 | { | 485 | { |
484 | struct GNUNET_FS_UnindexContext *uc = cls; | 486 | struct GNUNET_FS_UnindexContext *uc = cls; |
485 | const struct UBlock *ub; | 487 | const struct UBlock *ub; |
@@ -488,82 +490,82 @@ process_kblock_for_unindex (void *cls, | |||
488 | 490 | ||
489 | uc->dqe = NULL; | 491 | uc->dqe = NULL; |
490 | if (NULL == data) | 492 | if (NULL == data) |
491 | { | 493 | { |
492 | /* no result */ | 494 | /* no result */ |
493 | uc->ksk_offset++; | 495 | uc->ksk_offset++; |
494 | GNUNET_FS_unindex_do_remove_kblocks_ (uc); | 496 | GNUNET_FS_unindex_do_remove_kblocks_(uc); |
495 | return; | 497 | return; |
496 | } | 498 | } |
497 | GNUNET_assert (GNUNET_BLOCK_TYPE_FS_UBLOCK == type); | 499 | GNUNET_assert(GNUNET_BLOCK_TYPE_FS_UBLOCK == type); |
498 | if (size < sizeof (struct UBlock)) | 500 | if (size < sizeof(struct UBlock)) |
499 | { | 501 | { |
500 | GNUNET_break (0); | 502 | GNUNET_break(0); |
501 | goto get_next; | 503 | goto get_next; |
502 | } | 504 | } |
503 | ub = data; | 505 | ub = data; |
504 | GNUNET_CRYPTO_hash (&ub->verification_key, | 506 | GNUNET_CRYPTO_hash(&ub->verification_key, |
505 | sizeof (ub->verification_key), | 507 | sizeof(ub->verification_key), |
506 | &query); | 508 | &query); |
507 | if (0 != memcmp (&query, | 509 | if (0 != memcmp(&query, |
508 | key, | 510 | key, |
509 | sizeof (struct GNUNET_HashCode))) | 511 | sizeof(struct GNUNET_HashCode))) |
510 | { | 512 | { |
511 | /* result does not match our keyword, skip */ | 513 | /* result does not match our keyword, skip */ |
512 | goto get_next; | 514 | goto get_next; |
513 | } | 515 | } |
514 | { | 516 | { |
515 | char pt[size - sizeof (struct UBlock)]; | 517 | char pt[size - sizeof(struct UBlock)]; |
516 | struct GNUNET_CRYPTO_EcdsaPublicKey anon_pub; | 518 | struct GNUNET_CRYPTO_EcdsaPublicKey anon_pub; |
517 | const char *keyword; | 519 | const char *keyword; |
518 | 520 | ||
519 | GNUNET_CRYPTO_ecdsa_key_get_public (GNUNET_CRYPTO_ecdsa_key_get_anonymous (), | 521 | GNUNET_CRYPTO_ecdsa_key_get_public(GNUNET_CRYPTO_ecdsa_key_get_anonymous(), |
520 | &anon_pub); | 522 | &anon_pub); |
521 | keyword = &uc->ksk_uri->data.ksk.keywords[uc->ksk_offset][1]; | 523 | keyword = &uc->ksk_uri->data.ksk.keywords[uc->ksk_offset][1]; |
522 | GNUNET_FS_ublock_decrypt_ (&ub[1], size - sizeof (struct UBlock), | 524 | GNUNET_FS_ublock_decrypt_(&ub[1], size - sizeof(struct UBlock), |
523 | &anon_pub, | 525 | &anon_pub, |
524 | keyword, | 526 | keyword, |
525 | pt); | 527 | pt); |
526 | if (NULL == memchr (&pt[1], 0, sizeof (pt) - 1)) | 528 | if (NULL == memchr(&pt[1], 0, sizeof(pt) - 1)) |
527 | { | 529 | { |
528 | GNUNET_break_op (0); /* malformed UBlock */ | 530 | GNUNET_break_op(0); /* malformed UBlock */ |
529 | goto get_next; | 531 | goto get_next; |
530 | } | 532 | } |
531 | chk_uri = GNUNET_FS_uri_parse (&pt[1], NULL); | 533 | chk_uri = GNUNET_FS_uri_parse(&pt[1], NULL); |
532 | if (NULL == chk_uri) | 534 | if (NULL == chk_uri) |
535 | { | ||
536 | GNUNET_break_op(0); /* malformed UBlock */ | ||
537 | goto get_next; | ||
538 | } | ||
539 | } | ||
540 | if (0 != memcmp(&uc->chk, | ||
541 | &chk_uri->data.chk.chk, | ||
542 | sizeof(struct ContentHashKey))) | ||
533 | { | 543 | { |
534 | GNUNET_break_op (0); /* malformed UBlock */ | 544 | /* different CHK, ignore */ |
545 | GNUNET_FS_uri_destroy(chk_uri); | ||
535 | goto get_next; | 546 | goto get_next; |
536 | } | 547 | } |
537 | } | 548 | GNUNET_FS_uri_destroy(chk_uri); |
538 | if (0 != memcmp (&uc->chk, | ||
539 | &chk_uri->data.chk.chk, | ||
540 | sizeof (struct ContentHashKey))) | ||
541 | { | ||
542 | /* different CHK, ignore */ | ||
543 | GNUNET_FS_uri_destroy (chk_uri); | ||
544 | goto get_next; | ||
545 | } | ||
546 | GNUNET_FS_uri_destroy (chk_uri); | ||
547 | /* matches! */ | 549 | /* matches! */ |
548 | uc->dqe = GNUNET_DATASTORE_remove (uc->dsh, | 550 | uc->dqe = GNUNET_DATASTORE_remove(uc->dsh, |
549 | key, | 551 | key, |
550 | size, | 552 | size, |
551 | data, | 553 | data, |
554 | 0 /* priority */, | ||
555 | 1 /* queue size */, | ||
556 | &continue_after_remove, | ||
557 | uc); | ||
558 | return; | ||
559 | get_next: | ||
560 | uc->dqe = GNUNET_DATASTORE_get_key(uc->dsh, | ||
561 | uid + 1 /* next_uid */, | ||
562 | false /* random */, | ||
563 | &uc->uquery, | ||
564 | GNUNET_BLOCK_TYPE_FS_UBLOCK, | ||
552 | 0 /* priority */, | 565 | 0 /* priority */, |
553 | 1 /* queue size */, | 566 | 1 /* queue size */, |
554 | &continue_after_remove, | 567 | &process_kblock_for_unindex, |
555 | uc); | 568 | uc); |
556 | return; | ||
557 | get_next: | ||
558 | uc->dqe = GNUNET_DATASTORE_get_key (uc->dsh, | ||
559 | uid + 1 /* next_uid */, | ||
560 | false /* random */, | ||
561 | &uc->uquery, | ||
562 | GNUNET_BLOCK_TYPE_FS_UBLOCK, | ||
563 | 0 /* priority */, | ||
564 | 1 /* queue size */, | ||
565 | &process_kblock_for_unindex, | ||
566 | uc); | ||
567 | } | 569 | } |
568 | 570 | ||
569 | 571 | ||
@@ -573,7 +575,7 @@ process_kblock_for_unindex (void *cls, | |||
573 | * @param uc context for the unindex operation. | 575 | * @param uc context for the unindex operation. |
574 | */ | 576 | */ |
575 | void | 577 | void |
576 | GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc) | 578 | GNUNET_FS_unindex_do_remove_kblocks_(struct GNUNET_FS_UnindexContext *uc) |
577 | { | 579 | { |
578 | const char *keyword; | 580 | const char *keyword; |
579 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *anon; | 581 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *anon; |
@@ -581,41 +583,41 @@ GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc) | |||
581 | struct GNUNET_CRYPTO_EcdsaPublicKey dpub; | 583 | struct GNUNET_CRYPTO_EcdsaPublicKey dpub; |
582 | 584 | ||
583 | if (NULL == uc->dsh) | 585 | if (NULL == uc->dsh) |
584 | uc->dsh = GNUNET_DATASTORE_connect (uc->h->cfg); | 586 | uc->dsh = GNUNET_DATASTORE_connect(uc->h->cfg); |
585 | if (NULL == uc->dsh) | 587 | if (NULL == uc->dsh) |
586 | { | 588 | { |
587 | uc->state = UNINDEX_STATE_ERROR; | 589 | uc->state = UNINDEX_STATE_ERROR; |
588 | uc->emsg = GNUNET_strdup (_("Failed to connect to `datastore' service.")); | 590 | uc->emsg = GNUNET_strdup(_("Failed to connect to `datastore' service.")); |
589 | GNUNET_FS_unindex_sync_ (uc); | 591 | GNUNET_FS_unindex_sync_(uc); |
590 | signal_unindex_error (uc); | 592 | signal_unindex_error(uc); |
591 | return; | 593 | return; |
592 | } | 594 | } |
593 | if ( (NULL == uc->ksk_uri) || | 595 | if ((NULL == uc->ksk_uri) || |
594 | (uc->ksk_offset >= uc->ksk_uri->data.ksk.keywordCount) ) | 596 | (uc->ksk_offset >= uc->ksk_uri->data.ksk.keywordCount)) |
595 | { | 597 | { |
596 | unindex_finish (uc); | 598 | unindex_finish(uc); |
597 | return; | 599 | return; |
598 | } | 600 | } |
599 | anon = GNUNET_CRYPTO_ecdsa_key_get_anonymous (); | 601 | anon = GNUNET_CRYPTO_ecdsa_key_get_anonymous(); |
600 | GNUNET_CRYPTO_ecdsa_key_get_public (anon, | 602 | GNUNET_CRYPTO_ecdsa_key_get_public(anon, |
601 | &anon_pub); | 603 | &anon_pub); |
602 | keyword = &uc->ksk_uri->data.ksk.keywords[uc->ksk_offset][1]; | 604 | keyword = &uc->ksk_uri->data.ksk.keywords[uc->ksk_offset][1]; |
603 | GNUNET_CRYPTO_ecdsa_public_key_derive (&anon_pub, | 605 | GNUNET_CRYPTO_ecdsa_public_key_derive(&anon_pub, |
604 | keyword, | 606 | keyword, |
605 | "fs-ublock", | 607 | "fs-ublock", |
606 | &dpub); | 608 | &dpub); |
607 | GNUNET_CRYPTO_hash (&dpub, | 609 | GNUNET_CRYPTO_hash(&dpub, |
608 | sizeof (dpub), | 610 | sizeof(dpub), |
609 | &uc->uquery); | 611 | &uc->uquery); |
610 | uc->dqe = GNUNET_DATASTORE_get_key (uc->dsh, | 612 | uc->dqe = GNUNET_DATASTORE_get_key(uc->dsh, |
611 | 0 /* next_uid */, | 613 | 0 /* next_uid */, |
612 | false /* random */, | 614 | false /* random */, |
613 | &uc->uquery, | 615 | &uc->uquery, |
614 | GNUNET_BLOCK_TYPE_FS_UBLOCK, | 616 | GNUNET_BLOCK_TYPE_FS_UBLOCK, |
615 | 0 /* priority */, | 617 | 0 /* priority */, |
616 | 1 /* queue size */, | 618 | 1 /* queue size */, |
617 | &process_kblock_for_unindex, | 619 | &process_kblock_for_unindex, |
618 | uc); | 620 | uc); |
619 | } | 621 | } |
620 | 622 | ||
621 | 623 | ||
@@ -626,13 +628,13 @@ GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc) | |||
626 | * @param cls our unindexing context | 628 | * @param cls our unindexing context |
627 | */ | 629 | */ |
628 | static void | 630 | static void |
629 | unindex_extract_keywords (void *cls) | 631 | unindex_extract_keywords(void *cls) |
630 | { | 632 | { |
631 | struct GNUNET_FS_UnindexContext *uc = cls; | 633 | struct GNUNET_FS_UnindexContext *uc = cls; |
632 | 634 | ||
633 | uc->state = UNINDEX_STATE_EXTRACT_KEYWORDS; | 635 | uc->state = UNINDEX_STATE_EXTRACT_KEYWORDS; |
634 | GNUNET_FS_unindex_sync_ (uc); | 636 | GNUNET_FS_unindex_sync_(uc); |
635 | GNUNET_FS_unindex_do_extract_keywords_ (uc); | 637 | GNUNET_FS_unindex_do_extract_keywords_(uc); |
636 | } | 638 | } |
637 | 639 | ||
638 | 640 | ||
@@ -642,40 +644,40 @@ unindex_extract_keywords (void *cls) | |||
642 | * @param uc context for the unindex operation. | 644 | * @param uc context for the unindex operation. |
643 | */ | 645 | */ |
644 | void | 646 | void |
645 | GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc) | 647 | GNUNET_FS_unindex_do_remove_(struct GNUNET_FS_UnindexContext *uc) |
646 | { | 648 | { |
647 | if (NULL == uc->dsh) | 649 | if (NULL == uc->dsh) |
648 | uc->dsh = GNUNET_DATASTORE_connect (uc->h->cfg); | 650 | uc->dsh = GNUNET_DATASTORE_connect(uc->h->cfg); |
649 | if (NULL == uc->dsh) | 651 | if (NULL == uc->dsh) |
650 | { | 652 | { |
651 | uc->state = UNINDEX_STATE_ERROR; | 653 | uc->state = UNINDEX_STATE_ERROR; |
652 | uc->emsg = GNUNET_strdup (_("Failed to connect to `datastore' service.")); | 654 | uc->emsg = GNUNET_strdup(_("Failed to connect to `datastore' service.")); |
653 | GNUNET_FS_unindex_sync_ (uc); | 655 | GNUNET_FS_unindex_sync_(uc); |
654 | signal_unindex_error (uc); | 656 | signal_unindex_error(uc); |
655 | return; | 657 | return; |
656 | } | 658 | } |
657 | uc->fh = | 659 | uc->fh = |
658 | GNUNET_DISK_file_open (uc->filename, GNUNET_DISK_OPEN_READ, | 660 | GNUNET_DISK_file_open(uc->filename, GNUNET_DISK_OPEN_READ, |
659 | GNUNET_DISK_PERM_NONE); | 661 | GNUNET_DISK_PERM_NONE); |
660 | if (NULL == uc->fh) | 662 | if (NULL == uc->fh) |
661 | { | 663 | { |
662 | GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO); | 664 | GNUNET_DATASTORE_disconnect(uc->dsh, GNUNET_NO); |
663 | uc->dsh = NULL; | 665 | uc->dsh = NULL; |
664 | uc->state = UNINDEX_STATE_ERROR; | 666 | uc->state = UNINDEX_STATE_ERROR; |
665 | uc->emsg = GNUNET_strdup (_("Failed to open file for unindexing.")); | 667 | uc->emsg = GNUNET_strdup(_("Failed to open file for unindexing.")); |
666 | GNUNET_FS_unindex_sync_ (uc); | 668 | GNUNET_FS_unindex_sync_(uc); |
667 | signal_unindex_error (uc); | 669 | signal_unindex_error(uc); |
668 | return; | 670 | return; |
669 | } | 671 | } |
670 | uc->tc = | 672 | uc->tc = |
671 | GNUNET_FS_tree_encoder_create (uc->h, | 673 | GNUNET_FS_tree_encoder_create(uc->h, |
672 | uc->file_size, | 674 | uc->file_size, |
673 | uc, | 675 | uc, |
674 | &unindex_reader, | 676 | &unindex_reader, |
675 | &unindex_process, | 677 | &unindex_process, |
676 | &unindex_progress, | 678 | &unindex_progress, |
677 | &unindex_extract_keywords); | 679 | &unindex_extract_keywords); |
678 | GNUNET_FS_tree_encoder_next (uc->tc); | 680 | GNUNET_FS_tree_encoder_next(uc->tc); |
679 | } | 681 | } |
680 | 682 | ||
681 | 683 | ||
@@ -687,29 +689,29 @@ GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc) | |||
687 | * @param file_id computed hash, NULL on error | 689 | * @param file_id computed hash, NULL on error |
688 | */ | 690 | */ |
689 | void | 691 | void |
690 | GNUNET_FS_unindex_process_hash_ (void *cls, | 692 | GNUNET_FS_unindex_process_hash_(void *cls, |
691 | const struct GNUNET_HashCode *file_id) | 693 | const struct GNUNET_HashCode *file_id) |
692 | { | 694 | { |
693 | struct GNUNET_FS_UnindexContext *uc = cls; | 695 | struct GNUNET_FS_UnindexContext *uc = cls; |
694 | 696 | ||
695 | uc->fhc = NULL; | 697 | uc->fhc = NULL; |
696 | if (uc->state != UNINDEX_STATE_HASHING) | 698 | if (uc->state != UNINDEX_STATE_HASHING) |
697 | { | 699 | { |
698 | GNUNET_FS_unindex_stop (uc); | 700 | GNUNET_FS_unindex_stop(uc); |
699 | return; | 701 | return; |
700 | } | 702 | } |
701 | if (file_id == NULL) | 703 | if (file_id == NULL) |
702 | { | 704 | { |
703 | uc->state = UNINDEX_STATE_ERROR; | 705 | uc->state = UNINDEX_STATE_ERROR; |
704 | uc->emsg = GNUNET_strdup (_("Failed to compute hash of file.")); | 706 | uc->emsg = GNUNET_strdup(_("Failed to compute hash of file.")); |
705 | GNUNET_FS_unindex_sync_ (uc); | 707 | GNUNET_FS_unindex_sync_(uc); |
706 | signal_unindex_error (uc); | 708 | signal_unindex_error(uc); |
707 | return; | 709 | return; |
708 | } | 710 | } |
709 | uc->file_id = *file_id; | 711 | uc->file_id = *file_id; |
710 | uc->state = UNINDEX_STATE_DS_REMOVE; | 712 | uc->state = UNINDEX_STATE_DS_REMOVE; |
711 | GNUNET_FS_unindex_sync_ (uc); | 713 | GNUNET_FS_unindex_sync_(uc); |
712 | GNUNET_FS_unindex_do_remove_ (uc); | 714 | GNUNET_FS_unindex_do_remove_(uc); |
713 | } | 715 | } |
714 | 716 | ||
715 | 717 | ||
@@ -720,62 +722,62 @@ GNUNET_FS_unindex_process_hash_ (void *cls, | |||
720 | * @param cls the `struct GNUNET_FS_UnindexContext` to signal for | 722 | * @param cls the `struct GNUNET_FS_UnindexContext` to signal for |
721 | */ | 723 | */ |
722 | void | 724 | void |
723 | GNUNET_FS_unindex_signal_suspend_ (void *cls) | 725 | GNUNET_FS_unindex_signal_suspend_(void *cls) |
724 | { | 726 | { |
725 | struct GNUNET_FS_UnindexContext *uc = cls; | 727 | struct GNUNET_FS_UnindexContext *uc = cls; |
726 | struct GNUNET_FS_ProgressInfo pi; | 728 | struct GNUNET_FS_ProgressInfo pi; |
727 | 729 | ||
728 | /* FIXME: lots of duplication with unindex_stop here! */ | 730 | /* FIXME: lots of duplication with unindex_stop here! */ |
729 | if (uc->dscan != NULL) | 731 | if (uc->dscan != NULL) |
730 | { | 732 | { |
731 | GNUNET_FS_directory_scan_abort (uc->dscan); | 733 | GNUNET_FS_directory_scan_abort(uc->dscan); |
732 | uc->dscan = NULL; | 734 | uc->dscan = NULL; |
733 | } | 735 | } |
734 | if (NULL != uc->dqe) | 736 | if (NULL != uc->dqe) |
735 | { | 737 | { |
736 | GNUNET_DATASTORE_cancel (uc->dqe); | 738 | GNUNET_DATASTORE_cancel(uc->dqe); |
737 | uc->dqe = NULL; | 739 | uc->dqe = NULL; |
738 | } | 740 | } |
739 | if (uc->fhc != NULL) | 741 | if (uc->fhc != NULL) |
740 | { | 742 | { |
741 | GNUNET_CRYPTO_hash_file_cancel (uc->fhc); | 743 | GNUNET_CRYPTO_hash_file_cancel(uc->fhc); |
742 | uc->fhc = NULL; | 744 | uc->fhc = NULL; |
743 | } | 745 | } |
744 | if (NULL != uc->ksk_uri) | 746 | if (NULL != uc->ksk_uri) |
745 | { | 747 | { |
746 | GNUNET_FS_uri_destroy (uc->ksk_uri); | 748 | GNUNET_FS_uri_destroy(uc->ksk_uri); |
747 | uc->ksk_uri = NULL; | 749 | uc->ksk_uri = NULL; |
748 | } | 750 | } |
749 | if (NULL != uc->mq) | 751 | if (NULL != uc->mq) |
750 | { | 752 | { |
751 | GNUNET_MQ_destroy (uc->mq); | 753 | GNUNET_MQ_destroy(uc->mq); |
752 | uc->mq = NULL; | 754 | uc->mq = NULL; |
753 | } | 755 | } |
754 | if (NULL != uc->dsh) | 756 | if (NULL != uc->dsh) |
755 | { | 757 | { |
756 | GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO); | 758 | GNUNET_DATASTORE_disconnect(uc->dsh, GNUNET_NO); |
757 | uc->dsh = NULL; | 759 | uc->dsh = NULL; |
758 | } | 760 | } |
759 | if (NULL != uc->tc) | 761 | if (NULL != uc->tc) |
760 | { | 762 | { |
761 | GNUNET_FS_tree_encoder_finish (uc->tc, NULL); | 763 | GNUNET_FS_tree_encoder_finish(uc->tc, NULL); |
762 | uc->tc = NULL; | 764 | uc->tc = NULL; |
763 | } | 765 | } |
764 | if (uc->fh != NULL) | 766 | if (uc->fh != NULL) |
765 | { | 767 | { |
766 | GNUNET_DISK_file_close (uc->fh); | 768 | GNUNET_DISK_file_close(uc->fh); |
767 | uc->fh = NULL; | 769 | uc->fh = NULL; |
768 | } | 770 | } |
769 | GNUNET_FS_end_top (uc->h, uc->top); | 771 | GNUNET_FS_end_top(uc->h, uc->top); |
770 | pi.status = GNUNET_FS_STATUS_UNINDEX_SUSPEND; | 772 | pi.status = GNUNET_FS_STATUS_UNINDEX_SUSPEND; |
771 | GNUNET_FS_unindex_make_status_ (&pi, uc, | 773 | GNUNET_FS_unindex_make_status_(&pi, uc, |
772 | (uc->state == | 774 | (uc->state == |
773 | UNINDEX_STATE_COMPLETE) ? uc->file_size : 0); | 775 | UNINDEX_STATE_COMPLETE) ? uc->file_size : 0); |
774 | GNUNET_break (NULL == uc->client_info); | 776 | GNUNET_break(NULL == uc->client_info); |
775 | GNUNET_free (uc->filename); | 777 | GNUNET_free(uc->filename); |
776 | GNUNET_free_non_null (uc->serialization); | 778 | GNUNET_free_non_null(uc->serialization); |
777 | GNUNET_free_non_null (uc->emsg); | 779 | GNUNET_free_non_null(uc->emsg); |
778 | GNUNET_free (uc); | 780 | GNUNET_free(uc); |
779 | } | 781 | } |
780 | 782 | ||
781 | 783 | ||
@@ -788,38 +790,38 @@ GNUNET_FS_unindex_signal_suspend_ (void *cls) | |||
788 | * @return NULL on error, otherwise handle | 790 | * @return NULL on error, otherwise handle |
789 | */ | 791 | */ |
790 | struct GNUNET_FS_UnindexContext * | 792 | struct GNUNET_FS_UnindexContext * |
791 | GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h, | 793 | GNUNET_FS_unindex_start(struct GNUNET_FS_Handle *h, |
792 | const char *filename, | 794 | const char *filename, |
793 | void *cctx) | 795 | void *cctx) |
794 | { | 796 | { |
795 | struct GNUNET_FS_UnindexContext *uc; | 797 | struct GNUNET_FS_UnindexContext *uc; |
796 | struct GNUNET_FS_ProgressInfo pi; | 798 | struct GNUNET_FS_ProgressInfo pi; |
797 | uint64_t size; | 799 | uint64_t size; |
798 | 800 | ||
799 | if (GNUNET_OK != | 801 | if (GNUNET_OK != |
800 | GNUNET_DISK_file_size (filename, | 802 | GNUNET_DISK_file_size(filename, |
801 | &size, | 803 | &size, |
802 | GNUNET_YES, | 804 | GNUNET_YES, |
803 | GNUNET_YES)) | 805 | GNUNET_YES)) |
804 | return NULL; | 806 | return NULL; |
805 | uc = GNUNET_new (struct GNUNET_FS_UnindexContext); | 807 | uc = GNUNET_new(struct GNUNET_FS_UnindexContext); |
806 | uc->h = h; | 808 | uc->h = h; |
807 | uc->filename = GNUNET_strdup (filename); | 809 | uc->filename = GNUNET_strdup(filename); |
808 | uc->start_time = GNUNET_TIME_absolute_get (); | 810 | uc->start_time = GNUNET_TIME_absolute_get(); |
809 | uc->file_size = size; | 811 | uc->file_size = size; |
810 | uc->client_info = cctx; | 812 | uc->client_info = cctx; |
811 | GNUNET_FS_unindex_sync_ (uc); | 813 | GNUNET_FS_unindex_sync_(uc); |
812 | pi.status = GNUNET_FS_STATUS_UNINDEX_START; | 814 | pi.status = GNUNET_FS_STATUS_UNINDEX_START; |
813 | pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL; | 815 | pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL; |
814 | GNUNET_FS_unindex_make_status_ (&pi, uc, 0); | 816 | GNUNET_FS_unindex_make_status_(&pi, uc, 0); |
815 | uc->fhc = | 817 | uc->fhc = |
816 | GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, | 818 | GNUNET_CRYPTO_hash_file(GNUNET_SCHEDULER_PRIORITY_IDLE, |
817 | filename, | 819 | filename, |
818 | HASHING_BLOCKSIZE, | 820 | HASHING_BLOCKSIZE, |
819 | &GNUNET_FS_unindex_process_hash_, uc); | 821 | &GNUNET_FS_unindex_process_hash_, uc); |
820 | uc->top = GNUNET_FS_make_top (h, | 822 | uc->top = GNUNET_FS_make_top(h, |
821 | &GNUNET_FS_unindex_signal_suspend_, | 823 | &GNUNET_FS_unindex_signal_suspend_, |
822 | uc); | 824 | uc); |
823 | return uc; | 825 | return uc; |
824 | } | 826 | } |
825 | 827 | ||
@@ -830,67 +832,67 @@ GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h, | |||
830 | * @param uc handle | 832 | * @param uc handle |
831 | */ | 833 | */ |
832 | void | 834 | void |
833 | GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc) | 835 | GNUNET_FS_unindex_stop(struct GNUNET_FS_UnindexContext *uc) |
834 | { | 836 | { |
835 | struct GNUNET_FS_ProgressInfo pi; | 837 | struct GNUNET_FS_ProgressInfo pi; |
836 | 838 | ||
837 | if (NULL != uc->dscan) | 839 | if (NULL != uc->dscan) |
838 | { | 840 | { |
839 | GNUNET_FS_directory_scan_abort (uc->dscan); | 841 | GNUNET_FS_directory_scan_abort(uc->dscan); |
840 | uc->dscan = NULL; | 842 | uc->dscan = NULL; |
841 | } | 843 | } |
842 | if (NULL != uc->dqe) | 844 | if (NULL != uc->dqe) |
843 | { | 845 | { |
844 | GNUNET_DATASTORE_cancel (uc->dqe); | 846 | GNUNET_DATASTORE_cancel(uc->dqe); |
845 | uc->dqe = NULL; | 847 | uc->dqe = NULL; |
846 | } | 848 | } |
847 | if (NULL != uc->fhc) | 849 | if (NULL != uc->fhc) |
848 | { | 850 | { |
849 | GNUNET_CRYPTO_hash_file_cancel (uc->fhc); | 851 | GNUNET_CRYPTO_hash_file_cancel(uc->fhc); |
850 | uc->fhc = NULL; | 852 | uc->fhc = NULL; |
851 | } | 853 | } |
852 | if (NULL != uc->mq) | 854 | if (NULL != uc->mq) |
853 | { | 855 | { |
854 | GNUNET_MQ_destroy (uc->mq); | 856 | GNUNET_MQ_destroy(uc->mq); |
855 | uc->mq = NULL; | 857 | uc->mq = NULL; |
856 | } | 858 | } |
857 | if (NULL != uc->dsh) | 859 | if (NULL != uc->dsh) |
858 | { | 860 | { |
859 | GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO); | 861 | GNUNET_DATASTORE_disconnect(uc->dsh, GNUNET_NO); |
860 | uc->dsh = NULL; | 862 | uc->dsh = NULL; |
861 | } | 863 | } |
862 | if (NULL != uc->ksk_uri) | 864 | if (NULL != uc->ksk_uri) |
863 | { | 865 | { |
864 | GNUNET_FS_uri_destroy (uc->ksk_uri); | 866 | GNUNET_FS_uri_destroy(uc->ksk_uri); |
865 | uc->ksk_uri = NULL; | 867 | uc->ksk_uri = NULL; |
866 | } | 868 | } |
867 | if (NULL != uc->tc) | 869 | if (NULL != uc->tc) |
868 | { | 870 | { |
869 | GNUNET_FS_tree_encoder_finish (uc->tc, NULL); | 871 | GNUNET_FS_tree_encoder_finish(uc->tc, NULL); |
870 | uc->tc = NULL; | 872 | uc->tc = NULL; |
871 | } | 873 | } |
872 | if (uc->fh != NULL) | 874 | if (uc->fh != NULL) |
873 | { | 875 | { |
874 | GNUNET_DISK_file_close (uc->fh); | 876 | GNUNET_DISK_file_close(uc->fh); |
875 | uc->fh = NULL; | 877 | uc->fh = NULL; |
876 | } | 878 | } |
877 | GNUNET_FS_end_top (uc->h, uc->top); | 879 | GNUNET_FS_end_top(uc->h, uc->top); |
878 | if (uc->serialization != NULL) | 880 | if (uc->serialization != NULL) |
879 | { | 881 | { |
880 | GNUNET_FS_remove_sync_file_ (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, | 882 | GNUNET_FS_remove_sync_file_(uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, |
881 | uc->serialization); | 883 | uc->serialization); |
882 | GNUNET_free (uc->serialization); | 884 | GNUNET_free(uc->serialization); |
883 | uc->serialization = NULL; | 885 | uc->serialization = NULL; |
884 | } | 886 | } |
885 | pi.status = GNUNET_FS_STATUS_UNINDEX_STOPPED; | 887 | pi.status = GNUNET_FS_STATUS_UNINDEX_STOPPED; |
886 | pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO; | 888 | pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO; |
887 | GNUNET_FS_unindex_make_status_ (&pi, uc, | 889 | GNUNET_FS_unindex_make_status_(&pi, uc, |
888 | (uc->state == | 890 | (uc->state == |
889 | UNINDEX_STATE_COMPLETE) ? uc->file_size : 0); | 891 | UNINDEX_STATE_COMPLETE) ? uc->file_size : 0); |
890 | GNUNET_break (NULL == uc->client_info); | 892 | GNUNET_break(NULL == uc->client_info); |
891 | GNUNET_free_non_null (uc->emsg); | 893 | GNUNET_free_non_null(uc->emsg); |
892 | GNUNET_free (uc->filename); | 894 | GNUNET_free(uc->filename); |
893 | GNUNET_free (uc); | 895 | GNUNET_free(uc); |
894 | } | 896 | } |
895 | 897 | ||
896 | /* end of fs_unindex.c */ | 898 | /* end of fs_unindex.c */ |