From 94919f98069e07210579f2bab20a02994097ed2c Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 28 Nov 2003 17:29:27 +0000 Subject: [PATCH] *** empty log message *** --- docs/index.html | 145 ++++++++++++++++++++------ docs/index.rst | 125 ++++++++++++++++++---- examples/dump_torrent.cpp | 5 +- include/libtorrent/session.hpp | 17 --- include/libtorrent/torrent_handle.hpp | 24 +++-- src/peer_connection.cpp | 2 +- src/piece_picker.cpp | 2 +- src/policy.cpp | 16 +++ src/session.cpp | 36 ++++++- src/storage.cpp | 29 ++---- src/torrent_handle.cpp | 99 +++++++++--------- src/torrent_info.cpp | 2 +- 12 files changed, 342 insertions(+), 160 deletions(-) diff --git a/docs/index.html b/docs/index.html index b1000a5a0..bd9e70ff1 100755 --- a/docs/index.html +++ b/docs/index.html @@ -35,21 +35,31 @@
  • status()
  • get_download_queue()
  • get_peer_info()
  • +
  • get_torrent_info()
  • +
  • is_valid()
  • -
  • address
  • -
  • http_settings
  • -
  • big_number
  • -
  • hasher
  • -
  • example usage
  • -
  • Feedback
  • -
  • Aknowledgements
  • +
  • Feedback
  • +
  • Aknowledgements
  • @@ -159,7 +169,8 @@ The main thread will be idle as long it doesn't have any torrents to participate You add torrents through the add_torrent()-function where you give an object representing the information found in the torrent file and the path where you want to save the files. The save_path will be prepended to the directory- -structure in the torrent-file.

    +structure in the torrent-file. add_torrent will throw duplicate_torrent exception +if the torrent already exists in the session.

    remove_torrent() will close all peer connections associated with the torrent and tell the tracker that we've stopped participating in the swarm.

    If the torrent you are trying to add already exists in the session (is either queued @@ -388,9 +399,11 @@ struct torrent_handle { torrent_handle(); - torrent_status status() const; + torrent_status status(); void get_download_queue(std::vector<partial_piece_info>& queue); void get_peer_info(std::vector<peer_info>& v); + const torrent_info& get_torrent_info(); + bool is_valid(); };

    The default constructor will initialize the handle to an invalid state. Which means you cannot @@ -399,7 +412,8 @@ any operation they will simply return.

    status()

    status() will return a structure with information about the status of this -torrent. It contains the following fields:

    +torrent. If the torrent_handle is invalid, it will throw invalid_handle exception. +It contains the following fields:

     struct torrent_status
     {
    @@ -430,11 +444,6 @@ current task is in the state m
     
     
     
    -invalid_handle
    -This will be the state if you called status on an
    -uninitialized handle (a handle that was constructed
    -with the default constructor).
    -
     queued_for_checking
     The torrent is in the queue for being checked. But there
     currently is another torrent that are being checked.
    @@ -498,8 +507,10 @@ may pass then.

    get_peer_info()

    get_peer_info() takes a reference to a vector that will be cleared and filled -with one entry for each peer connected to this torrent. Each entry contains information about -that particular peer. It contains the following information:

    +with one entry for each peer connected to this torrent, given the handle is valid. If the +torrent_handle is invalid, it will throw invalid_handle exception. Each entry in +the vector contains information about that particular peer. It contains the following +fields:

     struct peer_info
     {
    @@ -543,9 +554,20 @@ or if the peer miss that piece (set to false).

    upload_limit is the number of bytes per second we are allowed to send to this peer every second. It may be -1 if there's no limit.

    +
    +

    get_torrent_info()

    +

    Returns a const reference to the torrent_info object associated with this torrent. +This reference is valid as long as the torrent_handle is valid, no longer. If the +torrent_handle is invalid, invalid_handle exception will be thrown.

    +
    +
    +

    is_valid()

    +

    Returns true if this handle refers to a valid torrent and false if it hasn't been initialized +or if the torrent it refers to has been aborted.

    +
    -

    address

    +

    address

    The address class represents a name of a network endpoint (usually referred to as IP-address) and a port number. This is the same thing as a sockaddr_in would contain. Its declaration looks like this:

    @@ -554,8 +576,7 @@ class address { public: address(); - address( - unsigned char a + address(unsigned char a , unsigned char b , unsigned char c , unsigned char d @@ -579,7 +600,7 @@ while it does the DNS lookup, it returns a string that points to the address rep

    ip() will return the 32-bit ip-address as an integer. port() returns the port number.

    -

    http_settings

    +

    http_settings

    You have some control over tracker requests through the http_settings object. You create it and fill it with your settings and the use session::set_http_settings() to apply them. You have control over proxy and authorization settings and also the user-agent @@ -607,9 +628,10 @@ on the uncompressed data. So, if you get 20 bytes of gzip response that'll expand to 2 megs, it will be interrupted before the entire response has been uncompressed (given your limit is lower than 2 megs). Default limit is 1 megabyte.

    +

    TODO: finish document http_settings

    -

    big_number

    +

    big_number

    Both the peer_id and sha1_hash types are typedefs of the class big_number. It represents 20 bytes of data. Its synopsis follows:

    @@ -630,7 +652,7 @@ public:
     

    The iterators gives you access to individual bytes.

    -

    hasher

    +

    hasher

    This class creates sha1-hashes. Its declaration looks like this:

     class hasher
    @@ -653,10 +675,69 @@ call reset() to reinitialize i
     

    The sha1-algorithm used was implemented by Steve Reid and released as public domain. For more info, see src/sha1.c.

    +
    +

    exceptions

    +

    There are a number of exceptions that can be thrown from different places in libtorrent, +here's a complete list with description.

    +
    +

    invalid_handle

    +

    This exception is thrown when querying information from a torrent_handle that hasn't +been initialized or that has become invalid.

    +
    +struct invalid_handle: std::exception
    +{
    +        const char* what() const throw();
    +};
    +
    +
    +
    +

    duplicate_torrent

    +

    This is thrown by session::add_torrent() if the torrent already has been added to +the session.

    +
    +struct duplicate_torrent: std::exception
    +{
    +        const char* what() const throw();
    +};
    +
    +
    +
    +

    invalid_encoding

    +

    This is thrown by bdecode() if the input data is not a valid bencoding.

    +
    +struct invalid_encoding: std::exception
    +{
    +        const char* what() const throw();
    +};
    +
    +
    +
    +

    type_error

    +

    This is thrown from the accessors of entry if the data type of the entry doesn't +match the type you want to extract from it.

    +
    +struct type_error: std::runtime_error
    +{
    +        type_error(const char* error);
    +};
    +
    +
    +
    +

    invalid_torrent_file

    +

    This exception is thrown from the constructor of torrent_info if the given bencoded information +doesn't meet the requirements on what information has to be present in a torrent file.

    +
    +struct invalid_torrent_file: std::exception
    +{
    +        const char* what() const throw();
    +};
    +
    +
    +
    -

    example usage

    +

    example usage

    -

    dump_torrent

    +

    dump_torrent

    This is an example of a program that will take a torrent-file as a parameter and print information about it to std out:

    @@ -664,13 +745,11 @@ print information about it to std out:

    #include <fstream> #include <iterator> #include <exception> -#include <vector> #include <iomanip> #include "libtorrent/entry.hpp" #include "libtorrent/bencode.hpp" -#include "libtorrent/session.hpp" -#include "libtorrent/http_settings.hpp" +#include "libtorrent/torrent_info.hpp" int main(int argc, char* argv[]) @@ -722,7 +801,7 @@ int main(int argc, char* argv[])
    -

    simple client

    +

    simple client

    This is a simple client. It doesn't have much output to keep it simple:

     #include <iostream>
    @@ -775,12 +854,12 @@ int main(int argc, char* argv[])
     
    -

    Feedback

    +

    Feedback

    There's a mailing list.

    You can usually find me as hydri in #btports @ irc.freenode.net.

    -

    Aknowledgements

    +

    Aknowledgements

    Written by Arvid Norberg and Daniel Wallin. Copyright (c) 2003

    Project is hosted by sourceforge.

    sf_logo

    diff --git a/docs/index.rst b/docs/index.rst index c9497a432..99e735fc5 100755 --- a/docs/index.rst +++ b/docs/index.rst @@ -138,7 +138,8 @@ The main thread will be idle as long it doesn't have any torrents to participate You add torrents through the ``add_torrent()``-function where you give an object representing the information found in the torrent file and the path where you want to save the files. The ``save_path`` will be prepended to the directory- -structure in the torrent-file. +structure in the torrent-file. ``add_torrent`` will throw ``duplicate_torrent`` exception +if the torrent already exists in the session. ``remove_torrent()`` will close all peer connections associated with the torrent and tell the tracker that we've stopped participating in the swarm. @@ -417,9 +418,11 @@ Its declaration looks like this:: { torrent_handle(); - torrent_status status() const; + torrent_status status(); void get_download_queue(std::vector& queue); void get_peer_info(std::vector& v); + const torrent_info& get_torrent_info(); + bool is_valid(); }; The default constructor will initialize the handle to an invalid state. Which means you cannot @@ -427,13 +430,12 @@ perform any operation on it, unless you first assign it a valid handle. If you t any operation they will simply return. - - status() ~~~~~~~~ ``status()`` will return a structure with information about the status of this -torrent. It contains the following fields:: +torrent. If the ``torrent_handle`` is invalid, it will throw ``invalid_handle`` exception. +It contains the following fields:: struct torrent_status { @@ -459,10 +461,6 @@ torrent. It contains the following fields:: torrent's current task. It may be checking files or downloading. The torrent's current task is in the ``state`` member, it will be one of the following: -+-----------------------+----------------------------------------------------------+ -|``invalid_handle`` |This will be the state if you called status on an | -| |uninitialized handle (a handle that was constructed | -| |with the default constructor). | +-----------------------+----------------------------------------------------------+ |``queued_for_checking``|The torrent is in the queue for being checked. But there | | |currently is another torrent that are being checked. | @@ -526,14 +524,14 @@ When a piece fails a hash verification, single blocks may be redownloaded to see may pass then. - - get_peer_info() ~~~~~~~~~~~~~~~ ``get_peer_info()`` takes a reference to a vector that will be cleared and filled -with one entry for each peer connected to this torrent. Each entry contains information about -that particular peer. It contains the following information:: +with one entry for each peer connected to this torrent, given the handle is valid. If the +``torrent_handle`` is invalid, it will throw ``invalid_handle`` exception. Each entry in +the vector contains information about that particular peer. It contains the following +fields:: struct peer_info { @@ -584,6 +582,20 @@ or if the peer miss that piece (set to false). peer every second. It may be -1 if there's no limit. +get_torrent_info() +~~~~~~~~~~~~~~~~~~ + +Returns a const reference to the ``torrent_info`` object associated with this torrent. +This reference is valid as long as the ``torrent_handle`` is valid, no longer. If the +``torrent_handle`` is invalid, ``invalid_handle`` exception will be thrown. + + +is_valid() +~~~~~~~~~~ + +Returns true if this handle refers to a valid torrent and false if it hasn't been initialized +or if the torrent it refers to has been aborted. + address ------- @@ -596,8 +608,7 @@ Its declaration looks like this:: { public: address(); - address( - unsigned char a + address(unsigned char a , unsigned char b , unsigned char c , unsigned char d @@ -658,7 +669,7 @@ expand to 2 megs, it will be interrupted before the entire response has been uncompressed (given your limit is lower than 2 megs). Default limit is 1 megabyte. - +TODO: finish document http_settings big_number ---------- @@ -713,6 +724,84 @@ The sha1-algorithm used was implemented by Steve Reid and released as public dom For more info, see ``src/sha1.c``. + + +exceptions +---------- + +There are a number of exceptions that can be thrown from different places in libtorrent, +here's a complete list with description. + + +invalid_handle +~~~~~~~~~~~~~~ + +This exception is thrown when querying information from a ``torrent_handle`` that hasn't +been initialized or that has become invalid. + +:: + + struct invalid_handle: std::exception + { + const char* what() const throw(); + }; + + +duplicate_torrent +~~~~~~~~~~~~~~~~~ + +This is thrown by ``session::add_torrent()`` if the torrent already has been added to +the session. + +:: + + struct duplicate_torrent: std::exception + { + const char* what() const throw(); + }; + + +invalid_encoding +~~~~~~~~~~~~~~~~ + +This is thrown by ``bdecode()`` if the input data is not a valid bencoding. + +:: + + struct invalid_encoding: std::exception + { + const char* what() const throw(); + }; + + +type_error +~~~~~~~~~~ + +This is thrown from the accessors of ``entry`` if the data type of the ``entry`` doesn't +match the type you want to extract from it. + +:: + + struct type_error: std::runtime_error + { + type_error(const char* error); + }; + + +invalid_torrent_file +~~~~~~~~~~~~~~~~~~~~ + +This exception is thrown from the constructor of ``torrent_info`` if the given bencoded information +doesn't meet the requirements on what information has to be present in a torrent file. + +:: + + struct invalid_torrent_file: std::exception + { + const char* what() const throw(); + }; + + example usage ------------- @@ -726,13 +815,11 @@ print information about it to std out:: #include #include #include - #include #include #include "libtorrent/entry.hpp" #include "libtorrent/bencode.hpp" - #include "libtorrent/session.hpp" - #include "libtorrent/http_settings.hpp" + #include "libtorrent/torrent_info.hpp" int main(int argc, char* argv[]) diff --git a/examples/dump_torrent.cpp b/examples/dump_torrent.cpp index 5c382d17c..5d2b4d9ca 100755 --- a/examples/dump_torrent.cpp +++ b/examples/dump_torrent.cpp @@ -33,14 +33,11 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include -#include -#include #include #include "libtorrent/entry.hpp" #include "libtorrent/bencode.hpp" -#include "libtorrent/session.hpp" -#include "libtorrent/http_settings.hpp" +#include "libtorrent/torrent_info.hpp" int main(int argc, char* argv[]) diff --git a/include/libtorrent/session.hpp b/include/libtorrent/session.hpp index 8a491aac4..b67b5a0c4 100755 --- a/include/libtorrent/session.hpp +++ b/include/libtorrent/session.hpp @@ -30,21 +30,6 @@ POSSIBILITY OF SUCH DAMAGE. */ -/* - implemented - - * http-proxy authentication for tracker requests - * multitracker support - * spawns separate temporary threads for file checking - * - - missing - - * endgame-mode - * correct algorithm for choking and unchoking - -*/ - #ifndef TORRENT_SESSION_HPP_INCLUDED #define TORRENT_SESSION_HPP_INCLUDED @@ -74,8 +59,6 @@ POSSIBILITY OF SUCH DAMAGE. // TODO: if we're not interested and the peer isn't interested, close the connections -// TODO: instead of implementing end-game mode, have an algorithm that -// constantly prioritizes high-bandwidth sources. namespace libtorrent { diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index 7515d73c8..8bc31eb41 100755 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -39,7 +39,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/peer_id.hpp" #include "libtorrent/peer_info.hpp" #include "libtorrent/piece_picker.hpp" - +#include "libtorrent/torrent_info.hpp" namespace libtorrent { @@ -55,11 +55,16 @@ namespace libtorrent { return "torrent already exists in session"; } }; + struct invalid_handle: std::exception + { + virtual const char* what() const throw() + { return "invalid torrent handle used"; } + }; + struct torrent_status { enum state_t { - invalid_handle, queued_for_checking, checking_files, downloading, @@ -96,17 +101,20 @@ namespace libtorrent torrent_handle(): m_ses(0) {} void get_peer_info(std::vector& v); - torrent_status status() const; - void get_download_queue(std::vector& queue) const; + torrent_status status(); + void get_download_queue(std::vector& queue); + + const torrent_info& get_torrent_info(); + bool is_valid(); // TODO: add force reannounce - // TODO: add torrent_info getter + + // TODO: add a feature where the user can ask the torrent + // to finish all pieces currently in the pipeline, and then + // abort the torrent. private: - // called by session::remove_torrent() - void abort() const; - torrent_handle(detail::session_impl* s, detail::checker_impl* c, const sha1_hash& h) diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 46a94fede..058bdc383 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -841,7 +841,7 @@ void libtorrent::peer_connection::receive_data() { // verify peer_id // TODO: It seems like the original client ignores to check the peer id - // can this be correct? + // can that be correct? if (!std::equal(m_recv_buffer.begin(), m_recv_buffer.begin() + 20, (const char*)m_peer_id.begin())) { #ifndef NDEBUG diff --git a/src/piece_picker.cpp b/src/piece_picker.cpp index cdcd38d00..f6bdb586d 100755 --- a/src/piece_picker.cpp +++ b/src/piece_picker.cpp @@ -305,7 +305,7 @@ namespace libtorrent // TODO: since inc_refcount is called // with sequential indices when peers - // connect, it will sort the pieces + // connect, the pieces will be sorted. // that is not good. one solution is // to insert the element at a random // index when moving it to another diff --git a/src/policy.cpp b/src/policy.cpp index eb09a92c2..c59a773e1 100755 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -37,6 +37,10 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/socket.hpp" #include "libtorrent/peer_connection.hpp" +#if defined(_MSC_VER) && _MSC_VER < 1300 +# define for if (false) {} else for +#endif + namespace { enum @@ -189,6 +193,18 @@ namespace libtorrent void peer_connection::unchoke(); void peer_connection::request_piece(int index); const std::vector& peer_connection::download_queue(); + + TODO: to implement choking/unchoking we need a list with all + connected peers. Something like this: + + struct peer + { + peer_id id; + boost::posix_time::ptime last_optimistically_unchoked; + float average_down_rate; + boost::weak_ptr connection; + }; + */ diff --git a/src/session.cpp b/src/session.cpp index 2690a7d6b..d4265e42e 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -42,6 +42,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include +#include #include "libtorrent/peer_id.hpp" #include "libtorrent/torrent_info.hpp" @@ -104,6 +105,12 @@ namespace libtorrent std::make_pair(t->info_hash, t->torrent_ptr)).first; } } + catch(const boost::filesystem::filesystem_error& e) + { +#ifndef NDEBUG + std::cerr << "error while checking files: " << e.what() << "\n"; +#endif + } catch(...) { #ifndef NDEBUG @@ -387,6 +394,9 @@ namespace libtorrent // will shift bandwidth from the peers that can't // utilize all their assigned bandwidth to the peers // that actually can maintain the upload rate. + // This should probably be done by accumulating the + // left-over bandwidth to next second. Since the + // the sockets consumes its data in rather big chunks. if (m_upload_rate != -1 && !m_connections.empty()) { assert(m_upload_rate >= 0); @@ -561,8 +571,6 @@ namespace libtorrent // create the torrent and the data associated with // the checker thread and store it before starting // the thread - // TODO: have a queue of checking torrents instead of - // having them all run at the same time boost::shared_ptr torrent_ptr(new torrent(&m_impl, ti)); detail::piece_checker_data d; @@ -585,8 +593,28 @@ namespace libtorrent void session::remove_torrent(const torrent_handle& h) { if (h.m_ses != &m_impl) return; - // TODO: move the code of abort() here instead of calling it - h.abort(); + assert(h.m_chk == &m_checker_impl); + + { + boost::mutex::scoped_lock l(m_impl.m_mutex); + torrent* t = m_impl.find_torrent(h.m_info_hash); + if (t != 0) + { + t->abort(); + return; + } + } + + { + boost::mutex::scoped_lock l(m_checker_impl.m_mutex); + + detail::piece_checker_data* d = m_checker_impl.find_torrent(h.m_info_hash); + if (d != 0) + { + d->abort = true; + return; + } + } } void session::set_http_settings(const http_settings& s) diff --git a/src/storage.cpp b/src/storage.cpp index 81beac184..d97ae350f 100755 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -771,9 +771,9 @@ void libtorrent::storage::allocate_pieces(int num) fs::ofstream out; if (fs::exists(path)) - out.open(path, std::ios_base::binary | std::ios_base::in); + out.open(path.native_file_string().c_str(), std::ios_base::binary | std::ios_base::in); else - out.open(path, std::ios_base::binary); + out.open(path.native_file_string().c_str(), std::ios_base::binary); // std::ofstream out((m_save_path / file_iter->path / file_iter->filename).native_file_string().c_str() // , std::ios_base::binary | std::ios_base::in); @@ -1156,8 +1156,11 @@ void libtorrent::storage::initialize_pieces(torrent* t, { boost::mutex::scoped_lock lock(mutex); +// TODO: finish +// data->progress = ; + if (data->abort) - ; + return; } fs::path path(m_save_path / file_iter->path); @@ -1173,7 +1176,7 @@ void libtorrent::storage::initialize_pieces(torrent* t, { in.close(); in.clear(); - in.open(path, std::ios_base::binary); + in.open(path.native_file_string().c_str(), std::ios_base::binary); changed_file = false; @@ -1311,6 +1314,7 @@ void libtorrent::storage::initialize_pieces(torrent* t, } #if 0 // OLD STORAGE +/* // allocate files will create all files that are missing // if there are some files that already exists, it checks @@ -1327,21 +1331,6 @@ void libtorrent::storage::initialize_pieces(torrent* t, m_save_path = path; m_torrent_file = &t->torrent_file(); - // TEMPORARY! -/* - m_bytes_left = 0; - m_have_piece.resize(m_torrent_file->num_pieces()); - std::fill(m_have_piece.begin(), m_have_piece.end(), true); - return; -*/ -/* - m_bytes_left = m_torrent_file->total_size(); - m_have_piece.resize(m_torrent_file->num_pieces()); - std::fill(m_have_piece.begin(), m_have_piece.end(), false); - return; -*/ - - // we don't know of any piece we have right now. Initialize // it to say we don't have anything and fill it in later on. m_have_piece.resize(m_torrent_file->num_pieces()); @@ -1476,6 +1465,6 @@ void libtorrent::storage::initialize_pieces(torrent* t, } } - +*/ #endif diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index 09ffbe497..77e620db2 100755 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -63,20 +63,9 @@ namespace std namespace libtorrent { - torrent_status torrent_handle::status() const + torrent_status torrent_handle::status() { - if (m_ses == 0) - { - torrent_status st; - st.total_download = 0; - st.total_upload = 0; - st.progress = 0.f; - st.state = torrent_status::invalid_handle; - st.next_announce = boost::posix_time::time_duration(); - st.pieces.clear(); - st.total_done = 0; - return st; - } + if (m_ses == 0) throw invalid_handle(); assert(m_chk != 0); { @@ -107,21 +96,54 @@ namespace libtorrent } } - torrent_status st; - st.total_download = 0; - st.total_upload = 0; - st.progress = 0.f; - st.state = torrent_status::invalid_handle; - st.pieces.clear(); - st.next_announce = boost::posix_time::time_duration(); - st.total_done = 0; - return st; + m_ses = 0; + throw invalid_handle(); + } + + const torrent_info& torrent_handle::get_torrent_info() + { + 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) return t->torrent_file(); + } + + { + boost::mutex::scoped_lock l(m_chk->m_mutex); + detail::piece_checker_data* d = m_chk->find_torrent(m_info_hash); + if (d != 0) return d->torrent_ptr->torrent_file(); + } + + m_ses = 0; + throw invalid_handle(); + } + + bool torrent_handle::is_valid() + { + if (m_ses == 0) return false; + + { + boost::mutex::scoped_lock l(m_ses->m_mutex); + torrent* t = m_ses->find_torrent(m_info_hash); + if (t != 0) return true; + } + + { + boost::mutex::scoped_lock l(m_chk->m_mutex); + detail::piece_checker_data* d = m_chk->find_torrent(m_info_hash); + if (d != 0) return true; + } + + m_ses = 0; + return false; } void torrent_handle::get_peer_info(std::vector& v) { v.clear(); - if (m_ses == 0) return; + if (m_ses == 0) throw invalid_handle(); assert(m_chk != 0); boost::mutex::scoped_lock l(m_ses->m_mutex); @@ -158,11 +180,11 @@ namespace libtorrent } } - void torrent_handle::get_download_queue(std::vector& queue) const + void torrent_handle::get_download_queue(std::vector& queue) { queue.clear(); - if (m_ses == 0) return; + if (m_ses == 0) throw invalid_handle(); assert(m_chk != 0); boost::mutex::scoped_lock l(m_ses->m_mutex); @@ -193,31 +215,4 @@ namespace libtorrent } } - void torrent_handle::abort() const - { - if (m_ses == 0) return; - assert(m_chk != 0); - - { - boost::mutex::scoped_lock l(m_ses->m_mutex); - torrent* t = m_ses->find_torrent(m_info_hash); - if (t != 0) - { - t->abort(); - return; - } - } - - { - 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->abort = true; - return; - } - } - } - } diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index 8dce311db..a343ce1a7 100755 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -228,7 +228,7 @@ namespace libtorrent if (!m_comment.empty()) os << "comment: " << m_comment << "\n"; if (m_creation_date != boost::posix_time::ptime(boost::gregorian::date(1970, boost::gregorian::Jan, 1))) - os << "creation date: " << to_simple_string(m_creation_date) << "\n"; + os << "creation date: " << boost::posix_time::to_simple_string(m_creation_date) << "\n"; os << "number of pieces: " << num_pieces() << "\n"; os << "piece length: " << piece_length() << "\n"; os << "files:\n";