Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

fileinfo.h File Reference


Detailed Description

Structure for storing meta-information about files being downloaded.

Author:
Vidar Madsen
Date:
2002

#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_tfile_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_tfile_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_tfile_info_has_identical (gchar *file, filesize_t size, gchar *sha1)
fileinfo_tfile_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.


Define Documentation

#define FI_F_DISCARD   0x00000002U /**< Discard fileinfo if refcount = 0 */
 

Discard fileinfo if refcount = 0.

#define FI_F_MARK   0x80000000U /**< Marked during traversal */
 

Marked during traversal.

#define FI_F_SUSPEND   0x00000001U /**< Marked "suspended" new downloads */
 

Marked "suspended" new downloads.

#define FI_F_TRANSIENT   0x40000000U /**< Don't persist to disk */
 

Don't persist to disk.

#define FI_LOW_SRC_COUNT   5 /**< Few sources known if beneath */
 

Few sources known if beneath.


Function Documentation

G_GNUC_CONST WARN_UNUSED_RESULT guint32 fi_alive_count fileinfo_t fi  )  [inline, static]
 

Return amount of currently active sources.

void file_info_add_new_source fileinfo_t fi,
struct download dl
 

Add new download source for the file.

void file_info_add_source fileinfo_t fi,
struct download dl
 

Add download source for the file, but preserve original "ntime".

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.

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.

Returns:
the size of the generated header.

void file_info_changed fileinfo_t fi  ) 
 

Signals that some information in the fileinfo has changed, warranting a display update in the GUI.

enum dl_chunk_status file_info_chunk_status fileinfo_t fi,
filesize_t  from,
filesize_t  to
 

Returns:
DONE if the range requested is marked as complete, or BUSY if not. Used to determine if we can do overlap checking.

void file_info_clear_download struct download d,
gboolean  lifecount
 

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

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.

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.

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.

If found, the returned chunk is marked BUSY and linked to the download `d'.

Returns:
TRUE if one was found, with `from' and `to' set, FALSE otherwise.
Attention:
NB: In accordance with other fileinfo semantics, `to' is NOT the last byte of the range but one byte AFTER the end.

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.

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.

fileinfo_t* file_info_get gchar *  file,
const gchar *  path,
filesize_t  size,
gchar *  sha1,
gboolean  file_size_known
 

Parameters:
`file' is the file name on the server.
`path' no brief description.
`size' no brief description.
`sha1' no brief description.
`file_size_known' no brief description.
Returns:
a pointer to file_info struct that matches the given file name, size and/or SHA1. A new struct will be allocated if necessary.

fileinfo_t* file_info_get_browse const gchar *  name  ) 
 

Create a transient fileinfo structure to be perused by browse host.

gboolean file_info_got_sha1 fileinfo_t fi,
const gchar *  sha1
 

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.

Returns:
TRUE if OK, FALSE if a duplicate record with the same SHA1 exists.

fileinfo_t* file_info_has_identical gchar *  file,
filesize_t  size,
gchar *  sha1
 

Returns:
a pointer to the file info struct if we have a file identical to the given properties in the download queue already, and NULL otherwise.

gboolean file_info_has_trailer const gchar *  path  ) 
 

Check whether file has a trailer.

void file_info_init void   ) 
 

Initialize fileinfo handling.

void file_info_init_post void   ) 
 

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.

void file_info_merge_adjacent fileinfo_t fi  ) 
 

Go through the chunk list and merge adjacent chunks that share the same status and download.

Keeps the chunk list short and tidy.

enum dl_chunk_status file_info_pos_status fileinfo_t fi,
filesize_t  pos
 

Returns:
the status (EMPTY, BUSY or DONE) of the byte requested. Used to detect if a download is crashing with another.

void file_info_recreate struct download d  ) 
 

void file_info_remove fileinfo_t fi  ) 
 

Remove non-referenced fileinfo and reclaim its data structures.

void file_info_remove_source fileinfo_t fi,
struct download dl,
gboolean  discard
 

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()

void file_info_reset fileinfo_t fi  ) 
 

Reset all chunks to EMPTY, clear computed SHA1 if any.

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.

Returns:
TRUE if the request is satisfiable, with `end' possibly adjusted, FALSE is the request cannot be satisfied because `start' is not within an available chunk.

void file_info_retrieve void   ) 
 

Loads the fileinfo database from disk, and saves a copy in fileinfo.orig.

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.

void file_info_set_discard fileinfo_t fi,
gboolean  state
 

Set or clear the discard state for a fileinfo.

shared_file_t* file_info_shared_sha1 const gchar *  sha1  ) 
 

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).

Returns:
NULL if don't have any download with this SHA1, otherwise return a "shared_file" structure suitable for uploading the parts of the file we have (which will happen only when PFSP-server is enabled).

void file_info_size_known struct download d,
filesize_t  size
 

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.

void file_info_spot_completed_orphans void   ) 
 

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.

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_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.

void file_info_timer void   ) 
 

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.

Add the corresponding file to the download list if we're swarming on it.

Parameters:
file_name the remote file name (as in the GET query).
idx the remote file index (as in the GET query).
addr the remote servent address.
port the remote servent port.
sha1 the SHA1 of the file.

void file_info_unlink fileinfo_t fi  ) 
 

Unlink file from disk.

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.

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.

void file_info_upload_stop fileinfo_t fi,
const gchar *  reason
 

Stop all sharing occuring for this fileinfo.


Generated on Sun Feb 12 10:50:01 2006 for Gtk-Gnutella by doxygen 1.3.6