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

core/downloads.c File Reference


Detailed Description

Handle downloads.

Author:
Raphael Manfredi
Date:
2001-2007

#include "common.h"
#include "sockets.h"
#include "downloads.h"
#include "hosts.h"
#include "routing.h"
#include "gmsg.h"
#include "bsched.h"
#include "huge.h"
#include "dmesh.h"
#include "file_object.h"
#include "http.h"
#include "version.h"
#include "ignore.h"
#include "ioheader.h"
#include "verify_sha1.h"
#include "move.h"
#include "settings.h"
#include "nodes.h"
#include "parq.h"
#include "token.h"
#include "hostiles.h"
#include "clock.h"
#include "uploads.h"
#include "ban.h"
#include "guid.h"
#include "pproxy.h"
#include "features.h"
#include "gnet_stats.h"
#include "geo_ip.h"
#include "bh_download.h"
#include "thex_download.h"
#include "tls_cache.h"
#include "udp.h"
#include "rx_inflate.h"
#include "vmsg.h"
#include "if/gnet_property.h"
#include "if/gnet_property_priv.h"
#include "if/bridge/c2ui.h"
#include "lib/adns.h"
#include "lib/array.h"
#include "lib/atoms.h"
#include "lib/base32.h"
#include "lib/dbus_util.h"
#include "lib/endian.h"
#include "lib/file.h"
#include "lib/getdate.h"
#include "lib/getline.h"
#include "lib/glib-missing.h"
#include "lib/hashlist.h"
#include "lib/idtable.h"
#include "lib/palloc.h"
#include "lib/magnet.h"
#include "lib/tigertree.h"
#include "lib/tm.h"
#include "lib/url.h"
#include "lib/utf8.h"
#include "lib/walloc.h"
#include "lib/override.h"

Data Structures

struct  dl_addr
 Keys in the `dl_by_addr' table. More...
struct  download_request
struct  server_select

Defines

#define DOWNLOAD_FILE_MODE   (S_IRUSR | S_IWUSR | S_IRGRP)
#define DOWNLOAD_MIN_OVERLAP   64
 Minimum overlap for safety.
#define DOWNLOAD_SHORT_DELAY   2
 Shortest retry delay.
#define DOWNLOAD_MAX_SINK   16384
 Max amount of data to sink.
#define DOWNLOAD_MAX_IGN_DATA   2097152
 Max amount of data to ignore.
#define DOWNLOAD_MAX_IGN_TIME   300
 Max amount of secs we can ignore.
#define DOWNLOAD_MAX_IGN_REQS   3
 How many mismatches per source.
#define DOWNLOAD_SERVER_HOLD   15
 Space requests to same server.
#define DOWNLOAD_DNS_LOOKUP   7200
 Period of server DNS lookups.
#define DOWNLOAD_STALLED   60
 Consider stalled after 60 secs.
#define DOWNLOAD_PING_DELAY   300
 Minimum delay for 2 HEAD pings.
#define DOWNLOAD_MAX_HEADER_EOF   5
 Max # of EOF in headers we allow.
#define DOWNLOAD_DATA_TIMEOUT   5
 Max # of data timeouts we allow.
#define IO_AVG_RATE   5
 Compute global recv rate every 5 secs.
#define DHASH_SIZE   (1UL << 10)
 Hash list size, must be a power of 2.
#define DHASH_MASK   (DHASH_SIZE - 1)
#define DL_HASH(x)   ((x) & DHASH_MASK)
#define MAGIC_TIME   1
 For recreation upon starup.

Functions

void download_add_to_list (struct download *d, enum dl_list idx)
gboolean download_send_push_request (struct download *d)
 Send a push request to the target GUID, in order to request the push of the file whose index is `file_id' there onto our local port `port'.
gboolean download_read (struct download *d, pmsg_t *mb)
 Read callback for file data from the RX stack.
gboolean download_ignore_data (struct download *d, pmsg_t *mb)
 Read callback for file data from the RX stack, used when we ignore those data after a failed resuming check.
void download_request (struct download *d, header_t *header, gboolean ok)
 Called to initiate the download once all the HTTP headers have been read.
void download_push_ready (struct download *d, getline_t *empty)
 Send download request on the opened connection.
void download_push_remove (struct download *d)
 Forget that we sent a push request for this download.
void download_push (struct download *d, gboolean on_timeout)
void download_resume_bg_tasks (void)
 Go through the downloads and check the completed ones that should be either moved to the "done" directory, or which should have their SHA1 computed/verified.
void download_incomplete_header (struct download *d)
 Called when header reading times out.
gboolean has_blank_guid (const struct download *d)
void download_verify_sha1 (struct download *d)
 Main entry point for verifying the SHA1 of a completed download.
gboolean download_get_server_name (struct download *d, header_t *header)
 Extract server name from headers.
gboolean use_push_proxy (struct download *d)
 Try to setup the download to use the push proxies available on the server.
