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

downloads.c File Reference


Detailed Description

Handle downloads.

Author:
Raphael Manfredi
Date:
2001-2003

#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 "http.h"
#include "version.h"
#include "ignore.h"
#include "ioheader.h"
#include "verify.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 "if/gnet_property.h"
#include "if/gnet_property_priv.h"
#include "if/bridge/c2ui.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/idtable.h"
#include "lib/palloc.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  server_select

Defines

#define DOWNLOAD_FILE_MODE   (S_IRUSR | S_IWUSR | S_IRGRP) /* 0640 */
#define DOWNLOAD_MIN_OVERLAP   64 /**< Minimum overlap for safety */
 Minimum overlap for safety.

#define DOWNLOAD_SHORT_DELAY   2 /**< Shortest retry delay */
 Shortest retry delay.

#define DOWNLOAD_MAX_SINK   16384 /**< Max amount of data to sink */
 Max amount of data to sink.

#define DOWNLOAD_SERVER_HOLD   15 /**< Space requests to same server */
 Space requests to same server.

#define DOWNLOAD_DNS_LOOKUP   7200 /**< Period of server DNS lookups */
 Period of server DNS lookups.

#define BUFFER_POOL_MAX   300 /**< Max amount of buffers to keep */
 Max amount of buffers to keep.

#define IO_AVG_RATE   5 /**< Compute global recv rate every 5 secs */
 Compute global recv rate every 5 secs.

#define DHASH_SIZE   1024 /**< Hash list size, must be a power of 2 */
 Hash list size, must be a power of 2.

#define DHASH_MASK   (DHASH_SIZE - 1)
#define DL_HASH(x)   ((x) & DHASH_MASK)
#define count_running_downloads()   (dl_establishing + dl_active)
#define count_running_on_server(s)   (s->count[DL_LIST_RUNNING])
#define MAGIC_TIME   1 /**< For recreation upon starup */
 For recreation upon starup.

#define DOWNLOAD(x)   cast_to_download(x)

Functions

 RCSID ("$Id:downloads.c, v 1.149 2006/02/04 21:31:46 rmanfredi Exp $")
void download_add_to_list (struct download *d, enum dl_list idx)
 download_add_to_list

gboolean send_push_request (const gchar *, guint32, guint16)
 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'.

void download_read (gpointer data, gint source, inputevt_cond_t cond)
 Read callback for file data.

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, guint32 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 that are not in PUSH mode (since we'll loose routing information when we quit).

void download_retrieve (void)
 Retrieve download list and requeue each download.

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)
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 a, gconstpointer b)
 Compare two `download' structures based on the `retry_after' field.

gint dl_server_retry_cmp (gconstpointer a, gconstpointer b)
 Compare two `dl_server' structures based on the `retry_after' field.

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?

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

void buffers_reset_writing (struct download *d)
 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 (struct download *d)
 Check whether reception buffers are full.

gboolean buffers_should_flush (struct download *d)
 Check whether we should request flushing of the buffered data.

