1 # Adjust number of pieces requested from peer if we're
2 # uploading too slowly but downloading very fast so it exhausts the
3 # queue before we finish sending a piece and can request more. See ticket #1302 - libtorrent.rakshasa.no
4 Index: libtorrent/src/protocol/peer_connection_base.cc
5 ===================================================================
6 --- libtorrent/src/protocol/peer_connection_base.cc (revision 1060)
7 +++ libtorrent/src/protocol/peer_connection_base.cc (working copy)
9 if (download_queue()->queued_empty())
12 - uint32_t pipeSize = download_queue()->calculate_pipe_size(m_peerChunks.download_throttle()->rate()->rate());
13 + uint32_t upRate = (!m_upChoke.choked() && !m_peerChunks.upload_queue()->empty()) ?
14 + m_peerChunks.upload_throttle()->rate()->rate() : 0;
16 + uint32_t pipeSize = download_queue()->calculate_pipe_size(m_peerChunks.download_throttle()->rate()->rate(), upRate);
18 // Don't start requesting if we can't do it in large enough chunks.
19 if (download_queue()->queued_size() >= (pipeSize + 10) / 2)
21 Index: libtorrent/src/protocol/request_list.cc
22 ===================================================================
23 --- libtorrent/src/protocol/request_list.cc (revision 1060)
24 +++ libtorrent/src/protocol/request_list.cc (working copy)
29 -RequestList::calculate_pipe_size(uint32_t rate) {
30 +RequestList::calculate_pipe_size(uint32_t downRate, uint32_t upRate) {
31 + // Compute how many pieces we will receive while transmitting one.
32 + // Since we can't request during that time, make sure the pipe is
33 + // big enough so it doesn't run dry.
35 + upRate = downRate / upRate;
41 if (!m_delegator->get_aggressive()) {
45 + downRate = downRate + 2;
47 - return rate / 5 + 18;
48 + downRate = downRate / 5 + 18;
52 - return rate / 5 + 1;
54 + downRate = downRate / 5 + 1;
56 - return rate / 10 + 2;
57 + downRate = downRate / 10 + 2;
60 + return std::max(downRate, 1 + upRate);
64 Index: libtorrent/src/protocol/request_list.h
65 ===================================================================
66 --- libtorrent/src/protocol/request_list.h (revision 1060)
67 +++ libtorrent/src/protocol/request_list.h (working copy)
69 bool canceled_empty() const { return m_canceled.empty(); }
70 size_t canceled_size() const { return m_queued.size(); }
72 - uint32_t calculate_pipe_size(uint32_t rate);
73 + uint32_t calculate_pipe_size(uint32_t downRate, uint32_t upRate);
75 void set_delegator(Delegator* d) { m_delegator = d; }
76 void set_peer_chunks(PeerChunks* b) { m_peerChunks = b; }