Added dht_get_peers and dht_announce at session_impl level.
This commit is contained in:
parent
94d6e06c97
commit
fcac7140f8
|
@ -2356,12 +2356,27 @@ namespace libtorrent
|
|||
int m_size;
|
||||
};
|
||||
|
||||
struct TORRENT_EXPORT dht_get_peers_reply_alert: alert {
|
||||
|
||||
dht_get_peers_reply_alert(aux::stack_allocator& alloc
|
||||
, sha1_hash const& ih
|
||||
, std::vector<tcp::endpoint> const& v);
|
||||
|
||||
const static int static_category = alert::dht_notification;
|
||||
TORRENT_DEFINE_ALERT(dht_get_peers_reply_alert, 87)
|
||||
|
||||
virtual std::string message() const;
|
||||
|
||||
sha1_hash info_hash;
|
||||
std::vector<tcp::endpoint> peers;
|
||||
};
|
||||
|
||||
#undef TORRENT_DEFINE_ALERT_IMPL
|
||||
#undef TORRENT_DEFINE_ALERT
|
||||
#undef TORRENT_DEFINE_ALERT_PRIO
|
||||
#undef TORRENT_CLONE
|
||||
|
||||
enum { num_alert_types = 87 };
|
||||
enum { num_alert_types = 88 };
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -311,9 +311,12 @@ namespace libtorrent
|
|||
|
||||
void dht_put_mutable_item(boost::array<char, 32> key
|
||||
, boost::function<void(entry&, boost::array<char,64>&
|
||||
, boost::uint64_t&, std::string const&)> cb
|
||||
, boost::uint64_t&, std::string const&)> cb
|
||||
, std::string salt = std::string());
|
||||
|
||||
void dht_get_peers(sha1_hash const& info_hash);
|
||||
void dht_announce(sha1_hash const& info_hash, int port = 0, int flags = 0);
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
entry dht_state() const;
|
||||
#endif
|
||||
|
|
|
@ -86,6 +86,8 @@ namespace libtorrent { namespace dht
|
|||
entry state() const;
|
||||
|
||||
enum flags_t { flag_seed = 1, flag_implied_port = 2 };
|
||||
void get_peers(sha1_hash const& ih
|
||||
, boost::function<void(std::vector<tcp::endpoint> const&)> f);
|
||||
void announce(sha1_hash const& ih, int listen_port, int flags
|
||||
, boost::function<void(std::vector<tcp::endpoint> const&)> f);
|
||||
|
||||
|
|
|
@ -1777,5 +1777,20 @@ namespace libtorrent {
|
|||
return buf;
|
||||
}
|
||||
|
||||
dht_get_peers_reply_alert::dht_get_peers_reply_alert(aux::stack_allocator&
|
||||
, sha1_hash const& ih
|
||||
, std::vector<tcp::endpoint> const& v)
|
||||
: info_hash(ih), peers(v)
|
||||
{}
|
||||
|
||||
std::string dht_get_peers_reply_alert::message() const
|
||||
{
|
||||
char ih_hex[41];
|
||||
to_hex((const char*)&info_hash[0], 20, ih_hex);
|
||||
char msg[200];
|
||||
snprintf(msg, sizeof(msg), "incoming dht get_peers reply: %s, peers %ld", ih_hex, peers.size());
|
||||
return msg;
|
||||
}
|
||||
|
||||
} // namespace libtorrent
|
||||
|
||||
|
|
|
@ -222,6 +222,12 @@ namespace libtorrent { namespace dht
|
|||
#endif
|
||||
}
|
||||
|
||||
void dht_tracker::get_peers(sha1_hash const& ih
|
||||
, boost::function<void(std::vector<tcp::endpoint> const&)> f)
|
||||
{
|
||||
m_dht.get_peers(ih, f, NULL, false);
|
||||
}
|
||||
|
||||
void dht_tracker::announce(sha1_hash const& ih, int listen_port, int flags
|
||||
, boost::function<void(std::vector<tcp::endpoint> const&)> f)
|
||||
{
|
||||
|
|
|
@ -5531,6 +5531,12 @@ retry:
|
|||
alerts.emplace_alert<dht_put_alert>(pk, sig, salt, seq);
|
||||
}
|
||||
|
||||
void on_dht_get_peers(alert_manager& alerts, sha1_hash info_hash, std::vector<tcp::endpoint> const& peers)
|
||||
{
|
||||
if (alerts.should_post<dht_get_peers_reply_alert>())
|
||||
alerts.emplace_alert<dht_get_peers_reply_alert>(info_hash, peers);
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
void session_impl::dht_put_item(entry data, sha1_hash target)
|
||||
|
@ -5542,7 +5548,7 @@ retry:
|
|||
|
||||
void session_impl::dht_put_mutable_item(boost::array<char, 32> key
|
||||
, boost::function<void(entry&, boost::array<char,64>&
|
||||
, boost::uint64_t&, std::string const&)> cb
|
||||
, boost::uint64_t&, std::string const&)> cb
|
||||
, std::string salt)
|
||||
{
|
||||
if (!m_dht) return;
|
||||
|
@ -5550,6 +5556,28 @@ retry:
|
|||
, boost::ref(m_alerts), _1, cb), salt);
|
||||
}
|
||||
|
||||
void session_impl::dht_get_peers(sha1_hash const& info_hash)
|
||||
{
|
||||
if (!m_dht) return;
|
||||
m_dht->get_peers(info_hash, boost::bind(&on_dht_get_peers, boost::ref(m_alerts), info_hash, _1));
|
||||
}
|
||||
|
||||
void session_impl::dht_announce(sha1_hash const& info_hash, int port, int flags)
|
||||
{
|
||||
if (!m_dht) return;
|
||||
|
||||
port = port <= 0 ? listen_port() : port;
|
||||
|
||||
// if incoming uTP connections are allowed, set the implied_port
|
||||
// argument in the announce, this will make the DHT node use
|
||||
// our source port in the packet as our listen port, which is
|
||||
// likely more accurate when behind a NAT
|
||||
if (settings().get_bool(settings_pack::enable_incoming_utp))
|
||||
flags |= dht::dht_tracker::flag_implied_port;
|
||||
|
||||
m_dht->announce(info_hash, port, flags, boost::bind(&on_dht_get_peers, boost::ref(m_alerts), info_hash, _1));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void session_impl::maybe_update_udp_mapping(int nat, int local_port, int external_port)
|
||||
|
|
Loading…
Reference in New Issue