move dht_settings into its own header cpp file-pair and dht_settings into the dht namespace

This commit is contained in:
arvidn 2017-09-02 23:58:10 +02:00 committed by Arvid Norberg
parent 95c8c3018a
commit bb51dcdbb9
41 changed files with 411 additions and 349 deletions

View File

@ -155,6 +155,7 @@ set(kademlia_sources
get_item
ed25519
sample_infohashes
dht_settings
)
# -- ed25519 --

View File

@ -693,6 +693,7 @@ KADEMLIA_SOURCES =
put_data
ed25519
sample_infohashes
dht_settings
;
ED25519_SOURCES =

View File

@ -98,27 +98,27 @@ void bind_session_settings()
#endif
#ifndef TORRENT_DISABLE_DHT
class_<dht_settings>("dht_settings")
.def_readwrite("max_peers_reply", &dht_settings::max_peers_reply)
.def_readwrite("search_branching", &dht_settings::search_branching)
class_<dht::dht_settings>("dht_settings")
.def_readwrite("max_peers_reply", &dht::dht_settings::max_peers_reply)
.def_readwrite("search_branching", &dht::dht_settings::search_branching)
#ifndef TORRENT_NO_DEPRECATE
.def_readwrite("service_port", &dht_settings::service_port)
.def_readwrite("service_port", &dht::dht_settings::service_port)
#endif
.def_readwrite("max_fail_count", &dht_settings::max_fail_count)
.def_readwrite("max_torrents", &dht_settings::max_torrents)
.def_readwrite("max_dht_items", &dht_settings::max_dht_items)
.def_readwrite("restrict_routing_ips", &dht_settings::restrict_routing_ips)
.def_readwrite("restrict_search_ips", &dht_settings::restrict_search_ips)
.def_readwrite("max_torrent_search_reply", &dht_settings::max_torrent_search_reply)
.def_readwrite("extended_routing_table", &dht_settings::extended_routing_table)
.def_readwrite("aggressive_lookups", &dht_settings::aggressive_lookups)
.def_readwrite("privacy_lookups", &dht_settings::privacy_lookups)
.def_readwrite("enforce_node_id", &dht_settings::enforce_node_id)
.def_readwrite("ignore_dark_internet", &dht_settings::ignore_dark_internet)
.def_readwrite("block_timeout", &dht_settings::block_timeout)
.def_readwrite("block_ratelimit", &dht_settings::block_ratelimit)
.def_readwrite("read_only", &dht_settings::read_only)
.def_readwrite("item_lifetime", &dht_settings::item_lifetime)
.def_readwrite("max_fail_count", &dht::dht_settings::max_fail_count)
.def_readwrite("max_torrents", &dht::dht_settings::max_torrents)
.def_readwrite("max_dht_items", &dht::dht_settings::max_dht_items)
.def_readwrite("restrict_routing_ips", &dht::dht_settings::restrict_routing_ips)
.def_readwrite("restrict_search_ips", &dht::dht_settings::restrict_search_ips)
.def_readwrite("max_torrent_search_reply", &dht::dht_settings::max_torrent_search_reply)
.def_readwrite("extended_routing_table", &dht::dht_settings::extended_routing_table)
.def_readwrite("aggressive_lookups", &dht::dht_settings::aggressive_lookups)
.def_readwrite("privacy_lookups", &dht::dht_settings::privacy_lookups)
.def_readwrite("enforce_node_id", &dht::dht_settings::enforce_node_id)
.def_readwrite("ignore_dark_internet", &dht::dht_settings::ignore_dark_internet)
.def_readwrite("block_timeout", &dht::dht_settings::block_timeout)
.def_readwrite("block_ratelimit", &dht::dht_settings::block_ratelimit)
.def_readwrite("read_only", &dht::dht_settings::read_only)
.def_readwrite("item_lifetime", &dht::dht_settings::item_lifetime)
;
#endif

View File

@ -6,7 +6,6 @@
#include <memory>
#include "libtorrent/torrent_info.hpp"
#include "libtorrent/session_settings.hpp"
#include "libtorrent/time.hpp"
#include "libtorrent/socket_io.hpp"
#include "libtorrent/announce_entry.hpp"

View File