void download_unavailable (struct download *d, download_status_t new_status, const gchar *reason,...) G_GNUC_PRINTF(3
 Like download_stop(), but flag the download as "unavailable".
void download_queue_delay (struct download *d, guint32 delay, const gchar *fmt,...) G_GNUC_PRINTF(3
 Put download back to queue, but don't reconsider it for starting before the next `delay' seconds.
void download_queue_hold (struct download *d, guint32 hold, const gchar *fmt,...) G_GNUC_PRINTF(3
 Same as download_queue_delay(), but make sure we don't consider scheduling any currently queued download to this server before the holding delay.
void download_reparent (struct download *d, struct dl_server *new_server)
 Move download from a server to another one.
gboolean download_flush (struct download *d, gboolean *trimmed, gboolean may_stop)
 Flush buffered data to disk.
void download_store (void)
 Store all pending downloads.
void download_retrieve (void)
 Retrieve download list and requeue each download.
const gchar * download_pathname (const struct download *d)
const gchar * download_basename (const struct download *d)
guint count_running_downloads (void)
guint server_list_length (const struct dl_server *server, enum dl_list idx)
guint count_running_on_server (const struct dl_server *server)
void src_init (void)
void src_close (void)
void src_add_listener (src_listener_t cb, gnet_src_ev_t ev, frequency_t t, guint32 interval)
void src_remove_listener (src_listener_t cb, gnet_src_ev_t ev)
downloadsrc_get_download (gnet_src_t src_handle)
 G_GNUC_PRINTF (2, 3)
void download_rx_got_eof (gpointer o)
gboolean download_data_ind (rxdrv_t *rx, pmsg_t *mb)
 RX data indication callback used to give us some new download traffic in a low-level message structure.
gboolean download_ignore_data_ind (rxdrv_t *rx, pmsg_t *mb)
 RX data indication callback used to give us some new download traffic in a low-level message structure.
void download_chunk_rx_done (gpointer o)
void download_write (struct download *d, gpointer data, size_t len)
 Received data from outside the RX stack.
downloaddownload_alloc (void)
 The only place to allocate a struct download.
void download_free (struct download **d_ptr)
 The only place to release a struct download.
guint dl_key_hash (gconstpointer key)
 Hashing of a `dl_key' structure.
gint dl_key_eq (gconstpointer a, gconstpointer b)
 Comparison of `dl_key' structures.
guint dl_addr_hash (gconstpointer key)
 Hashing of a `dl_addr' structure.
gint dl_addr_eq (gconstpointer a, gconstpointer b)
 Comparison of `dl_addr' structures.
gint dl_retry_cmp (gconstpointer p, gconstpointer q)
 Compare two `download' structures based on the `retry_after' field.
gint dl_server_retry_cmp (gconstpointer p, gconstpointer q)
 Compare two `dl_server' structures based on the `retry_after' field.
gboolean download_has_blank_guid (const struct download *d)
gboolean is_faked_download (const struct download *d)
gboolean has_good_sha1 (const struct download *d)
 Was downloaded file verified to have a SHA1 matching the advertised one?
void download_update_timeout_delay (struct download *d)
 Sets proper timeout delay, with exponential back-off and min/max enforcement.
void download_retry (struct download *d)
 Called to request retry of a download after a timeout, with exponential back-off timeout delay, up to a maximum.
gdouble download_total_progress (const struct download *d)
 Return the total progress of a download.
gdouble download_source_progress (const struct download *d)
 Return the total progress of a download source.
void download_init (void)
 Initialize downloading data structures.
void download_restore_state (void)
 Initialize downloading data structures.
void buffers_alloc (struct download *d)
 Allocate a set of buffers for data reception.
void buffers_free_item (gpointer data, gpointer unused_udata)
void buffers_free (struct download *d)
 Dispose of the buffers used for reading.
void buffers_reset_reading (struct download *d)
 Reset the I/O vector for reading from the start.
iovec * buffers_to_iovec (struct download *d, gint *iov_cnt)
 Reset the I/O vector for writing the whole data held in the buffer.
void buffers_discard (struct download *d)
 Discard all read data from buffers.
gboolean buffers_full (const struct download *d)
 Check whether reception buffers are full.
gboolean buffers_should_flush (const struct download *d)
 Check whether we should request flushing of the buffered data.
void buffers_add_read (struct download *d, pmsg_t *mb)
 Update the buffer structure after having read "amount" more bytes: prepare `iovcnt' for the next read and increase the amount of data held.
gboolean buffers_match (const struct download *d, const gchar *data, size_t len)
 Compare data held in the read buffers with the data chunk supplied.
void buffers_strip_leading (struct download *d, size_t amount)
 Strip leading `amount' bytes from the read buffers.
void buffers_check_held (const struct download *d)
void buffers_strip_trailing (struct download *d, size_t amount)
 Strip trailing `amount' bytes from the read buffers.
void download_timer (time_t now)
 Download heartbeat timer.
void dl_by_time_insert (struct dl_server *server)
 Insert server by retry time into the `dl_by_time' structure.
void dl_by_time_remove (struct dl_server *server)
 Remove server from the `dl_by_time' structure.
GSList * hostvec_to_slist (const gnet_host_vec_t *vec)
 Convert a vector of host to a single-linked list.
void free_proxies (struct dl_server *server)
 Get rid of the list of push proxies held in the server.
void remove_proxy (struct dl_server *server, const host_addr_t addr, guint16 port)
 Remove push proxy from server.
dl_serverallocate_server (const gchar *guid, const host_addr_t addr, guint16 port)
 Allocate new server structure.
void server_list_free_all (struct dl_server *server)
void free_server (struct dl_server *server)
 Free server structure.
void server_delay_delete (struct dl_server *server)
 Marks server for delayed removal (via asynchronous timer).
void server_undelete (struct dl_server *server)
 Resurrect server pending deletion.
dl_serverget_server (const gchar *guid, const host_addr_t addr, guint16 port, gboolean allocate)
 Fetch server entry identified by IP:port first, then GUID+IP:port.
void change_server_addr (struct dl_server *server, const host_addr_t new_addr)
 The server address changed.
void set_server_hostname (struct dl_server *server, const gchar *hostname)
 Set/change the server's hostname.
gboolean download_server_nopush (const gchar *guid, const host_addr_t addr, guint16 port)
 Check whether we can safely ignore Push indication for this server, identified by its GUID, IP and port.
guint count_running_downloads_with_name (const char *name)
 How many downloads with same filename are running (active or establishing)?
void downloads_with_name_inc (const gchar *name)
 Add one to the amount of downloads running and bearing the filename.
void downloads_with_name_dec (const gchar *name)
 Remove one from the amount of downloads running and bearing the filename.
const struct sha1download_get_sha1 (const struct download *d)
void server_sha1_count_inc (struct dl_server *server, struct download *d)
void server_sha1_count_dec (struct dl_server *server, struct download *d)
gboolean download_eq (gconstpointer p, gconstpointer q)
downloadserver_list_lookup (const struct dl_server *server, enum dl_list idx, const struct sha1 *sha1, const gchar *file, filesize_t size)
list_tserver_list_by_index (struct dl_server *server, enum dl_list idx)
void server_list_insert_download_sorted (struct dl_server *server, enum dl_list idx, struct download *d)
void server_list_append_download (struct dl_server *server, enum dl_list idx, struct download *d)
void server_list_prepend_download (struct dl_server *server, enum dl_list idx, struct download *d)
downloadserver_list_head (struct dl_server *server, enum dl_list idx)
void server_list_remove_download (struct dl_server *server, enum dl_list idx, struct download *d)
downloadhas_same_download (const gchar *file, const struct sha1 *sha1, filesize_t size, const gchar *guid, const host_addr_t addr, guint16 port)
 Check whether we already have an identical (same file, same SHA1, same host) running or queued download.
gboolean download_has_enough_active_sources (struct download *d)
void download_actively_queued (struct download *d, gboolean queued)
 Mark a download as being actively queued.
void download_passively_queued (struct download *d, gboolean queued)
 Mark download as being passively queued.
gboolean download_file_exists (const struct download *d)
void download_remove_file (struct download *d, gboolean reset)
 Remove temporary download file.
void download_info_change_all (fileinfo_t *old_fi, fileinfo_t *new_fi)
 Change all the fileinfo of downloads from `old_fi' to `new_fi'.
void download_info_reget (struct download *d)
 Invalidate improper fileinfo for the download, and get new one.
void queue_suspend_downloads_with_file (fileinfo_t *fi, gboolean suspend)
 Mark all downloads that point to the file_info struct as "suspended" if `suspend' is TRUE, or clear that mark if FALSE.
void queue_remove_downloads_with_file (fileinfo_t *fi, struct download *skip)
 Removes all downloads that point to the file_info struct.
gint download_remove_all_from_peer (const gchar *guid, const host_addr_t addr, guint16 port, gboolean unavailable)
 Remove all downloads to a given peer from the download queue and abort all connections to peer in the active download list.
gint download_remove_all_named (const gchar *name)
 Remove all downloads with a given name from the download queue and abort all connections to peer in the active download list.
gint download_remove_all_with_sha1 (const struct sha1 *sha1)
 remove all downloads with a given sha1 hash from the download queue and abort all conenctions to peer in the active download list.
void download_remove_all_thex (const struct sha1 *sha1)
 Remove all THEX downloads for a given sha1.
void download_set_socket_rx_size (gint rx_size)
 Change the socket RX buffer size for all the currently connected downloads.
void download_set_sha1 (struct download *d, const struct sha1 *sha1)
void download_clear_stopped (gboolean complete, gboolean failed, gboolean unavailable, gboolean now)
 [GUI] Remove stopped downloads.
void download_move_to_list (struct download *d, enum dl_list idx)
 Move download from its current list to the `idx' one.
void download_server_retry_after (struct dl_server *server, time_t now, gint hold)
 Change the `retry_after' field of the host where this download runs.
void download_reclaim_server (struct download *d, gboolean delayed)
 Reclaim download's server if it is no longer holding anything.
void download_remove_from_server (struct download *d, gboolean reclaim)
 Remove download from server.
void download_redirect_to_server (struct download *d, const host_addr_t addr, guint16 port)
 Move download from a server to another when the IP:port changed due to a Location: redirection for instance, or because of a QUEUE callback.
void download_stop_v (struct download *d, download_status_t new_status, const gchar *reason, va_list ap)
 Vectorized version common to download_stop() and download_unavailable().
void download_stop (struct download *d, download_status_t new_status, const gchar *reason,...)
 Stop an active download, close its socket and its data file descriptor.
void download_queue_v (struct download *d, const gchar *fmt, va_list ap)
 The vectorized (message-wise) version of download_queue().
void download_queue (struct download *d, const gchar *fmt,...)
 Put download into queue.
void download_freeze_queue (void)
 Freeze the scheduling queue.
void download_thaw_queue (void)
 Thaw the scheduling queue.
gboolean download_queue_is_frozen (void)
 Test whether download queue is frozen.
void download_queue_hold_delay_v (struct download *d, gint delay, time_t hold, const gchar *fmt, va_list ap)
 Common vectorized code for download_queue_delay() and download_queue_hold().
void download_push_insert (struct download *d)
 Record that we sent a push request for this download.
void download_send_head_ping (struct download *d)
 Send a HEAD Ping vendor message to node to get alternate sources via UDP since we're not going to issue an HTTP request right now.
void download_list_send_head_ping (list_t *list)
 Send a HEAD Ping to all the downloads in the list.
gboolean download_ignore_requested (struct download *d)
 Check whether download should be ignored, and stop it immediately if it is.
void download_unqueue (struct download *d)
 Remove download from queue.
gboolean download_start_prepare_running (struct download *d)
 Setup the download structure with proper range offset, and check that the download is not otherwise completed.
gboolean download_start_prepare (struct download *d)
 Make download a "running" one (in running list, unqueued), then call download_start_prepare_running().
gboolean download_pick_chunk (struct download *d)
 Called for swarming downloads when we are connected to the remote server, but before making the request, to pick up a chunk for downloading.
gboolean download_pick_available (struct download *d)
 Pickup a range we don't have yet from the available ranges.
void download_bad_source (struct download *d)
 Indicates that this download source is not good enough for us: it is either non-connectible, does not allow resuming, etc...
gnutella_socketdownload_connect (struct download *d)
 Establish asynchronous connection to remote server.
void download_start (struct download *d, gboolean check_allowed)
 (Re)start a stopped or queued download.
void download_pause (struct download *d)
 Pause a download.
void download_pickup_queued (void)
 Pick up new downloads from the queue as needed.
void download_fallback_to_push (struct download *d, gboolean on_timeout, gboolean user_request)
 Direct download failed, let's try it with a push request.
const gchar * download_escape_name (const gchar *name)
guint32 get_index_from_uri (const gchar *uri)
downloadcreate_download (const gchar *file_name, const gchar *uri, filesize_t size, const host_addr_t addr, guint16 port, const gchar *guid, const gchar *hostname, const struct sha1 *sha1, time_t stamp, fileinfo_t *file_info, const gnet_host_vec_t *proxies, guint32 cflags, const gchar *parq_id)
 Create a new download.
void download_auto_new (const gchar *file_name, filesize_t size, const host_addr_t addr, guint16 port, const gchar *guid, const gchar *hostname, const struct sha1 *sha1, time_t stamp, fileinfo_t *fi, gnet_host_vec_t *proxies, guint32 flags)
 Automatic download request.
downloaddownload_clone (struct download *d)
 Clone download, resetting most dynamically allocated structures in the original since they are shallow-copied to the new download.
void download_index_changed (const host_addr_t addr, guint16 port, const gchar *guid, guint32 from, guint32 to)
 Search has detected index change in queued download.
download_requestdownload_request_new (const gchar *filename, const gchar *uri, filesize_t size, host_addr_t addr, guint16 port, const gchar *guid, const gchar *hostname, const struct sha1 *sha1, time_t stamp, fileinfo_t *fi, guint32 flags, const gnet_host_vec_t *proxies, const gchar *parq_id)
void download_request_free (struct download_request **req_ptr)
void download_new_by_hostname_helper (const host_addr_t *addrs, size_t n, gpointer user_data)
 Called when we got a reply from the ADNS process.
void download_new_by_hostname (struct download_request *req)
gboolean download_new (const gchar *filename, const gchar *uri, filesize_t size, const host_addr_t addr, guint16 port, const gchar *guid, const gchar *hostname, const struct sha1 *sha1, time_t stamp, fileinfo_t *fi, const gnet_host_vec_t *proxies, guint32 flags, const gchar *parq_id)
 Create a new download, usually called from an interactive user action.
void download_orphan_new (const gchar *filename, filesize_t size, const struct sha1 *sha1, fileinfo_t *fi)
 Fake a new download for an existing file that is marked complete in its fileinfo trailer.
void download_free_removed (void)
 Free all downloads listed in the `sl_removed' list.
gboolean download_remove (struct download *d)
 Freeing a download cannot be done simply, because it might happen when we are traversing the `sl_downloads' or `sl_unqueued' lists.
void download_forget (struct download *d, gboolean unavailable)
 Forget about download: stop it if running.
void download_abort (struct download *d)
 Abort download (forget about it) AND delete file if we removed the last reference to it and they want to delete on abort.
void download_resume (struct download *d)
void download_requeue (struct download *d)
 Explicitly re-enqueue potentially stopped download.
void download_proxy_newstate (struct download *d)
 Called when the status of the HTTP request made by the client push-proxy code changes.
void download_proxy_sent (struct download *d)
 Called by client push-proxy side when we got indication that the PUSH has been sent.
void download_proxy_failed (struct download *d)
 Called by client push-proxy side to indicate that it could not send a PUSH.
gboolean send_udp_push (const struct array packet, host_addr_t addr, guint16 port)
downloadcast_to_download (gpointer p)
void err_line_too_long (gpointer o)
void err_header_error (gpointer o, gint error)
void err_input_buffer_full (gpointer o)
void err_header_read_error (gpointer o, gint error)
void err_header_read_eof (gpointer o)
void download_start_reading (gpointer o)
void call_download_request (gpointer o, header_t *header)
void call_download_push_ready (gpointer o, header_t *unused_header)
gboolean download_can_ignore (struct download *d)
 See whether we can ignore the data from now on, keeping the connection open and sinking to /dev/null: the idea is that we keep the slot busy to get a chance to re-issue another request later.
void download_backout (struct download *d)
 Forget that we ever downloaded some bytes when there was a resuming mismatch at some point.
gboolean download_overlap_check (struct download *d)
 Check that the leading overlapping data in the read buffers match with the last ones in the downloaded file.
void download_continue (struct download *d, gboolean trimmed)
 Called when a chunk has been fully received but the file is still incomplete and more data is to be fetched.
gboolean download_write_data (struct download *d)
 Write data in socket buffer to file.
gboolean download_moved_permanently (struct download *d, header_t *header)
 Refresh IP:port, download index and name, by looking at the new location in the header ("Location:").
gboolean download_check_status (struct download *d, getline_t *line, gint code)
 Check status code from status line.
gboolean download_convert_to_urires (struct download *d)
 Convert download to /uri-res/N2R? request.
guint extract_retry_after (struct download *d, const header_t *header)
 Extract Retry-After delay from header, returning 0 if none.
void download_handle_thex_uri_header (struct download *d, header_t *header)
void check_date (const header_t *header, const host_addr_t addr, struct download *d)
 Look for a Date: header in the reply and use it to update our skew.
void check_xhostname (struct download *d, const header_t *header)
 Look for an X-Hostname header in the reply.
void check_xhost (struct download *d, const header_t *header)
 Look for an X-Host header in the reply.
gboolean content_range_check (struct download *d, header_t *header)
gboolean handle_content_urn (struct download *d, header_t *header)
 Handle X-Gnutella-Content-URN header.
void check_push_proxies (struct download *d, header_t *header)
 Extract host:port information out of X-Push-Proxy if present and update the server's list.
void update_available_ranges (struct download *d, header_t *header)
 Partial File Sharing Protocol (PFSP) -- client-side.
void download_sink (struct download *d)
 Sink read data.
void download_sink_read (gpointer data, gint unused_source, inputevt_cond_t unused_cond)
 Read callback for file data.
const gchar * lazy_ack_message_to_ui_string (const gchar *src)
void download_mark_active (struct download *d)
 Mark download as receiving data: download is becoming active.
gboolean is_dumb_spammer (const gchar *user_agent)
 Checks whether the contents of a User-Agent or Server header match the signature of a dumb spammer.
void download_request_sent (struct download *d)
 Called when the whole HTTP request has been sent out.
void download_write_request (gpointer data, gint unused_source, inputevt_cond_t cond)
 I/O callback invoked when we can write more data to the server to finish sending the HTTP request.
void download_send_request (struct download *d)
 Send the HTTP request for a download, then prepare I/O reading callbacks to read the incoming status line and following headers.
void download_connected (struct download *d)
 This function is called once a connection has been established.
downloadselect_push_download (GSList *servers)
 On reception of a "GIV index:GUID" string, select the appropriate download to request, from the list of potential server targets.
void select_matching_servers (gpointer key, gpointer value, gpointer user)
 If server is matching the selection criteria, insert it in the result set.
GSList * select_servers (const gchar *guid, const host_addr_t addr, gint *count)
 Given a servent GUID and an IP address, build a list of all the servents that bear either this GUID or that IP address.
gboolean parse_giv (const gchar *line, gchar *hex_guid, size_t size)
void download_push_ack (struct gnutella_socket *s)
 Initiate download on the remotely initiated connection.
downloaddownload_find_waiting_unparq (const host_addr_t addr, guint16 port)
 Find a waiting download on the specified server, identified by its IP:port for which we have no PARQ information yet.
gchar * download_build_magnet (const struct download *d)
void download_store_magnet (FILE *f, const struct download *d)
void download_store_magnets (void)
void download_store_if_dirty (void)
 Store pending download if needed.
gboolean download_retrieve_magnets (FILE *f)
void download_retrieve_old (FILE *f)
void download_moved_with_bad_sha1 (struct download *d)
 Post renaming/moving routine called when download had a bad SHA1.
void download_move (struct download *d, const gchar *dir, const gchar *ext)
 Main entry point to move the completed file `d' to target directory `dir'.
void download_move_start (struct download *d)
 Called when the moving daemon task starts processing a download.
void download_move_progress (struct download *d, filesize_t copied)
 Called to register the current moving progress.
void download_move_done (struct download *d, const gchar *pathname, guint elapsed)
 Called when file has been moved/renamed with its fileinfo trailer stripped.
void download_move_error (struct download *d)
 Called when we cannot move the file (I/O error, etc...).
void download_verify_start (struct download *d)
 Called when the verification daemon task starts processing a download.
void download_verify_progress (struct download *d, guint32 hashed)
 Called to register the current verification progress.
void download_verify_done (struct download *d, const struct sha1 *sha1, guint elapsed)
 Called when download verification is finished and digest is known.
void download_verify_error (struct download *d)
 Called when we cannot verify the SHA1 for the file (I/O error, etc...).
gboolean download_verify_callback (const struct verify *ctx, enum verify_status status, void *user_data)
void download_close (void)
 Terminating processing, cleanup data structures.
gchar * download_url_for_uri (const struct download *d, const gchar *uri)
gchar * download_build_url (const struct download *d)
 Creates a URL which points to a downloads (e.g.
const gchar * download_get_hostname (const struct download *d)
gint download_get_http_req_percent (const struct download *d)
gboolean download_something_to_clear (void)
 Checks unqueued list to see if there are any downloads that are finished and therefore ready to be cleared.
downloaddownload_browse_start (const gchar *hostname, host_addr_t addr, guint16 port, const gchar *guid, const gnet_host_vec_t *proxies, gnet_search_t search, guint32 flags)
 Create special non-persisted download that will request "/" on the remote host and expect a stream of Gnutella query hits back.
void download_thex_done (struct download *d)
downloaddownload_thex_start (const gchar *uri, const struct sha1 *sha1, const struct tth *tth, filesize_t filesize, const gchar *hostname, host_addr_t addr, guint16 port, const gchar *guid, const gnet_host_vec_t *proxies, guint32 flags)
 Create special non-persisted download that will request THEX data from the remote host.
void download_abort_browse_host (struct download *d, gnet_search_t sh)
 Abort browse-host download when corresponding search is closed.
void download_got_eof (struct download *d)
 Called when an EOF is received during data reception.
void download_rx_done (struct download *d)
 Called when all data has been received.
void download_data_received (struct download *d, ssize_t received)
 Called when more data has been received on the RX stack, for non-file downloads (e.g.
void download_maybe_finished (struct download *d)
 Called when all the received data so far have been processed to check whether we are done.
guint download_handle_magnet (const gchar *url)
gboolean download_handle_http (const gchar *url)
guint download_speed_avg (struct download *d)
gboolean download_is_stalled (struct download *d)

Variables

hash_list_tsl_downloads
 All downloads (queued + unqueued).
hash_list_tsl_unqueued
 Unqueued downloads only.
GSList * sl_removed
 Removed downloads only.
GSList * sl_removed_servers
 Removed servers only.
gchar dl_tmp [4096]
const gchar DL_OK_EXT [] = ".OK"
 Extension to mark OK files.
const gchar DL_BAD_EXT [] = ".BAD"
 "Bad" files (SHA1 mismatch)
const gchar DL_UNKN_EXT [] = ".UNKN"
 For unchecked files.
const gchar no_reason [] = "<no reason>"
 Don't translate this.
gboolean download_dirty = FALSE
GHashTable * dl_by_host = NULL
GHashTable * dl_count_by_name = NULL
struct {
   GList *   servers [DHASH_SIZE]
 Lists of servers, by retry time.
   gint   change [DHASH_SIZE]
 Counts changes to the list.
dl_by_time
GHashTable * dl_by_addr = NULL
 To handle download meshes, where we only know the IP/port of the host and not its GUID, we need to be able to locate the server.
guint dl_establishing = 0
 Establishing downloads.
guint dl_active = 0
 Active downloads.
eventsrc_events [EV_SRC_EVENTS]
idtable_tsrc_handle_map = NULL
const struct rx_link_cb download_rx_link_cb
const struct rx_chunk_cb download_rx_chunk_cb
const struct rx_inflate_cb download_rx_inflate_cb
io_error download_io_error
const gchar download_file [] = "downloads"
const gchar file_what [] = "downloads"
 What is persisted to file.
gboolean retrieving = FALSE


Define Documentation

#define DHASH_MASK   (DHASH_SIZE - 1)
 

#define DHASH_SIZE   (1UL << 10)
 

Hash list size, must be a power of 2.

#define DL_HASH  )     ((x) & DHASH_MASK)
 

#define DOWNLOAD_DATA_TIMEOUT   5
 

Max # of data timeouts we allow.

#define DOWNLOAD_DNS_LOOKUP   7200
 

Period of server DNS lookups.

#define DOWNLOAD_FILE_MODE   (S_IRUSR | S_IWUSR | S_IRGRP)
 

#define DOWNLOAD_MAX_HEADER_EOF   5
 

Max # of EOF in headers we allow.

#define DOWNLOAD_MAX_IGN_DATA   2097152
 

Max amount of data to ignore.

#define DOWNLOAD_MAX_IGN_REQS   3
 

How many mismatches per source.

#define DOWNLOAD_MAX_IGN_TIME   300
 

Max amount of secs we can ignore.

#define DOWNLOAD_MAX_SINK   16384
 

Max amount of data to sink.

#define DOWNLOAD_MIN_OVERLAP   64
 

Minimum overlap for safety.

#define DOWNLOAD_PING_DELAY   300
 

Minimum delay for 2 HEAD pings.

#define DOWNLOAD_SERVER_HOLD   15
 

Space requests to same server.

#define DOWNLOAD_SHORT_DELAY   2
 

Shortest retry delay.

#define DOWNLOAD_STALLED   60
 

Consider stalled after 60 secs.

#define IO_AVG_RATE   5
 

Compute global recv rate every 5 secs.

#define MAGIC_TIME   1
 

For recreation upon starup.


Function Documentation

struct dl_server* allocate_server const gchar *  guid,
const host_addr_t  addr,
guint16  port
[static]
 

Allocate new server structure.

void buffers_add_read struct download d,
pmsg_t mb
[static]
 

Update the buffer structure after having read "amount" more bytes: prepare `iovcnt' for the next read and increase the amount of data held.

void buffers_alloc struct download d  )  [static]
 

Allocate a set of buffers for data reception.

void buffers_check_held const struct download d  )  [static]
 

void buffers_discard struct download d  )  [inline, static]
 

Discard all read data from buffers.

void buffers_free struct download d  )  [static]
 

Dispose of the buffers used for reading.

void buffers_free_item gpointer  data,
gpointer  unused_udata
[static]
 

gboolean buffers_full const struct download d  )  [inline, static]
 

Check whether reception buffers are full.

gboolean buffers_match const struct download d,
const gchar *  data,
size_t  len
[static]
 

Compare data held in the read buffers with the data chunk supplied.

Returns:
TRUE if data match.

void buffers_reset_reading struct download d  )  [static]
 

Reset the I/O vector for reading from the start.

gboolean buffers_should_flush const struct download d  )  [inline, static]
 

Check whether we should request flushing of the buffered data.

void buffers_strip_leading struct download d,
size_t  amount
[static]
 

Strip leading `amount' bytes from the read buffers.

void buffers_strip_trailing struct download d,
size_t  amount
[static]
 

Strip trailing `amount' bytes from the read buffers.

struct iovec* buffers_to_iovec struct download d,
gint *  iov_cnt
[static]
 

Reset the I/O vector for writing the whole data held in the buffer.

void call_download_push_ready gpointer  o,
header_t unused_header
[static]
 

void call_download_request gpointer  o,
header_t header
[static]
 

struct download* cast_to_download gpointer  p  )  [inline, static]
 

void change_server_addr struct dl_server server,
const host_addr_t  new_addr
[static]
 

The server address changed.

void check_date const header_t header,
const host_addr_t  addr,
struct download d
[static]
 

Look for a Date: header in the reply and use it to update our skew.

void check_push_proxies struct download d,
header_t header
[static]
 

Extract host:port information out of X-Push-Proxy if present and update the server's list.

void check_xhost struct download d,
const header_t header
[static]
 

Look for an X-Host header in the reply.

If we get one, then it means the remote server is not firewalled and can be reached there.

We only pay attention to such headers for pushed downloads.

void check_xhostname struct download d,
const header_t header
[static]
 

Look for an X-Hostname header in the reply.

If we get one, then it means the remote server is not firewalled and can be reached there, using the symbolic hostname given.

gboolean content_range_check struct download d,
header_t header
[static]
 

guint count_running_downloads void   )  [inline, static]
 

guint count_running_downloads_with_name const char *  name  )  [static]
 

How many downloads with same filename are running (active or establishing)?

guint count_running_on_server const struct dl_server server  )  [inline, static]
 

struct download* create_download const gchar *  file_name,
const gchar *  uri,
filesize_t  size,
const host_addr_t  addr,
guint16  port,
const gchar *  guid,
const gchar *  hostname,
const struct sha1 sha1,
time_t  stamp,
fileinfo_t file_info,
const gnet_host_vec_t proxies,
guint32  cflags,
const gchar *  parq_id
[static]
 

Create a new download.

Returns:
created download structure, or NULL if none.

gint dl_addr_eq gconstpointer  a,
gconstpointer  b
[static]
 

Comparison of `dl_addr' structures.

guint dl_addr_hash gconstpointer  key  )  [static]
 

Hashing of a `dl_addr' structure.

void dl_by_time_insert struct dl_server server  )  [static]
 

Insert server by retry time into the `dl_by_time' structure.

void dl_by_time_remove struct dl_server server  )  [static]
 

Remove server from the `dl_by_time' structure.

gint dl_key_eq gconstpointer  a,
gconstpointer  b
[static]
 

Comparison of `dl_key' structures.

guint dl_key_hash gconstpointer  key  )  [static]
 

Hashing of a `dl_key' structure.

gint dl_retry_cmp gconstpointer  p,
gconstpointer  q
[static]
 

Compare two `download' structures based on the `retry_after' field.

The smaller that time, the smaller the structure is.

gint dl_server_retry_cmp gconstpointer  p,
gconstpointer  q
[static]
 

Compare two `dl_server' structures based on the `retry_after' field.

The smaller that time, the smaller the structure is.

void download_abort struct download d  ) 
 

Abort download (forget about it) AND delete file if we removed the last reference to it and they want to delete on abort.

void download_abort_browse_host struct download d,
gnet_search_t  sh
 

Abort browse-host download when corresponding search is closed.

void download_actively_queued struct download d,
gboolean  queued
 

Mark a download as being actively queued.

void download_add_to_list struct download d,
enum dl_list  idx
[static]
 

struct download* download_alloc void   )  [static]
 

The only place to allocate a struct download.

void download_auto_new const gchar *  file_name,
filesize_t  size,
const host_addr_t  addr,
guint16  port,
const gchar *  guid,
const gchar *  hostname,
const struct sha1 sha1,
time_t  stamp,
fileinfo_t fi,
gnet_host_vec_t proxies,
guint32  flags
 

Automatic download request.

void download_backout struct download d  )  [static]
 

