LT SYNC
[tore.git] / libtorrent / include / libtorrent / session_settings.hpp
blobe71efc7e3a8375fc784e263c212bb84421197257
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(false)
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)
144 , prioritize_partial_pieces(false)
145 , auto_manage_startup(120)
148 // this is the user agent that will be sent to the tracker
149 // when doing requests. It is used to identify the client.
150 // It cannot contain \r or \n
151 std::string user_agent;
153 // the number of seconds to wait until giving up on a
154 // tracker request if it hasn't finished
155 int tracker_completion_timeout;
157 // the number of seconds where no data is received
158 // from the tracker until it should be considered
159 // as timed out
160 int tracker_receive_timeout;
162 // the time to wait when sending a stopped message
163 // before considering a tracker to have timed out.
164 // this is usually shorter, to make the client quit
165 // faster
166 int stop_tracker_timeout;
168 // if the content-length is greater than this value
169 // the tracker connection will be aborted
170 int tracker_maximum_response_length;
172 // the number of seconds from a request is sent until
173 // it times out if no piece response is returned.
174 int piece_timeout;
176 // the number of seconds one block (16kB) is expected
177 // to be received within. If it's not, the block is
178 // requested from a different peer
179 int request_timeout;
181 // the length of the request queue given in the number
182 // of seconds it should take for the other end to send
183 // all the pieces. i.e. the actual number of requests
184 // depends on the download rate and this number.
185 float request_queue_time;
187 // the number of outstanding block requests a peer is
188 // allowed to queue up in the client. If a peer sends
189 // more requests than this (before the first one has
190 // been sent) the last request will be dropped.
191 // the higher this is, the faster upload speeds the
192 // client can get to a single peer.
193 int max_allowed_in_request_queue;
195 // the maximum number of outstanding requests to
196 // send to a peer. This limit takes precedence over
197 // request_queue_time.
198 int max_out_request_queue;
200 // if a whole piece can be downloaded in this number
201 // of seconds, or less, the peer_connection will prefer
202 // to request whole pieces at a time from this peer.
203 // The benefit of this is to better utilize disk caches by
204 // doing localized accesses and also to make it easier
205 // to identify bad peers if a piece fails the hash check.
206 int whole_pieces_threshold;
208 // the number of seconds to wait for any activity on
209 // the peer wire before closing the connectiong due
210 // to time out.
211 int peer_timeout;
213 // same as peer_timeout, but only applies to url-seeds.
214 // this is usually set lower, because web servers are
215 // expected to be more reliable.
216 int urlseed_timeout;
218 // controls the pipelining size of url-seeds
219 int urlseed_pipeline_size;
221 // time to wait until a new retry takes place
222 int urlseed_wait_retry;
224 // sets the upper limit on the total number of files this
225 // session will keep open. The reason why files are
226 // left open at all is that some anti virus software
227 // hooks on every file close, and scans the file for
228 // viruses. deferring the closing of the files will
229 // be the difference between a usable system and
230 // a completely hogged down system. Most operating
231 // systems also has a limit on the total number of
232 // file descriptors a process may have open. It is
233 // usually a good idea to find this limit and set the
234 // number of connections and the number of files
235 // limits so their sum is slightly below it.
236 int file_pool_size;
238 // false to not allow multiple connections from the same
239 // IP address. true will allow it.
240 bool allow_multiple_connections_per_ip;
242 // the number of times we can fail to connect to a peer
243 // before we stop retrying it.
244 int max_failcount;
246 // the number of seconds to wait to reconnect to a peer.
247 // this time is multiplied with the failcount.
248 int min_reconnect_time;
250 // this is the timeout for a connection attempt. If
251 // the connect does not succeed within this time, the
252 // connection is dropped. The time is specified in seconds.
253 int peer_connect_timeout;
255 // if set to true, upload, download and unchoke limits
256 // are ignored for peers on the local network.
257 bool ignore_limits_on_local_network;
259 // the number of connection attempts that
260 // are made per second.
261 int connection_speed;
263 // if this is set to true, have messages will be sent
264 // to peers that already have the piece. This is
265 // typically not necessary, but it might be necessary
266 // for collecting statistics in some cases. Default is false.
267 bool send_redundant_have;
269 // if this is true, outgoing bitfields will never be fuil. If the
270 // client is seed, a few bits will be set to 0, and later filled
271 // in with have messages. This is to prevent certain ISPs
272 // from stopping people from seeding.
273 bool lazy_bitfields;
275 // if a peer is uninteresting and uninterested for longer
276 // than this number of seconds, it will be disconnected.
277 // default is 10 minutes
278 int inactivity_timeout;
280 // the number of seconds between chokes/unchokes
281 int unchoke_interval;
283 // the number of unchoke intervals between
284 // optimistic unchokes
285 int optimistic_unchoke_multiplier;
287 // if this is set, this IP will be reported do the
288 // tracker in the ip= parameter.
289 address announce_ip;
291 // the num want sent to trackers
292 int num_want;
294 // while we have fewer pieces than this, pick
295 // random pieces instead of rarest first.
296 int initial_picker_threshold;
298 // the number of allowed pieces to send to peers
299 // that supports the fast extensions
300 int allowed_fast_set_size;
302 // the maximum number of bytes a connection may have
303 // pending in the disk write queue before its download
304 // rate is being throttled. This prevents fast downloads
305 // to slow medias to allocate more and more memory
306 // indefinitely. This should be set to at least 32 kB
307 // to not completely disrupt normal downloads.
308 int max_outstanding_disk_bytes_per_connection;
310 // the number of seconds to wait for a handshake
311 // response from a peer. If no response is received
312 // within this time, the peer is disconnected.
313 int handshake_timeout;
315 #ifndef TORRENT_DISABLE_DHT
316 // while this is true, the dht will note be used unless the
317 // tracker is online
318 bool use_dht_as_fallback;
319 #endif
321 // if this is true, the piece hashes will be freed, in order
322 // to save memory, once the torrent is seeding. This will
323 // make the get_torrent_info() function to return an incomplete
324 // torrent object that cannot be passed back to add_torrent()
325 bool free_torrent_hashes;
327 // when this is true, the upnp port mapper will ignore
328 // any upnp devices that don't have an address that matches
329 // our currently configured router.
330 bool upnp_ignore_nonrouters;
332 // if the send buffer has fewer bytes than this, we'll
333 // read another 16kB block onto it. If set too small,
334 // upload rate capacity will suffer. If set too high,
335 // memory will be wasted.
336 // The actual watermark may be lower than this in case
337 // the upload rate is low, this is the upper limit.
338 int send_buffer_watermark;
340 // if auto_upload_slots is true, and a global upload
341 // limit is set and the upload rate is less than 90%
342 // of the upload limit, on new slot is opened up. If
343 // the upload rate is >= upload limit for an extended
344 // period of time, one upload slot is closed. The
345 // upload slots are never automatically decreased below
346 // the manual settings, through max_uploads.
347 bool auto_upload_slots;
349 // if set to true, peers that participate in a failing
350 // piece is put in parole mode. i.e. They will only
351 // download whole pieces until they either fail or pass.
352 // they are taken out of parole mode as soon as they
353 // participate in a piece that passes.
354 bool use_parole_mode;
356 // the disk write cache, specified in 16 KiB blocks.
357 // default is 512 (= 8 MB)
358 int cache_size;
360 // the number of seconds a write cache entry sits
361 // idle in the cache before it's forcefully flushed
362 // to disk. Default is 60 seconds.
363 int cache_expiry;
365 // if != (0, 0), this is the range of ports that
366 // outgoing connections will be bound to. This
367 // is useful for users that have routers that
368 // allow QoS settings based on local port.
369 std::pair<int, int> outgoing_ports;
371 // the TOS byte of all peer traffic (including
372 // web seeds) is set to this value. The default
373 // is the QBSS scavenger service
374 // http://qbone.internet2.edu/qbss/
375 // For unmarked packets, set to 0
376 char peer_tos;
378 // for auto managed torrents, these are the limits
379 // they are subject to. If there are too many torrents
380 // some of the auto managed ones will be paused until
381 // some slots free up.
382 int active_downloads;
383 int active_seeds;
384 int active_limit;
386 // if this is true, torrents that don't have any significant
387 // transfers are not counted as active when determining which
388 // auto managed torrents to pause and resume
389 bool dont_count_slow_torrents;
391 // the number of seconds in between recalculating which
392 // torrents to activate and which ones to queue
393 int auto_manage_interval;
395 // when a seeding torrent reaches eaither the share ratio
396 // (bytes up / bytes down) or the seed time ratio
397 // (seconds as seed / seconds as downloader) or the seed
398 // time limit (seconds as seed) it is considered
399 // done, and it will leave room for other torrents
400 // the default value for share ratio is 2
401 // the default seed time ratio is 7, because that's a common
402 // asymmetry ratio on connections
403 float share_ratio_limit;
404 float seed_time_ratio_limit;
405 int seed_time_limit;
407 // the percentage of peers to disconnect every
408 // 90 seconds (if we're at the peer limit)
409 // defaults to 1/50:th
410 float peer_turnover;
412 // when we are connected to more than
413 // limit * peer_turnover_enable peers
414 // disconnect peer_turnover fraction
415 // of the peers
416 float peer_turnover_cutoff;
418 // if this is true (default) connections where both
419 // ends have no utility in keeping the connection open
420 // are closed. for instance if both ends have completed
421 // their downloads
422 bool close_redundant_connections;
424 // the number of seconds between scrapes of
425 // queued torrents (auto managed and paused)
426 int auto_scrape_interval;
428 // the minimum number of seconds between any
429 // automatic scrape (regardless of torrent)
430 int auto_scrape_min_interval;
432 // the max number of peers in the peer list
433 // per torrent. This is the peers we know
434 // about, not necessarily connected to.
435 int max_peerlist_size;
437 // any announce intervals reported from a tracker
438 // that is lower than this, will be clamped to this
439 // value. It's specified in seconds
440 int min_announce_interval;
442 // if true, partial pieces are picked before pieces
443 // that are more rare
444 bool prioritize_partial_pieces;
446 // the number of seconds a torrent is considered
447 // active after it was started, regardless of
448 // upload and download speed. This is so that
449 // newly started torrents are not considered
450 // inactive until they have a fair chance to
451 // start downloading.
452 int auto_manage_startup;
455 #ifndef TORRENT_DISABLE_DHT
456 struct dht_settings
458 dht_settings()
459 : max_peers_reply(50)
460 , search_branching(5)
461 , service_port(0)
462 , max_fail_count(20)
465 // the maximum number of peers to send in a
466 // reply to get_peers
467 int max_peers_reply;
469 // the number of simultanous "connections" when
470 // searching the DHT.
471 int search_branching;
473 // the listen port for the dht. This is a UDP port.
474 // zero means use the same as the tcp interface
475 int service_port;
477 // the maximum number of times a node can fail
478 // in a row before it is removed from the table.
479 int max_fail_count;
481 #endif
483 #ifndef TORRENT_DISABLE_ENCRYPTION
485 struct pe_settings
487 pe_settings()
488 : out_enc_policy(enabled)
489 , in_enc_policy(enabled)
490 , allowed_enc_level(both)
491 , prefer_rc4(false)
494 enum enc_policy
496 forced, // disallow non encrypted connections
497 enabled, // allow encrypted and non encrypted connections
498 disabled // disallow encrypted connections
501 enum enc_level
503 plaintext, // use only plaintext encryption
504 rc4, // use only rc4 encryption
505 both // allow both
508 enc_policy out_enc_policy;
509 enc_policy in_enc_policy;
511 enc_level allowed_enc_level;
512 // if the allowed encryption level is both, setting this to
513 // true will prefer rc4 if both methods are offered, plaintext
514 // otherwise
515 bool prefer_rc4;
517 #endif
521 #endif