From d03d50b6a832c996cd75a80236a16a35025bc132 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 26 Nov 2013 02:23:33 +0000 Subject: [PATCH] reorder some more fields to reduce padding --- include/libtorrent/kademlia/node.hpp | 2 +- include/libtorrent/kademlia/node_entry.hpp | 34 +++++++++++-------- include/libtorrent/kademlia/routing_table.hpp | 4 +-- include/libtorrent/kademlia/rpc_manager.hpp | 3 +- src/kademlia/rpc_manager.cpp | 3 +- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/include/libtorrent/kademlia/node.hpp b/include/libtorrent/kademlia/node.hpp index 230e18a4d..079c101fd 100644 --- a/include/libtorrent/kademlia/node.hpp +++ b/include/libtorrent/kademlia/node.hpp @@ -103,8 +103,8 @@ bool TORRENT_EXTRA_EXPORT verify_message(lazy_entry const* msg, key_desc_t const // to remove stale peers struct peer_entry { - tcp::endpoint addr; ptime added; + tcp::endpoint addr; bool seed; }; diff --git a/include/libtorrent/kademlia/node_entry.hpp b/include/libtorrent/kademlia/node_entry.hpp index caa919911..3eb5cf85f 100644 --- a/include/libtorrent/kademlia/node_entry.hpp +++ b/include/libtorrent/kademlia/node_entry.hpp @@ -48,10 +48,10 @@ namespace libtorrent { namespace dht struct node_entry { node_entry(node_id const& id_, udp::endpoint ep, int roundtriptime = 0xffff, bool pinged = false) - : endpoint(ep) - , timeout_count(pinged ? 0 : 0xff) + : id(id_) + , endpoint(ep) , rtt(roundtriptime) - , id(id_) + , timeout_count(pinged ? 0 : 0xff) { #ifdef TORRENT_DHT_VERBOSE_LOGGING first_seen = time_now(); @@ -59,10 +59,10 @@ struct node_entry } node_entry(udp::endpoint ep) - : endpoint(ep) - , timeout_count(0xff) + : id(0) + , endpoint(ep) , rtt(0xffff) - , id(0) + , timeout_count(0xff) { #ifdef TORRENT_DHT_VERBOSE_LOGGING first_seen = time_now(); @@ -70,9 +70,9 @@ struct node_entry } node_entry() - : timeout_count(0xff) + : id(0) , rtt(0xffff) - , id(0) + , timeout_count(0xff) { #ifdef TORRENT_DHT_VERBOSE_LOGGING first_seen = time_now(); @@ -94,16 +94,20 @@ struct node_entry address addr() const { return endpoint.address(); } int port() const { return endpoint.port; } - union_endpoint endpoint; - // the number of times this node has failed to - // respond in a row - boost::uint8_t timeout_count; - // the average RTT of this node - boost::uint16_t rtt; - node_id id; #ifdef TORRENT_DHT_VERBOSE_LOGGING ptime first_seen; #endif + + node_id id; + + union_endpoint endpoint; + + // the average RTT of this node + boost::uint16_t rtt; + + // the number of times this node has failed to + // respond in a row + boost::uint8_t timeout_count; }; } } // namespace libtorrent::dht diff --git a/include/libtorrent/kademlia/routing_table.hpp b/include/libtorrent/kademlia/routing_table.hpp index f30d4cc6c..d6fecc186 100644 --- a/include/libtorrent/kademlia/routing_table.hpp +++ b/include/libtorrent/kademlia/routing_table.hpp @@ -181,11 +181,11 @@ private: // port has to match node_entry* find_node(udp::endpoint const& ep, routing_table::table_t::iterator* bucket); + dht_settings const& m_settings; + // constant called k in paper int m_bucket_size; - dht_settings const& m_settings; - // (k-bucket, replacement cache) pairs // the first entry is the bucket the furthest // away from our own ID. Each time the bucket diff --git a/include/libtorrent/kademlia/rpc_manager.hpp b/include/libtorrent/kademlia/rpc_manager.hpp index 9426769dc..28120e6ff 100644 --- a/include/libtorrent/kademlia/rpc_manager.hpp +++ b/include/libtorrent/kademlia/rpc_manager.hpp @@ -111,10 +111,9 @@ private: transactions_t m_transactions; udp_socket_interface* m_sock; - node_id m_our_id; routing_table& m_table; ptime m_timer; - node_id m_random_number; + node_id m_our_id; int m_allocated_observers; bool m_destructing; }; diff --git a/src/kademlia/rpc_manager.cpp b/src/kademlia/rpc_manager.cpp index 8ffefc098..060729e8b 100644 --- a/src/kademlia/rpc_manager.cpp +++ b/src/kademlia/rpc_manager.cpp @@ -162,10 +162,9 @@ rpc_manager::rpc_manager(node_id const& our_id , routing_table& table, udp_socket_interface* sock) : m_pool_allocator(observer_size, 10) , m_sock(sock) - , m_our_id(our_id) , m_table(table) , m_timer(time_now()) - , m_random_number(generate_random_id()) + , m_our_id(our_id) , m_allocated_observers(0) , m_destructing(false) {