|
| 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 |
0 commit comments