void buffers_add_read (struct download *d, ssize_t amount)
 Update the buffer structure after having read "amount" more bytes: prepare `iov_cur' and `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 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 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 (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 (gchar *name)
 Remove one from the amount of downloads running and bearing the filename.

downloadhas_same_download (const gchar *file, const gchar *sha1, 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.

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 (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 gchar *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_set_socket_rx_size (gint rx_size)
 Change the socket RX buffer size for all the currently connected downloads.

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, guint32 new_status, const gchar *reason, va_list ap)
 Vectorized version common to download_stop() and download_unavailable().

void download_stop (struct download *d, guint32 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.

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

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

downloadcreate_download (gchar *file, const gchar *uri, filesize_t size, guint32 record_index, const host_addr_t addr, guint16 port, const gchar *guid, const gchar *hostname, gchar *sha1, time_t stamp, gboolean push, gboolean interactive, gboolean file_size_known, fileinfo_t *file_info, const gnet_host_vec_t *proxies, guint32 cflags)
 Create a new download.

void download_auto_new (gchar *file, filesize_t size, guint32 record_index, const host_addr_t addr, guint16 port, const gchar *guid, gchar *hostname, gchar *sha1, time_t stamp, gboolean push, gboolean file_size_known, 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, gchar *guid, guint32 from, guint32 to)
 Search has detected index change in queued download.

gboolean download_new (gchar *file, filesize_t size, guint32 record_index, const host_addr_t addr, guint16 port, const gchar *guid, gchar *hostname, gchar *sha1, time_t stamp, gboolean push, fileinfo_t *fi, gnet_host_vec_t *proxies, guint32 flags)
 Create a new download, usually called from an interactive user action.

gboolean download_new_unknown_size (gchar *file, guint32 record_index, const host_addr_t addr, guint16 port, const gchar *guid, gchar *hostname, gchar *sha1, time_t stamp, gboolean push, fileinfo_t *fi, gnet_host_vec_t *proxies, guint32 flags)
 Create a new download whose total size is unknown.

gboolean download_new_uri (gchar *file, const gchar *uri, filesize_t size, const host_addr_t addr, guint16 port, const gchar *guid, gchar *hostname, gchar *sha1, time_t stamp, gboolean push, fileinfo_t *fi, gnet_host_vec_t *proxies, guint32 flags)
void download_orphan_new (gchar *file, filesize_t size, gchar *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.

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_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_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 check_date (const header_t *header, const host_addr_t addr, struct download *d)
 check_date

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 check_content_urn (struct download *d, header_t *header)
 Check for X-Gnutella-Content-URN.

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

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.

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.

void download_push_ack (struct gnutella_socket *s)
 Initiate download on the remotely initiated connection.

void download_retry (struct download *d)
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.

void download_store_if_dirty (void)
 Store pending download if needed.

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, 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, gchar *digest, 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...).

void download_close (void)
 Terminating processing, cleanup data structures.

const gchar * build_url_from_download (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)
 download_something_to_clear

downloaddownload_browse_start (const gchar *name, const gchar *hostname, host_addr_t addr, guint16 port, const gchar *guid, gboolean push, const gnet_host_vec_t *proxies, gnet_search_t search)
 Create special non-persisted download that will request "/" on the remote host and expect a stream of Gnutella query hits back.

void download_abort_browse_host (gpointer download, gnet_search_t sh)
 Abort browse-hosst 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_browse_received (struct download *d, ssize_t received)
 Called when more data has been received.

void download_browse_maybe_finished (struct download *d)
 Called when all the received data so far have been processed to check whether we are done.


Variables

GSList * sl_downloads = NULL
 All downloads (queued + unqueued).

GSList * sl_unqueued = NULL
 Global Data.

GSList * sl_removed = NULL
 Removed downloads only.

GSList * sl_removed_servers = NULL
 Removed servers only.

gchar dl_tmp [4096]
gint queue_frozen = 0
pool_tbuffer_pool
 Memory pool for read buffers.

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 file_what [] = "downloads"
 What is persisted to file.

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]
   gint   change [DHASH_SIZE]
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
io_error download_io_error
const gchar * download_file = "downloads"
gboolean retrieving = FALSE


Define Documentation

#define BUFFER_POOL_MAX   300 /**< Max amount of buffers to keep */
 

Max amount of buffers to keep.

 
#define count_running_downloads  )     (dl_establishing + dl_active)
 

#define count_running_on_server s   )     (s->count[DL_LIST_RUNNING])
 

#define DHASH_MASK   (DHASH_SIZE - 1)
 

#define DHASH_SIZE   1024 /**< Hash list size, must be a power of 2 */
 

Hash list size, must be a power of 2.

#define DL_HASH  )     ((x) & DHASH_MASK)
 

#define DOWNLOAD  )     cast_to_download(x)
 

#define DOWNLOAD_DNS_LOOKUP   7200 /**< Period of server DNS lookups */
 

Period of server DNS lookups.

#define DOWNLOAD_FILE_MODE   (S_IRUSR | S_IWUSR | S_IRGRP) /* 0640 */
 

#define DOWNLOAD_MAX_SINK   16384 /**< Max amount of data to sink */
 

Max amount of data to sink.

#define DOWNLOAD_MIN_OVERLAP   64 /**< Minimum overlap for safety */
 

Minimum overlap for safety.

#define DOWNLOAD_SERVER_HOLD   15 /**< Space requests to same server */
 

Space requests to same server.

#define DOWNLOAD_SHORT_DELAY   2 /**< Shortest retry delay */
 

Shortest retry delay.

#define IO_AVG_RATE   5 /**< Compute global recv rate every 5 secs */
 

Compute global recv rate every 5 secs.

#define MAGIC_TIME   1 /**< For recreation upon starup */
 

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,
ssize_t  amount
[static]
 

Update the buffer structure after having read "amount" more bytes: prepare `iov_cur' and `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_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.

gboolean buffers_full 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.
Note:
precondition is: len <= SOCK_BUFSZ, the size of the socket buffer.

void buffers_reset_reading struct download d  )  [static]
 

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

void buffers_reset_writing struct download d  )  [static]
 

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

gboolean buffers_should_flush 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.

const gchar* build_url_from_download 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).

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.

gboolean check_content_urn struct download d,
header_t header
[static]
 

Check for X-Gnutella-Content-URN.

Returns:
FALSE if we cannot continue with the download.

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

check_date

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.

guint count_running_downloads_with_name const char *  name  )  [static]
 

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

struct download* create_download gchar *  file,
const gchar *  uri,
filesize_t  size,
guint32  record_index,
const host_addr_t  addr,
guint16  port,
const gchar *  guid,
const gchar *  hostname,
gchar *  sha1,
time_t  stamp,
gboolean  push,
gboolean  interactive,
gboolean  file_size_known,
fileinfo_t file_info,
const gnet_host_vec_t proxies,
guint32  cflags
[static]
 

