diff --git a/ChangeLog b/ChangeLog index 26ff2db78..e81c20e31 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ + * exposed more settings for tweaking parameters in the piece-picker, + downloader and uploader. + * tweaked default settings to improve high bandwidth transfers. * improved the piece picker performance and made it possible to download popular pieces in sequence to improve disk performance. * added the possibility to control upload and download limits per peer. @@ -9,8 +12,9 @@ * changed the extensions protocol to use the new one, which is also implemented by uTorrent. * factorized the peer_connection and added web_peer_connection which is - able to download from http-sources. (currently only for single file torrents). - * converted the network code to use asio + able to download from http-sources. + * converted the network code to use asio (resulted in slight api changes + dealing with network addresses). * made libtorrent build in vc7 (patches from Allen Zhao) * fixed bug caused when binding outgoing connections to a non-local interface. * add_torrent() will now throw if called while the session object is diff --git a/examples/client_test.cpp b/examples/client_test.cpp index 7b3eb9231..9af8cec26 100755 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -54,7 +54,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/entry.hpp" #include "libtorrent/bencode.hpp" #include "libtorrent/session.hpp" -#include "libtorrent/http_settings.hpp" #include "libtorrent/identify_client.hpp" #include "libtorrent/alert_types.hpp" @@ -511,8 +510,8 @@ int main(int ac, char* av[]) if (vm.count("input-file") > 0) input = vm["input-file"].as< std::vector >(); - http_settings settings; - settings.user_agent = "client_test"; + session_settings settings; + settings.user_agent = "client_test " LIBTORRENT_VERSION; std::deque events; @@ -530,7 +529,7 @@ int main(int ac, char* av[]) ses.set_upload_rate_limit(upload_limit); ses.listen_on(std::make_pair(listen_port, listen_port + 10) , bind_to_interface.c_str()); - ses.set_http_settings(settings); + ses.set_settings(settings); if (log_level == "debug") ses.set_severity_level(alert::debug); else if (log_level == "warning") diff --git a/include/Makefile.am b/include/Makefile.am index cbdebbfad..c3a05efc8 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -10,7 +10,6 @@ libtorrent/escape_string.hpp \ libtorrent/file.hpp \ libtorrent/fingerprint.hpp \ libtorrent/hasher.hpp \ -libtorrent/http_settings.hpp \ libtorrent/http_tracker_connection.hpp \ libtorrent/identify_client.hpp \ libtorrent/invariant_check.hpp \ diff --git a/include/libtorrent/http_tracker_connection.hpp b/include/libtorrent/http_tracker_connection.hpp index dd9fea09e..b66d4349d 100755 --- a/include/libtorrent/http_tracker_connection.hpp +++ b/include/libtorrent/http_tracker_connection.hpp @@ -53,7 +53,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/socket.hpp" #include "libtorrent/entry.hpp" -#include "libtorrent/http_settings.hpp" +#include "libtorrent/session_settings.hpp" #include "libtorrent/peer_id.hpp" #include "libtorrent/peer.hpp" #include "libtorrent/tracker_manager.hpp" @@ -118,7 +118,7 @@ namespace libtorrent , unsigned short port , std::string request , boost::weak_ptr c - , const http_settings& stn + , session_settings const& stn , std::string const& password = ""); private: @@ -160,7 +160,7 @@ namespace libtorrent std::string m_server_message; std::string m_server_protocol; - const http_settings& m_settings; + session_settings const& m_settings; std::string m_password; int m_code; diff --git a/include/libtorrent/session.hpp b/include/libtorrent/session.hpp index be4ca7d99..bcef51ad1 100755 --- a/include/libtorrent/session.hpp +++ b/include/libtorrent/session.hpp @@ -221,6 +221,8 @@ namespace libtorrent void connection_failed(boost::shared_ptr const& s , tcp::endpoint const& a, char const* message); + void set_settings(session_settings const& s); + // this maps sockets to their peer_connection // object. It is the complete list of all connected // peers. @@ -272,7 +274,6 @@ namespace libtorrent // the settings for the client session_settings m_settings; - http_settings m_http_settings; // set to true when the session object // is being destructed and the thread @@ -319,8 +320,6 @@ namespace libtorrent }; } - struct http_settings; - struct TORRENT_EXPORT session_status { bool has_incoming_connections; @@ -413,7 +412,8 @@ namespace libtorrent void remove_torrent(const torrent_handle& h); - void set_http_settings(const http_settings& s); + void set_settings(session_settings const& s); + session_settings const& settings(); void set_upload_rate_limit(int bytes_per_second); void set_download_rate_limit(int bytes_per_second); void set_max_uploads(int limit); diff --git a/include/libtorrent/session_settings.hpp b/include/libtorrent/session_settings.hpp index 80a5d5320..bd5418785 100644 --- a/include/libtorrent/session_settings.hpp +++ b/include/libtorrent/session_settings.hpp @@ -33,13 +33,22 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef TORRENT_SESSION_SETTINGS_HPP_INCLUDED #define TORRENT_SESSION_SETTINGS_HPP_INCLUDED +#include "libtorrent/version.hpp" + namespace libtorrent { struct TORRENT_EXPORT session_settings { - session_settings() - : piece_timeout(120) + session_settings(std::string const& user_agent_ = "libtorrent " + LIBTORRENT_VERSION) + : proxy_port(0) + , user_agent(user_agent_) + , tracker_completion_timeout(60) + , tracker_receive_timeout(20) + , stop_tracker_timeout(10) + , tracker_maximum_response_length(1024*1024) + , piece_timeout(120) , request_queue_time(3.f) , sequenced_download_threshold(7) , max_allowed_in_request_queue(250) @@ -47,6 +56,35 @@ namespace libtorrent , whole_pieces_threshold(20) {} + std::string proxy_ip; + int proxy_port; + std::string proxy_login; + std::string proxy_password; + + // this is the user agent that will be sent to the tracker + // when doing requests. It is used to identify the client. + // It cannot contain \r or \n + std::string user_agent; + + // the number of seconds to wait until giving up on a + // tracker request if it hasn't finished + int tracker_completion_timeout; + + // the number of seconds where no data is received + // from the tracker until it should be considered + // as timed out + int tracker_receive_timeout; + + // the time to wait when sending a stopped message + // before considering a tracker to have timed out. + // this is usually shorter, to make the client quit + // faster + int stop_tracker_timeout; + + // if the content-length is greater than this value + // the tracker connection will be aborted + int tracker_maximum_response_length; + // the number of seconds from a request is sent until // it times out if no piece response is returned. int piece_timeout; @@ -78,7 +116,7 @@ namespace libtorrent // send to a peer. This limit takes precedence over // request_queue_time. int max_out_request_queue; - + // if a whole piece can be downloaded in this number // of seconds, or less, the peer_connection will prefer // to request whole pieces at a time from this peer. diff --git a/include/libtorrent/tracker_manager.hpp b/include/libtorrent/tracker_manager.hpp index c51804f1d..8b9bf0145 100755 --- a/include/libtorrent/tracker_manager.hpp +++ b/include/libtorrent/tracker_manager.hpp @@ -57,7 +57,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/socket.hpp" #include "libtorrent/entry.hpp" -#include "libtorrent/http_settings.hpp" +#include "libtorrent/session_settings.hpp" #include "libtorrent/peer_id.hpp" #include "libtorrent/peer.hpp" #include "libtorrent/config.hpp" @@ -218,7 +218,7 @@ namespace libtorrent { public: - tracker_manager(const http_settings& s) + tracker_manager(const session_settings& s) : m_settings(s) {} void queue_request( @@ -239,7 +239,7 @@ namespace libtorrent typedef std::list > tracker_connections_t; tracker_connections_t m_connections; - const http_settings& m_settings; + session_settings const& m_settings; }; } diff --git a/include/libtorrent/udp_tracker_connection.hpp b/include/libtorrent/udp_tracker_connection.hpp index 184f4dc95..43671ed86 100755 --- a/include/libtorrent/udp_tracker_connection.hpp +++ b/include/libtorrent/udp_tracker_connection.hpp @@ -52,7 +52,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/socket.hpp" #include "libtorrent/entry.hpp" -#include "libtorrent/http_settings.hpp" +#include "libtorrent/session_settings.hpp" #include "libtorrent/peer_id.hpp" #include "libtorrent/peer.hpp" #include "libtorrent/tracker_manager.hpp" @@ -72,7 +72,7 @@ namespace libtorrent , std::string const& hostname , unsigned short port , boost::weak_ptr c - , const http_settings& stn); + , session_settings const& stn); private: @@ -111,7 +111,7 @@ namespace libtorrent int m_transaction_id; boost::int64_t m_connection_id; - const http_settings& m_settings; + session_settings const& m_settings; int m_attempts; std::vector m_buffer; }; diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index ea4d7db66..1a6756d35 100755 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -1120,7 +1120,7 @@ namespace libtorrent handshake["m"] = extension_list; handshake["p"] = m_ses.m_listen_interface.port(); - handshake["v"] = m_ses.m_http_settings.user_agent; + handshake["v"] = m_ses.m_settings.user_agent; handshake["reqq"] = m_ses.m_settings.max_allowed_in_request_queue; std::vector msg; diff --git a/src/http_tracker_connection.cpp b/src/http_tracker_connection.cpp index 830a853df..4fcd45133 100755 --- a/src/http_tracker_connection.cpp +++ b/src/http_tracker_connection.cpp @@ -237,7 +237,7 @@ namespace libtorrent , unsigned short port , std::string request , boost::weak_ptr c - , const http_settings& stn + , session_settings const& stn , std::string const& auth) : tracker_connection(man, req, d, c) , m_man(man) diff --git a/src/session.cpp b/src/session.cpp index 25ee3b936..22c2491c2 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -409,7 +409,7 @@ namespace libtorrent { namespace detail std::pair listen_port_range , const fingerprint& cl_fprint , char const* listen_interface) - : m_tracker_manager(m_http_settings) + : m_tracker_manager(m_settings) , m_listen_port_range(listen_port_range) , m_listen_interface(address::from_string(listen_interface), listen_port_range.first) , m_abort(false) @@ -468,6 +468,23 @@ namespace libtorrent { namespace detail , m_extension_enabled + n, true) != m_extension_enabled + n; } + void session_impl::set_settings(session_settings const& s) + { + if (m_settings.sequenced_download_threshold + != s.sequenced_download_threshold) + { + for (torrent_map::iterator i = m_torrents.begin() + , end(m_torrents.end()); i != end; ++i) + { + torrent& t = *i->second; + if (t.valid_metadata()) + t.picker().set_sequenced_download_threshold( + s.sequenced_download_threshold); + } + } + m_settings = s; + } + void session_impl::open_listen_port() { try @@ -931,7 +948,7 @@ namespace libtorrent { namespace detail } } m_timer.expires_from_now(boost::posix_time::seconds( - m_http_settings.stop_tracker_timeout)); + m_settings.stop_tracker_timeout)); m_timer.async_wait(bind(&demuxer::interrupt, &m_selector)); } @@ -1371,10 +1388,15 @@ namespace libtorrent return m_impl.m_listen_socket; } - void session::set_http_settings(const http_settings& s) + void session::set_settings(session_settings const& s) { session_impl::mutex_t::scoped_lock l(m_impl.m_mutex); - m_impl.m_http_settings = s; + m_impl.set_settings(s); + } + + session_settings const& session::settings() + { + return m_impl.m_settings; } session::~session() diff --git a/src/udp_tracker_connection.cpp b/src/udp_tracker_connection.cpp index 4182e6bc3..3681ec10b 100755 --- a/src/udp_tracker_connection.cpp +++ b/src/udp_tracker_connection.cpp @@ -79,7 +79,7 @@ namespace libtorrent , std::string const& hostname , unsigned short port , boost::weak_ptr c - , const http_settings& stn) + , session_settings const& stn) : tracker_connection(man, req, d, c) , m_man(man) , m_name_lookup(d) diff --git a/src/web_peer_connection.cpp b/src/web_peer_connection.cpp index 25989fe07..746007d8d 100755 --- a/src/web_peer_connection.cpp +++ b/src/web_peer_connection.cpp @@ -145,8 +145,8 @@ namespace libtorrent if (m_first_request) { request += "\r\nUser-Agent: "; - request += escape_string(m_ses.m_http_settings.user_agent.c_str() - , m_ses.m_http_settings.user_agent.size()); + request += escape_string(m_ses.m_settings.user_agent.c_str() + , m_ses.m_settings.user_agent.size()); } request += "\r\nRange: bytes="; request += boost::lexical_cast(r.piece @@ -180,8 +180,8 @@ namespace libtorrent if (m_first_request) { request += "\r\nUser-Agent: "; - request += escape_string(m_ses.m_http_settings.user_agent.c_str() - , m_ses.m_http_settings.user_agent.size()); + request += escape_string(m_ses.m_settings.user_agent.c_str() + , m_ses.m_settings.user_agent.size()); } request += "\r\nRange: bytes="; request += boost::lexical_cast(f.offset);