From df281f81aeb51bb9134207524c77425ec69371c5 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 31 Oct 2004 23:16:08 +0000 Subject: [PATCH] *** empty log message *** --- Jamfile | 33 ++---- docs/manual.html | 186 +++++++++++++++++++-------------- docs/manual.rst | 41 ++++++-- examples/Jamfile | 19 +--- include/libtorrent/session.hpp | 9 ++ src/identify_client.cpp | 1 + src/peer_connection.cpp | 18 ++-- src/session.cpp | 33 +++++- src/torrent.cpp | 2 +- src/torrent_info.cpp | 37 +++++-- 10 files changed, 230 insertions(+), 149 deletions(-) diff --git a/Jamfile b/Jamfile index f22143535..c539c1d6c 100755 --- a/Jamfile +++ b/Jamfile @@ -8,33 +8,33 @@ BOOST_ROOT = [ modules.peek : BOOST_ROOT ] ; ECHO "BOOST_ROOT =" $(BOOST_ROOT) ; ECHO "OS =" [ os.name ] ; -use-project /boost/thread : $(BOOST_ROOT)/libs/thread/build ; -use-project /boost/filesystem : $(BOOST_ROOT)/libs/filesystem/build ; -use-project /boost/date_time : $(BOOST_ROOT)/libs/date_time/build ; +use-project /boost : $(BOOST_ROOT) ; + +project torrent + + : requirements -REQUIREMENTS = ./include ./zlib $(BOOST_ROOT) release:NDEBUG BOOST_ALL_NO_LIB _FILE_OFFSET_BITS=64 - /boost/thread//boost_thread + /boost/thread//boost_thread/ /boost/filesystem//boost_filesystem/static /boost/date_time//boost_date_time/static - -# devstudio switches - + static + multi msvc-7:/Zc:wchar_t msvc-7.1:/Zc:wchar_t - ; + : usage-requirements -USAGE_REQUIREMENTS = ./include $(BOOST_ROOT) release:NDEBUG BOOST_ALL_NO_LIB + ; SOURCES = @@ -89,24 +89,11 @@ LIBS = ; SOURCES += file.cpp ; } -project torrent - : requirements - $(REQUIREMENTS) - : usage-requirements - $(USAGE_REQUIREMENTS) - ; - - lib torrent : src/$(SOURCES) zlib/$(ZLIB_SOURCES) $(LIBS) - : - multi - static - debug:TORRENT_VERBOSE_LOGGING - : debug release ; diff --git a/docs/manual.html b/docs/manual.html index 6b0ab9318..07d0be9af 100755 --- a/docs/manual.html +++ b/docs/manual.html @@ -25,98 +25,99 @@
  • ~session()
  • add_torrent()
  • remove_torrent()
  • -
  • set_upload_rate_limit() set_download_rate_limit()
  • -
  • set_max_uploads() set_max_connections()
  • -
  • status()
  • -
  • is_listening() listen_port() listen_on()
  • -
  • pop_alert() set_severity_level()
  • +
  • disable_extensions() enable_extension()
  • +
  • set_upload_rate_limit() set_download_rate_limit()
  • +
  • set_max_uploads() set_max_connections()
  • +
  • status()
  • +
  • is_listening() listen_port() listen_on()
  • +
  • pop_alert() set_severity_level()
  • -
  • entry
      -
    • integer() string() list() dict() type()
    • +
    • entry
    • -
    • torrent_info
        -
      • begin_files() end_files() rbegin_files() rend_files()
      • -
      • num_files() file_at()
      • -
      • print()
      • -
      • trackers()
      • -
      • total_size() piece_length() piece_size() num_pieces()
      • -
      • hash_for_piece() info_hash()
      • -
      • name() comment() creation_date()
      • +
      • torrent_info
      • -
      • torrent_handle
          -
        • save_path()
        • -
        • move_storage()
        • -
        • force_reannounce()
        • -
        • connect_peer()
        • -
        • set_ratio()
        • -
        • set_upload_limit() set_download_limit()
        • -
        • pause() resume() is_paused()
        • -
        • is_seed()
        • -
        • set_tracker_login()
        • -
        • use_interface()
        • -
        • info_hash()
        • -
        • set_max_uploads() set_max_connections()
        • -
        • write_resume_data()
        • -
        • metadata()
        • -
        • status()
        • -
        • get_download_queue()
        • -
        • get_peer_info()
        • -
        • get_torrent_info()
        • -
        • is_valid()
        • +
        • torrent_handle
        • -
        • torrent_status
        • -
        • peer_info
        • -
        • address
        • -
        • http_settings
        • -
        • big_number
        • -
        • hasher
        • -
        • fingerprint
        • -
        • free functions
            -
          • identify_client()
          • -
          • bdecode() bencode()
          • +
          • torrent_status
          • +
          • peer_info
          • +
          • address
          • +
          • http_settings
          • +
          • big_number
          • +
          • hasher
          • +
          • fingerprint
          • +
          • free functions
          • -
          • alerts
              -
            • listen_failed_alert
            • -
            • file_error_alert
            • -
            • tracker_alert
            • -
            • hash_failed_alert
            • -
            • peer_ban_alert
            • -
            • peer_error_alert
            • -
            • invalid_request_alert
            • -
            • torrent_finished_alert
            • -
            • metadata_received_alert
            • -
            • dispatcher
            • +
            • alerts
            • -
            • exceptions
                -
              • invalid_handle
              • -
              • duplicate_torrent
              • -
              • invalid_encoding
              • -
              • type_error
              • -
              • invalid_torrent_file
              • +
              • exceptions
              • -
              • examples
                  -
                • dump_torrent
                • -
                • simple client
                • +
                • examples
                • -
                • fast resume -

                  libtorrent is portable at least among windows, macosx, and UNIX-systems. It uses boost.thread, -boost.filesystem, boost.date_time and various other boost libraries as well as zlib.

                  +

                  libtorrent is portable at least among windows, macosx, and other UNIX-systems. It uses Boost.Thread, +Boost.Filesystem, Boost.Date_time and various other boost libraries as well as zlib.

                  libtorrent has been successfully compiled and tested on:

                  • Windows 2000 vc7.1
                  • -
                  • Linux x86 (debian) GCC 3.0.4, GCC 3.2.3
                  • +
                  • Linux x86 GCC 3.0.4, GCC 3.2.3, GCC 3.4.2
                  • MacOS X, GCC 3.3
                  • SunOS 5.8 GCC 3.1
                  • +
                  • Cygwin GCC 3.3.3

                  Fails on:

                  • GCC 2.95.4 (std::ios_base is missing)
                  • -
                  • Cygwin GCC 3.3.1 (builds but crashes)
                  • msvc6 sp5
                  @@ -272,11 +273,6 @@ written. checks in the storage, including logging of piece sorting. -TORRENT_DISABLE_EXTENSIONS -This will disble the support for extensions. -For more information on which extensions are -currently implemented, see extensions. -

                  If you experience that libtorrent uses unreasonable amounts of cpu, it will definately help to @@ -337,6 +333,9 @@ class session: public boost::noncopyable void remove_torrent(torrent_handle const& h); + void disable_extensions(); + void enable_extension(peer_connection::extension_index); + void set_http_settings(const http_settings& settings); void set_upload_rate_limit(int bytes_per_second); @@ -429,6 +428,31 @@ void remove_torrent(torrent_handle const& h);

                  remove_torrent() will close all peer connections associated with the torrent and tell the tracker that we've stopped participating in the swarm.

                  +
                  +

                  disable_extensions() enable_extension()

                  +
                  +
                  +void disable_extensions();
                  +void enable_extension(peer_connection::extension_index);
                  +
                  +
                  +

                  disable_extensions() will disable all extensions available in libtorrent. +enable_extension() will enable a single extension. The available extensions +are enumerated in the peer_connection class. These are the available extensions:

                  +
                  +enum extension_index
                  +{
                  +        extended_chat_message,
                  +        extended_metadata_message,
                  +        extended_peer_exchange_message,
                  +        extended_listen_port_message,
                  +        num_supported_extensions
                  +};
                  +
                  +

                  peer_exchange is not implemented yet

                  +

                  By default, all extensions are enabled. +For more information about the extensions, see the extensions section.

                  +

                  set_upload_rate_limit() set_download_rate_limit()

                  diff --git a/docs/manual.rst b/docs/manual.rst index 61326c084..90d2948ab 100755 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -61,20 +61,20 @@ Functions that are yet to be implemented: * ip-filters * file-level priority -libtorrent is portable at least among windows, macosx, and UNIX-systems. It uses boost.thread, -boost.filesystem, boost.date_time and various other boost libraries as well as zlib. +libtorrent is portable at least among windows, macosx, and other UNIX-systems. It uses Boost.Thread, +Boost.Filesystem, Boost.Date_time and various other boost libraries as well as zlib. libtorrent has been successfully compiled and tested on: * Windows 2000 vc7.1 - * Linux x86 (debian) GCC 3.0.4, GCC 3.2.3 + * Linux x86 GCC 3.0.4, GCC 3.2.3, GCC 3.4.2 * MacOS X, GCC 3.3 * SunOS 5.8 GCC 3.1 + * Cygwin GCC 3.3.3 Fails on: * GCC 2.95.4 (``std::ios_base`` is missing) - * Cygwin GCC 3.3.1 (builds but crashes) * msvc6 sp5 libtorrent is released under the BSD-license_. @@ -174,10 +174,6 @@ table below for which defines you can use to control the build. The ``Jamfile`` | | checks in the storage, including logging of | | | piece sorting. | +--------------------------------+-------------------------------------------------+ -| ``TORRENT_DISABLE_EXTENSIONS`` | This will disble the support for extensions. | -| | For more information on which extensions are | -| | currently implemented, see extensions_. | -+--------------------------------+-------------------------------------------------+ If you experience that libtorrent uses unreasonable amounts of cpu, it will definately help to @@ -235,6 +231,9 @@ The ``session`` class has the following synopsis:: void remove_torrent(torrent_handle const& h); + void disable_extensions(); + void enable_extension(peer_connection::extension_index); + void set_http_settings(const http_settings& settings); void set_upload_rate_limit(int bytes_per_second); @@ -335,6 +334,32 @@ remove_torrent() the tracker that we've stopped participating in the swarm. +disable_extensions() enable_extension() +--------------------------------------- + + :: + + void disable_extensions(); + void enable_extension(peer_connection::extension_index); + +``disable_extensions()`` will disable all extensions available in libtorrent. +``enable_extension()`` will enable a single extension. The available extensions +are enumerated in the ``peer_connection`` class. These are the available extensions:: + + enum extension_index + { + extended_chat_message, + extended_metadata_message, + extended_peer_exchange_message, + extended_listen_port_message, + num_supported_extensions + }; + +*peer_exchange is not implemented yet* + +By default, all extensions are enabled. +For more information about the extensions, see the extensions_ section. + set_upload_rate_limit() set_download_rate_limit() ------------------------------------------------- diff --git a/examples/Jamfile b/examples/Jamfile index d03ca0fa8..a01d2cdc0 100755 --- a/examples/Jamfile +++ b/examples/Jamfile @@ -1,38 +1,25 @@ use-project /torrent : .. ; +project + : requirements /torrent multi + ; exe client_test : client_test.cpp - /torrent - : - multi - : debug release ; exe simple_client : simple_client.cpp - /torrent - : - multi - : debug release ; exe dump_torrent : dump_torrent.cpp - /torrent - : - multi - : debug release ; exe make_torrent : make_torrent.cpp - /torrent - : - multi - : debug release ; diff --git a/include/libtorrent/session.hpp b/include/libtorrent/session.hpp index 828a265bb..c5c371d8e 100755 --- a/include/libtorrent/session.hpp +++ b/include/libtorrent/session.hpp @@ -216,6 +216,12 @@ namespace libtorrent boost::shared_ptr m_listen_socket; + // the entries in this array maps the + // extension index (as specified in peer_connection) + bool m_extension_enabled[peer_connection::num_supported_extensions]; + + bool extensions_enabled() const; + // the settings for the client http_settings m_settings; @@ -304,6 +310,9 @@ namespace libtorrent session_status status() const; + void enable_extension(peer_connection::extension_index i); + void disable_extensions(); + bool is_listening() const; // if the listen port failed in some way diff --git a/src/identify_client.cpp b/src/identify_client.cpp index 7bb8a1128..e828c95dd 100755 --- a/src/identify_client.cpp +++ b/src/identify_client.cpp @@ -155,6 +155,7 @@ namespace map_entry name_map[] = { map_entry("A", "ABC") + , map_entry("AR", "Arctic Torrent") , map_entry("AZ", "Azureus") , map_entry("BB", "BitBuddy") , map_entry("BX", "BittorrentX") diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 262b4ebd4..9a445d440 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -413,9 +413,9 @@ namespace libtorrent , m_send_buffer.begin() + pos + 8 , 0); // indicate that we support the extension protocol -#ifndef TORRENT_DISABLE_EXTENSIONS - m_send_buffer[pos+7] = 0x01; -#endif + + if (m_ses.extensions_enabled()) + m_send_buffer[pos+7] = 0x01; pos += 8; // info hash @@ -1057,7 +1057,7 @@ namespace libtorrent assert(m_torrent); assert(received > 0); - if (m_packet_size > 100 * 1024) + if (m_packet_size > 100 * 1000) { // too big extension message, abort throw protocol_error("'extensions' message size > 100kB"); @@ -1125,6 +1125,9 @@ namespace libtorrent const char* ptr = &m_recv_buffer[1]; int extended_id = detail::read_int32(ptr); + if (!m_ses.m_extension_enabled[extended_id]) + throw protocol_error("'extended' message using disabled extension"); + switch (extended_id) { case extended_chat_message: @@ -1587,6 +1590,9 @@ namespace libtorrent for (int i = 0; i < num_supported_extensions; ++i) { + // if this specific extension is disabled + // just don't add it to the supported set + if (!m_ses.m_extension_enabled[i]) continue; extension_list[extension_names[i]] = i; } @@ -1953,10 +1959,8 @@ namespace libtorrent // ok, now we have got enough of the handshake. Is this connection // attached to a torrent? -#ifndef TORRENT_DISABLE_EXTENSIONS - if (m_recv_buffer[7] & 0x01) + if ((m_recv_buffer[7] & 0x01) && m_ses.extensions_enabled()) m_supports_extensions = true; -#endif if (m_torrent == 0) { diff --git a/src/session.cpp b/src/session.cpp index 158fa4757..c6abfa49d 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -203,6 +203,8 @@ namespace libtorrent { namespace detail #ifndef NDEBUG m_logger = create_log("main session"); #endif + std::fill(m_extension_enabled, m_extension_enabled + + peer_connection::num_supported_extensions, true); // ---- generate a peer id ---- std::srand((unsigned int)std::time(0)); @@ -229,6 +231,13 @@ namespace libtorrent { namespace detail } } + bool session_impl::extensions_enabled() const + { + const int n = peer_connection::num_supported_extensions; + return std::find(m_extension_enabled + , m_extension_enabled + n, true) != m_extension_enabled + n; + } + void session_impl::purge_connections() { while (!m_disconnect_peer.empty()) @@ -852,6 +861,21 @@ namespace libtorrent #endif } + void session::disable_extensions() + { + boost::mutex::scoped_lock l(m_impl.m_mutex); + std::fill(m_impl.m_extension_enabled, m_impl.m_extension_enabled + + peer_connection::num_supported_extensions, false); + } + + void session::enable_extension(peer_connection::extension_index i) + { + assert(i >= 0); + assert(i < peer_connection::num_supported_extensions); + boost::mutex::scoped_lock l(m_impl.m_mutex); + m_impl.m_extension_enabled[i] = true; + } + // TODO: add a check to see if filenames are accepted on the // current platform. // if the torrent already exists, this will throw duplicate_torrent @@ -903,7 +927,6 @@ namespace libtorrent return torrent_handle(&m_impl, &m_checker_impl, ti.info_hash()); } -#ifndef TORRENT_DISABLE_EXTENSIONS torrent_handle session::add_torrent( char const* tracker_url , sha1_hash const& info_hash @@ -923,6 +946,10 @@ namespace libtorrent // lock the session boost::mutex::scoped_lock l(m_impl.m_mutex); + // the metadata extension has to be enabled for this to work + assert(m_impl.m_extension_enabled + [peer_connection::extended_metadata_message]); + // is the torrent already active? if (m_impl.find_torrent(info_hash)) throw duplicate_torrent(); @@ -931,14 +958,14 @@ namespace libtorrent // the checker thread and store it before starting // the thread boost::shared_ptr torrent_ptr( - new torrent(m_impl, tracker_url, info_hash, save_path, m_impl.m_listen_interface)); + new torrent(m_impl, tracker_url, info_hash, save_path + , m_impl.m_listen_interface)); m_impl.m_torrents.insert( std::make_pair(info_hash, torrent_ptr)).first; return torrent_handle(&m_impl, &m_checker_impl, info_hash); } -#endif void session::remove_torrent(const torrent_handle& h) { diff --git a/src/torrent.cpp b/src/torrent.cpp index 98ca935df..686dd44e6 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -827,7 +827,7 @@ namespace libtorrent if (m_paused) { // let the stats fade out to 0 - m_stat.second_tick(); + m_stat.second_tick(); return; } diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index 366b43fde..a9632a7ef 100755 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -43,10 +43,10 @@ POSSIBILITY OF SUCH DAMAGE. #endif #include -#include #include #include #include +#include #ifdef _MSC_VER #pragma warning(pop) @@ -83,13 +83,6 @@ namespace } } - size_type to_seconds(const boost::posix_time::time_duration& d) - { - return d.hours() * 60 * 60 - + d.minutes() * 60 - + d.seconds(); - } - void remove_dir(path& p) { assert(p.begin() != p.end()); @@ -318,6 +311,10 @@ namespace libtorrent announce_entry e(url); e.tier = tier; m_urls.push_back(e); + + using boost::bind; + std::sort(m_urls.begin(), m_urls.end(), bind(std::less() + , bind(&announce_entry::tier, _1), bind(&announce_entry::tier, _2))); } void torrent_info::add_file(boost::filesystem::path file, size_type size) @@ -455,12 +452,32 @@ namespace libtorrent } dict["announce"] = m_urls.front().url; - + + if (m_urls.size() > 1) + { + entry trackers(entry::list_t); + entry tier(entry::list_t); + int current_tier = m_urls.front().tier; + for (std::vector::const_iterator i = m_urls.begin(); + i != m_urls.end(); ++i) + { + if (i->tier != current_tier) + { + current_tier = i->tier; + trackers.list().push_back(tier); + tier.list().clear(); + } + tier.list().push_back(i->url); + } + trackers.list().push_back(tier); + dict["announce-list"] = trackers; + } + if (!m_comment.empty()) dict["comment"] = m_comment; dict["creation date"] = - to_seconds(m_creation_date - ptime(date(1970, Jan, 1))); + (m_creation_date - ptime(date(1970, Jan, 1))).total_seconds(); if (!m_created_by.empty()) dict["created by"] = m_created_by;