struct GNUNET_BIO_ReadHandle *rh;
char *emsg;
- rh = get_read_handle (h, "publish-fi", filename);
+ rh = get_read_handle (h, GNUNET_FS_SYNC_PATH_FILE_INFO, filename);
if (rh == NULL)
return NULL;
ret = deserialize_fi_node (h, filename, rh);
char *chks;
if (NULL == fi->serialization)
- fi->serialization = make_serialization_file_name (fi->h, "publish-fi");
+ fi->serialization = make_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO);
if (NULL == fi->serialization)
return;
- wh = get_write_handle (fi->h, "publish-fi", fi->serialization);
+ wh = get_write_handle (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, fi->serialization);
if (wh == NULL)
{
GNUNET_free (fi->serialization);
(void) GNUNET_BIO_write_close (wh);
GNUNET_free_non_null (chks);
GNUNET_free_non_null (ksks);
- fn = get_serialization_file_name (fi->h, "publish-fi", fi->serialization);
+ fn = get_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, fi->serialization);
if (0 != UNLINK (fn))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
GNUNET_free (fn);
}
if (pc->fi != NULL)
GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL);
- if (pc->serialization != NULL)
- GNUNET_FS_remove_sync_file_ (h, "publish", pc->serialization);
+ if (0 != UNLINK (filename))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
GNUNET_free_non_null (pc->serialization);
GNUNET_free (pc);
return GNUNET_OK;
if (NULL == pc->serialization)
pc->serialization = make_serialization_file_name (pc->h,
- "publish");
+ GNUNET_FS_SYNC_PATH_MASTER_PUBLISH);
if (NULL == pc->serialization)
return;
if (NULL == pc->fi)
GNUNET_break (0);
return;
}
- wh = get_write_handle (pc->h, "publish", pc->serialization);
+ wh = get_write_handle (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, pc->serialization);
if ( (GNUNET_OK !=
GNUNET_BIO_write_string (wh, pc->nid)) ||
(GNUNET_OK !=
(GNUNET_OK !=
GNUNET_BIO_write_string (wh, (pc->namespace == NULL) ? NULL : pc->namespace->name)) )
{
- (void) GNUNET_BIO_write_close (wh);
- GNUNET_FS_remove_sync_file_ (pc->h, "publish", pc->serialization);
- GNUNET_free (pc->serialization);
- pc->serialization = NULL;
- return;
+ goto cleanup;
}
if (GNUNET_OK !=
GNUNET_BIO_write_close (wh))
{
- GNUNET_FS_remove_sync_file_ (pc->h, "publish", pc->serialization);
- GNUNET_free (pc->serialization);
- pc->serialization = NULL;
- return;
- }
+ wh = NULL;
+ goto cleanup;
+ }
+ return;
+ cleanup:
+ if (wh != NULL)
+ (void) GNUNET_BIO_write_close (wh);
+ GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, pc->serialization);
+ GNUNET_free (pc->serialization);
+ pc->serialization = NULL;
}
return;
if (NULL == uc->serialization)
uc->serialization = make_serialization_file_name (uc->h,
- "unindex");
+ GNUNET_FS_SYNC_PATH_MASTER_UNINDEX);
if (NULL == uc->serialization)
return;
- wh = get_write_handle (uc->h, "unindex", uc->serialization);
+ wh = get_write_handle (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, uc->serialization);
if ( (GNUNET_OK !=
GNUNET_BIO_write_string (wh, uc->filename)) ||
(GNUNET_OK !=
( (uc->state == UNINDEX_STATE_ERROR) &&
(GNUNET_OK !=
GNUNET_BIO_write_string (wh, uc->emsg)) ) )
- {
- (void) GNUNET_BIO_write_close (wh);
- GNUNET_FS_remove_sync_file_ (uc->h, "publish", uc->serialization);
- GNUNET_free (uc->serialization);
- uc->serialization = NULL;
- return;
- }
+ goto cleanup;
if (GNUNET_OK !=
GNUNET_BIO_write_close (wh))
{
- GNUNET_FS_remove_sync_file_ (uc->h, "unindex", uc->serialization);
- GNUNET_free (uc->serialization);
- uc->serialization = NULL;
- return;
+ wh = NULL;
+ goto cleanup;
}
+ return;
+ cleanup:
+ if (wh != NULL)
+ (void) GNUNET_BIO_write_close (wh);
+ GNUNET_FS_remove_sync_file_ (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, uc->serialization);
+ GNUNET_free (uc->serialization);
+ uc->serialization = NULL;
}
GNUNET_snprintf (pbuf,
sizeof (pbuf),
"%s%s%s",
- "subdownloads",
+ GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD,
DIR_SEPARATOR_STR,
dc->parent->serialization);
category = pbuf;
}
else
{
- category = "download";
+ category = GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD;
}
if (NULL == dc->serialization)
dc->serialization = make_serialization_file_name (dc->h,
uris = NULL;
if (NULL == sr->serialization)
sr->serialization = make_serialization_file_name (sr->sc->h,
- "search-results");
+ GNUNET_FS_SYNC_PATH_SEARCH_RESULT);
if (NULL == sr->serialization)
return;
- wh = get_write_handle (sr->sc->h, "search-results", sr->serialization);
+ wh = get_write_handle (sr->sc->h, GNUNET_FS_SYNC_PATH_SEARCH_RESULT, sr->serialization);
uris = GNUNET_FS_uri_to_string (sr->uri);
if ( (GNUNET_OK !=
GNUNET_BIO_write_string (wh, uris)) ||
GNUNET_free_non_null (uris);
if (wh != NULL)
(void) GNUNET_BIO_write_close (wh);
- GNUNET_FS_remove_sync_file_ (sr->sc->h, "search-results", sr->serialization);
+ GNUNET_FS_remove_sync_file_ (sr->sc->h, GNUNET_FS_SYNC_PATH_SEARCH_RESULT, sr->serialization);
GNUNET_free (sr->serialization);
sr->serialization = NULL;
}
struct GNUNET_FS_SearchContext *scc;
char *uris;
char in_pause;
+ const char *category;
+
+ category = (sc->parent == NULL) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH : GNUNET_FS_SYNC_PATH_CHILD_SEARCH;
if (NULL == sc->serialization)
sc->serialization = make_serialization_file_name (sc->h,
- "search");
+ category);
if (NULL == sc->serialization)
return;
- wh = get_write_handle (sc->h, "search", sc->serialization);
+ wh = get_write_handle (sc->h, category, sc->serialization);
GNUNET_assert ( (GNUNET_YES == GNUNET_FS_uri_test_ksk (sc->uri)) ||
(GNUNET_YES == GNUNET_FS_uri_test_sks (sc->uri)) );
uris = GNUNET_FS_uri_to_string (sc->uri);
if (wh != NULL)
(void) GNUNET_BIO_write_close (wh);
GNUNET_free_non_null (uris);
- GNUNET_FS_remove_sync_file_ (sc->h, "search", sc->serialization);
+ GNUNET_FS_remove_sync_file_ (sc->h, category, sc->serialization);
GNUNET_free (sc->serialization);
sc->serialization = NULL;
}
{
char *dn;
- dn = get_serialization_file_name (h, "publish", "");
+ dn = get_serialization_file_name (h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, "");
if (dn == NULL)
return;
GNUNET_DISK_directory_scan (dn, &deserialize_publish_file, h);
GNUNET_free (emsg);
}
if (uc->serialization != NULL)
- GNUNET_FS_remove_sync_file_ (h, "unindex", uc->serialization);
+ GNUNET_FS_remove_sync_file_ (h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, uc->serialization);
GNUNET_free_non_null (uc->serialization);
GNUNET_free (uc);
return GNUNET_OK;
{
char *dn;
- dn = get_serialization_file_name (h, "unindex", "");
+ dn = get_serialization_file_name (h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, "");
if (dn == NULL)
return;
GNUNET_DISK_directory_scan (dn, &deserialize_unindex_file, h);
GNUNET_snprintf (pbuf,
sizeof (pbuf),
"%s%s%s",
- "search-results",
+ GNUNET_FS_SYNC_PATH_SEARCH_RESULT,
DIR_SEPARATOR_STR,
sc->serialization);
GNUNET_FS_remove_sync_file_ (sc->h, pbuf, ser);
if (download != NULL)
{
drh = get_read_handle (sc->h,
- "subdownloads",
+ GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD,
download);
deserialize_download (sc->h,
drh,
}
GNUNET_free_non_null (sc->emsg);
if (sc->serialization != NULL)
- GNUNET_FS_remove_sync_file_ (sc->h, "search", sc->serialization);
+ GNUNET_FS_remove_sync_file_ (sc->h, GNUNET_FS_SYNC_PATH_MASTER_SEARCH, sc->serialization);
/* FIXME: remove 'pbuf' directory with search results as well! */
GNUNET_free_non_null (sc->serialization);
if (sc->uri != NULL)
GNUNET_snprintf (pbuf,
sizeof (pbuf),
"%s%s%s",
- "subdownloads",
+ GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD,
DIR_SEPARATOR_STR,
dc->serialization);
dn = get_serialization_file_name (h, pbuf, "");
GNUNET_snprintf (pbuf,
sizeof (pbuf),
"%s%s%s",
- "search-results",
+ GNUNET_FS_SYNC_PATH_SEARCH_RESULT,
DIR_SEPARATOR_STR,
sc->serialization);
dn = get_serialization_file_name (h, pbuf, "");
goto cleanup;
if (child_ser == NULL)
break;
- rhc = get_read_handle (h, "search-children", child_ser);
+ rhc = get_read_handle (h, GNUNET_FS_SYNC_PATH_CHILD_SEARCH, child_ser);
if (rhc != NULL)
{
scc = deserialize_search (h, rhc, sc, child_ser);
{
if (ser != NULL)
{
- GNUNET_FS_remove_sync_file_ (h, "search", ser);
+ GNUNET_FS_remove_sync_file_ (h, GNUNET_FS_SYNC_PATH_MASTER_SEARCH, ser);
GNUNET_free (ser);
}
return GNUNET_OK;
{
char *dn;
- dn = get_serialization_file_name (h, "search", "");
+ dn = get_serialization_file_name (h, GNUNET_FS_SYNC_PATH_MASTER_SEARCH, "");
if (dn == NULL)
return;
GNUNET_DISK_directory_scan (dn, &deserialize_search_file, h);
{
char *dn;
- dn = get_serialization_file_name (h, "download", "");
+ dn = get_serialization_file_name (h, GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, "");
if (dn == NULL)
return;
GNUNET_DISK_directory_scan (dn, &deserialize_download_file, h);
...)
{
struct GNUNET_FS_Handle *ret;
- struct GNUNET_CLIENT_Connection *client;
enum GNUNET_FS_OPTIONS opt;
va_list ap;
- client = GNUNET_CLIENT_connect (sched,
- "fs",
- cfg);
- if (NULL == client)
- return NULL;
ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Handle));
ret->sched = sched;
ret->cfg = cfg;
ret->client_name = GNUNET_strdup (client_name);
ret->upcb = upcb;
ret->upcb_cls = upcb_cls;
- ret->client = client;
ret->flags = flags;
ret->max_parallel_downloads = 1;
ret->max_parallel_requests = 1;
}
}
va_end (ap);
- // FIXME: setup receive-loop with client (do we need one?)
if (0 != (GNUNET_FS_FLAGS_PERSISTENCE & flags))
{
/* FIXME: could write one generic deserialization
/* generate SUSPEND events and clean up state */
while (h->top_head != NULL)
h->top_head->ssf (h->top_head->ssf_cls);
- // FIXME: terminate receive-loop with client (do we need one?)
+ /* FIXME: terminate receive-loop with client (do we need one?) */
if (h->queue_job != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (h->sched,
h->queue_job);
- GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
GNUNET_free (h->client_name);
GNUNET_free (h);
}
* @author Christian Grothoff
*
* TODO:
- * - remove *directory* with search results upon completion
* - centralize code that sprintf's the 'pbuf[32]' strings
* - add support for pushing "already seen" information
* to FS service for bloomfilter (can wait)
#define DEBUG_SEARCH GNUNET_NO
-
-
/**
* Fill in all of the generic fields for a search event and
* call the callback.
uu.type = sks;
uu.data.sks.namespace = sc->uri->data.sks.namespace;
uu.data.sks.identifier = GNUNET_strdup (id_update);
- /* FIXME: should attach update search
- to the individual result, not
+ /* FIXME: should attach update search to the individual result, not
the entire SKS search! */
search_start (sc->h,
&uu,
sm[i].type = htonl (GNUNET_BLOCK_TYPE_ANY);
sm[i].anonymity_level = htonl (sc->anonymity);
sm[i].query = sc->requests[i].query;
+ /* FIXME: should transmit hash codes of all already-known results here!
+ (and if they do not fit, add another message with the same
+ header and additional already-seen results!) */
}
}
else
GNUNET_CRYPTO_hash_xor (&idh,
&sm->target,
&sm->query);
+ /* FIXME: should transmit hash codes of all already-known results here!
+ (and if they do not fit, add another message with the same
+ header and additional already-seen results!) */
}
GNUNET_CLIENT_receive (sc->client,
&receive_results,
}
+/**
+ * Freeze probes for the given search result.
+ *
+ * @param cls the global FS handle
+ * @param key the key for the search result (unused)
+ * @param value the search result to free
+ * @return GNUNET_OK
+ */
+static int
+search_result_freeze_probes (void *cls,
+ const GNUNET_HashCode * key,
+ void *value)
+{
+ struct GNUNET_FS_SearchContext *sc = cls;
+ struct GNUNET_FS_Handle *h = sc->h;
+ struct GNUNET_FS_SearchResult *sr = value;
+
+ if (sr->probe_ctx != NULL)
+ {
+ GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES);
+ sr->probe_ctx = NULL;
+ }
+ if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (h->sched,
+ sr->probe_cancel_task);
+ sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * Resume probes for the given search result.
+ *
+ * @param cls the global FS handle
+ * @param key the key for the search result (unused)
+ * @param value the search result to free
+ * @return GNUNET_OK
+ */
+static int
+search_result_resume_probes (void *cls,
+ const GNUNET_HashCode * key,
+ void *value)
+{
+ struct GNUNET_FS_SearchResult *sr = value;
+
+ GNUNET_FS_search_start_probe_ (sr);
+ return GNUNET_OK;
+}
+
/**
* Signal suspend and free the given search result.
GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO);
sc->client = NULL;
GNUNET_FS_search_sync_ (sc);
- // FIXME: should this freeze all active probes?
+ GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
+ &search_result_freeze_probes,
+ sc);
pi.status = GNUNET_FS_STATUS_SEARCH_PAUSED;
sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
}
GNUNET_FS_search_sync_ (sc);
pi.status = GNUNET_FS_STATUS_SEARCH_CONTINUED;
sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
+ GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
+ &search_result_resume_probes,
+ sc);
}
if (NULL != sr->download)
{
sr->download->search = NULL;
+ if (NULL != sr->download->serialization)
+ {
+ GNUNET_FS_remove_sync_file_ (sc->h,
+ GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD,
+ sr->download->serialization);
+ GNUNET_free (sr->download->serialization);
+ sr->download->serialization = NULL;
+ }
pi.status = GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT;
GNUNET_FS_download_make_status_ (&pi,
- sr->download);
- /* FIXME: promote download to top-level! */
+ sr->download);
+ GNUNET_FS_download_sync_ (sr->download);
sr->download = NULL;
}
pi.status = GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED;
GNUNET_snprintf (pbuf,
sizeof (pbuf),
"%s%s%s",
- "search-results",
+ GNUNET_FS_SYNC_PATH_SEARCH_RESULT,
DIR_SEPARATOR_STR,
sc->serialization);
GNUNET_FS_remove_sync_file_ (sc->h,
GNUNET_FS_end_top (sc->h, sc->top);
if (sc->serialization != NULL)
GNUNET_FS_remove_sync_file_ (sc->h,
- (sc->parent != NULL) ? "search-children" : "search",
+ (sc->parent != NULL)
+ ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH
+ : GNUNET_FS_SYNC_PATH_MASTER_SEARCH,
sc->serialization);
if (NULL != (parent = sc->parent))
{
&search_result_free,
sc);
if (had_result)
- GNUNET_FS_remove_sync_dir_ (sc->h, "search-results", sc->serialization);
+ GNUNET_FS_remove_sync_dir_ (sc->h,
+ GNUNET_FS_SYNC_PATH_SEARCH_RESULT,
+ sc->serialization);
pi.status = GNUNET_FS_STATUS_SEARCH_STOPPED;
sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
GNUNET_break (NULL == sc->client_info);