aboutsummaryrefslogtreecommitdiff
path: root/src/fs/fs_unindex.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-05-26 19:55:24 +0000
committerChristian Grothoff <christian@grothoff.org>2010-05-26 19:55:24 +0000
commitd0e25cca5eb56a18bd4feddcb4235aff09131a80 (patch)
treef85aa9dacc43f4528daf7c417b61e2506700df83 /src/fs/fs_unindex.c
parent95c050064311c6153a5312da89d3a076617141b5 (diff)
downloadgnunet-d0e25cca5eb56a18bd4feddcb4235aff09131a80.tar.gz
gnunet-d0e25cca5eb56a18bd4feddcb4235aff09131a80.zip
change unindex processing order to avoid transient dangling DB entries
Diffstat (limited to 'src/fs/fs_unindex.c')
-rw-r--r--src/fs/fs_unindex.c115
1 files changed, 53 insertions, 62 deletions
diff --git a/src/fs/fs_unindex.c b/src/fs/fs_unindex.c
index 220ec5870..b69610409 100644
--- a/src/fs/fs_unindex.c
+++ b/src/fs/fs_unindex.c
@@ -226,49 +226,6 @@ unindex_process (void *cls,
226 226
227 227
228/** 228/**
229 * Function called when the tree encoder has
230 * processed all blocks. Clean up.
231 *
232 * @param cls our unindexing context
233 * @param tc not used
234 */
235static void
236unindex_finish (void *cls,
237 const struct GNUNET_SCHEDULER_TaskContext *tc)
238{
239 struct GNUNET_FS_UnindexContext *uc = cls;
240 char *emsg;
241 struct GNUNET_FS_Uri *uri;
242 struct GNUNET_FS_ProgressInfo pi;
243
244 GNUNET_FS_tree_encoder_finish (uc->tc,
245 &uri,
246 &emsg);
247 uc->tc = NULL;
248 if (uri != NULL)
249 GNUNET_FS_uri_destroy (uri);
250 GNUNET_DISK_file_close (uc->fh);
251 uc->fh = NULL;
252 GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO);
253 uc->dsh = NULL;
254 if (emsg != NULL)
255 {
256 uc->state = UNINDEX_STATE_ERROR;
257 uc->emsg = emsg;
258 signal_unindex_error (uc);
259 }
260 else
261 {
262 uc->state = UNINDEX_STATE_COMPLETE;
263 pi.status = GNUNET_FS_STATUS_UNINDEX_COMPLETED;
264 pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO;
265 GNUNET_FS_unindex_make_status_ (&pi, uc, uc->file_size);
266 }
267 GNUNET_FS_unindex_sync_ (uc);
268}
269
270
271/**
272 * Function called with the response from the 229 * Function called with the response from the
273 * FS service to our unindexing request. 230 * FS service to our unindexing request.
274 * 231 *
@@ -280,6 +237,7 @@ process_fs_response (void *cls,
280 const struct GNUNET_MessageHeader *msg) 237 const struct GNUNET_MessageHeader *msg)
281{ 238{
282 struct GNUNET_FS_UnindexContext *uc = cls; 239 struct GNUNET_FS_UnindexContext *uc = cls;
240 struct GNUNET_FS_ProgressInfo pi;
283 241
284 if (uc->client != NULL) 242 if (uc->client != NULL)
285 { 243 {
@@ -291,7 +249,7 @@ process_fs_response (void *cls,
291 uc->state = UNINDEX_STATE_ERROR; 249 uc->state = UNINDEX_STATE_ERROR;
292 uc->emsg = GNUNET_strdup (_("Unexpected time for a response from `fs' service.")); 250 uc->emsg = GNUNET_strdup (_("Unexpected time for a response from `fs' service."));
293 GNUNET_FS_unindex_sync_ (uc); 251 GNUNET_FS_unindex_sync_ (uc);
294 signal_unindex_error (uc); 252 signal_unindex_error (uc);
295 return; 253 return;
296 } 254 }
297 if (NULL == msg) 255 if (NULL == msg)
@@ -310,9 +268,56 @@ process_fs_response (void *cls,
310 signal_unindex_error (uc); 268 signal_unindex_error (uc);
311 return; 269 return;
312 } 270 }
313 uc->state = UNINDEX_STATE_DS_REMOVE; 271 uc->state = UNINDEX_STATE_COMPLETE;
272 pi.status = GNUNET_FS_STATUS_UNINDEX_COMPLETED;
273 pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO;
314 GNUNET_FS_unindex_sync_ (uc); 274 GNUNET_FS_unindex_sync_ (uc);
315 GNUNET_FS_unindex_do_remove_ (uc); 275 GNUNET_FS_unindex_make_status_ (&pi, uc, uc->file_size);
276}
277
278
279/**
280 * Function called when the tree encoder has
281 * processed all blocks. Clean up.
282 *
283 * @param cls our unindexing context
284 * @param tc not used
285 */
286static void
287unindex_finish (void *cls,
288 const struct GNUNET_SCHEDULER_TaskContext *tc)
289{
290 struct GNUNET_FS_UnindexContext *uc = cls;
291 char *emsg;
292 struct GNUNET_FS_Uri *uri;
293 struct UnindexMessage req;
294
295 GNUNET_FS_tree_encoder_finish (uc->tc,
296 &uri,
297 &emsg);
298 uc->tc = NULL;
299 if (uri != NULL)
300 GNUNET_FS_uri_destroy (uri);
301 GNUNET_DISK_file_close (uc->fh);
302 uc->fh = NULL;
303 GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO);
304 uc->dsh = NULL;
305 uc->state = UNINDEX_STATE_FS_NOTIFY;
306 GNUNET_FS_unindex_sync_ (uc);
307 uc->client = GNUNET_CLIENT_connect (uc->h->sched,
308 "fs",
309 uc->h->cfg);
310 req.header.size = htons (sizeof (struct UnindexMessage));
311 req.header.type = htons (GNUNET_MESSAGE_TYPE_FS_UNINDEX);
312 req.reserved = 0;
313 req.file_id = uc->file_id;
314 GNUNET_break (GNUNET_OK ==
315 GNUNET_CLIENT_transmit_and_get_response (uc->client,
316 &req.header,
317 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
318 GNUNET_YES,
319 &process_fs_response,
320 uc));
316} 321}
317 322
318 323
@@ -370,7 +375,6 @@ GNUNET_FS_unindex_process_hash_ (void *cls,
370 const GNUNET_HashCode *file_id) 375 const GNUNET_HashCode *file_id)
371{ 376{
372 struct GNUNET_FS_UnindexContext *uc = cls; 377 struct GNUNET_FS_UnindexContext *uc = cls;
373 struct UnindexMessage req;
374 378
375 uc->fhc = NULL; 379 uc->fhc = NULL;
376 if (uc->state != UNINDEX_STATE_HASHING) 380 if (uc->state != UNINDEX_STATE_HASHING)
@@ -387,22 +391,9 @@ GNUNET_FS_unindex_process_hash_ (void *cls,
387 return; 391 return;
388 } 392 }
389 uc->file_id = *file_id; 393 uc->file_id = *file_id;
390 uc->state = UNINDEX_STATE_FS_NOTIFY; 394 uc->state = UNINDEX_STATE_DS_REMOVE;
391 GNUNET_FS_unindex_sync_ (uc); 395 GNUNET_FS_unindex_sync_ (uc);
392 uc->client = GNUNET_CLIENT_connect (uc->h->sched, 396 GNUNET_FS_unindex_do_remove_ (uc);
393 "fs",
394 uc->h->cfg);
395 req.header.size = htons (sizeof (struct UnindexMessage));
396 req.header.type = htons (GNUNET_MESSAGE_TYPE_FS_UNINDEX);
397 req.reserved = 0;
398 req.file_id = *file_id;
399 GNUNET_break (GNUNET_OK ==
400 GNUNET_CLIENT_transmit_and_get_response (uc->client,
401 &req.header,
402 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
403 GNUNET_YES,
404 &process_fs_response,
405 uc));
406} 397}
407 398
408 399