Forget that we ever downloaded some bytes when there was a resuming mismatch at some point.

void download_bad_source struct download d  )  [static]
 

Indicates that this download source is not good enough for us: it is either non-connectible, does not allow resuming, etc...

Remove it from the mesh.

const gchar* download_basename const struct download d  ) 
 

struct download* download_browse_start const gchar *  hostname,
host_addr_t  addr,
guint16  port,
const gchar *  guid,
const gnet_host_vec_t proxies,
gnet_search_t  search,
guint32  flags
 

Create special non-persisted download that will request "/" on the remote host and expect a stream of Gnutella query hits back.

Those query hits will be feed back to the search given as parameter for display.

Parameters:
hostname the DNS name of the host, or NULL if none known
addr the IP address of the host to browse
port the port to contact
guid the GUID of the remote host
push whether a PUSH request is neeed to reach remote host
proxies vector holding known push-proxies
search the search we have to send back query hits to.
Returns:
created download, or NULL on error.

gchar* download_build_magnet const struct download d  ) 
 

gchar* download_build_url const struct download d  ) 
 

Creates a URL which points to a downloads (e.g.

you can move this to a browser and download the file there with this URL).

Returns:
NULL on failure, an URL string which must be freed with g_free().

gboolean download_can_ignore struct download d  )  [static]
 