Create a new download.

When `interactive' is false, we assume that `file' was already duped, and take ownership of the pointer.

Attention:
NB: If `record_index' == URN_INDEX, and a `sha1' is also supplied, then this is our convention for expressing a /uri-res/N2R? download URL. However, we don't forbid 0 as a valid record index if it does not have a SHA1.
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  a,
gconstpointer  b
[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  a,
gconstpointer  b
[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 gpointer  download,
gnet_search_t  sh
 

Abort browse-hosst 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]
 

download_add_to_list

void download_auto_new gchar *  file,
filesize_t  size,
guint32  record_index,
const host_addr_t  addr,
guint16  port,
const gchar *  guid,
gchar *  hostname,
gchar *  sha1,
time_t  stamp,
gboolean  push,
gboolean  file_size_known,
fileinfo_t fi,
gnet_host_vec_t proxies,
guint32  flags
 

Automatic download request.

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.

void download_browse_maybe_finished struct download d  ) 
 

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

void download_browse_received struct download d,
ssize_t  received
 

Called when more data has been received.

struct download* download_browse_start const gchar *  name,
const gchar *  hostname,
host_addr_t  addr,
guint16  port,
const gchar *  guid,
gboolean  push,
const gnet_host_vec_t proxies,
gnet_search_t  search
 

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:
name the stringified "addr:port" of the host.
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.

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

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!

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.

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

void download_got_eof struct download d  ) 
 

Called when an EOF is received during data reception.

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

void download_mark_active struct download d  )  [static]
 

Mark download as receiving data: download is becoming active.

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,
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
[static]
 

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 gchar *  file,
filesize_t  size,
guint32  record_index,
const host_addr_t  addr,
guint16  port,
const gchar *  guid,
gchar *  hostname,
gchar *  sha1,
time_t  stamp,
gboolean  push,
fileinfo_t fi,
gnet_host_vec_t proxies,
guint32  flags
 

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

Returns:
whether download was created.

gboolean download_new_unknown_size gchar *  file,
guint32  record_index,
const host_addr_t  addr,
guint16  port,
const gchar *  guid,
gchar *  hostname,
gchar *  sha1,
time_t  stamp,
gboolean  push,
fileinfo_t fi,
gnet_host_vec_t proxies,
guint32  flags
 

Create a new download whose total size is unknown.

gboolean download_new_uri gchar *  file,
const gchar *  uri,
filesize_t  size,
const host_addr_t  addr,
guint16  port,
const gchar *  guid,
gchar *  hostname,
gchar *  sha1,
time_t  stamp,
gboolean  push,
fileinfo_t fi,
gnet_host_vec_t proxies,
guint32  flags
 

void download_orphan_new gchar *  file,
filesize_t  size,
gchar *  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.

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

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

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

Read callback for file data.

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

gint download_remove_all_with_sha1 const gchar *  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_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.

void download_retry struct download d  ) 
 

void download_rx_done struct download d  ) 
 

Called when all data has been received.

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 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_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  cond
[static]
 

Read callback for file data.

gboolean download_something_to_clear void   ) 
 

download_something_to_clear

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 for the whole file completion percentage if the source is not receiving at the moment.

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,
guint32  new_status,
const gchar *  reason,
... 
 

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

void download_stop_v struct download d,
guint32  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 that are not in PUSH mode (since we'll loose routing information when we quit).

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_thaw_queue void   ) 
 

Thaw the scheduling queue.

Multiple freezing requires multiple thawing.

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,
guint32  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_verify_done struct download d,
gchar *  digest,
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...).

void download_verify_progress struct download d,
guint32  hashed
 

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  ) 
 

Called when the verification daemon task starts processing a download.

void download_write_data struct download d  )  [static]
 

Write data in socket buffer to file.

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

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 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 gchar *  sha1,
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_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]
 

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.

RCSID "$Id:downloads.  c,
v 1.149 2006/02/04 21:31:46 rmanfredi Exp $" 
 

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_push_request const gchar *  guid,
guint32  file_id,
guint16  port
[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'.

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

void server_delay_delete struct dl_server server  )  [static]
 

Marks server for delayed removal (via asynchronous timer).

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

pool_t* buffer_pool [static]
 

Memory pool for read buffers.

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 gchar file_what[] = "downloads" [static]
 

What is persisted to file.

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

Don't translate this.

gint queue_frozen = 0 [static]
 

gboolean retrieving = FALSE [static]
 

GList* servers[DHASH_SIZE]
 

Lists of servers, by retry time.

GSList* sl_downloads = NULL [static]
 

All downloads (queued + unqueued).

GSList* sl_removed = NULL
 

Removed downloads only.

GSList* sl_removed_servers = NULL
 

Removed servers only.

GSList* sl_unqueued = NULL
 

Global Data.

struct event* src_events[EV_SRC_EVENTS] [static]
 

Initial value:

 {
    NULL, NULL, NULL, NULL
}

idtable_t* src_handle_map = NULL [static]
 


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