[package] update libtorrent to r1093 (#5218)
[openwrt/svn-archive/archive.git] / libs / libtorrent / patches / 011-pipe_size.patch
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)
8 @@ -783,8 +783,11 @@
9 if (download_queue()->queued_empty())
10 m_downStall = 0;
11
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;
15
16 + uint32_t pipeSize = download_queue()->calculate_pipe_size(m_peerChunks.download_throttle()->rate()->rate(), upRate);
17 +
18 // Don't start requesting if we can't do it in large enough chunks.
19 if (download_queue()->queued_size() >= (pipeSize + 10) / 2)
20 return false;
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)
25 @@ -263,22 +263,30 @@
26 }
27
28 uint32_t
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.
34 + if (upRate)
35 + upRate = downRate / upRate;
36 +
37 // Change into KB.
38 - rate /= 1024;
39 + downRate /= 1024;
40
41 if (!m_delegator->get_aggressive()) {
42 - if (rate < 20)
43 - return rate + 2;
44 + if (downRate < 20)
45 + downRate = downRate + 2;
46 else
47 - return rate / 5 + 18;
48 + downRate = downRate / 5 + 18;
49
50 } else {
51 - if (rate < 10)
52 - return rate / 5 + 1;
53 + if (downRate < 10)
54 + downRate = downRate / 5 + 1;
55 else
56 - return rate / 10 + 2;
57 + downRate = downRate / 10 + 2;
58 }
59 +
60 + return std::max(downRate, 1 + upRate);
61 }
62
63 }
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)
68 @@ -87,7 +87,7 @@
69 bool canceled_empty() const { return m_canceled.empty(); }
70 size_t canceled_size() const { return m_queued.size(); }
71
72 - uint32_t calculate_pipe_size(uint32_t rate);
73 + uint32_t calculate_pipe_size(uint32_t downRate, uint32_t upRate);
74
75 void set_delegator(Delegator* d) { m_delegator = d; }
76 void set_peer_chunks(PeerChunks* b) { m_peerChunks = b; }