See whether we can ignore the data from now on, keeping the connection open and sinking to /dev/null: the idea is that we keep the slot busy to get a chance to re-issue another request later.

Returns:
TRUE if we successfully setup the downloaded data to be ignored.

gboolean download_check_status struct download d,
getline_t line,
gint  code
[static]
 

Check status code from status line.

Returns:
TRUE if we can continue.

void download_chunk_rx_done gpointer  o  )  [static]
 

void download_clear_stopped gboolean  complete,
gboolean  failed,
gboolean  unavailable,
gboolean  now
 

[GUI] Remove stopped downloads.

complete == TRUE: removes DONE | COMPLETED failed == TRUE: removes ERROR | ABORTED without `unavailable' set unavailable == TRUE: removes ERROR | ABORTED with `unavailable' set now == TRUE: remove immediately, else remove only downloads idle since at least "entry_removal_timeout" seconds

struct download* download_clone struct download d  )  [static]
 

Clone download, resetting most dynamically allocated structures in the original since they are shallow-copied to the new download.

(This routine is used because each different download from the same host will become a line in the GUI, and the GUI stores download structures in ts row data, expecting a one-to-one mapping between a download and the GUI).

void download_close void   ) 
 

Terminating processing, cleanup data structures.

struct gnutella_socket* download_connect struct download d  )  [static]
 

