diff --git a/docs/manual.html b/docs/manual.html index d336223fe..23e53fb12 100755 --- a/docs/manual.html +++ b/docs/manual.html @@ -597,11 +597,13 @@ struct torrent_status boost::posix_time::time_duration next_announce; boost::posix_time::time_duration announce_interval; - std::size_t total_download; - std::size_t total_upload; + std::string current_tracker; - std::size_t total_payload_download; - std::size_t total_payload_upload; + size_type total_download; + size_type total_upload; + + size_type total_payload_download; + size_type total_payload_upload; float download_rate; float upload_rate; @@ -609,7 +611,7 @@ struct torrent_status int num_peers; const std::vector<bool>* pieces; - std::size_t total_done; + size_type total_done; };

progress is a value in the range [0, 1], that represents the progress of the @@ -649,6 +651,8 @@ is a pure seeder.

next_announce is the time until the torrent will announce itself to the tracker. And announce_interval is the time the tracker want us to wait until we announce ourself again the next time.

+

current_tracker is the URL of the last working tracker. If no tracker request has +been successful yet, it's set to an empty string.

total_download and total_upload is the number of bytes downloaded and uploaded to all peers, accumulated, this session only.

total_payload_download and total_payload_upload counts the amount of bytes @@ -1146,38 +1150,52 @@ struct hash_failed_alert: alert

peer_error_alert

This alert is generated when a peer sends invalid data over the peer-peer protocol. The peer -will be disconnected, but you get its peer-id from the alert. This alert is generated -as severity level debug.

+will be disconnected, but you get its ip address from the alert, to identify it. This alert +is generated as severity level debug.

 struct peer_error_alert: alert
 {
-        peer_error_alert(const peer_id& pid, const std::string& msg);
+        peer_error_alert(const address& pid, const std::string& msg);
         virtual std::auto_ptr<alert> clone() const;
 
-        peer_id id;
+        address ip;
 };
 

invalid_request_alert

-

This is a debug alert that is generated by an incoming invalid piece request. It is -generated as severity level debug.

+

This is a debug alert that is generated by an incoming invalid piece request. The handle +is a handle to the torrent the peer is a member of. ìp is the address of the peer and the +request is the actual incoming request from the peer. The alert is generated as severity level +debug.

 struct invalid_request_alert: alert
 {
         invalid_request_alert(
                 const peer_request& r
                 , const torrent_handle& h
-                , const peer_id& send
+                , const address& send
                 , const std::string& msg);
 
         virtual std::auto_ptr<alert> clone() const;
 
         torrent_handle handle;
-        peer_id sender;
+        address ip;
         peer_request request;
 };
+
+
+struct peer_request
+{
+        int piece;
+        int start;
+        int length;
+        bool operator==(const peer_request& r);
+};
 
+

The peer_request contains the values the client sent in its request message. piece is +the index of the piece it want data from, start is the offset within the piece where the data +should be read, and length is the amount of data it wants.

torrent_finished_alert

