diff --git a/docs/manual.html b/docs/manual.html
index f42c1c604..50dcd0a06 100644
--- a/docs/manual.html
+++ b/docs/manual.html
@@ -2262,6 +2262,13 @@ struct peer_info
web_seed = 1
};
int connection_type;
+
+ int remote_dl_rate;
+
+ int pending_disk_bytes;
+
+ int send_quota;
+ int receive_quota;
};
The flags attribute tells you in which state the peer is. It is set to
@@ -2406,6 +2413,14 @@ In the case of a web seed, the server type and version will be a part of this
string.
connection_type can currently be one of standard_bittorrent or
web_seed. These are currently the only implemented protocols.
+remote_dl_rate is an estimate of the rate this peer is downloading at, in
+bytes per second.
+pending_disk_bytes is the number of bytes this peer has pending in the
+disk-io thread. Downloaded and waiting to be written to disk. This is what
+is capped by session_settings::max_outstanding_disk_bytes_per_connection.
+send_quota and receive_quota are the number of bytes this peer has been
+assigned to be allowed to send and receive until it has to request more quota
+from the bandwidth manager.
diff --git a/docs/manual.rst b/docs/manual.rst
index b27f7f1c1..001f9fd5f 100644
--- a/docs/manual.rst
+++ b/docs/manual.rst
@@ -2251,6 +2251,13 @@ It contains the following fields::
web_seed = 1
};
int connection_type;
+
+ int remote_dl_rate;
+
+ int pending_disk_bytes;
+
+ int send_quota;
+ int receive_quota;
};
The ``flags`` attribute tells you in which state the peer is. It is set to
@@ -2389,6 +2396,17 @@ string.
``connection_type`` can currently be one of ``standard_bittorrent`` or
``web_seed``. These are currently the only implemented protocols.
+``remote_dl_rate`` is an estimate of the rate this peer is downloading at, in
+bytes per second.
+
+``pending_disk_bytes`` is the number of bytes this peer has pending in the
+disk-io thread. Downloaded and waiting to be written to disk. This is what
+is capped by ``session_settings::max_outstanding_disk_bytes_per_connection``.
+
+``send_quota`` and ``receive_quota`` are the number of bytes this peer has been
+assigned to be allowed to send and receive until it has to request more quota
+from the bandwidth manager.
+
session_settings
================
diff --git a/examples/client_test.cpp b/examples/client_test.cpp
index 8799d3117..cb9e5265b 100644
--- a/examples/client_test.cpp
+++ b/examples/client_test.cpp
@@ -306,7 +306,7 @@ int peer_index(libtorrent::tcp::endpoint addr, std::vector
const& peers)
{
using namespace libtorrent;
- out << "IP down (total) up (total) sent-req recv flags source fail hshf sndb inactive wait disk block-progress "
+ out << "IP down (total) up (total) sent-req recv flags source fail hshf sndb inactive wait disk quota block-progress "
#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES
"country "
#endif
@@ -352,12 +352,13 @@ void print_peer_info(std::ostream& out, std::vector const
<< ((i->source & peer_info::dht)?"D":"_")
<< ((i->source & peer_info::lsd)?"L":"_")
<< ((i->source & peer_info::resume_data)?"R":"_") << " "
- << to_string(i->failcount, 4) << " "
- << to_string(i->num_hashfails, 4) << " "
- << to_string(i->send_buffer_size, 4) << " "
+ << to_string(i->failcount, 2) << " "
+ << to_string(i->num_hashfails, 2) << " "
+ << to_string(i->send_buffer_size, 6) << " "
<< to_string(total_seconds(i->last_active), 8) << " "
<< to_string(total_seconds(i->last_request), 4) << " "
- << to_string(i->pending_disk_bytes, 4) << " ";
+ << to_string(i->pending_disk_bytes, 6) << " "
+ << to_string(i->send_quota, 5) << " ";
if (i->downloading_piece_index >= 0)
{
diff --git a/include/libtorrent/peer_info.hpp b/include/libtorrent/peer_info.hpp
index b07acffd4..94ab79815 100755
--- a/include/libtorrent/peer_info.hpp
+++ b/include/libtorrent/peer_info.hpp
@@ -155,6 +155,10 @@ namespace libtorrent
// number of bytes this peer has in
// the disk write queue
int pending_disk_bytes;
+
+ // numbers used for bandwidth limiting
+ int send_quota;
+ int receive_quota;
};
}
diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp
index ef0064802..d4c8a098b 100755
--- a/include/libtorrent/torrent.hpp
+++ b/include/libtorrent/torrent.hpp
@@ -234,12 +234,11 @@ namespace libtorrent
void request_bandwidth(int channel
, boost::intrusive_ptr const& p
- , bool non_prioritized);
+ , bool non_prioritized, int max_block_size);
void perform_bandwidth_request(int channel
, boost::intrusive_ptr const& p
- , int block_size
- , bool non_prioritized);
+ , int block_size, bool non_prioritized);
void expire_bandwidth(int channel, int amount);
void assign_bandwidth(int channel, int amount, int blk);
diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp
index d230e152a..88aa390d6 100755
--- a/src/peer_connection.cpp
+++ b/src/peer_connection.cpp
@@ -2033,6 +2033,8 @@ namespace libtorrent
void peer_connection::timed_out()
{
+ TORRENT_ASSERT(m_connecting);
+ TORRENT_ASSERT(m_connection_ticket >= 0);
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
(*m_ses.m_logger) << time_now_string() << " CONNECTION TIMED OUT: " << m_remote.address().to_string()
<< "\n";
@@ -2152,6 +2154,8 @@ namespace libtorrent
p.pid = pid();
p.ip = remote();
p.pending_disk_bytes = m_outstanding_writing_bytes;
+ p.send_quota = m_bandwidth_limit[upload_channel].quota_left();
+ p.receive_quota = m_bandwidth_limit[download_channel].quota_left();
#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES
p.country[0] = m_country[0];
@@ -2560,7 +2564,8 @@ namespace libtorrent
m_requested_write_quota = true;
#endif
t->request_bandwidth(upload_channel, self()
- , !(is_interesting() && !has_peer_choked()));
+ , !(is_interesting() && !has_peer_choked())
+ , m_send_buffer.size());
}
return;
}
@@ -2617,7 +2622,8 @@ namespace libtorrent
TORRENT_ASSERT(!m_requested_read_quota);
m_requested_read_quota = true;
#endif
- t->request_bandwidth(download_channel, self(), m_non_prioritized);
+ t->request_bandwidth(download_channel, self(), m_non_prioritized
+ , m_download_queue.size() * 16 * 1024 + 30);
}
return;
}
@@ -3031,6 +3037,7 @@ namespace libtorrent
== m_ses.m_bandwidth_manager[i]->is_in_history(this)
|| m_bandwidth_limit[i].throttle() == bandwidth_limit::inf);
}
+
std::set unique;
std::copy(m_download_queue.begin(), m_download_queue.end(), std::inserter(unique, unique.begin()));
std::copy(m_request_queue.begin(), m_request_queue.end(), std::inserter(unique, unique.begin()));
diff --git a/src/storage.cpp b/src/storage.cpp
index 07878e7ee..40aa8abb4 100755
--- a/src/storage.cpp
+++ b/src/storage.cpp
@@ -1061,6 +1061,10 @@ namespace libtorrent
// since that is the size of the pool allocator's buffers
TORRENT_ASSERT(r.length <= 16 * 1024 || buffer != 0);
m_io_thread.add_job(j, handler);
+#ifndef NDEBUG
+ boost::recursive_mutex::scoped_lock l(m_mutex);
+ TORRENT_ASSERT(slot_for(r.piece) >= 0);
+#endif
}
void piece_manager::async_write(
diff --git a/src/torrent.cpp b/src/torrent.cpp
index dbc30e298..abe405ebe 100755
--- a/src/torrent.cpp
+++ b/src/torrent.cpp
@@ -2273,11 +2273,13 @@ namespace libtorrent
void torrent::request_bandwidth(int channel
, boost::intrusive_ptr const& p
- , bool non_prioritized)
+ , bool non_prioritized, int max_block_size)
{
+ TORRENT_ASSERT(max_block_size > 0);
TORRENT_ASSERT(m_bandwidth_limit[channel].throttle() > 0);
TORRENT_ASSERT(p->max_assignable_bandwidth(channel) > 0);
- int block_size = m_bandwidth_limit[channel].throttle() / 10;
+ int block_size = (std::min)(m_bandwidth_limit[channel].throttle() / 10
+ , max_block_size);
if (block_size <= 0) block_size = 1;
if (m_bandwidth_limit[channel].max_assignable() > 0)