diff --git a/docs/extension_protocol.html b/docs/extension_protocol.html index cbea09cfa..52fae31d5 100644 --- a/docs/extension_protocol.html +++ b/docs/extension_protocol.html @@ -116,8 +116,8 @@ i.e. The IDs are local to this particular peer.

Here are some other items that an implementation may choose to support:

--++ @@ -133,10 +133,17 @@ this extension message, since its port number is already known. - + + + attempt. This may happen if there is a limit set on the number of half-open TCP connections. + + + + + + + + +
name
vClient name and version (as an utf-8 string). +Client name and version (as a utf-8 string). This is a much more reliable way of identifying the client than relying on the peer id encoding.
youripA string containing the compact representation of the ip +address this peer sees you as. i.e. this is the +receiver's external ip address (no port is included). +This may be both an IPv4 (4 bytes) or an IPv6 (16 bytes) +address.
reqq An integer, the number of outstanding request messages this client supports without dropping any. The default in diff --git a/docs/manual.html b/docs/manual.html index 438b8ac5c..0a7316655 100644 --- a/docs/manual.html +++ b/docs/manual.html @@ -62,7 +62,7 @@
  • num_files() file_at()
  • map_block()
  • map_file()
  • -
  • url_seeds()
  • +
  • url_seeds() add_url_seed()
  • print()
  • trackers()
  • total_size() piece_length() piece_size() num_pieces()
  • @@ -91,7 +91,7 @@
  • has_metadata()
  • set_tracker_login()
  • trackers() replace_trackers()
  • -
  • add_url_seed()
  • +
  • add_url_seed() remove_url_seed() url_seeds()
  • use_interface()
  • info_hash()
  • set_max_uploads() set_max_connections()
  • @@ -144,34 +144,36 @@
  • metadata_received_alert
  • fastresume_rejected_alert
  • peer_blocked_alert
  • -
  • dispatcher
  • +
  • storage_moved_alert
  • +
  • torrent_paused_alert
  • +
  • dispatcher
  • -
  • exceptions
      -
    • invalid_handle
    • -
    • duplicate_torrent
    • -
    • invalid_encoding
    • -
    • type_error
    • -
    • invalid_torrent_file
    • +
    • exceptions
    • -
    • fast resume
        -
      • file format
      • +
      • fast resume
      • -
      • threads
      • -
      • storage allocation
          -
        • full allocation
        • -
        • compact allocation
        • +
        • threads
        • +
        • storage allocation
        • -
        • extensions
          @@ -242,7 +244,7 @@ class session: public boost::noncopyable , boost::filesystem::path const& save_path , entry const& resume_data = entry() , bool compact_mode = true - , int block_size = 16 * 1024); + , bool paused = false); torrent_handle add_torrent( char const* tracker_url @@ -251,7 +253,7 @@ class session: public boost::noncopyable , boost::filesystem::path const& save_path , entry const& resume_data = entry() , bool compact_mode = true - , int block_size = 16 * 1024); + , bool paused = true); session_proxy abort(); @@ -370,7 +372,7 @@ torrent_handle add_torrent( , boost::filesystem::path const& save_path , entry const& resume_data = entry() , bool compact_mode = true - , int block_size = 16 * 1024); + , bool paused = false); torrent_handle add_torrent( char const* tracker_url @@ -379,7 +381,7 @@ torrent_handle add_torrent( , boost::filesystem::path const& save_path , entry const& resume_data = entry() , bool compact_mode = true - , int block_size = 16 * 1024); + , bool paused = false);

          You add torrents through the add_torrent() function where you give an @@ -398,10 +400,10 @@ are rearranged to finally be in their correct places once the entire torrent has downloaded. If it is false, the entire storage is allocated before download begins. I.e. the files contained in the torrent are filled with zeros, and each downloaded piece is put in its final place directly when downloaded. For more info, see storage allocation.

          -

          block_size sets the preferred request size, i.e. the number of bytes to request from -a peer at a time. This block size must be a divisor of the piece size, and since the piece -size is an even power of 2, so must the block size be. If the block size given here turns -out to be greater than the piece size, it will simply be clamped to the piece size.

          +

          paused is a boolean that specifies whether or not the torrent is to be started in +a paused state. I.e. it won't connect to the tracker or any of the peers until it's +resumed. This is typically a good way of avoiding race conditions when setting +configuration options on torrents before starting them.

          The torrent_handle returned by add_torrent() can be used to retrieve information about the torrent's progress, its peers etc. It is also used to abort a torrent.

          The second overload that takes a tracker url and an info-hash instead of metadata @@ -1163,7 +1165,7 @@ struct peer_request must refer to a valid file, i.e. it cannot be >= num_files().

          -

          url_seeds()

          +

          url_seeds() add_url_seed()

           std::vector<std::string> const& url_seeds() const;
          @@ -1320,6 +1322,8 @@ struct torrent_handle
                   void replace_trackers(std::vector<announce_entry> const&);
           
                   void add_url_seed(std::string const& url);
          +        void remove_url_seed(std::string const& url);
          +        std::set<std::string> url_seeds() const;
           
                   void set_ratio(float ratio) const;
                   void set_max_uploads(int max_uploads) const;
          @@ -1361,7 +1365,7 @@ struct torrent_handle
                   bool has_metadata() const;
           
                   boost::filesystem::path save_path() const;
          -        bool move_storage(boost::filesystem::path const& save_path) const;
          +        void move_storage(boost::filesystem::path const& save_path) const;
           
                   sha1_hash info_hash() const;
           
          @@ -1453,14 +1457,14 @@ was started.

          move_storage()

          -bool move_storage(boost::filesystem::path const& save_path) const;
          +void move_storage(boost::filesystem::path const& save_path) const;
           

          Moves the file(s) that this torrent are currently seeding from or downloading to. This operation will only have the desired effect if the given save_path is located on -the same drive as the original save path. If the move operation fails, this function -returns false, otherwise true. Post condition for successful operation is: -save_path() == save_path.

          +the same drive as the original save path. Since disk IO is performed in a separate +thread, this operation is also asynchronous. Once the operation completes, the +storage_moved_alert is generated, with the new path as the message.

          force_reannounce()

          @@ -1640,16 +1644,21 @@ replace it. If you want an immediate effect, you have to call force_reannounce().

          -

          add_url_seed()

          +

          add_url_seed() remove_url_seed() url_seeds()

           void add_url_seed(std::string const& url);
          +void remove_url_seed(std::string const& url);
          +std::set<std::string> url_seeds() const;
           

          add_url_seed() adds another url to the torrent's list of url seeds. If the given url already exists in that list, the call has no effect. The torrent will connect to the server and try to download pieces from it, unless it's -paused, queued, checking or seeding.

          +paused, queued, checking or seeding. remove_url_seed() removes the given +url if it exists already. url_seeds() return a set of the url seeds +currently in this torrent. Note that urls that fails may be removed +automatically from the list.

          See HTTP seeding for more information.

          @@ -1709,7 +1718,9 @@ not be ready to write resume data.
        • Note that by the time this function returns, the resume data may already be invalid if the torrent is still downloading! The recommended practice is to first pause the torrent, then generate the -fast resume data, and then close it down.

          +fast resume data, and then close it down. Since the disk IO is done in a separate thread, in order +to synchronize, you shoule to wait for the torrent_paused_alert before you write the resume +data.

          It is still a good idea to save resume data periodically during download as well as when closing down. In full allocation mode the reume data is never invalidated by subsequent writes to the files, since pieces won't move around.

          @@ -1762,7 +1773,7 @@ struct block_info tcp::endpoint peer; unsigned state:2; - unsigned num_downloads:14; + unsigned num_peers:14; };

          The block_info array contains data for each individual block in the piece. Each block has @@ -1774,7 +1785,9 @@ a state (state) which

        • finished - The block has been written to disk.

        The peer field is the ip address of the peer this block was downloaded from. -num_downloads is the number of times this block has been downloaded.

        +num_peers is the number of peers that is currently requesting this block. Typically this +is 0 or 1, but at the end of the torrent blocks may be requested by more peers in parallel to +speed things up.

        get_peer_info()

        @@ -2011,8 +2024,9 @@ struct peer_info queued = 0x100, on_parole = 0x200, seed = 0x400, - rc4_encrypted = 0x800, - plaintext_encrypted = 0x1000 + optimistic_unchoke = 0x800, + rc4_encrypted = 0x100000, + plaintext_encrypted = 0x200000 }; unsigned int flags; @@ -2106,6 +2120,23 @@ being connected).
  • on_paroleThe peer has participated in a piece that failed the +hash check, and is now "on parole", which means we're +only requesting whole pieces from this peer until +it either fails that piece or proves that it doesn't +send bad data.
    seedThis peer is a seed (it has all the pieces).
    optimistic_unchokeThis peer is subject to an optimistic unchoke. It has +been unchoked for a while to see if it might unchoke +us in return an earn an upload/unchoke slot. If it +doesn't within some period of time, it will be choked +and another peer will be optimistically unchoked.

    source is a combination of flags describing from which sources this peer @@ -3134,6 +3165,32 @@ struct peer_blocked_alert: alert

    +

    storage_moved_alert

    +

    The storage_moved_alert is generated when all the disk IO has completed and the +files have been moved, as an effect of a call to torrent_handle::move_storage. This +is useful to synchronize with the actual disk.

    +
    +struct storage_moved_alert: torrent_alert
    +{
    +        storage_moved_alert(torrent_handle const& h, std::string const& path);
    +        virtual std::auto_ptr<alert> clone() const;
    +};
    +
    +
    +
    +

    torrent_paused_alert

    +

    This alert is generated as a response to a torrent_handle::pause request. It is +generated once all disk IO is complete and the files in the torrent have been closed. +This is useful for synchronizing with the disk.

    +
    +struct torrent_paused_alert: torrent_alert
    +{
    +        torrent_paused_alert(torrent_handle const& h, std::string const& msg);
    +        virtual std::auto_ptr<alert> clone() const;
    +};
    +
    +
    +

    dispatcher

    The handle_alert class is defined in <libtorrent/alert.hpp>.

    Examples usage:

    diff --git a/docs/manual.rst b/docs/manual.rst index e9b32aad1..40314773b 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -75,7 +75,7 @@ The ``session`` class has the following synopsis:: , boost::filesystem::path const& save_path , entry const& resume_data = entry() , bool compact_mode = true - , int block_size = 16 * 1024); + , bool paused = false); torrent_handle add_torrent( char const* tracker_url @@ -84,7 +84,7 @@ The ``session`` class has the following synopsis:: , boost::filesystem::path const& save_path , entry const& resume_data = entry() , bool compact_mode = true - , int block_size = 16 * 1024); + , bool paused = true); session_proxy abort(); @@ -208,7 +208,7 @@ add_torrent() , boost::filesystem::path const& save_path , entry const& resume_data = entry() , bool compact_mode = true - , int block_size = 16 * 1024); + , bool paused = false); torrent_handle add_torrent( char const* tracker_url @@ -217,7 +217,7 @@ add_torrent() , boost::filesystem::path const& save_path , entry const& resume_data = entry() , bool compact_mode = true - , int block_size = 16 * 1024); + , bool paused = false); You add torrents through the ``add_torrent()`` function where you give an object representing the information found in the torrent file and the path where you @@ -239,10 +239,10 @@ downloaded. If it is false, the entire storage is allocated before download begi the files contained in the torrent are filled with zeros, and each downloaded piece is put in its final place directly when downloaded. For more info, see `storage allocation`_. -``block_size`` sets the preferred request size, i.e. the number of bytes to request from -a peer at a time. This block size must be a divisor of the piece size, and since the piece -size is an even power of 2, so must the block size be. If the block size given here turns -out to be greater than the piece size, it will simply be clamped to the piece size. +``paused`` is a boolean that specifies whether or not the torrent is to be started in +a paused state. I.e. it won't connect to the tracker or any of the peers until it's +resumed. This is typically a good way of avoiding race conditions when setting +configuration options on torrents before starting them. The torrent_handle_ returned by ``add_torrent()`` can be used to retrieve information about the torrent's progress, its peers etc. It is also used to abort a torrent. @@ -2009,8 +2009,9 @@ It contains the following fields:: queued = 0x100, on_parole = 0x200, seed = 0x400, - rc4_encrypted = 0x800, - plaintext_encrypted = 0x1000 + optimistic_unchoke = 0x800, + rc4_encrypted = 0x100000, + plaintext_encrypted = 0x200000 }; unsigned int flags; @@ -2091,6 +2092,20 @@ any combination of the enums above. The following table describes each flag: | | attempt. This may happen if there is a limit set on | | | the number of half-open TCP connections. | +-------------------------+-------------------------------------------------------+ +| ``on_parole`` | The peer has participated in a piece that failed the | +| | hash check, and is now "on parole", which means we're | +| | only requesting whole pieces from this peer until | +| | it either fails that piece or proves that it doesn't | +| | send bad data. | ++-------------------------+-------------------------------------------------------+ +| ``seed`` | This peer is a seed (it has all the pieces). | ++-------------------------+-------------------------------------------------------+ +| ``optimistic_unchoke`` | This peer is subject to an optimistic unchoke. It has | +| | been unchoked for a while to see if it might unchoke | +| | us in return an earn an upload/unchoke slot. If it | +| | doesn't within some period of time, it will be choked | +| | and another peer will be optimistically unchoked. | ++-------------------------+-------------------------------------------------------+ __ extension_protocol.html diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index e30a07c0b..606a38930 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -244,8 +244,8 @@ namespace libtorrent , fs::path const& save_path , entry const& resume_data , bool compact_mode - , int block_size - , storage_constructor_type sc); + , storage_constructor_type sc + , bool paused); torrent_handle add_torrent( char const* tracker_url @@ -254,8 +254,8 @@ namespace libtorrent , fs::path const& save_path , entry const& resume_data , bool compact_mode - , int block_size - , storage_constructor_type sc); + , storage_constructor_type sc + , bool paused); void remove_torrent(torrent_handle const& h); diff --git a/include/libtorrent/session.hpp b/include/libtorrent/session.hpp index a123314ed..7b54c1ad5 100755 --- a/include/libtorrent/session.hpp +++ b/include/libtorrent/session.hpp @@ -141,23 +141,9 @@ namespace libtorrent , fs::path const& save_path , entry const& resume_data = entry() , bool compact_mode = true - , int block_size = 16 * 1024 + , bool paused = false , storage_constructor_type sc = default_storage_constructor); - // ==== deprecated, this is for backwards compatibility only - // instead, use one of the other add_torrent overloads - torrent_handle add_torrent( - entry const& e - , fs::path const& save_path - , entry const& resume_data = entry() - , bool compact_mode = true - , int block_size = 16 * 1024 - , storage_constructor_type sc = default_storage_constructor) TORRENT_DEPRECATED - { - return add_torrent(torrent_info(e), save_path, resume_data - , compact_mode, block_size, sc); - } - torrent_handle add_torrent( char const* tracker_url , sha1_hash const& info_hash @@ -165,7 +151,7 @@ namespace libtorrent , fs::path const& save_path , entry const& resume_data = entry() , bool compact_mode = true - , int block_size = 16 * 1024 + , bool paused = true , storage_constructor_type sc = default_storage_constructor); session_proxy abort() { return session_proxy(m_impl); } diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 6781465c0..dabc34141 100755 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -102,8 +102,8 @@ namespace libtorrent , tcp::endpoint const& net_interface , bool compact_mode , int block_size - , session_settings const& s - , storage_constructor_type sc); + , storage_constructor_type sc + , bool paused); // used with metadata-less torrents // (the metadata is downloaded from the peers) @@ -117,8 +117,8 @@ namespace libtorrent , tcp::endpoint const& net_interface , bool compact_mode , int block_size - , session_settings const& s - , storage_constructor_type sc); + , storage_constructor_type sc + , bool paused); ~torrent(); diff --git a/src/session.cpp b/src/session.cpp index 6d6fa55b2..8175cbdfe 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -179,11 +179,11 @@ namespace libtorrent , fs::path const& save_path , entry const& resume_data , bool compact_mode - , int block_size + , bool paused , storage_constructor_type sc) { return m_impl->add_torrent(ti, save_path, resume_data - , compact_mode, block_size, sc); + , compact_mode, sc, paused); } torrent_handle session::add_torrent( @@ -193,11 +193,11 @@ namespace libtorrent , fs::path const& save_path , entry const& e , bool compact_mode - , int block_size + , bool paused , storage_constructor_type sc) { return m_impl->add_torrent(tracker_url, info_hash, name, save_path, e - , compact_mode, block_size, sc); + , compact_mode, sc, paused); } void session::remove_torrent(const torrent_handle& h) diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 2b069ba65..d20cf9668 100755 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -1447,25 +1447,12 @@ namespace detail , fs::path const& save_path , entry const& resume_data , bool compact_mode - , int block_size - , storage_constructor_type sc) + , storage_constructor_type sc + , bool paused) { // if you get this assert, you haven't managed to // open a listen port. call listen_on() first. assert(m_external_listen_port > 0); - - // make sure the block_size is an even power of 2 -#ifndef NDEBUG - for (int i = 0; i < 32; ++i) - { - if (block_size & (1 << i)) - { - assert((block_size & ~(1 << i)) == 0); - break; - } - } -#endif - assert(!save_path.empty()); if (ti.begin_files() == ti.end_files()) @@ -1493,8 +1480,8 @@ namespace detail // the thread boost::shared_ptr torrent_ptr( new torrent(*this, m_checker_impl, ti, save_path - , m_listen_interface, compact_mode, block_size - , settings(), sc)); + , m_listen_interface, compact_mode, 16 * 1024 + , sc, paused)); torrent_ptr->start(); #ifndef TORRENT_DISABLE_EXTENSIONS @@ -1540,20 +1527,9 @@ namespace detail , fs::path const& save_path , entry const& , bool compact_mode - , int block_size - , storage_constructor_type sc) + , storage_constructor_type sc + , bool paused) { - // make sure the block_size is an even power of 2 -#ifndef NDEBUG - for (int i = 0; i < 32; ++i) - { - if (block_size & (1 << i)) - { - assert((block_size & ~(1 << i)) == 0); - break; - } - } -#endif // TODO: support resume data in this case assert(!save_path.empty()); @@ -1583,8 +1559,8 @@ namespace detail // the thread boost::shared_ptr torrent_ptr( new torrent(*this, m_checker_impl, tracker_url, info_hash, name - , save_path, m_listen_interface, compact_mode, block_size - , settings(), sc)); + , save_path, m_listen_interface, compact_mode, 16 * 1024 + , sc, paused)); torrent_ptr->start(); #ifndef TORRENT_DISABLE_EXTENSIONS diff --git a/src/torrent.cpp b/src/torrent.cpp index 31dc5b83d..a425a8f51 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -155,11 +155,11 @@ namespace libtorrent , tcp::endpoint const& net_interface , bool compact_mode , int block_size - , session_settings const& s - , storage_constructor_type sc) + , storage_constructor_type sc + , bool paused) : m_torrent_file(tf) , m_abort(false) - , m_paused(false) + , m_paused(paused) , m_just_paused(false) , m_event(tracker_request::started) , m_block_size(0) @@ -197,7 +197,7 @@ namespace libtorrent , m_compact_mode(compact_mode) , m_default_block_size(block_size) , m_connections_initialized(true) - , m_settings(s) + , m_settings(ses.settings()) , m_storage_constructor(sc) , m_max_uploads((std::numeric_limits::max)()) , m_num_uploads(0) @@ -219,11 +219,11 @@ namespace libtorrent , tcp::endpoint const& net_interface , bool compact_mode , int block_size - , session_settings const& s - , storage_constructor_type sc) + , storage_constructor_type sc + , bool paused) : m_torrent_file(info_hash) , m_abort(false) - , m_paused(false) + , m_paused(paused) , m_just_paused(false) , m_event(tracker_request::started) , m_block_size(0) @@ -260,7 +260,7 @@ namespace libtorrent , m_compact_mode(compact_mode) , m_default_block_size(block_size) , m_connections_initialized(false) - , m_settings(s) + , m_settings(ses.settings()) , m_storage_constructor(sc) , m_max_uploads((std::numeric_limits::max)()) , m_num_uploads(0)