Skip to content

Commit c1d0c46

Browse files
committed
* Added unlimited setting for max unchoked in ChokeManager and made it
the default. Set with 0 as a temporary hack. git-svn-id: svn://rakshasa.no/libtorrent/trunk/libtorrent@878 e378c898-3ddf-0310-93e7-cc216c733640
1 parent 2bce2ef commit c1d0c46

File tree

4 files changed

+40
-182
lines changed

4 files changed

+40
-182
lines changed

ChangeLog

-149
Original file line numberDiff line numberDiff line change
@@ -1,149 +0,0 @@
1-
2004-11-21 Jari Petter Sundell <[email protected]>
2-
3-
* library: Properly update interested/not interested depending on
4-
file priorities.
5-
6-
2004-11-15 Jari Petter Sundell <[email protected]>
7-
8-
* library: Variable pipe size depending on download speed.
9-
10-
2004-10-27 <[email protected]>
11-
12-
* client: On 'T' key, retrive 250 peers from tracker.
13-
14-
* library: Added tracker numwant and key.
15-
16-
2004-10-02 Jari Petter Sundell <[email protected]>
17-
18-
* torrent: New class for selecting the chunks to download.
19-
20-
* client: File priority added.
21-
22-
2004-09-25 Jari Petter Sundell <[email protected]>
23-
24-
* client: View files in torrent and their size. Will be used for priority later.
25-
26-
2004-09-19 Jari Petter Sundell <[email protected]>
27-
28-
* all: Forgotten to update this file for a while. Lot's of stuff happen with the code. ;)
29-
30-
* client: Added resume of torrents and snubbing.
31-
32-
2004-08-23 Jari Petter Sundell <[email protected]>
33-
34-
* torrent/data: Wrote new and cleaner files to chunk abstraction. Much prettier.
35-
36-
2004-08-14 <[email protected]>
37-
38-
* torrent/tracker: New tracker request code. Modular using sigc++
39-
and ready for extension.
40-
41-
* torrent: Moved over to using libcurl for http downloads.
42-
43-
2004-08-07 <[email protected]>
44-
45-
* configure: Added sigc++-2.0 to dependencies.
46-
47-
* torrent/url: Shiny new http interface with sigc++ signals.
48-
49-
2004-08-05 <[email protected]>
50-
51-
* client: Added support for http urls.
52-
53-
* delegator: Fixed a bug that caused us to request pieces the peer
54-
didn't have. (DOH!)
55-
56-
2004-08-04 <[email protected]>
57-
58-
* bitfield: Clean up bitfield class and opimized .notIn().
59-
60-
* torrent: Finished http class, testing remains.
61-
62-
2004-08-03 <[email protected]>
63-
64-
* torrent: Don't throw on zero length piece messages. Why do they
65-
send these?
66-
67-
2004-07-28 <[email protected]>
68-
69-
* torrent: Fixed a few bugs in the throttle and added min chunk
70-
size.
71-
72-
2004-07-25 <[email protected]>
73-
74-
* torrent: Fixed bug that made it skip sending the stop message to
75-
the tracker when quiting.
76-
77-
* torrent: Changed stdint.h to inttypes.h and made it easy to
78-
disable execinfo.h in client.
79-
80-
* torrent: Added throttle with tree structure. Bandwidth
81-
delegation needs work.
82-
83-
2004-07-20 <[email protected]>
84-
85-
* torrent: Using deque instead of list to increase performance.
86-
87-
* torrent: Don't close the connection if errno == EINTR.
88-
89-
* client: Added view of the exceptions log.
90-
91-
2004-07-11 <[email protected]>
92-
93-
* torrent: Choosing new chunks to download according to how many
94-
we see.
95-
96-
2004-07-10 <[email protected]>
97-
98-
* torrent: BitField::allSet() now works right, fixes problems with
99-
finished peers not being disconnected.
100-
101-
* client: No longer breaks when it receives resize interrupts
102-
during select.
103-
104-
2004-07-08 <[email protected]>
105-
106-
* torrent: Fixed mangling of outgoing commands.
107-
108-
2004-07-07 <[email protected]>
109-
110-
* torrent: Cleaned up the BitField class.
111-
112-
* client: Cleaned up the UI.
113-
114-
2004-07-04 <[email protected]>
115-
116-
* client: Added scrolling when selecting peers or downloads. View
117-
the local bitfield.
118-
119-
* torrent: Fixed some unchoking bugs and made it better at
120-
choosing whom to unchoke.
121-
122-
2004-06-29 <[email protected]>
123-
124-
* torrent: Cleaned up PeerConnection::write and made it buffer
125-
more commands in one send.
126-
127-
2004-06-27 <[email protected]>
128-
129-
* torrent: Added automatic creation of directories.
130-
131-
* configure: Added tests for OpenSSL's crypto lib.
132-
133-
2004-06-26 <[email protected]>
134-
135-
* client: Made the display code more maintainable. Added chunks
136-
seen amongst peers
137-
138-
* torrent: Added counting of chunks seen amongst the peers.
139-
140-
2004-06-25 <[email protected]>
141-
142-
* torrent: Restructed stuff, removed redundancy in up/down stuff.
143-
144-
2004-06-12 <[email protected]>
145-
146-
* configure: Added autoconf scripts.
147-
148-
* configure: Separated the test client and library.
149-

