From e122678d044f544a6397f65fdb8c6cfb44e5bef1 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 26 Nov 2013 04:39:33 +0000 Subject: [PATCH] pack fields in internal_file_entry, torrent_status and chained_buffer --- include/libtorrent/chained_buffer.hpp | 8 +- include/libtorrent/file_storage.hpp | 51 +++--- include/libtorrent/peer_connection.hpp | 36 ++-- include/libtorrent/torrent_handle.hpp | 230 ++++++++++++------------- src/torrent_handle.cpp | 54 +++--- 5 files changed, 190 insertions(+), 189 deletions(-) diff --git a/include/libtorrent/chained_buffer.hpp b/include/libtorrent/chained_buffer.hpp index e4aa9bc5e..63034eca9 100644 --- a/include/libtorrent/chained_buffer.hpp +++ b/include/libtorrent/chained_buffer.hpp @@ -101,6 +101,10 @@ namespace libtorrent // send std::list m_vec; + // this is the vector of buffers used when + // invoking the async write call + std::list m_tmp_vec; + // this is the number of bytes in the send buf. // this will always be equal to the sum of the // size of all buffers in vec @@ -110,10 +114,6 @@ namespace libtorrent // including unused space int m_capacity; - // this is the vector of buffers used when - // invoking the async write call - std::list m_tmp_vec; - #if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS bool m_destructed; #endif diff --git a/include/libtorrent/file_storage.hpp b/include/libtorrent/file_storage.hpp index cfb2703f0..305f66a92 100644 --- a/include/libtorrent/file_storage.hpp +++ b/include/libtorrent/file_storage.hpp @@ -58,6 +58,10 @@ namespace libtorrent // encoded in UTF-8. std::string path; + // the path which this is a symlink to, or empty if this is + // not a symlink. This field is only used if the ``symlink_attribute`` is set. + std::string symlink_path; + // the offset of this file inside the torrent size_type offset; @@ -98,10 +102,6 @@ namespace libtorrent // the ``symlink_index`` refers to a string which specifies the original location // where the data for this file was found. bool symlink_attribute:1; - - // the path which this is a symlink to, or empty if this is - // not a symlink. This field is only used if the ``symlink_attribute`` is set. - std::string symlink_path; }; // only export this type if deprecated functions are enabled @@ -110,6 +110,7 @@ namespace libtorrent #else #define TORRENT_DEPRECATED_EXPORT TORRENT_EXPORT #endif + // internal struct TORRENT_DEPRECATED_EXPORT internal_file_entry { @@ -121,28 +122,28 @@ namespace libtorrent internal_file_entry() : name(NULL) , offset(0) - , size(0) , symlink_index(not_a_symlink) + , no_root_dir(false) + , size(0) , name_len(name_is_owned) , pad_file(false) , hidden_attribute(false) , executable_attribute(false) , symlink_attribute(false) - , no_root_dir(false) , path_index(-1) {} internal_file_entry(file_entry const& e) : name(NULL) , offset(e.offset) - , size(e.size) , symlink_index(not_a_symlink) + , no_root_dir(false) + , size(e.size) , name_len(name_is_owned) , pad_file(e.pad_file) , hidden_attribute(e.hidden_attribute) , executable_attribute(e.executable_attribute) , symlink_attribute(e.symlink_attribute) - , no_root_dir(false) , path_index(-1) { set_name(e.path.c_str()); @@ -156,17 +157,6 @@ namespace libtorrent void set_name(char const* n, bool borrow_string = false, int string_len = 0); std::string filename() const; - // make it available for logging -#if !defined TORRENT_VERBOSE_LOGGING \ - && !defined TORRENT_LOGGING \ - && !defined TORRENT_ERROR_LOGGING - private: -#endif - // This string is not necessarily null terminated! - // that's why it's private, to keep people away from it - char const* name; - public: - enum { name_is_owned = (1<<12)-1, not_a_symlink = (1<<15)-1 @@ -174,13 +164,17 @@ namespace libtorrent // the offset of this file inside the torrent boost::uint64_t offset:48; - // the size of this file - boost::uint64_t size:48; - // index into file_storage::m_symlinks or not_a_symlink // if this is not a symlink boost::uint64_t symlink_index:15; + // if this is true, don't include m_name as part of the + // path to this file + boost::uint64_t no_root_dir:1; + + // the size of this file + boost::uint64_t size:48; + // the number of characters in the name. If this is // name_is_owned, name is null terminated and owned by this object // (i.e. it should be freed in the destructor). If @@ -192,9 +186,16 @@ namespace libtorrent boost::uint64_t executable_attribute:1; boost::uint64_t symlink_attribute:1; - // if this is true, don't include m_name as part of the - // path to this file - boost::uint64_t no_root_dir:1; + // make it available for logging +#if !defined TORRENT_VERBOSE_LOGGING \ + && !defined TORRENT_LOGGING \ + && !defined TORRENT_ERROR_LOGGING + private: +#endif + // This string is not necessarily null terminated! + // that's why it's private, to keep people away from it + char const* name; + public: // the index into file_storage::m_paths. To get // the full path to this file, concatenate the path diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index b9f8dd618..4aff9cc5f 100644 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -866,6 +866,24 @@ namespace libtorrent // for the round-robin unchoke algorithm. size_type m_uploaded_at_last_unchoke; + template + struct handler_storage + { +#ifdef TORRENT_DEBUG + handler_storage() + : used(false) + {} + + bool used; +#else + handler_storage() {} +#endif + boost::aligned_storage bytes; + }; + + handler_storage m_read_handler_storage; + handler_storage m_write_handler_storage; + #ifndef TORRENT_DISABLE_GEO_IP std::string m_inet_as_name; #endif @@ -1207,24 +1225,6 @@ namespace libtorrent // other peers to compare it to. bool m_exceeded_limit:1; - template - struct handler_storage - { -#ifdef TORRENT_DEBUG - handler_storage() - : used(false) - {} - - bool used; -#else - handler_storage() {} -#endif - boost::aligned_storage bytes; - }; - - handler_storage m_read_handler_storage; - handler_storage m_write_handler_storage; - template struct allocating_handler { diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index cb0758527..fe36e79e6 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -44,6 +44,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #ifdef _MSC_VER #pragma warning(pop) @@ -1081,51 +1082,6 @@ namespace libtorrent checking_resume_data }; - // the main state the torrent is in. See torrent_status::state_t. - state_t state; - - // set to true if the torrent is paused and false otherwise. It's only true - // if the torrent itself is paused. If the torrent is not running because the session is - // paused, this is still false. To know if a torrent is active or not, you need to inspect - // both ``torrent_status::paused`` and ``session::is_paused()``. - bool paused; - - // set to true if the torrent is auto managed, i.e. libtorrent is - // responsible for determining whether it should be started or queued. For more info - // see queuing_ - bool auto_managed; - - // true when the torrent is in sequential download mode. In - // this mode pieces are downloaded in order rather than rarest first. - bool sequential_download; - - // true if all pieces have been downloaded. - bool is_seeding; - - // true if all pieces that have a priority > 0 are downloaded. There is - // only a distinction between finished and seeding if some pieces or files have been - // set to priority 0, i.e. are not downloaded. - bool is_finished; - - // true if this torrent has metadata (either it was started from a - // .torrent file or the metadata has been downloaded). The only scenario where this can be - // false is when the torrent was started torrent-less (i.e. with just an info-hash and tracker - // ip, a magnet link for instance). - bool has_metadata; - - // a value in the range [0, 1], that represents the progress of the - // torrent's current task. It may be checking files or downloading. - float progress; - - // progress parts per million (progress * 1000000) - // when disabling floating point operations, this is - // the only option to query progress - - // reflects the same value as ``progress``, but instead in a range - // [0, 1000000] (ppm = parts per million). When floating point operations are disabled, - // this is the only alternative to the floating point value in progress. - int progress_ppm; - // may be set to an error message describing why the torrent was paused, in // case it was paused by an error. If the torrent is not paused or if it's paused but // not because of an error, this string is empty. @@ -1187,6 +1143,70 @@ namespace libtorrent // order block). This is supposed to be as low as possible. size_type total_redundant_bytes; + // a bitmask that represents which pieces we have (set to true) and + // the pieces we don't have. It's a pointer and may be set to 0 if the torrent isn't + // downloading or seeding. + bitfield pieces; + + // a bitmask representing which pieces has had their hash + // checked. This only applies to torrents in *seed mode*. If the torrent is not + // in seed mode, this bitmask may be empty. + bitfield verified_pieces; + + // the total number of bytes of the file(s) that we have. All + // this does not necessarily has to be downloaded during this session (that's + // ``total_payload_download``). + size_type total_done; + + // the number of bytes we have downloaded, only counting the + // pieces that we actually want to download. i.e. excluding any pieces that we have but + // have priority 0 (i.e. not wanted). + size_type total_wanted_done; + + // The total number of bytes we want to download. + // This may be smaller than the total torrent size + // in case any pieces are prioritized to 0, i.e. not wanted + size_type total_wanted; + + // are accumulated upload and download + // payload byte counters. They are saved in and restored from resume data to keep totals + // across sessions. + size_type all_time_upload; + size_type all_time_download; + + // the posix-time when this torrent was added. i.e. what + // ``time(NULL)`` returned at the time. + time_t added_time; + + // the posix-time when this torrent was finished. If + // the torrent is not yet finished, this is 0. + time_t completed_time; + + // the time when we, or one of our peers, last + // saw a complete copy of this torrent. + time_t last_seen_complete; + + // The allocation mode for the torrent. See storage_mode_t for the options. + // For more information, see storage-allocation_. + storage_mode_t storage_mode; + + // a value in the range [0, 1], that represents the progress of the + // torrent's current task. It may be checking files or downloading. + float progress; + + // progress parts per million (progress * 1000000) + // when disabling floating point operations, this is + // the only option to query progress + + // reflects the same value as ``progress``, but instead in a range + // [0, 1000000] (ppm = parts per million). When floating point operations are disabled, + // this is the only alternative to the floating point value in progress. + int progress_ppm; + + // the position this torrent has in the download + // queue. If the torrent is a seed or finished, this is -1. + int queue_position; + // the total rates for all peers for this // torrent. These will usually have better precision than summing the rates from // all peers. The rates are given as the number of bytes per second. @@ -1233,38 +1253,12 @@ namespace libtorrent // etc. If this is 0, it means we don't know of any more peers that we can try. int connect_candidates; - // a bitmask that represents which pieces we have (set to true) and - // the pieces we don't have. It's a pointer and may be set to 0 if the torrent isn't - // downloading or seeding. - bitfield pieces; - - // a bitmask representing which pieces has had their hash - // checked. This only applies to torrents in *seed mode*. If the torrent is not - // in seed mode, this bitmask may be empty. - bitfield verified_pieces; - // the number of pieces that has been downloaded. It is equivalent // to: ``std::accumulate(pieces->begin(), pieces->end())``. So you don't have to // count yourself. This can be used to see if anything has updated since last time // if you want to keep a graph of the pieces up to date. int num_pieces; - // the total number of bytes of the file(s) that we have. All - // this does not necessarily has to be downloaded during this session (that's - // ``total_payload_download``). - size_type total_done; - - // the number of bytes we have downloaded, only counting the - // pieces that we actually want to download. i.e. excluding any pieces that we have but - // have priority 0 (i.e. not wanted). - size_type total_wanted_done; - - // The total number of bytes we want to download. - // This may be smaller than the total torrent size - // in case any pieces are prioritized to 0, i.e. not wanted - size_type total_wanted; - - // the number of distributed copies of the torrent. // Note that one copy may be spread out among many peers. It tells how many copies // there are currently of the rarest piece(s) among the peers this client is @@ -1317,10 +1311,6 @@ namespace libtorrent // the set limit of number of connections for this torrent. int connections_limit; - // The allocation mode for the torrent. See storage_mode_t for the options. - // For more information, see storage-allocation_. - storage_mode_t storage_mode; - // the number of peers in this // torrent that are waiting for more bandwidth quota from the torrent rate limiter. // This can determine if the rate you get from this torrent is bound by the torrents @@ -1330,11 +1320,11 @@ namespace libtorrent int up_bandwidth_queue; int down_bandwidth_queue; - // are accumulated upload and download - // payload byte counters. They are saved in and restored from resume data to keep totals - // across sessions. - size_type all_time_upload; - size_type all_time_download; + // the number of + // seconds since any peer last uploaded from this torrent and the last + // time a downloaded piece passed the hash check, respectively. + int time_since_upload; + int time_since_download; // These keep track of the number of seconds this torrent has been active (not // paused) and the number of seconds it has been active while being finished and @@ -1355,19 +1345,25 @@ namespace libtorrent // If it has never done that, this value is -1. int last_scrape; - // true if there has ever been an incoming connection attempt - // to this torrent. - bool has_incoming; - // the number of regions of non-downloaded pieces in the // torrent. This is an interesting metric on windows vista, since there is // a limit on the number of sparse regions in a single file there. int sparse_regions; - // true if the torrent is in seed_mode. If the torrent was - // started in seed mode, it will leave seed mode once all pieces have been - // checked or as soon as one piece fails the hash check. - bool seed_mode; + // the priority of this torrent + int priority; + + // the main state the torrent is in. See torrent_status::state_t. + boost::uint8_t state; + + // true if this torrent has unsaved changes + // to its download state and statistics since the last resume data + // was saved. + bool need_save_resume; + + // true if the session global IP filter applies + // to this torrent. This defaults to true. + bool ip_filter_applies; // true if the torrent is blocked from downloading. This // typically happens when a disk write operation fails. If the torrent is @@ -1385,39 +1381,43 @@ namespace libtorrent // true if the torrent is in super seeding mode bool super_seeding; - // the priority of this torrent - int priority; + // set to true if the torrent is paused and false otherwise. It's only true + // if the torrent itself is paused. If the torrent is not running because the session is + // paused, this is still false. To know if a torrent is active or not, you need to inspect + // both ``torrent_status::paused`` and ``session::is_paused()``. + bool paused; - // the posix-time when this torrent was added. i.e. what - // ``time(NULL)`` returned at the time. - time_t added_time; - - // the posix-time when this torrent was finished. If - // the torrent is not yet finished, this is 0. - time_t completed_time; + // set to true if the torrent is auto managed, i.e. libtorrent is + // responsible for determining whether it should be started or queued. For more info + // see queuing_ + bool auto_managed; - // the time when we, or one of our peers, last - // saw a complete copy of this torrent. - time_t last_seen_complete; + // true when the torrent is in sequential download mode. In + // this mode pieces are downloaded in order rather than rarest first. + bool sequential_download; - // the number of - // seconds since any peer last uploaded from this torrent and the last - // time a downloaded piece passed the hash check, respectively. - int time_since_upload; - int time_since_download; + // true if all pieces have been downloaded. + bool is_seeding; - // the position this torrent has in the download - // queue. If the torrent is a seed or finished, this is -1. - int queue_position; + // true if all pieces that have a priority > 0 are downloaded. There is + // only a distinction between finished and seeding if some pieces or files have been + // set to priority 0, i.e. are not downloaded. + bool is_finished; - // true if this torrent has unsaved changes - // to its download state and statistics since the last resume data - // was saved. - bool need_save_resume; + // true if this torrent has metadata (either it was started from a + // .torrent file or the metadata has been downloaded). The only scenario where this can be + // false is when the torrent was started torrent-less (i.e. with just an info-hash and tracker + // ip, a magnet link for instance). + bool has_metadata; - // true if the session global IP filter applies - // to this torrent. This defaults to true. - bool ip_filter_applies; + // true if there has ever been an incoming connection attempt + // to this torrent. + bool has_incoming; + + // true if the torrent is in seed_mode. If the torrent was + // started in seed mode, it will leave seed mode once all pieces have been + // checked or as soon as one piece fails the hash check. + bool seed_mode; // the info-hash for this torrent sha1_hash info_hash; diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index 339c116d0..3280ef86c 100644 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -77,21 +77,24 @@ namespace libtorrent { torrent_status::torrent_status() - : state(checking_resume_data) - , paused(false) - , auto_managed(false) - , sequential_download(false) - , is_seeding(false) - , is_finished(false) - , has_metadata(false) - , progress(0.f) - , progress_ppm(0) - , total_download(0) + : total_download(0) , total_upload(0) , total_payload_download(0) , total_payload_upload(0) , total_failed_bytes(0) , total_redundant_bytes(0) + , total_done(0) + , total_wanted_done(0) + , total_wanted(0) + , all_time_upload(0) + , all_time_download(0) + , added_time(0) + , completed_time(0) + , last_seen_complete(0) + , storage_mode(storage_mode_sparse) + , progress(0.f) + , progress_ppm(0) + , queue_position(0) , download_rate(0) , upload_rate(0) , download_payload_rate(0) @@ -104,9 +107,6 @@ namespace libtorrent , list_peers(0) , connect_candidates(0) , num_pieces(0) - , total_done(0) - , total_wanted_done(0) - , total_wanted(0) , distributed_full_copies(0) , distributed_fraction(0) , distributed_copies(0.f) @@ -115,31 +115,31 @@ namespace libtorrent , num_connections(0) , uploads_limit(0) , connections_limit(0) - , storage_mode(storage_mode_sparse) , up_bandwidth_queue(0) , down_bandwidth_queue(0) - , all_time_upload(0) - , all_time_download(0) + , time_since_upload(0) + , time_since_download(0) , active_time(0) , finished_time(0) , seeding_time(0) , seed_rank(0) , last_scrape(0) - , has_incoming(false) , sparse_regions(0) - , seed_mode(false) + , priority(0) + , state(checking_resume_data) + , need_save_resume(false) + , ip_filter_applies(true) , upload_mode(false) , share_mode(false) , super_seeding(false) - , priority(0) - , added_time(0) - , completed_time(0) - , last_seen_complete(0) - , time_since_upload(0) - , time_since_download(0) - , queue_position(0) - , need_save_resume(false) - , ip_filter_applies(true) + , paused(false) + , auto_managed(false) + , sequential_download(false) + , is_seeding(false) + , is_finished(false) + , has_metadata(false) + , has_incoming(false) + , seed_mode(false) , info_hash(0) {}