Establish asynchronous connection to remote server.

Returns:
connecting socket.

void download_connected struct download d  ) 
 

This function is called once a connection has been established.

void download_continue struct download d,
gboolean  trimmed
[static]
 

Called when a chunk has been fully received but the file is still incomplete and more data is to be fetched.

Continue downloading from this source, now that the previous chunk was fully received: if the connection was flagged "keep alive", go on with the next request.

Parameters:
d the download source whose request has been completed
trimmed whether we had to trim the tail of the received data

gboolean download_convert_to_urires struct download d  )  [static]
 

Convert download to /uri-res/N2R? request.

This is called when we have a /get/index/name URL for the download, yet we attempted a GET /uri-res/ and either got a 503, or a 2xx return code. This means the remote server understands /uri-res/ with high probability.

Converting the download to /uri-res/N2R? means that we get rid of the old index/name information in the download structure and replace it with URN_INDEX/URN. Indeed, to access the download, we only need to issue a /uri-res request from now on.

As a side effect, we remove the old index/name information from the download mesh as well.

Returns:
TRUE if OK, FALSE if we stopped the download because we finally spotted it as being a duplicate!

gboolean download_data_ind rxdrv_t rx,
pmsg_t mb
[static]
 

RX data indication callback used to give us some new download traffic in a low-level message structure.

Returns:
FALSE if an error occurred.

void download_data_received struct download d,
ssize_t  received
 

Called when more data has been received on the RX stack, for non-file downloads (e.g.

when issuing a browse host request), so that we update the download structure for accurate GUI feedback.

gboolean download_eq gconstpointer  p,
gconstpointer  q
[static]
 

const gchar* download_escape_name const gchar *  name  )  [static]
 

void download_fallback_to_push struct download d,
gboolean  on_timeout,
gboolean  user_request
 

Direct download failed, let's try it with a push request.

gboolean download_file_exists const struct download d  ) 
 

Returns:
whether the download file exists in the temporary directory.

struct download* download_find_waiting_unparq const host_addr_t  addr,
guint16  port
 

Find a waiting download on the specified server, identified by its IP:port for which we have no PARQ information yet.

Returns:
NULL if none, the download we found otherwise.

gboolean download_flush struct download d,
gboolean *  trimmed,
gboolean  may_stop
[static]
 

Flush buffered data to disk.

Parameters:
d the download to flush
trimmed if not NULL, filled with whether we trimmed data or not
may_stop whether we can stop the download on errors
Returns:
TRUE if OK, FALSE on failure.

writev() and others do not necessarily flush the complete buffer to disk, especially if the configured buffer size is large. As this is not handled gracefully i.e., the non-flushed buffer content would be discarded, we loop here until the complete buffer has been flushed or an error occurs. With large buffer sizes or a slow disk, this may of course increase the latency and cause some stalling. The right thing to do would be keeping the buffered data and attempting another flush next time.

void download_forget struct download d,
gboolean  unavailable
 

Forget about download: stop it if running.

When `unavailable' is TRUE, mark the download as unavailable.

void download_free struct download **  d_ptr  )  [static]
 

The only place to release a struct download.

The pointer will be nullified to prevent further access of the memory chunk through this pointer.

Parameters:
d_ptr Pointer to a pointer holding a struct download.

void download_free_removed void   ) 
 

Free all downloads listed in the `sl_removed' list.

void download_freeze_queue void   ) 
 

Freeze the scheduling queue.

Multiple freezing requires multiple thawing.

const gchar* download_get_hostname const struct download d  ) 
 

gint download_get_http_req_percent const struct download d  ) 
 

gboolean download_get_server_name struct download d,
header_t header
[static]
 

Extract server name from headers.

Returns:
whether new server name was found.

const struct sha1* download_get_sha1 const struct download d  )  [inline, static]
 

void download_got_eof struct download d  ) 
 

Called when an EOF is received during data reception.

gboolean download_handle_http const gchar *  url  ) 
 

guint download_handle_magnet const gchar *  url  ) 
 

void download_handle_thex_uri_header struct download d,
header_t header
[static]
 

gboolean download_has_blank_guid const struct download d  ) 
 

gboolean download_has_enough_active_sources struct download d  )  [static]
 

gboolean download_ignore_data struct download d,
pmsg_t mb
[static]
 

Read callback for file data from the RX stack, used when we ignore those data after a failed resuming check.

gboolean download_ignore_data_ind rxdrv_t rx,
pmsg_t mb
[static]
 

RX data indication callback used to give us some new download traffic in a low-level message structure.

Returns:
FALSE if an error occurred.

