diff --git a/docs/manual.rst b/docs/manual.rst index 7265e3334..58a946b14 100755 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -469,6 +469,8 @@ Its declaration looks like this:: bool is_valid(); entry write_resume_data(); + void force_reannounce(); + void connect_peer(const address& adr) const; boost::filsystem::path save_path() const; @@ -488,6 +490,17 @@ any operation on an uninitialized handle, it will throw ``invalid_handle``. ``save_path()`` returns the path that was given to ``add_torrent()`` when this torrent was started. +``force_reannounce()`` will force this torrent to do another tracker request, to receive new +peers. If the torrent is invalid, queued or in checking mode, this functions will throw +invalid_handle_. + +``connect_peer()`` is a way to manually connect to peers that one believe is a part of the +torrent. If the peer does not respond, or is not a member of this torrent, it will simply +be disconnected. No harm can be done by using this other than an unnecessary connection +attempt is made. If the torrent is uninitialized or in queued or checking mode, this +will throw invalid_handle_. + + ``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 @@ -676,7 +689,7 @@ the payload data. ``id`` is the peer's id as used in the bit torrent protocol. This id can be used to extract 'fingerprints' from the peer. Sometimes it can tell you which client the peer -is using. +is using. See identify_client_ ``pieces`` is a vector of booleans that has as many entries as there are pieces in the torrent. Each boolean tells you if the peer has that piece (if it's set to true) @@ -908,6 +921,18 @@ version of your client. All these numbers must be within the range [0, 9]. ``to_string()`` will generate the actual string put in the peer-id, and return it. +identify_client +~~~~~~~~~~~~~~~ + +There's a function, in the header ``libtorrent/identify_client.hpp``, that can be used +to extract a string describing a client version from its peer-id. It has the following +declaration:: + + std::string identify_client(const peer_id& id); + +It will recognize most clients that have this kind of identification in the peer-id. + + alerts ====== diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 614c24dc0..81f0ae0f5 100755 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -127,10 +127,16 @@ namespace libtorrent return m_next_request < boost::posix_time::second_clock::local_time(); } + void force_tracker_request() + { + m_next_request = boost::posix_time::second_clock::local_time(); + } + void print(std::ostream& os) const; - void check_files(detail::piece_checker_data& data, - boost::mutex& mutex); + void check_files( + detail::piece_checker_data& data + , boost::mutex& mutex); stat statistics() const { return m_stat; } size_type bytes_left() const; @@ -141,7 +147,7 @@ namespace libtorrent const address& a , const peer_id& id); - const torrent_info& torrent_file() const throw() + const torrent_info& torrent_file() const { return m_torrent_file; } policy& get_policy() { return *m_policy; } diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index 5f2459cdb..137a5602e 100755 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -135,12 +135,17 @@ namespace libtorrent entry write_resume_data(); - // TODO: add force reannounce + // forces this torrent to reannounce + // (make a rerequest from the tracker) + void force_reannounce() const; // TODO: add a feature where the user can ask the torrent // to finish all pieces currently in the pipeline, and then // abort the torrent. + // manually connect a peer + void connect_peer(const address& adr) const; + // TODO: add finish_file_allocation, which will force the // torrent to allocate storage for all pieces. diff --git a/src/identify_client.cpp b/src/identify_client.cpp index 49a0e6f5e..21619d9d9 100755 --- a/src/identify_client.cpp +++ b/src/identify_client.cpp @@ -131,8 +131,6 @@ namespace libtorrent } // namespace unnamed - - // TODO: document std::string identify_client(const peer_id& p) { peer_id::const_iterator PID = p.begin(); diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index b92de0c17..9ff0ca56b 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -1264,20 +1264,7 @@ namespace libtorrent } #endif - if (m_active) - { - // verify peer_id - // TODO: It seems like the original client ignores to check the peer id - // can that be correct? - if (!std::equal(m_recv_buffer.begin(), m_recv_buffer.begin() + 20, (const char*)m_peer_id.begin())) - { - #ifndef NDEBUG - (*m_logger) << m_socket->sender().as_string() << " invalid peer_id (it doesn't equal the one from the tracker)\n"; - #endif - throw network_error(0); - } - } - else + if (!m_active) { // check to make sure we don't have another connection with the same // info_hash and peer_id. If we do. close this connection. diff --git a/src/torrent.cpp b/src/torrent.cpp index 4e105648f..a182c63c7 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -721,7 +721,7 @@ namespace libtorrent } // TODO: this function should also take the - // HTTP-response code as an argument + // HTTP-response code as an argument. // with some codes, we should just consider // the tracker as a failure and not retry // it anymore diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index 0a21a4966..a2a677778 100755 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -276,6 +276,30 @@ namespace libtorrent throw invalid_handle(); } + void torrent_handle::connect_peer(const address& adr) const + { + 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) throw invalid_handle(); + + peer_id id; + std::fill(id.begin(), id.end(), 0); + t->get_policy().peer_from_tracker(adr, id); + } + + void torrent_handle::force_reannounce() const + { + 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) throw invalid_handle(); + + t->force_tracker_request(); + } + void torrent_handle::get_peer_info(std::vector& v) const { v.clear();