From 9983e7c85ba53c8f69dc87bc40dfcac4f1f791cb Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 14 Jan 2004 01:19:30 +0000 Subject: [PATCH] *** empty log message *** --- docs/manual.html | 131 ++++++++++++++++++--------------- docs/manual.rst | 55 ++++++++------ include/libtorrent/session.hpp | 5 +- include/libtorrent/torrent.hpp | 3 - src/identify_client.cpp | 2 +- src/peer_connection.cpp | 12 +-- src/policy.cpp | 39 ++++++---- src/torrent.cpp | 26 ++++++- 8 files changed, 167 insertions(+), 106 deletions(-) diff --git a/docs/manual.html b/docs/manual.html index da57ca8db..2fbe3c9a9 100755 --- a/docs/manual.html +++ b/docs/manual.html @@ -40,29 +40,29 @@
  • tracker_alert
  • hash_failed_alert
  • peer_error_alert
  • -
  • chat_message_alert
  • -
  • dispatcher
  • +
  • invalid_request_alert
  • +
  • chat_message_alert
  • +
  • dispatcher
  • -
  • exceptions +

    libtorrent is released under the BSD-license.

    building

    @@ -1057,8 +1058,28 @@ struct peer_error_alert: alert };
    +
    +

    invalid_request_alert

    +

    Thie is a debug alert that is generated by an incoming invalid piece request.

    +
    +struct invalid_request_alert: alert
    +{
    +        invalid_request_alert(
    +                const peer_request& r
    +                , const torrent_handle& h
    +                , const peer_id& send
    +                , const std::string& msg);
    +
    +        virtual std::auto_ptr<alert> clone() const;
    +
    +        torrent_handle handle;
    +        peer_id sender;
    +        peer_request request;
    +};
    +
    +
    -

    chat_message_alert

    +

    chat_message_alert

    This alert is generated when you receive a chat message from another peer. Chat messages are supported as an extension ("chat"). It is generated as severity level critical, even though it doesn't necessarily require any user intervention, it's high priority @@ -1080,16 +1101,16 @@ struct chat_message_alert: alert

    -

    dispatcher

    +

    dispatcher

    TODO: describe the dispatcher mechanism

    -

    exceptions

    +

    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

    +

    invalid_handle

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

    @@ -1100,7 +1121,7 @@ struct invalid_handle: std::exception
     
    -

    duplicate_torrent

    +

    duplicate_torrent

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

    @@ -1111,7 +1132,7 @@ struct duplicate_torrent: std::exception
     
    -

    invalid_encoding

    +

    invalid_encoding

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

     struct invalid_encoding: std::exception
    @@ -1121,7 +1142,7 @@ struct invalid_encoding: std::exception
     
    -

    type_error

    +

    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.

    @@ -1132,7 +1153,7 @@ struct type_error: std::runtime_error
     
    -

    invalid_torrent_file

    +

    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.

    @@ -1144,9 +1165,9 @@ struct invalid_torrent_file: std::exception
     
    -

    examples

    +

    examples

    -

    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:

    @@ -1210,7 +1231,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>
    @@ -1262,7 +1283,7 @@ int main(int argc, char* argv[])
     
    -

    fast resume

    +

    fast resume

    The fast resume mechanism is a way to remember which pieces are downloaded and where they are put between sessions. You can generate fast resume data by calling torrent_handle::write_resume_data() on torrent_handle. You can then save this data @@ -1274,9 +1295,8 @@ so it will not have to start from scratch on the partially downloaded pieces.

    -
    -

    file format

    +

    file format

    The file format is a bencoded dictionary containing the following fields:

    @@ -1297,7 +1317,7 @@ not trust the fast-resume data and just do the checking.

    +each block is 16 * 1024 bytes in size.
    integer, the number of blocks per piece. Must be: piece_size / (16 * 1024). Clamped to be within the range [1, 128]. It is the number of blocks per (normal sized) piece. Usually -each piece is 16 * 1024 bytes in size.
    slots

    list of integers. The list mappes slots ti piece indices. It @@ -1355,39 +1375,32 @@ piece.

    +
    -

    extensions

    +

    extensions

    These extensions all operates within the extension protocol. The name of the extension is the name used in the extension-list packets, and the payload is the data in the extended message (not counting the length-prefix, message-id nor extension-id).

    -

    These are the extensions that are currently implemented.

    -
    -

    chat messages

    -

    Extension name: "chat"

    -

    The payload in the packet is a bencoded dictionary with any -combination of the following entries:

    - ---- - - - - - - - - -
    "msg"This is a string that contains a message that -should be displayed to the user.
    "ctrl"This is a control string that can tell a client that -it is ignored (to make the user aware of that) and -it can also tell a client that it is no longer ignored. -These notifications are encoded as the strings: -"ignored" and "not ignored". -Any unrecognized strings should be ignored.
    -
    +

    The extension protocol is currently disabled, since it may not be compatible +with future versions of bittorrent.

    + + + + + + +

    Aknowledgements

    diff --git a/docs/manual.rst b/docs/manual.rst index 7c7d122a8..5732836a2 100755 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -39,7 +39,7 @@ The current state includes the following features: * fast resume support, a way to get rid of the costly piece check at the start of a resumed torrent. Saves the storage state, piece_picker state as well as all local peers in a separate fast-resume file. - * The extension protocol `described by Nolar`__. See extensions_. + * Supports the extension protocol `described by Nolar`__. See extensions_. __ http://home.elp.rr.com/tur/multitracker-spec.txt .. _Azureus: http://azureus.sourceforge.net @@ -65,6 +65,10 @@ It does not compile on * GCC 2.95 +libtorrent is released under the BSD-license_. + +.. _BSD-license: http://www.opensource.org/licenses/bsd-license.php + building ======== @@ -74,7 +78,7 @@ Then you can use ``bjam`` to build libtorrent. .. _boost: http://www.boost.org 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 +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 @@ -1373,21 +1377,25 @@ fast-resume data is corrupt or doesn't fit the storage for that torrent, then it not trust the fast-resume data and just do the checking. file format -=========== +----------- The file format is a bencoded dictionary containing the following fields: +----------------------+--------------------------------------------------------------+ | ``file-format`` | string: "libtorrent resume file" | +| | | +----------------------+--------------------------------------------------------------+ | ``file-version`` | integer: 1 | +| | | +----------------------+--------------------------------------------------------------+ | ``info-hash`` | string, the info hash of the torrent this data is saved for. | +| | | +----------------------+--------------------------------------------------------------+ | ``blocks per piece`` | integer, the number of blocks per piece. Must be: piece_size | | | / (16 * 1024). Clamped to be within the range [1, 128]. It | | | is the number of blocks per (normal sized) piece. Usually | -| | each piece is 16 * 1024 bytes in size. | +| | each block is 16 * 1024 bytes in size. | +| | | +----------------------+--------------------------------------------------------------+ | ``slots`` | list of integers. The list mappes slots ti piece indices. It | | | tells which piece is on which slot. If piece index is -2 it | @@ -1397,6 +1405,7 @@ The file format is a bencoded dictionary containing the following fields: | | | | | If there's a slot at the position of the piece index, | | | the piece must be located in that slot. | +| | | +----------------------+--------------------------------------------------------------+ | ``peers`` | list of dictionaries. Each dictionary has the following | | | layout: | @@ -1409,6 +1418,7 @@ The file format is a bencoded dictionary containing the following fields: | | | | | These are the local peers we were connected to when this | | | fast-resume data was saved. | +| | | +----------------------+--------------------------------------------------------------+ | ``unfinished`` | list of dictionaries. Each dictionary represents an | | | piece, and has the following layout: | @@ -1435,27 +1445,30 @@ length-prefix, message-id nor extension-id). __ http://nolar.com/azureus/extended.html -These are the extensions that are currently implemented. +The extension protocol is currently disabled, since it may not be compatible +with future versions of bittorrent. -chat messages -------------- +.. These are the extensions that are currently implemented. -Extension name: "chat" +.. chat messages +.. ------------- -The payload in the packet is a bencoded dictionary with any -combination of the following entries: +.. Extension name: "chat" -+----------+--------------------------------------------------------+ -| "msg" | This is a string that contains a message that | -| | should be displayed to the user. | -+----------+--------------------------------------------------------+ -| "ctrl" | This is a control string that can tell a client that | -| | it is ignored (to make the user aware of that) and | -| | it can also tell a client that it is no longer ignored.| -| | These notifications are encoded as the strings: | -| | "ignored" and "not ignored". | -| | Any unrecognized strings should be ignored. | -+----------+--------------------------------------------------------+ +.. The payload in the packet is a bencoded dictionary with any +.. combination of the following entries: + +.. +----------+--------------------------------------------------------+ + | "msg" | This is a string that contains a message that | + | | should be displayed to the user. | + +----------+--------------------------------------------------------+ + | "ctrl" | This is a control string that can tell a client that | + | | it is ignored (to make the user aware of that) and | + | | it can also tell a client that it is no longer ignored.| + | | These notifications are encoded as the strings: | + | | "ignored" and "not ignored". | + | | Any unrecognized strings should be ignored. | + +----------+--------------------------------------------------------+ diff --git a/include/libtorrent/session.hpp b/include/libtorrent/session.hpp index 34a390dce..417eb946f 100755 --- a/include/libtorrent/session.hpp +++ b/include/libtorrent/session.hpp @@ -64,8 +64,6 @@ POSSIBILITY OF SUCH DAMAGE. # include #endif -// TODO: if we're a seed and the peer is a seed, close the connections - namespace libtorrent { @@ -237,7 +235,8 @@ namespace libtorrent void set_http_settings(const http_settings& s); void set_upload_rate_limit(int bytes_per_second); - // TODO: add a session_status that contain + // TODO: add a session_status that contain + // some indication of if the listen-port works std::auto_ptr pop_alert(); void set_severity_level(alert::severity_t s); diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 12060a01f..f6212a69e 100755 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -318,10 +318,7 @@ namespace libtorrent // from the tracker int m_duration; - // TODO: this should be a map, mapping address - // to peer_connection* std::map m_connections; -// std::vector m_connections; // this is the upload and download statistics for the whole torrent. // it's updated from all its peers once every second. diff --git a/src/identify_client.cpp b/src/identify_client.cpp index 987fcd56f..773c6d749 100755 --- a/src/identify_client.cpp +++ b/src/identify_client.cpp @@ -94,7 +94,7 @@ namespace libtorrent ret.id[1] = 0; ++i; - if (id[8] == 45) + if (std::equal(id.begin()+4, id.begin()+8, "----")) { if (!std::isdigit(*i)) return boost::optional(); ret.major_version = *i - '0'; diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index c9995a560..a6ae36f02 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -230,7 +230,8 @@ namespace libtorrent , m_send_buffer.begin() + pos + 8 , 0); // indicate that we support the extension protocol - m_send_buffer[pos] = 0x80; + // curently disabled +// m_send_buffer[pos] = 0x80; pos += 8; // info hash @@ -1287,10 +1288,11 @@ namespace libtorrent // TODO: if the protocol is to be extended // these 8 bytes would be used to describe the // extensions available on the other side - if (m_recv_buffer[0] & 0x80) - { - m_supports_extensions = true; - } + // currently disabled +// if (m_recv_buffer[0] & 0x80) +// { +// m_supports_extensions = true; +// } if (m_torrent == 0) { diff --git a/src/policy.cpp b/src/policy.cpp index 4e15e156e..845223b7f 100755 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -365,19 +365,24 @@ namespace libtorrent , old_disconnected_peer()) , m_peers.end()); - // accumulate all the free download we get - // and add it to the available free upload - m_available_free_upload - += collect_free_download( + // if the share ratio is 0 (infinite) + // m_available_free_upload isn't used + // because it isn't necessary + if (m_torrent->ratio() != 0.f) + { + // accumulate all the free download we get + // and add it to the available free upload + m_available_free_upload + += collect_free_download( + m_torrent->begin() + , m_torrent->end()); + + // distribute the free upload among the peers + m_available_free_upload = distribute_free_upload( m_torrent->begin() - , m_torrent->end()); - - // distribute the free upload among the peers - m_available_free_upload = distribute_free_upload( - m_torrent->begin() - , m_torrent->end() - , m_available_free_upload); - + , m_torrent->end() + , m_available_free_upload); + } if (m_torrent->is_seed()) { @@ -652,7 +657,15 @@ namespace libtorrent --m_num_unchoked; unchoke_one_peer(); } - m_available_free_upload += i->connection->share_diff(); + + // if the share ratio is 0 (infinite), the + // m_available_free_upload isn't used, + // because it isn't necessary. + if (m_torrent->ratio() != 0.f) + { + assert(i->connection->share_diff() < std::numeric_limits::max()); + m_available_free_upload += i->connection->share_diff(); + } i->connection = 0; } diff --git a/src/torrent.cpp b/src/torrent.cpp index 86fe8ad49..fad170e6d 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -420,7 +420,31 @@ namespace libtorrent for (peer_iterator i = m_connections.begin(); i != m_connections.end(); ++i) i->second->announce_piece(index); - // TODO: if we became a seed, disconnect from all other seeds + // if we became a seed, disconnect from all other seeds + if (is_seed()) + { + for (peer_iterator i = m_connections.begin(); + i != m_connections.end();) + { + assert(i->second->associated_torrent() == this); + + if (!i->second->is_seed()) continue; + + detail::session_impl::connection_map::iterator j = + m_ses.m_connections.find(i->second->get_socket()); + + assert(j != m_ses.m_connections.end()); + + // in the destructor of the peer_connection + // it will remove itself from this torrent + // and from the list we're iterating over. + // so we need to increment the iterator riht + // away. + ++i; + + m_ses.m_connections.erase(j); + } + } } std::string torrent::generate_tracker_request(int port)