@@ -294,12 +296,14 @@ class session: public boost::noncopyable
session(fingerprint const& print
= libtorrent::fingerprint(
- "LT", 0, 1, 0, 0));
+ "LT", 0, 1, 0, 0)
+ , int flags = start_default_features | add_default_plugins);
session(
fingerprint const& print
, std::pair<int, int> listen_port_range
- , char const* listen_interface = 0);
+ , char const* listen_interface = 0
+ , int flags = start_default_features | add_default_plugins);
torrent_handle add_torrent(add_torrent_params const& params);
@@ -315,6 +319,12 @@ class session: public boost::noncopyable
delete_files = 1
};
+ enum session_flags_t
+ {
+ add_default_plugins = 1,
+ start_default_features = 2
+ };
+
void remove_torrent(torrent_handle const& h, int options = none);
torrent_handle find_torrent(sha_hash const& ih);
std::vector<torrent_handle> get_torrents() const;
@@ -394,10 +404,13 @@ The main thread will be idle as long it doesn't have any torrents to participate
session(fingerprint const& print
- = libtorrent::fingerprint("LT", 0, 1, 0, 0));
+ = libtorrent::fingerprint("LT", 0, 1, 0, 0)
+ , int flags = start_default_features | add_default_plugins);
+
session(fingerprint const& print
, std::pair<int, int> listen_port_range
- , char const* listen_interface = 0);
+ , char const* listen_interface = 0
+ , int flags = start_default_features | add_default_plugins);
If the fingerprint in the first overload is omited, the client will get a default
@@ -408,6 +421,9 @@ listen port for the session, to get it running you'll have to call listen_on() function.
+
The flags paramater can be used to start default features (upnp & nat-pmp) and default plugins
+(ut_metadata, ut_pex and smart_ban). The default is to start those things. If you do not want
+them to start, pass 0 as the flags parameter.
@@ -685,25 +701,42 @@ session_status status() const;
status() returns session wide-statistics and status. The session_status
struct has the following members:
+struct dht_lookup
+{
+ char const* type;
+ int outstanding_requests;
+ int timeouts;
+ int responses;
+ int branch_factor;
+};
+
struct session_status
{
bool has_incoming_connections;
float upload_rate;
float download_rate;
-
- float payload_upload_rate;
- float payload_download_rate;
-
size_type total_download;
size_type total_upload;
- size_type total_redundant_bytes;
- size_type total_failed_bytes;
-
+ float payload_upload_rate;
+ float payload_download_rate;
size_type total_payload_download;
size_type total_payload_upload;
+ float ip_overhead_upload_rate;
+ float ip_overhead_download_rate;
+ size_type total_ip_overhead_download;
+ size_type total_ip_overhead_upload;
+
+ float dht_upload_rate;
+ float dht_download_rate;
+ size_type total_dht_download;
+ size_type total_dht_upload;
+
+ size_type total_redundant_bytes;
+ size_type total_failed_bytes;
+
int num_peers;
int num_unchoked;
int allowed_upload_slots;
@@ -712,17 +745,26 @@ struct session_status
int dht_cache_nodes;
int dht_torrents;
int dht_global_nodes;
+ std::vector<dht_lookup> active_requests;
};
has_incoming_connections is false as long as no incoming connections have been
established on the listening socket. Every time you change the listen port, this will
be reset to false.
-
upload_rate, download_rate, payload_download_rate and payload_upload_rate
-are the total download and upload rates accumulated from all torrents. The payload
-versions is the payload download only.
+
upload_rate, download_rate are the total download and upload rates accumulated
+from all torrents. This includes bittorrent protocol, DHT and an estimated TCP/IP
+protocol overhead.
total_download and total_upload are the total number of bytes downloaded and
-uploaded to and from all torrents. total_payload_download and total_payload_upload
-are the same thing but where only the payload is considered.
+uploaded to and from all torrents. This also includes all the protocol overhead.
+
payload_download_rate and payload_upload_rate is the rate of the payload
+down- and upload only.
+
total_payload_download and total_payload_upload is the total transfers of payload
+only. The payload does not include the bittorrent protocol overhead, but only parts of the
+actual files to be downloaded.
+
ip_overhead_upload_rate, ip_overhead_download_rate, total_ip_overhead_download
+and total_ip_overhead_upload is the estimated TCP/IP overhead in each direction.
+
dht_upload_rate, dht_download_rate, total_dht_download and total_dht_upload
+is the DHT bandwidth usage.
total_redundant_bytes is the number of bytes that has been received more than once.
This can happen if a request from a peer times out and is requested from a different
peer, and then received again from the first one. To make this lower, increase the
@@ -746,6 +788,7 @@ becomes unresponsive.
dht_torrents are the number of torrents tracked by the DHT at the moment.
dht_global_nodes is an estimation of the total number of nodes in the DHT
network.
+
active_requests is a vector of the currently running DHT lookups.
@@ -3773,6 +3816,7 @@ public:
progress_notification =
implementation defined,
ip_block_notification =
implementation defined,
performance_warning =
implementation defined,
+ dht_notification =
implementation defined,
all_categories =
implementation defined
};
@@ -4200,6 +4244,32 @@ struct save_resume_data_failed_alert: torrent_alert
The handle_alert class is defined in <libtorrent/alert.hpp>.
Examples usage:
diff --git a/docs/manual.rst b/docs/manual.rst
index 08583341a..6e35e96bc 100644
--- a/docs/manual.rst
+++ b/docs/manual.rst
@@ -74,12 +74,14 @@ The ``session`` class has the following synopsis::
session(fingerprint const& print
= libtorrent::fingerprint(
- "LT", 0, 1, 0, 0));
+ "LT", 0, 1, 0, 0)
+ , int flags = start_default_features | add_default_plugins);
session(
fingerprint const& print
, std::pair
listen_port_range
- , char const* listen_interface = 0);
+ , char const* listen_interface = 0
+ , int flags = start_default_features | add_default_plugins);
torrent_handle add_torrent(add_torrent_params const& params);
@@ -95,6 +97,12 @@ The ``session`` class has the following synopsis::
delete_files = 1
};
+ enum session_flags_t
+ {
+ add_default_plugins = 1,
+ start_default_features = 2
+ };
+
void remove_torrent(torrent_handle const& h, int options = none);
torrent_handle find_torrent(sha_hash const& ih);
std::vector get_torrents() const;
@@ -176,10 +184,13 @@ session()
::
session(fingerprint const& print
- = libtorrent::fingerprint("LT", 0, 1, 0, 0));
+ = libtorrent::fingerprint("LT", 0, 1, 0, 0)
+ , int flags = start_default_features | add_default_plugins);
+
session(fingerprint const& print
, std::pair listen_port_range
- , char const* listen_interface = 0);
+ , char const* listen_interface = 0
+ , int flags = start_default_features | add_default_plugins);
If the fingerprint in the first overload is omited, the client will get a default
fingerprint stating the version of libtorrent. The fingerprint is a short string that will be
@@ -190,6 +201,10 @@ The other constructor, that takes a port range and an interface as well as the f
will automatically try to listen on a port on the given interface. For more information about
the parameters, see ``listen_on()`` function.
+The flags paramater can be used to start default features (upnp & nat-pmp) and default plugins
+(ut_metadata, ut_pex and smart_ban). The default is to start those things. If you do not want
+them to start, pass 0 as the flags parameter.
+
~session()
----------
diff --git a/include/libtorrent/session.hpp b/include/libtorrent/session.hpp
index a3fa9e5cd..f112253ea 100644
--- a/include/libtorrent/session.hpp
+++ b/include/libtorrent/session.hpp
@@ -155,6 +155,7 @@ namespace libtorrent
session(fingerprint const& print = fingerprint("LT"
, LIBTORRENT_VERSION_MAJOR, LIBTORRENT_VERSION_MINOR, 0, 0)
+ , int flags = start_default_features | add_default_plugins
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
, fs::path logpath = "."
#endif
@@ -163,6 +164,7 @@ namespace libtorrent
fingerprint const& print
, std::pair listen_port_range
, char const* listen_interface = "0.0.0.0"
+ , int flags = start_default_features | add_default_plugins
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
, fs::path logpath = "."
#endif
@@ -290,6 +292,12 @@ namespace libtorrent
delete_files = 1
};
+ enum session_flags_t
+ {
+ add_default_plugins = 1,
+ start_default_features = 2
+ };
+
void remove_torrent(const torrent_handle& h, int options = none);
void set_settings(session_settings const& s);
diff --git a/src/session.cpp b/src/session.cpp
index 3c65d02b5..b0db1d9ef 100644
--- a/src/session.cpp
+++ b/src/session.cpp
@@ -56,6 +56,9 @@ POSSIBILITY OF SUCH DAMAGE.
#pragma warning(pop)
#endif
+#include "libtorrent/extensions/ut_pex.hpp"
+#include "libtorrent/extensions/ut_metadata.hpp"
+#include "libtorrent/extensions/smart_ban.hpp"
#include "libtorrent/peer_id.hpp"
#include "libtorrent/torrent_info.hpp"
#include "libtorrent/tracker_manager.hpp"
@@ -112,6 +115,7 @@ namespace libtorrent
fingerprint const& id
, std::pair listen_port_range
, char const* listen_interface
+ , int flags
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
, fs::path logpath
#endif
@@ -120,7 +124,7 @@ namespace libtorrent
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
, logpath
#endif
- ))
+ ))
{
#ifdef TORRENT_MEMDEBUG
start_malloc_debug();
@@ -135,9 +139,23 @@ namespace libtorrent
boost::function0 test = boost::ref(*m_impl);
TORRENT_ASSERT(!test.empty());
#endif
+#ifndef TORRENT_DISABLE_EXTENSIONS
+ if (flags & add_default_plugins)
+ {
+ add_extension(create_ut_pex_plugin);
+ add_extension(create_ut_metadata_plugin);
+ add_extension(create_smart_ban_plugin);
+ }
+#endif
+ if (flags & start_default_features)
+ {
+ start_upnp();
+ start_upnp();
+ }
}
session::session(fingerprint const& id
+ , int flags
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
, fs::path logpath
#endif
@@ -155,6 +173,19 @@ namespace libtorrent
boost::function0 test = boost::ref(*m_impl);
TORRENT_ASSERT(!test.empty());
#endif
+#ifndef TORRENT_DISABLE_EXTENSIONS
+ if (flags & add_default_plugins)
+ {
+ add_extension(create_ut_pex_plugin);
+ add_extension(create_ut_metadata_plugin);
+ add_extension(create_smart_ban_plugin);
+ }
+#endif
+ if (flags & start_default_features)
+ {
+ start_upnp();
+ start_natpmp();
+ }
}
session::~session()
@@ -170,10 +201,12 @@ namespace libtorrent
m_impl->abort();
}
+#ifndef TORRENT_DISABLE_EXTENSIONS
void session::add_extension(boost::function(torrent*, void*)> ext)
{
m_impl->add_extension(ext);
}
+#endif
#ifndef TORRENT_DISABLE_GEO_IP
bool session::load_asnum_db(char const* file)
diff --git a/src/session_impl.cpp b/src/session_impl.cpp
index 9a4e0e395..3a7c5d22e 100644
--- a/src/session_impl.cpp
+++ b/src/session_impl.cpp
@@ -51,6 +51,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include
#include
#include
+#include
#ifdef _MSC_VER
#pragma warning(pop)
@@ -386,6 +387,17 @@ namespace aux {
void session_impl::add_extension(
boost::function(torrent*, void*)> ext)
{
+ TORRENT_ASSERT(ext);
+
+ typedef boost::shared_ptr(*function_t)(torrent*, void*);
+ function_t const* f = ext.target();
+
+ if (f)
+ {
+ for (extension_list_t::iterator i = m_extensions.begin(); i != m_extensions.end(); ++i)
+ if (function_equal(*i, *f)) return;
+ }
+
m_extensions.push_back(ext);
}
#endif
@@ -2482,7 +2494,7 @@ namespace aux {
++total_downloaders;
unique.insert(i->second->queue_position());
}
- TORRENT_ASSERT(unique.size() == total_downloaders);
+ TORRENT_ASSERT(unique.size() == int(total_downloaders));
TORRENT_ASSERT(m_max_connections > 0);
TORRENT_ASSERT(m_max_uploads > 0);