gboolean download_ignore_requested struct download d  )  [static]
 

Check whether download should be ignored, and stop it immediately if it is.

Returns:
whether download was stopped (i.e. if it must be ignored).

void download_incomplete_header struct download d  )  [static]
 

Called when header reading times out.

void download_index_changed const host_addr_t  addr,
guint16  port,
const gchar *  guid,
guint32  from,
guint32  to
 

Search has detected index change in queued download.

void download_info_change_all fileinfo_t old_fi,
fileinfo_t new_fi
 

Change all the fileinfo of downloads from `old_fi' to `new_fi'.

All running downloads are requeued immediately, since a change means the underlying file we're writing to can change.

void download_info_reget struct download d  )  [static]
 

Invalidate improper fileinfo for the download, and get new one.

This usually happens when we discover the SHA1 of the file on the remote server, and see that it does not match the one for the associated file on disk, as described in `file_info'.

void download_init void   ) 
 

Initialize downloading data structures.

gboolean download_is_stalled struct download d  ) 
 

Returns:
whether download is stalled, not having received data for some time now.

void download_list_send_head_ping list_t list  )  [static]
 

Send a HEAD Ping to all the downloads in the list.

void download_mark_active struct download d  )  [static]
 

Mark download as receiving data: download is becoming active.

void download_maybe_finished struct download d  ) 
 

Called when all the received data so far have been processed to check whether we are done.

void download_move struct download d,
const gchar *  dir,
const gchar *  ext
[static]
 

Main entry point to move the completed file `d' to target directory `dir'.

In case the target directory is the same as the source, the file is simply renamed with the extension `ext' appended to it.

void download_move_done struct download d,
const gchar *  pathname,
guint  elapsed
 

Called when file has been moved/renamed with its fileinfo trailer stripped.

void download_move_error struct download d  ) 
 

Called when we cannot move the file (I/O error, etc...).

void download_move_progress struct download d,
filesize_t  copied
 

Called to register the current moving progress.

void download_move_start struct download d  ) 
 

Called when the moving daemon task starts processing a download.

void download_move_to_list struct download d,
enum dl_list  idx
[static]
 

Move download from its current list to the `idx' one.

gboolean download_moved_permanently struct download d,
header_t header
 

Refresh IP:port, download index and name, by looking at the new location in the header ("Location:").

Returns:
TRUE if we managed to parse the new location.

void download_moved_with_bad_sha1 struct download d  )  [static]
 

Post renaming/moving routine called when download had a bad SHA1.

gboolean download_new const gchar *  filename,
const gchar *  uri,
filesize_t  size,
const host_addr_t  addr,
guint16  port,
const gchar *  guid,
const gchar *  hostname,
const struct sha1 sha1,
time_t  stamp,
fileinfo_t fi,
const gnet_host_vec_t proxies,
guint32  flags,
const gchar *  parq_id
 

Create a new download, usually called from an interactive user action.

Returns:
whether download was created.

void download_new_by_hostname struct download_request req  )  [static]
 

void download_new_by_hostname_helper const host_addr_t addrs,
size_t  n,
gpointer  user_data
[static]
 

Called when we got a reply from the ADNS process.

Todo:
TODO: All resolved addresses should be attempted.

void download_orphan_new const gchar *  filename,
filesize_t  size,
const struct sha1 sha1,
fileinfo_t fi
 

Fake a new download for an existing file that is marked complete in its fileinfo trailer.

gboolean download_overlap_check struct download d  )  [static]
 

Check that the leading overlapping data in the read buffers match with the last ones in the downloaded file.

Then remove them.

Returns:
TRUE if the data match, FALSE if they don't, in which case the download is stopped.

void download_passively_queued struct download d,
gboolean  queued
[static]
 

Mark download as being passively queued.

const gchar* download_pathname const struct download d  ) 
 

void download_pause struct download d  ) 
 

Pause a download.

gboolean download_pick_available struct download d  )  [static]
 

Pickup a range we don't have yet from the available ranges.

Returns:
TRUE if we selected a chunk, FALSE if we can't select a chunk (e.g. we have everything the remote server makes available).

gboolean download_pick_chunk struct download d  )  [static]
 

Called for swarming downloads when we are connected to the remote server, but before making the request, to pick up a chunk for downloading.

Returns:
TRUE if we can continue with the download, FALSE if it has been stopped.

void download_pickup_queued void   ) 
 

Pick up new downloads from the queue as needed.

void download_proxy_failed struct download d  ) 
 

Called by client push-proxy side to indicate that it could not send a PUSH.

void download_proxy_newstate struct download d  ) 
 

Called when the status of the HTTP request made by the client push-proxy code changes.

void download_proxy_sent struct download d  ) 
 

Called by client push-proxy side when we got indication that the PUSH has been sent.

void download_push struct download d,
gboolean  on_timeout
[static]
 

void download_push_ack struct gnutella_socket s  ) 
 

Initiate download on the remotely initiated connection.

This is called when an incoming "GIV" request is received in answer to some of our pushes.

void download_push_insert struct download d  )  [static]
 

Record that we sent a push request for this download.

void download_push_ready struct download d,
getline_t empty
[static]
 

Send download request on the opened connection.

Header processing callback, invoked when we have read the second "\n" at the end of the GIV string.

void download_push_remove struct download d  )  [static]
 

Forget that we sent a push request for this download.

void download_queue struct download d,
const gchar *  fmt,
  ...
 

Put download into queue.

void download_queue_delay struct download d,
guint32  delay,
const gchar *  fmt,
  ...
[static]
 

Put download back to queue, but don't reconsider it for starting before the next `delay' seconds.

-- RAM, 03/09/2001

void download_queue_hold struct download d,
guint32  hold,
const gchar *  fmt,
  ...
[static]
 

Same as download_queue_delay(), but make sure we don't consider scheduling any currently queued download to this server before the holding delay.

void download_queue_hold_delay_v struct download d,
gint  delay,
time_t  hold,
const gchar *  fmt,
va_list  ap
[static]
 

Common vectorized code for download_queue_delay() and download_queue_hold().

gboolean download_queue_is_frozen void   ) 
 

Test whether download queue is frozen.

void download_queue_v struct download d,
const gchar *  fmt,
va_list  ap
[static]
 

The vectorized (message-wise) version of download_queue().

gboolean download_read struct download d,
pmsg_t mb
[static]
 

Read callback for file data from the RX stack.

void download_reclaim_server struct download d,
gboolean  delayed
[static]
 

Reclaim download's server if it is no longer holding anything.

If `delayed' is true, we're performing a batch free of downloads.

void download_redirect_to_server struct download d,
const host_addr_t  addr,
guint16  port
 

Move download from a server to another when the IP:port changed due to a Location: redirection for instance, or because of a QUEUE callback.

gboolean download_remove struct download d  ) 
 

Freeing a download cannot be done simply, because it might happen when we are traversing the `sl_downloads' or `sl_unqueued' lists.

Therefore download_free() marks the download as "removed" and frees some of the memory used, but does not reclaim the download structure yet, nor does it remove it from the lists.

The "freed" download is marked GTA_DL_REMOVED and is put into the `sl_removed' list where it will be reclaimed later on via download_free_removed().

gint download_remove_all_from_peer const gchar *  guid,
const host_addr_t  addr,
guint16  port,
gboolean  unavailable
 

Remove all downloads to a given peer from the download queue and abort all connections to peer in the active download list.

When `unavailable' is TRUE, the downloads are marked unavailable, so that they can be cleared up differently by the GUI .

Returns:
the number of removed downloads.

gint download_remove_all_named const gchar *  name  ) 
 

Remove all downloads with a given name from the download queue and abort all connections to peer in the active download list.

Returns:
the number of removed downloads.

void download_remove_all_thex const struct sha1 sha1  )  [static]
 

Remove all THEX downloads for a given sha1.

gint download_remove_all_with_sha1 const struct sha1 sha1  ) 
 

remove all downloads with a given sha1 hash from the download queue and abort all conenctions to peer in the active download list.

Returns:
the number of removed downloads.
Note:
If sha1 is NULL, we do not clear all download with sha1==NULL but abort instead.

void download_remove_file struct download d,
gboolean  reset
 

Remove temporary download file.

Optionally reset the fileinfo if unlinking is successful and `reset' is TRUE. The purpose of resetting on unlink is to prevent the fileinfo from being discarded at the next relaunch (we discard non-reset fileinfos when the file is missing).

void download_remove_from_server struct download d,
gboolean  reclaim
[static]
 

Remove download from server.

Reclaim server if this was the last download held and `reclaim' is true.

void download_reparent struct download d,
struct dl_server new_server
[static]
 

Move download from a server to another one.

void download_request struct download d,
header_t header,
gboolean  ok
[static]
 