@ -128,11 +128,6 @@ namespace aux {
struct tracker_logger;
#endif
#ifndef TORRENT_DISABLE_DHT
TORRENT_EXTRA_EXPORT dht_settings read_dht_settings(bdecode_node const& e);
TORRENT_EXTRA_EXPORT entry save_dht_settings(dht_settings const& settings);
#endif
struct listen_socket_t
{
listen_socket_t()
@ -371,8 +366,8 @@ namespace aux {
void add_dht_node_name(std::pair<std::string, int> const& node);
void add_dht_node(udp::endpoint const& n) override;
void add_dht_router(std::pair<std::string, int> const& node);
void set_dht_settings(dht_settings const& s);
dht_settings const& get_dht_settings() const { return m_dht_settings; }
void set_dht_settings(dht::dht_settings const& s);
dht::dht_settings const& get_dht_settings() const { return m_dht_settings; }
void set_dht_state(dht::dht_state state);
void set_dht_storage(dht::dht_storage_constructor_type sc);
void start_dht();
@ -1039,7 +1034,7 @@ namespace aux {
#ifndef TORRENT_DISABLE_DHT
std::unique_ptr<dht::dht_storage_interface> m_dht_storage;
std::shared_ptr<dht::dht_tracker> m_dht;
dht_settings m_dht_settings;
dht::dht_settings m_dht_settings;
dht::dht_storage_constructor_type m_dht_storage_constructor
= dht::dht_default_storage_constructor;
@ -1156,9 +1151,6 @@ namespace aux {
#endif
// mask is a bitmask of which protocols to remap on:
// 1: NAT-PMP
// 2: UPnP
// TODO: 3 perhaps this function should move into listen_socket_t
enum remap_port_mask_t
{
remap_natpmp = 1,

View File

@ -204,7 +204,6 @@ class session;
struct session_handle;
// include/libtorrent/session_settings.hpp
struct dht_settings;
struct pe_settings;
// include/libtorrent/session_stats.hpp
@ -239,6 +238,9 @@ struct torrent_status;
namespace dht {
// include/libtorrent/kademlia/dht_settings.hpp
struct dht_settings;
// include/libtorrent/kademlia/dht_state.hpp
struct dht_state;

View File

@ -54,7 +54,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/deadline_timer.hpp"
#include "libtorrent/assert.hpp"
#include "libtorrent/socket_type.hpp"
#include "libtorrent/session_settings.hpp"
#include "libtorrent/i2p_stream.hpp"
#include "libtorrent/aux_/vector.hpp"
#include "libtorrent/resolver_interface.hpp"

View File

@ -43,9 +43,9 @@ POSSIBILITY OF SUCH DAMAGE.
#include <functional>
#include "libtorrent/proxy_base.hpp"
#include "libtorrent/session_settings.hpp"
#include "libtorrent/string_util.hpp"
#include "libtorrent/aux_/vector.hpp"
#include "libtorrent/aux_/proxy_settings.hpp"
namespace libtorrent {

View File

@ -35,10 +35,13 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp"
#include "libtorrent/address.hpp"
#include "libtorrent/string_view.hpp"
#include "libtorrent/kademlia/msg.hpp"
namespace libtorrent {
class entry;
namespace aux { struct listen_socket_handle; }
namespace dht {

View File

@ -0,0 +1,176 @@
/*
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_DHT_SETTINGS_HPP_INCLUDED
#define TORRENT_DHT_SETTINGS_HPP_INCLUDED
#include "libtorrent/config.hpp"
#include "libtorrent/bdecode.hpp"
#include "libtorrent/entry.hpp"
namespace libtorrent {
namespace dht {
// structure used to hold configuration options for the DHT
//
// The ``dht_settings`` struct used to contain a ``service_port`` member to
// control which port the DHT would listen on and send messages from. This
// field is deprecated and ignored. libtorrent always tries to open the UDP
// socket on the same port as the TCP socket.
struct TORRENT_EXPORT dht_settings
{
// the maximum number of peers to send in a reply to ``get_peers``
int max_peers_reply = 100;
// the number of concurrent search request the node will send when
// announcing and refreshing the routing table. This parameter is called
// alpha in the kademlia paper
int search_branching = 5;
// the maximum number of failed tries to contact a node before it is
// removed from the routing table. If there are known working nodes that
// are ready to replace a failing node, it will be replaced immediately,
// this limit is only used to clear out nodes that don't have any node
// that can replace them.
int max_fail_count = 20;
// the total number of torrents to track from the DHT. This is simply an
// upper limit to make sure malicious DHT nodes cannot make us allocate
// an unbounded amount of memory.
int max_torrents = 2000;
// max number of items the DHT will store
int max_dht_items = 700;
// the max number of peers to store per torrent (for the DHT)
int max_peers = 500;
// the max number of torrents to return in a torrent search query to the
// DHT
int max_torrent_search_reply = 20;
// determines if the routing table entries should restrict entries to one
// per IP. This defaults to true, which helps mitigate some attacks on
// the DHT. It prevents adding multiple nodes with IPs with a very close
// CIDR distance.
//
// when set, nodes whose IP address that's in the same /24 (or /64 for
// IPv6) range in the same routing table bucket. This is an attempt to
// mitigate node ID spoofing attacks also restrict any IP to only have a
// single entry in the whole routing table
bool restrict_routing_ips = true;
// determines if DHT searches should prevent adding nodes with IPs with
// very close CIDR distance. This also defaults to true and helps
// mitigate certain attacks on the DHT.
bool restrict_search_ips = true;
// makes the first buckets in the DHT routing table fit 128, 64, 32 and
// 16 nodes respectively, as opposed to the standard size of 8. All other
// buckets have size 8 still.
bool extended_routing_table = true;
// slightly changes the lookup behavior in terms of how many outstanding
// requests we keep. Instead of having branch factor be a hard limit, we
// always keep *branch factor* outstanding requests to the closest nodes.
// i.e. every time we get results back with closer nodes, we query them
// right away. It lowers the lookup times at the cost of more outstanding
// queries.
bool aggressive_lookups = true;
// when set, perform lookups in a way that is slightly more expensive,
// but which minimizes the amount of information leaked about you.
bool privacy_lookups = false;
// when set, node's whose IDs that are not correctly generated based on
// its external IP are ignored. When a query arrives from such node, an
// error message is returned with a message saying "invalid node ID".
bool enforce_node_id = false;
// ignore DHT messages from parts of the internet we wouldn't expect to
// see any traffic from
bool ignore_dark_internet = true;
// the number of seconds a DHT node is banned if it exceeds the rate
// limit. The rate limit is averaged over 10 seconds to allow for bursts
// above the limit.
int block_timeout = 5 * 60;
// the max number of packets per second a DHT node is allowed to send
// without getting banned.
int block_ratelimit = 5;
// when set, the other nodes won't keep this node in their routing
// tables, it's meant for low-power and/or ephemeral devices that
// cannot support the DHT, it is also useful for mobile devices which
// are sensitive to network traffic and battery life.
// this node no longer responds to 'query' messages, and will place a
// 'ro' key (value = 1) in the top-level message dictionary of outgoing
// query messages.
bool read_only = false;
// the number of seconds a immutable/mutable item will be expired.
// default is 0, means never expires.
int item_lifetime = 0;
// the number of bytes per second (on average) the DHT is allowed to send.
// If the incoming requests causes to many bytes to be sent in responses,
// incoming requests will be dropped until the quota has been replenished.
int upload_rate_limit = 8000;
// the info-hashes sample recomputation interval (in seconds).
// The node will precompute a subset of the tracked info-hashes and return
// that instead of calculating it upon each request. The permissible range
// is between 0 and 21600 seconds (inclusive).
int sample_infohashes_interval = 21600;
// the maximum number of elements in the sampled subset of info-hashes.
// If this number is too big, expect the DHT storage implementations
// to clamp it in order to allow UDP packets go through
int max_infohashes_sample_count = 20;
#ifndef TORRENT_NO_DEPRECATE
// the listen port for the dht. This is a UDP port. zero means use the
// same as the tcp interface
int service_port = 0;
#endif
};
TORRENT_EXTRA_EXPORT dht_settings read_dht_settings(bdecode_node const& e);
TORRENT_EXTRA_EXPORT entry save_dht_settings(dht_settings const& settings);
}
}
#endif

View File

@ -45,11 +45,12 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent {
struct dht_settings;
class entry;
}
namespace libtorrent { namespace dht {
struct dht_settings;
// This structure hold the relevant counters for the storage
struct TORRENT_EXPORT dht_storage_counters
{

View File

@ -45,17 +45,18 @@ POSSIBILITY OF SUCH DAMAGE.
#include <libtorrent/span.hpp>
#include <libtorrent/io_service.hpp>
#include <libtorrent/udp_socket.hpp>
#include <libtorrent/entry.hpp>
namespace libtorrent {
struct counters;
struct dht_settings;
#ifndef TORRENT_NO_DEPRECATE
struct session_status;
#endif
}
namespace libtorrent { namespace dht {
struct dht_settings;
struct TORRENT_EXTRA_EXPORT dht_tracker final
: socket_manager
@ -149,7 +150,7 @@ namespace libtorrent { namespace dht {
{
tracker_node(io_service& ios
, aux::listen_socket_handle const& s, socket_manager* sock
, libtorrent::dht_settings const& settings
, dht_settings const& settings
, node_id const& nid
, dht_observer* observer, counters& cnt
, get_foreign_node_t get_foreign_node

View File

@ -40,6 +40,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <libtorrent/config.hpp>
#include <libtorrent/kademlia/dht_storage.hpp>
#include <libtorrent/kademlia/dht_settings.hpp>
#include <libtorrent/kademlia/routing_table.hpp>
#include <libtorrent/kademlia/rpc_manager.hpp>
#include <libtorrent/kademlia/node_id.hpp>
@ -54,7 +55,6 @@ namespace libtorrent {
struct counters;
struct dht_routing_bucket;
struct dht_settings;
}
namespace libtorrent { namespace dht {
@ -91,7 +91,7 @@ class TORRENT_EXTRA_EXPORT node : boost::noncopyable
{
public:
node(aux::listen_socket_handle const& sock, socket_manager* sock_man
, libtorrent::dht_settings const& settings
, dht_settings const& settings
, node_id const& nid
, dht_observer* observer, counters& cnt
, get_foreign_node_t get_foreign_node
@ -194,7 +194,7 @@ public:
void status(libtorrent::session_status& s);
#endif
libtorrent::dht_settings const& settings() const { return m_settings; }
dht_settings const& settings() const { return m_settings; }
counters& stats_counters() const { return m_counters; }
dht_observer* observer() const { return m_observer; }
@ -220,7 +220,7 @@ private:
bool lookup_peers(sha1_hash const& info_hash, entry& reply
, bool noseed, bool scrape, address const& requester) const;
libtorrent::dht_settings const& m_settings;
dht_settings const& m_settings;
std::mutex m_mutex;

View File

@ -42,7 +42,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <libtorrent/kademlia/node_id.hpp>
#include <libtorrent/kademlia/node_entry.hpp>
#include <libtorrent/session_settings.hpp>
#include <libtorrent/assert.hpp>
#include <libtorrent/time.hpp>
#include <libtorrent/aux_/vector.hpp>
@ -57,6 +56,7 @@ namespace libtorrent {
namespace libtorrent { namespace dht {
struct dht_settings;
struct dht_logger;
typedef aux::vector<node_entry> bucket_t;

View File

@ -46,10 +46,12 @@ POSSIBILITY OF SUCH DAMAGE.
#include <libtorrent/kademlia/observer.hpp>
#include <libtorrent/aux_/listen_socket_handle.hpp>
namespace libtorrent { struct dht_settings; class entry; }
namespace libtorrent { class entry; }
namespace libtorrent { namespace dht {
namespace libtorrent {
namespace dht {
struct dht_settings;
struct dht_logger;
struct socket_manager;

View File

@ -42,6 +42,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <libtorrent/kademlia/observer.hpp>
#include <libtorrent/address.hpp>
#include <libtorrent/flags.hpp>
#include <libtorrent/bdecode.hpp>
namespace libtorrent {

View File

@ -40,7 +40,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/io_service.hpp"
#include "libtorrent/settings_pack.hpp"
#include "libtorrent/session_handle.hpp"
#include "libtorrent/session_settings.hpp" // for dht_settings
#include "libtorrent/kademlia/dht_settings.hpp"
#include "libtorrent/kademlia/dht_state.hpp"
#include "libtorrent/kademlia/dht_storage.hpp"
@ -153,7 +153,7 @@ namespace aux {
std::vector<std::shared_ptr<plugin>> extensions;
libtorrent::dht_settings dht_settings;
dht::dht_settings dht_settings;
dht::dht_state dht_state;

View File

@ -47,6 +47,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/portmap.hpp" // for portmap_protocol
#include "libtorrent/kademlia/dht_storage.hpp"
#include "libtorrent/kademlia/dht_settings.hpp"
#ifndef TORRENT_NO_DEPRECATE
#include "libtorrent/session_settings.hpp"
@ -332,9 +333,9 @@ namespace libtorrent {
// otherwise.
//
// ``get_dht_settings()`` returns the current settings
void set_dht_settings(dht_settings const& settings);
void set_dht_settings(dht::dht_settings const& settings);
bool is_dht_running() const;
dht_settings get_dht_settings() const;
dht::dht_settings get_dht_settings() const;
// ``set_dht_storage`` set a dht custom storage constructor function
// to be used internally when the dht is created.

View File

@ -33,179 +33,24 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_SESSION_SETTINGS_HPP_INCLUDED
#define TORRENT_SESSION_SETTINGS_HPP_INCLUDED
#ifndef TORRENT_NO_DEPRECATE
#include "libtorrent/config.hpp"
#include "libtorrent/settings_pack.hpp"
#include "libtorrent/aux_/proxy_settings.hpp"
#ifndef TORRENT_NO_DEPRECATE
#include "libtorrent/version.hpp"
#endif
#include "libtorrent/kademlia/dht_settings.hpp"
#include <string>
namespace libtorrent {
#ifndef TORRENT_NO_DEPRECATE
using dht_settings = dht::dht_settings;
using aux::proxy_settings;
#endif
// structure used to hold configuration options for the DHT
//
// The ``dht_settings`` struct used to contain a ``service_port`` member to
// control which port the DHT would listen on and send messages from. This
// field is deprecated and ignored. libtorrent always tries to open the UDP
// socket on the same port as the TCP socket.
struct TORRENT_EXPORT dht_settings
{
// initialized dht_settings to the default values
dht_settings()
: max_peers_reply(100)
, search_branching(5)
#ifndef TORRENT_NO_DEPRECATE
, service_port(0)
#endif
, max_fail_count(20)
, max_torrents(2000)
, max_dht_items(700)
, max_peers(5000)
, max_torrent_search_reply(20)
, restrict_routing_ips(true)
, restrict_search_ips(true)
, extended_routing_table(true)
, aggressive_lookups(true)
, privacy_lookups(false)
, enforce_node_id(false)
, ignore_dark_internet(true)
, block_timeout(5 * 60)
, block_ratelimit(5)
, read_only(false)
, item_lifetime(0)
, upload_rate_limit(8000)
{}
// the maximum number of peers to send in a reply to ``get_peers``
int max_peers_reply;
// the number of concurrent search request the node will send when
// announcing and refreshing the routing table. This parameter is called
// alpha in the kademlia paper
int search_branching;
#ifndef TORRENT_NO_DEPRECATE
// the listen port for the dht. This is a UDP port. zero means use the
// same as the tcp interface
int service_port;
#endif
// the maximum number of failed tries to contact a node before it is
// removed from the routing table. If there are known working nodes that
// are ready to replace a failing node, it will be replaced immediately,
// this limit is only used to clear out nodes that don't have any node
// that can replace them.
int max_fail_count;
// the total number of torrents to track from the DHT. This is simply an
// upper limit to make sure malicious DHT nodes cannot make us allocate
// an unbounded amount of memory.
int max_torrents;
// max number of items the DHT will store
int max_dht_items;
// the max number of peers to store per torrent (for the DHT)
int max_peers;
// the max number of torrents to return in a torrent search query to the
// DHT
int max_torrent_search_reply;
// determines if the routing table entries should restrict entries to one
// per IP. This defaults to true, which helps mitigate some attacks on
// the DHT. It prevents adding multiple nodes with IPs with a very close
// CIDR distance.
//
// when set, nodes whose IP address that's in the same /24 (or /64 for
// IPv6) range in the same routing table bucket. This is an attempt to
// mitigate node ID spoofing attacks also restrict any IP to only have a
// single entry in the whole routing table
bool restrict_routing_ips;
// determines if DHT searches should prevent adding nodes with IPs with
// very close CIDR distance. This also defaults to true and helps
// mitigate certain attacks on the DHT.
bool restrict_search_ips;
// makes the first buckets in the DHT routing table fit 128, 64, 32 and
// 16 nodes respectively, as opposed to the standard size of 8. All other
// buckets have size 8 still.
bool extended_routing_table;
// slightly changes the lookup behavior in terms of how many outstanding
// requests we keep. Instead of having branch factor be a hard limit, we
// always keep *branch factor* outstanding requests to the closest nodes.
// i.e. every time we get results back with closer nodes, we query them
// right away. It lowers the lookup times at the cost of more outstanding
// queries.
bool aggressive_lookups;
// when set, perform lookups in a way that is slightly more expensive,
// but which minimizes the amount of information leaked about you.
bool privacy_lookups;
// when set, node's whose IDs that are not correctly generated based on
// its external IP are ignored. When a query arrives from such node, an
// error message is returned with a message saying "invalid node ID".
bool enforce_node_id;
// ignore DHT messages from parts of the internet we wouldn't expect to
// see any traffic from
bool ignore_dark_internet;
// the number of seconds a DHT node is banned if it exceeds the rate
// limit. The rate limit is averaged over 10 seconds to allow for bursts
// above the limit.
int block_timeout;
// the max number of packets per second a DHT node is allowed to send
// without getting banned.
int block_ratelimit;
// when set, the other nodes won't keep this node in their routing
// tables, it's meant for low-power and/or ephemeral devices that
// cannot support the DHT, it is also useful for mobile devices which
// are sensitive to network traffic and battery life.
// this node no longer responds to 'query' messages, and will place a
// 'ro' key (value = 1) in the top-level message dictionary of outgoing
// query messages.
bool read_only;
// the number of seconds a immutable/mutable item will be expired.
// default is 0, means never expires.
int item_lifetime;
// the number of bytes per second (on average) the DHT is allowed to send.
// If the incoming requests causes to many bytes to be sent in responses,
// incoming requests will be dropped until the quota has been replenished.
int upload_rate_limit;
// the info-hashes sample recomputation interval (in seconds).
// The node will precompute a subset of the tracked info-hashes and return
// that instead of calculating it upon each request. The permissible range
// is between 0 and 21600 seconds (inclusive).
int sample_infohashes_interval = 21600;
// the maximum number of elements in the sampled subset of info-hashes.
// If this number is too big, expect the DHT storage implementations
// to clamp it in order to allow UDP packets go through
int max_infohashes_sample_count = 20;
};
#ifndef TORRENT_NO_DEPRECATE
// The ``pe_settings`` structure is used to control the settings related
// to peer protocol encryption.
struct TORRENT_EXPORT pe_settings
struct TORRENT_DEPRECATED_EXPORT pe_settings
{
// initializes the encryption settings with the default values
pe_settings()
@ -262,8 +107,7 @@ namespace libtorrent {
// otherwise
bool prefer_rc4;
};
#endif // TORRENT_NO_DEPRECATE
}
#endif // TORRENT_NO_DEPRECATE
#endif

View File

@ -30,7 +30,7 @@ POSSIBILITY OF SUCH DAMAGE.
*/
#include "libtorrent/session_settings.hpp"
#include "libtorrent/kademlia/dht_settings.hpp"
#include "libtorrent/io_service.hpp"
#include "libtorrent/deadline_timer.hpp"
#include "libtorrent/address.hpp"
@ -89,7 +89,7 @@ namespace {
struct dht_node final : lt::dht::socket_manager
{
dht_node(sim::simulation& sim, lt::dht_settings const& sett, lt::counters& cnt
dht_node(sim::simulation& sim, lt::dht::dht_settings const& sett, lt::counters& cnt
, int const idx, std::uint32_t const flags)
: m_io_service(sim, (flags & dht_network::bind_ipv6) ? addr6_from_int(idx) : addr_from_int(idx))
, m_dht_storage(lt::dht::dht_default_storage_constructor(sett))

View File

@ -35,7 +35,7 @@ POSSIBILITY OF SUCH DAMAGE.
#define TORRENT_SETUP_DHT_HPP_INCLUDED
#include <vector>
#include "libtorrent/session_settings.hpp" // for dht_settings
#include "libtorrent/kademlia/dht_settings.hpp" // for dht_settings
#include "libtorrent/performance_counters.hpp" // for counters
@ -71,7 +71,7 @@ private:
// used for all the nodes in the network
lt::counters m_cnt;
lt::dht_settings m_sett;
lt::dht::dht_settings m_sett;
std::list<dht_node> m_nodes;
};

View File

@ -31,7 +31,6 @@ POSSIBILITY OF SUCH DAMAGE.
*/
#include "libtorrent/session.hpp"
#include "libtorrent/session_settings.hpp"
#include "libtorrent/io_service.hpp"
#include "libtorrent/deadline_timer.hpp"
#include "libtorrent/address.hpp"

View File

@ -37,7 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/alert.hpp"
#include "libtorrent/time.hpp"
#include "libtorrent/settings_pack.hpp"
#include "libtorrent/session_settings.hpp"
#include "libtorrent/kademlia/dht_settings.hpp"
#include "libtorrent/session.hpp"
#include "libtorrent/session_stats.hpp"
#include "libtorrent/alert_types.hpp"
@ -53,7 +53,7 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_DISABLE_DHT
void bootstrap_session(std::vector<dht_network*> networks, lt::session& ses)
{
lt::dht_settings sett;
lt::dht::dht_settings sett;
sett.ignore_dark_internet = false;
ses.set_dht_settings(sett);

View File

@ -41,7 +41,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/kademlia/dht_state.hpp"
#include "libtorrent/performance_counters.hpp"
#include "libtorrent/entry.hpp"
#include "libtorrent/session_settings.hpp"
#include "libtorrent/kademlia/dht_settings.hpp"
#include "libtorrent/span.hpp"
#include "libtorrent/kademlia/dht_observer.hpp"
@ -109,7 +109,7 @@ TORRENT_TEST(dht_rate_limit)
ls->local_endpoint = tcp::endpoint(address_v4::from_string("40.30.20.10"), 8888);
error_code ec;
sock.bind(udp::endpoint(address_v4::from_string("40.30.20.10"), 8888), ec);
dht_settings dhtsett;
dht::dht_settings dhtsett;
dhtsett.block_ratelimit = 100000; // disable the DOS blocker
dhtsett.ignore_dark_internet = false;
dhtsett.upload_rate_limit = 400;
@ -235,7 +235,7 @@ TORRENT_TEST(dht_delete_socket)
auto ls = std::make_shared<lt::aux::listen_socket_t>();
ls->external_address.cast_vote(address_v4::from_string("40.30.20.10"), 1, lt::address());
ls->local_endpoint = tcp::endpoint(address_v4::from_string("40.30.20.10"), 8888);
dht_settings dhtsett;
dht::dht_settings dhtsett;
counters cnt;
dht::dht_state state;
std::unique_ptr<lt::dht::dht_storage_interface> dht_storage(dht::dht_default_storage_constructor(dhtsett));

View File

@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "setup_transfer.hpp" // for ep()
#include "libtorrent/config.hpp"
#include "libtorrent/kademlia/dht_storage.hpp"
#include "libtorrent/kademlia/dht_settings.hpp"
#include "libtorrent/io_service.hpp"
#include "libtorrent/address.hpp"
@ -59,8 +60,8 @@ using namespace std::placeholders;
namespace
{
dht_settings test_settings() {
dht_settings sett;
dht::dht_settings test_settings() {
dht::dht_settings sett;
sett.max_torrents = 2;
sett.max_dht_items = 2;
sett.item_lifetime = int(seconds(120 * 60).count());
@ -68,7 +69,7 @@ namespace
}
std::unique_ptr<dht_storage_interface> create_default_dht_storage(
dht_settings const& sett)
dht::dht_settings const& sett)
{
std::unique_ptr<dht_storage_interface> s(dht_default_storage_constructor(sett));
TEST_CHECK(s.get() != nullptr);
@ -110,7 +111,7 @@ void test_expiration(high_resolution_clock::duration const& expiry_time
TORRENT_TEST(dht_storage_counters)
{
dht_settings sett = test_settings();
dht::dht_settings sett = test_settings();
std::unique_ptr<dht_storage_interface> s(create_default_dht_storage(sett));
TEST_CHECK(s.get() != nullptr);
@ -164,7 +165,7 @@ TORRENT_TEST(dht_storage_counters)
TORRENT_TEST(dht_storage_infohashes_sample)
{
dht_settings sett = test_settings();
dht::dht_settings sett = test_settings();
sett.max_torrents = 5;
sett.sample_infohashes_interval = 30;
sett.max_infohashes_sample_count = 2;

View File

@ -23,6 +23,7 @@ KADEMLIA_SOURCES = \
kademlia/item.cpp \
kademlia/ed25519.cpp \
kademlia/sample_infohashes.cpp \
kademlia/dht_settings.cpp \
../ed25519/src/add_scalar.cpp \
../ed25519/src/fe.cpp \
../ed25519/src/ge.cpp \

View File

@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE.
#if TORRENT_USE_I2P
#include "libtorrent/i2p_stream.hpp"
#include "libtorrent/aux_/proxy_settings.hpp"
#include "libtorrent/assert.hpp"
#include "libtorrent/error_code.hpp"
#include "libtorrent/string_util.hpp"

View File

@ -31,7 +31,6 @@ POSSIBILITY OF SUCH DAMAGE.
*/
#include "libtorrent/socket.hpp"
#include "libtorrent/session_settings.hpp"
#include "libtorrent/socket_type.hpp"
#include "libtorrent/utp_socket_manager.hpp"
#include "libtorrent/instantiate_connection.hpp"

View File

@ -0,0 +1,114 @@
/*
Copyright (c) 2003-2016, 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.
*/
#include "libtorrent/config.hpp"
#include "libtorrent/kademlia/dht_settings.hpp"
#include "libtorrent/bdecode.hpp"
namespace libtorrent {
namespace dht {
dht_settings read_dht_settings(bdecode_node const& e)
{
dht_settings sett;
if (e.type() != bdecode_node::dict_t) return sett;
bdecode_node val;
val = e.dict_find_int("max_peers_reply");
if (val) sett.max_peers_reply = int(val.int_value());
val = e.dict_find_int("search_branching");
if (val) sett.search_branching = int(val.int_value());
val = e.dict_find_int("max_fail_count");
if (val) sett.max_fail_count = int(val.int_value());
val = e.dict_find_int("max_torrents");
if (val) sett.max_torrents = int(val.int_value());
val = e.dict_find_int("max_dht_items");
if (val) sett.max_dht_items = int(val.int_value());
val = e.dict_find_int("max_peers");
if (val) sett.max_peers = int(val.int_value());
val = e.dict_find_int("max_torrent_search_reply");
if (val) sett.max_torrent_search_reply = int(val.int_value());
val = e.dict_find_int("restrict_routing_ips");
if (val) sett.restrict_routing_ips = (val.int_value() != 0);
val = e.dict_find_int("restrict_search_ips");
if (val) sett.restrict_search_ips = (val.int_value() != 0);
val = e.dict_find_int("extended_routing_table");
if (val) sett.extended_routing_table = (val.int_value() != 0);
val = e.dict_find_int("aggressive_lookups");
if (val) sett.aggressive_lookups = (val.int_value() != 0);
val = e.dict_find_int("privacy_lookups");
if (val) sett.privacy_lookups = (val.int_value() != 0);
val = e.dict_find_int("enforce_node_id");
if (val) sett.enforce_node_id = (val.int_value() != 0);
val = e.dict_find_int("ignore_dark_internet");
if (val) sett.ignore_dark_internet = (val.int_value() != 0);
val = e.dict_find_int("block_timeout");
if (val) sett.block_timeout = int(val.int_value());
val = e.dict_find_int("block_ratelimit");
if (val) sett.block_ratelimit = int(val.int_value());
val = e.dict_find_int("read_only");
if (val) sett.read_only = (val.int_value() != 0);
val = e.dict_find_int("item_lifetime");
if (val) sett.item_lifetime = int(val.int_value());
return sett;
}
entry save_dht_settings(dht_settings const& settings)
{
entry e;
entry::dictionary_type& dht_sett = e.dict();
dht_sett["max_peers_reply"] = settings.max_peers_reply;
dht_sett["search_branching"] = settings.search_branching;
dht_sett["max_fail_count"] = settings.max_fail_count;
dht_sett["max_torrents"] = settings.max_torrents;
dht_sett["max_dht_items"] = settings.max_dht_items;
dht_sett["max_peers"] = settings.max_peers;
dht_sett["max_torrent_search_reply"] = settings.max_torrent_search_reply;
dht_sett["restrict_routing_ips"] = settings.restrict_routing_ips;
dht_sett["restrict_search_ips"] = settings.restrict_search_ips;
dht_sett["extended_routing_table"] = settings.extended_routing_table;
dht_sett["aggressive_lookups"] = settings.aggressive_lookups;
dht_sett["privacy_lookups"] = settings.privacy_lookups;
dht_sett["enforce_node_id"] = settings.enforce_node_id;
dht_sett["ignore_dark_internet"] = settings.ignore_dark_internet;
dht_sett["block_timeout"] = settings.block_timeout;
dht_sett["block_ratelimit"] = settings.block_ratelimit;
dht_sett["read_only"] = settings.read_only;
dht_sett["item_lifetime"] = settings.item_lifetime;
return e;
}
}
}

View File

@ -31,6 +31,7 @@ POSSIBILITY OF SUCH DAMAGE.
*/
#include "libtorrent/kademlia/dht_storage.hpp"
#include "libtorrent/kademlia/dht_settings.hpp"
#include <tuple>
#include <algorithm>
@ -43,7 +44,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <libtorrent/aux_/time.hpp>
#include <libtorrent/config.hpp>
#include <libtorrent/bloom_filter.hpp>
#include <libtorrent/session_settings.hpp>
#include <libtorrent/random.hpp>
#include <libtorrent/aux_/vector.hpp>
#include <libtorrent/aux_/numeric_cast.hpp>

View File

@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <libtorrent/kademlia/msg.hpp>
#include <libtorrent/kademlia/dht_observer.hpp>
#include <libtorrent/kademlia/dht_settings.hpp>
#include <libtorrent/bencode.hpp>
#include <libtorrent/version.hpp>
@ -43,7 +44,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <libtorrent/performance_counters.hpp> // for counters
#include <libtorrent/aux_/time.hpp>
#include <libtorrent/session_status.hpp>
#include <libtorrent/session_settings.hpp>
#include <libtorrent/broadcast_socket.hpp> // for is_local
#ifndef TORRENT_DISABLE_LOGGING
@ -570,7 +570,7 @@ namespace libtorrent { namespace dht {
dht_tracker::tracker_node::tracker_node(io_service& ios
, aux::listen_socket_handle const& s, socket_manager* sock
, libtorrent::dht_settings const& settings
, dht_settings const& settings
, node_id const& nid
, dht_observer* observer, counters& cnt
, get_foreign_node_t get_foreign_node

View File

@ -46,6 +46,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/session_status.hpp"
#include "libtorrent/kademlia/node_id.hpp"
#include "libtorrent/kademlia/dht_observer.hpp"
#include "libtorrent/kademlia/dht_settings.hpp"
#include "libtorrent/aux_/time.hpp"
#include "libtorrent/alert_types.hpp" // for dht_routing_bucket
#include "libtorrent/socket_io.hpp" // for print_endpoint

View File

@ -44,10 +44,10 @@ POSSIBILITY OF SUCH DAMAGE.
#include <libtorrent/kademlia/direct_request.hpp>
#include <libtorrent/kademlia/get_item.hpp>
#include <libtorrent/kademlia/sample_infohashes.hpp>
#include <libtorrent/kademlia/dht_settings.hpp>
#include <libtorrent/socket_io.hpp> // for print_endpoint
#include <libtorrent/hasher.hpp>
#include <libtorrent/session_settings.hpp> // for dht_settings
#include <libtorrent/aux_/time.hpp> // for aux::time_now
#include <libtorrent/aux_/aligned_union.hpp>

View File

@ -273,7 +273,7 @@ namespace libtorrent {
settings = e.dict_find_dict("dht");
if (settings)
{
params.dht_settings = aux::read_dht_settings(settings);
params.dht_settings = dht::read_dht_settings(settings);
}
}

View File

@ -517,7 +517,7 @@ namespace {
}
#endif // TORRENT_NO_DEPRECATE
void session_handle::set_dht_settings(dht_settings const& settings)
void session_handle::set_dht_settings(dht::dht_settings const& settings)
{
#ifndef TORRENT_DISABLE_DHT
async_call(&session_impl::set_dht_settings, settings);
@ -526,12 +526,12 @@ namespace {
#endif
}
dht_settings session_handle::get_dht_settings() const
dht::dht_settings session_handle::get_dht_settings() const
{
#ifndef TORRENT_DISABLE_DHT
return sync_call_ret<dht_settings>(&session_impl::get_dht_settings);
return sync_call_ret<dht::dht_settings>(&session_impl::get_dht_settings);
#else
return dht_settings();
return dht::dht_settings();
#endif
}

View File

@ -183,83 +183,6 @@ namespace libtorrent {
namespace aux {
// TODO: 3 move this out of this file
#ifndef TORRENT_DISABLE_DHT
dht_settings read_dht_settings(bdecode_node const& e)
{
dht_settings sett;
if (e.type() != bdecode_node::dict_t) return sett;
bdecode_node val;
val = e.dict_find_int("max_peers_reply");
if (val) sett.max_peers_reply = int(val.int_value());
val = e.dict_find_int("search_branching");
if (val) sett.search_branching = int(val.int_value());
val = e.dict_find_int("max_fail_count");
if (val) sett.max_fail_count = int(val.int_value());
val = e.dict_find_int("max_torrents");
if (val) sett.max_torrents = int(val.int_value());
val = e.dict_find_int("max_dht_items");
if (val) sett.max_dht_items = int(val.int_value());
val = e.dict_find_int("max_peers");
if (val) sett.max_peers = int(val.int_value());
val = e.dict_find_int("max_torrent_search_reply");
if (val) sett.max_torrent_search_reply = int(val.int_value());
val = e.dict_find_int("restrict_routing_ips");
if (val) sett.restrict_routing_ips = (val.int_value() != 0);
val = e.dict_find_int("restrict_search_ips");
if (val) sett.restrict_search_ips = (val.int_value() != 0);
val = e.dict_find_int("extended_routing_table");
if (val) sett.extended_routing_table = (val.int_value() != 0);
val = e.dict_find_int("aggressive_lookups");
if (val) sett.aggressive_lookups = (val.int_value() != 0);
val = e.dict_find_int("privacy_lookups");
if (val) sett.privacy_lookups = (val.int_value() != 0);
val = e.dict_find_int("enforce_node_id");
if (val) sett.enforce_node_id = (val.int_value() != 0);
val = e.dict_find_int("ignore_dark_internet");
if (val) sett.ignore_dark_internet = (val.int_value() != 0);
val = e.dict_find_int("block_timeout");
if (val) sett.block_timeout = int(val.int_value());
val = e.dict_find_int("block_ratelimit");
if (val) sett.block_ratelimit = int(val.int_value());
val = e.dict_find_int("read_only");
if (val) sett.read_only = (val.int_value() != 0);
val = e.dict_find_int("item_lifetime");
if (val) sett.item_lifetime = int(val.int_value());
return sett;
}
entry save_dht_settings(dht_settings const& settings)
{
entry e;
entry::dictionary_type& dht_sett = e.dict();
dht_sett["max_peers_reply"] = settings.max_peers_reply;
dht_sett["search_branching"] = settings.search_branching;
dht_sett["max_fail_count"] = settings.max_fail_count;
dht_sett["max_torrents"] = settings.max_torrents;
dht_sett["max_dht_items"] = settings.max_dht_items;
dht_sett["max_peers"] = settings.max_peers;
dht_sett["max_torrent_search_reply"] = settings.max_torrent_search_reply;
dht_sett["restrict_routing_ips"] = settings.restrict_routing_ips;
dht_sett["restrict_search_ips"] = settings.restrict_search_ips;
dht_sett["extended_routing_table"] = settings.extended_routing_table;
dht_sett["aggressive_lookups"] = settings.aggressive_lookups;
dht_sett["privacy_lookups"] = settings.privacy_lookups;
dht_sett["enforce_node_id"] = settings.enforce_node_id;
dht_sett["ignore_dark_internet"] = settings.ignore_dark_internet;
dht_sett["block_timeout"] = settings.block_timeout;
dht_sett["block_ratelimit"] = settings.block_ratelimit;
dht_sett["read_only"] = settings.read_only;
dht_sett["item_lifetime"] = settings.item_lifetime;
return e;
}
#endif // TORRENT_DISABLE_DHT
std::vector<std::shared_ptr<listen_socket_t>>::iterator partition_listen_sockets(
std::vector<listen_endpoint_t>& eps
, std::vector<std::shared_ptr<listen_socket_t>>& sockets)
@ -733,7 +656,7 @@ namespace aux {
#ifndef TORRENT_DISABLE_DHT
if (flags & session::save_dht_settings)
{
e["dht"] = save_dht_settings(m_dht_settings);
e["dht"] = dht::save_dht_settings(m_dht_settings);
}
if (m_dht && (flags & session::save_dht_state))
@ -770,7 +693,7 @@ namespace aux {
settings = e->dict_find_dict("dht");
if (settings)
{
m_dht_settings = read_dht_settings(settings);
m_dht_settings = dht::read_dht_settings(settings);
}
}
@ -5722,7 +5645,7 @@ namespace {
m_dht_storage.reset();
}
void session_impl::set_dht_settings(dht_settings const& settings)
void session_impl::set_dht_settings(dht::dht_settings const& settings)
{
m_dht_settings = settings;
}

View File

@ -31,7 +31,6 @@ POSSIBILITY OF SUCH DAMAGE.
*/
#include "libtorrent/config.hpp"
#include "libtorrent/session_settings.hpp"
#include "libtorrent/assert.hpp"
#include "libtorrent/settings_pack.hpp"
#include "libtorrent/aux_/session_impl.hpp"

View File

@ -549,9 +549,9 @@ struct obs : dht::dht_observer
#endif
};
dht_settings test_settings()
dht::dht_settings test_settings()
{
dht_settings sett;
dht::dht_settings sett;
sett.max_torrents = 4;
sett.max_dht_items = 4;
sett.enforce_node_id = false;
@ -571,7 +571,7 @@ struct dht_test_setup
dht_storage->update_node_ids({node_id::min()});
}
dht_settings sett;
dht::dht_settings sett;
mock_socket s;
std::shared_ptr<aux::listen_socket_t> ls;
obs observer;
@ -1562,7 +1562,7 @@ void test_routing_table(address(&rand_addr)())
bdecode_node response;
// test kademlia routing table
dht_settings s;
dht::dht_settings s;
s.extended_routing_table = false;
// s.restrict_routing_ips = false;
node_id id = to_hash("3123456789abcdef01232456789abcdef0123456");
@ -2628,7 +2628,7 @@ TORRENT_TEST(traversal_done)
TORRENT_TEST(dht_dual_stack)
{
// TODO: 3 use dht_test_setup class to simplify the node setup
dht_settings sett = test_settings();
dht::dht_settings sett = test_settings();
mock_socket s;
auto sock4 = dummy_listen_socket4();
auto sock6 = dummy_listen_socket6();
@ -2927,7 +2927,7 @@ TORRENT_TEST(verify_message)
TORRENT_TEST(routing_table_uniform)
{
// test routing table
dht_settings sett = test_settings();
dht::dht_settings sett = test_settings();
obs observer;
sett.extended_routing_table = false;
@ -2969,7 +2969,7 @@ TORRENT_TEST(routing_table_uniform)
TORRENT_TEST(routing_table_balance)
{
dht_settings sett = test_settings();
dht::dht_settings sett = test_settings();
obs observer;
sett.extended_routing_table = false;
@ -2992,7 +2992,7 @@ TORRENT_TEST(routing_table_balance)
TORRENT_TEST(routing_table_extended)
{
dht_settings sett = test_settings();
dht::dht_settings sett = test_settings();
obs observer;
sett.extended_routing_table = true;
node_id id = to_hash("1234876923549721020394873245098347598635");
@ -3024,7 +3024,7 @@ void inserter(std::set<node_id>* nodes, node_entry const& ne)
TORRENT_TEST(routing_table_set_id)
{
dht_settings sett = test_settings();
dht::dht_settings sett = test_settings();
sett.enforce_node_id = false;
sett.extended_routing_table = false;
obs observer;
@ -3070,7 +3070,7 @@ TORRENT_TEST(routing_table_set_id)
TORRENT_TEST(routing_table_for_each)
{
dht_settings sett = test_settings();
dht::dht_settings sett = test_settings();
obs observer;
sett.extended_routing_table = false;
@ -3141,7 +3141,7 @@ TORRENT_TEST(node_set_id)
TORRENT_TEST(read_only_node)
{
// TODO: 3 use dht_test_setup class to simplify the node setup
dht_settings sett = test_settings();
dht::dht_settings sett = test_settings();
sett.read_only = true;
mock_socket s;
auto ls = dummy_listen_socket4();
@ -3231,7 +3231,7 @@ TORRENT_TEST(read_only_node)
TORRENT_TEST(invalid_error_msg)
{
// TODO: 3 use dht_test_setup class to simplify the node setup
dht_settings sett = test_settings();
dht::dht_settings sett = test_settings();
mock_socket s;
auto ls = dummy_listen_socket4();
obs observer;
@ -3319,7 +3319,7 @@ TORRENT_TEST(unsorted_traversal_results)
TORRENT_TEST(rpc_invalid_error_msg)
{
// TODO: 3 use dht_test_setup class to simplify the node setup
dht_settings sett = test_settings();
dht::dht_settings sett = test_settings();
mock_socket s;
auto ls = dummy_listen_socket4();
obs observer;
@ -3443,7 +3443,7 @@ TORRENT_TEST(dht_verify_node_address)
{
obs observer;
// initial setup taken from dht test above
dht_settings s;
dht::dht_settings s;
s.extended_routing_table = false;
node_id id = to_hash("3123456789abcdef01232456789abcdef0123456");
const int bucket_size = 10;

View File

@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp"
#include "libtorrent/session.hpp"
#include "libtorrent/kademlia/dht_settings.hpp"
#include "libtorrent/bencode.hpp"
#include "libtorrent/socket_io.hpp" // for hash_address
#include "libtorrent/broadcast_socket.hpp" // for supports_ipv6
@ -58,8 +59,8 @@ using namespace lt::dht;
namespace
{
dht_settings test_settings() {
dht_settings sett;
dht::dht_settings test_settings() {
dht::dht_settings sett;
sett.max_torrents = 2;
sett.max_dht_items = 2;
sett.item_lifetime = int(seconds(120 * 60).count());
@ -69,14 +70,14 @@ namespace
bool g_storage_constructor_invoked = false;
std::unique_ptr<dht_storage_interface> dht_custom_storage_constructor(
dht_settings const& settings)
dht::dht_settings const& settings)
{
g_storage_constructor_invoked = true;
return dht_default_storage_constructor(settings);
}
std::unique_ptr<dht_storage_interface> create_default_dht_storage(
dht_settings const& sett)
dht::dht_settings const& sett)
{
std::unique_ptr<dht_storage_interface> s(dht_default_storage_constructor(sett));
TEST_CHECK(s != nullptr);
@ -94,7 +95,7 @@ sha1_hash const n4 = to_hash("5fbfbff10c5d6a4ec8a88e4c6ab4c28b95eee404");
TORRENT_TEST(announce_peer)
{
dht_settings sett = test_settings();
dht::dht_settings sett = test_settings();
std::unique_ptr<dht_storage_interface> s(create_default_dht_storage(sett));
entry peers;
@ -125,7 +126,7 @@ TORRENT_TEST(announce_peer)
#if TORRENT_USE_IPV6
TORRENT_TEST(dual_stack)
{
dht_settings sett = test_settings();
dht::dht_settings sett = test_settings();
std::unique_ptr<dht_storage_interface> s(create_default_dht_storage(sett));
tcp::endpoint const p1 = ep("124.31.75.21", 1);
@ -152,7 +153,7 @@ TORRENT_TEST(dual_stack)
TORRENT_TEST(put_items)
{
dht_settings sett = test_settings();
dht::dht_settings sett = test_settings();
std::unique_ptr<dht_storage_interface> s(create_default_dht_storage(sett));
entry item;
@ -182,7 +183,7 @@ TORRENT_TEST(put_items)
TORRENT_TEST(counters)
{
dht_settings sett = test_settings();
dht::dht_settings sett = test_settings();
std::unique_ptr<dht_storage_interface> s(create_default_dht_storage(sett));
sha1_hash const n1 = to_hash("5fbfbff10c5d6a4ec8a88e4c6ab4c28b95eee401");
@ -272,7 +273,7 @@ TORRENT_TEST(default_set_custom)
TORRENT_TEST(peer_limit)
{
dht_settings sett = test_settings();
dht::dht_settings sett = test_settings();
sett.max_peers = 42;
std::unique_ptr<dht_storage_interface> s(create_default_dht_storage(sett));
@ -289,7 +290,7 @@ TORRENT_TEST(peer_limit)
TORRENT_TEST(torrent_limit)
{
dht_settings sett = test_settings();
dht::dht_settings sett = test_settings();
sett.max_torrents = 42;
std::unique_ptr<dht_storage_interface> s(create_default_dht_storage(sett));
@ -306,7 +307,7 @@ TORRENT_TEST(torrent_limit)
TORRENT_TEST(immutable_item_limit)
{
dht_settings sett = test_settings();
dht::dht_settings sett = test_settings();
sett.max_dht_items = 42;
std::unique_ptr<dht_storage_interface> s(create_default_dht_storage(sett));
@ -322,7 +323,7 @@ TORRENT_TEST(immutable_item_limit)
TORRENT_TEST(mutable_item_limit)
{
dht_settings sett = test_settings();
dht::dht_settings sett = test_settings();
sett.max_dht_items = 42;
std::unique_ptr<dht_storage_interface> s(create_default_dht_storage(sett));
@ -344,7 +345,7 @@ TORRENT_TEST(get_peers_dist)
// test that get_peers returns reasonably disjoint sets of peers with each call
// take two samples of 100 peers from 1000 and make sure there aren't too many
// peers found in both lists
dht_settings sett = test_settings();
dht::dht_settings sett = test_settings();
sett.max_peers = 2000;
sett.max_peers_reply = 100;
std::unique_ptr<dht_storage_interface> s(create_default_dht_storage(sett));
@ -390,7 +391,7 @@ TORRENT_TEST(get_peers_dist)
TORRENT_TEST(update_node_ids)
{
dht_settings sett = test_settings();
dht::dht_settings sett = test_settings();
std::unique_ptr<dht_storage_interface> s(dht_default_storage_constructor(sett));
TEST_CHECK(s != nullptr);
@ -440,7 +441,7 @@ TORRENT_TEST(update_node_ids)
TORRENT_TEST(infohashes_sample)
{
dht_settings sett = test_settings();
dht::dht_settings sett = test_settings();
sett.max_torrents = 5;
sett.sample_infohashes_interval = 10;
sett.max_infohashes_sample_count = 2;
@ -482,7 +483,7 @@ TORRENT_TEST(infohashes_sample)
TORRENT_TEST(infohashes_sample_dist)
{
dht_settings sett = test_settings();
dht::dht_settings sett = test_settings();
sett.max_torrents = 1000;
sett.sample_infohashes_interval = 0; // need this to force refresh every call
sett.max_infohashes_sample_count = 1;

View File

@ -96,7 +96,7 @@ TORRENT_TEST(magnet)
TEST_EQUAL(pack.get_int(settings_pack::tracker_receive_timeout), 1234);
#ifndef TORRENT_DISABLE_DHT
dht_settings dhts;
dht::dht_settings dhts;
dhts.max_peers_reply = 70;
s->set_dht_settings(dhts);
#endif

View File

@ -51,7 +51,7 @@ namespace
bool g_storage_constructor_invoked = false;
std::unique_ptr<dht_storage_interface> dht_custom_storage_constructor(
dht_settings const& settings)
dht::dht_settings const& settings)
{
g_storage_constructor_invoked = true;
return dht_default_storage_constructor(settings);
@ -105,7 +105,7 @@ TORRENT_TEST(dht_state)
settings_pack p = settings();
p.set_bool(settings_pack::enable_dht, true);
dht_settings sett;
dht::dht_settings sett;
sett.max_dht_items = 10000;
sett.max_peers = 20000;