|
Data Structures |
| struct | dl_file_chunk |
| struct | trailer |
| | The trailer fields of the fileinfo trailer. More...
|
| struct | fi_tag |
| struct | file_info_foreach |
Defines |
| #define | FI_MIN_CHUNK_SPLIT 512 |
| | Max field length we accept to save.
|
| #define | FI_MAX_FIELD_LEN (TTH_RAW_SIZE * TTH_MAX_LEAVES) |
| #define | FILE_INFO_MAGIC32 0xD1BB1ED0U |
| #define | FILE_INFO_MAGIC64 0X91E63640U |
| #define | FILE_INFO_VERSION 6 |
| #define | FI_STORE_DELAY 10 |
| | Max delay (secs) for flushing fileinfo.
|
| #define | FI_TRAILER_INT 6 |
| | Amount of guint32 in the trailer.
|
| #define | TBUF_SIZE 512 |
| | Initial trailing buffer size.
|
| #define | TBUF_GROW_BITS 9 |
| | Growing chunks.
|
| #define | TBUF_GROW ((size_t) 1 << TBUF_GROW_BITS) |
| #define | TBUF_GROW_MASK (TBUF_GROW - 1) |
| #define | BAILOUT(x) |
| #define | GET_KEY(i) (fi_tag_map[(i)].str) |
| #define | FOUND(i) |
| #define | bs_nop(x) (x) |
Typedefs |
| typedef guint32 | fi_magic_t |
Enumerations |
| enum | dl_file_chunk_magic { DL_FILE_CHUNK_MAGIC = 0xd63b483dU
} |
| enum | dl_file_info_field {
FILE_INFO_FIELD_NAME = 1,
FILE_INFO_FIELD_ALIAS,
FILE_INFO_FIELD_SHA1,
FILE_INFO_FIELD_CHUNK,
FILE_INFO_FIELD_END,
FILE_INFO_FIELD_CHA1,
FILE_INFO_FIELD_GUID,
FILE_INFO_FIELD_TTH,
FILE_INFO_FIELD_TIGERTREE,
NUM_FILE_INFO_FIELDS
} |
| enum | fi_tag_t {
FI_TAG_UNKNOWN = 0,
FI_TAG_ALIA,
FI_TAG_CHA1,
FI_TAG_CHNK,
FI_TAG_CTIM,
FI_TAG_DONE,
FI_TAG_FSKN,
FI_TAG_GENR,
FI_TAG_GUID,
FI_TAG_NAME,
FI_TAG_NTIM,
FI_TAG_PATH,
FI_TAG_PAUS,
FI_TAG_SHA1,
FI_TAG_SIZE,
FI_TAG_SWRM,
FI_TAG_TIME,
FI_TAG_TTH,
NUM_FI_TAGS
} |
Functions |
| size_t | round_grow (size_t x) |
| void | tbuf_check (void) |
| void | tbuf_extend (size_t x, gboolean writing) |
| | Make sure there is enough room in the buffer for `x' more bytes.
|
| void | TBUF_INIT_READ (size_t size) |
| void | TBUF_INIT_WRITE (void) |
| size_t | TBUF_WRITTEN_LEN (void) |
| void | TBUF_CHECK (size_t size) |
| WARN_UNUSED_RESULT gboolean | TBUF_GETCHAR (guint8 *x) |
| WARN_UNUSED_RESULT gboolean | TBUF_GET_UINT32 (guint32 *x) |
| WARN_UNUSED_RESULT gboolean | TBUF_READ (gchar *x, size_t size) |
| void | TBUF_PUT_CHAR (guint8 x) |
| void | TBUF_PUT_UINT32 (guint32 x) |
| void | TBUF_WRITE (const gchar *data, size_t size) |
| void | file_info_checksum (guint32 *checksum, gconstpointer data, size_t len) |
| void | WRITE_CHAR (guint8 val, guint32 *checksum) |
| void | WRITE_UINT32 (guint32 val, guint32 *checksum) |
| void | WRITE_STR (const gchar *data, size_t size, guint32 *checksum) |
| WARN_UNUSED_RESULT gboolean | READ_CHAR (guint8 *val, guint32 *checksum) |
| WARN_UNUSED_RESULT gboolean | READ_UINT32 (guint32 *val_ptr, guint32 *checksum) |
| WARN_UNUSED_RESULT gboolean | READ_STR (gchar *data, size_t size, guint32 *checksum) |
| void | FIELD_ADD (enum dl_file_info_field id, size_t n, gconstpointer data, guint32 *checksum) |
| fileinfo_t * | file_info_retrieve_binary (const gchar *pathname) |
| | Reads the file metainfo from the trailer of a file, if it exists.
|
| void | fi_free (fileinfo_t *fi) |
| | Free a `file_info' structure.
|
| void | fi_update_seen_on_network (gnet_src_t srcid) |
| | Callback for updates to ranges available on the network.
|
| const gchar * | file_info_new_outname (const gchar *dir, const gchar *name) |
| | Allocate unique output name for file `name', stored in `dir'.
|
| gboolean | looks_like_urn (const gchar *filename) |
| | Check whether filename looks like an URN.
|
| fileinfo_t * | file_info_find_by_handle (gnet_fi_t n) |
| gnet_fi_t | file_info_request_handle (fileinfo_t *fi) |
| void | file_info_drop_handle (gnet_fi_t n) |
| gboolean | trailer_is_64bit (const struct trailer *tb) |
| | Checks the kind of trailer.
|
| void | tbuf_write (const struct file_object *fo, filesize_t offset) |
| | Write trailer buffer at current position on `fd', whose name is `name'.
|
| ssize_t | tbuf_read (gint fd, size_t len) |
| | Read trailer buffer at current position from `fd'.
|
| dl_file_chunk * | dl_file_chunk_alloc (void) |
| void | dl_file_chunk_check (const struct dl_file_chunk *fc) |
| void | dl_file_chunk_free (struct dl_file_chunk **fc_ptr) |
| gboolean | file_info_check_chunklist (const fileinfo_t *fi, gboolean assertion) |
| | Checks the chunklist of fi.
|
| void | file_info_fd_store_binary (fileinfo_t *fi, const struct file_object *fo, gboolean force) |
| | Store a binary record of the file metainformation at the end of the supplied file descriptor, opened for writing.
|
| 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_mark_stripped (fileinfo_t *fi) |
| | Record that the fileinfo trailer has been stripped.
|
| void | file_info_strip_trailer (fileinfo_t *fi, const gchar *pathname) |
| 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 *pathname) |
| | Strips the file metainfo trailer off specified file.
|
| void | file_info_chunklist_free (fileinfo_t *fi) |
| | Frees the chunklist and all its elements of a fileinfo struct.
|
| void | fi_tigertree_free (fileinfo_t *fi) |
| void | file_info_hash_insert_name_size (fileinfo_t *fi) |
| void | fi_resize (fileinfo_t *fi, filesize_t size) |
| | Resize fileinfo to be `size' bytes, by adding empty chunk at the tail.
|
| void | fi_alias (fileinfo_t *fi, const gchar *name, gboolean record) |
| | Add `name' as an alias for `fi' if not already known.
|
| gboolean | file_info_get_trailer (gint fd, struct trailer *tb, const gchar *name) |
| | Extract fixed trailer at the end of the file `name', already opened as `fd'.
|
| gint | file_info_has_trailer (const gchar *path) |
| | Check whether file has a trailer.
|
| fileinfo_t * | file_info_by_sha1 (const struct sha1 *sha1) |
| fileinfo_t * | file_info_lookup (const gchar *name, filesize_t size, const struct sha1 *sha1) |
| | Lookup our existing fileinfo structs to see if we can spot one referencing the supplied file `name' and `size', as well as the optional `sha1' hash.
|
| fileinfo_t * | file_info_lookup_dup (fileinfo_t *fi) |
| | Given a fileinfo structure, look for any other known duplicate.
|
| const gchar * | file_info_readable_filename (const fileinfo_t *fi) |
| | Determines a human-readable filename for the file, using heuristics to skip what looks like an URN.
|
| shared_file_t * | file_info_shared_sha1 (const struct sha1 *sha1) |
| | Look whether we have a partially downloaded file bearing the given SHA1.
|
| const gchar * | fi_random_guid_atom (void) |
| | Allocate random GUID to use as the file ID.
|
| gboolean | fi_upgrade_older_version (fileinfo_t *fi) |
| | Ensure potentially old fileinfo structure is brought up-to-date by inferring or allocating missing fields.
|
| void | fi_tigertree_check (fileinfo_t *fi) |
| void | file_info_store_one (FILE *f, fileinfo_t *fi) |
| | Stores a file info record to the config_dir/fileinfo file, and appends it to the output file in question if needed.
|
| void | file_info_store_list (gpointer key, gpointer value, gpointer user_data) |
| | Callback for hash table iterator.
|
| void | file_info_store (void) |
| | Stores the list of output files and their metainfo to the configdir/fileinfo database.
|
| void | file_info_store_if_dirty (void) |
| | Store global file information cache if dirty.
|
| void | fi_dispose (fileinfo_t *fi) |
| void | file_info_free_sha1_kv (gpointer key, gpointer val, gpointer unused_x) |
| | Callback for hash table iterator.
|
| void | file_info_free_namesize_kv (gpointer key, gpointer val, gpointer unused_x) |
| | Callback for hash table iterator.
|
| void | file_info_free_guid_kv (gpointer key, gpointer val, gpointer unused_x) |
| | Callback for hash table iterator.
|
| void | file_info_free_outname_kv (gpointer key, gpointer val, gpointer unused_x) |
| | Callback for hash table iterator.
|
| void | file_info_changed (fileinfo_t *fi) |
| | Signals that some information in the fileinfo has changed, warranting a display update in the GUI.
|
| void | file_info_close_pre (void) |
| | Pre-close some file_info information.
|
| void | file_info_close (void) |
| | Close and free all file_info structs in the list.
|
| void | file_info_hash_insert (fileinfo_t *fi) |
| | Inserts a file_info struct into the hash tables.
|
| void | file_info_hash_remove (fileinfo_t *fi) |
| | Remove fileinfo data from all the hash tables.
|
| void | file_info_upload_stop (fileinfo_t *fi, const gchar *reason) |
| | Stop all sharing occuring for this fileinfo.
|
| void | file_info_unlink (fileinfo_t *fi) |
| | Unlink file from disk.
|
| void | file_info_reparent_all (fileinfo_t *from, fileinfo_t *to) |
| | Reparent all downloads using `from' as a fileinfo, so they use `to' now.
|
| gboolean | file_info_got_sha1 (fileinfo_t *fi, const struct sha1 *sha1) |
| | Called when we discover the SHA1 of a running download.
|
| void | file_info_got_tth (fileinfo_t *fi, const struct tth *tth) |
| void | file_info_got_tigertree (fileinfo_t *fi, const struct tth *leaves, size_t num_leaves) |
| const gchar * | extract_guid (const gchar *s) |
| | Extract GUID from GUID line in the ASCII "fileinfo" summary file and return NULL if none or invalid, the GUID atom otherwise.
|
| const struct sha1 * | extract_sha1 (const gchar *s) |
| | Extract sha1 from SHA1/CHA1 line in the ASCII "fileinfo" summary file and return NULL if none or invalid, the SHA1 atom otherwise.
|
| const struct tth * | extract_tth (const gchar *s) |
| fi_tag_t | file_info_string_to_tag (const gchar *s) |
| | Transform fileinfo tag string into tag constant.
|
| void | fi_reset_chunks (fileinfo_t *fi) |
| | Reset CHUNK info: everything will have to be downloaded again.
|
| void | fi_copy_chunks (fileinfo_t *fi, fileinfo_t *trailer) |
| | Copy CHUNK info from binary trailer `trailer' into `fi'.
|
| void | file_info_retrieve (void) |
| | Loads the fileinfo database from disk, and saves a copy in fileinfo.orig.
|
| gboolean | file_info_name_is_uniq (const gchar *pathname) |
| fileinfo_t * | file_info_create (const gchar *file, const gchar *path, filesize_t size, const struct sha1 *sha1, gboolean file_size_known) |
| | Create a fileinfo structure from existing file with no swarming trailer.
|
| fileinfo_t * | file_info_get_transient (const gchar *name) |
| | Create a transient fileinfo structure.
|
| void | fi_rename_dead (fileinfo_t *fi, const gchar *pathname) |
| | Rename dead file we cannot use, either because it bears a duplicate SHA1 or because its file trailer bears a duplicate file ID.
|
| void | file_info_moved (fileinfo_t *fi, const gchar *pathname) |
| | Called to update the fileinfo information with the new path and possibly filename information, once the downloaded file has been moved/renamed.
|
| fileinfo_t * | file_info_get (const gchar *file, const gchar *path, filesize_t size, const struct sha1 *sha1, gboolean file_size_known) |
| fileinfo_t * | file_info_has_identical (const struct sha1 *sha1, filesize_t size) |
| void | file_info_set_discard (fileinfo_t *fi, gboolean state) |
| | Set or clear the discard state for a fileinfo.
|
| 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_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.
|
| void | file_info_clear_download (struct download *d, gboolean lifecount) |
| | Go through all chunks that belong to the download, and unmark them as busy.
|
| void | file_info_reset (fileinfo_t *fi) |
| | Reset all chunks to EMPTY, clear computed SHA1 if any.
|
| enum dl_chunk_status | file_info_chunk_status (fileinfo_t *fi, filesize_t from, filesize_t to) |
| enum dl_chunk_status | file_info_pos_status (fileinfo_t *fi, filesize_t pos) |
| void | fi_check_file (fileinfo_t *fi) |
| | This routine is called each time we start a new download, before making the request to the remote server.
|
| gint | fi_busy_count (fileinfo_t *fi, struct download *d) |
| | Count the amount of BUSY chunks attached to a given download.
|
| filesize_t | get_random_offset (const filesize_t size) |
| GSList * | list_clone_shift (fileinfo_t *fi) |
| | Clone fileinfo's chunk list, shifting the origin of the list to a randomly selected offset within the file.
|
| filesize_t | fi_chunksize (fileinfo_t *fi) |
| | Compute chunksize to be used for the current request.
|
| gdouble | fi_missing_coverage (struct download *d) |
| | Compute how much the source covers the missing chunks we still have which are not busy.
|
| const struct dl_file_chunk * | fi_find_largest (const fileinfo_t *fi) |
| | Find the largest busy chunk.
|
| const struct dl_file_chunk * | fi_find_slowest (const fileinfo_t *fi) |
| | Find the largest busy chunk served by the host with the smallest uploading rate.
|
| gboolean | fi_find_aggressive_candidate (struct download *d, guint busy, filesize_t *from, filesize_t *to) |
| | Find the spot we could download at the tail of an already active chunk to be aggressively completing the file ASAP.
|
| 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_try_to_swarm_with (const gchar *file_name, const host_addr_t addr, guint16 port, const struct sha1 *sha1) |
| | Called when we add something to the dmesh.
|
| 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 | fi_spot_completed_kv (gpointer key, gpointer val, gpointer unused_x) |
| | Callback for hash table iterator.
|
| void | file_info_spot_completed_orphans (void) |
| | Look through all the known fileinfo structures, looking for orphaned files that are complete.
|
| void | fi_add_listener (fi_listener_t cb, gnet_fi_ev_t ev, frequency_t t, guint32 interval) |
| void | fi_remove_listener (fi_listener_t cb, gnet_fi_ev_t ev) |
| gnet_fi_info_t * | fi_get_info (gnet_fi_t fih) |
| | Get an information structure summarizing the file info.
|
| void | fi_free_info (gnet_fi_info_t *info) |
| | Dispose of the info structure.
|
| void | fi_increase_uploaded (fileinfo_t *fi, size_t amount) |
| void | fi_get_status (gnet_fi_t fih, gnet_fi_status_t *s) |
| | Fill in the fileinfo status structure "s" using the fileinfo associated with the fileinfo handle "fih".
|
| GSList * | fi_get_chunks (gnet_fi_t fih) |
| | Get a list with information about each chunk and status.
|
| void | fi_free_chunks (GSList *chunks) |
| | Free chunk list got by calling fi_get_chunks.
|
| GSList * | fi_get_ranges (gnet_fi_t fih) |
| | Get a list of available ranges for this fileinfo handle.
|
| void | fi_free_ranges (GSList *ranges) |
| gchar ** | fi_get_aliases (gnet_fi_t fih) |
| 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".
|
| void | file_info_remove_source (fileinfo_t *fi, struct download *dl, gboolean discard) |
| | Removing one source reference from the fileinfo.
|
| void | file_info_remove (fileinfo_t *fi) |
| | Remove non-referenced fileinfo and reclaim its data structures.
|
| void | fi_notify_helper (gpointer unused_key, gpointer value, gpointer unused_udata) |
| void | file_info_timer (void) |
| gboolean | file_info_purge (fileinfo_t *fi) |
| | Kill all downloads associated with a fi and remove the fi itself.
|
| gboolean | fi_purge (gnet_fi_t fih) |
| void | fi_purge_by_handle_list (const GSList *list) |
| | Purge all handles contained in list.
|
| 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.
|
| gchar * | file_info_build_magnet (gnet_fi_t handle) |
| | Creates a URL which points to a downloads (e.g.
|
| gchar * | file_info_get_file_url (gnet_fi_t handle) |
| | Creates a file:// URL which points to the file on the local filesystem.
|
| GSList * | fi_range_for_complete_file (filesize_t size) |
| | Create a ranges list with one item covering the whole file.
|
| void | file_info_foreach_helper (gpointer unused_key, gpointer value, gpointer udata) |
| void | file_info_foreach (file_info_foreach_cb callback, gpointer udata) |
| const char * | file_info_status_to_string (const gnet_fi_status_t *status) |
| void | file_info_init (void) |
| | Initialize fileinfo handling.
|
| void | file_info_init_post (void) |
| | Finish initialization of fileinfo handling.
|
Variables |
| GHashTable * | fi_by_sha1 |
| GHashTable * | fi_by_namesize |
| GHashTable * | fi_by_outname |
| GHashTable * | fi_by_guid |
| const gchar | file_info_file [] = "fileinfo" |
| const gchar | file_info_what [] = "the fileinfo database" |
| gboolean | fileinfo_dirty = FALSE |
| gboolean | can_swarm = FALSE |
| | Set by file_info_retrieve().
|
| struct { |
| gchar * arena |
| | Base arena.
|
| gchar * wptr |
| | Write pointer.
|
| const gchar * rptr |
| | Read pointer.
|
| const gchar * end |
| | First byte off arena.
|
| size_t size |
| | Current size of arena.
|
| } | tbuf |
| | The swarming trailer is built within a memory buffer first, to avoid having to issue mutliple write() system calls.
|
| idtable_t * | fi_handle_map = NULL |
| event_t * | fi_events [EV_FI_EVENTS] |
| const struct fi_tag | fi_tag_map [] |