Called to initiate the download once all the HTTP headers have been read.

If `ok' is false, we timed out reading the header, and have therefore something incomplete.

Validate the reply, and begin saving the incoming data if OK. Otherwise, stop the download.

void download_request_free struct download_request **  req_ptr  )  [static]
 

struct download_request* download_request_new const gchar *  filename,
const gchar *  uri,
filesize_t  size,
host_addr_t  addr,
guint16  port,
const gchar *  guid,
const gchar *  hostname,
const struct sha1 sha1,
time_t  stamp,
fileinfo_t fi,
guint32  flags,
const gnet_host_vec_t proxies,
const gchar *  parq_id
[static]
 

void download_request_sent struct download d  )  [static]
 

Called when the whole HTTP request has been sent out.

void download_requeue struct download d  ) 
 

Explicitly re-enqueue potentially stopped download.

void download_restore_state void   ) 
 

Initialize downloading data structures.

void download_resume struct download d  ) 
 

void download_resume_bg_tasks void   )  [static]
 

Go through the downloads and check the completed ones that should be either moved to the "done" directory, or which should have their SHA1 computed/verified.

void download_retrieve void   )  [static]
 

Retrieve download list and requeue each download.

The downloads are normally retrieved from ~/.gtk-gnutella/downloads.

gboolean download_retrieve_magnets FILE *  f  )  [static]
 

void download_retrieve_old FILE *  f  )  [static]
 

void download_retry struct download d  )  [static]
 

Called to request retry of a download after a timeout, with exponential back-off timeout delay, up to a maximum.

void download_rx_done struct download d  ) 
 

Called when all data has been received.

void download_rx_got_eof gpointer  o  )  [static]
 

void download_send_head_ping struct download d  )  [static]
 

Send a HEAD Ping vendor message to node to get alternate sources via UDP since we're not going to issue an HTTP request right now.

gboolean download_send_push_request struct download d  )  [static]
 

Send a push request to the target GUID, in order to request the push of the file whose index is `file_id' there onto our local port `port'.

We're very aggressive: we send a PUSH via UDP to the host itself, as well as all the known push proxies. We also broadcast to the proper routes on Gnutella.

Returns:
TRUE if the request could be sent, FALSE if we don't have the route.

void download_send_request struct download d  ) 
 

Send the HTTP request for a download, then prepare I/O reading callbacks to read the incoming status line and following headers.

Attention:
NB: can stop the download, but does not return anything.

gboolean download_server_nopush const gchar *  guid,
const host_addr_t  addr,
guint16  port
 

Check whether we can safely ignore Push indication for this server, identified by its GUID, IP and port.

void download_server_retry_after struct dl_server server,
time_t  now,
gint  hold
[static]
 

Change the `retry_after' field of the host where this download runs.

If a non-zero `hold' is specified, make sure nothing will be scheduled from this server before the next `hold' seconds.

void download_set_sha1 struct download d,
const struct sha1 sha1
[static]
 

void download_set_socket_rx_size gint  rx_size  ) 
 

Change the socket RX buffer size for all the currently connected downloads.

void download_sink struct download d  )  [static]
 

Sink read data.

Used when waiting for the end of the previous HTTP reply.

When all the data has been sunk, issue the next HTTP request.

void download_sink_read gpointer  data,
gint  unused_source,
inputevt_cond_t  unused_cond
[static]
 

Read callback for file data.

gboolean download_something_to_clear void   ) 
 

Checks unqueued list to see if there are any downloads that are finished and therefore ready to be cleared.

gdouble download_source_progress const struct download d  ) 
 

Return the total progress of a download source.

The range on the return value should be 0..1 but there is no guarantee.

Same as download_total_progress() if source is not receiving.

Parameters:
d The download structure which we are interested in knowing the progress of.
Returns:
The percent completed for this source, or zero if the source is not receiving at the moment.

guint download_speed_avg struct download d  ) 
 

Returns:
average download speed overall for the server, and if not available yet, for this particular source if it is active.

void download_start struct download d,
gboolean  check_allowed
 

(Re)start a stopped or queued download.

gboolean download_start_prepare struct download d  ) 
 

Make download a "running" one (in running list, unqueued), then call download_start_prepare_running().

Returns:
TRUE if we may continue with the download, FALSE if it has been stopped due to a problem.

gboolean download_start_prepare_running struct download d  ) 
 

Setup the download structure with proper range offset, and check that the download is not otherwise completed.

Returns:
TRUE if we may continue with the download, FALSE if it has been stopped due to a problem.

void download_start_reading gpointer  o  )  [static]
 

void download_stop struct download d,
download_status_t  new_status,
const gchar *  reason,
  ...
 

Stop an active download, close its socket and its data file descriptor.

void download_stop_v struct download d,
download_status_t  new_status,
const gchar *  reason,
va_list  ap
 

Vectorized version common to download_stop() and download_unavailable().

void download_store void   )  [static]
 

Store all pending downloads.

The downloads are normally stored in ~/.gtk-gnutella/downloads.

void download_store_if_dirty void   ) 
 

Store pending download if needed.

The fileinfo database is also flushed if dirty, but only when the downloads themselves are stored. Since both are linked via SHA1 and name, it's best to try to keep them in sync.

void download_store_magnet FILE *  f,
const struct download d
[static]
 

void download_store_magnets void   )  [static]
 

void download_thaw_queue void   ) 
 

Thaw the scheduling queue.

Multiple freezing requires multiple thawing.

void download_thex_done struct download d  )  [static]
 

struct download* download_thex_start const gchar *  uri,
const struct sha1 sha1,
const struct tth tth,
filesize_t  filesize,
const gchar *  hostname,
host_addr_t  addr,
guint16  port,
const gchar *  guid,
const gnet_host_vec_t proxies,
guint32  flags
 

Create special non-persisted download that will request THEX data from the remote host.

Parameters:
uri the URI to request
hostname the DNS name of the host, or NULL if none known
addr the IP address of the host
port the port to contact
guid the GUID of the remote host
push whether a PUSH request is neeed to reach remote host
proxies vector holding known push-proxies
Returns:
created download, or NULL on error.

void download_timer time_t  now  ) 
 

Download heartbeat timer.

gdouble download_total_progress const struct download d  ) 
 

Return the total progress of a download.

The range on the return value should be 0..1 but there is no guarantee.

Parameters:
d The download structure which we are interested in knowing the progress of.
Returns:
The total percent completed for this file.

void download_unavailable struct download d,
download_status_t  new_status,
const gchar *  reason,
  ...
[static]
 

Like download_stop(), but flag the download as "unavailable".

void download_unqueue struct download d  )  [static]
 

Remove download from queue.

It is put in a state where it can be stopped if necessary.

void download_update_timeout_delay struct download d  )  [static]
 

Sets proper timeout delay, with exponential back-off and min/max enforcement.

NB: This routine must be invoked before download_stop() is called because it uses the d->start_date field which is reset there.

gchar* download_url_for_uri const struct download d,
const gchar *  uri
[static]
 

gboolean download_verify_callback const struct verify ctx,
enum verify_status  status,
void *  user_data
[static]
 

void download_verify_done struct download d,
const struct sha1 sha1,
guint  elapsed
[static]
 

Called when download verification is finished and digest is known.

void download_verify_error struct download d  )  [static]
 

Called when we cannot verify the SHA1 for the file (I/O error, etc...).

void download_verify_progress struct download d,
guint32  hashed
[static]
 

Called to register the current verification progress.

void download_verify_sha1 struct download d  )  [static]
 

Main entry point for verifying the SHA1 of a completed download.

void download_verify_start struct download d  )  [static]
 

Called when the verification daemon task starts processing a download.

void download_write struct download d,
gpointer  data,
size_t  len
[static]
 

Received data from outside the RX stack.

gboolean download_write_data struct download d  )  [static]
 

Write data in socket buffer to file.

Returns:
FALSE if an error occurred.

void download_write_request gpointer  data,
gint  unused_source,
inputevt_cond_t  cond
[static]
 

I/O callback invoked when we can write more data to the server to finish sending the HTTP request.

void downloads_with_name_dec const gchar *  name  )  [static]
 

Remove one from the amount of downloads running and bearing the filename.

void downloads_with_name_inc const gchar *  name  )  [static]
 

Add one to the amount of downloads running and bearing the filename.

void err_header_error gpointer  o,
gint  error
[static]
 

void err_header_read_eof gpointer  o  )  [static]
 

void err_header_read_error gpointer  o,
gint  error
[static]
 

void err_input_buffer_full gpointer  o  )  [static]
 

void err_line_too_long gpointer  o  )  [static]
 

guint extract_retry_after struct download d,
const header_t header
 

Extract Retry-After delay from header, returning 0 if none.

void free_proxies struct dl_server server  )  [static]
 

