Skip to content

Commit bb51dcd

Browse files
committed
move dht_settings into its own header cpp file-pair and dht_settings into the dht namespace
1 parent 95c8c30 commit bb51dcd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+411
-349
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ set(kademlia_sources
155155
get_item
156156
ed25519
157157
sample_infohashes
158+
dht_settings
158159
)
159160

160161
# -- ed25519 --

Jamfile

+1
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,7 @@ KADEMLIA_SOURCES =
693693
put_data
694694
ed25519
695695
sample_infohashes
696+
dht_settings
696697
;
697698

698699
ED25519_SOURCES =

bindings/python/src/session_settings.cpp

+19-19
Original file line numberDiff line numberDiff line change
@@ -98,27 +98,27 @@ void bind_session_settings()
9898
#endif
9999

100100
#ifndef TORRENT_DISABLE_DHT
101-
class_<dht_settings>("dht_settings")
102-
.def_readwrite("max_peers_reply", &dht_settings::max_peers_reply)
103-
.def_readwrite("search_branching", &dht_settings::search_branching)
101+
class_<dht::dht_settings>("dht_settings")
102+
.def_readwrite("max_peers_reply", &dht::dht_settings::max_peers_reply)
103+
.def_readwrite("search_branching", &dht::dht_settings::search_branching)
104104
#ifndef TORRENT_NO_DEPRECATE
105-
.def_readwrite("service_port", &dht_settings::service_port)
105+
.def_readwrite("service_port", &dht::dht_settings::service_port)
106106
#endif
107-
.def_readwrite("max_fail_count", &dht_settings::max_fail_count)
108-
.def_readwrite("max_torrents", &dht_settings::max_torrents)
109-
.def_readwrite("max_dht_items", &dht_settings::max_dht_items)
110-
.def_readwrite("restrict_routing_ips", &dht_settings::restrict_routing_ips)
111-
.def_readwrite("restrict_search_ips", &dht_settings::restrict_search_ips)
112-
.def_readwrite("max_torrent_search_reply", &dht_settings::max_torrent_search_reply)
113-
.def_readwrite("extended_routing_table", &dht_settings::extended_routing_table)
114-
.def_readwrite("aggressive_lookups", &dht_settings::aggressive_lookups)
115-
.def_readwrite("privacy_lookups", &dht_settings::privacy_lookups)
116-
.def_readwrite("enforce_node_id", &dht_settings::enforce_node_id)
117-
.def_readwrite("ignore_dark_internet", &dht_settings::ignore_dark_internet)
118-
.def_readwrite("block_timeout", &dht_settings::block_timeout)
119-
.def_readwrite("block_ratelimit", &dht_settings::block_ratelimit)
120-
.def_readwrite("read_only", &dht_settings::read_only)
121-
.def_readwrite("item_lifetime", &dht_settings::item_lifetime)
107+
.def_readwrite("max_fail_count", &dht::dht_settings::max_fail_count)
108+
.def_readwrite("max_torrents", &dht::dht_settings::max_torrents)
109+
.def_readwrite("max_dht_items", &dht::dht_settings::max_dht_items)
110+
.def_readwrite("restrict_routing_ips", &dht::dht_settings::restrict_routing_ips)
111+
.def_readwrite("restrict_search_ips", &dht::dht_settings::restrict_search_ips)
112+
.def_readwrite("max_torrent_search_reply", &dht::dht_settings::max_torrent_search_reply)
113+
.def_readwrite("extended_routing_table", &dht::dht_settings::extended_routing_table)
114+
.def_readwrite("aggressive_lookups", &dht::dht_settings::aggressive_lookups)
115+
.def_readwrite("privacy_lookups", &dht::dht_settings::privacy_lookups)
116+
.def_readwrite("enforce_node_id", &dht::dht_settings::enforce_node_id)
117+
.def_readwrite("ignore_dark_internet", &dht::dht_settings::ignore_dark_internet)
118+
.def_readwrite("block_timeout", &dht::dht_settings::block_timeout)
119+
.def_readwrite("block_ratelimit", &dht::dht_settings::block_ratelimit)
120+
.def_readwrite("read_only", &dht::dht_settings::read_only)
121+
.def_readwrite("item_lifetime", &dht::dht_settings::item_lifetime)
122122
;
123123
#endif
124124

