From 4292cfbf04b3e3cebad67016a2adb03daf13ef30 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Mon, 11 Apr 2016 14:20:50 -0400 Subject: [PATCH 01/15] Missing alert categories and support for dht_get_peers_reply_alert in python binding --- ChangeLog | 4 ++++ bindings/python/src/alert.cpp | 29 ++++++++++++++++++++++++++++ include/libtorrent/settings_pack.hpp | 2 +- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index e28359fe2..106405c10 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +1.1.1 release + + * Added missing alert categories in python binding + * Added dht_get_peers_reply_alert alert in python binding 1.1.0 release diff --git a/bindings/python/src/alert.cpp b/bindings/python/src/alert.cpp index 5d1dc623e..729bb4788 100644 --- a/bindings/python/src/alert.cpp +++ b/bindings/python/src/alert.cpp @@ -194,6 +194,22 @@ dict session_stats_values(session_stats_alert const& alert) return d; } +list dht_get_peers_reply_alert_peers(dht_get_peers_reply_alert const& a) +{ + list result; + + std::vector v; + a.peers(v); + + for (std::vector::const_iterator i = v.begin(); + i != v.end(); ++i) + { + result.append(endpoint_to_tuple(*i)); + } + + return result; +} + void bind_alert() { using boost::noncopyable; @@ -239,10 +255,16 @@ void bind_alert() .value("progress_notification", alert::progress_notification) .value("ip_block_notification", alert::ip_block_notification) .value("performance_warning", alert::performance_warning) + .value("dht_notification", alert::dht_notification) .value("stats_notification", alert::stats_notification) .value("session_log_notification", alert::session_log_notification) .value("torrent_log_notification", alert::torrent_log_notification) .value("peer_log_notification", alert::peer_log_notification) + .value("incoming_request_notification", alert::incoming_request_notification) + .value("dht_log_notification", alert::dht_log_notification) + .value("dht_operation_notification", alert::dht_operation_notification) + .value("port_mapping_log_notification", alert::port_mapping_log_notification) + .value("picker_log_notification", alert::picker_log_notification) // deliberately not INT_MAX. Arch linux crash while throwing an exception .value("all_categories", (alert::category_t)0xfffffff) ; @@ -745,4 +767,11 @@ void bind_alert() "session_stats_alert", no_init) .add_property("values", &session_stats_values) ; + + class_, noncopyable>( + "dht_get_peers_reply_alert", no_init) + .def_readonly("info_hash", &dht_get_peers_reply_alert::info_hash) + .def("num_peers", &dht_get_peers_reply_alert::num_peers) + .add_property("peers", &dht_get_peers_reply_alert_peers) + ; } diff --git a/include/libtorrent/settings_pack.hpp b/include/libtorrent/settings_pack.hpp index 456eaee4f..ffc37feb2 100644 --- a/include/libtorrent/settings_pack.hpp +++ b/include/libtorrent/settings_pack.hpp @@ -1033,7 +1033,7 @@ namespace libtorrent // // ``active_loaded_limit`` is the number of torrents that are allowed // to be *loaded* at any given time. Note that a torrent can be active - // even though it's not loaded. if an unloaded torrents finds a peer + // even though it's not loaded. If an unloaded torrents finds a peer // that wants to access it, the torrent will be loaded on demand, // using a user-supplied callback function. If the feature of // unloading torrents is not enabled, this setting have no effect. If From 856700e4018487715694780dc50644576a7de346 Mon Sep 17 00:00:00 2001 From: arvidn Date: Mon, 11 Apr 2016 18:42:09 -0400 Subject: [PATCH 02/15] fix build documentation --- docs/building.rst | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/docs/building.rst b/docs/building.rst index 61adbd756..42c5c8939 100644 --- a/docs/building.rst +++ b/docs/building.rst @@ -245,16 +245,13 @@ Build features: | | * ``shared`` - links dynamically against the boost | | | libraries. | +--------------------------+----------------------------------------------------+ -| ``logging`` | * ``off`` - logging alerts disabled. | -| | * ``on`` - default. logging alerts available, | -| | still need to be enabled by the alert mask. The | +| ``logging`` | * ``off`` - logging alerts disabled. The | | | reason to disable logging is to keep the binary | -| | size down. | +| | size low where that matters. | +| | * ``on`` - default. logging alerts available, | +| | still need to be enabled by the alert mask. | +--------------------------+----------------------------------------------------+ -| ``dht`` | * ``on`` - build with support for tracker less | -| | torrents and DHT support. | -| | * ``logging`` - build with DHT support and verbose | -| | logging of the DHT protocol traffic. | +| ``dht`` | * ``on`` - build with DHT support | | | * ``off`` - build without DHT support. | +--------------------------+----------------------------------------------------+ | ``asserts`` | * ``auto`` - asserts are on if in debug mode | From f23cf8466473de271f73541ac8e46e7e6ed77d39 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Wed, 13 Apr 2016 00:08:08 -0400 Subject: [PATCH 03/15] Disable preadv/pwritev for android --- include/libtorrent/config.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index d7fa0ab3d..9fba3c647 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -216,6 +216,8 @@ POSSIBILITY OF SUCH DAMAGE. // ===== ANDROID ===== (almost linux, sort of) #if defined __ANDROID__ +#define TORRENT_USE_PREADV 0 +#define TORRENT_USE_PREAD 1 #define TORRENT_ANDROID #define TORRENT_HAS_FALLOCATE 0 #define TORRENT_USE_ICONV 0 From 774ea740b4dc9fc83e135cad788b4285df6e93ce Mon Sep 17 00:00:00 2001 From: arvidn Date: Thu, 14 Apr 2016 19:22:27 -0400 Subject: [PATCH 04/15] make session_time return uint16_t --- include/libtorrent/aux_/session_impl.hpp | 7 +++++-- include/libtorrent/aux_/session_interface.hpp | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index 3ffb4273d..65a82a6de 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -982,12 +982,15 @@ namespace libtorrent void recalculate_optimistic_unchoke_slots(); time_point m_created; - boost::int64_t session_time() const TORRENT_OVERRIDE + boost::uint16_t session_time() const TORRENT_OVERRIDE { // +1 is here to make it possible to distinguish uninitialized (to // 0) timestamps and timestamps of things that happend during the // first second after the session was constructed - return total_seconds(aux::time_now() - m_created) + 1; + boost::int64_t const ret = total_seconds(aux::time_now() - m_created) + 1; + TORRENT_ASSERT(ret >= 0); + TORRENT_ASSERT(ret <= (std::numeric_limits::max)()); + return static_cast(ret); } time_point m_last_tick; diff --git a/include/libtorrent/aux_/session_interface.hpp b/include/libtorrent/aux_/session_interface.hpp index a46b825e6..363a64b95 100644 --- a/include/libtorrent/aux_/session_interface.hpp +++ b/include/libtorrent/aux_/session_interface.hpp @@ -177,7 +177,7 @@ namespace libtorrent { namespace aux virtual port_filter const& get_port_filter() const = 0; virtual void ban_ip(address addr) = 0; - virtual boost::int64_t session_time() const = 0; + virtual boost::uint16_t session_time() const = 0; virtual bool is_paused() const = 0; virtual bool is_aborted() const = 0; From 249dff6014bc48ac5263e9d6417fda92e69d4410 Mon Sep 17 00:00:00 2001 From: arvidn Date: Thu, 14 Apr 2016 19:26:06 -0400 Subject: [PATCH 05/15] make dht_get_peers_reply_alert::peers a function in python binding --- bindings/python/src/alert.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/python/src/alert.cpp b/bindings/python/src/alert.cpp index 729bb4788..a39f7712f 100644 --- a/bindings/python/src/alert.cpp +++ b/bindings/python/src/alert.cpp @@ -772,6 +772,6 @@ void bind_alert() "dht_get_peers_reply_alert", no_init) .def_readonly("info_hash", &dht_get_peers_reply_alert::info_hash) .def("num_peers", &dht_get_peers_reply_alert::num_peers) - .add_property("peers", &dht_get_peers_reply_alert_peers) + .def("peers", &dht_get_peers_reply_alert_peers) ; } From a73d424b82355af0e52e2d4d617fbc452d36e337 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Thu, 14 Apr 2016 14:03:11 -0400 Subject: [PATCH 06/15] typos --- include/libtorrent/peer_info.hpp | 2 +- include/libtorrent/session_settings.hpp | 30 ++++++++++++------------- include/libtorrent/settings_pack.hpp | 2 +- include/libtorrent/torrent_handle.hpp | 12 +++++----- src/file_pool.cpp | 2 +- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/include/libtorrent/peer_info.hpp b/include/libtorrent/peer_info.hpp index 73a99e56e..11d21e478 100644 --- a/include/libtorrent/peer_info.hpp +++ b/include/libtorrent/peer_info.hpp @@ -344,7 +344,7 @@ namespace libtorrent int upload_rate_peak; // the progress of the peer in the range [0, 1]. This is always 0 when - // floating point operations are diabled, instead use ``progress_ppm``. + // floating point operations are disabled, instead use ``progress_ppm``. float progress; // [0, 1] // indicates the download progress of the peer in the range [0, 1000000] diff --git a/include/libtorrent/session_settings.hpp b/include/libtorrent/session_settings.hpp index 6ec1c2e20..031e526db 100644 --- a/include/libtorrent/session_settings.hpp +++ b/include/libtorrent/session_settings.hpp @@ -135,7 +135,7 @@ namespace libtorrent int whole_pieces_threshold; // the number of seconds to wait for any activity on the peer wire before - // closing the connectiong due to time out. This defaults to 120 seconds, + // closing the connection due to time out. This defaults to 120 seconds, // since that's what's specified in the protocol specification. After // half the time out, a keep alive message is sent. int peer_timeout; @@ -170,7 +170,7 @@ namespace libtorrent // connections should be rejected or not. Multiple connections from the // same IP address is not allowed by default, to prevent abusive behavior // by peers. It may be useful to allow such connections in cases where - // simulations are run on the same machie, and all peers in a swarm has + // simulations are run on the same machine, and all peers in a swarm has // the same IP address. bool allow_multiple_connections_per_ip; @@ -280,7 +280,7 @@ namespace libtorrent // // When this limit is reached, the peer connections will stop reading // data from their sockets, until the disk thread catches up. Setting - // this too low will severly limit your download rate. + // this too low will severely limit your download rate. int max_queued_disk_bytes; #ifndef TORRENT_NO_DEPRECATE @@ -497,7 +497,7 @@ namespace libtorrent // from growing its file cache indefinitely. Since some OSes only allow // aligned files to be opened in unbuffered mode, It is recommended to // make the largest file in a torrent the first file (with offset 0) or - // use pad files to align all files to piece boundries. + // use pad files to align all files to piece boundaries. int disk_io_write_mode; int disk_io_read_mode; @@ -634,7 +634,7 @@ namespace libtorrent int peer_turnover_interval; // the percentage of peers to disconnect every - // turnoever interval (if we're at the peer limit) + // turnover interval (if we're at the peer limit) // defaults to 4% // this is specified in percent float peer_turnover; @@ -760,7 +760,7 @@ namespace libtorrent // complete and needs to be verified against the piece hash. This happens // if some blocks were flushed to the disk out of order. Everything that // is flushed in order is hashed as it goes along. Optimizing for speed - // will allocate space to fit all the the remaingin, unhashed, part of + // will allocate space to fit all the remaining, unhashed, part of // the piece, reads the data into it in a single call and hashes it. This // is the default. If ``optimizing_hashing_for_speed`` is false, a single // block will be allocated (16 kB), and the unhashed parts of the piece @@ -785,7 +785,7 @@ namespace libtorrent lru, // will flush the largest sequences of contiguous blocks from the - // write cache, regarless of the piece's last use time. + // write cache, regardless of the piece's last use time. largest_contiguous, // will prioritize flushing blocks that will avoid having to read them @@ -802,7 +802,7 @@ namespace libtorrent // the number of blocks to read into the read cache when a read cache // miss occurs. Setting this to 0 is essentially the same thing as // disabling read cache. The number of blocks read into the read cache is - // always capped by the piece boundry. + // always capped by the piece boundary. // // When a piece in the write cache has ``write_cache_line_size`` // contiguous blocks in it, they will be flushed. Setting this to 1 @@ -929,7 +929,7 @@ namespace libtorrent // waste finding the true reciprocation rate. int default_est_reciprocation_rate; - // specifies how many percent the extimated reciprocation rate should be + // specifies how many percent the estimated reciprocation rate should be // increased by each unchoke interval a peer is still choking us back. // This defaults to 20%. This only applies to the BitTyrant choker. int increase_est_reciprocation_rate; @@ -950,8 +950,8 @@ namespace libtorrent bool incoming_starts_queued_torrents; // when set to true, the downloaded counter sent to trackers will include - // the actual number of payload bytes donwnloaded including redundant - // bytes. If set to false, it will not include any redundany bytes + // the actual number of payload bytes downloaded including redundant + // bytes. If set to false, it will not include any redundancy bytes bool report_true_downloaded; // defaults to true, and controls when a block may be requested twice. If @@ -981,7 +981,7 @@ namespace libtorrent // the max number of peers we accept from pex messages from a single peer. // this limits the number of concurrent peers any of our peers claims to - // be connected to. If they clain to be connected to more than this, we'll + // be connected to. If they claim to be connected to more than this, we'll // ignore any peer that exceeds this limit int max_pex_peers; @@ -998,7 +998,7 @@ namespace libtorrent // determines if the storage should check the whole files when resume // data is incomplete or missing or whether it should simply assume we // don't have any of the data. By default, this is determined by the - // existance of any of the files. By setting this setting to true, the + // existence of any of the files. By setting this setting to true, the // files won't be checked, but will go straight to download mode. bool no_recheck_incomplete_resume; @@ -1216,7 +1216,7 @@ namespace libtorrent bool seeding_outgoing_connections; // if true (which is the default), libtorrent will not connect to any - // peers on priviliged ports (<= 1023). This can mitigate using + // peers on privileged ports (<= 1023). This can mitigate using // bittorrent swarms for certain DDoS attacks. bool no_connect_privileged_ports; @@ -1233,7 +1233,7 @@ namespace libtorrent // second may be limited to below the ``connection_speed``, in case we're // close to bump up against the limit of number of connections. The // intention of this setting is to more evenly distribute our connection - // attempts over time, instead of attempting to connectin in batches, and + // attempts over time, instead of attempting to connect in batches, and // timing them out in batches. bool smooth_connects; diff --git a/include/libtorrent/settings_pack.hpp b/include/libtorrent/settings_pack.hpp index ffc37feb2..a62077098 100644 --- a/include/libtorrent/settings_pack.hpp +++ b/include/libtorrent/settings_pack.hpp @@ -213,7 +213,7 @@ namespace libtorrent // connections should be rejected or not. Multiple connections from // the same IP address is not allowed by default, to prevent abusive // behavior by peers. It may be useful to allow such connections in - // cases where simulations are run on the same machie, and all peers + // cases where simulations are run on the same machine, and all peers // in a swarm has the same IP address. allow_multiple_connections_per_ip = bool_type_base, diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index 383accd9e..63e534306 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -215,7 +215,7 @@ namespace libtorrent // made synchronously. This means it has to wait for the main thread to // complete the query before it can return. This might potentially be // expensive if done from within a GUI thread that needs to stay - // responsive. Try to avoid quering for information you don't need, and + // responsive. Try to avoid querying for information you don't need, and // try to do it in as few calls as possible. You can get most of the // interesting information about a torrent from the // torrent_handle::status() call. @@ -227,7 +227,7 @@ namespace libtorrent // // .. warning:: // All operations on a torrent_handle may throw libtorrent_exception - // exception, in case the handle is no longer refering to a torrent. + // exception, in case the handle is no longer referring to a torrent. // There is one exception is_valid() will never throw. Since the torrents // are processed by a background thread, there is no guarantee that a // handle will remain valid between two calls. @@ -285,7 +285,7 @@ namespace libtorrent // specified piece before calling this function. // // When the read operation is completed, it is passed back through an - // alert, read_piece_alert. Since this alert is a reponse to an explicit + // alert, read_piece_alert. Since this alert is a response to an explicit // call, it will always be posted, regardless of the alert mask. // // Note that if you read multiple pieces, the read operations are not @@ -397,7 +397,7 @@ namespace libtorrent // To query the priority of a torrent, use the // ``torrent_handle::status()`` call. // - // Torrents with higher priority will not nececcarily get as much + // Torrents with higher priority will not necessarily get as much // bandwidth as they can consume, even if there's is more quota. Other // peers will still be weighed in when bandwidth is being distributed. // With other words, bandwidth is not distributed strictly in order of @@ -709,7 +709,7 @@ namespace libtorrent // resume data saved when they complete and on exit, since their // statistics might be updated. // - // In full allocation mode the reume data is never invalidated by + // In full allocation mode the resume data is never invalidated by // subsequent writes to the files, since pieces won't move around. This // means that you don't need to pause before writing resume data in full // or sparse mode. If you don't, however, any data written to disk after @@ -835,7 +835,7 @@ namespace libtorrent #ifndef TORRENT_NO_DEPRECATE // deprecated in 1.1 - // Sets or gets the flag that derermines if countries should be resolved + // Sets or gets the flag that determines if countries should be resolved // for the peers of this torrent. It defaults to false. If it is set to // true, the peer_info structure for the peers in this torrent will have // their ``country`` member set. See peer_info for more information on diff --git a/src/file_pool.cpp b/src/file_pool.cpp index 370842422..6035b6d19 100644 --- a/src/file_pool.cpp +++ b/src/file_pool.cpp @@ -172,7 +172,7 @@ namespace libtorrent || (e.mode & file::random_access) != (m & file::random_access)) { // close the file before we open it with - // the new read/write privilages, since windows may + // the new read/write privileges, since windows may // file opening a file twice. However, since there may // be outstanding operations on it, we can't close the // file, we can only delete our reference to it. From 680eddf3d421f97ba01e8c162b263f31693ba352 Mon Sep 17 00:00:00 2001 From: arvidn Date: Fri, 15 Apr 2016 23:50:45 -0400 Subject: [PATCH 07/15] remove -msse4.2 commandline option from configure script --- configure.ac | 2 -- simulation/libsimulator | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index efa1943fc..413da26cb 100644 --- a/configure.ac +++ b/configure.ac @@ -536,8 +536,6 @@ AM_CONDITIONAL([WITH_OPENSSL], [test "x$ARG_ENABLE_ENCRYPTION" = "xyes" -o "x$AR AC_DEFINE([BOOST_ASIO_HASH_MAP_BUCKETS],[1021],[Define to fix a wrong behavior in boost 1.39.]) COMPILETIME_OPTIONS="$COMPILETIME_OPTIONS -DBOOST_ASIO_HASH_MAP_BUCKETS=1021 " -COMPILETIME_OPTIONS="$COMPILETIME_OPTIONS -msse4.2 " - AC_DEFINE([BOOST_EXCEPTION_DISABLE],[1],[Define to disable the boost.exception features.]) COMPILETIME_OPTIONS="$COMPILETIME_OPTIONS -DBOOST_EXCEPTION_DISABLE " diff --git a/simulation/libsimulator b/simulation/libsimulator index 5f7cbb8bd..0151d5c17 160000 --- a/simulation/libsimulator +++ b/simulation/libsimulator @@ -1 +1 @@ -Subproject commit 5f7cbb8bd222ed0e5cfdaffc2a2f5010fb5b4a29 +Subproject commit 0151d5c17fa3f4cf0ce518d0b8f90a23792c9b24 From e4fd45e109f9572a27500637ad5283a6fb32c9fc Mon Sep 17 00:00:00 2001 From: Steven Siloti Date: Sat, 16 Apr 2016 12:43:26 -0700 Subject: [PATCH 08/15] fix the fix for python binding backwards compat f409a5ab caused session.settings to return a setting pack dict rather than the 1.0 compatibile session_settings class. --- bindings/python/src/session.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/python/src/session.cpp b/bindings/python/src/session.cpp index 918be8763..972a97cb1 100644 --- a/bindings/python/src/session.cpp +++ b/bindings/python/src/session.cpp @@ -810,7 +810,7 @@ void bind_session() #ifndef TORRENT_NO_DEPRECATE .def("add_feed", &add_feed) .def("status", allow_threads(<::session::status)) - .def("settings", &session_get_settings) + .def("settings", <::session::settings) .def("set_settings", &session_set_settings) #endif .def("get_settings", &session_get_settings) From 8dd1da9d327868ecf293e8580caa72d36d2ddb28 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sun, 17 Apr 2016 01:56:05 -0400 Subject: [PATCH 09/15] fix warnings --- .travis.yml | 2 +- simulation/libsimulator | 2 +- simulation/test_tracker.cpp | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7ec2bf611..9280c68dc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -111,7 +111,7 @@ script: - cd simulation - if [ $sim = "1" ]; then - bjam --hash -j2 crypto=built-in $coverage_toolset; + bjam --hash -j2 crypto=built-in warnings-as-errors=on $coverage_toolset; fi - cd .. - ccache --show-stats diff --git a/simulation/libsimulator b/simulation/libsimulator index 0151d5c17..ad23c932e 160000 --- a/simulation/libsimulator +++ b/simulation/libsimulator @@ -1 +1 @@ -Subproject commit 0151d5c17fa3f4cf0ce518d0b8f90a23792c9b24 +Subproject commit ad23c932ecd852f89c7d8b29dfe162e9ee073a1b diff --git a/simulation/test_tracker.cpp b/simulation/test_tracker.cpp index afa8ef6d5..0f9a1e439 100644 --- a/simulation/test_tracker.cpp +++ b/simulation/test_tracker.cpp @@ -663,7 +663,7 @@ TORRENT_TEST(try_next) TEST_EQUAL(tr.size(), 3); - for (int i = 0; i < tr.size(); ++i) + for (int i = 0; i < int(tr.size()); ++i) { fprintf(stderr, "tracker \"%s\"\n", tr[i].url.c_str()); if (tr[i].url == "http://tracker.com:8080/announce") @@ -732,7 +732,7 @@ TORRENT_TEST(tracker_ipv6_argument) , std::map& headers) { got_announce = true; - int pos = req.find("&ipv6="); + std::string::size_type pos = req.find("&ipv6="); TEST_CHECK(pos != std::string::npos); got_ipv6 = pos != std::string::npos; return sim::send_response(200, "OK", 11) + "d5:peers0:e"; @@ -762,7 +762,7 @@ TORRENT_TEST(tracker_ipv6_argument_non_private) , std::map& headers) { got_announce = true; - int pos = req.find("&ipv6="); + std::string::size_type pos = req.find("&ipv6="); TEST_CHECK(pos == std::string::npos); got_ipv6 = pos != std::string::npos; return sim::send_response(200, "OK", 11) + "d5:peers0:e"; @@ -790,7 +790,7 @@ TORRENT_TEST(tracker_ipv6_argument_privacy_mode) , std::map& headers) { got_announce = true; - int pos = req.find("&ipv6="); + std::string::size_type pos = req.find("&ipv6="); TEST_CHECK(pos == std::string::npos); got_ipv6 = pos != std::string::npos; return sim::send_response(200, "OK", 11) + "d5:peers0:e"; From 93408a02ff0f90a8c437b543b248b980c02e6ec1 Mon Sep 17 00:00:00 2001 From: arvidn Date: Mon, 18 Apr 2016 01:29:46 -0400 Subject: [PATCH 10/15] fix classification of UDP packets as peer traffic --- simulation/libsimulator | 2 +- src/utp_socket_manager.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/simulation/libsimulator b/simulation/libsimulator index ad23c932e..0151d5c17 160000 --- a/simulation/libsimulator +++ b/simulation/libsimulator @@ -1 +1 @@ -Subproject commit ad23c932ecd852f89c7d8b29dfe162e9ee073a1b +Subproject commit 0151d5c17fa3f4cf0ce518d0b8f90a23792c9b24 diff --git a/src/utp_socket_manager.cpp b/src/utp_socket_manager.cpp index 58d534827..c7b104493 100644 --- a/src/utp_socket_manager.cpp +++ b/src/utp_socket_manager.cpp @@ -167,7 +167,7 @@ namespace libtorrent TORRENT_ASSERT_VAL(!tmp, tmp.message()); } #endif - m_sock.send(ep, p, len, ec); + m_sock.send(ep, p, len, ec, udp_socket::peer_connection); #ifdef TORRENT_HAS_DONT_FRAGMENT if (flags & utp_socket_manager::dont_fragment) { From bd6efe11792a7d5715eb90cc066968c1efda3791 Mon Sep 17 00:00:00 2001 From: arvidn Date: Mon, 18 Apr 2016 08:37:58 -0400 Subject: [PATCH 11/15] fix simulator submodule --- simulation/libsimulator | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simulation/libsimulator b/simulation/libsimulator index 0151d5c17..ad23c932e 160000 --- a/simulation/libsimulator +++ b/simulation/libsimulator @@ -1 +1 @@ -Subproject commit 0151d5c17fa3f4cf0ce518d0b8f90a23792c9b24 +Subproject commit ad23c932ecd852f89c7d8b29dfe162e9ee073a1b From 0fddd403b28b1e0bee1e4caffd1004e148a5d830 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Tue, 19 Apr 2016 16:16:51 -0400 Subject: [PATCH 12/15] Better api for peers() method in dht_get_peers_reply_alert (#628) --- bindings/python/src/alert.cpp | 3 +-- include/libtorrent/alert_types.hpp | 7 ++++++- include/libtorrent/aux_/proxy_settings.hpp | 4 ++-- src/alert.cpp | 15 +++++++++++---- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/bindings/python/src/alert.cpp b/bindings/python/src/alert.cpp index a39f7712f..cde20e0a8 100644 --- a/bindings/python/src/alert.cpp +++ b/bindings/python/src/alert.cpp @@ -198,8 +198,7 @@ list dht_get_peers_reply_alert_peers(dht_get_peers_reply_alert const& a) { list result; - std::vector v; - a.peers(v); + std::vector v(a.peers()); for (std::vector::const_iterator i = v.begin(); i != v.end(); ++i) diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index 06ee4cb44..9b884ccbb 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -2403,7 +2403,12 @@ namespace libtorrent sha1_hash info_hash; int num_peers() const; - void peers(std::vector& peers) const; + +#ifndef TORRENT_NO_DEPRECATE + TORRENT_DEPRECATED + void peers(std::vector& v) const; +#endif + std::vector peers() const; private: aux::stack_allocator& m_alloc; diff --git a/include/libtorrent/aux_/proxy_settings.hpp b/include/libtorrent/aux_/proxy_settings.hpp index dbaa15467..19e9de6b3 100644 --- a/include/libtorrent/aux_/proxy_settings.hpp +++ b/include/libtorrent/aux_/proxy_settings.hpp @@ -63,7 +63,7 @@ namespace aux { // set to authenticate with the proxy. std::string hostname; - // when using a proy type that requires authentication, the username + // when using a proxy type that requires authentication, the username // and password fields must be set to the credentials for the proxy. std::string username; std::string password; @@ -128,7 +128,7 @@ namespace aux { // This is only supported by SOCKS5 and HTTP. bool proxy_hostnames; - // determines whether or not to excempt peer and web seed connections + // determines whether or not to exempt peer and web seed connections // from using the proxy. This defaults to true, i.e. peer connections are // proxied by default. bool proxy_peer_connections; diff --git a/src/alert.cpp b/src/alert.cpp index 076beb0e2..1b64d70d6 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -1918,17 +1918,24 @@ namespace libtorrent { return m_num_peers; } - void dht_get_peers_reply_alert::peers(std::vector& peers) const - { - peers.resize(m_num_peers); +#ifndef TORRENT_NO_DEPRECATE + void dht_get_peers_reply_alert::peers(std::vector &v) const { + std::vector p(peers()); + v.reserve(p.size()); + std::copy(p.begin(), p.end(), std::back_inserter(v)); + } +#endif + std::vector dht_get_peers_reply_alert::peers() const { + std::vector peers(m_num_peers); const char *ptr = m_alloc.ptr(m_peers_idx); for (int i = 0; i < m_num_peers; i++) { - std::size_t size = detail::read_uint8(ptr); memcpy(peers[i].data(), ptr, size); ptr += size; } + + return peers; } dht_direct_response_alert::dht_direct_response_alert( From 0b53fb70ad9c447becb09587b2fbd91e9e1374ea Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 20 Apr 2016 00:46:42 -0400 Subject: [PATCH 13/15] add missing torrent_error_alert::filename function (#629) --- src/alert.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/alert.cpp b/src/alert.cpp index 1b64d70d6..b5eba7e2f 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -1241,6 +1241,11 @@ namespace libtorrent { return torrent_alert::message() + msg; } + char const* torrent_error_alert::filename() const + { + return m_alloc.ptr(m_file_idx); + } + torrent_added_alert::torrent_added_alert(aux::stack_allocator& alloc , torrent_handle const& h) : torrent_alert(alloc, h) @@ -1783,11 +1788,7 @@ namespace libtorrent { char const* file_error_alert::filename() const { -#ifndef TORRENT_NO_DEPRECATE - return file.c_str(); -#else return m_alloc.ptr(m_file_idx); -#endif } std::string file_error_alert::message() const From 423ee1cef4c6f3da422adb21f6d05b7094008d20 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 20 Apr 2016 07:50:57 -0400 Subject: [PATCH 14/15] move some implementation details of bitfield into its own translation unit to not expose MMX and SSE internals (and fix shared linking) (#630) --- CMakeLists.txt | 1 + Jamfile | 1 + include/libtorrent/bitfield.hpp | 123 +----------------------- src/Makefile.am | 1 + src/bitfield.cpp | 160 ++++++++++++++++++++++++++++++++ 5 files changed, 167 insertions(+), 119 deletions(-) create mode 100644 src/bitfield.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index de5604922..d0846d1e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,7 @@ set(sources bandwidth_manager bandwidth_queue_entry bdecode + bitfield block_cache bloom_filter chained_buffer diff --git a/Jamfile b/Jamfile index ccd636596..097e7bc20 100644 --- a/Jamfile +++ b/Jamfile @@ -563,6 +563,7 @@ SOURCES = bandwidth_manager bandwidth_queue_entry bdecode + bitfield block_cache bloom_filter chained_buffer diff --git a/include/libtorrent/bitfield.hpp b/include/libtorrent/bitfield.hpp index 938de163b..850e1ac6a 100644 --- a/include/libtorrent/bitfield.hpp +++ b/include/libtorrent/bitfield.hpp @@ -36,17 +36,12 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/assert.hpp" #include "libtorrent/config.hpp" #include "libtorrent/aux_/byteswap.hpp" -#include "libtorrent/aux_/cpuid.hpp" #include // for memset and memcpy #include // for malloc, free and realloc #include // uint32_t #include // for min() -#ifdef _MSC_VER -#include -#endif - namespace libtorrent { // The bitfiled type stores any number of bits as a bitfield @@ -116,21 +111,7 @@ namespace libtorrent } // returns true if all bits in the bitfield are set - bool all_set() const - { - const int words = size() / 32; - for (int i = 0; i < words; ++i) - { - if (m_buf[i] != 0xffffffff) return false; - } - int rest = size() & 31; - if (rest > 0) - { - boost::uint32_t mask = aux::host_to_network(0xffffffff << (32-rest)); - if ((m_buf[words] & mask) != mask) return false; - } - return true; - } + bool all_set() const; bool none_set() const { @@ -172,46 +153,7 @@ namespace libtorrent } // count the number of bits in the bitfield that are set to 1. - int count() const - { - int ret = 0; - const int words = num_words(); -#if TORRENT_HAS_SSE - if (aux::mmx_support) - { - for (int i = 0; i < words; ++i) - { -#ifdef __GNUC__ - ret += __builtin_popcount(m_buf[i]); -#else - ret += _mm_popcnt_u32(m_buf[i]); -#endif - } - - return ret; - } -#endif // TORRENT_HAS_SSE - - for (int i = 0; i < words; ++i) - { - boost::uint32_t v = m_buf[i]; - // from: - // http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel - static const int S[] = {1, 2, 4, 8, 16}; // Magic Binary Numbers - static const int B[] = {0x55555555, 0x33333333, 0x0F0F0F0F, 0x00FF00FF, 0x0000FFFF}; - - boost::uint32_t c = v - ((v >> 1) & B[0]); - c = ((c >> S[1]) & B[1]) + (c & B[1]); - c = ((c >> S[2]) + c) & B[2]; - c = ((c >> S[3]) + c) & B[3]; - c = ((c >> S[4]) + c) & B[4]; - ret += c; - } - - TORRENT_ASSERT(ret <= size()); - TORRENT_ASSERT(ret >= 0); - return ret; - } + int count() const; struct const_iterator { @@ -277,66 +219,9 @@ namespace libtorrent // set the size of the bitfield to ``bits`` length. If the bitfield is extended, // the new bits are initialized to ``val``. - void resize(int bits, bool val) - { - if (bits == size()) return; + void resize(int bits, bool val); - int s = size(); - int b = size() & 31; - resize(bits); - if (s >= size()) return; - int old_size_words = (s + 31) / 32; - int new_size_words = num_words(); - if (val) - { - if (old_size_words && b) m_buf[old_size_words - 1] |= aux::host_to_network((0xffffffff >> b)); - if (old_size_words < new_size_words) - std::memset(m_buf + old_size_words, 0xff - , size_t((new_size_words - old_size_words) * 4)); - clear_trailing_bits(); - } - else - { - if (old_size_words < new_size_words) - std::memset(m_buf + old_size_words, 0x00 - , size_t((new_size_words - old_size_words) * 4)); - } - TORRENT_ASSERT(size() == bits); - } - - void resize(int bits) - { - if (bits == size()) return; - - TORRENT_ASSERT(bits >= 0); - // +1 because the first word is the size (in bits) - const int b = (bits + 31) / 32; - if (m_buf) - { - boost::uint32_t* tmp = static_cast(std::realloc(m_buf-1, (b+1) * 4)); -#ifndef BOOST_NO_EXCEPTIONS - if (tmp == NULL) throw std::bad_alloc(); -#endif - m_buf = tmp + 1; - m_buf[-1] = bits; - } - else if (bits > 0) - { - boost::uint32_t* tmp = static_cast(std::malloc((b+1) * 4)); -#ifndef BOOST_NO_EXCEPTIONS - if (tmp == NULL) throw std::bad_alloc(); -#endif - m_buf = tmp + 1; - m_buf[-1] = bits; - } - else if (m_buf != NULL) - { - std::free(m_buf-1); - m_buf = NULL; - } - clear_trailing_bits(); - TORRENT_ASSERT(size() == bits); - } + void resize(int bits); // set all bits in the bitfield to 1 (set_all) or 0 (clear_all). void set_all() diff --git a/src/Makefile.am b/src/Makefile.am index 8e8bafc74..d2ff91f79 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -43,6 +43,7 @@ libtorrent_rasterbar_la_SOURCES = \ bandwidth_manager.cpp \ bandwidth_queue_entry.cpp \ bdecode.cpp \ + bitfield.cpp \ bloom_filter.cpp \ broadcast_socket.cpp \ block_cache.cpp \ diff --git a/src/bitfield.cpp b/src/bitfield.cpp new file mode 100644 index 000000000..5432e34db --- /dev/null +++ b/src/bitfield.cpp @@ -0,0 +1,160 @@ +/* + +Copyright (c) 2008-2016, Arvid Norberg +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the distribution. + * Neither the name of the author nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +*/ + +#include "libtorrent/bitfield.hpp" +#include "libtorrent/aux_/cpuid.hpp" + +#ifdef _MSC_VER +#include +#endif + +namespace libtorrent +{ + bool bitfield::all_set() const + { + const int words = size() / 32; + for (int i = 0; i < words; ++i) + { + if (m_buf[i] != 0xffffffff) return false; + } + int rest = size() & 31; + if (rest > 0) + { + boost::uint32_t mask = aux::host_to_network(0xffffffff << (32-rest)); + if ((m_buf[words] & mask) != mask) return false; + } + return true; + } + + int bitfield::count() const + { + int ret = 0; + const int words = num_words(); +#if TORRENT_HAS_SSE + if (aux::mmx_support) + { + for (int i = 0; i < words; ++i) + { +#ifdef __GNUC__ + ret += __builtin_popcount(m_buf[i]); +#else + ret += _mm_popcnt_u32(m_buf[i]); +#endif + } + + return ret; + } +#endif // TORRENT_HAS_SSE + + for (int i = 0; i < words; ++i) + { + boost::uint32_t v = m_buf[i]; + // from: + // http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel + static const int S[] = {1, 2, 4, 8, 16}; // Magic Binary Numbers + static const int B[] = {0x55555555, 0x33333333, 0x0F0F0F0F, 0x00FF00FF, 0x0000FFFF}; + + boost::uint32_t c = v - ((v >> 1) & B[0]); + c = ((c >> S[1]) & B[1]) + (c & B[1]); + c = ((c >> S[2]) + c) & B[2]; + c = ((c >> S[3]) + c) & B[3]; + c = ((c >> S[4]) + c) & B[4]; + ret += c; + } + + TORRENT_ASSERT(ret <= size()); + TORRENT_ASSERT(ret >= 0); + return ret; + } + + void bitfield::resize(int bits, bool val) + { + if (bits == size()) return; + + int s = size(); + int b = size() & 31; + resize(bits); + if (s >= size()) return; + int old_size_words = (s + 31) / 32; + int new_size_words = num_words(); + if (val) + { + if (old_size_words && b) m_buf[old_size_words - 1] |= aux::host_to_network((0xffffffff >> b)); + if (old_size_words < new_size_words) + std::memset(m_buf + old_size_words, 0xff + , size_t((new_size_words - old_size_words) * 4)); + clear_trailing_bits(); + } + else + { + if (old_size_words < new_size_words) + std::memset(m_buf + old_size_words, 0x00 + , size_t((new_size_words - old_size_words) * 4)); + } + TORRENT_ASSERT(size() == bits); + } + + void bitfield::resize(int bits) + { + if (bits == size()) return; + + TORRENT_ASSERT(bits >= 0); + // +1 because the first word is the size (in bits) + const int b = (bits + 31) / 32; + if (m_buf) + { + boost::uint32_t* tmp = static_cast(std::realloc(m_buf-1, (b+1) * 4)); +#ifndef BOOST_NO_EXCEPTIONS + if (tmp == NULL) throw std::bad_alloc(); +#endif + m_buf = tmp + 1; + m_buf[-1] = bits; + } + else if (bits > 0) + { + boost::uint32_t* tmp = static_cast(std::malloc((b+1) * 4)); +#ifndef BOOST_NO_EXCEPTIONS + if (tmp == NULL) throw std::bad_alloc(); +#endif + m_buf = tmp + 1; + m_buf[-1] = bits; + } + else if (m_buf != NULL) + { + std::free(m_buf-1); + m_buf = NULL; + } + clear_trailing_bits(); + TORRENT_ASSERT(size() == bits); + } +} + From 2bd8622f4bd71d884039467b056f478508652c6a Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 20 Apr 2016 07:51:25 -0400 Subject: [PATCH 15/15] fix missing EXPORT annotation of functions in the test utility library (#631) --- test/make_torrent.hpp | 11 +++++++++-- test/peer_server.hpp | 11 ++++++++--- test/print_alerts.hpp | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/test/make_torrent.hpp b/test/make_torrent.hpp index 5d701f737..a385170a8 100644 --- a/test/make_torrent.hpp +++ b/test/make_torrent.hpp @@ -30,10 +30,14 @@ POSSIBILITY OF SUCH DAMAGE. */ +#ifndef MAKE_TORRENT_HPP +#define MAKE_TORRENT_HPP + #include "libtorrent/torrent_info.hpp" #include #include #include +#include "test.hpp" enum flags_t { @@ -56,7 +60,10 @@ struct torrent_args std::string m_http_seed; }; -boost::shared_ptr make_test_torrent(torrent_args const& args); +EXPORT boost::shared_ptr + make_test_torrent(torrent_args const& args); -void generate_files(libtorrent::torrent_info const& ti, std::string const& path, bool random = false); +EXPORT void generate_files(libtorrent::torrent_info const& ti, std::string const& path, bool random = false); + +#endif diff --git a/test/peer_server.hpp b/test/peer_server.hpp index 3e5e28534..707042151 100644 --- a/test/peer_server.hpp +++ b/test/peer_server.hpp @@ -30,13 +30,18 @@ POSSIBILITY OF SUCH DAMAGE. */ +#ifndef PEER_SERVER_HPP +#define PEER_SERVER_HPP + #include "test.hpp" // for EXPORT // returns the port the peer is running on -int EXPORT start_peer(); +EXPORT int start_peer(); // the number of incoming connections to this peer -int EXPORT num_peer_hits(); +EXPORT int num_peer_hits(); -void EXPORT stop_peer(); +EXPORT void stop_peer(); + +#endif diff --git a/test/print_alerts.hpp b/test/print_alerts.hpp index 1c95b7e93..e5ecff382 100644 --- a/test/print_alerts.hpp +++ b/test/print_alerts.hpp @@ -37,7 +37,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/session.hpp" #include "test.hpp" // for EXPORT -void EXPORT print_alerts(libtorrent::session* ses, libtorrent::time_point start_time); +EXPORT void print_alerts(libtorrent::session* ses, libtorrent::time_point start_time); #endif