Use dht_settings directly instead of add a read_only member variable.

Since rpc_manager has a reference of dht_settings, needn't pass it
as a parameter for incoming().
This commit is contained in:
Thomas Yuan 2015-09-02 18:09:49 -04:00 committed by Thomas Yuan
parent 3d4ed9f37f
commit d6bb387ab9
4 changed files with 14 additions and 15 deletions

View File

@ -81,17 +81,17 @@ class TORRENT_EXTRA_EXPORT rpc_manager
public:
rpc_manager(node_id const& our_id
, dht_settings const& settings
, routing_table& table
, udp_socket_interface* sock
, dht_logger* log
, bool read_only = false);
, dht_logger* log);
~rpc_manager();
void unreachable(udp::endpoint const& ep);
// returns true if the node needs a refresh
// if so, id is assigned the node id to refresh
bool incoming(msg const&, node_id* id, libtorrent::dht_settings const& settings);
bool incoming(msg const&, node_id* id);
time_duration tick();
bool invoke(entry& e, udp::endpoint target
@ -126,12 +126,12 @@ private:
udp_socket_interface* m_sock;
dht_logger* m_log;
dht_settings const& m_settings;
routing_table& m_table;
time_point m_timer;
node_id m_our_id;
boost::uint32_t m_allocated_observers:31;
boost::uint32_t m_destructing:1;
bool m_read_only;
};
} } // namespace libtorrent::dht

View File

@ -1490,7 +1490,7 @@ namespace libtorrent
// without getting banned.
int block_ratelimit;
// when set, the other nodes won't kept this node in their routing
// 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.

View File

@ -109,7 +109,7 @@ node::node(udp_socket_interface* sock
: m_settings(settings)
, m_id(calculate_node_id(nid, observer))
, m_table(m_id, 8, settings, observer)
, m_rpc(m_id, m_table, sock, observer, settings.read_only)
, m_rpc(m_id, m_settings, m_table, sock, observer)
, m_observer(observer)
, m_last_tracker_tick(aux::time_now())
, m_last_self_refresh(min_time())
@ -274,7 +274,7 @@ void node::incoming(msg const& m)
case 'r':
{
node_id id;
m_rpc.incoming(m, &id, m_settings);
m_rpc.incoming(m, &id);
break;
}
case 'q':
@ -300,7 +300,7 @@ void node::incoming(msg const& m)
}
#endif
node_id id;
m_rpc.incoming(m, &id, m_settings);
m_rpc.incoming(m, &id);
break;
}
}

View File

@ -163,18 +163,18 @@ enum { observer_size = max3<
};
rpc_manager::rpc_manager(node_id const& our_id
, dht_settings const& settings
, routing_table& table, udp_socket_interface* sock
, dht_logger* log
, bool read_only)
, dht_logger* log)
: m_pool_allocator(observer_size, 10)
, m_sock(sock)
, m_log(log)
, m_settings(settings)
, m_table(table)
, m_timer(aux::time_now())
, m_our_id(our_id)
, m_allocated_observers(0)
, m_destructing(false)
, m_read_only(read_only)
{}
rpc_manager::~rpc_manager()
@ -246,8 +246,7 @@ void rpc_manager::unreachable(udp::endpoint const& ep)
}
}
bool rpc_manager::incoming(msg const& m, node_id* id
, libtorrent::dht_settings const& settings)
bool rpc_manager::incoming(msg const& m, node_id* id)
{
INVARIANT_CHECK;
@ -337,7 +336,7 @@ bool rpc_manager::incoming(msg const& m, node_id* id
}
node_id nid = node_id(node_id_ent.string_ptr());
if (settings.enforce_node_id && !verify_id(nid, m.addr.address()))
if (m_settings.enforce_node_id && !verify_id(nid, m.addr.address()))
{
o->timeout();
return false;
@ -443,7 +442,7 @@ bool rpc_manager::invoke(entry& e, udp::endpoint target_addr
// When a DHT node enters the read-only state, in each outgoing query message,
// places a 'ro' key in the top-level message dictionary and sets its value to 1.
if (m_read_only) e["ro"] = 1;
if (m_settings.read_only) e["ro"] = 1;
o->set_target(target_addr);
o->set_transaction_id(tid);