2003-10-23 01:00:57 +02:00
|
|
|
/*
|
|
|
|
|
2014-02-23 20:12:25 +01:00
|
|
|
Copyright (c) 2006-2014, Arvid Norberg, Magnus Jonsson
|
2003-10-23 01:00:57 +02:00
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in
|
|
|
|
the documentation and/or other materials provided with the distribution.
|
|
|
|
* Neither the name of the author nor the names of its
|
|
|
|
contributors may be used to endorse or promote products derived
|
|
|
|
from this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <ctime>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <set>
|
2011-03-14 03:59:46 +01:00
|
|
|
#include <deque>
|
2003-10-25 03:31:06 +02:00
|
|
|
#include <cctype>
|
2003-10-27 16:43:33 +01:00
|
|
|
#include <algorithm>
|
2003-10-23 01:00:57 +02:00
|
|
|
|
2004-01-25 19:18:36 +01:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(push, 1)
|
|
|
|
#endif
|
|
|
|
|
2003-12-15 18:46:47 +01:00
|
|
|
#include <boost/limits.hpp>
|
2004-01-17 21:04:19 +01:00
|
|
|
#include <boost/bind.hpp>
|
2003-10-23 01:00:57 +02:00
|
|
|
|
2004-01-25 19:18:36 +01:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|
|
|
|
|
2008-09-22 01:19:58 +02:00
|
|
|
#include "libtorrent/extensions/ut_pex.hpp"
|
|
|
|
#include "libtorrent/extensions/ut_metadata.hpp"
|
2008-11-27 21:51:59 +01:00
|
|
|
#include "libtorrent/extensions/lt_trackers.hpp"
|
2008-09-22 01:19:58 +02:00
|
|
|
#include "libtorrent/extensions/smart_ban.hpp"
|
2003-10-23 01:00:57 +02:00
|
|
|
#include "libtorrent/peer_id.hpp"
|
|
|
|
#include "libtorrent/torrent_info.hpp"
|
2004-01-31 11:46:15 +01:00
|
|
|
#include "libtorrent/tracker_manager.hpp"
|
2003-10-23 01:00:57 +02:00
|
|
|
#include "libtorrent/bencode.hpp"
|
|
|
|
#include "libtorrent/hasher.hpp"
|
|
|
|
#include "libtorrent/entry.hpp"
|
|
|
|
#include "libtorrent/session.hpp"
|
2003-12-16 14:33:29 +01:00
|
|
|
#include "libtorrent/fingerprint.hpp"
|
2004-01-07 01:48:02 +01:00
|
|
|
#include "libtorrent/entry.hpp"
|
2004-01-18 20:12:18 +01:00
|
|
|
#include "libtorrent/alert_types.hpp"
|
2004-01-25 19:18:36 +01:00
|
|
|
#include "libtorrent/invariant_check.hpp"
|
2004-01-26 02:08:59 +01:00
|
|
|
#include "libtorrent/file.hpp"
|
2006-04-25 23:04:48 +02:00
|
|
|
#include "libtorrent/bt_peer_connection.hpp"
|
2005-07-06 02:58:23 +02:00
|
|
|
#include "libtorrent/ip_filter.hpp"
|
2006-04-25 23:04:48 +02:00
|
|
|
#include "libtorrent/socket.hpp"
|
2006-10-11 16:02:21 +02:00
|
|
|
#include "libtorrent/aux_/session_impl.hpp"
|
2014-08-26 06:51:09 +02:00
|
|
|
#include "libtorrent/aux_/session_call.hpp"
|
2006-08-01 17:27:08 +02:00
|
|
|
#include "libtorrent/kademlia/dht_tracker.hpp"
|
2009-06-13 12:45:07 +02:00
|
|
|
#include "libtorrent/natpmp.hpp"
|
|
|
|
#include "libtorrent/upnp.hpp"
|
2010-12-30 02:47:30 +01:00
|
|
|
#include "libtorrent/magnet_uri.hpp"
|
2003-10-23 01:00:57 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
#ifdef TORRENT_PROFILE_CALLS
|
|
|
|
#include <boost/unordered_map.hpp>
|
|
|
|
#endif
|
|
|
|
|
2006-04-25 23:04:48 +02:00
|
|
|
using boost::shared_ptr;
|
|
|
|
using boost::weak_ptr;
|
2006-10-11 16:02:21 +02:00
|
|
|
using libtorrent::aux::session_impl;
|
2004-10-14 03:17:04 +02:00
|
|
|
|
2006-10-11 16:02:21 +02:00
|
|
|
namespace libtorrent
|
|
|
|
{
|
|
|
|
|
2008-11-23 16:44:11 +01:00
|
|
|
TORRENT_EXPORT void TORRENT_LINK_TEST_NAME() {}
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
TORRENT_EXPORT void min_memory_usage(settings_pack& set)
|
2009-05-12 20:05:04 +02:00
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
// receive data directly into disk buffers
|
|
|
|
// this yields more system calls to read() and
|
|
|
|
// kqueue(), but saves RAM.
|
|
|
|
set.set_bool(settings_pack::contiguous_recv_buffer, false);
|
|
|
|
|
|
|
|
set.set_int(settings_pack::disk_io_write_mode, settings_pack::disable_os_cache);
|
|
|
|
set.set_int(settings_pack::disk_io_read_mode, settings_pack::disable_os_cache);
|
2011-01-23 19:00:52 +01:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
// keep 2 blocks outstanding when hashing
|
|
|
|
set.set_int(settings_pack::checking_mem_usage, 2);
|
2011-01-23 19:00:52 +01:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
// don't use any extra threads to do SHA-1 hashing
|
|
|
|
set.set_int(settings_pack::hashing_threads, 0);
|
|
|
|
set.set_int(settings_pack::network_threads, 0);
|
|
|
|
set.set_int(settings_pack::aio_threads, 1);
|
|
|
|
|
|
|
|
set.set_int(settings_pack::alert_queue_size, 100);
|
|
|
|
|
|
|
|
set.set_int(settings_pack::max_out_request_queue, 300);
|
|
|
|
set.set_int(settings_pack::max_allowed_in_request_queue, 100);
|
2013-09-18 08:50:49 +02:00
|
|
|
|
2009-05-12 20:05:04 +02:00
|
|
|
// setting this to a low limit, means more
|
|
|
|
// peers are more likely to request from the
|
|
|
|
// same piece. Which means fewer partial
|
|
|
|
// pieces and fewer entries in the partial
|
|
|
|
// piece list
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_int(settings_pack::whole_pieces_threshold, 2);
|
|
|
|
set.set_bool(settings_pack::use_parole_mode, false);
|
|
|
|
set.set_bool(settings_pack::prioritize_partial_pieces, true);
|
2009-05-12 20:05:04 +02:00
|
|
|
|
2011-01-22 02:36:57 +01:00
|
|
|
// connect to 5 peers per second
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_int(settings_pack::connection_speed, 5);
|
2011-01-22 02:36:57 +01:00
|
|
|
|
2009-05-22 08:32:39 +02:00
|
|
|
// be extra nice on the hard drive when running
|
|
|
|
// on embedded devices. This might slow down
|
|
|
|
// torrent checking
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_int(settings_pack::file_checks_delay_per_block, 5);
|
2009-05-22 08:32:39 +02:00
|
|
|
|
2009-05-12 20:05:04 +02:00
|
|
|
// only have 4 files open at a time
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_int(settings_pack::file_pool_size, 4);
|
2009-05-12 20:05:04 +02:00
|
|
|
|
|
|
|
// we want to keep the peer list as small as possible
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_bool(settings_pack::allow_multiple_connections_per_ip, false);
|
|
|
|
set.set_int(settings_pack::max_failcount, 2);
|
|
|
|
set.set_int(settings_pack::inactivity_timeout, 120);
|
2009-05-12 20:05:04 +02:00
|
|
|
|
|
|
|
// whenever a peer has downloaded one block, write
|
|
|
|
// it to disk, and don't read anything from the
|
|
|
|
// socket until the disk write is complete
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_int(settings_pack::max_queued_disk_bytes, 1);
|
2009-05-12 20:05:04 +02:00
|
|
|
|
|
|
|
// don't keep track of all upnp devices, keep
|
|
|
|
// the device list small
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_bool(settings_pack::upnp_ignore_nonrouters, true);
|
2009-05-12 20:05:04 +02:00
|
|
|
|
|
|
|
// never keep more than one 16kB block in
|
|
|
|
// the send buffer
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_int(settings_pack::send_buffer_watermark, 9);
|
2009-05-12 20:05:04 +02:00
|
|
|
|
|
|
|
// don't use any disk cache
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_int(settings_pack::cache_size, 0);
|
|
|
|
set.set_int(settings_pack::cache_buffer_chunk_size, 1);
|
|
|
|
set.set_bool(settings_pack::use_read_cache, false);
|
|
|
|
set.set_bool(settings_pack::use_disk_read_ahead, false);
|
2009-05-12 20:05:04 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_bool(settings_pack::close_redundant_connections, true);
|
2009-05-12 20:05:04 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_int(settings_pack::max_peerlist_size, 500);
|
|
|
|
set.set_int(settings_pack::max_paused_peerlist_size, 50);
|
2009-05-12 20:05:04 +02:00
|
|
|
|
|
|
|
// udp trackers are cheaper to talk to
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_bool(settings_pack::prefer_udp_trackers, true);
|
2009-05-12 20:05:04 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_int(settings_pack::max_rejects, 10);
|
2009-05-12 20:05:04 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_int(settings_pack::recv_socket_buffer_size, 16 * 1024);
|
|
|
|
set.set_int(settings_pack::send_socket_buffer_size, 16 * 1024);
|
2009-05-12 20:05:04 +02:00
|
|
|
|
|
|
|
// use less memory when reading and writing
|
|
|
|
// whole pieces
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_bool(settings_pack::coalesce_reads, false);
|
|
|
|
set.set_bool(settings_pack::coalesce_writes, false);
|
2009-05-12 20:05:04 +02:00
|
|
|
|
2010-11-29 02:33:05 +01:00
|
|
|
// disallow the buffer size to grow for the uTP socket
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_bool(settings_pack::utp_dynamic_sock_buf, false);
|
2009-05-12 20:05:04 +02:00
|
|
|
}
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
TORRENT_EXPORT void high_performance_seed(settings_pack& set)
|
2009-05-12 20:05:04 +02:00
|
|
|
{
|
2011-01-28 19:23:54 +01:00
|
|
|
// don't throttle TCP, assume there is
|
|
|
|
// plenty of bandwidth
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_int(settings_pack::mixed_mode_algorithm, settings_pack::prefer_tcp);
|
2011-01-28 19:23:54 +01:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_int(settings_pack::max_out_request_queue, 1500);
|
|
|
|
set.set_int(settings_pack::max_allowed_in_request_queue, 2000);
|
2013-09-18 08:50:49 +02:00
|
|
|
|
2011-03-13 05:46:33 +01:00
|
|
|
// we will probably see a high rate of alerts, make it less
|
|
|
|
// likely to loose alerts
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_int(settings_pack::alert_queue_size, 10000);
|
2011-01-23 19:00:52 +01:00
|
|
|
|
2009-05-27 08:37:45 +02:00
|
|
|
// allow 500 files open at a time
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_int(settings_pack::file_pool_size, 500);
|
2009-05-12 20:05:04 +02:00
|
|
|
|
2011-03-15 03:21:28 +01:00
|
|
|
// don't update access time for each read/write
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_bool(settings_pack::no_atime_storage, true);
|
2011-03-15 03:21:28 +01:00
|
|
|
|
2009-05-12 20:05:04 +02:00
|
|
|
// as a seed box, we must accept multiple peers behind
|
|
|
|
// the same NAT
|
2014-07-06 21:18:00 +02:00
|
|
|
// set.set_bool(settings_pack::allow_multiple_connections_per_ip, true);
|
2009-05-12 20:05:04 +02:00
|
|
|
|
2011-01-22 02:36:57 +01:00
|
|
|
// connect to 50 peers per second
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_int(settings_pack::connection_speed, 500);
|
2011-01-22 02:36:57 +01:00
|
|
|
|
2011-03-13 05:46:33 +01:00
|
|
|
// allow 8000 peer connections
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_int(settings_pack::connections_limit, 8000);
|
2011-03-13 05:46:33 +01:00
|
|
|
|
2011-04-27 10:06:44 +02:00
|
|
|
// allow lots of peers to try to connect simultaneously
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_int(settings_pack::listen_queue_size, 3000);
|
2011-04-27 10:06:44 +02:00
|
|
|
|
2011-03-13 05:46:33 +01:00
|
|
|
// unchoke many peers
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_int(settings_pack::unchoke_slots_limit, 2000);
|
2011-03-13 05:46:33 +01:00
|
|
|
|
2011-03-14 08:47:24 +01:00
|
|
|
// we need more DHT capacity to ping more peers
|
|
|
|
// candidates before trying to connect
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_int(settings_pack::dht_upload_rate_limit, 20000);
|
2011-03-24 01:50:45 +01:00
|
|
|
|
2010-01-15 17:45:42 +01:00
|
|
|
// use 1 GB of cache
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_int(settings_pack::cache_size, 32768 * 2);
|
|
|
|
set.set_bool(settings_pack::use_read_cache, true);
|
|
|
|
set.set_int(settings_pack::cache_buffer_chunk_size, 0);
|
|
|
|
set.set_int(settings_pack::read_cache_line_size, 32);
|
|
|
|
set.set_int(settings_pack::write_cache_line_size, 256);
|
|
|
|
set.set_bool(settings_pack::low_prio_disk, false);
|
|
|
|
// 30 seconds expiration to save cache
|
|
|
|
// space for active pieces
|
|
|
|
set.set_int(settings_pack::cache_expiry, 30);
|
2010-05-13 17:01:20 +02:00
|
|
|
// this is expensive and could add significant
|
|
|
|
// delays when freeing a large number of buffers
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_bool(settings_pack::lock_disk_cache, false);
|
|
|
|
|
|
|
|
// in case the OS we're running on doesn't support
|
|
|
|
// readv/writev, allocate contiguous buffers for
|
|
|
|
// reads and writes
|
|
|
|
// disable, since it uses a lot more RAM and a significant
|
|
|
|
// amount of CPU to copy it around
|
|
|
|
set.set_bool(settings_pack::coalesce_reads, false);
|
|
|
|
set.set_bool(settings_pack::coalesce_writes, false);
|
2009-05-12 20:05:04 +02:00
|
|
|
|
2011-01-22 02:36:57 +01:00
|
|
|
// the max number of bytes pending write before we throttle
|
|
|
|
// download rate
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_int(settings_pack::max_queued_disk_bytes, 7 * 1024 * 1024);
|
2010-01-15 17:45:42 +01:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_bool(settings_pack::explicit_read_cache, false);
|
2010-01-15 17:45:42 +01:00
|
|
|
// prevent fast pieces to interfere with suggested pieces
|
|
|
|
// since we unchoke everyone, we don't need fast pieces anyway
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_int(settings_pack::allowed_fast_set_size, 0);
|
2010-01-15 17:45:42 +01:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
// suggest pieces in the read cache for higher cache hit rate
|
|
|
|
set.set_int(settings_pack::suggest_mode, settings_pack::suggest_read_cache);
|
2009-05-12 20:05:04 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_bool(settings_pack::close_redundant_connections, true);
|
2009-05-12 20:05:04 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_int(settings_pack::max_rejects, 10);
|
2013-09-02 11:24:34 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_int(settings_pack::recv_socket_buffer_size, 1024 * 1024);
|
|
|
|
set.set_int(settings_pack::send_socket_buffer_size, 1024 * 1024);
|
2009-05-12 20:05:04 +02:00
|
|
|
|
2009-05-27 08:37:45 +02:00
|
|
|
// don't let connections linger for too long
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_int(settings_pack::request_timeout, 10);
|
|
|
|
set.set_int(settings_pack::peer_timeout, 20);
|
|
|
|
set.set_int(settings_pack::inactivity_timeout, 20);
|
2009-05-27 08:37:45 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_int(settings_pack::active_limit, 2000);
|
|
|
|
set.set_int(settings_pack::active_tracker_limit, 2000);
|
|
|
|
set.set_int(settings_pack::active_dht_limit, 600);
|
|
|
|
set.set_int(settings_pack::active_seeds, 2000);
|
2009-05-27 08:37:45 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_int(settings_pack::choking_algorithm, settings_pack::fixed_slots_choker);
|
2009-05-27 08:37:45 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
// of 500 ms, and a send rate of 4 MB/s, the upper
|
|
|
|
// limit should be 2 MB
|
|
|
|
set.set_int(settings_pack::send_buffer_watermark, 3 * 1024 * 1024);
|
2009-08-17 19:33:57 +02:00
|
|
|
|
2011-09-23 23:12:28 +02:00
|
|
|
// put 1.5 seconds worth of data in the send buffer
|
2010-03-12 03:36:55 +01:00
|
|
|
// this gives the disk I/O more heads-up on disk
|
|
|
|
// reads, and can maximize throughput
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_int(settings_pack::send_buffer_watermark_factor, 150);
|
2010-03-12 03:36:55 +01:00
|
|
|
|
2012-03-07 03:59:50 +01:00
|
|
|
// always stuff at least 1 MiB down each peer
|
|
|
|
// pipe, to quickly ramp up send rates
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_int(settings_pack::send_buffer_low_watermark, 1 * 1024 * 1024);
|
2012-03-07 03:59:50 +01:00
|
|
|
|
2009-05-27 08:37:45 +02:00
|
|
|
// don't retry peers if they fail once. Let them
|
|
|
|
// connect to us if they want to
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_int(settings_pack::max_failcount, 1);
|
2009-05-27 08:37:45 +02:00
|
|
|
|
2010-11-29 02:33:05 +01:00
|
|
|
// allow the buffer size to grow for the uTP socket
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_bool(settings_pack::utp_dynamic_sock_buf, true);
|
|
|
|
|
|
|
|
// we're likely to have more than 4 cores on a high
|
|
|
|
// performance machine. One core is needed for the
|
|
|
|
// network thread
|
|
|
|
set.set_int(settings_pack::hashing_threads, 4);
|
|
|
|
|
|
|
|
// the number of threads to use to call async_write_some
|
|
|
|
// and read_some on peer sockets
|
|
|
|
// this doesn't work. See comment in settings_pack.cpp
|
|
|
|
set.set_int(settings_pack::network_threads, 0);
|
|
|
|
|
|
|
|
// number of disk threads for low level file operations
|
|
|
|
set.set_int(settings_pack::aio_threads, 8);
|
2010-11-29 02:33:05 +01:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
// keep 5 MiB outstanding when checking hashes
|
|
|
|
// of a resumed file
|
|
|
|
set.set_int(settings_pack::checking_mem_usage, 320);
|
2012-10-19 03:28:47 +02:00
|
|
|
|
2013-03-21 02:18:39 +01:00
|
|
|
// the disk cache performs better with the pool allocator
|
2014-07-06 21:18:00 +02:00
|
|
|
set.set_bool(settings_pack::use_disk_cache_pool, true);
|
|
|
|
}
|
2013-03-21 02:18:39 +01:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
|
|
|
// this function returns a session_settings object
|
|
|
|
// which will optimize libtorrent for minimum memory
|
|
|
|
// usage, with no consideration of performance.
|
|
|
|
TORRENT_EXPORT session_settings min_memory_usage()
|
|
|
|
{
|
|
|
|
aux::session_settings def;
|
|
|
|
initialize_default_settings(def);
|
|
|
|
settings_pack pack;
|
|
|
|
min_memory_usage(pack);
|
|
|
|
apply_pack(&pack, def, 0);
|
|
|
|
session_settings ret;
|
|
|
|
load_struct_from_settings(def, ret);
|
|
|
|
return ret;
|
2009-05-12 20:05:04 +02:00
|
|
|
}
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
TORRENT_EXPORT session_settings high_performance_seed()
|
|
|
|
{
|
|
|
|
aux::session_settings def;
|
|
|
|
initialize_default_settings(def);
|
|
|
|
settings_pack pack;
|
|
|
|
high_performance_seed(pack);
|
|
|
|
apply_pack(&pack, def, 0);
|
|
|
|
session_settings ret;
|
|
|
|
load_struct_from_settings(def, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-07-14 06:16:38 +02:00
|
|
|
#define TORRENT_ASYNC_CALL(x) \
|
2013-07-25 05:02:06 +02:00
|
|
|
m_impl->m_io_service.dispatch(boost::bind(&session_impl:: x, m_impl.get()))
|
2010-07-14 06:16:38 +02:00
|
|
|
|
|
|
|
#define TORRENT_ASYNC_CALL1(x, a1) \
|
2013-07-25 05:02:06 +02:00
|
|
|
m_impl->m_io_service.dispatch(boost::bind(&session_impl:: x, m_impl.get(), a1))
|
2010-07-14 06:16:38 +02:00
|
|
|
|
|
|
|
#define TORRENT_ASYNC_CALL2(x, a1, a2) \
|
2013-07-25 05:02:06 +02:00
|
|
|
m_impl->m_io_service.dispatch(boost::bind(&session_impl:: x, m_impl.get(), a1, a2))
|
2010-07-14 06:16:38 +02:00
|
|
|
|
2014-02-24 01:31:13 +01:00
|
|
|
#define TORRENT_ASYNC_CALL3(x, a1, a2, a3) \
|
|
|
|
m_impl->m_io_service.dispatch(boost::bind(&session_impl:: x, m_impl.get(), a1, a2, a3))
|
|
|
|
|
2010-07-14 06:16:38 +02:00
|
|
|
#define TORRENT_SYNC_CALL(x) \
|
2014-08-26 06:51:09 +02:00
|
|
|
aux::sync_call(*m_impl, boost::function<void(void)>(boost::bind(&session_impl:: x, m_impl.get())))
|
2010-07-14 06:16:38 +02:00
|
|
|
|
|
|
|
#define TORRENT_SYNC_CALL1(x, a1) \
|
2014-08-26 06:51:09 +02:00
|
|
|
aux::sync_call(*m_impl, boost::function<void(void)>(boost::bind(&session_impl:: x, m_impl.get(), a1)))
|
2010-07-14 06:16:38 +02:00
|
|
|
|
|
|
|
#define TORRENT_SYNC_CALL2(x, a1, a2) \
|
2014-08-26 06:51:09 +02:00
|
|
|
aux::sync_call(*m_impl, boost::function<void(void)>(boost::bind(&session_impl:: x, m_impl.get(), a1, a2)))
|
2010-07-14 06:16:38 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
#define TORRENT_SYNC_CALL3(x, a1, a2, a3) \
|
2014-08-26 06:51:09 +02:00
|
|
|
aux::sync_call(*m_impl, boost::function<void(void)>(boost::bind(&session_impl:: x, m_impl.get(), a1, a2, a3)))
|
2011-02-01 10:48:28 +01:00
|
|
|
|
2011-02-16 07:35:53 +01:00
|
|
|
#define TORRENT_SYNC_CALL4(x, a1, a2, a3, a4) \
|
2014-08-26 06:51:09 +02:00
|
|
|
aux::sync_call(*m_impl, boost::function<void(void)>(boost::bind(&session_impl:: x, m_impl.get(), a1, a2, a3, a4)))
|
2011-02-16 07:35:53 +01:00
|
|
|
|
2010-07-14 06:16:38 +02:00
|
|
|
#define TORRENT_SYNC_CALL_RET(type, x) \
|
2014-08-26 06:51:09 +02:00
|
|
|
aux::sync_call_ret<type>(*m_impl, boost::function<type(void)>(boost::bind(&session_impl:: x, m_impl.get())))
|
2010-07-14 06:16:38 +02:00
|
|
|
|
|
|
|
#define TORRENT_SYNC_CALL_RET1(type, x, a1) \
|
2014-08-26 06:51:09 +02:00
|
|
|
aux::sync_call_ret<type>(*m_impl, boost::function<type(void)>(boost::bind(&session_impl:: x, m_impl.get(), a1)))
|
2010-07-14 06:16:38 +02:00
|
|
|
|
|
|
|
#define TORRENT_SYNC_CALL_RET2(type, x, a1, a2) \
|
2014-08-26 06:51:09 +02:00
|
|
|
aux::sync_call_ret<type>(*m_impl, boost::function<type(void)>(boost::bind(&session_impl:: x, m_impl.get(), a1, a2)))
|
2010-07-14 06:16:38 +02:00
|
|
|
|
|
|
|
#define TORRENT_SYNC_CALL_RET3(type, x, a1, a2, a3) \
|
2014-08-26 06:51:09 +02:00
|
|
|
aux::sync_call_ret<type>(*m_impl, boost::function<type(void)>(boost::bind(&session_impl:: x, m_impl.get(), a1, a2, a3)))
|
2010-07-14 06:16:38 +02:00
|
|
|
|
2012-03-19 03:43:06 +01:00
|
|
|
#ifndef TORRENT_CFG
|
|
|
|
#error TORRENT_CFG is not defined!
|
|
|
|
#endif
|
|
|
|
|
2010-10-24 02:44:07 +02:00
|
|
|
// this is a dummy function that's exported and named based
|
|
|
|
// on the configuration. The session.hpp file will reference
|
|
|
|
// it and if the library and the client are built with different
|
|
|
|
// configurations this will give a link error
|
|
|
|
void TORRENT_EXPORT TORRENT_CFG() {}
|
|
|
|
|
2013-07-19 21:06:27 +02:00
|
|
|
#if defined _MSC_VER && defined TORRENT_DEBUG
|
|
|
|
static void straight_to_debugger(unsigned int, _EXCEPTION_POINTERS*)
|
|
|
|
{ throw; }
|
|
|
|
#endif
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
void session::init(fingerprint const& id)
|
2006-10-11 16:02:21 +02:00
|
|
|
{
|
2013-07-19 21:06:27 +02:00
|
|
|
#if defined _MSC_VER && defined TORRENT_DEBUG
|
|
|
|
// workaround for microsofts
|
|
|
|
// hardware exceptions that makes
|
|
|
|
// it hard to debug stuff
|
|
|
|
::_set_se_translator(straight_to_debugger);
|
|
|
|
#endif
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
m_impl.reset(new session_impl(id));
|
2013-03-10 10:19:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void session::set_log_path(std::string const& p)
|
|
|
|
{
|
2013-12-02 11:00:03 +01:00
|
|
|
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING \
|
|
|
|
|| defined TORRENT_ERROR_LOGGING
|
2013-03-10 10:19:58 +01:00
|
|
|
m_impl->set_log_path(p);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
void session::start(int flags, settings_pack const& pack)
|
2013-03-10 10:19:58 +01:00
|
|
|
{
|
2008-09-22 01:19:58 +02:00
|
|
|
#ifndef TORRENT_DISABLE_EXTENSIONS
|
|
|
|
if (flags & add_default_plugins)
|
|
|
|
{
|
|
|
|
add_extension(create_ut_pex_plugin);
|
|
|
|
add_extension(create_ut_metadata_plugin);
|
2008-11-27 21:51:59 +01:00
|
|
|
add_extension(create_lt_trackers_plugin);
|
2008-09-22 01:19:58 +02:00
|
|
|
add_extension(create_smart_ban_plugin);
|
|
|
|
}
|
|
|
|
#endif
|
2010-12-05 22:08:19 +01:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
m_impl->start_session(pack);
|
2006-10-11 16:02:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
session::~session()
|
|
|
|
{
|
2014-08-26 06:51:09 +02:00
|
|
|
aux::dump_call_profile();
|
2014-07-06 21:18:00 +02:00
|
|
|
|
2007-10-05 02:30:00 +02:00
|
|
|
TORRENT_ASSERT(m_impl);
|
2006-10-11 16:02:21 +02:00
|
|
|
// if there is at least one destruction-proxy
|
|
|
|
// abort the session and let the destructor
|
|
|
|
// of the proxy to syncronize
|
|
|
|
if (!m_impl.unique())
|
2010-07-14 06:16:38 +02:00
|
|
|
{
|
|
|
|
TORRENT_ASYNC_CALL(abort);
|
|
|
|
}
|
2006-10-11 16:02:21 +02:00
|
|
|
}
|
|
|
|
|
2010-03-06 08:49:40 +01:00
|
|
|
void session::save_state(entry& e, boost::uint32_t flags) const
|
2009-12-03 06:11:57 +01:00
|
|
|
{
|
2010-07-14 06:16:38 +02:00
|
|
|
TORRENT_SYNC_CALL2(save_state, &e, flags);
|
2009-12-03 06:11:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void session::load_state(lazy_entry const& e)
|
|
|
|
{
|
2010-07-14 06:16:38 +02:00
|
|
|
// this needs to be synchronized since the lifespan
|
|
|
|
// of e is tied to the caller
|
|
|
|
TORRENT_SYNC_CALL1(load_state, &e);
|
2009-12-03 06:11:57 +01:00
|
|
|
}
|
|
|
|
|
2011-01-18 04:41:54 +01:00
|
|
|
feed_handle session::add_feed(feed_settings const& feed)
|
|
|
|
{
|
|
|
|
// if you have auto-download enabled, you must specify a download directory!
|
2014-03-23 08:40:43 +01:00
|
|
|
TORRENT_ASSERT_PRECOND(!feed.auto_download || !feed.add_args.save_path.empty());
|
2014-08-26 06:51:09 +02:00
|
|
|
return TORRENT_SYNC_CALL_RET1(feed_handle, add_feed, feed);
|
2011-01-18 04:41:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void session::remove_feed(feed_handle h)
|
|
|
|
{
|
|
|
|
TORRENT_ASYNC_CALL1(remove_feed, h);
|
|
|
|
}
|
|
|
|
|
|
|
|
void session::get_feeds(std::vector<feed_handle>& f) const
|
|
|
|
{
|
|
|
|
f.clear();
|
|
|
|
TORRENT_SYNC_CALL1(get_feeds, &f);
|
|
|
|
}
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
void session::set_load_function(user_load_function_t fun)
|
|
|
|
{
|
|
|
|
TORRENT_ASYNC_CALL1(set_load_function, fun);
|
|
|
|
}
|
|
|
|
|
2007-09-14 02:11:33 +02:00
|
|
|
void session::add_extension(boost::function<boost::shared_ptr<torrent_plugin>(torrent*, void*)> ext)
|
2006-10-11 16:02:21 +02:00
|
|
|
{
|
2013-04-09 04:38:11 +02:00
|
|
|
#ifndef TORRENT_DISABLE_EXTENSIONS
|
2010-07-14 06:16:38 +02:00
|
|
|
TORRENT_ASYNC_CALL1(add_extension, ext);
|
2013-04-09 04:38:11 +02:00
|
|
|
#endif
|
2006-10-11 16:02:21 +02:00
|
|
|
}
|
2011-01-29 11:37:21 +01:00
|
|
|
|
|
|
|
void session::add_extension(boost::shared_ptr<plugin> ext)
|
|
|
|
{
|
2013-04-09 04:38:11 +02:00
|
|
|
#ifndef TORRENT_DISABLE_EXTENSIONS
|
2011-01-29 11:37:21 +01:00
|
|
|
TORRENT_ASYNC_CALL1(add_ses_extension, ext);
|
2008-09-22 01:19:58 +02:00
|
|
|
#endif
|
2013-04-09 04:38:11 +02:00
|
|
|
}
|
2006-10-11 16:02:21 +02:00
|
|
|
|
2014-09-21 23:01:48 +02:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
|
|
|
void session::load_asnum_db(char const* file) {}
|
|
|
|
void session::load_country_db(char const* file) {}
|
2008-04-22 02:05:23 +02:00
|
|
|
|
|
|
|
int session::as_for_ip(address const& addr)
|
2014-09-21 23:01:48 +02:00
|
|
|
{ return 0; }
|
2008-04-22 02:05:23 +02:00
|
|
|
|
2009-10-29 19:12:43 +01:00
|
|
|
#if TORRENT_USE_WSTRING
|
2014-09-21 23:01:48 +02:00
|
|
|
void session::load_asnum_db(wchar_t const* file) {}
|
|
|
|
void session::load_country_db(wchar_t const* file) {}
|
2009-10-29 19:12:43 +01:00
|
|
|
#endif // TORRENT_USE_WSTRING
|
2008-04-05 06:53:22 +02:00
|
|
|
|
|
|
|
void session::load_state(entry const& ses_state)
|
|
|
|
{
|
2011-06-05 08:42:51 +02:00
|
|
|
if (ses_state.type() == entry::undefined_t) return;
|
2010-03-04 17:42:39 +01:00
|
|
|
std::vector<char> buf;
|
|
|
|
bencode(std::back_inserter(buf), ses_state);
|
|
|
|
lazy_entry e;
|
2010-10-28 06:01:59 +02:00
|
|
|
error_code ec;
|
2013-06-14 23:11:28 +02:00
|
|
|
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS || !defined BOOST_NO_EXCEPTIONS
|
2013-06-14 18:41:47 +02:00
|
|
|
int ret =
|
|
|
|
#endif
|
|
|
|
lazy_bdecode(&buf[0], &buf[0] + buf.size(), e, ec);
|
|
|
|
|
2011-02-21 06:24:41 +01:00
|
|
|
TORRENT_ASSERT(ret == 0);
|
2012-06-25 16:17:51 +02:00
|
|
|
#ifndef BOOST_NO_EXCEPTIONS
|
|
|
|
if (ret != 0) throw libtorrent_exception(ec);
|
|
|
|
#endif
|
2010-07-14 06:16:38 +02:00
|
|
|
TORRENT_SYNC_CALL1(load_state, &e);
|
2008-04-05 06:53:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
entry session::state() const
|
|
|
|
{
|
2010-03-04 17:42:39 +01:00
|
|
|
entry ret;
|
2010-07-14 06:16:38 +02:00
|
|
|
TORRENT_SYNC_CALL2(save_state, &ret, 0xffffffff);
|
2010-03-04 17:42:39 +01:00
|
|
|
return ret;
|
2008-04-05 06:53:22 +02:00
|
|
|
}
|
2014-09-21 23:01:48 +02:00
|
|
|
#endif // TORRENT_NO_DEPRECATE
|
2008-04-05 06:53:22 +02:00
|
|
|
|
2006-10-11 16:02:21 +02:00
|
|
|
void session::set_ip_filter(ip_filter const& f)
|
|
|
|
{
|
2010-07-14 06:16:38 +02:00
|
|
|
TORRENT_ASYNC_CALL1(set_ip_filter, f);
|
2006-10-11 16:02:21 +02:00
|
|
|
}
|
2009-07-21 03:52:37 +02:00
|
|
|
|
2010-07-14 06:16:38 +02:00
|
|
|
ip_filter session::get_ip_filter() const
|
2009-07-21 03:52:37 +02:00
|
|
|
{
|
2014-08-26 06:51:09 +02:00
|
|
|
return TORRENT_SYNC_CALL_RET(ip_filter, get_ip_filter);
|
2009-07-21 03:52:37 +02:00
|
|
|
}
|
2006-10-11 16:02:21 +02:00
|
|
|
|
2007-06-01 03:05:57 +02:00
|
|
|
void session::set_port_filter(port_filter const& f)
|
|
|
|
{
|
2010-07-14 06:16:38 +02:00
|
|
|
TORRENT_ASYNC_CALL1(set_port_filter, f);
|
2007-06-01 03:05:57 +02:00
|
|
|
}
|
|
|
|
|
2006-10-11 16:02:21 +02:00
|
|
|
void session::set_peer_id(peer_id const& id)
|
|
|
|
{
|
2010-07-14 06:16:38 +02:00
|
|
|
TORRENT_ASYNC_CALL1(set_peer_id, id);
|
2006-10-11 16:02:21 +02:00
|
|
|
}
|
2007-06-09 01:02:31 +02:00
|
|
|
|
|
|
|
peer_id session::id() const
|
|
|
|
{
|
2014-08-26 06:51:09 +02:00
|
|
|
return TORRENT_SYNC_CALL_RET(peer_id, get_peer_id);
|
2007-06-09 01:02:31 +02:00
|
|
|
}
|
2006-10-11 16:02:21 +02:00
|
|
|
|
2009-03-17 10:34:44 +01:00
|
|
|
io_service& session::get_io_service()
|
|
|
|
{
|
|
|
|
return m_impl->m_io_service;
|
|
|
|
}
|
|
|
|
|
2006-10-11 16:02:21 +02:00
|
|
|
void session::set_key(int key)
|
|
|
|
{
|
2010-07-14 06:16:38 +02:00
|
|
|
TORRENT_ASYNC_CALL1(set_key, key);
|
2006-10-11 16:02:21 +02:00
|
|
|
}
|
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
void session::get_torrent_status(std::vector<torrent_status>* ret
|
|
|
|
, boost::function<bool(torrent_status const&)> const& pred
|
|
|
|
, boost::uint32_t flags) const
|
|
|
|
{
|
|
|
|
TORRENT_SYNC_CALL3(get_torrent_status, ret, boost::ref(pred), flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void session::refresh_torrent_status(std::vector<torrent_status>* ret
|
|
|
|
, boost::uint32_t flags) const
|
|
|
|
{
|
|
|
|
TORRENT_SYNC_CALL2(refresh_torrent_status, ret, flags);
|
|
|
|
}
|
|
|
|
|
2011-11-15 03:34:00 +01:00
|
|
|
void session::post_torrent_updates()
|
|
|
|
{
|
|
|
|
TORRENT_ASYNC_CALL(post_torrent_updates);
|
|
|
|
}
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
std::vector<stats_metric> session_stats_metrics()
|
|
|
|
{
|
|
|
|
std::vector<stats_metric> ret;
|
|
|
|
// defined in session_stats.cpp
|
|
|
|
extern void get_stats_metric_map(std::vector<stats_metric>& stats);
|
|
|
|
get_stats_metric_map(ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void session::post_session_stats()
|
|
|
|
{
|
|
|
|
TORRENT_ASYNC_CALL(post_session_stats);
|
|
|
|
}
|
|
|
|
|
2006-10-11 16:02:21 +02:00
|
|
|
std::vector<torrent_handle> session::get_torrents() const
|
|
|
|
{
|
2014-08-26 06:51:09 +02:00
|
|
|
return TORRENT_SYNC_CALL_RET(std::vector<torrent_handle>, get_torrents);
|
2006-10-11 16:02:21 +02:00
|
|
|
}
|
2006-11-14 01:08:16 +01:00
|
|
|
|
|
|
|
torrent_handle session::find_torrent(sha1_hash const& info_hash) const
|
|
|
|
{
|
2014-08-26 06:51:09 +02:00
|
|
|
return TORRENT_SYNC_CALL_RET1(torrent_handle, find_torrent_handle, info_hash);
|
2006-11-14 01:08:16 +01:00
|
|
|
}
|
|
|
|
|
2009-02-23 02:21:19 +01:00
|
|
|
#ifndef BOOST_NO_EXCEPTIONS
|
2008-04-24 05:28:48 +02:00
|
|
|
torrent_handle session::add_torrent(add_torrent_params const& params)
|
|
|
|
{
|
2009-02-23 02:21:19 +01:00
|
|
|
error_code ec;
|
2014-08-26 06:51:09 +02:00
|
|
|
torrent_handle r = TORRENT_SYNC_CALL_RET2(torrent_handle, add_torrent, params, boost::ref(ec));
|
2009-02-23 02:21:19 +01:00
|
|
|
if (ec) throw libtorrent_exception(ec);
|
2010-07-14 06:16:38 +02:00
|
|
|
return r;
|
2009-02-23 02:21:19 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
torrent_handle session::add_torrent(add_torrent_params const& params, error_code& ec)
|
|
|
|
{
|
2011-01-19 11:07:51 +01:00
|
|
|
ec.clear();
|
2014-08-26 06:51:09 +02:00
|
|
|
return TORRENT_SYNC_CALL_RET2(torrent_handle, add_torrent, params, boost::ref(ec));
|
2008-04-24 05:28:48 +02:00
|
|
|
}
|
2006-10-11 16:02:21 +02:00
|
|
|
|
2011-10-12 12:27:17 +02:00
|
|
|
void session::async_add_torrent(add_torrent_params const& params)
|
|
|
|
{
|
|
|
|
add_torrent_params* p = new add_torrent_params(params);
|
2013-09-11 01:35:37 +02:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
|
|
|
if (params.tracker_url)
|
|
|
|
{
|
|
|
|
p->trackers.push_back(params.tracker_url);
|
|
|
|
p->tracker_url = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
2011-10-12 12:27:17 +02:00
|
|
|
TORRENT_ASYNC_CALL1(async_add_torrent, p);
|
|
|
|
}
|
|
|
|
|
2009-02-26 08:09:56 +01:00
|
|
|
#ifndef BOOST_NO_EXCEPTIONS
|
2008-08-03 17:14:08 +02:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2006-10-11 16:02:21 +02:00
|
|
|
// if the torrent already exists, this will throw duplicate_torrent
|
|
|
|
torrent_handle session::add_torrent(
|
|
|
|
torrent_info const& ti
|
2009-10-26 02:29:39 +01:00
|
|
|
, std::string const& save_path
|
2006-10-11 16:02:21 +02:00
|
|
|
, entry const& resume_data
|
2007-10-08 22:01:36 +02:00
|
|
|
, storage_mode_t storage_mode
|
2007-08-22 07:31:42 +02:00
|
|
|
, bool paused
|
2007-03-16 06:29:23 +01:00
|
|
|
, storage_constructor_type sc)
|
2007-09-01 05:00:31 +02:00
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
boost::shared_ptr<torrent_info> tip(boost::make_shared<torrent_info>(ti));
|
2008-04-24 05:28:48 +02:00
|
|
|
add_torrent_params p(sc);
|
|
|
|
p.ti = tip;
|
|
|
|
p.save_path = save_path;
|
2008-07-01 01:14:31 +02:00
|
|
|
if (resume_data.type() != entry::undefined_t)
|
|
|
|
{
|
2013-07-17 22:21:48 +02:00
|
|
|
bencode(std::back_inserter(p.resume_data), resume_data);
|
2008-07-01 01:14:31 +02:00
|
|
|
}
|
2008-04-24 05:28:48 +02:00
|
|
|
p.storage_mode = storage_mode;
|
|
|
|
p.paused = paused;
|
2009-02-23 02:21:19 +01:00
|
|
|
return add_torrent(p);
|
2007-09-01 05:00:31 +02:00
|
|
|
}
|
|
|
|
|
2006-10-11 16:02:21 +02:00
|
|
|
torrent_handle session::add_torrent(
|
|
|
|
char const* tracker_url
|
|
|
|
, sha1_hash const& info_hash
|
2006-11-14 01:08:16 +01:00
|
|
|
, char const* name
|
2009-10-26 02:29:39 +01:00
|
|
|
, std::string const& save_path
|
2006-10-11 16:02:21 +02:00
|
|
|
, entry const& e
|
2007-10-08 22:01:36 +02:00
|
|
|
, storage_mode_t storage_mode
|
2007-08-22 07:31:42 +02:00
|
|
|
, bool paused
|
2007-09-14 02:11:33 +02:00
|
|
|
, storage_constructor_type sc
|
|
|
|
, void* userdata)
|
2006-10-11 16:02:21 +02:00
|
|
|
{
|
2008-04-24 05:28:48 +02:00
|
|
|
add_torrent_params p(sc);
|
|
|
|
p.tracker_url = tracker_url;
|
|
|
|
p.info_hash = info_hash;
|
|
|
|
p.save_path = save_path;
|
|
|
|
p.paused = paused;
|
|
|
|
p.userdata = userdata;
|
2009-02-23 02:21:19 +01:00
|
|
|
return add_torrent(p);
|
2006-10-11 16:02:21 +02:00
|
|
|
}
|
2009-06-13 06:09:54 +02:00
|
|
|
#endif // TORRENT_NO_DEPRECATE
|
|
|
|
#endif // BOOST_NO_EXCEPTIONS
|
2006-10-11 16:02:21 +02:00
|
|
|
|
2007-10-13 05:33:33 +02:00
|
|
|
void session::remove_torrent(const torrent_handle& h, int options)
|
2006-10-11 16:02:21 +02:00
|
|
|
{
|
2011-06-21 04:02:58 +02:00
|
|
|
if (!h.is_valid())
|
|
|
|
#ifdef BOOST_NO_EXCEPTIONS
|
|
|
|
return;
|
|
|
|
#else
|
|
|
|
throw_invalid_handle();
|
|
|
|
#endif
|
2010-07-14 06:16:38 +02:00
|
|
|
TORRENT_ASYNC_CALL2(remove_torrent, h, options);
|
2006-10-11 16:02:21 +02:00
|
|
|
}
|
|
|
|
|
2011-02-16 07:35:53 +01:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2014-07-06 21:18:00 +02:00
|
|
|
void session::listen_on(
|
2006-10-11 16:02:21 +02:00
|
|
|
std::pair<int, int> const& port_range
|
2014-07-06 21:18:00 +02:00
|
|
|
, error_code& ec
|
2010-06-17 19:14:56 +02:00
|
|
|
, const char* net_interface, int flags)
|
2006-10-11 16:02:21 +02:00
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
settings_pack p;
|
|
|
|
std::string interfaces_str;
|
|
|
|
if (net_interface == NULL || strlen(net_interface) == 0)
|
|
|
|
net_interface = "0.0.0.0";
|
|
|
|
|
|
|
|
interfaces_str = print_endpoint(tcp::endpoint(address::from_string(net_interface, ec), port_range.first));
|
|
|
|
if (ec) return;
|
|
|
|
|
|
|
|
p.set_str(settings_pack::listen_interfaces, interfaces_str);
|
|
|
|
p.set_int(settings_pack::max_retry_port_bind, port_range.second - port_range.first);
|
|
|
|
p.set_bool(settings_pack::listen_system_port_fallback, (flags & session::listen_no_system_port) == 0);
|
|
|
|
apply_settings(p);
|
2011-02-16 07:35:53 +01:00
|
|
|
}
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
void session::use_interfaces(char const* interfaces)
|
2011-02-16 07:35:53 +01:00
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
settings_pack pack;
|
|
|
|
pack.set_str(settings_pack::outgoing_interfaces, interfaces);
|
|
|
|
apply_settings(pack);
|
2006-10-11 16:02:21 +02:00
|
|
|
}
|
2014-07-06 21:18:00 +02:00
|
|
|
#endif
|
2006-10-11 16:02:21 +02:00
|
|
|
|
|
|
|
unsigned short session::listen_port() const
|
|
|
|
{
|
2014-08-26 06:51:09 +02:00
|
|
|
return TORRENT_SYNC_CALL_RET(unsigned short, listen_port);
|
2006-10-11 16:02:21 +02:00
|
|
|
}
|
|
|
|
|
2013-07-28 17:06:28 +02:00
|
|
|
unsigned short session::ssl_listen_port() const
|
|
|
|
{
|
2014-08-26 06:51:09 +02:00
|
|
|
return TORRENT_SYNC_CALL_RET(unsigned short, ssl_listen_port);
|
2013-07-28 17:06:28 +02:00
|
|
|
}
|
|
|
|
|
2006-10-11 16:02:21 +02:00
|
|
|
session_status session::status() const
|
|
|
|
{
|
2014-08-26 06:51:09 +02:00
|
|
|
return TORRENT_SYNC_CALL_RET(session_status, status);
|
2006-10-11 16:02:21 +02:00
|
|
|
}
|
|
|
|
|
2009-05-23 23:36:09 +02:00
|
|
|
void session::pause()
|
|
|
|
{
|
2010-07-14 06:16:38 +02:00
|
|
|
TORRENT_ASYNC_CALL(pause);
|
2009-05-23 23:36:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void session::resume()
|
|
|
|
{
|
2010-07-14 06:16:38 +02:00
|
|
|
TORRENT_ASYNC_CALL(resume);
|
2009-05-23 23:36:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool session::is_paused() const
|
|
|
|
{
|
2014-08-26 06:51:09 +02:00
|
|
|
return TORRENT_SYNC_CALL_RET(bool, is_paused);
|
2009-05-23 23:36:09 +02:00
|
|
|
}
|
2008-06-29 21:08:30 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2008-02-08 11:22:05 +01:00
|
|
|
void session::get_cache_info(sha1_hash const& ih
|
|
|
|
, std::vector<cached_piece_info>& ret) const
|
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
cache_status st;
|
|
|
|
get_cache_info(&st, find_torrent(ih));
|
|
|
|
ret.swap(st.pieces);
|
2008-02-08 11:22:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cache_status session::get_cache_status() const
|
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
cache_status st;
|
|
|
|
get_cache_info(&st);
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void session::get_cache_info(cache_status* ret
|
|
|
|
, torrent_handle h, int flags) const
|
|
|
|
{
|
|
|
|
piece_manager* st = 0;
|
|
|
|
boost::shared_ptr<torrent> t = h.m_torrent.lock();
|
|
|
|
if (t)
|
|
|
|
{
|
|
|
|
if (t->has_storage())
|
|
|
|
st = &t->storage();
|
|
|
|
else
|
|
|
|
flags = session::disk_cache_no_pieces;
|
|
|
|
}
|
|
|
|
m_impl->m_disk_thread.get_cache_info(ret, flags & session::disk_cache_no_pieces, st);
|
2008-02-08 11:22:05 +01:00
|
|
|
}
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2010-03-04 17:42:39 +01:00
|
|
|
void session::start_dht()
|
2006-10-11 16:02:21 +02:00
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
settings_pack p;
|
|
|
|
p.set_bool(settings_pack::enable_dht, true);
|
|
|
|
apply_settings(p);
|
2006-10-11 16:02:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void session::stop_dht()
|
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
settings_pack p;
|
|
|
|
p.set_bool(settings_pack::enable_dht, false);
|
|
|
|
apply_settings(p);
|
2006-10-11 16:02:21 +02:00
|
|
|
}
|
2014-07-06 21:18:00 +02:00
|
|
|
#endif
|
2006-10-11 16:02:21 +02:00
|
|
|
|
|
|
|
void session::set_dht_settings(dht_settings const& settings)
|
|
|
|
{
|
2013-04-09 03:04:43 +02:00
|
|
|
#ifndef TORRENT_DISABLE_DHT
|
2010-07-14 06:16:38 +02:00
|
|
|
TORRENT_ASYNC_CALL1(set_dht_settings, settings);
|
2013-04-09 03:04:43 +02:00
|
|
|
#endif
|
2006-10-11 16:02:21 +02:00
|
|
|
}
|
|
|
|
|
2010-03-04 17:42:39 +01:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
|
|
|
void session::start_dht(entry const& startup_state)
|
|
|
|
{
|
2013-04-09 03:04:43 +02:00
|
|
|
#ifndef TORRENT_DISABLE_DHT
|
2010-07-14 06:16:38 +02:00
|
|
|
TORRENT_ASYNC_CALL1(start_dht, startup_state);
|
2013-04-09 03:04:43 +02:00
|
|
|
#endif
|
2010-03-04 17:42:39 +01:00
|
|
|
}
|
|
|
|
|
2006-10-11 16:02:21 +02:00
|
|
|
entry session::dht_state() const
|
|
|
|
{
|
2013-04-09 03:04:43 +02:00
|
|
|
#ifndef TORRENT_DISABLE_DHT
|
2014-08-26 06:51:09 +02:00
|
|
|
return TORRENT_SYNC_CALL_RET(entry, dht_state);
|
2013-04-09 03:04:43 +02:00
|
|
|
#else
|
|
|
|
return entry();
|
2010-03-04 17:42:39 +01:00
|
|
|
#endif
|
2013-04-09 03:04:43 +02:00
|
|
|
}
|
|
|
|
#endif // TORRENT_NO_DEPRECATE
|
2006-10-11 16:02:21 +02:00
|
|
|
|
|
|
|
void session::add_dht_node(std::pair<std::string, int> const& node)
|
|
|
|
{
|
2013-04-09 03:04:43 +02:00
|
|
|
#ifndef TORRENT_DISABLE_DHT
|
2010-07-14 06:16:38 +02:00
|
|
|
TORRENT_ASYNC_CALL1(add_dht_node_name, node);
|
2013-04-09 03:04:43 +02:00
|
|
|
#endif
|
2006-10-11 16:02:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void session::add_dht_router(std::pair<std::string, int> const& node)
|
|
|
|
{
|
2013-04-09 03:04:43 +02:00
|
|
|
#ifndef TORRENT_DISABLE_DHT
|
2010-07-14 06:16:38 +02:00
|
|
|
TORRENT_ASYNC_CALL1(add_dht_router, node);
|
2013-04-09 03:04:43 +02:00
|
|
|
#endif
|
2006-10-11 16:02:21 +02:00
|
|
|
}
|
|
|
|
|
2009-10-24 23:55:16 +02:00
|
|
|
bool session::is_dht_running() const
|
|
|
|
{
|
2013-04-09 03:04:43 +02:00
|
|
|
#ifndef TORRENT_DISABLE_DHT
|
2014-08-26 06:51:09 +02:00
|
|
|
return TORRENT_SYNC_CALL_RET(bool, is_dht_running);
|
2013-04-09 03:04:43 +02:00
|
|
|
#else
|
|
|
|
return false;
|
2006-10-11 16:02:21 +02:00
|
|
|
#endif
|
2013-04-09 03:04:43 +02:00
|
|
|
}
|
2006-10-11 16:02:21 +02:00
|
|
|
|
2014-02-24 01:31:13 +01:00
|
|
|
void session::dht_get_item(sha1_hash const& target)
|
|
|
|
{
|
|
|
|
#ifndef TORRENT_DISABLE_DHT
|
|
|
|
TORRENT_ASYNC_CALL1(dht_get_immutable_item, target);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void session::dht_get_item(boost::array<char, 32> key
|
|
|
|
, std::string salt)
|
|
|
|
{
|
|
|
|
#ifndef TORRENT_DISABLE_DHT
|
|
|
|
TORRENT_ASYNC_CALL2(dht_get_mutable_item, key, salt);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
sha1_hash session::dht_put_item(entry data)
|
|
|
|
{
|
|
|
|
std::vector<char> buf;
|
|
|
|
bencode(std::back_inserter(buf), data);
|
|
|
|
sha1_hash ret = hasher(&buf[0], buf.size()).final();
|
|
|
|
|
|
|
|
#ifndef TORRENT_DISABLE_DHT
|
2014-02-28 05:02:48 +01:00
|
|
|
TORRENT_ASYNC_CALL2(dht_put_item, data, ret);
|
2014-02-24 01:31:13 +01:00
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void session::dht_put_item(boost::array<char, 32> key
|
|
|
|
, boost::function<void(entry&, boost::array<char,64>&
|
|
|
|
, boost::uint64_t&, std::string const&)> cb
|
|
|
|
, std::string salt)
|
|
|
|
{
|
|
|
|
#ifndef TORRENT_DISABLE_DHT
|
|
|
|
TORRENT_ASYNC_CALL3(dht_put_mutable_item, key, cb, salt);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
|
|
|
void session::set_pe_settings(pe_settings const& r)
|
2007-06-06 02:41:20 +02:00
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
settings_pack pack;
|
|
|
|
pack.set_bool(settings_pack::prefer_rc4, r.prefer_rc4);
|
|
|
|
pack.set_int(settings_pack::out_enc_policy, r.out_enc_policy);
|
|
|
|
pack.set_int(settings_pack::in_enc_policy, r.in_enc_policy);
|
|
|
|
pack.set_int(settings_pack::allowed_enc_level, r.allowed_enc_level);
|
|
|
|
|
|
|
|
apply_settings(pack);
|
2007-06-06 02:41:20 +02:00
|
|
|
}
|
|
|
|
|
2010-07-14 06:16:38 +02:00
|
|
|
pe_settings session::get_pe_settings() const
|
2007-06-06 02:41:20 +02:00
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
aux::session_settings sett = get_settings();
|
|
|
|
|
2013-12-19 06:35:47 +01:00
|
|
|
pe_settings r;
|
2014-07-06 21:18:00 +02:00
|
|
|
r.prefer_rc4 = sett.get_bool(settings_pack::prefer_rc4);
|
|
|
|
r.out_enc_policy = sett.get_int(settings_pack::out_enc_policy);
|
|
|
|
r.in_enc_policy = sett.get_int(settings_pack::in_enc_policy);
|
|
|
|
r.allowed_enc_level = sett.get_int(settings_pack::allowed_enc_level);
|
2010-07-14 06:16:38 +02:00
|
|
|
return r;
|
2007-06-06 02:41:20 +02:00
|
|
|
}
|
2014-07-06 21:18:00 +02:00
|
|
|
#endif // TORRENT_NO_DEPRECATE
|
|
|
|
|
|
|
|
void session::set_peer_class_filter(ip_filter const& f)
|
|
|
|
{
|
|
|
|
TORRENT_ASYNC_CALL1(set_peer_class_filter, f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void session::set_peer_class_type_filter(peer_class_type_filter const& f)
|
|
|
|
{
|
|
|
|
TORRENT_ASYNC_CALL1(set_peer_class_type_filter, f);
|
|
|
|
}
|
|
|
|
|
|
|
|
int session::create_peer_class(char const* name)
|
|
|
|
{
|
2014-08-26 06:51:09 +02:00
|
|
|
return TORRENT_SYNC_CALL_RET1(int, create_peer_class, name);
|
2014-07-06 21:18:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void session::delete_peer_class(int cid)
|
|
|
|
{
|
|
|
|
TORRENT_ASYNC_CALL1(delete_peer_class, cid);
|
|
|
|
}
|
|
|
|
|
|
|
|
peer_class_info session::get_peer_class(int cid)
|
|
|
|
{
|
2014-08-26 06:51:09 +02:00
|
|
|
return TORRENT_SYNC_CALL_RET1(peer_class_info, get_peer_class, cid);
|
2014-07-06 21:18:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void session::set_peer_class(int cid, peer_class_info const& pci)
|
|
|
|
{
|
|
|
|
TORRENT_ASYNC_CALL2(set_peer_class, cid, pci);
|
|
|
|
}
|
2007-06-06 02:41:20 +02:00
|
|
|
|
2006-10-11 16:02:21 +02:00
|
|
|
bool session::is_listening() const
|
|
|
|
{
|
2014-08-26 06:51:09 +02:00
|
|
|
return TORRENT_SYNC_CALL_RET(bool, is_listening);
|
2006-10-11 16:02:21 +02:00
|
|
|
}
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2006-10-11 16:02:21 +02:00
|
|
|
void session::set_settings(session_settings const& s)
|
|
|
|
{
|
2010-07-14 06:16:38 +02:00
|
|
|
TORRENT_ASYNC_CALL1(set_settings, s);
|
2006-10-11 16:02:21 +02:00
|
|
|
}
|
|
|
|
|
2010-12-26 09:03:02 +01:00
|
|
|
session_settings session::settings() const
|
2006-10-11 16:02:21 +02:00
|
|
|
{
|
2014-08-26 06:51:09 +02:00
|
|
|
return TORRENT_SYNC_CALL_RET(session_settings, deprecated_settings);
|
2006-10-11 16:02:21 +02:00
|
|
|
}
|
2014-07-06 21:18:00 +02:00
|
|
|
#endif
|
2006-10-11 16:02:21 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
void session::apply_settings(settings_pack const& s)
|
2010-08-23 08:27:18 +02:00
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
settings_pack* copy = new settings_pack(s);
|
|
|
|
TORRENT_ASYNC_CALL1(apply_settings_pack, copy);
|
2010-08-23 08:27:18 +02:00
|
|
|
}
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
aux::session_settings session::get_settings() const
|
2010-08-23 08:27:18 +02:00
|
|
|
{
|
2014-08-26 06:51:09 +02:00
|
|
|
return TORRENT_SYNC_CALL_RET(aux::session_settings, settings);
|
2010-08-23 08:27:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2014-07-06 21:18:00 +02:00
|
|
|
|
|
|
|
void session::set_proxy(proxy_settings const& s)
|
|
|
|
{
|
|
|
|
settings_pack pack;
|
|
|
|
pack.set_str(settings_pack::proxy_hostname, s.hostname);
|
|
|
|
pack.set_str(settings_pack::proxy_username, s.username);
|
|
|
|
pack.set_str(settings_pack::proxy_password, s.password);
|
|
|
|
pack.set_int(settings_pack::proxy_type, s.type);
|
|
|
|
pack.set_int(settings_pack::proxy_port, s.port);
|
|
|
|
pack.set_bool(settings_pack::proxy_hostnames,s.proxy_hostnames);
|
|
|
|
pack.set_bool(settings_pack::proxy_peer_connections, s.proxy_peer_connections);
|
|
|
|
|
|
|
|
apply_settings(pack);
|
|
|
|
}
|
|
|
|
|
|
|
|
proxy_settings session::proxy() const
|
|
|
|
{
|
|
|
|
aux::session_settings sett = get_settings();
|
2014-10-21 02:28:51 +02:00
|
|
|
return proxy_settings(sett);
|
2014-07-06 21:18:00 +02:00
|
|
|
}
|
|
|
|
|
2007-04-25 20:26:35 +02:00
|
|
|
void session::set_peer_proxy(proxy_settings const& s)
|
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
set_proxy(s);
|
2007-04-25 20:26:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void session::set_web_seed_proxy(proxy_settings const& s)
|
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
set_proxy(s);
|
2007-04-25 20:26:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void session::set_tracker_proxy(proxy_settings const& s)
|
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
set_proxy(s);
|
2007-04-25 20:26:35 +02:00
|
|
|
}
|
|
|
|
|
2010-07-14 06:16:38 +02:00
|
|
|
proxy_settings session::peer_proxy() const
|
2007-04-25 20:26:35 +02:00
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
return proxy();
|
2007-04-25 20:26:35 +02:00
|
|
|
}
|
|
|
|
|
2010-07-14 06:16:38 +02:00
|
|
|
proxy_settings session::web_seed_proxy() const
|
2007-04-25 20:26:35 +02:00
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
return proxy();
|
2007-04-25 20:26:35 +02:00
|
|
|
}
|
|
|
|
|
2010-07-14 06:16:38 +02:00
|
|
|
proxy_settings session::tracker_proxy() const
|
2007-04-25 20:26:35 +02:00
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
return proxy();
|
2007-04-25 20:26:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void session::set_dht_proxy(proxy_settings const& s)
|
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
set_proxy(s);
|
2007-04-25 20:26:35 +02:00
|
|
|
}
|
|
|
|
|
2010-07-14 06:16:38 +02:00
|
|
|
proxy_settings session::dht_proxy() const
|
2007-04-25 20:26:35 +02:00
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
return proxy();
|
2013-04-09 03:04:43 +02:00
|
|
|
}
|
2007-04-25 20:26:35 +02:00
|
|
|
|
2009-08-20 05:19:12 +02:00
|
|
|
void session::set_i2p_proxy(proxy_settings const& s)
|
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
settings_pack pack;
|
|
|
|
pack.set_str(settings_pack::i2p_hostname, s.hostname);
|
|
|
|
pack.set_int(settings_pack::i2p_port, s.port);
|
|
|
|
|
|
|
|
apply_settings(pack);
|
2009-08-20 05:19:12 +02:00
|
|
|
}
|
|
|
|
|
2010-07-14 06:16:38 +02:00
|
|
|
proxy_settings session::i2p_proxy() const
|
2009-08-20 05:19:12 +02:00
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
proxy_settings ret;
|
|
|
|
aux::session_settings sett = get_settings();
|
|
|
|
ret.hostname = sett.get_str(settings_pack::i2p_hostname);
|
|
|
|
ret.port = sett.get_int(settings_pack::i2p_port);
|
|
|
|
return ret;
|
2009-08-20 05:19:12 +02:00
|
|
|
}
|
2011-04-06 08:27:42 +02:00
|
|
|
|
2014-10-04 21:54:12 +02:00
|
|
|
void session::set_max_half_open_connections(int limit) {}
|
|
|
|
int session::max_half_open_connections() const { return 8; }
|
|
|
|
|
2009-04-07 17:55:05 +02:00
|
|
|
int session::max_uploads() const
|
|
|
|
{
|
2014-08-26 06:51:09 +02:00
|
|
|
return TORRENT_SYNC_CALL_RET(int, max_uploads);
|
2009-04-07 17:55:05 +02:00
|
|
|
}
|
|
|
|
|
2006-10-11 16:02:21 +02:00
|
|
|
void session::set_max_uploads(int limit)
|
|
|
|
{
|
2010-07-14 06:16:38 +02:00
|
|
|
TORRENT_ASYNC_CALL1(set_max_uploads, limit);
|
2006-10-11 16:02:21 +02:00
|
|
|
}
|
|
|
|
|
2008-11-08 08:40:55 +01:00
|
|
|
int session::max_connections() const
|
|
|
|
{
|
2014-08-26 06:51:09 +02:00
|
|
|
return TORRENT_SYNC_CALL_RET(int, max_connections);
|
2008-11-08 08:40:55 +01:00
|
|
|
}
|
|
|
|
|
2006-10-11 16:02:21 +02:00
|
|
|
void session::set_max_connections(int limit)
|
|
|
|
{
|
2010-07-14 06:16:38 +02:00
|
|
|
TORRENT_ASYNC_CALL1(set_max_connections, limit);
|
2006-10-11 16:02:21 +02:00
|
|
|
}
|
|
|
|
|
2009-05-14 19:21:19 +02:00
|
|
|
int session::local_upload_rate_limit() const
|
|
|
|
{
|
2014-08-26 06:51:09 +02:00
|
|
|
return TORRENT_SYNC_CALL_RET(int, local_upload_rate_limit);
|
2009-05-14 19:21:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int session::local_download_rate_limit() const
|
|
|
|
{
|
2014-08-26 06:51:09 +02:00
|
|
|
return TORRENT_SYNC_CALL_RET(int, local_download_rate_limit);
|
2009-05-14 19:21:19 +02:00
|
|
|
}
|
|
|
|
|
2007-01-02 00:51:24 +01:00
|
|
|
int session::upload_rate_limit() const
|
|
|
|
{
|
2014-08-26 06:51:09 +02:00
|
|
|
return TORRENT_SYNC_CALL_RET(int, upload_rate_limit);
|
2007-01-02 00:51:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int session::download_rate_limit() const
|
|
|
|
{
|
2014-08-26 06:51:09 +02:00
|
|
|
return TORRENT_SYNC_CALL_RET(int, download_rate_limit);
|
2007-01-02 00:51:24 +01:00
|
|
|
}
|
|
|
|
|
2009-05-14 19:21:19 +02:00
|
|
|
void session::set_local_upload_rate_limit(int bytes_per_second)
|
|
|
|
{
|
2010-07-14 06:16:38 +02:00
|
|
|
TORRENT_ASYNC_CALL1(set_local_upload_rate_limit, bytes_per_second);
|
2009-05-14 19:21:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void session::set_local_download_rate_limit(int bytes_per_second)
|
|
|
|
{
|
2010-07-14 06:16:38 +02:00
|
|
|
TORRENT_ASYNC_CALL1(set_local_download_rate_limit, bytes_per_second);
|
2009-05-14 19:21:19 +02:00
|
|
|
}
|
|
|
|
|
2006-10-11 16:02:21 +02:00
|
|
|
void session::set_upload_rate_limit(int bytes_per_second)
|
|
|
|
{
|
2010-07-14 06:16:38 +02:00
|
|
|
TORRENT_ASYNC_CALL1(set_upload_rate_limit, bytes_per_second);
|
2004-03-28 19:45:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void session::set_download_rate_limit(int bytes_per_second)
|
|
|
|
{
|
2010-07-14 06:16:38 +02:00
|
|
|
TORRENT_ASYNC_CALL1(set_download_rate_limit, bytes_per_second);
|
2003-11-09 19:17:09 +01:00
|
|
|
}
|
|
|
|
|
2007-01-01 22:04:30 +01:00
|
|
|
int session::num_uploads() const
|
|
|
|
{
|
2014-08-26 06:51:09 +02:00
|
|
|
return TORRENT_SYNC_CALL_RET(int, num_uploads);
|
2007-01-01 22:04:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int session::num_connections() const
|
|
|
|
{
|
2014-08-26 06:51:09 +02:00
|
|
|
return TORRENT_SYNC_CALL_RET(int, num_connections);
|
2007-01-01 22:04:30 +01:00
|
|
|
}
|
2011-09-16 06:03:54 +02:00
|
|
|
#endif // TORRENT_NO_DEPRECATE
|
2007-01-01 22:04:30 +01:00
|
|
|
|
2011-01-23 19:00:52 +01:00
|
|
|
void session::set_alert_dispatch(boost::function<void(std::auto_ptr<alert>)> const& fun)
|
2003-11-29 17:34:07 +01:00
|
|
|
{
|
2011-01-23 19:00:52 +01:00
|
|
|
TORRENT_ASYNC_CALL1(set_alert_dispatch, fun);
|
2003-11-29 17:34:07 +01:00
|
|
|
}
|
|
|
|
|
2011-01-23 19:00:52 +01:00
|
|
|
std::auto_ptr<alert> session::pop_alert()
|
2008-12-15 08:12:08 +01:00
|
|
|
{
|
2011-01-23 19:00:52 +01:00
|
|
|
return m_impl->pop_alert();
|
2008-12-15 08:12:08 +01:00
|
|
|
}
|
|
|
|
|
2011-03-14 03:59:46 +01:00
|
|
|
void session::pop_alerts(std::deque<alert*>* alerts)
|
|
|
|
{
|
|
|
|
for (std::deque<alert*>::iterator i = alerts->begin()
|
|
|
|
, end(alerts->end()); i != end; ++i)
|
|
|
|
delete *i;
|
|
|
|
alerts->clear();
|
|
|
|
m_impl->pop_alerts(alerts);
|
|
|
|
}
|
|
|
|
|
2007-11-25 09:18:57 +01:00
|
|
|
alert const* session::wait_for_alert(time_duration max_wait)
|
|
|
|
{
|
|
|
|
return m_impl->wait_for_alert(max_wait);
|
|
|
|
}
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2011-06-13 18:46:46 +02:00
|
|
|
void session::set_alert_mask(boost::uint32_t m)
|
2008-07-06 14:22:56 +02:00
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
settings_pack p;
|
|
|
|
p.set_int(settings_pack::alert_mask, m);
|
|
|
|
apply_settings(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
boost::uint32_t session::get_alert_mask() const
|
|
|
|
{
|
|
|
|
return get_settings().get_int(settings_pack::alert_mask);
|
2008-07-06 14:22:56 +02:00
|
|
|
}
|
|
|
|
|
2008-10-07 09:12:32 +02:00
|
|
|
size_t session::set_alert_queue_size_limit(size_t queue_size_limit_)
|
2008-10-07 07:46:42 +02:00
|
|
|
{
|
2014-08-26 06:51:09 +02:00
|
|
|
return TORRENT_SYNC_CALL_RET1(size_t, set_alert_queue_size_limit, queue_size_limit_);
|
2008-10-07 07:46:42 +02:00
|
|
|
}
|
|
|
|
|
2003-12-22 08:14:35 +01:00
|
|
|
void session::set_severity_level(alert::severity_t s)
|
2003-12-21 18:28:27 +01:00
|
|
|
{
|
2008-07-06 14:22:56 +02:00
|
|
|
int m = 0;
|
|
|
|
switch (s)
|
|
|
|
{
|
|
|
|
case alert::debug: m = alert::all_categories; break;
|
|
|
|
case alert::info: m = alert::all_categories & ~(alert::debug_notification
|
2008-10-22 03:12:14 +02:00
|
|
|
| alert::progress_notification | alert::dht_notification); break;
|
2008-07-06 14:22:56 +02:00
|
|
|
case alert::warning: m = alert::all_categories & ~(alert::debug_notification
|
2008-10-22 03:12:14 +02:00
|
|
|
| alert::status_notification | alert::progress_notification
|
|
|
|
| alert::dht_notification); break;
|
2008-07-06 14:22:56 +02:00
|
|
|
case alert::critical: m = alert::error_notification | alert::storage_notification; break;
|
|
|
|
case alert::fatal: m = alert::error_notification; break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
settings_pack p;
|
|
|
|
p.set_int(settings_pack::alert_mask, m);
|
|
|
|
apply_settings(p);
|
2003-12-22 08:14:35 +01:00
|
|
|
}
|
2003-10-25 03:31:06 +02:00
|
|
|
|
2007-05-31 02:21:54 +02:00
|
|
|
void session::start_lsd()
|
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
settings_pack p;
|
|
|
|
p.set_bool(settings_pack::enable_lsd, true);
|
|
|
|
apply_settings(p);
|
2007-05-31 02:21:54 +02:00
|
|
|
}
|
|
|
|
|
2013-07-19 21:06:27 +02:00
|
|
|
void session::start_natpmp()
|
2007-05-31 02:21:54 +02:00
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
settings_pack p;
|
|
|
|
p.set_bool(settings_pack::enable_natpmp, true);
|
|
|
|
apply_settings(p);
|
2007-05-31 02:21:54 +02:00
|
|
|
}
|
|
|
|
|
2013-07-19 21:06:27 +02:00
|
|
|
void session::start_upnp()
|
2007-05-31 02:21:54 +02:00
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
settings_pack p;
|
|
|
|
p.set_bool(settings_pack::enable_upnp, true);
|
|
|
|
apply_settings(p);
|
2007-05-31 02:21:54 +02:00
|
|
|
}
|
2013-12-31 21:42:37 +01:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
void session::stop_lsd()
|
2013-12-31 21:42:37 +01:00
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
settings_pack p;
|
|
|
|
p.set_bool(settings_pack::enable_lsd, false);
|
|
|
|
apply_settings(p);
|
2013-12-31 21:42:37 +01:00
|
|
|
}
|
2014-07-06 21:18:00 +02:00
|
|
|
|
|
|
|
void session::stop_natpmp()
|
2013-12-31 21:42:37 +01:00
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
settings_pack p;
|
|
|
|
p.set_bool(settings_pack::enable_natpmp, false);
|
|
|
|
apply_settings(p);
|
2013-12-31 21:42:37 +01:00
|
|
|
}
|
2007-05-31 02:21:54 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
void session::stop_upnp()
|
2007-05-31 02:21:54 +02:00
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
settings_pack p;
|
|
|
|
p.set_bool(settings_pack::enable_upnp, false);
|
|
|
|
apply_settings(p);
|
2007-05-31 02:21:54 +02:00
|
|
|
}
|
2014-07-06 21:18:00 +02:00
|
|
|
#endif
|
2007-05-31 02:21:54 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
int session::add_port_mapping(protocol_type t, int external_port, int local_port)
|
2007-05-31 02:21:54 +02:00
|
|
|
{
|
2014-08-26 06:51:09 +02:00
|
|
|
return TORRENT_SYNC_CALL_RET3(int, add_port_mapping, int(t), external_port, local_port);
|
2007-05-31 02:21:54 +02:00
|
|
|
}
|
2014-07-06 21:18:00 +02:00
|
|
|
|
|
|
|
void session::delete_port_mapping(int handle)
|
2007-05-31 02:21:54 +02:00
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
TORRENT_ASYNC_CALL1(delete_port_mapping, handle);
|
2007-05-31 02:21:54 +02:00
|
|
|
}
|
|
|
|
|
2012-06-21 17:05:57 +02:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2014-07-06 21:18:00 +02:00
|
|
|
session_settings::session_settings(std::string const& user_agent_)
|
|
|
|
{
|
|
|
|
aux::session_settings def;
|
|
|
|
initialize_default_settings(def);
|
|
|
|
def.set_str(settings_pack::user_agent, user_agent_);
|
|
|
|
load_struct_from_settings(def, *this);
|
|
|
|
}
|
2012-03-19 07:06:52 +01:00
|
|
|
|
|
|
|
session_settings::~session_settings() {}
|
2014-07-06 21:18:00 +02:00
|
|
|
#endif // TORRENT_NO_DEPRECATE
|
|
|
|
|
2003-10-23 01:00:57 +02:00
|
|
|
}
|
2006-10-11 22:57:54 +02:00
|
|
|
|