#include "share.h"
#include "if/core/fileinfo.h"
Go to the source code of this file.
Defines | |
#define | FI_LOW_SRC_COUNT 5 /**< Few sources known if beneath */ |
Few sources known if beneath. | |
#define | FI_F_SUSPEND 0x00000001U /**< Marked "suspended" new downloads */ |
Marked "suspended" new downloads. | |
#define | FI_F_DISCARD 0x00000002U /**< Discard fileinfo if refcount = 0 */ |
Discard fileinfo if refcount = 0. | |
#define | FI_F_TRANSIENT 0x40000000U /**< Don't persist to disk */ |
Don't persist to disk. | |
#define | FI_F_MARK 0x80000000U /**< Marked during traversal */ |
Marked during traversal. | |
Functions | |
void | file_info_init (void) |
Initialize fileinfo handling. | |
void | file_info_init_post (void) |
Finish initialization of fileinfo handling. | |
void | file_info_scandir (const gchar *dir) |
Scan the given directory for files, looking at those bearing a valid fileinfo trailer, yet which we know nothing about. | |
gboolean | file_info_has_trailer (const gchar *path) |
Check whether file has a trailer. | |
void | file_info_retrieve (void) |
Loads the fileinfo database from disk, and saves a copy in fileinfo.orig. | |
void | file_info_store (void) |
Stores the list of output files and their metainfo to the configdir/fileinfo database. | |
void | file_info_store_binary (fileinfo_t *fi) |
Store a binary record of the file metainformation at the end of the output file, if it exists. | |
void | file_info_store_if_dirty (void) |
Store global file information cache if dirty. | |
void | file_info_set_discard (fileinfo_t *fi, gboolean state) |
Set or clear the discard state for a fileinfo. | |
enum dl_chunk_status | file_info_find_hole (struct download *d, filesize_t *from, filesize_t *to) |
Finds a range to download, and stores it in *from and *to. | |
gboolean | file_info_find_available_hole (struct download *d, GSList *ranges, filesize_t *from, filesize_t *to) |
Find free chunk that also fully belongs to the `ranges' list. | |
void | file_info_merge_adjacent (fileinfo_t *fi) |
Go through the chunk list and merge adjacent chunks that share the same status and download. | |
void | file_info_clear_download (struct download *d, gboolean lifecount) |
Go through all chunks that belong to the download, and unmark them as busy. | |
enum dl_chunk_status | file_info_chunk_status (fileinfo_t *fi, filesize_t from, filesize_t to) |
void | file_info_reset (fileinfo_t *fi) |
Reset all chunks to EMPTY, clear computed SHA1 if any. | |
void | file_info_recreate (struct download *d) |
fileinfo_t * | file_info_get (gchar *file, const gchar *path, filesize_t size, gchar *sha1, gboolean file_size_known) |
void | file_info_strip_binary (fileinfo_t *fi) |
Strips the file metainfo trailer off a file. | |
void | file_info_strip_binary_from_file (fileinfo_t *fi, const gchar *file) |
Strips the file metainfo trailer off specified file. | |
gboolean | file_info_got_sha1 (fileinfo_t *fi, const gchar *sha1) |
Called when we discover the SHA1 of a running download. | |
void | file_info_size_known (struct download *d, filesize_t size) |
Signals that file size became known suddenly. | |
void | file_info_update (struct download *d, filesize_t from, filesize_t to, enum dl_chunk_status status) |
Marks a chunk of the file with given status. | |
enum dl_chunk_status | file_info_pos_status (fileinfo_t *fi, filesize_t pos) |
void | file_info_close (void) |
Close and free all file_info structs in the list. | |
void | file_info_close_pre (void) |
Pre-close some file_info information. | |
void | file_info_try_to_swarm_with (gchar *file_name, guint32 idx, const host_addr_t addr, guint16 port, gchar *sha1) |
Called when we add something to the dmesh. | |
void | file_info_spot_completed_orphans (void) |
Look through all the known fileinfo structures, looking for orphaned files that are complete. | |
void | file_info_add_source (fileinfo_t *fi, struct download *dl) |
Add download source for the file, but preserve original "ntime". | |
void | file_info_add_new_source (fileinfo_t *fi, struct download *dl) |
Add new download source for the file. | |
void | file_info_remove_source (fileinfo_t *fi, struct download *dl, gboolean discard) |
Removing one source reference from the fileinfo. | |
void | file_info_timer (void) |
void | file_info_unlink (fileinfo_t *fi) |
Unlink file from disk. | |
void | file_info_upload_stop (fileinfo_t *fi, const gchar *reason) |
Stop all sharing occuring for this fileinfo. | |
void | file_info_changed (fileinfo_t *fi) |
Signals that some information in the fileinfo has changed, warranting a display update in the GUI. | |
shared_file_t * | file_info_shared_sha1 (const gchar *sha1) |
Look whether we have a partially downloaded file bearing the given SHA1. | |
gint | file_info_available_ranges (fileinfo_t *fi, gchar *buf, gint size) |
Emit an X-Available-Ranges header listing the ranges within the file that we have on disk and we can share as a PFSP-server. | |
gboolean | file_info_restrict_range (fileinfo_t *fi, filesize_t start, filesize_t *end) |
Given a request range `start' (included) and `end' (included) for the partially downloaded file represented by `fi', see whether we can satisfy it, even partially, without touching `start' but only only by possibly moving `end' down. | |
fileinfo_t * | file_info_has_identical (gchar *file, filesize_t size, gchar *sha1) |
fileinfo_t * | file_info_get_browse (const gchar *name) |
Create a transient fileinfo structure to be perused by browse host. | |
void | file_info_remove (fileinfo_t *fi) |
Remove non-referenced fileinfo and reclaim its data structures. | |
G_GNUC_CONST WARN_UNUSED_RESULT guint32 | fi_alive_count (fileinfo_t *fi) |
Return amount of currently active sources. |
|
Discard fileinfo if refcount = 0.
|
|
Marked during traversal.
|
|
Marked "suspended" new downloads.
|
|
Don't persist to disk.
|
|
Few sources known if beneath.
|
|
Return amount of currently active sources.
|
|
Add new download source for the file.
|
|
Add download source for the file, but preserve original "ntime".
|
|
Emit an X-Available-Ranges header listing the ranges within the file that we have on disk and we can share as a PFSP-server. The header is emitted in `buf', which is `size' bytes long. If there is not enough room to emit all the ranges, emit a random subset of the ranges.
|
|
Signals that some information in the fileinfo has changed, warranting a display update in the GUI.
|
|
|
|
Go through all chunks that belong to the download, and unmark them as busy. If `lifecount' is TRUE, the download is still counted as being "alive", and this is only used for assertions. < For assertions only |
|
Close and free all file_info structs in the list.
|
|
Pre-close some file_info information. This should be separate from file_info_close so that we can avoid circular dependencies with other close routines, in this case with download_close. |
|
Find free chunk that also fully belongs to the `ranges' list. If found, the returned chunk is marked BUSY and linked to the download `d'.
|
|
Finds a range to download, and stores it in *from and *to. If "aggressive" is off, it will return only ranges that are EMPTY. If on, and no EMPTY ranges are available, it will grab a chunk out of the longest BUSY chunk instead, and "compete" with the download that reserved it. |
|
|
|
Create a transient fileinfo structure to be perused by browse host.
|
|
Called when we discover the SHA1 of a running download. Make sure there is no other entry already bearing that SHA1, and record the information.
|
|
|
|
Check whether file has a trailer.
|
|
Initialize fileinfo handling.
|
|
Finish initialization of fileinfo handling. This post initialization is needed to avoid circular dependencies during the init phase. The listener we set up here is set up in download_init, but that must be called after file_info_init. |
|
Go through the chunk list and merge adjacent chunks that share the same status and download. Keeps the chunk list short and tidy. |
|
|
|
|
|
Remove non-referenced fileinfo and reclaim its data structures.
|
|
Removing one source reference from the fileinfo. When no sources reference the fileinfo structure, free it if `discard' is TRUE, or if the fileinfo has been marked with FI_F_DISCARD. This replaces file_info_free() |
|
Reset all chunks to EMPTY, clear computed SHA1 if any.
|
|
Given a request range `start' (included) and `end' (included) for the partially downloaded file represented by `fi', see whether we can satisfy it, even partially, without touching `start' but only only by possibly moving `end' down.
|
|
Loads the fileinfo database from disk, and saves a copy in fileinfo.orig.
|
|
Scan the given directory for files, looking at those bearing a valid fileinfo trailer, yet which we know nothing about.
|
|
Set or clear the discard state for a fileinfo.
|
|
Look whether we have a partially downloaded file bearing the given SHA1. If we do, return a "shared_file" structure suitable for uploading the parts of the file we have (will happen only when PFSP-server is enabled).
|
|
Signals that file size became known suddenly. The download becomes the owner of the "busy" part between what we have done and the end of the file. |
|
Look through all the known fileinfo structures, looking for orphaned files that are complete. A fake download is created for them, so that download_resume_bg_tasks() can pick them up. |
|
Stores the list of output files and their metainfo to the configdir/fileinfo database.
|
|
Store a binary record of the file metainformation at the end of the output file, if it exists.
|
|
Store global file information cache if dirty.
|
|
Strips the file metainfo trailer off a file.
|
|
Strips the file metainfo trailer off specified file.
|
|
|
|
Called when we add something to the dmesh. Add the corresponding file to the download list if we're swarming on it.
|
|
Unlink file from disk.
|
|
Marks a chunk of the file with given status. The bytes range from `from' (included) to `to' (excluded). When not marking the chunk as EMPTY, the range is linked to the supplied download `d' so we know who "owns" it currently. |
|
Stop all sharing occuring for this fileinfo.
|