diff --git a/Jamfile b/Jamfile index bca1e7074..e23477f33 100755 --- a/Jamfile +++ b/Jamfile @@ -12,28 +12,30 @@ use-project /boost/date_time : $(BOOST_ROOT)/libs/date_time/build ; project torrent : requirements - /boost/thread - /boost/date_time - /boost/filesystem + + /boost/thread + /boost/date_time + /boost/filesystem - /boost/thread - /boost/date_time - /boost/filesystem + /boost/thread + /boost/date_time + /boost/filesystem : usage-requirements - ./include - $(BOOST_ROOT) + ./include + $(BOOST_ROOT) + release:NDEBUG # devstudio switches - msvc-7:/Zc:wchar_t - msvc-7.1:/Zc:wchar_t - msvc:WIN32 + msvc-7:/Zc:wchar_t + msvc-7.1:/Zc:wchar_t + msvc:WIN32 # gcc switches - gcc:-Wno-unused-variable + gcc:-Wno-unused-variable ; @@ -82,11 +84,12 @@ SOURCES = lib torrent : - zlib//zlib - src/$(SOURCES) - : ./include - multi - static + zlib//zlib + src/$(SOURCES) + : + ./include + multi + static : debug release ; diff --git a/docs/manual.html b/docs/manual.html index fde80cdec..cf46f19b0 100755 --- a/docs/manual.html +++ b/docs/manual.html @@ -13,63 +13,63 @@
@@ -148,36 +148,22 @@ boost.filesystem, boost.date_time and various other boost libraries as well as z

building

-

To build libtorrent you need boost and bjam installed. -Then you can use bjam to build libtorrent.

- -

To make bjam work, you need to set the environment variable BOOST_ROOT to the -path where boost is installed (e.g. c:\boost_1_30_2 on windows). Then you can just run -bjam in the libtorrent directory.

-

The Jamfile doesn't work yet. On unix-systems you can use the makefile however. You -first have to build boost.thread and boost.filesystem. You do this by, in the directory -'boost-1.30.2/tools/build/jam_src' run the build script ./build.sh. This should -produce at least one folder with the 'bin' prefix (and the rest of the name describes -your platform). Put the files in that folder somewhere in your path.

-

You can then invoke bjam in the directories 'boost-1.30.2/libs/thread/build', -'boost-1.30.2/libs/date_time/build' and 'boost-1.30.2/libs/filesystem/build'. That will -produce the needed libraries. Put these libraries in the libtorrent root directory. -You then have to modify the makefile to use you prefered compiler and to have the -correct path to your boost istallation.

-

Then the makefile should be able to do the rest.

-

When building (with boost 1.30.2) on linux and solaris however, I found that I had to make the following -modifications to the boost.date-time library. In the file: -'boost-1.30.2/boost/date_time/gregorian_calendar.hpp' line 59. Prepend 'boost/date_time/' -to the include path.

-

And the second modification was in the file: -'boost-1.30.2/boost/date_time/microsec_time_clock.hpp' add the following include at the top -of the file:

+

The easiest way to build libtorrent is probably to use boost-build. Make sure you install it +correctly by setting the environment variable BOOST_BUILD_PATH and modifying the +user_config.jam to reflect the toolsets you have installed.

+

You also need to install boost 1.31.0.

+

Before you invoke bjam you have to set the environment variable BOOST_ROOT to the +path where you installed boost. This will be used to build and link against the required +boost libraries as well as be used as include path for boost headers.

+

To build you just have to run:

-#include "boost/cstdint.hpp"
+bjam <toolset>
 
-

In developer studio, you may have to set the compiler options "force conformance in for -loop scope" and "treat wchar_t as built-in type" to Yes.

-

TODO: more detailed build instructions.

+

in the libtorrent directory.

+

If you're building in developer studio, you may have to set the compiler options +"force conformance in for loop scope" and "treat wchar_t as built-in type" to Yes.

+

If you're building in developer studio 6, you will probably have to use the previous +version of boost, boost 1.30.2.