src/download/choke_manager.cc

+19-18
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ ChokeManager::~ChokeManager() {
7575
// 33 > 5 < 41
7676
// 65 > 9 < 81
7777

78-
inline unsigned int
78+
inline uint32_t
7979
ChokeManager::max_alternate() const {
8080
if (m_unchoked.size() < 31)
8181
return (m_unchoked.size() + 7) / 8;
@@ -91,15 +91,17 @@ ChokeManager::max_alternate() const {
9191

9292
void
9393
ChokeManager::balance() {
94-
// Return if no balancing is needed.
94+
// Return if no balancing is needed. Don't return if is_unlimited()
95+
// as we might have just changed the value and have interested that
96+
// can be unchoked.
9597
if (m_unchoked.size() == m_maxUnchoked)
9698
return;
9799

98100
int adjust = m_maxUnchoked - m_unchoked.size();
99101

100102
if (adjust > 0) {
101103
adjust = unchoke_range(m_queued.begin(), m_queued.end(),
102-
std::min((unsigned int)adjust, m_slotCanUnchoke()));
104+
std::min((uint32_t)adjust, m_slotCanUnchoke()));
103105

104106
m_slotUnchoke(adjust);
105107

@@ -114,13 +116,14 @@ ChokeManager::balance() {
114116
}
115117

116118
int
117-
ChokeManager::cycle(unsigned int quota) {
119+
ChokeManager::cycle(uint32_t quota) {
118120
quota = std::min(quota, m_maxUnchoked);
119121

120-
unsigned int oldSize = m_unchoked.size();
121-
unsigned int unchoked = unchoke_range(m_queued.begin(), m_queued.end(),
122-
std::max<int>((int)quota - (int)m_unchoked.size(),
123-
std::min(quota, max_alternate())));
122+
// Does this properly handle 'unlimited' quota?
123+
uint32_t oldSize = m_unchoked.size();
124+
uint32_t unchoked = unchoke_range(m_queued.begin(), m_queued.end(),
125+
std::max<uint32_t>(m_unchoked.size() < quota ? quota - m_unchoked.size() : 0,
126+
std::min(quota, max_alternate())));
124127

125128
if (m_unchoked.size() > quota)
126129
choke_range(m_unchoked.begin(), m_unchoked.end() - unchoked, m_unchoked.size() - quota);
@@ -141,9 +144,8 @@ ChokeManager::set_queued(PeerConnectionBase* pc, ChokeManagerNode* base) {
141144
if (base->snubbed())
142145
return;
143146

144-
if (m_unchoked.size() < m_maxUnchoked &&
145-
base->time_last_choke() + rak::timer::from_seconds(10) < cachedTime &&
146-
(m_flags && flag_unchoke_all_new || m_slotCanUnchoke())) {
147+
if ((m_flags & flag_unchoke_all_new || (!is_full() && m_slotCanUnchoke())) &&
148+
base->time_last_choke() + rak::timer::from_seconds(10) < cachedTime) {
147149
m_unchoked.push_back(value_type(pc, 0));
148150
m_slotConnection(pc, false);
149151

@@ -206,9 +208,8 @@ ChokeManager::set_not_snubbed(PeerConnectionBase* pc, ChokeManagerNode* base) {
206208
if (base->unchoked())
207209
throw internal_error("ChokeManager::set_not_snubbed(...) base->unchoked().");
208210

209-
if (m_unchoked.size() < m_maxUnchoked &&
210-
base->time_last_choke() + rak::timer::from_seconds(10) < cachedTime &&
211-
(m_flags && flag_unchoke_all_new || m_slotCanUnchoke())) {
211+
if ((m_flags & flag_unchoke_all_new || (!is_full() && m_slotCanUnchoke())) &&
212+
base->time_last_choke() + rak::timer::from_seconds(10) < cachedTime) {
212213
m_unchoked.push_back(value_type(pc, 0));
213214
m_slotConnection(pc, false);
214215

@@ -321,8 +322,8 @@ choke_manager_allocate_slots(ChokeManager::iterator first, ChokeManager::iterato
321322
}
322323
}
323324

324-
unsigned int
325-
ChokeManager::choke_range(iterator first, iterator last, unsigned int max) {
325+
uint32_t
326+
ChokeManager::choke_range(iterator first, iterator last, uint32_t max) {
326327
m_slotChokeWeight(first, last);
327328

328329
target_type target[order_max_size + 1];
@@ -366,8 +367,8 @@ ChokeManager::choke_range(iterator first, iterator last, unsigned int max) {
366367
return count;
367368
}
368369

369-
unsigned int
370-
ChokeManager::unchoke_range(iterator first, iterator last, unsigned int max) {
370+
uint32_t
371+
ChokeManager::unchoke_range(iterator first, iterator last, uint32_t max) {
371372
m_slotUnchokeWeight(first, last);
372373

373374
target_type target[order_max_size + 1];

src/download/choke_manager.h

+19-14
Original file line numberDiff line numberDiff line change
@@ -69,26 +69,31 @@ class ChokeManager {
6969
static const uint32_t order_max_size = 4;
7070
static const uint32_t weight_size_bytes = order_max_size * sizeof(uint32_t);
7171

72+
static const uint32_t unlimited = ~uint32_t();
73+
7274
ChokeManager(ConnectionList* cl, int flags = 0) :
7375
m_connectionList(cl),
7476
m_flags(flags),
75-
m_maxUnchoked(15),
77+
m_maxUnchoked(unlimited),
7678
m_generousUnchokes(3),
7779
m_slotConnection(NULL) {}
7880
~ChokeManager();
7981

80-
unsigned int size_unchoked() const { return m_unchoked.size(); }
81-
unsigned int size_queued() const { return m_queued.size(); }
82-
unsigned int size_total() const { return m_queued.size() + m_unchoked.size(); }
82+
bool is_full() const { return !is_unlimited() && m_unchoked.size() < m_maxUnchoked; }
83+
bool is_unlimited() const { return m_maxUnchoked == unlimited; }
84+
85+
uint32_t size_unchoked() const { return m_unchoked.size(); }
86+
uint32_t size_queued() const { return m_queued.size(); }
87+
uint32_t size_total() const { return m_queued.size() + m_unchoked.size(); }
8388

84-
unsigned int max_unchoked() const { return m_maxUnchoked; }
85-
void set_max_unchoked(unsigned int v) { m_maxUnchoked = v; }
89+
uint32_t max_unchoked() const { return m_maxUnchoked; }
90+
void set_max_unchoked(uint32_t v) { m_maxUnchoked = v; }
8691

87-
unsigned int generous_unchokes() const { return m_generousUnchokes; }
88-
void set_generous_unchokes(unsigned int v) { m_generousUnchokes = v; }
92+
uint32_t generous_unchokes() const { return m_generousUnchokes; }
93+
void set_generous_unchokes(uint32_t v) { m_generousUnchokes = v; }
8994

9095
void balance();
91-
int cycle(unsigned int quota);
96+
int cycle(uint32_t quota);
9297

9398
// Assume interested state is already updated for the PCB and that
9499
// this gets called once every time the status changes.
@@ -111,10 +116,10 @@ class ChokeManager {
111116
void set_slot_connection(slot_connection s) { m_slotConnection = s; }
112117

113118
private:
114-
inline unsigned int max_alternate() const;
119+
inline uint32_t max_alternate() const;
115120

116-
unsigned int choke_range(iterator first, iterator last, unsigned int max);
117-
unsigned int unchoke_range(iterator first, iterator last, unsigned int max);
121+
uint32_t choke_range(iterator first, iterator last, uint32_t max);
122+
uint32_t unchoke_range(iterator first, iterator last, uint32_t max);
118123

119124
ConnectionList* m_connectionList;
120125

@@ -126,8 +131,8 @@ class ChokeManager {
126131

127132
int m_flags;
128133

129-
unsigned int m_maxUnchoked;
130-
unsigned int m_generousUnchokes;
134+
uint32_t m_maxUnchoked;
135+
uint32_t m_generousUnchokes;
131136

132137
slot_weight m_slotChokeWeight;
133138
slot_weight m_slotUnchokeWeight;

src/torrent/download.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,8 @@ Download::set_uploads_max(uint32_t v) {
439439
if (v > (1 << 16))
440440
throw input_error("Max uploads must be between 0 and 2^16.");
441441

442-
m_ptr->main()->upload_choke_manager()->set_max_unchoked(v);
442+
// For the moment, treat 0 as unlimited.
443+
m_ptr->main()->upload_choke_manager()->set_max_unchoked(v == 0 ? ChokeManager::unlimited : v);
443444
m_ptr->main()->upload_choke_manager()->balance();
444445
}
445446

0 commit comments

Comments
 (0)