make session inherit from session_handle and remove wrapper functions

This commit is contained in:
Steven Siloti 2015-07-07 20:32:35 -07:00
parent b072b0ca5f
commit 1d55bcba72
3 changed files with 93 additions and 1619 deletions

File diff suppressed because it is too large Load Diff

View File

@ -42,7 +42,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/peer_class.hpp"
#include "libtorrent/peer_class_type_filter.hpp"
#include "libtorrent/session_settings.hpp"
#include "libtorrent/session.hpp"
#ifndef TORRENT_NO_DEPRECATE
#include "libtorrent/rss.hpp"
@ -50,6 +49,21 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent
{
struct plugin;
struct torrent_plugin;
class torrent;
struct ip_filter;
class port_filter;
class connection_queue;
class alert;
#ifndef TORRENT_NO_DEPRECATE
struct session_status;
#endif
typedef boost::function<void(sha1_hash const&, std::vector<char>&
, error_code&)> user_load_function_t;
struct TORRENT_EXPORT session_handle
{
session_handle(aux::session_impl* impl)
@ -58,6 +72,39 @@ namespace libtorrent
// TODO: 2 the ip filter should probably be saved here too
// flags that determines which aspects of the session should be
// saved when calling save_state().
enum save_state_flags_t
{
// saves settings (i.e. the session_settings)
save_settings = 0x001,
// saves dht_settings
save_dht_settings = 0x002,
// saves dht state such as nodes and node-id, possibly accelerating
// joining the DHT if provided at next session startup.
save_dht_state = 0x004,
// save pe_settings
save_encryption_settings = 0x020,
// internal
save_as_map = 0x040
#ifndef TORRENT_NO_DEPRECATE
,
// saves RSS feeds
save_feeds = 0x080,
save_proxy = 0x008,
save_i2p_proxy = 0x010,
save_dht_proxy = save_proxy,
save_peer_proxy = save_proxy,
save_web_proxy = save_proxy,
save_tracker_proxy = save_proxy
#endif
};
// loads and saves all session settings, including dht_settings,
// encryption settings and proxy settings. ``save_state`` writes all keys
// to the ``entry`` that's passed in, which needs to either not be
@ -247,6 +294,8 @@ namespace libtorrent
cache_status get_cache_status() const;
#endif
enum { disk_cache_no_pieces = 1 };
// Fills in the cache_status struct with information about the given torrent.
// If ``flags`` is ``session::disk_cache_no_pieces`` the ``cache_status::pieces`` field
// will not be set. This may significantly reduce the cost of this call.
@ -508,6 +557,13 @@ namespace libtorrent
// peer potentially across you changing your IP.
void set_key(int key);
// built-in peer classes
enum {
global_peer_class_id,
tcp_peer_class_id,
local_peer_class_id
};
// ``is_listening()`` will tell you whether or not the session has
// successfully opened a listening port. If it hasn't, this function will
// return false, and then you can set a new
@ -653,6 +709,12 @@ namespace libtorrent
// interface and port range). As usual, if the interface is left as 0
// this function will return false on failure. If it fails, it will also
// generate alerts describing the error. It will return true on success.
enum listen_on_flags_t
{
// this is always on starting with 0.16.2
listen_reuse_address = 0x01,
listen_no_system_port = 0x02
};
// deprecated in 0.16
@ -671,6 +733,25 @@ namespace libtorrent
, int flags = 0);
#endif
// flags to be passed in to remove_torrent().
enum options_t
{
// delete the files belonging to the torrent from disk.
delete_files = 1
};
// flags to be passed in to the session constructor
enum session_flags_t
{
// this will add common extensions like ut_pex, ut_metadata, lt_tex
// smart_ban and possibly others.
add_default_plugins = 1,
// this will start features like DHT, local service discovery, UPnP
// and NAT-PMP.
start_default_features = 2
};
// ``remove_torrent()`` will close all peer connections associated with
// the torrent and tell the tracker that we've stopped participating in
// the swarm. This operation cannot fail. When it completes, you will
@ -932,11 +1013,14 @@ namespace libtorrent
void stop_natpmp();
#endif
// protocols used by add_port_mapping()
enum protocol_type { udp = 1, tcp = 2 };
// add_port_mapping adds a port forwarding on UPnP and/or NAT-PMP,
// whichever is enabled. The return value is a handle referring to the
// port mapping that was just created. Pass it to delete_port_mapping()
// to remove it.
int add_port_mapping(session::protocol_type t, int external_port, int local_port);
int add_port_mapping(protocol_type t, int external_port, int local_port);
void delete_port_mapping(int handle);
// This function is intended only for use by plugins. This type does

View File

@ -373,6 +373,7 @@ namespace libtorrent
}
m_impl = boost::make_shared<session_impl>(boost::ref(*ios));
*static_cast<session_handle*>(this) = session_handle(m_impl.get());
#ifndef TORRENT_DISABLE_EXTENSIONS
if (flags & add_default_plugins)
@ -404,643 +405,6 @@ namespace libtorrent
m_thread->join();
}
void session::save_state(entry& e, boost::uint32_t flags) const
{
session_handle(m_impl.get()).save_state(e, flags);
}
void session::load_state(bdecode_node const& e)
{
// this needs to be synchronized since the lifespan
// of e is tied to the caller
session_handle(m_impl.get()).load_state(e);
}
#ifndef TORRENT_NO_DEPRECATE
feed_handle session::add_feed(feed_settings const& feed)
{
return session_handle(m_impl.get()).add_feed(feed);
}
void session::remove_feed(feed_handle h)
{
session_handle(m_impl.get()).remove_feed(h);
}
void session::get_feeds(std::vector<feed_handle>& f) const
{
session_handle(m_impl.get()).get_feeds(f);
}
#endif
void session::set_load_function(user_load_function_t fun)
{
session_handle(m_impl.get()).set_load_function(fun);
}
void session::add_extension(boost::function<boost::shared_ptr<torrent_plugin>(torrent*, void*)> ext)
{
session_handle(m_impl.get()).add_extension(ext);
}
void session::add_extension(boost::shared_ptr<plugin> ext)
{
session_handle(m_impl.get()).add_extension(ext);
}
#ifndef TORRENT_NO_DEPRECATE
void session::load_asnum_db(char const*) {}
void session::load_country_db(char const*) {}
int session::as_for_ip(address const&)
{ return 0; }
#if TORRENT_USE_WSTRING
void session::load_asnum_db(wchar_t const*) {}
void session::load_country_db(wchar_t const*) {}
#endif // TORRENT_USE_WSTRING
void session::load_state(entry const& ses_state)
{
session_handle(m_impl.get()).load_state(ses_state);
}
void session::load_state(lazy_entry const& ses_state)
{
session_handle(m_impl.get()).load_state(ses_state);
}
entry session::state() const
{
return session_handle(m_impl.get()).state();
}
#endif // TORRENT_NO_DEPRECATE
void session::set_ip_filter(ip_filter const& f)
{
session_handle(m_impl.get()).set_ip_filter(f);
}
ip_filter session::get_ip_filter() const
{
return session_handle(m_impl.get()).get_ip_filter();
}
void session::set_port_filter(port_filter const& f)
{
session_handle(m_impl.get()).set_port_filter(f);
}
#ifndef TORRENT_NO_DEPRECATE
void session::set_peer_id(peer_id const& id)
{
session_handle(m_impl.get()).set_peer_id(id);
}
#endif
peer_id session::id() const
{
return session_handle(m_impl.get()).id();
}
io_service& session::get_io_service()
{
return session_handle(m_impl.get()).get_io_service();
}
void session::set_key(int key)
{
session_handle(m_impl.get()).set_key(key);
}
void session::get_torrent_status(std::vector<torrent_status>* ret
, boost::function<bool(torrent_status const&)> const& pred
, boost::uint32_t flags) const
{
session_handle(m_impl.get()).get_torrent_status(ret, pred, flags);
}
void session::refresh_torrent_status(std::vector<torrent_status>* ret
, boost::uint32_t flags) const
{
session_handle(m_impl.get()).refresh_torrent_status(ret, flags);
}
void session::post_torrent_updates(boost::uint32_t flags)
{
session_handle(m_impl.get()).post_torrent_updates(flags);
}
void session::post_session_stats()
{
session_handle(m_impl.get()).post_session_stats();
}
void session::post_dht_stats()
{
session_handle(m_impl.get()).post_dht_stats();
}
std::vector<torrent_handle> session::get_torrents() const
{
return session_handle(m_impl.get()).get_torrents();
}
torrent_handle session::find_torrent(sha1_hash const& info_hash) const
{
return session_handle(m_impl.get()).find_torrent(info_hash);
}
#ifndef BOOST_NO_EXCEPTIONS
torrent_handle session::add_torrent(add_torrent_params const& params)
{
return session_handle(m_impl.get()).add_torrent(params);
}
#endif
torrent_handle session::add_torrent(add_torrent_params const& params, error_code& ec)
{
return session_handle(m_impl.get()).add_torrent(params, ec);
}
void session::async_add_torrent(add_torrent_params const& params)
{
session_handle(m_impl.get()).async_add_torrent(params);
}
#ifndef BOOST_NO_EXCEPTIONS
#ifndef TORRENT_NO_DEPRECATE
// if the torrent already exists, this will throw duplicate_torrent
torrent_handle session::add_torrent(
torrent_info const& ti
, std::string const& save_path
, entry const& resume_data
, storage_mode_t storage_mode
, bool paused
, storage_constructor_type sc)
{
return session_handle(m_impl.get()).add_torrent(ti, save_path
, resume_data, storage_mode, paused, sc);
}
torrent_handle session::add_torrent(
char const* tracker_url
, sha1_hash const& info_hash
, char const* name
, std::string const& save_path
, entry const& resume_data
, storage_mode_t storage_mode
, bool paused
, storage_constructor_type sc
, void* userdata)
{
return session_handle(m_impl.get()).add_torrent(tracker_url, info_hash
, name, save_path, resume_data, storage_mode, paused, sc, userdata);
}
#endif // TORRENT_NO_DEPRECATE
#endif // BOOST_NO_EXCEPTIONS
void session::remove_torrent(const torrent_handle& h, int options)
{
session_handle(m_impl.get()).remove_torrent(h, options);
}
#ifndef TORRENT_NO_DEPRECATE
void session::listen_on(
std::pair<int, int> const& port_range
, error_code& ec
, const char* net_interface, int flags)
{
session_handle(m_impl.get()).listen_on(port_range, ec, net_interface, flags);
}
void session::use_interfaces(char const* interfaces)
{
session_handle(m_impl.get()).use_interfaces(interfaces);
}
#endif
unsigned short session::listen_port() const
{
return session_handle(m_impl.get()).listen_port();
}
unsigned short session::ssl_listen_port() const
{
return session_handle(m_impl.get()).ssl_listen_port();
}
void session::pause()
{
session_handle(m_impl.get()).pause();
}
void session::resume()
{
session_handle(m_impl.get()).resume();
}
bool session::is_paused() const
{
return session_handle(m_impl.get()).is_paused();
}
#ifndef TORRENT_NO_DEPRECATE
session_status session::status() const
{
return session_handle(m_impl.get()).status();
}
void session::get_cache_info(sha1_hash const& ih
, std::vector<cached_piece_info>& ret) const
{
session_handle(m_impl.get()).get_cache_info(ih, ret);
}
cache_status session::get_cache_status() const
{
return session_handle(m_impl.get()).get_cache_status();
}
#endif
void session::get_cache_info(cache_status* ret
, torrent_handle h, int flags) const
{
session_handle(m_impl.get()).get_cache_info(ret, h, flags);
}
#ifndef TORRENT_NO_DEPRECATE
void session::start_dht()
{
session_handle(m_impl.get()).start_dht();
}
void session::stop_dht()
{
session_handle(m_impl.get()).stop_dht();
}
#endif
void session::set_dht_settings(dht_settings const& settings)
{
session_handle(m_impl.get()).set_dht_settings(settings);
}
dht_settings session::get_dht_settings() const
{
return session_handle(m_impl.get()).get_dht_settings();
}
#ifndef TORRENT_NO_DEPRECATE
void session::start_dht(entry const& startup_state)
{
session_handle(m_impl.get()).start_dht(startup_state);
}
entry session::dht_state() const
{
return session_handle(m_impl.get()).dht_state();
}
#endif // TORRENT_NO_DEPRECATE
void session::add_dht_node(std::pair<std::string, int> const& node)
{
session_handle(m_impl.get()).add_dht_node(node);
}
void session::add_dht_router(std::pair<std::string, int> const& node)
{
session_handle(m_impl.get()).add_dht_router(node);
}
bool session::is_dht_running() const
{
return session_handle(m_impl.get()).is_dht_running();
}
void session::dht_get_item(sha1_hash const& target)
{
session_handle(m_impl.get()).dht_get_item(target);
}
void session::dht_get_item(boost::array<char, 32> key
, std::string salt)
{
session_handle(m_impl.get()).dht_get_item(key, salt);
}
sha1_hash session::dht_put_item(entry data)
{
return session_handle(m_impl.get()).dht_put_item(data);
}
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)
{
session_handle(m_impl.get()).dht_put_item(key, cb, salt);
}
#ifndef TORRENT_NO_DEPRECATE
void session::set_pe_settings(pe_settings const& r)
{
session_handle(m_impl.get()).set_pe_settings(r);
}
pe_settings session::get_pe_settings() const
{
return session_handle(m_impl.get()).get_pe_settings();
}
#endif // TORRENT_NO_DEPRECATE
void session::set_peer_class_filter(ip_filter const& f)
{
session_handle(m_impl.get()).set_peer_class_filter(f);
}
void session::set_peer_class_type_filter(peer_class_type_filter const& f)
{
session_handle(m_impl.get()).set_peer_class_type_filter(f);
}
int session::create_peer_class(char const* name)
{
return session_handle(m_impl.get()).create_peer_class(name);
}
void session::delete_peer_class(int cid)
{
session_handle(m_impl.get()).delete_peer_class(cid);
}
peer_class_info session::get_peer_class(int cid)
{
return session_handle(m_impl.get()).get_peer_class(cid);
}
void session::set_peer_class(int cid, peer_class_info const& pci)
{
session_handle(m_impl.get()).set_peer_class(cid, pci);
}
bool session::is_listening() const
{
return session_handle(m_impl.get()).is_listening();
}
#ifndef TORRENT_NO_DEPRECATE
void session::set_settings(session_settings const& s)
{
session_handle(m_impl.get()).set_settings(s);
}
session_settings session::settings() const
{
return session_handle(m_impl.get()).settings();
}
#endif
void session::apply_settings(settings_pack const& s)
{
session_handle(m_impl.get()).apply_settings(s);
}
settings_pack session::get_settings() const
{
return session_handle(m_impl.get()).get_settings();
}
#ifndef TORRENT_NO_DEPRECATE
void session::set_proxy(proxy_settings const& s)
{
session_handle(m_impl.get()).set_proxy(s);
}
proxy_settings session::proxy() const
{
return session_handle(m_impl.get()).proxy();
}
void session::set_peer_proxy(proxy_settings const& s)
{
session_handle(m_impl.get()).set_peer_proxy(s);
}
void session::set_web_seed_proxy(proxy_settings const& s)
{
session_handle(m_impl.get()).set_web_seed_proxy(s);
}
void session::set_tracker_proxy(proxy_settings const& s)
{
session_handle(m_impl.get()).set_tracker_proxy(s);
}
proxy_settings session::peer_proxy() const
{
return session_handle(m_impl.get()).peer_proxy();
}
proxy_settings session::web_seed_proxy() const
{
return session_handle(m_impl.get()).web_seed_proxy();
}
proxy_settings session::tracker_proxy() const
{
return session_handle(m_impl.get()).tracker_proxy();
}
void session::set_dht_proxy(proxy_settings const& s)
{
session_handle(m_impl.get()).set_dht_proxy(s);
}
proxy_settings session::dht_proxy() const
{
return session_handle(m_impl.get()).dht_proxy();
}
void session::set_i2p_proxy(proxy_settings const& s)
{
session_handle(m_impl.get()).set_i2p_proxy(s);
}
proxy_settings session::i2p_proxy() const
{
return session_handle(m_impl.get()).i2p_proxy();
}
void session::set_max_half_open_connections(int) {}
int session::max_half_open_connections() const { return 8; }
int session::max_uploads() const
{
return session_handle(m_impl.get()).max_uploads();
}
void session::set_max_uploads(int limit)
{
session_handle(m_impl.get()).set_max_uploads(limit);
}
int session::max_connections() const
{
return session_handle(m_impl.get()).max_connections();
}
void session::set_max_connections(int limit)
{
session_handle(m_impl.get()).set_max_connections(limit);
}
int session::local_upload_rate_limit() const
{
return session_handle(m_impl.get()).local_upload_rate_limit();
}
int session::local_download_rate_limit() const
{
return session_handle(m_impl.get()).local_download_rate_limit();
}
int session::upload_rate_limit() const
{
return session_handle(m_impl.get()).upload_rate_limit();
}
int session::download_rate_limit() const
{
return session_handle(m_impl.get()).download_rate_limit();
}
void session::set_local_upload_rate_limit(int bytes_per_second)
{
session_handle(m_impl.get()).set_local_upload_rate_limit(bytes_per_second);
}
void session::set_local_download_rate_limit(int bytes_per_second)
{
session_handle(m_impl.get()).set_local_download_rate_limit(bytes_per_second);
}
void session::set_upload_rate_limit(int bytes_per_second)
{
session_handle(m_impl.get()).set_upload_rate_limit(bytes_per_second);
}
void session::set_download_rate_limit(int bytes_per_second)
{
session_handle(m_impl.get()).set_download_rate_limit(bytes_per_second);
}
int session::num_uploads() const
{
return session_handle(m_impl.get()).num_uploads();
}
int session::num_connections() const
{
return session_handle(m_impl.get()).num_connections();
}
void session::set_alert_dispatch(boost::function<void(std::auto_ptr<alert>)> const& fun)
{
session_handle(m_impl.get()).set_alert_dispatch(fun);
}
#endif // TORRENT_NO_DEPRECATE
alert* session::wait_for_alert(time_duration max_wait)
{
return session_handle(m_impl.get()).wait_for_alert(max_wait);
}
// the alerts are const, they may not be deleted by the client
void session::pop_alerts(std::vector<alert*>* alerts)
{
session_handle(m_impl.get()).pop_alerts(alerts);
}
void session::set_alert_notify(boost::function<void()> const& fun)
{
session_handle(m_impl.get()).set_alert_notify(fun);
}
#ifndef TORRENT_NO_DEPRECATE
void session::pop_alerts(std::deque<alert*>* alerts)
{
session_handle(m_impl.get()).pop_alerts(alerts);
}
std::auto_ptr<alert> session::pop_alert()
{
return session_handle(m_impl.get()).pop_alert();
}
void session::set_alert_mask(boost::uint32_t m)
{
session_handle(m_impl.get()).set_alert_mask(m);
}
boost::uint32_t session::get_alert_mask() const
{
return session_handle(m_impl.get()).get_alert_mask();
}
size_t session::set_alert_queue_size_limit(size_t queue_size_limit_)
{
return session_handle(m_impl.get()).set_alert_queue_size_limit(queue_size_limit_);
}
void session::set_severity_level(alert::severity_t s)
{
session_handle(m_impl.get()).set_severity_level(s);
}
void session::start_lsd()
{
session_handle(m_impl.get()).start_lsd();
}
void session::start_natpmp()
{
session_handle(m_impl.get()).start_natpmp();
}
void session::start_upnp()
{
session_handle(m_impl.get()).start_upnp();
}
void session::stop_lsd()
{
session_handle(m_impl.get()).stop_lsd();
}
void session::stop_natpmp()
{
session_handle(m_impl.get()).stop_natpmp();
}
void session::stop_upnp()
{
session_handle(m_impl.get()).stop_upnp();
}
#endif // TORRENT_NO_DEPRECATED
int session::add_port_mapping(protocol_type t, int external_port, int local_port)
{
return session_handle(m_impl.get()).add_port_mapping(t, external_port, local_port);
}
void session::delete_port_mapping(int handle)
{
session_handle(m_impl.get()).delete_port_mapping(handle);
}
#ifndef TORRENT_NO_DEPRECATE
session_settings::session_settings(std::string const& user_agent_)
{