|
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) |
download * | src_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_server * | allocate_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_server * | get_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.
|
download * | has_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_socket * | download_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.
|
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) |
| 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.
|
download * | download_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.
|
download * | cast_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.
|
download * | select_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) |
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.
|
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
|
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.
|
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_t * | buffer_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.
|
event * | src_events [EV_SRC_EVENTS] |
idtable_t * | src_handle_map = NULL |
io_error | download_io_error |
const gchar * | download_file = "downloads" |
gboolean | retrieving = FALSE |