diff --git a/ChangeLog b/ChangeLog index afad7ced3..376501a1d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -36,6 +36,10 @@ * resume data no longer has timestamps of files * require C++11 to build libtorrent + * remove file size limit in torrent_info filename constructor + * fix tail-padding for last file in create_torrent + * don't send user-agent in metadata http downloads or UPnP requests when + in anonymous mode * fix internal resolve links lookup for mutable torrents * hint DHT bootstrap nodes of actual bootstrap request @@ -162,6 +166,16 @@ * added support for asynchronous disk I/O * almost completely changed the storage interface (for custom storage) * added support for hashing pieces in multiple threads + + * fix padfile issue + * fix PMTUd bug + * update puff to fix gzip crash + +1.0.10 release + + * fixed inverted priority of incoming piece suggestions + * fixed crash on invalid input in http_parser + * added a new "preformatted" type to bencode entry variant type * fix division by zero in super-seeding logic 1.0.9 release diff --git a/examples/make_torrent.cpp b/examples/make_torrent.cpp index c4d032b8d..041ec63be 100644 --- a/examples/make_torrent.cpp +++ b/examples/make_torrent.cpp @@ -44,6 +44,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #ifdef TORRENT_WINDOWS #include // for _getcwd @@ -52,65 +53,18 @@ POSSIBILITY OF SUCH DAMAGE. using namespace libtorrent; using namespace std::placeholders; -int load_file(std::string const& filename, std::vector& v, libtorrent::error_code& ec, int limit = 8000000) +std::vector load_file(std::string const& filename) { - ec.clear(); - FILE* f = std::fopen(filename.c_str(), "rb"); - if (f == nullptr) - { - ec.assign(errno, boost::system::system_category()); - return -1; - } - - int r = fseek(f, 0, SEEK_END); - if (r != 0) - { - ec.assign(errno, boost::system::system_category()); - std::fclose(f); - return -1; - } - long s = ftell(f); - if (s < 0) - { - ec.assign(errno, boost::system::system_category()); - std::fclose(f); - return -1; - } - - if (s > limit) - { - std::fclose(f); - return -2; - } - - r = fseek(f, 0, SEEK_SET); - if (r != 0) - { - ec.assign(errno, boost::system::system_category()); - std::fclose(f); - return -1; - } - - v.resize(s); - if (s == 0) - { - std::fclose(f); - return 0; - } - - r = int(fread(&v[0], 1, v.size(), f)); - if (r < 0) - { - ec.assign(errno, boost::system::system_category()); - std::fclose(f); - return -1; - } - - std::fclose(f); - - if (r != s) return -3; - - return 0; + std::vector ret; + std::fstream in; + in.exceptions(std::ifstream::failbit); + in.open(filename.c_str(), std::ios_base::in | std::ios_base::binary); + in.seekg(0, std::ios_base::end); + size_t const size = in.tellg(); + in.seekg(0, std::ios_base::beg); + ret.resize(size); + in.read(ret.data(), ret.size()); + return ret; } std::string branch_path(std::string const& f) @@ -394,51 +348,31 @@ int main(int argc, char* argv[]) if (!root_cert.empty()) { - std::vector pem; - load_file(root_cert, pem, ec, 10000); - if (ec) - { - std::fprintf(stderr, "failed to load root certificate for tracker: %s\n", ec.message().c_str()); - } - else - { - t.set_root_cert(std::string(&pem[0], pem.size())); - } + std::vector pem = load_file(root_cert); + t.set_root_cert(std::string(&pem[0], pem.size())); } // create the torrent and print it to stdout std::vector torrent; bencode(back_inserter(torrent), t.generate()); - FILE* output = stdout; if (!outfile.empty()) - output = std::fopen(outfile.c_str(), "wb+"); - if (output == nullptr) { - std::fprintf(stderr, "failed to open file \"%s\": (%d) %s\n" - , outfile.c_str(), errno, std::strerror(errno)); - return 1; + std::fstream out; + out.exceptions(std::ifstream::failbit); + out.open(outfile.c_str(), std::ios_base::out | std::ios_base::binary); + out.write(&torrent[0], torrent.size()); + } + else + { + fwrite(&torrent[0], 1, torrent.size(), stdout); } - fwrite(&torrent[0], 1, torrent.size(), output); - - if (output != stdout) - std::fclose(output); if (!merklefile.empty()) { - output = std::fopen(merklefile.c_str(), "wb+"); - if (output == nullptr) - { - std::fprintf(stderr, "failed to open file \"%s\": (%d) %s\n" - , merklefile.c_str(), errno, std::strerror(errno)); - return 1; - } - int ret = int(fwrite(&t.merkle_tree()[0], 20, t.merkle_tree().size(), output)); - if (ret != int(t.merkle_tree().size())) - { - std::fprintf(stderr, "failed to write %s: (%d) %s\n" - , merklefile.c_str(), errno, std::strerror(errno)); - } - std::fclose(output); + std::fstream merkle; + merkle.exceptions(std::ifstream::failbit); + merkle.open(merklefile.c_str(), std::ios_base::out | std::ios_base::binary); + merkle.write(reinterpret_cast(&t.merkle_tree()[0]), t.merkle_tree().size() * 20); } #ifndef BOOST_NO_EXCEPTIONS diff --git a/examples/simple_client.cpp b/examples/simple_client.cpp index 46734beb2..8480b6d89 100644 --- a/examples/simple_client.cpp +++ b/examples/simple_client.cpp @@ -51,15 +51,10 @@ int main(int argc, char* argv[]) settings_pack sett; sett.set_str(settings_pack::listen_interfaces, "0.0.0.0:6881"); lt::session s(sett); - error_code ec; - if (ec) - { - std::fprintf(stderr, "failed to open listen socket: %s\n", ec.message().c_str()); - return 1; - } add_torrent_params p; p.save_path = "./"; p.ti = std::make_shared(std::string(argv[1]), std::ref(ec), 0); + error_code ec; if (ec) { std::fprintf(stderr, "%s\n", ec.message().c_str()); diff --git a/include/libtorrent/upnp.hpp b/include/libtorrent/upnp.hpp index f0b50d735..c863860fe 100644 --- a/include/libtorrent/upnp.hpp +++ b/include/libtorrent/upnp.hpp @@ -128,6 +128,8 @@ struct TORRENT_EXTRA_EXPORT upnp final , bool ignore_nonrouters); ~upnp(); + void set_user_agent(std::string const& v) { m_user_agent = v; } + void start(); // Attempts to add a port mapping for the specified protocol. Valid protocols are @@ -325,7 +327,7 @@ private: std::vector m_mappings; - std::string const& m_user_agent; + std::string m_user_agent; // the set of devices we've found std::set m_devices; diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 107613221..20cbd39c3 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -6246,8 +6246,15 @@ namespace aux { void session_impl::update_anonymous_mode() { - if (!m_settings.get_bool(settings_pack::anonymous_mode)) return; + if (!m_settings.get_bool(settings_pack::anonymous_mode)) + { + if (m_upnp) + m_upnp->set_user_agent(m_settings.get_str(settings_pack::user_agent)); + return; + } + if (m_upnp) + m_upnp->set_user_agent(""); m_settings.set_str(settings_pack::user_agent, ""); url_random(m_peer_id.data(), m_peer_id.data() + 20); } @@ -6512,7 +6519,8 @@ namespace aux { // the upnp constructor may fail and call the callbacks m_upnp = std::make_shared(m_io_service - , m_settings.get_str(settings_pack::user_agent) + , m_settings.get_bool(settings_pack::anonymous_mode) + ? "" : m_settings.get_str(settings_pack::user_agent) , *this , m_settings.get_bool(settings_pack::upnp_ignore_nonrouters)); m_upnp->start(); diff --git a/src/torrent.cpp b/src/torrent.cpp index 8bb929d46..3dd3474bb 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -754,7 +754,9 @@ namespace libtorrent )); aux::proxy_settings ps = m_ses.proxy(); conn->get(m_url, seconds(30), 0, &ps - , 5, settings().get_str(settings_pack::user_agent)); + , 5 + , settings().get_bool(settings_pack::anonymous_mode) + ? "" : settings().get_str(settings_pack::user_agent)); set_state(torrent_status::downloading_metadata); } #endif @@ -7412,8 +7414,7 @@ namespace libtorrent else if (m_state == torrent_status::downloading_metadata || m_state == torrent_status::downloading || m_state == torrent_status::finished - || m_state == torrent_status::seeding - || m_state == torrent_status::downloading) + || m_state == torrent_status::seeding) { // torrents that are started (not paused) and // inactive are not part of any list. They will not be touched because diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index f74aff2b0..cd59a6702 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -606,18 +606,13 @@ namespace libtorrent } int load_file(std::string const& filename, std::vector& v - , error_code& ec, int limit = 8000000) + , error_code& ec) { ec.clear(); file f; if (!f.open(filename, file::read_only, ec)) return -1; std::int64_t s = f.get_size(ec); if (ec) return -1; - if (s > limit) - { - ec = errors::metadata_too_large; - return -2; - } v.resize(std::size_t(s)); if (s == 0) return 0; file::iovec_t b = {&v[0], size_t(s) }; diff --git a/src/udp_tracker_connection.cpp b/src/udp_tracker_connection.cpp index 68bae77cc..cb648d539 100644 --- a/src/udp_tracker_connection.cpp +++ b/src/udp_tracker_connection.cpp @@ -635,7 +635,6 @@ namespace libtorrent return true; } - std::vector peer_list; resp.peers4.reserve(num_peers); for (int i = 0; i < num_peers; ++i) { diff --git a/src/utp_stream.cpp b/src/utp_stream.cpp index 88dbdc50d..5829a281a 100644 --- a/src/utp_stream.cpp +++ b/src/utp_stream.cpp @@ -1813,6 +1813,7 @@ bool utp_socket_impl::send_pkt(int const flags) int const effective_mtu = mtu_probe ? m_mtu : m_mtu_floor; int payload_size = (std::min)(m_write_buffer_size , effective_mtu - header_size); + TORRENT_ASSERT(payload_size >= 0); // if we have one MSS worth of data, make sure it fits in our // congestion window and the advertised receive window from @@ -1915,6 +1916,7 @@ bool utp_socket_impl::send_pkt(int const flags) #if TORRENT_USE_ASSERTS p->num_fast_resend = 0; #endif + p->mtu_probe = false; p->need_resend = false; ptr = p->buf; h = reinterpret_cast(ptr); diff --git a/src/web_connection_base.cpp b/src/web_connection_base.cpp index c8b86576b..d92a65003 100644 --- a/src/web_connection_base.cpp +++ b/src/web_connection_base.cpp @@ -124,7 +124,8 @@ namespace libtorrent { request += "Host: "; request += m_host; - if (m_first_request || m_settings.get_bool(settings_pack::always_send_user_agent)) { + if ((m_first_request || m_settings.get_bool(settings_pack::always_send_user_agent)) + && !m_settings.get_bool(settings_pack::anonymous_mode)) { request += "\r\nUser-Agent: "; request += m_settings.get_str(settings_pack::user_agent); } diff --git a/src/web_peer_connection.cpp b/src/web_peer_connection.cpp index 36a62dba9..dc2dc96a5 100644 --- a/src/web_peer_connection.cpp +++ b/src/web_peer_connection.cpp @@ -982,9 +982,16 @@ void web_peer_connection::incoming_payload(char const* buf, int len) , "piece: %d start: %d len: %d" , front_request.piece, front_request.start, front_request.length); #endif + + // Make a copy of the request and pop it off the queue before calling + // incoming_piece because that may lead to a call to disconnect() + // which will clear the request queue and invalidate any references + // to the request + peer_request const front_request_copy = front_request; m_requests.pop_front(); - incoming_piece(front_request, &m_piece[0]); + incoming_piece(front_request_copy, &m_piece[0]); + m_piece.clear(); } }