From dc2e25141ce2616299124b36730d6730c940f0b9 Mon Sep 17 00:00:00 2001
From: Arvid Norberg
Date: Mon, 4 Sep 2006 23:22:21 +0000
Subject: [PATCH] changed sequencial download threshold api, it is now per
torrent
---
docs/manual.html | 12 ++++
docs/manual.rst | 14 +++++
include/Makefile.am | 1 +
include/libtorrent/kademlia/dht_tracker.hpp | 3 +
include/libtorrent/kademlia/node.hpp | 1 +
include/libtorrent/session.hpp | 20 +-----
include/libtorrent/session_status.hpp | 68 +++++++++++++++++++++
src/kademlia/dht_tracker.cpp | 6 ++
src/session.cpp | 13 ++++
9 files changed, 119 insertions(+), 19 deletions(-)
create mode 100644 include/libtorrent/session_status.hpp
diff --git a/docs/manual.html b/docs/manual.html
index 6bc94fd37..725083753 100755
--- a/docs/manual.html
+++ b/docs/manual.html
@@ -473,6 +473,10 @@ struct session_status
size_type total_payload_upload;
int num_peers;
+
+ int dht_nodes;
+ int dht_cache_nodes;
+ int dht_torrents;
};
has_incoming_connections is false as long as no incoming connections have been
@@ -485,6 +489,14 @@ versions is the payload download only.
uploaded to and from all torrents. total_payload_download and total_payload_upload
are the same thing but where only the payload is considered.
num_peers is the total number of peer connections this session have.
+dht_nodes, dht_cache_nodes and dht_torrents are only available when
+built with DHT support. They are all set to 0 if the DHT isn't running. When
+the DHT is running, dht_nodes is set to the number of nodes in the routing
+table. This number only includes active nodes, not cache nodes. The
+dht_cache_nodes is set to the number of nodes in the node cache. These nodes
+are used to replace the regular nodes in the routing table in case any of them
+becomes unresponsive.
+dht_torrents are the number of torrents tracked by the DHT at the moment.
diff --git a/docs/manual.rst b/docs/manual.rst
index f7e96341d..06b63def9 100755
--- a/docs/manual.rst
+++ b/docs/manual.rst
@@ -334,6 +334,10 @@ struct has the following members::
size_type total_payload_upload;
int num_peers;
+
+ int dht_nodes;
+ int dht_cache_nodes;
+ int dht_torrents;
};
``has_incoming_connections`` is false as long as no incoming connections have been
@@ -350,6 +354,16 @@ are the same thing but where only the payload is considered.
``num_peers`` is the total number of peer connections this session have.
+``dht_nodes``, ``dht_cache_nodes`` and ``dht_torrents`` are only available when
+built with DHT support. They are all set to 0 if the DHT isn't running. When
+the DHT is running, ``dht_nodes`` is set to the number of nodes in the routing
+table. This number only includes *active* nodes, not cache nodes. The
+``dht_cache_nodes`` is set to the number of nodes in the node cache. These nodes
+are used to replace the regular nodes in the routing table in case any of them
+becomes unresponsive.
+
+``dht_torrents`` are the number of torrents tracked by the DHT at the moment.
+
is_listening() listen_port() listen_on()
----------------------------------------
diff --git a/include/Makefile.am b/include/Makefile.am
index 0a85c3154..eff167880 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -29,6 +29,7 @@ libtorrent/random_sample.hpp \
libtorrent/resource_request.hpp \
libtorrent/session.hpp \
libtorrent/session_settings.hpp \
+libtorrent/session_status.hpp \
libtorrent/size_type.hpp \
libtorrent/socket.hpp \
libtorrent/stat.hpp \
diff --git a/include/libtorrent/kademlia/dht_tracker.hpp b/include/libtorrent/kademlia/dht_tracker.hpp
index c5c1abfdc..273196e0b 100644
--- a/include/libtorrent/kademlia/dht_tracker.hpp
+++ b/include/libtorrent/kademlia/dht_tracker.hpp
@@ -51,6 +51,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/kademlia/traversal_algorithm.hpp"
#include "libtorrent/kademlia/packet_iterator.hpp"
#include "libtorrent/session_settings.hpp"
+#include "libtorrent/session_status.hpp"
namespace libtorrent { namespace dht
{
@@ -75,6 +76,8 @@ namespace libtorrent { namespace dht
, boost::function
const&
, sha1_hash const&)> f);
+ void dht_status(session_status& s);
+
private:
void on_name_lookup(asio::error const& e
diff --git a/include/libtorrent/kademlia/node.hpp b/include/libtorrent/kademlia/node.hpp
index 5b9c4cdce..e5660c03d 100644
--- a/include/libtorrent/kademlia/node.hpp
+++ b/include/libtorrent/kademlia/node.hpp
@@ -118,6 +118,7 @@ public:
data_iterator begin_data() { return m_map.begin(); }
data_iterator end_data() { return m_map.end(); }
+ int data_size() const { return int(m_map.size()); }
void print_state(std::ostream& os) const
{ m_table.print_state(os); }
diff --git a/include/libtorrent/session.hpp b/include/libtorrent/session.hpp
index 17196405e..cbfa23b0c 100755
--- a/include/libtorrent/session.hpp
+++ b/include/libtorrent/session.hpp
@@ -73,6 +73,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/session_settings.hpp"
#include "libtorrent/version.hpp"
#include "libtorrent/kademlia/dht_tracker.hpp"
+#include "libtorrent/session_status.hpp"
#if !defined(NDEBUG) && defined(_MSC_VER)
# include
@@ -326,25 +327,6 @@ namespace libtorrent
};
}
- struct TORRENT_EXPORT 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_payload_download;
- size_type total_payload_upload;
-
- int num_peers;
- };
-
class TORRENT_EXPORT session: public boost::noncopyable, detail::eh_initializer
{
public:
diff --git a/include/libtorrent/session_status.hpp b/include/libtorrent/session_status.hpp
new file mode 100644
index 000000000..7d12674fd
--- /dev/null
+++ b/include/libtorrent/session_status.hpp
@@ -0,0 +1,68 @@
+/*
+
+Copyright (c) 2006, Arvid Norberg
+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.
+
+*/
+
+#ifndef TORRENT_SESSION_STATUS_HPP_INCLUDED
+#define TORRENT_SESSION_STATUS_HPP_INCLUDED
+
+
+namespace libtorrent
+{
+
+ struct TORRENT_EXPORT 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_payload_download;
+ size_type total_payload_upload;
+
+ int num_peers;
+
+#ifndef TORRENT_DISABLE_DHT
+ int m_dht_nodes;
+ int m_dht_node_cache;
+ int m_dht_torrents;
+#endif
+ };
+
+}
+
+#endif // TORRENT_SESSION_STATUS_HPP_INCLUDED
+
diff --git a/src/kademlia/dht_tracker.cpp b/src/kademlia/dht_tracker.cpp
index 96df9a3cf..44cf8272e 100644
--- a/src/kademlia/dht_tracker.cpp
+++ b/src/kademlia/dht_tracker.cpp
@@ -196,6 +196,12 @@ namespace libtorrent { namespace dht
m_refresh_timer.async_wait(bind(&dht_tracker::refresh_timeout, this, _1));
}
+ void dht_tracker::dht_status(session_status& s)
+ {
+ boost::tie(s.m_dht_nodes, s.m_dht_node_cache) = m_dht.size();
+ s.m_dht_torrents = m_dht.data_size();
+ }
+
void dht_tracker::connection_timeout(asio::error const& e)
try
{
diff --git a/src/session.cpp b/src/session.cpp
index a64fb34fe..4f27bd6eb 100755
--- a/src/session.cpp
+++ b/src/session.cpp
@@ -1464,6 +1464,19 @@ namespace libtorrent
s.total_payload_download = m_impl.m_stat.total_payload_download();
s.total_payload_upload = m_impl.m_stat.total_payload_upload();
+#ifndef TORRENT_DISABLE_DHT
+ if (m_impl.m_dht)
+ {
+ m_impl.m_dht->dht_status(s);
+ }
+ else
+ {
+ s.m_dht_nodes = 0;
+ s.m_dht_node_cache = 0;
+ s.m_dht_torrents = 0;
+ }
+#endif
+
return s;
}