From 4693fcf3f176316317a99784f5a3defaa7da3b32 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Sat, 24 Sep 2016 22:20:20 -0400 Subject: [PATCH] dht source code and headers cleanup (#1150) --- include/libtorrent/close_reason.hpp | 1 - include/libtorrent/kademlia/dht_tracker.hpp | 3 --- include/libtorrent/kademlia/find_data.hpp | 3 --- include/libtorrent/kademlia/node.hpp | 5 ----- include/libtorrent/kademlia/node_entry.hpp | 4 ++-- include/libtorrent/kademlia/put_data.hpp | 2 +- include/libtorrent/kademlia/refresh.hpp | 4 ---- include/libtorrent/kademlia/traversal_algorithm.hpp | 1 - include/libtorrent/kademlia/types.hpp | 1 - src/close_reason.cpp | 11 +---------- src/kademlia/dht_tracker.cpp | 7 ------- src/kademlia/get_peers.cpp | 7 ++----- src/kademlia/node.cpp | 4 +--- src/kademlia/node_entry.cpp | 4 ++-- src/kademlia/rpc_manager.cpp | 6 ++---- src/kademlia/traversal_algorithm.cpp | 11 +++-------- 16 files changed, 14 insertions(+), 60 deletions(-) diff --git a/include/libtorrent/close_reason.hpp b/include/libtorrent/close_reason.hpp index 0be54e067..024ea7bab 100644 --- a/include/libtorrent/close_reason.hpp +++ b/include/libtorrent/close_reason.hpp @@ -154,4 +154,3 @@ namespace libtorrent } #endif - diff --git a/include/libtorrent/kademlia/dht_tracker.hpp b/include/libtorrent/kademlia/dht_tracker.hpp index a958d0b2c..7448c83e3 100644 --- a/include/libtorrent/kademlia/dht_tracker.hpp +++ b/include/libtorrent/kademlia/dht_tracker.hpp @@ -30,8 +30,6 @@ POSSIBILITY OF SUCH DAMAGE. */ -#ifndef TORRENT_DISABLE_DHT - #ifndef TORRENT_DHT_TRACKER #define TORRENT_DHT_TRACKER @@ -183,4 +181,3 @@ namespace libtorrent { namespace dht }} #endif -#endif diff --git a/include/libtorrent/kademlia/find_data.hpp b/include/libtorrent/kademlia/find_data.hpp index 35eeca907..6955e3f10 100644 --- a/include/libtorrent/kademlia/find_data.hpp +++ b/include/libtorrent/kademlia/find_data.hpp @@ -46,9 +46,6 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { namespace dht { -typedef std::vector packet_t; - -class rpc_manager; class node; // -------- find data ----------- diff --git a/include/libtorrent/kademlia/node.hpp b/include/libtorrent/kademlia/node.hpp index 665c9e6a1..88fb08811 100644 --- a/include/libtorrent/kademlia/node.hpp +++ b/include/libtorrent/kademlia/node.hpp @@ -58,9 +58,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/socket.hpp" namespace libtorrent { - class alert_manager; - struct alert_dispatcher; - class alert; struct counters; struct dht_routing_bucket; } @@ -74,8 +71,6 @@ struct msg; TORRENT_EXTRA_EXPORT entry write_nodes_entry(std::vector const& nodes); -struct null_type {}; - class announce_observer : public observer { public: diff --git a/include/libtorrent/kademlia/node_entry.hpp b/include/libtorrent/kademlia/node_entry.hpp index 4a87547f1..f838cd2ec 100644 --- a/include/libtorrent/kademlia/node_entry.hpp +++ b/include/libtorrent/kademlia/node_entry.hpp @@ -44,9 +44,9 @@ namespace libtorrent { namespace dht struct TORRENT_EXTRA_EXPORT node_entry { - node_entry(node_id const& id_, udp::endpoint ep, int roundtriptime = 0xffff + node_entry(node_id const& id_, udp::endpoint const& ep, int roundtriptime = 0xffff , bool pinged = false); - node_entry(udp::endpoint ep); + node_entry(udp::endpoint const& ep); node_entry(); void update_rtt(int new_rtt); diff --git a/include/libtorrent/kademlia/put_data.hpp b/include/libtorrent/kademlia/put_data.hpp index 7f5b78300..fb7864387 100644 --- a/include/libtorrent/kademlia/put_data.hpp +++ b/include/libtorrent/kademlia/put_data.hpp @@ -56,7 +56,7 @@ struct put_data: traversal_algorithm void set_data(item const& data) { m_data = data; } - void set_targets(std::vector > const& targets); + void set_targets(std::vector> const& targets); protected: diff --git a/include/libtorrent/kademlia/refresh.hpp b/include/libtorrent/kademlia/refresh.hpp index 73a1880e1..97390e4d3 100644 --- a/include/libtorrent/kademlia/refresh.hpp +++ b/include/libtorrent/kademlia/refresh.hpp @@ -33,16 +33,12 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef REFRESH_050324_HPP #define REFRESH_050324_HPP -#include #include #include namespace libtorrent { namespace dht { -class routing_table; -class rpc_manager; - class bootstrap : public get_peers { public: diff --git a/include/libtorrent/kademlia/traversal_algorithm.hpp b/include/libtorrent/kademlia/traversal_algorithm.hpp index c28e52907..9c7640e29 100644 --- a/include/libtorrent/kademlia/traversal_algorithm.hpp +++ b/include/libtorrent/kademlia/traversal_algorithm.hpp @@ -50,7 +50,6 @@ namespace libtorrent { struct dht_lookup; } namespace libtorrent { namespace dht { -class rpc_manager; class node; // this class may not be instantiated as a stack object diff --git a/include/libtorrent/kademlia/types.hpp b/include/libtorrent/kademlia/types.hpp index d3dbf1b62..48a12e203 100644 --- a/include/libtorrent/kademlia/types.hpp +++ b/include/libtorrent/kademlia/types.hpp @@ -93,4 +93,3 @@ namespace libtorrent { namespace dht }} #endif // LIBTORRENT_TYPES_HPP - diff --git a/src/close_reason.cpp b/src/close_reason.cpp index bb4cbe595..a632ae3d7 100644 --- a/src/close_reason.cpp +++ b/src/close_reason.cpp @@ -31,16 +31,8 @@ POSSIBILITY OF SUCH DAMAGE. */ #include "libtorrent/close_reason.hpp" -#include "libtorrent/error_code.hpp" +#include "libtorrent/error.hpp" #include "libtorrent/assert.hpp" -#include "libtorrent/error_code.hpp" - -#include "libtorrent/aux_/disable_warnings_push.hpp" - -#include -#include - -#include "libtorrent/aux_/disable_warnings_pop.hpp" namespace libtorrent { @@ -173,4 +165,3 @@ namespace libtorrent return close_no_reason; } } - diff --git a/src/kademlia/dht_tracker.cpp b/src/kademlia/dht_tracker.cpp index ce11422c8..7a0f85bf4 100644 --- a/src/kademlia/dht_tracker.cpp +++ b/src/kademlia/dht_tracker.cpp @@ -57,10 +57,6 @@ POSSIBILITY OF SUCH DAMAGE. #include // to_hex #endif -using libtorrent::dht::node; -using libtorrent::dht::node_id; -using libtorrent::dht::packet_t; -using libtorrent::dht::msg; using libtorrent::detail::write_endpoint; using namespace std::placeholders; @@ -149,9 +145,6 @@ namespace libtorrent { namespace dht update_storage_node_ids(); } - // defined in node.cpp - void nop(); - void dht_tracker::start(dht_state const& bootstrap , find_data::nodes_callback const& f) { diff --git a/src/kademlia/get_peers.cpp b/src/kademlia/get_peers.cpp index 7c533b66b..892edc32f 100644 --- a/src/kademlia/get_peers.cpp +++ b/src/kademlia/get_peers.cpp @@ -43,9 +43,6 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { namespace dht { -using detail::read_endpoint_list; -using detail::read_v4_endpoint; - void get_peers_observer::reply(msg const& m) { bdecode_node r = m.message.dict_find_dict("r"); @@ -91,12 +88,12 @@ void get_peers_observer::reply(msg const& m) } #endif while (end - peers >= 6) - peer_list.push_back(read_v4_endpoint(peers)); + peer_list.push_back(detail::read_v4_endpoint(peers)); } else { // assume it's uTorrent/libtorrent format - peer_list = read_endpoint_list(n); + peer_list = detail::read_endpoint_list(n); #ifndef TORRENT_DISABLE_LOGGING auto logger = get_observer(); if (logger != nullptr && logger->should_log(dht_logger::traversal)) diff --git a/src/kademlia/node.cpp b/src/kademlia/node.cpp index cc9ebcaa1..a8ed262bf 100644 --- a/src/kademlia/node.cpp +++ b/src/kademlia/node.cpp @@ -67,8 +67,6 @@ using namespace std::placeholders; namespace libtorrent { namespace dht { -using detail::write_endpoint; - namespace { void nop() {} @@ -776,7 +774,7 @@ entry write_nodes_entry(std::vector const& nodes) for (auto const& n : nodes) { std::copy(n.id.begin(), n.id.end(), out); - write_endpoint(udp::endpoint(n.addr(), n.port()), out); + detail::write_endpoint(udp::endpoint(n.addr(), n.port()), out); } return r; } diff --git a/src/kademlia/node_entry.cpp b/src/kademlia/node_entry.cpp index b4235c7e1..29711f7d6 100644 --- a/src/kademlia/node_entry.cpp +++ b/src/kademlia/node_entry.cpp @@ -36,7 +36,7 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { namespace dht { - node_entry::node_entry(node_id const& id_, udp::endpoint ep + node_entry::node_entry(node_id const& id_, udp::endpoint const& ep , int roundtriptime , bool pinged) : last_queried(pinged ? aux::time_now() : min_time()) @@ -50,7 +50,7 @@ namespace libtorrent { namespace dht #endif } - node_entry::node_entry(udp::endpoint ep) + node_entry::node_entry(udp::endpoint const& ep) : last_queried(min_time()) , id(nullptr) , endpoint(ep) diff --git a/src/kademlia/rpc_manager.cpp b/src/kademlia/rpc_manager.cpp index e4bdf7f64..0db645fcf 100644 --- a/src/kademlia/rpc_manager.cpp +++ b/src/kademlia/rpc_manager.cpp @@ -62,8 +62,6 @@ using namespace std::placeholders; namespace libtorrent { namespace dht { -namespace io = libtorrent::detail; - // TODO: 3 move this into it's own .cpp file dht_observer* observer::get_observer() const { @@ -249,7 +247,7 @@ bool rpc_manager::incoming(msg const& m, node_id* id) if (transaction_id.empty()) return false; auto ptr = transaction_id.begin(); - int tid = transaction_id.size() != 2 ? -1 : io::read_uint16(ptr); + int tid = transaction_id.size() != 2 ? -1 : detail::read_uint16(ptr); observer_ptr o; auto range = m_transactions.equal_range(tid); @@ -451,7 +449,7 @@ bool rpc_manager::invoke(entry& e, udp::endpoint const& target_addr transaction_id.resize(2); char* out = &transaction_id[0]; int tid = random(0x7fff); - io::write_uint16(tid, out); + detail::write_uint16(tid, out); e["t"] = transaction_id; // When a DHT node enters the read-only state, in each outgoing query message, diff --git a/src/kademlia/traversal_algorithm.cpp b/src/kademlia/traversal_algorithm.cpp index 59d6a9d98..eeb4d7e10 100644 --- a/src/kademlia/traversal_algorithm.cpp +++ b/src/kademlia/traversal_algorithm.cpp @@ -50,11 +50,6 @@ using namespace std::placeholders; namespace libtorrent { namespace dht { -using detail::address_size; -using detail::read_v4_endpoint; -#if TORRENT_USE_IPV6 -using detail::read_v6_endpoint; -#endif #if TORRENT_USE_ASSERTS template @@ -599,7 +594,7 @@ void traversal_observer::reply(msg const& m) char const* nodes = n.string_ptr(); char const* end = nodes + n.string_length(); - while (end - nodes >= 20 + address_size(protocol) + 2) + while (end - nodes >= 20 + detail::address_size(protocol) + 2) { node_id id; std::copy(nodes, nodes + 20, id.begin()); @@ -607,10 +602,10 @@ void traversal_observer::reply(msg const& m) udp::endpoint ep; #if TORRENT_USE_IPV6 if (protocol == udp::v6()) - ep = read_v6_endpoint(nodes); + ep = detail::read_v6_endpoint(nodes); else #endif - ep = read_v4_endpoint(nodes); + ep = detail::read_v4_endpoint(nodes); algorithm()->traverse(id, ep); } }