Get rid of the list of push proxies held in the server.

void free_server struct dl_server server  )  [static]
 

Free server structure.

G_GNUC_PRINTF ,
[static]
 

guint32 get_index_from_uri const gchar *  uri  )  [static]
 

struct dl_server* get_server const gchar *  guid,
const host_addr_t  addr,
guint16  port,
gboolean  allocate
[static]
 

Fetch server entry identified by IP:port first, then GUID+IP:port.

Returns:
server, allocated if needed when allocate is TRUE.

gboolean handle_content_urn struct download d,
header_t header
[static]
 

Handle X-Gnutella-Content-URN header.

Returns:
FALSE if we cannot continue with the download.

LimeWire emits a X-Gnutella-Content-Urn header with the SHA-1 of the file described by the THEX data. Thus the SHA-1 won't match the THEX data we are actually downloading. As there are many LimeWire clones we cannot just check the Server/User-Agent header.

gboolean has_blank_guid const struct download d  )  [static]
 

Returns:
whether download has a blank (fake) GUID.

gboolean has_good_sha1 const struct download d  )  [static]
 

Was downloaded file verified to have a SHA1 matching the advertised one?

struct download* has_same_download const gchar *  file,
const struct sha1 sha1,
filesize_t  size,
const gchar *  guid,
const host_addr_t  addr,
guint16  port
[static]
 

Check whether we already have an identical (same file, same SHA1, same host) running or queued download.

Returns:
found active download, or NULL if we have no such download yet.

GSList* hostvec_to_slist const gnet_host_vec_t vec  )  [static]
 

Convert a vector of host to a single-linked list.

Returns:
new list, with every item cloned.

gboolean is_dumb_spammer const gchar *  user_agent  )  [static]
 

Checks whether the contents of a User-Agent or Server header match the signature of a dumb spammer.

Parameters:
user_agent Value of a User-Agent respectively Server header.
Returns:
TRUE if the given User-Agent string is known to be used by spammers only, FALSE otherwise.

gboolean is_faked_download const struct download d  ) 
 

Returns:
whether download was faked to reparent a complete orphaned file.

const gchar* lazy_ack_message_to_ui_string const gchar *  src  )  [static]
 

gboolean parse_giv const gchar *  line,
gchar *  hex_guid,
size_t  size
[static]
 

Returns:
FALSE on failure, TRUE if the GIV was successfully parsed.

void queue_remove_downloads_with_file fileinfo_t fi,
struct download skip
[static]
 

Removes all downloads that point to the file_info struct.

If `skip' is non-NULL, that download is skipped.

void queue_suspend_downloads_with_file fileinfo_t fi,
gboolean  suspend
[static]
 

Mark all downloads that point to the file_info struct as "suspended" if `suspend' is TRUE, or clear that mark if FALSE.

void remove_proxy struct dl_server server,
const host_addr_t  addr,
guint16  port
[static]
 

Remove push proxy from server.

void select_matching_servers gpointer  key,
gpointer  value,
gpointer  user
[static]
 

If server is matching the selection criteria, insert it in the result set.

This routine is a hash table iterator callback.

struct download* select_push_download GSList *  servers  )  [static]
 

On reception of a "GIV index:GUID" string, select the appropriate download to request, from the list of potential server targets.

Returns:
the selected download, or NULL if we could not find one.

GSList* select_servers const gchar *  guid,
const host_addr_t  addr,
gint *  count
[static]
 

Given a servent GUID and an IP address, build a list of all the servents that bear either this GUID or that IP address.

Returns:
a list a servers matching, with `count' being updated with the amount of matching servers we found.
Note:
It is up to the caller to g_slist_free() the returned list.

gboolean send_udp_push const struct array  packet,
host_addr_t  addr,
guint16  port
[static]
 

void server_delay_delete struct dl_server server  )  [static]
 

Marks server for delayed removal (via asynchronous timer).

void server_list_append_download struct dl_server server,
enum dl_list  idx,
struct download d
[static]
 

list_t* server_list_by_index struct dl_server server,
enum dl_list  idx
[static]
 

void server_list_free_all struct dl_server server  )  [static]
 

struct download* server_list_head struct dl_server server,
enum dl_list  idx
[static]
 

void server_list_insert_download_sorted struct dl_server server,
enum dl_list  idx,
struct download d
[static]
 

guint server_list_length const struct dl_server server,
enum dl_list  idx
[inline, static]
 

struct download* server_list_lookup const struct dl_server server,
enum dl_list  idx,
const struct sha1 sha1,
const gchar *  file,
filesize_t  size
[static]
 

void server_list_prepend_download struct dl_server server,
enum dl_list  idx,
struct download d
[static]
 

void server_list_remove_download struct dl_server server,
enum dl_list  idx,
struct download d
[static]
 

void server_sha1_count_dec struct dl_server server,
struct download d
[inline, static]
 

void server_sha1_count_inc struct dl_server server,
struct download d
[inline, static]
 

void server_undelete struct dl_server server  )  [static]
 

Resurrect server pending deletion.

void set_server_hostname struct dl_server server,
const gchar *  hostname
[static]
 

Set/change the server's hostname.

void src_add_listener src_listener_t  cb,
gnet_src_ev_t  ev,
frequency_t  t,
guint32  interval
 

void src_close void   )  [static]
 

struct download* src_get_download gnet_src_t  src_handle  ) 
 

void src_init void   )  [static]
 

void src_remove_listener src_listener_t  cb,
gnet_src_ev_t  ev
 

void update_available_ranges struct download d,
header_t header
[static]
 

Partial File Sharing Protocol (PFSP) -- client-side.

If there is an X-Available-Range header, parse it to know whether we can spot a range that is available and which we do not have.

Parameters:
[in,out] d The download for which we update available ranges
[in] header The HTTP header which contains ranges info

gboolean use_push_proxy struct download d  )  [static]
 

Try to setup the download to use the push proxies available on the server.

Returns:
TRUE is we can use a push proxy.


Variable Documentation

gint change[DHASH_SIZE]
 

Counts changes to the list.

guint dl_active = 0 [static]
 

Active downloads.

const gchar DL_BAD_EXT[] = ".BAD" [static]
 

"Bad" files (SHA1 mismatch)

GHashTable* dl_by_addr = NULL [static]
 

To handle download meshes, where we only know the IP/port of the host and not its GUID, we need to be able to locate the server.

We know that the IP will not be a private one.

Therefore, for each (GUID, IP, port) tuple, where IP is NOT private, we store the (IP, port) => server association as well. There should be only one such entry, ever. If there is more, it means the server changed its GUID, which is possible, in which case we simply supersede the old entry.

GHashTable* dl_by_host = NULL [static]
 

struct { ... } dl_by_time [static]
 

GHashTable* dl_count_by_name = NULL [static]
 

guint dl_establishing = 0 [static]
 

Establishing downloads.

const gchar DL_OK_EXT[] = ".OK" [static]
 

Extension to mark OK files.

gchar dl_tmp[4096] [static]
 

const gchar DL_UNKN_EXT[] = ".UNKN" [static]
 

For unchecked files.

gboolean download_dirty = FALSE [static]
 

const gchar download_file[] = "downloads" [static]
 

struct io_error download_io_error [static]
 

Initial value:

 {
    err_line_too_long,
    NULL,
    err_header_error,
    err_header_read_eof,        
    err_input_buffer_full,
    err_header_read_error,
    err_header_read_eof,
    NULL,
}

const struct rx_chunk_cb download_rx_chunk_cb [static]
 

Initial value:

 {
    download_rx_error,      
    download_chunk_rx_done,         
}

const struct rx_inflate_cb download_rx_inflate_cb [static]
 

Initial value:

 {
    NULL,                   
    download_rx_error,      
}

const struct rx_link_cb download_rx_link_cb [static]
 

Initial value:

 {
    NULL,                   
    download_rx_error,      
    download_rx_got_eof,    
}

const gchar file_what[] = "downloads" [static]
 

What is persisted to file.

const gchar no_reason[] = "<no reason>" [static]
 

Don't translate this.

gboolean retrieving = FALSE [static]
 

GList* servers[DHASH_SIZE]
 

Lists of servers, by retry time.

hash_list_t* sl_downloads [static]
 

All downloads (queued + unqueued).

GSList* sl_removed [static]
 

Removed downloads only.

GSList* sl_removed_servers [static]
 

Removed servers only.

hash_list_t* sl_unqueued [static]
 

Unqueued downloads only.

struct event* src_events[EV_SRC_EVENTS] [static]
 

Initial value:

 {
    NULL, NULL, NULL, NULL
}

idtable_t* src_handle_map = NULL [static]
 


Generated on Sat Jun 30 17:53:25 2007 for gtk-gnutella by  doxygen 1.3.9.1