diff --git a/include/libtorrent/add_torrent_params.hpp b/include/libtorrent/add_torrent_params.hpp index a2e1636b0..7a33bc92b 100644 --- a/include/libtorrent/add_torrent_params.hpp +++ b/include/libtorrent/add_torrent_params.hpp @@ -86,6 +86,14 @@ namespace libtorrent , userdata(0) #ifndef TORRENT_NO_DEPRECATE , flags(flag_ignore_flags | default_flags) +#else + , flags(default_flags) +#endif + , max_uploads(-1) + , max_connections(-1) + , upload_limit(-1) + , download_limit(-1) +#ifndef TORRENT_NO_DEPRECATE , seed_mode(false) , override_resume_data(false) , upload_mode(false) @@ -95,13 +103,7 @@ namespace libtorrent , auto_managed(true) , duplicate_is_error(false) , merge_resume_trackers(false) -#else - , flags(default_flags) #endif - , max_uploads(-1) - , max_connections(-1) - , upload_limit(-1) - , download_limit(-1) { } diff --git a/include/libtorrent/file_storage.hpp b/include/libtorrent/file_storage.hpp index 305f66a92..1f7ac81cc 100644 --- a/include/libtorrent/file_storage.hpp +++ b/include/libtorrent/file_storage.hpp @@ -120,8 +120,7 @@ namespace libtorrent friend class torrent_info; #endif internal_file_entry() - : name(NULL) - , offset(0) + : offset(0) , symlink_index(not_a_symlink) , no_root_dir(false) , size(0) @@ -130,12 +129,12 @@ namespace libtorrent , hidden_attribute(false) , executable_attribute(false) , symlink_attribute(false) + , name(NULL) , path_index(-1) {} internal_file_entry(file_entry const& e) - : name(NULL) - , offset(e.offset) + : offset(e.offset) , symlink_index(not_a_symlink) , no_root_dir(false) , size(e.size) @@ -144,6 +143,7 @@ namespace libtorrent , hidden_attribute(e.hidden_attribute) , executable_attribute(e.executable_attribute) , symlink_attribute(e.symlink_attribute) + , name(NULL) , path_index(-1) { set_name(e.path.c_str()); diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index 4aff9cc5f..0d77768a8 100644 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -613,6 +613,11 @@ namespace libtorrent int receive_pos() const { return m_recv_pos; } + void max_out_request_queue(int s) + { m_max_out_request_queue = s; } + int max_out_request_queue() const + { return m_max_out_request_queue; } + #ifdef TORRENT_DEBUG bool piece_failed; #endif @@ -717,10 +722,6 @@ namespace libtorrent void update_desired_queue_size(); - // the bandwidth channels, upload and download - // keeps track of the current quotas - bandwidth_channel m_bandwidth_channel[num_channels]; - // number of bytes this peer can send and receive int m_quota[2]; @@ -733,6 +734,11 @@ namespace libtorrent // the peer belongs to. aux::session_impl& m_ses; +#ifndef TORRENT_DISABLE_EXTENSIONS + typedef std::list > extension_list_t; + extension_list_t m_extensions; +#endif + // called from the main loop when this connection has any // work to do. void on_send_data(error_code const& error @@ -740,33 +746,12 @@ namespace libtorrent void on_receive_data(error_code const& error , std::size_t bytes_transferred); - // this is the limit on the number of outstanding requests - // we have to this peer. This is initialized to the settings - // in the session_settings structure. But it may be lowered - // if the peer is known to require a smaller limit (like BitComet). - // or if the extended handshake sets a limit. - // web seeds also has a limit on the queue size. - int m_max_out_request_queue; - // the average rate of receiving complete piece messages sliding_average<20> m_piece_rate; sliding_average<20> m_send_rate; void set_timeout(int s) { m_timeout = s; } -#ifndef TORRENT_DISABLE_EXTENSIONS - typedef std::list > extension_list_t; - extension_list_t m_extensions; -#endif - -#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES - // in case the session settings is set - // to resolve countries, this is set to - // the two character country code this - // peer resides in. - char m_country[2]; -#endif - boost::intrusive_ptr self() { TORRENT_ASSERT(!m_in_constructor); @@ -899,11 +884,7 @@ namespace libtorrent chained_buffer m_send_buffer; boost::shared_ptr m_socket; - // this is the peer we're actually talking to - // it may not necessarily be the peer we're - // connected to, in case we use a proxy - tcp::endpoint m_remote; - + // this is the torrent this connection is // associated with. If the connection is an // incoming connection, this is set to zero @@ -911,9 +892,6 @@ namespace libtorrent // set to the torrent it belongs to. boost::weak_ptr m_torrent; - // remote peer's id - peer_id m_peer_id; - // the pieces the other end have bitfield m_have_piece; @@ -951,14 +929,31 @@ namespace libtorrent // the piece requests std::vector m_requests_in_buffer; - // the block we're currently receiving. Or - // (-1, -1) if we're not receiving one - piece_block m_receiving_block; + // this peer's peer info struct. This may + // be 0, in case the connection is incoming + // and hasn't been added to a torrent yet. + policy::peer* m_peer_info; // the time when this peer last saw a complete copy // of this torrent time_t m_last_seen_complete; + // the block we're currently receiving. Or + // (-1, -1) if we're not receiving one + piece_block m_receiving_block; + + // this is the peer we're actually talking to + // it may not necessarily be the peer we're + // connected to, in case we use a proxy + tcp::endpoint m_remote; + + // remote peer's id + peer_id m_peer_id; + + // the bandwidth channels, upload and download + // keeps track of the current quotas + bandwidth_channel m_bandwidth_channel[num_channels]; + // if the timeout is extended for the outstanding // requests, this is the number of seconds it was // extended. @@ -1030,11 +1025,6 @@ namespace libtorrent int m_upload_limit; int m_download_limit; - // this peer's peer info struct. This may - // be 0, in case the connection is incoming - // and hasn't been added to a torrent yet. - policy::peer* m_peer_info; - // this is a measurement of how fast the peer // it allows some variance without changing // back and forth between states @@ -1075,12 +1065,28 @@ namespace libtorrent // us int m_est_reciprocation_rate; + // this is the limit on the number of outstanding requests + // we have to this peer. This is initialized to the settings + // in the session_settings structure. But it may be lowered + // if the peer is known to require a smaller limit (like BitComet). + // or if the extended handshake sets a limit. + // web seeds also has a limit on the queue size. + int m_max_out_request_queue; + // estimated round trip time to this peer // based on the time from when async_connect // was called to when on_connection_complete // was called. The rtt is specified in milliseconds boost::uint16_t m_rtt; +#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES + // in case the session settings is set + // to resolve countries, this is set to + // the two character country code this + // peer resides in. + char m_country[2]; +#endif + // if set to non-zero, this peer will always prefer // to request entire n pieces, rather than blocks. // where n is the value of this variable. diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index f081b5276..b2151237e 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -1176,6 +1176,8 @@ namespace libtorrent // haven't bool m_seed_mode:1; +// ---- + // total time we've been available on this torrent // does not count when the torrent is stopped or paused // in seconds @@ -1184,6 +1186,8 @@ namespace libtorrent // the index to the last tracker that worked boost::int8_t m_last_working_tracker; +// ---- + // total time we've been finished with this torrent // does not count when the torrent is stopped or paused unsigned int m_finished_time:24; @@ -1231,6 +1235,8 @@ namespace libtorrent // whenever something is downloaded bool m_need_save_resume_data:1; +// ---- + // total time we've been available as a seed on this torrent // does not count when the torrent is stopped or paused unsigned int m_seeding_time:24; @@ -1240,6 +1246,8 @@ namespace libtorrent // is called and the time scaler is reset to 10. boost::int8_t m_time_scaler; +// ---- + // the maximum number of uploads for this torrent unsigned int m_max_uploads:24; @@ -1247,6 +1255,8 @@ namespace libtorrent // we need to save them to check them in write_resume_data boost::uint8_t m_save_resume_flags; +// ---- + // the number of unchoked peers in this torrent unsigned int m_num_uploads:24; @@ -1269,28 +1279,90 @@ namespace libtorrent // checking queue in the session bool m_queued_for_checking:1; +// ---- + // the maximum number of connections for this torrent unsigned int m_max_connections:24; - // the number of bytes of padding files - unsigned int m_padding:24; + // set to true when this torrent has been paused but + // is waiting to finish all current download requests + // before actually closing all connections + bool m_graceful_pause_mode:1; - // the scrape data from the tracker response, this - // is optional and may be 0xffffff - unsigned int m_complete:24; + // this is set to true when the torrent starts up + // The first tracker response, when this is true, + // will attempt to connect to a bunch of peers immediately + // and set this to false. We only do this once to get + // the torrent kick-started + bool m_need_connect_boost:1; + + // rotating sequence number for LSD announces sent out. + // used to only use IP broadcast for every 8th lsd announce + boost::uint8_t m_lsd_seq:3; + + // this is set to true if the torrent was started without + // metadata. It is used to save metadata in the resume file + // by default for such torrents. It does not necessarily + // have to be a magnet link. + bool m_magnet_link:1; + + // set to true if the session IP filter applies to this + // torrent or not. Defaults to true. + bool m_apply_ip_filter:1; + + // if set to true, add tracker URLs loaded from resume + // data into this torrent instead of replacing them + bool m_merge_resume_trackers:1; + +// ---- + + // the number of bytes of padding files + boost::uint32_t m_padding:24; // this is the priority of the torrent. The higher // the value is, the more bandwidth is assigned to // the torrent's peers - boost::uint8_t m_priority; + boost::uint32_t m_priority:8; + +// ---- // the scrape data from the tracker response, this // is optional and may be 0xffffff - unsigned int m_incomplete:24; + boost::uint32_t m_complete:24; - // progress parts per million (the number of - // millionths of completeness) - unsigned int m_progress_ppm:20; + // state subscription. If set, a pointer to this torrent + // will be added to the m_state_updates set in session_impl + // whenever this torrent's state changes (any state). + bool m_state_subscription:1; + + // in state_updates list. When adding a torrent to the + // session_impl's m_state_update list, this bit is set + // to never add the same torrent twice + bool m_in_state_updates:1; + + // these represent whether or not this torrent is counted + // in the total counters of active seeds and downloads + // in the session. + bool m_is_active_download:1; + bool m_is_active_finished:1; + + // even if we're not built to support SSL torrents, + // remember that this is an SSL torrent, so that we don't + // accidentally start seeding it without any authentication. + bool m_ssl_torrent:1; + + // this is set to true if we're trying to delete the + // files belonging to it. When set, don't write any + // more blocks to disk! + bool m_deleted:1; + + // TODO: there's space for another 2 bits here + +// ---- + + // the scrape data from the tracker response, this + // is optional and may be 0xffffff + boost::uint32_t m_incomplete:24; // is set to true when the torrent has // been aborted. @@ -1324,17 +1396,21 @@ namespace libtorrent // this is set when the torrent is in share-mode bool m_share_mode:1; +// ---- + // the number of seconds since the last piece passed for // this torrent - boost::uint32_t m_last_download:24; - - // the number of seconds since the last byte was uploaded - // from this torrent - boost::uint32_t m_last_upload:24; + boost::uint64_t m_last_download:24; // the number of seconds since the last scrape request to // one of the trackers in this torrent - boost::uint16_t m_last_scrape; + boost::uint64_t m_last_scrape:16; + + // the number of seconds since the last byte was uploaded + // from this torrent + boost::uint64_t m_last_upload:24; + +// ---- // the scrape data from the tracker response, this // is optional and may be 0xffffff @@ -1343,61 +1419,11 @@ namespace libtorrent // round-robin index into m_interfaces mutable boost::uint8_t m_interface_index; - // set to true when this torrent has been paused but - // is waiting to finish all current download requests - // before actually closing all connections - bool m_graceful_pause_mode:1; +// ---- - // this is set to true when the torrent starts up - // The first tracker response, when this is true, - // will attempt to connect to a bunch of peers immediately - // and set this to false. We only do this once to get - // the torrent kick-started - bool m_need_connect_boost:1; - - // rotating sequence number for LSD announces sent out. - // used to only use IP broadcast for every 8th lsd announce - boost::uint8_t m_lsd_seq:3; - - // this is set to true if the torrent was started without - // metadata. It is used to save metadata in the resume file - // by default for such torrents. It does not necessarily - // have to be a magnet link. - bool m_magnet_link:1; - - // set to true if the session IP filter applies to this - // torrent or not. Defaults to true. - bool m_apply_ip_filter:1; - - // if set to true, add tracker URLs loaded from resume - // data into this torrent instead of replacing them - bool m_merge_resume_trackers:1; - - // state subscription. If set, a pointer to this torrent - // will be added to the m_state_updates set in session_impl - // whenever this torrent's state changes (any state). - bool m_state_subscription:1; - - // in state_updates list. When adding a torrent to the - // session_impl's m_state_update list, this bit is set - // to never add the same torrent twice - bool m_in_state_updates:1; - - // these represent whether or not this torrent is counted - // in the total counters of active seeds and downloads - // in the session. - bool m_is_active_download:1; - bool m_is_active_finished:1; - - // even if we're not built to support SSL torrents, - // remember that this is an SSL torrent, so that we don't - // accidentally start seeding it without any authentication. - bool m_ssl_torrent:1; - - // this is set to true if we're trying to delete the - // files belonging to it. When set, don't write any - // more blocks to disk! - bool m_deleted:1; + // progress parts per million (the number of + // millionths of completeness) + unsigned int m_progress_ppm:20; #if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS public: diff --git a/include/libtorrent/utp_stream.hpp b/include/libtorrent/utp_stream.hpp index fb7e109c4..90381a9c0 100644 --- a/include/libtorrent/utp_stream.hpp +++ b/include/libtorrent/utp_stream.hpp @@ -453,6 +453,8 @@ public: asio::io_service& m_io_service; utp_socket_impl* m_impl; + + // this field requires another 8 bytes (including padding) bool m_open; }; diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index 70380eef2..bc235389d 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -1748,7 +1748,7 @@ namespace libtorrent if (!client_info.empty()) m_client_version = client_info; int reqq = int(root.dict_find_int_value("reqq")); - if (reqq > 0) m_max_out_request_queue = reqq; + if (reqq > 0) max_out_request_queue(reqq); if (root.dict_find_int_value("upload_only", 0)) set_upload_only(true); @@ -3143,7 +3143,7 @@ namespace libtorrent if (f && std::equal(f->name, f->name + 2, "BC")) { // if this is a bitcomet client, lower the request queue size limit - if (m_max_out_request_queue > 50) m_max_out_request_queue = 50; + if (max_out_request_queue() > 50) max_out_request_queue(50); } #ifndef TORRENT_DISABLE_EXTENSIONS diff --git a/src/file_storage.cpp b/src/file_storage.cpp index 3dd3c17a4..5cc7d6961 100644 --- a/src/file_storage.cpp +++ b/src/file_storage.cpp @@ -135,8 +135,7 @@ namespace libtorrent } internal_file_entry::internal_file_entry(internal_file_entry const& fe) - : name(0) - , offset(fe.offset) + : offset(fe.offset) , size(fe.size) , symlink_index(fe.symlink_index) , name_len(fe.name_len) @@ -145,6 +144,7 @@ namespace libtorrent , executable_attribute(fe.executable_attribute) , symlink_attribute(fe.symlink_attribute) , no_root_dir(fe.no_root_dir) + , name(0) , path_index(fe.path_index) { set_name(fe.filename().c_str()); diff --git a/src/http_seed_connection.cpp b/src/http_seed_connection.cpp index 816237e63..0922e7bb5 100644 --- a/src/http_seed_connection.cpp +++ b/src/http_seed_connection.cpp @@ -77,8 +77,8 @@ namespace libtorrent // multiply with the blocks per piece since that many requests are // merged into one http request - m_max_out_request_queue = ses.settings().urlseed_pipeline_size - * blocks_per_piece; + max_out_request_queue(ses.settings().urlseed_pipeline_size + * blocks_per_piece); prefer_whole_pieces(1); diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 8feaf3155..584fd7c78 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -113,7 +113,6 @@ namespace libtorrent , policy::peer* peerinfo , bool outgoing) : m_ses(ses) - , m_max_out_request_queue(m_ses.settings().max_out_request_queue) , m_work(ses.m_io_service) , m_last_piece(time_now()) , m_last_request(time_now()) @@ -134,10 +133,11 @@ namespace libtorrent , m_uploaded_at_last_unchoke(0) , m_disk_recv_buffer(ses, 0) , m_socket(s) - , m_remote(endp) , m_torrent(tor) - , m_receiving_block(piece_block::invalid) + , m_peer_info(peerinfo) , m_last_seen_complete(0) + , m_receiving_block(piece_block::invalid) + , m_remote(endp) , m_timeout_extend(0) , m_outstanding_bytes(0) , m_extension_outstanding_bytes(0) @@ -153,7 +153,6 @@ namespace libtorrent , m_priority(1) , m_upload_limit(0) , m_download_limit(0) - , m_peer_info(peerinfo) , m_speed(slow) , m_connection_ticket(-1) , m_remote_bytes_dled(0) @@ -161,6 +160,7 @@ namespace libtorrent , m_outstanding_writing_bytes(0) , m_download_rate_peak(0) , m_upload_rate_peak(0) + , m_max_out_request_queue(m_ses.settings().max_out_request_queue) , m_rtt(0) , m_prefer_whole_pieces(0) , m_desired_queue_size(2) diff --git a/src/torrent.cpp b/src/torrent.cpp index 8624db3be..5b198bb2c 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -399,11 +399,22 @@ namespace libtorrent , m_files_checked(false) , m_queued_for_checking(false) , m_max_connections((1<<24)-1) + , m_graceful_pause_mode(false) + , m_need_connect_boost(true) + , m_lsd_seq(0) + , m_magnet_link(false) + , m_apply_ip_filter(p.flags & add_torrent_params::flag_apply_ip_filter) + , m_merge_resume_trackers(p.flags & add_torrent_params::flag_merge_resume_trackers) , m_padding(0) - , m_complete(0xffffff) , m_priority(0) + , m_complete(0xffffff) + , m_state_subscription(p.flags & add_torrent_params::flag_update_subscribe) + , m_in_state_updates(false) + , m_is_active_download(false) + , m_is_active_finished(false) + , m_ssl_torrent(false) + , m_deleted(false) , m_incomplete(0xffffff) - , m_progress_ppm(0) , m_abort(false) , m_announce_to_dht((p.flags & add_torrent_params::flag_paused) == 0) , m_announce_to_trackers((p.flags & add_torrent_params::flag_paused) == 0) @@ -413,22 +424,11 @@ namespace libtorrent , m_auto_managed(p.flags & add_torrent_params::flag_auto_managed) , m_share_mode(p.flags & add_torrent_params::flag_share_mode) , m_last_download(0) - , m_last_upload(0) , m_last_scrape(0) + , m_last_upload(0) , m_downloaded(0xffffff) , m_interface_index(0) - , m_graceful_pause_mode(false) - , m_need_connect_boost(true) - , m_lsd_seq(0) - , m_magnet_link(false) - , m_apply_ip_filter(p.flags & add_torrent_params::flag_apply_ip_filter) - , m_merge_resume_trackers(p.flags & add_torrent_params::flag_merge_resume_trackers) - , m_state_subscription(p.flags & add_torrent_params::flag_update_subscribe) - , m_in_state_updates(false) - , m_is_active_download(false) - , m_is_active_finished(false) - , m_ssl_torrent(false) - , m_deleted(false) + , m_progress_ppm(0) { // if there is resume data already, we don't need to trigger the initial save // resume data