@@ -1203,7 +1221,7 @@ This alert is generated when you receive a chat message from another peer. Chat 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 since you would almost never want to ignore such a message. The alert class contain -a torrent_handle_ to the torrent in which the sender-peer is a member and the peer_id +a torrent_handle_ to the torrent in which the sender-peer is a member and the ip of the sending peer. :: @@ -1211,13 +1229,13 @@ of the sending peer. struct chat_message_alert: alert { chat_message_alert(const torrent_handle& h - , const peer_id& sender + , const address& sender , const std::string& msg); virtual std::auto_ptr clone() const; torrent_handle handle; - peer_id sender; + address ip; }; -->
diff --git a/docs/manual.rst b/docs/manual.rst index cd8b39b39..32fc56926 100755 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -595,11 +595,13 @@ It contains the following fields:: boost::posix_time::time_duration next_announce; boost::posix_time::time_duration announce_interval; - std::size_t total_download; - std::size_t total_upload; + std::string current_tracker; - std::size_t total_payload_download; - std::size_t total_payload_upload; + size_type total_download; + size_type total_upload; + + size_type total_payload_download; + size_type total_payload_upload; float download_rate; float upload_rate; @@ -607,7 +609,7 @@ It contains the following fields:: int num_peers; const std::vector* pieces; - std::size_t total_done; + size_type total_done; }; ``progress`` is a value in the range [0, 1], that represents the progress of the @@ -643,6 +645,9 @@ current task is in the ``state`` member, it will be one of the following: ``announce_interval`` is the time the tracker want us to wait until we announce ourself again the next time. +``current_tracker`` is the URL of the last working tracker. If no tracker request has +been successful yet, it's set to an empty string. + ``total_download`` and ``total_upload`` is the number of bytes downloaded and uploaded to all peers, accumulated, *this session* only. @@ -1190,25 +1195,27 @@ peer_error_alert ---------------- This alert is generated when a peer sends invalid data over the peer-peer protocol. The peer -will be disconnected, but you get its peer-id from the alert. This alert is generated -as severity level ``debug``. +will be disconnected, but you get its ip address from the alert, to identify it. This alert +is generated as severity level ``debug``. :: struct peer_error_alert: alert { - peer_error_alert(const peer_id& pid, const std::string& msg); + peer_error_alert(const address& pid, const std::string& msg); virtual std::auto_ptr clone() const; - peer_id id; + address ip; }; invalid_request_alert --------------------- -This is a debug alert that is generated by an incoming invalid piece request. It is -generated as severity level ``debug``. +This is a debug alert that is generated by an incoming invalid piece request. The ``handle`` +is a handle to the torrent the peer is a member of. ``ìp`` is the address of the peer and the +``request`` is the actual incoming request from the peer. The alert is generated as severity level +``debug``. :: @@ -1217,17 +1224,30 @@ generated as severity level ``debug``. invalid_request_alert( const peer_request& r , const torrent_handle& h - , const peer_id& send + , const address& send , const std::string& msg); virtual std::auto_ptr clone() const; torrent_handle handle; - peer_id sender; + address ip; peer_request request; }; + struct peer_request + { + int piece; + int start; + int length; + bool operator==(const peer_request& r); + }; + + +The ``peer_request`` contains the values the client sent in its ``request`` message. ``piece`` is +the index of the piece it want data from, ``start`` is the offset within the piece where the data +should be read, and ``length`` is the amount of data it wants. + torrent_finished_alert ---------------------- @@ -1256,7 +1276,7 @@ torrent in question. This alert is generated as severity level ``info``. 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 since you would almost never want to ignore such a message. The alert class contain - a torrent_handle_ to the torrent in which the sender-peer is a member and the peer_id + a torrent_handle_ to the torrent in which the sender-peer is a member and the ip of the sending peer. :: @@ -1264,13 +1284,13 @@ torrent in question. This alert is generated as severity level ``info``. struct chat_message_alert: alert { chat_message_alert(const torrent_handle& h - , const peer_id& sender + , const address& sender , const std::string& msg); virtual std::auto_ptr clone() const; torrent_handle handle; - peer_id sender; + address ip; }; diff --git a/examples/client_test.cpp b/examples/client_test.cpp index e67d3c68a..797082b87 100755 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -370,6 +370,7 @@ int main(int argc, char* argv[]) boost::posix_time::time_duration t = s.next_announce; out << "next announce: " << boost::posix_time::to_simple_string(t) << "\n"; + out << "tracker: " << s.current_tracker << "\n"; out << "___________________________________\n"; diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index 6b9b2a2cb..8b17328ba 100755 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -72,35 +72,33 @@ namespace libtorrent struct peer_error_alert: alert { - peer_error_alert(const peer_id& pid, const std::string& msg) + peer_error_alert(const address& pip, const std::string& msg) : alert(alert::debug, msg) - , id(pid) + , ip(pip) {} virtual std::auto_ptr clone() const { return std::auto_ptr(new peer_error_alert(*this)); } - // TODO: use address instead of peer_id - peer_id id; + address ip; }; struct chat_message_alert: alert { chat_message_alert( const torrent_handle& h - , const peer_id& send + , const address& sender , const std::string& msg) : alert(alert::critical, msg) , handle(h) - , sender(send) + , ip(sender) {} virtual std::auto_ptr clone() const { return std::auto_ptr(new chat_message_alert(*this)); } torrent_handle handle; - // TODO: use address instead of peer_id - peer_id sender; + address ip; }; struct invalid_request_alert: alert @@ -108,11 +106,11 @@ namespace libtorrent invalid_request_alert( const peer_request& r , const torrent_handle& h - , const peer_id& send + , const address& sender , const std::string& msg) : alert(alert::debug, msg) , handle(h) - , sender(send) + , ip(sender) , request(r) {} @@ -120,8 +118,7 @@ namespace libtorrent { return std::auto_ptr(new invalid_request_alert(*this)); } torrent_handle handle; - // TODO: use address instead of peer_id - peer_id sender; + address ip; peer_request request; }; diff --git a/include/libtorrent/socket.hpp b/include/libtorrent/socket.hpp index 4b7c4ce40..7463c8d72 100755 --- a/include/libtorrent/socket.hpp +++ b/include/libtorrent/socket.hpp @@ -50,7 +50,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -// TODO: support QoS +// TODO: support ToS namespace libtorrent { diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index 8e754c8dd..029bde541 100755 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -100,7 +100,7 @@ namespace libtorrent boost::posix_time::time_duration next_announce; boost::posix_time::time_duration announce_interval; - // TODO: add name of tracker that is currently used + std::string current_tracker; // transferred this session! // total, payload plus protocol diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 97e3da446..27d2ed8a9 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -601,7 +601,7 @@ namespace libtorrent m_torrent->alerts().post_alert(invalid_request_alert( r , m_torrent->get_handle() - , m_peer_id + , m_socket->sender() , "peer sent an illegal request, ignoring")); } } @@ -715,7 +715,7 @@ namespace libtorrent { m_torrent->alerts().post_alert( peer_error_alert( - m_peer_id + m_socket->sender() , "got a block that was not requested")); } #ifndef NDEBUG @@ -885,8 +885,10 @@ namespace libtorrent if (m_torrent->alerts().should_post(alert::critical)) { - m_torrent->alerts() - .post_alert(chat_message_alert(m_torrent->get_handle(), m_peer_id, str)); + m_torrent->alerts().post_alert( + chat_message_alert( + m_torrent->get_handle() + , m_socket->sender(), str)); } } @@ -1750,12 +1752,8 @@ namespace libtorrent send_buffer_updated(); } - // TODO: this could be implemented more efficient - // by maintaining a counter of the number of pieces - // the peer has bool peer_connection::is_seed() const { - return std::count(m_have_piece.begin(), m_have_piece.end(), true) - == (int)m_have_piece.size(); + return m_num_pieces == m_have_piece.size(); } } diff --git a/src/policy.cpp b/src/policy.cpp index 5836b9eab..1d8123dd9 100755 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -93,15 +93,29 @@ namespace namespace { - int to_seconds(const boost::posix_time::time_duration& d) + float to_seconds(const boost::posix_time::time_duration& d) { - return d.hours() * 60 * 60 + d.minutes() * 60 + d.seconds(); + return d.hours() * 60.f * 60.f + + d.minutes() * 60.f + + d.seconds() + + d.fractional_seconds() / 1000.f; } } void request_a_block(torrent& t, peer_connection& c) { - int desired_queue_size = max_request_queue + 1 - to_seconds(c.last_piece_time()) / 4; + float time_for_last_piece = to_seconds(c.last_piece_time()); + if (time_for_last_piece == 0) time_for_last_piece = 0.001f; + const float rate = 1.f / time_for_last_piece; + + // this will make the number of requests linearly dependent + // on the rate in which we download from the peer. 2.5kB/s and + // less will make the desired queue size 2 and at about 70 kB/s + // it will reach the maximum of 16 requests. + // matlab expression to plot: + // x = 1:100:100000; plot(x, round(min(max(x ./ 5000 + 1.5, 2), 16))); + + int desired_queue_size = rate / 5000.f + 1.5f; if (desired_queue_size > max_request_queue) desired_queue_size = max_request_queue; if (desired_queue_size < min_request_queue) desired_queue_size = min_request_queue; @@ -624,7 +638,7 @@ namespace libtorrent { assert(!c.is_local()); - // TODO: make an exception if the incoming connection + // TODO: have an exception if the incoming connection // is from the tracker if(m_torrent->num_peers() >= m_max_connections) throw protocol_error("too many connections, refusing incoming connection"); // cause a disconnect @@ -720,7 +734,7 @@ namespace libtorrent if (m_torrent->alerts().should_post(alert::debug)) { m_torrent->alerts().post_alert( - peer_error_alert(id, e.what())); + peer_error_alert(remote, e.what())); } } catch(protocol_error& e) @@ -728,7 +742,7 @@ namespace libtorrent if (m_torrent->alerts().should_post(alert::debug)) { m_torrent->alerts().post_alert( - peer_error_alert(id, e.what())); + peer_error_alert(remote, e.what())); } } } diff --git a/src/session.cpp b/src/session.cpp index 30d2228f6..c07239375 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -547,7 +547,7 @@ namespace libtorrent if (m_alerts.should_post(alert::debug)) { m_alerts.post_alert( - peer_error_alert(p->second->get_peer_id(), e.what())); + peer_error_alert(p->first->sender(), e.what())); } m_selector.remove(*i); @@ -629,7 +629,7 @@ namespace libtorrent if (m_alerts.should_post(alert::debug)) { m_alerts.post_alert( - peer_error_alert(p->second->get_peer_id(), e.what())); + peer_error_alert(p->first->sender(), e.what())); } // the connection wants to disconnect for some reason, remove it // from the connection-list @@ -659,7 +659,7 @@ namespace libtorrent { m_alerts.post_alert( peer_error_alert( - p->second->get_peer_id() + p->first->sender() , "socket received an exception")); } diff --git a/src/torrent.cpp b/src/torrent.cpp index a3e134d74..69e2d653b 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -228,7 +228,7 @@ namespace libtorrent , m_ses(ses) , m_picker(torrent_file.piece_length() / m_block_size, static_cast((torrent_file.total_size()+m_block_size-1)/m_block_size)) - , m_last_working_tracker(0) + , m_last_working_tracker(-1) , m_currently_trying_tracker(0) , m_time_scaler(0) , m_priority(.5) @@ -715,6 +715,12 @@ namespace libtorrent torrent_status st; + if (m_last_working_tracker >= 0) + { + st.current_tracker + = m_torrent_file.trackers()[m_last_working_tracker].url; + } + st.total_done = bytes_done(); // payload transfer