makes all tracker requests 'stopped' when aborting
[libtorrent.git] / include / libtorrent / session_settings.hpp
blob9aafbb921992cad6f9e913da9de76d42c74d0791
1 /*
3 Copyright (c) 2003, Arvid Norberg
4 All rights reserved.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
10 * Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in
14 the documentation and/or other materials provided with the distribution.
15 * Neither the name of the author nor the names of its
16 contributors may be used to endorse or promote products derived
17 from this software without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 POSSIBILITY OF SUCH DAMAGE.
33 #ifndef TORRENT_SESSION_SETTINGS_HPP_INCLUDED
34 #define TORRENT_SESSION_SETTINGS_HPP_INCLUDED
36 #include "libtorrent/version.hpp"
37 #include "libtorrent/config.hpp"
39 namespace libtorrent
42 struct TORRENT_EXPORT proxy_settings
44 proxy_settings() : port(0), type(none) {}
46 std::string hostname;
47 int port;
49 std::string username;
50 std::string password;
52 enum proxy_type
54 // a plain tcp socket is used, and
55 // the other settings are ignored.
56 none,
57 // socks4 server, requires username.
58 socks4,
59 // the hostname and port settings are
60 // used to connect to the proxy. No
61 // username or password is sent.
62 socks5,
63 // the hostname and port are used to
64 // connect to the proxy. the username
65 // and password are used to authenticate
66 // with the proxy server.
67 socks5_pw,
68 // the http proxy is only available for
69 // tracker and web seed traffic
70 // assumes anonymous access to proxy
71 http,
72 // http proxy with basic authentication
73 // uses username and password
74 http_pw
77 proxy_type type;
81 struct TORRENT_EXPORT session_settings
83 session_settings(std::string const& user_agent_ = "libtorrent/"
84 LIBTORRENT_VERSION)
85 : user_agent(user_agent_)
86 , tracker_completion_timeout(60)
87 , tracker_receive_timeout(40)
88 , stop_tracker_timeout(5)
89 , tracker_maximum_response_length(1024*1024)
90 , piece_timeout(20)
91 , request_timeout(50)
92 , request_queue_time(3.f)
93 , max_allowed_in_request_queue(250)
94 , max_out_request_queue(200)
95 , whole_pieces_threshold(20)
96 , peer_timeout(120)
97 , urlseed_timeout(20)
98 , urlseed_pipeline_size(5)
99 , urlseed_wait_retry(30)
100 , file_pool_size(40)
101 , allow_multiple_connections_per_ip(false)
102 , max_failcount(3)
103 , min_reconnect_time(60)
104 , peer_connect_timeout(7)
105 , ignore_limits_on_local_network(true)
106 , connection_speed(20)
107 , send_redundant_have(false)
108 , lazy_bitfields(true)
109 , inactivity_timeout(600)
110 , unchoke_interval(15)
111 , optimistic_unchoke_multiplier(4)
112 , num_want(200)
113 , initial_picker_threshold(4)
114 , allowed_fast_set_size(10)
115 , max_outstanding_disk_bytes_per_connection(64 * 1024)
116 , handshake_timeout(10)
117 #ifndef TORRENT_DISABLE_DHT
118 , use_dht_as_fallback(true)
119 #endif
120 , free_torrent_hashes(true)
121 , upnp_ignore_nonrouters(true)
122 , send_buffer_watermark(80 * 1024)
123 , auto_upload_slots(true)
124 , use_parole_mode(true)
125 , cache_size(512)
126 , cache_expiry(60)
127 , outgoing_ports(0,0)
128 , peer_tos(0)
129 , active_downloads(8)
130 , active_seeds(5)
131 , active_limit(15)
132 , dont_count_slow_torrents(true)
133 , auto_manage_interval(30)
134 , share_ratio_limit(2.f)
135 , seed_time_ratio_limit(7.f)
136 , seed_time_limit(24 * 60 * 60) // 24 hours
137 , peer_turnover(1 / 50.f)
138 , peer_turnover_cutoff(1.f)
139 , close_redundant_connections(true)
140 , auto_scrape_interval(1800)
141 , auto_scrape_min_interval(300)
142 , max_peerlist_size(8000)
143 , min_announce_interval(5 * 60)
146 // this is the user agent that will be sent to the tracker
147 // when doing requests. It is used to identify the client.
148 // It cannot contain \r or \n
149 std::string user_agent;
151 // the number of seconds to wait until giving up on a
152 // tracker request if it hasn't finished
153 int tracker_completion_timeout;
155 // the number of seconds where no data is received
156 // from the tracker until it should be considered
157 // as timed out
158 int tracker_receive_timeout;
160 // the time to wait when sending a stopped message
161 // before considering a tracker to have timed out.
162 // this is usually shorter, to make the client quit
163 // faster
164 int stop_tracker_timeout;
166 // if the content-length is greater than this value
167 // the tracker connection will be aborted
168 int tracker_maximum_response_length;
170 // the number of seconds from a request is sent until
171 // it times out if no piece response is returned.
172 int piece_timeout;
174 // the number of seconds one block (16kB) is expected
175 // to be received within. If it's not, the block is
176 // requested from a different peer
177 int request_timeout;
179 // the length of the request queue given in the number
180 // of seconds it should take for the other end to send
181 // all the pieces. i.e. the actual number of requests
182 // depends on the download rate and this number.
183 float request_queue_time;
185 // the number of outstanding block requests a peer is
186 // allowed to queue up in the client. If a peer sends
187 // more requests than this (before the first one has
188 // been sent) the last request will be dropped.
189 // the higher this is, the faster upload speeds the
190 // client can get to a single peer.
191 int max_allowed_in_request_queue;
193 // the maximum number of outstanding requests to
194 // send to a peer. This limit takes precedence over
195 // request_queue_time.
196 int max_out_request_queue;
198 // if a whole piece can be downloaded in this number
199 // of seconds, or less, the peer_connection will prefer
200 // to request whole pieces at a time from this peer.
201 // The benefit of this is to better utilize disk caches by
202 // doing localized accesses and also to make it easier
203 // to identify bad peers if a piece fails the hash check.
204 int whole_pieces_threshold;
206 // the number of seconds to wait for any activity on
207 // the peer wire before closing the connectiong due
208 // to time out.
209 int peer_timeout;
211 // same as peer_timeout, but only applies to url-seeds.
212 // this is usually set lower, because web servers are
213 // expected to be more reliable.
214 int urlseed_timeout;
216 // controls the pipelining size of url-seeds
217 int urlseed_pipeline_size;
219 // time to wait until a new retry takes place
220 int urlseed_wait_retry;
222 // sets the upper limit on the total number of files this
223 // session will keep open. The reason why files are
224 // left open at all is that some anti virus software
225 // hooks on every file close, and scans the file for
226 // viruses. deferring the closing of the files will
227 // be the difference between a usable system and
228 // a completely hogged down system. Most operating
229 // systems also has a limit on the total number of
230 // file descriptors a process may have open. It is
231 // usually a good idea to find this limit and set the
232 // number of connections and the number of files
233 // limits so their sum is slightly below it.
234 int file_pool_size;
236 // false to not allow multiple connections from the same
237 // IP address. true will allow it.
238 bool allow_multiple_connections_per_ip;
240 // the number of times we can fail to connect to a peer
241 // before we stop retrying it.
242 int max_failcount;
244 // the number of seconds to wait to reconnect to a peer.
245 // this time is multiplied with the failcount.
246 int min_reconnect_time;
248 // this is the timeout for a connection attempt. If
249 // the connect does not succeed within this time, the
250 // connection is dropped. The time is specified in seconds.
251 int peer_connect_timeout;
253 // if set to true, upload, download and unchoke limits
254 // are ignored for peers on the local network.
255 bool ignore_limits_on_local_network;
257 // the number of connection attempts that
258 // are made per second.
259 int connection_speed;
261 // if this is set to true, have messages will be sent
262 // to peers that already have the piece. This is
263 // typically not necessary, but it might be necessary
264 // for collecting statistics in some cases. Default is false.
265 bool send_redundant_have;
267 // if this is true, outgoing bitfields will never be fuil. If the
268 // client is seed, a few bits will be set to 0, and later filled
269 // in with have messages. This is to prevent certain ISPs
270 // from stopping people from seeding.
271 bool lazy_bitfields;
273 // if a peer is uninteresting and uninterested for longer
274 // than this number of seconds, it will be disconnected.
275 // default is 10 minutes
276 int inactivity_timeout;
278 // the number of seconds between chokes/unchokes
279 int unchoke_interval;
281 // the number of unchoke intervals between
282 // optimistic unchokes
283 int optimistic_unchoke_multiplier;
285 // if this is set, this IP will be reported do the
286 // tracker in the ip= parameter.
287 address announce_ip;
289 // the num want sent to trackers
290 int num_want;
292 // while we have fewer pieces than this, pick
293 // random pieces instead of rarest first.
294 int initial_picker_threshold;
296 // the number of allowed pieces to send to peers
297 // that supports the fast extensions
298 int allowed_fast_set_size;
300 // the maximum number of bytes a connection may have
301 // pending in the disk write queue before its download
302 // rate is being throttled. This prevents fast downloads
303 // to slow medias to allocate more and more memory
304 // indefinitely. This should be set to at least 32 kB
305 // to not completely disrupt normal downloads.
306 int max_outstanding_disk_bytes_per_connection;
308 // the number of seconds to wait for a handshake
309 // response from a peer. If no response is received
310 // within this time, the peer is disconnected.
311 int handshake_timeout;
313 #ifndef TORRENT_DISABLE_DHT
314 // while this is true, the dht will note be used unless the
315 // tracker is online
316 bool use_dht_as_fallback;
317 #endif
319 // if this is true, the piece hashes will be freed, in order
320 // to save memory, once the torrent is seeding. This will
321 // make the get_torrent_info() function to return an incomplete
322 // torrent object that cannot be passed back to add_torrent()
323 bool free_torrent_hashes;
325 // when this is true, the upnp port mapper will ignore
326 // any upnp devices that don't have an address that matches
327 // our currently configured router.
328 bool upnp_ignore_nonrouters;
330 // if the send buffer has fewer bytes than this, we'll
331 // read another 16kB block onto it. If set too small,
332 // upload rate capacity will suffer. If set too high,
333 // memory will be wasted.
334 // The actual watermark may be lower than this in case
335 // the upload rate is low, this is the upper limit.
336 int send_buffer_watermark;
338 // if auto_upload_slots is true, and a global upload
339 // limit is set and the upload rate is less than 90%
340 // of the upload limit, on new slot is opened up. If
341 // the upload rate is >= upload limit for an extended
342 // period of time, one upload slot is closed. The
343 // upload slots are never automatically decreased below
344 // the manual settings, through max_uploads.
345 bool auto_upload_slots;
347 // if set to true, peers that participate in a failing
348 // piece is put in parole mode. i.e. They will only
349 // download whole pieces until they either fail or pass.
350 // they are taken out of parole mode as soon as they
351 // participate in a piece that passes.
352 bool use_parole_mode;
354 // the disk write cache, specified in 16 KiB blocks.
355 // default is 512 (= 8 MB)
356 int cache_size;
358 // the number of seconds a write cache entry sits
359 // idle in the cache before it's forcefully flushed
360 // to disk. Default is 60 seconds.
361 int cache_expiry;
363 // if != (0, 0), this is the range of ports that
364 // outgoing connections will be bound to. This
365 // is useful for users that have routers that
366 // allow QoS settings based on local port.
367 std::pair<int, int> outgoing_ports;
369 // the TOS byte of all peer traffic (including
370 // web seeds) is set to this value. The default
371 // is the QBSS scavenger service
372 // http://qbone.internet2.edu/qbss/
373 // For unmarked packets, set to 0
374 char peer_tos;
376 // for auto managed torrents, these are the limits
377 // they are subject to. If there are too many torrents
378 // some of the auto managed ones will be paused until
379 // some slots free up.
380 int active_downloads;
381 int active_seeds;
382 int active_limit;
384 // if this is true, torrents that don't have any significant
385 // transfers are not counted as active when determining which
386 // auto managed torrents to pause and resume
387 bool dont_count_slow_torrents;
389 // the number of seconds in between recalculating which
390 // torrents to activate and which ones to queue
391 int auto_manage_interval;
393 // when a seeding torrent reaches eaither the share ratio
394 // (bytes up / bytes down) or the seed time ratio
395 // (seconds as seed / seconds as downloader) or the seed
396 // time limit (seconds as seed) it is considered
397 // done, and it will leave room for other torrents
398 // the default value for share ratio is 2
399 // the default seed time ratio is 7, because that's a common
400 // asymmetry ratio on connections
401 float share_ratio_limit;
402 float seed_time_ratio_limit;
403 int seed_time_limit;
405 // the percentage of peers to disconnect every
406 // 90 seconds (if we're at the peer limit)
407 // defaults to 1/50:th
408 float peer_turnover;
410 // when we are connected to more than
411 // limit * peer_turnover_enable peers
412 // disconnect peer_turnover fraction
413 // of the peers
414 float peer_turnover_cutoff;
416 // if this is true (default) connections where both
417 // ends have no utility in keeping the connection open
418 // are closed. for instance if both ends have completed
419 // their downloads
420 bool close_redundant_connections;
422 // the number of seconds between scrapes of
423 // queued torrents (auto managed and paused)
424 int auto_scrape_interval;
426 // the minimum number of seconds between any
427 // automatic scrape (regardless of torrent)
428 int auto_scrape_min_interval;
430 // the max number of peers in the peer list
431 // per torrent. This is the peers we know
432 // about, not necessarily connected to.
433 int max_peerlist_size;
435 // any announce intervals reported from a tracker
436 // that is lower than this, will be clamped to this
437 // value. It's specified in seconds
438 int min_announce_interval;
441 #ifndef TORRENT_DISABLE_DHT
442 struct dht_settings
444 dht_settings()
445 : max_peers_reply(50)
446 , search_branching(5)
447 , service_port(0)
448 , max_fail_count(20)
451 // the maximum number of peers to send in a
452 // reply to get_peers
453 int max_peers_reply;
455 // the number of simultanous "connections" when
456 // searching the DHT.
457 int search_branching;
459 // the listen port for the dht. This is a UDP port.
460 // zero means use the same as the tcp interface
461 int service_port;
463 // the maximum number of times a node can fail
464 // in a row before it is removed from the table.
465 int max_fail_count;
467 #endif
469 #ifndef TORRENT_DISABLE_ENCRYPTION
471 struct pe_settings
473 pe_settings()
474 : out_enc_policy(enabled)
475 , in_enc_policy(enabled)
476 , allowed_enc_level(both)
477 , prefer_rc4(false)
480 enum enc_policy
482 forced, // disallow non encrypted connections
483 enabled, // allow encrypted and non encrypted connections
484 disabled // disallow encrypted connections
487 enum enc_level
489 plaintext, // use only plaintext encryption
490 rc4, // use only rc4 encryption
491 both // allow both
494 enc_policy out_enc_policy;
495 enc_policy in_enc_policy;
497 enc_level allowed_enc_level;
498 // if the allowed encryption level is both, setting this to
499 // true will prefer rc4 if both methods are offered, plaintext
500 // otherwise
501 bool prefer_rc4;
503 #endif
507 #endif