release and debug builds

If you just invoke the makefile you'll get a debug build. In debug the libtorrent vill @@ -536,6 +522,8 @@ struct torrent_handle void connect_peer(const address& adr) const; void set_ratio(float ratio); + void set_tracker_login(std::string const& username, std::string const& password); + boost::filsystem::path save_path() const; void set_max_uploads(int max_uploads); @@ -564,10 +552,12 @@ will throw invalid_handle.

set_ratio() sets the desired download / upload ratio. If set to 0, it is considered being infinite. i.e. the client will always upload as much as it can, no matter how much it gets back in return. With this setting it will work much like the standard clients.

-

Besides 0, the ration can be set to any number greater than or equal to 1. It means how much to +

Besides 0, the ratio can be set to any number greater than or equal to 1. It means how much to attempt to upload in return for each download. e.g. if set to 2, the client will try to upload 2 bytes for every byte received. The default setting for this is 0, which will make it work as a standard client.

+

set_tracker_login() sets a username and password that will be sent along in the HTTP-request +of the tracker announce. Set this if the tracker requires authorization.

info_hash() returns the info hash for the torrent.

set_max_uploads() sets the maximum number of peers that's unchoked at the same time on this torrent. If you set this to -1, there will be no limit.

diff --git a/docs/manual.rst b/docs/manual.rst index baa6f29a8..58c8ae438 100755 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -83,47 +83,33 @@ libtorrent is released under the BSD-license_. building ======== -To build libtorrent you need boost_ and bjam installed. -Then you can use ``bjam`` to build libtorrent. +The easiest way to build libtorrent is probably to use `boost-build`_. Make sure you install it +correctly by setting the environment variable ``BOOST_BUILD_PATH`` and modifying the +``user_config.jam`` to reflect the toolsets you have installed. -.. _boost: http://www.boost.org +.. _`boost-build`: http://sourceforge.net/project/showfiles.php?group_id=7586&package_id=80982 -.. http://sourceforge.net/project/showfiles.php?group_id=7586&package_id=80982 +You also need to install `boost 1.31.0`__. -To make bjam work, you need to set the environment variable ``BOOST_ROOT`` to the -path where boost is installed (e.g. c:\\boost_1_30_2 on windows). Then you can just run -``bjam`` in the libtorrent directory. +__ http://sourceforge.net/project/showfiles.php?group_id=7586&package_id=8041&release_id=214915 -The Jamfile doesn't work yet. On unix-systems you can use the makefile however. You -first have to build boost.thread and boost.filesystem. You do this by, in the directory -'boost-1.30.2/tools/build/jam_src' run the build script ``./build.sh``. This should -produce at least one folder with the 'bin' prefix (and the rest of the name describes -your platform). Put the files in that folder somewhere in your path. +Before you invoke ``bjam`` you have to set the environment variable ``BOOST_ROOT`` to the +path where you installed boost. This will be used to build and link against the required +boost libraries as well as be used as include path for boost headers. -You can then invoke ``bjam`` in the directories 'boost-1.30.2/libs/thread/build', -'boost-1.30.2/libs/date_time/build' and 'boost-1.30.2/libs/filesystem/build'. That will -produce the needed libraries. Put these libraries in the libtorrent root directory. -You then have to modify the makefile to use you prefered compiler and to have the -correct path to your boost istallation. +To build you just have to run:: -Then the makefile should be able to do the rest. + bjam -When building (with boost 1.30.2) on linux and solaris however, I found that I had to make the following -modifications to the boost.date-time library. In the file: -'boost-1.30.2/boost/date_time/gregorian_calendar.hpp' line 59. Prepend 'boost/date_time/' -to the include path. +in the libtorrent directory. -And the second modification was in the file: -'boost-1.30.2/boost/date_time/microsec_time_clock.hpp' add the following include at the top -of the file:: +If you're building in developer studio, you may have to set the compiler options +"force conformance in for loop scope" and "treat wchar_t as built-in type" to Yes. - #include "boost/cstdint.hpp" - -In developer studio, you may have to set the compiler options "force conformance in for -loop scope" and "treat wchar_t as built-in type" to Yes. - -TODO: more detailed build instructions. +If you're building in developer studio 6, you will probably have to use the previous +version of boost, `boost 1.30.2`__. +__ http://sourceforge.net/project/showfiles.php?group_id=7586&package_id=8041&release_id=178835 release and debug builds ------------------------ @@ -523,6 +509,8 @@ Its declaration looks like this:: void connect_peer(const address& adr) const; void set_ratio(float ratio); + void set_tracker_login(std::string const& username, std::string const& password); + boost::filsystem::path save_path() const; void set_max_uploads(int max_uploads); @@ -556,11 +544,14 @@ will throw invalid_handle_. infinite. i.e. the client will always upload as much as it can, no matter how much it gets back in return. With this setting it will work much like the standard clients. -Besides 0, the ration can be set to any number greater than or equal to 1. It means how much to +Besides 0, the ratio can be set to any number greater than or equal to 1. It means how much to attempt to upload in return for each download. e.g. if set to 2, the client will try to upload 2 bytes for every byte received. The default setting for this is 0, which will make it work as a standard client. +``set_tracker_login()`` sets a username and password that will be sent along in the HTTP-request +of the tracker announce. Set this if the tracker requires authorization. + ``info_hash()`` returns the info hash for the torrent. ``set_max_uploads()`` sets the maximum number of peers that's unchoked at the same time on this diff --git a/include/libtorrent/http_tracker_connection.hpp b/include/libtorrent/http_tracker_connection.hpp index e71748383..6ce99f4cf 100755 --- a/include/libtorrent/http_tracker_connection.hpp +++ b/include/libtorrent/http_tracker_connection.hpp @@ -71,7 +71,8 @@ namespace libtorrent , unsigned short port , std::string const& request , request_callback* c - , const http_settings& stn); + , const http_settings& stn + , std::string const& password = ""); virtual bool tick(); virtual bool send_finished() const { return m_send_buffer.empty(); } diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index a2d9e4876..bfac9d6eb 100755 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -187,6 +187,7 @@ namespace libtorrent // generates a request string for sending // to the tracker tracker_request generate_tracker_request(int port); + std::string tracker_password() const; boost::posix_time::ptime next_announce() const { return m_next_request; } @@ -261,6 +262,12 @@ namespace libtorrent alert_manager& alerts() const; torrent_handle get_handle() const; + void set_tracker_login(std::string const& name, std::string const& pw) + { + m_username = name; + m_password = pw; + } + // DEBUG #ifndef NDEBUG logger* spawn_logger(const char* title); @@ -349,6 +356,9 @@ namespace libtorrent // tries to maintain. // 0 is infinite float m_ratio; + + std::string m_username; + std::string m_password; }; } diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index 8a77de655..67c1a76c9 100755 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -181,6 +181,8 @@ namespace libtorrent // -1 means unlimited connections void set_max_connections(int max_connections); + void set_tracker_login(std::string const& name, std::string const& password); + const sha1_hash& info_hash() const { return m_info_hash; } diff --git a/include/libtorrent/tracker_manager.hpp b/include/libtorrent/tracker_manager.hpp index 2e6ca523b..7fa76fd89 100755 --- a/include/libtorrent/tracker_manager.hpp +++ b/include/libtorrent/tracker_manager.hpp @@ -137,7 +137,10 @@ namespace libtorrent : m_settings(s) {} void tick(); - void queue_request(tracker_request const& r, request_callback* c = 0); + void queue_request( + tracker_request const& r + , request_callback* c = 0 + , std::string const& password = ""); void abort_request(request_callback* c); void abort_all_requests(); bool send_finished() const; diff --git a/src/http_tracker_connection.cpp b/src/http_tracker_connection.cpp index 78e092781..52be7794d 100755 --- a/src/http_tracker_connection.cpp +++ b/src/http_tracker_connection.cpp @@ -81,7 +81,8 @@ namespace libtorrent , unsigned short port , std::string const& request , request_callback* c - , const http_settings& stn) + , const http_settings& stn + , std::string const& password) : tracker_connection(c) , m_state(read_status) , m_content_encoding(plain) @@ -121,6 +122,7 @@ namespace libtorrent } m_send_buffer += request; +/* m_send_buffer += "?info_hash="; m_send_buffer += escape_string( reinterpret_cast(req.info_hash.begin()), 20); @@ -151,7 +153,7 @@ namespace libtorrent // extension that tells the tracker that // we don't need any peer_id's in the response m_send_buffer += "&no_peer_id=1"; - +*/ m_send_buffer += " HTTP/1.0\r\nAccept-Encoding: gzip\r\n" "User-Agent: "; m_send_buffer += m_settings.user_agent; @@ -168,6 +170,11 @@ namespace libtorrent m_send_buffer += "\r\nProxy-Authorization: Basic "; m_send_buffer += base64encode(m_settings.proxy_login + ":" + m_settings.proxy_password); } + if (password != "") + { + m_send_buffer += "\r\nAuthorization: Basic "; + m_send_buffer += base64encode(password); + } m_send_buffer += "\r\n\r\n"; #ifndef NDEBUG if (c) c->debug_log("==> TRACKER_REQUEST [ str: " + m_send_buffer + " ]"); diff --git a/src/session.cpp b/src/session.cpp index 9d20492ea..12f5e8e0d 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -590,7 +590,8 @@ namespace libtorrent ++i) { i->second->abort(); - m_tracker_manager.queue_request(i->second->generate_tracker_request(m_listen_port)); + m_tracker_manager.queue_request( + i->second->generate_tracker_request(m_listen_port)); } m_connections.clear(); m_torrents.clear(); @@ -844,8 +845,9 @@ namespace libtorrent else if (i->second->should_request()) { m_tracker_manager.queue_request( - i->second->generate_tracker_request(m_listen_port), - boost::get_pointer(i->second)); + i->second->generate_tracker_request(m_listen_port) + , boost::get_pointer(i->second) + , i->second->tracker_password()); } i->second->second_tick(); diff --git a/src/torrent.cpp b/src/torrent.cpp index 5178f1d7f..8a46aa88b 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -459,6 +459,12 @@ namespace libtorrent i->second->announce_piece(index); } + std::string torrent::tracker_password() const + { + if (m_username.empty() && m_password.empty()) return ""; + return m_username + ":" + m_password; + } + tracker_request torrent::generate_tracker_request(int port) { assert(port > 0); diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index d9f33b6e5..d8fd6be35 100755 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -185,6 +185,26 @@ namespace libtorrent throw invalid_handle(); } + void torrent_handle::set_tracker_login(std::string const& name, std::string const& password) + { + if (m_ses == 0) throw invalid_handle(); + + { + boost::mutex::scoped_lock l(m_ses->m_mutex); + torrent* t = m_ses->find_torrent(m_info_hash); + if (t != 0) t->set_tracker_login(name, password); + } + + if (m_chk) + { + boost::mutex::scoped_lock l(m_chk->m_mutex); + detail::piece_checker_data* d = m_chk->find_torrent(m_info_hash); + if (d != 0) d->torrent_ptr->set_tracker_login(name, password); + } + + throw invalid_handle(); + } + bool torrent_handle::is_valid() const { if (m_ses == 0) return false; diff --git a/src/tracker_manager.cpp b/src/tracker_manager.cpp index ee0c97db2..3ec730241 100755 --- a/src/tracker_manager.cpp +++ b/src/tracker_manager.cpp @@ -304,7 +304,8 @@ namespace libtorrent void tracker_manager::queue_request( tracker_request const& req - , request_callback* c) + , request_callback* c + , std::string const& password) { try { @@ -363,7 +364,8 @@ namespace libtorrent , port , request_string , c - , m_settings)); + , m_settings + , password)); } else if (protocol == "udp") {