bindings/python/src/torrent_info.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <memory>
77

88
#include "libtorrent/torrent_info.hpp"
9-
#include "libtorrent/session_settings.hpp"
109
#include "libtorrent/time.hpp"
1110
#include "libtorrent/socket_io.hpp"
1211
#include "libtorrent/announce_entry.hpp"

include/libtorrent/aux_/session_impl.hpp

+3-11
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,6 @@ namespace aux {
128128
struct tracker_logger;
129129
#endif
130130

131-
#ifndef TORRENT_DISABLE_DHT
132-
TORRENT_EXTRA_EXPORT dht_settings read_dht_settings(bdecode_node const& e);
133-
TORRENT_EXTRA_EXPORT entry save_dht_settings(dht_settings const& settings);
134-
#endif
135-
136131
struct listen_socket_t
137132
{
138133
listen_socket_t()
@@ -371,8 +366,8 @@ namespace aux {
371366
void add_dht_node_name(std::pair<std::string, int> const& node);
372367
void add_dht_node(udp::endpoint const& n) override;
373368
void add_dht_router(std::pair<std::string, int> const& node);
374-
void set_dht_settings(dht_settings const& s);
375-
dht_settings const& get_dht_settings() const { return m_dht_settings; }
369+
void set_dht_settings(dht::dht_settings const& s);
370+
dht::dht_settings const& get_dht_settings() const { return m_dht_settings; }
376371
void set_dht_state(dht::dht_state state);
377372
void set_dht_storage(dht::dht_storage_constructor_type sc);
378373
void start_dht();
@@ -1039,7 +1034,7 @@ namespace aux {
10391034
#ifndef TORRENT_DISABLE_DHT
10401035
std::unique_ptr<dht::dht_storage_interface> m_dht_storage;
10411036
std::shared_ptr<dht::dht_tracker> m_dht;
1042-
dht_settings m_dht_settings;
1037+
dht::dht_settings m_dht_settings;
10431038
dht::dht_storage_constructor_type m_dht_storage_constructor
10441039
= dht::dht_default_storage_constructor;
10451040

@@ -1156,9 +1151,6 @@ namespace aux {
11561151
#endif
11571152

11581153
// mask is a bitmask of which protocols to remap on:
1159-
// 1: NAT-PMP
1160-
// 2: UPnP
1161-
// TODO: 3 perhaps this function should move into listen_socket_t
11621154
enum remap_port_mask_t
11631155
{
11641156
remap_natpmp = 1,

include/libtorrent/fwd.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ class session;
204204
struct session_handle;
205205

206206
// include/libtorrent/session_settings.hpp
207-
struct dht_settings;
208207
struct pe_settings;
209208

210209
// include/libtorrent/session_stats.hpp
@@ -239,6 +238,9 @@ struct torrent_status;
239238

240239
namespace dht {
241240

241+
// include/libtorrent/kademlia/dht_settings.hpp
242+
struct dht_settings;
243+
242244
// include/libtorrent/kademlia/dht_state.hpp
243245
struct dht_state;
244246

include/libtorrent/http_connection.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ POSSIBILITY OF SUCH DAMAGE.
5454
#include "libtorrent/deadline_timer.hpp"
5555
#include "libtorrent/assert.hpp"
5656
#include "libtorrent/socket_type.hpp"
57-
#include "libtorrent/session_settings.hpp"
5857
#include "libtorrent/i2p_stream.hpp"
5958
#include "libtorrent/aux_/vector.hpp"
6059
#include "libtorrent/resolver_interface.hpp"

include/libtorrent/i2p_stream.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ POSSIBILITY OF SUCH DAMAGE.
4343
#include <functional>
4444

4545
#include "libtorrent/proxy_base.hpp"
46-
#include "libtorrent/session_settings.hpp"
4746
#include "libtorrent/string_util.hpp"
4847
#include "libtorrent/aux_/vector.hpp"
48+
#include "libtorrent/aux_/proxy_settings.hpp"
4949

5050
namespace libtorrent {
5151

include/libtorrent/kademlia/dht_observer.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ POSSIBILITY OF SUCH DAMAGE.
3535

3636
#include "libtorrent/config.hpp"
3737
#include "libtorrent/address.hpp"
38+
#include "libtorrent/string_view.hpp"
3839
#include "libtorrent/kademlia/msg.hpp"
3940

4041
namespace libtorrent {
4142

43+
class entry;
44+
4245
namespace aux { struct listen_socket_handle; }
4346

4447
namespace dht {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
/*
2+
3+
Copyright (c) 2006, Arvid Norberg
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions
8+
are met:
9+
10+
* Redistributions of source code must retain the above copyright
11+
notice, this list of conditions and the following disclaimer.
12+
* Redistributions in binary form must reproduce the above copyright
13+
notice, this list of conditions and the following disclaimer in
14+
the documentation and/or other materials provided with the distribution.
15+
* Neither the name of the author nor the names of its
16+
contributors may be used to endorse or promote products derived
17+
from this software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+
POSSIBILITY OF SUCH DAMAGE.
30+
31+
*/
32+
33+
#ifndef TORRENT_DHT_SETTINGS_HPP_INCLUDED
34+
#define TORRENT_DHT_SETTINGS_HPP_INCLUDED
35+
36+
#include "libtorrent/config.hpp"
37+
#include "libtorrent/bdecode.hpp"
38+
#include "libtorrent/entry.hpp"
39+
40+
namespace libtorrent {
41+
namespace dht {
42+
43+
// structure used to hold configuration options for the DHT
44+
//
45+
// The ``dht_settings`` struct used to contain a ``service_port`` member to
46+
// control which port the DHT would listen on and send messages from. This
47+
// field is deprecated and ignored. libtorrent always tries to open the UDP
48+
// socket on the same port as the TCP socket.
49+
struct TORRENT_EXPORT dht_settings
50+
{
51+
// the maximum number of peers to send in a reply to ``get_peers``
52+
int max_peers_reply = 100;
53+
54+
// the number of concurrent search request the node will send when
55+
// announcing and refreshing the routing table. This parameter is called
56+
// alpha in the kademlia paper
57+
int search_branching = 5;
58+
59+
// the maximum number of failed tries to contact a node before it is
60+
// removed from the routing table. If there are known working nodes that
61+
// are ready to replace a failing node, it will be replaced immediately,
62+
// this limit is only used to clear out nodes that don't have any node
63+
// that can replace them.
64+
int max_fail_count = 20;
65+
66+
// the total number of torrents to track from the DHT. This is simply an
67+
// upper limit to make sure malicious DHT nodes cannot make us allocate
68+
// an unbounded amount of memory.
69+
int max_torrents = 2000;
70+
71+
// max number of items the DHT will store
72+
int max_dht_items = 700;
73+
74+
// the max number of peers to store per torrent (for the DHT)
75+
int max_peers = 500;
76+
77+
// the max number of torrents to return in a torrent search query to the
78+
// DHT
79+
int max_torrent_search_reply = 20;
80+
81+
// determines if the routing table entries should restrict entries to one
82+
// per IP. This defaults to true, which helps mitigate some attacks on
83+
// the DHT. It prevents adding multiple nodes with IPs with a very close
84+
// CIDR distance.
85+
//
86+
// when set, nodes whose IP address that's in the same /24 (or /64 for
87+
// IPv6) range in the same routing table bucket. This is an attempt to
88+
// mitigate node ID spoofing attacks also restrict any IP to only have a
89+
// single entry in the whole routing table
90+
bool restrict_routing_ips = true;
91+
92+
// determines if DHT searches should prevent adding nodes with IPs with
93+
// very close CIDR distance. This also defaults to true and helps
94+
// mitigate certain attacks on the DHT.
95+
bool restrict_search_ips = true;
96+
97+
// makes the first buckets in the DHT routing table fit 128, 64, 32 and
98+
// 16 nodes respectively, as opposed to the standard size of 8. All other
99+
// buckets have size 8 still.
100+
bool extended_routing_table = true;
101+
102+
// slightly changes the lookup behavior in terms of how many outstanding
103+
// requests we keep. Instead of having branch factor be a hard limit, we
104+
// always keep *branch factor* outstanding requests to the closest nodes.
105+
// i.e. every time we get results back with closer nodes, we query them
106+
// right away. It lowers the lookup times at the cost of more outstanding
107+
// queries.
108+
bool aggressive_lookups = true;
109+
110+
// when set, perform lookups in a way that is slightly more expensive,
111+
// but which minimizes the amount of information leaked about you.
112+
bool privacy_lookups = false;
113+
114+
// when set, node's whose IDs that are not correctly generated based on
115+
// its external IP are ignored. When a query arrives from such node, an
116+
// error message is returned with a message saying "invalid node ID".
117+
bool enforce_node_id = false;
118+
119+
// ignore DHT messages from parts of the internet we wouldn't expect to
120+
// see any traffic from
121+
bool ignore_dark_internet = true;
122+
123+
// the number of seconds a DHT node is banned if it exceeds the rate
124+
// limit. The rate limit is averaged over 10 seconds to allow for bursts
125+
// above the limit.
126+
int block_timeout = 5 * 60;
127+
128+
// the max number of packets per second a DHT node is allowed to send
129+
// without getting banned.
130+
int block_ratelimit = 5;
131+
132+
// when set, the other nodes won't keep this node in their routing
133+
// tables, it's meant for low-power and/or ephemeral devices that
134+
// cannot support the DHT, it is also useful for mobile devices which
135+
// are sensitive to network traffic and battery life.
136+
// this node no longer responds to 'query' messages, and will place a
137+
// 'ro' key (value = 1) in the top-level message dictionary of outgoing
138+
// query messages.
139+
bool read_only = false;
140+
141+
// the number of seconds a immutable/mutable item will be expired.
142+
// default is 0, means never expires.
143+
int item_lifetime = 0;
144+
145+
// the number of bytes per second (on average) the DHT is allowed to send.
146+
// If the incoming requests causes to many bytes to be sent in responses,
147+
// incoming requests will be dropped until the quota has been replenished.
148+
int upload_rate_limit = 8000;
149+
150+
// the info-hashes sample recomputation interval (in seconds).
151+
// The node will precompute a subset of the tracked info-hashes and return
152+
// that instead of calculating it upon each request. The permissible range
153+
// is between 0 and 21600 seconds (inclusive).
154+
int sample_infohashes_interval = 21600;
155+
156+
// the maximum number of elements in the sampled subset of info-hashes.
157+
// If this number is too big, expect the DHT storage implementations
158+
// to clamp it in order to allow UDP packets go through
159+
int max_infohashes_sample_count = 20;
160+
161+
#ifndef TORRENT_NO_DEPRECATE
162+
// the listen port for the dht. This is a UDP port. zero means use the
163+
// same as the tcp interface
164+
int service_port = 0;
165+
#endif
166+
167+
};
168+
169+
170+
TORRENT_EXTRA_EXPORT dht_settings read_dht_settings(bdecode_node const& e);
171+
TORRENT_EXTRA_EXPORT entry save_dht_settings(dht_settings const& settings);
172+
173+
}
174+
}
175+
176+
#endif

include/libtorrent/kademlia/dht_storage.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ POSSIBILITY OF SUCH DAMAGE.
4545

4646
namespace libtorrent {
4747

48-
struct dht_settings;
4948
class entry;
5049
}
5150

5251
namespace libtorrent { namespace dht {
52+
struct dht_settings;
53+
5354
// This structure hold the relevant counters for the storage
5455
struct TORRENT_EXPORT dht_storage_counters
5556
{

include/libtorrent/kademlia/dht_tracker.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,18 @@ POSSIBILITY OF SUCH DAMAGE.
4545
#include <libtorrent/span.hpp>
4646
#include <libtorrent/io_service.hpp>
4747
#include <libtorrent/udp_socket.hpp>
48+
#include <libtorrent/entry.hpp>
4849

4950
namespace libtorrent {
5051

5152
struct counters;
52-
struct dht_settings;
5353
#ifndef TORRENT_NO_DEPRECATE
5454
struct session_status;
5555
#endif
5656
}
5757

5858
namespace libtorrent { namespace dht {
59+
struct dht_settings;
5960

6061
struct TORRENT_EXTRA_EXPORT dht_tracker final
6162
: socket_manager
@@ -149,7 +150,7 @@ namespace libtorrent { namespace dht {
149150
{
150151
tracker_node(io_service& ios
151152
, aux::listen_socket_handle const& s, socket_manager* sock
152-
, libtorrent::dht_settings const& settings
153+
, dht_settings const& settings
153154
, node_id const& nid
154155
, dht_observer* observer, counters& cnt
155156
, get_foreign_node_t get_foreign_node

0 commit comments

Comments
 (0)