Ejemplo n.º 1
0
/**
 * Dump the whole in-memory cache onto disk.
 */
static void
dump_cache(bool force)
{
	FILE *f;
	file_path_t fp;

	if (!force && !cache_dirty)
		return;
	
	file_path_set(&fp, settings_config_dir(), "sha1_cache");
	f = file_config_open_write("SHA-1 cache", &fp);
	if (f) {
		struct dump_cache_context ctx;
		
		fputs(sha1_persistent_cache_file_header, f);
		ctx.f = f;
		ctx.forced = force;
		hikset_foreach(sha1_cache, dump_cache_one_entry, &ctx);
		if (file_config_close(f, &fp)) {
			cache_dirty = FALSE;
		}
	}

	/*
	 * Update the timestamp even on failure to avoid that we retry this
	 * too frequently.
	 */
	cache_dumped = tm_time();
}
Ejemplo n.º 2
0
/**
 * Save upload statistics to file.
 */
static void
upload_stats_dump_history(void)
{
	FILE *out;
	file_path_t fp;

	/* open file for writing */
	file_path_set(&fp, settings_config_dir(), ul_stats_file);
	out = file_config_open_write(ul_stats_what, &fp);

	if (NULL == out)
		return;

	file_config_preamble(out, "Upload statistics");

	fputs(
		"#\n"
		"# Format is:\n"
		"#    File basename <TAB> size <TAB> attempts <TAB> completed\n"
		"#        <TAB> bytes_sent-high <TAB> bytes_sent-low\n"
		"#        <TAB> time of last request <TAB> time of last served chunk\n"
		"#        <TAB> SHA1 (\"*\" if unknown)\n"
		"#\n"
		"\n",
		out
	);

	/*
	 * Don't check this sooner so that the file is cleared, if the user
	 * cleared the history.
	 */
	if (upload_stats_list) {
		/* for each element in uploads_stats_list, write out to hist file */
		hash_list_foreach(upload_stats_list, upload_stats_dump_item, out);
	}

	file_config_close(out, &fp);
	dirty = FALSE;
}
Ejemplo n.º 3
0
/**
 * Store known GWC URLs.
 * They are normally saved in ~/.gtk-gnutella/gwcache.
 */
static void
gwc_store(void)
{
    FILE *out;
    int i;
    int j;
    file_path_t fp;

    file_path_set(&fp, settings_config_dir(), gwc_file);
    out = file_config_open_write(gwc_what, &fp);
    if (!out)
        return;

    file_config_preamble(out, "Gnutella web cache URLs");

    /*
     * Start dumping with the next slot we'll supersede, so that the oldest
     * entries are at the top: when the cache is full, we'll loop over at
     * retrieve time and will start superseding the oldest entries.
     */

    i = gwc_url_slot + 1;
    if (i >= MAX_GWC_URLS)
        i = 0;

    for (j = 0; j < MAX_GWC_URLS; j++) {
        const char *url = gwc_url[i].url;

        i = (i + 1) % MAX_GWC_URLS;
        if (url == NULL)
            continue;
        fprintf(out, "%s\n", url);
    }

    if (file_config_close(out, &fp))
        gwc_file_dirty = FALSE;
}