forked from premiere/premiere-libtorrent
Merge branch 'master' of https://github.com/arvidn/libtorrent
This commit is contained in:
commit
fbf926da1f
|
@ -57,7 +57,7 @@ struct find_data : traversal_algorithm
|
|||
{
|
||||
typedef std::function<void(std::vector<std::pair<node_entry, std::string>> const&)> nodes_callback;
|
||||
|
||||
find_data(node& node, node_id const& target
|
||||
find_data(node& dht_node, node_id const& target
|
||||
, nodes_callback const& ncallback);
|
||||
|
||||
void got_write_token(node_id const& n, std::string write_token);
|
||||
|
|
|
@ -82,4 +82,3 @@ struct TORRENT_EXTRA_EXPORT node_entry
|
|||
} } // namespace libtorrent::dht
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ struct TORRENT_EXTRA_EXPORT traversal_algorithm : boost::noncopyable
|
|||
void resort_results();
|
||||
void add_entry(node_id const& id, udp::endpoint const& addr, unsigned char flags);
|
||||
|
||||
traversal_algorithm(node& node, node_id const& target);
|
||||
traversal_algorithm(node& dht_node, node_id const& target);
|
||||
int invoke_count() const { return m_invoke_count; }
|
||||
int branch_factor() const { return m_branch_factor; }
|
||||
|
||||
|
|
|
@ -97,10 +97,9 @@ void find_data::start()
|
|||
std::vector<node_entry> nodes;
|
||||
m_node.m_table.find_node(m_target, nodes, routing_table::include_failed);
|
||||
|
||||
for (std::vector<node_entry>::iterator i = nodes.begin()
|
||||
, end(nodes.end()); i != end; ++i)
|
||||
for (auto const& n : nodes)
|
||||
{
|
||||
add_entry(i->id, i->ep(), observer::flag_initial);
|
||||
add_entry(n.id, n.ep(), observer::flag_initial);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,7 +109,9 @@ void find_data::start()
|
|||
void find_data::got_write_token(node_id const& n, std::string write_token)
|
||||
{
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
get_node().observer()->log(dht_logger::traversal
|
||||
auto logger = get_node().observer();
|
||||
if (logger != nullptr && logger->should_log(dht_logger::traversal))
|
||||
logger->log(dht_logger::traversal
|
||||
, "[%p] adding write token '%s' under id '%s'"
|
||||
, static_cast<void*>(this), aux::to_hex(write_token).c_str()
|
||||
, aux::to_hex(n).c_str());
|
||||
|
@ -135,7 +136,9 @@ void find_data::done()
|
|||
m_done = true;
|
||||
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
get_node().observer()->log(dht_logger::traversal, "[%p] %s DONE"
|
||||
auto logger = get_node().observer();
|
||||
if (logger != nullptr)
|
||||
logger->log(dht_logger::traversal, "[%p] %s DONE"
|
||||
, static_cast<void*>(this), name());
|
||||
#endif
|
||||
|
||||
|
@ -148,7 +151,8 @@ void find_data::done()
|
|||
if ((o->flags & observer::flag_alive) == 0)
|
||||
{
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
get_node().observer()->log(dht_logger::traversal, "[%p] not alive: %s"
|
||||
if (logger != nullptr && logger->should_log(dht_logger::traversal))
|
||||
logger->log(dht_logger::traversal, "[%p] not alive: %s"
|
||||
, static_cast<void*>(this), print_endpoint(o->target_ep()).c_str());
|
||||
#endif
|
||||
continue;
|
||||
|
@ -157,14 +161,16 @@ void find_data::done()
|
|||
if (j == m_write_tokens.end())
|
||||
{
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
get_node().observer()->log(dht_logger::traversal, "[%p] no write token: %s"
|
||||
if (logger != nullptr && logger->should_log(dht_logger::traversal))
|
||||
logger->log(dht_logger::traversal, "[%p] no write token: %s"
|
||||
, static_cast<void*>(this), print_endpoint(o->target_ep()).c_str());
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
results.push_back(std::make_pair(node_entry(o->id(), o->target_ep()), j->second));
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
get_node().observer()->log(dht_logger::traversal, "[%p] %s"
|
||||
if (logger != nullptr && logger->should_log(dht_logger::traversal))
|
||||
logger->log(dht_logger::traversal, "[%p] %s"
|
||||
, static_cast<void*>(this), print_endpoint(o->target_ep()).c_str());
|
||||
#endif
|
||||
--num_results;
|
||||
|
|
|
@ -72,10 +72,12 @@ void get_peers_observer::reply(msg const& m)
|
|||
char const* end = peers + n.list_at(0).string_length();
|
||||
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
auto logger = get_observer();
|
||||
bdecode_node const id = r.dict_find_string("id");
|
||||
if (id && id.string_length() == 20)
|
||||
if (logger != nullptr && logger->should_log(dht_logger::traversal)
|
||||
&& id && id.string_length() == 20)
|
||||
{
|
||||
get_observer()->log(dht_logger::traversal, "[%p] PEERS "
|
||||
logger->log(dht_logger::traversal, "[%p] PEERS "
|
||||
"invoke-count: %d branch-factor: %d addr: %s id: %s distance: %d p: %d"
|
||||
, static_cast<void*>(algorithm())
|
||||
, algorithm()->invoke_count()
|
||||
|
@ -94,10 +96,12 @@ void get_peers_observer::reply(msg const& m)
|
|||
// assume it's uTorrent/libtorrent format
|
||||
read_endpoint_list<tcp::endpoint>(n, peer_list);
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
auto logger = get_observer();
|
||||
bdecode_node const id = r.dict_find_string("id");
|
||||
if (id && id.string_length() == 20)
|
||||
if (logger != nullptr && logger->should_log(dht_logger::traversal)
|
||||
&& id && id.string_length() == 20)
|
||||
{
|
||||
get_observer()->log(dht_logger::traversal, "[%p] PEERS "
|
||||
logger->log(dht_logger::traversal, "[%p] PEERS "
|
||||
"invoke-count: %d branch-factor: %d addr: %s id: %s distance: %d p: %d"
|
||||
, static_cast<void*>(algorithm())
|
||||
, algorithm()->invoke_count()
|
||||
|
@ -105,7 +109,7 @@ void get_peers_observer::reply(msg const& m)
|
|||
, print_endpoint(m.addr).c_str()
|
||||
, aux::to_hex({id.string_ptr(), size_t(id.string_length())}).c_str()
|
||||
, distance_exp(algorithm()->target(), node_id(id.string_ptr()))
|
||||
, int(n.list_size()));
|
||||
, n.list_size());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -79,9 +79,7 @@ namespace libtorrent { namespace dht
|
|||
TORRENT_ASSERT(new_rtt >= 0);
|
||||
if (new_rtt == 0xffff) return;
|
||||
if (rtt == 0xffff) rtt = new_rtt;
|
||||
else rtt = int(rtt) * 2 / 3 + int(new_rtt) / 3;
|
||||
else rtt = int(rtt) * 2 / 3 + new_rtt / 3;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue