forked from premiere/premiere-libtorrent
move shared_ptr instead of copying them, when constructing DHT observers
This commit is contained in:
parent
b0c101a475
commit
f41d2b5d3b
|
@ -67,9 +67,9 @@ protected:
|
||||||
|
|
||||||
struct direct_observer : observer
|
struct direct_observer : observer
|
||||||
{
|
{
|
||||||
direct_observer(std::shared_ptr<traversal_algorithm> const& algo
|
direct_observer(std::shared_ptr<traversal_algorithm> algo
|
||||||
, udp::endpoint const& ep, node_id const& id)
|
, udp::endpoint const& ep, node_id const& id)
|
||||||
: observer(algo, ep, id)
|
: observer(std::move(algo), ep, id)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void reply(msg const& m) override
|
void reply(msg const& m) override
|
||||||
|
|
|
@ -76,9 +76,9 @@ protected:
|
||||||
struct find_data_observer : traversal_observer
|
struct find_data_observer : traversal_observer
|
||||||
{
|
{
|
||||||
find_data_observer(
|
find_data_observer(
|
||||||
std::shared_ptr<traversal_algorithm> const& algorithm
|
std::shared_ptr<traversal_algorithm> algorithm
|
||||||
, udp::endpoint const& ep, node_id const& id)
|
, udp::endpoint const& ep, node_id const& id)
|
||||||
: traversal_observer(algorithm, ep, id)
|
: traversal_observer(std::move(algorithm), ep, id)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void reply(msg const&) override;
|
void reply(msg const&) override;
|
||||||
|
|
|
@ -80,9 +80,9 @@ class get_item_observer : public find_data_observer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
get_item_observer(
|
get_item_observer(
|
||||||
std::shared_ptr<traversal_algorithm> const& algorithm
|
std::shared_ptr<traversal_algorithm> algorithm
|
||||||
, udp::endpoint const& ep, node_id const& id)
|
, udp::endpoint const& ep, node_id const& id)
|
||||||
: find_data_observer(algorithm, ep, id)
|
: find_data_observer(std::move(algorithm), ep, id)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void reply(msg const&) override;
|
void reply(msg const&) override;
|
||||||
|
|
|
@ -85,9 +85,9 @@ private:
|
||||||
struct get_peers_observer : find_data_observer
|
struct get_peers_observer : find_data_observer
|
||||||
{
|
{
|
||||||
get_peers_observer(
|
get_peers_observer(
|
||||||
std::shared_ptr<traversal_algorithm> const& algorithm
|
std::shared_ptr<traversal_algorithm> algorithm
|
||||||
, udp::endpoint const& ep, node_id const& id)
|
, udp::endpoint const& ep, node_id const& id)
|
||||||
: find_data_observer(algorithm, ep, id)
|
: find_data_observer(std::move(algorithm), ep, id)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void reply(msg const&) override;
|
void reply(msg const&) override;
|
||||||
|
@ -100,9 +100,9 @@ private:
|
||||||
struct obfuscated_get_peers_observer : traversal_observer
|
struct obfuscated_get_peers_observer : traversal_observer
|
||||||
{
|
{
|
||||||
obfuscated_get_peers_observer(
|
obfuscated_get_peers_observer(
|
||||||
std::shared_ptr<traversal_algorithm> const& algorithm
|
std::shared_ptr<traversal_algorithm> algorithm
|
||||||
, udp::endpoint const& ep, node_id const& id)
|
, udp::endpoint const& ep, node_id const& id)
|
||||||
: traversal_observer(algorithm, ep, id)
|
: traversal_observer(std::move(algorithm), ep, id)
|
||||||
{}
|
{}
|
||||||
void reply(msg const&) override;
|
void reply(msg const&) override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -68,9 +68,9 @@ TORRENT_EXTRA_EXPORT entry write_nodes_entry(std::vector<node_entry> const& node
|
||||||
class announce_observer : public observer
|
class announce_observer : public observer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
announce_observer(std::shared_ptr<traversal_algorithm> const& algo
|
announce_observer(std::shared_ptr<traversal_algorithm> algo
|
||||||
, udp::endpoint const& ep, node_id const& id)
|
, udp::endpoint const& ep, node_id const& id)
|
||||||
: observer(algo, ep, id)
|
: observer(std::move(algo), ep, id)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void reply(msg const&) override { flags |= flag_done; }
|
void reply(msg const&) override { flags |= flag_done; }
|
||||||
|
|
|
@ -54,22 +54,12 @@ using observer_flags_t = libtorrent::flags::bitfield_flag<std::uint8_t, observer
|
||||||
struct TORRENT_EXTRA_EXPORT observer
|
struct TORRENT_EXTRA_EXPORT observer
|
||||||
: std::enable_shared_from_this<observer>
|
: std::enable_shared_from_this<observer>
|
||||||
{
|
{
|
||||||
observer(std::shared_ptr<traversal_algorithm> const& a
|
observer(std::shared_ptr<traversal_algorithm> a
|
||||||
, udp::endpoint const& ep, node_id const& id)
|
, udp::endpoint const& ep, node_id const& id)
|
||||||
: m_sent()
|
: m_algorithm(std::move(a))
|
||||||
, m_algorithm(a)
|
|
||||||
, m_id(id)
|
, m_id(id)
|
||||||
, m_port(0)
|
|
||||||
, m_transaction_id()
|
|
||||||
, flags{}
|
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(a);
|
TORRENT_ASSERT(m_algorithm);
|
||||||
#if TORRENT_USE_ASSERTS
|
|
||||||
m_in_constructor = true;
|
|
||||||
m_was_sent = false;
|
|
||||||
m_was_abandoned = false;
|
|
||||||
m_in_use = true;
|
|
||||||
#endif
|
|
||||||
set_target(ep);
|
set_target(ep);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,18 +139,18 @@ private:
|
||||||
address_v4::bytes_type v4;
|
address_v4::bytes_type v4;
|
||||||
} m_addr;
|
} m_addr;
|
||||||
|
|
||||||
std::uint16_t m_port;
|
std::uint16_t m_port = 0;
|
||||||
|
|
||||||
// the transaction ID for this call
|
// the transaction ID for this call
|
||||||
std::uint16_t m_transaction_id;
|
std::uint16_t m_transaction_id = 0;
|
||||||
public:
|
public:
|
||||||
observer_flags_t flags;
|
observer_flags_t flags{};
|
||||||
|
|
||||||
#if TORRENT_USE_ASSERTS
|
#if TORRENT_USE_ASSERTS
|
||||||
bool m_in_constructor:1;
|
bool m_in_constructor = true;
|
||||||
bool m_was_sent:1;
|
bool m_was_sent = false;
|
||||||
bool m_was_abandoned:1;
|
bool m_was_abandoned = false;
|
||||||
bool m_in_use:1;
|
bool m_in_use = true;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -71,9 +71,9 @@ protected:
|
||||||
struct put_data_observer : traversal_observer
|
struct put_data_observer : traversal_observer
|
||||||
{
|
{
|
||||||
put_data_observer(
|
put_data_observer(
|
||||||
std::shared_ptr<traversal_algorithm> const& algorithm
|
std::shared_ptr<traversal_algorithm> algorithm
|
||||||
, udp::endpoint const& ep, node_id const& id, std::string const& token)
|
, udp::endpoint const& ep, node_id const& id, std::string const& token)
|
||||||
: traversal_observer(algorithm, ep, id)
|
: traversal_observer(std::move(algorithm), ep, id)
|
||||||
, m_token(token)
|
, m_token(token)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,8 +57,9 @@ struct socket_manager;
|
||||||
|
|
||||||
struct TORRENT_EXTRA_EXPORT null_observer : observer
|
struct TORRENT_EXTRA_EXPORT null_observer : observer
|
||||||
{
|
{
|
||||||
null_observer(std::shared_ptr<traversal_algorithm> const& a
|
null_observer(std::shared_ptr<traversal_algorithm> a
|
||||||
, udp::endpoint const& ep, node_id const& id): observer(a, ep, id) {}
|
, udp::endpoint const& ep, node_id const& id)
|
||||||
|
: observer(std::move(a), ep, id) {}
|
||||||
void reply(msg const&) override { flags |= flag_done; }
|
void reply(msg const&) override { flags |= flag_done; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,7 @@ class sample_infohashes_observer final : public traversal_observer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
sample_infohashes_observer(std::shared_ptr<traversal_algorithm> const& algorithm
|
sample_infohashes_observer(std::shared_ptr<traversal_algorithm> algorithm
|
||||||
, udp::endpoint const& ep, node_id const& id);
|
, udp::endpoint const& ep, node_id const& id);
|
||||||
|
|
||||||
void reply(msg const&) override;
|
void reply(msg const&) override;
|
||||||
|
|
|
@ -156,9 +156,9 @@ void look_for_nodes(char const* nodes_key, udp const& protocol
|
||||||
struct traversal_observer : observer
|
struct traversal_observer : observer
|
||||||
{
|
{
|
||||||
traversal_observer(
|
traversal_observer(
|
||||||
std::shared_ptr<traversal_algorithm> const& algorithm
|
std::shared_ptr<traversal_algorithm> algorithm
|
||||||
, udp::endpoint const& ep, node_id const& id)
|
, udp::endpoint const& ep, node_id const& id)
|
||||||
: observer(algorithm, ep, id)
|
: observer(std::move(algorithm), ep, id)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
// parses out "nodes" and keeps traversing
|
// parses out "nodes" and keeps traversing
|
||||||
|
|
|
@ -463,7 +463,7 @@ void node::direct_request(udp::endpoint const& ep, entry& e
|
||||||
// not really a traversal
|
// not really a traversal
|
||||||
auto algo = std::make_shared<direct_traversal>(*this, node_id(), f);
|
auto algo = std::make_shared<direct_traversal>(*this, node_id(), f);
|
||||||
|
|
||||||
auto o = m_rpc.allocate_observer<direct_observer>(algo, ep, node_id());
|
auto o = m_rpc.allocate_observer<direct_observer>(std::move(algo), ep, node_id());
|
||||||
if (!o) return;
|
if (!o) return;
|
||||||
#if TORRENT_USE_ASSERTS
|
#if TORRENT_USE_ASSERTS
|
||||||
o->m_in_constructor = false;
|
o->m_in_constructor = false;
|
||||||
|
@ -603,9 +603,9 @@ void node::sample_infohashes(udp::endpoint const& ep, sha1_hash const& target
|
||||||
struct ping_observer : observer
|
struct ping_observer : observer
|
||||||
{
|
{
|
||||||
ping_observer(
|
ping_observer(
|
||||||
std::shared_ptr<traversal_algorithm> const& algorithm
|
std::shared_ptr<traversal_algorithm> algorithm
|
||||||
, udp::endpoint const& ep, node_id const& id)
|
, udp::endpoint const& ep, node_id const& id)
|
||||||
: observer(algorithm, ep, id)
|
: observer(std::move(algorithm), ep, id)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
// parses out "nodes"
|
// parses out "nodes"
|
||||||
|
@ -675,8 +675,8 @@ void node::send_single_refresh(udp::endpoint const& ep, int const bucket
|
||||||
target |= m_id & mask;
|
target |= m_id & mask;
|
||||||
|
|
||||||
// create a dummy traversal_algorithm
|
// create a dummy traversal_algorithm
|
||||||
auto const algo = std::make_shared<traversal_algorithm>(*this, node_id());
|
auto algo = std::make_shared<traversal_algorithm>(*this, node_id());
|
||||||
auto o = m_rpc.allocate_observer<ping_observer>(algo, ep, id);
|
auto o = m_rpc.allocate_observer<ping_observer>(std::move(algo), ep, id);
|
||||||
if (!o) return;
|
if (!o) return;
|
||||||
#if TORRENT_USE_ASSERTS
|
#if TORRENT_USE_ASSERTS
|
||||||
o->m_in_constructor = false;
|
o->m_in_constructor = false;
|
||||||
|
|
|
@ -62,9 +62,9 @@ void sample_infohashes::got_samples(time_duration interval
|
||||||
}
|
}
|
||||||
|
|
||||||
sample_infohashes_observer::sample_infohashes_observer(
|
sample_infohashes_observer::sample_infohashes_observer(
|
||||||
std::shared_ptr<traversal_algorithm> const& algorithm
|
std::shared_ptr<traversal_algorithm> algorithm
|
||||||
, udp::endpoint const& ep, node_id const& id)
|
, udp::endpoint const& ep, node_id const& id)
|
||||||
: traversal_observer(algorithm, ep, id) {}
|
: traversal_observer(std::move(algorithm), ep, id) {}
|
||||||
|
|
||||||
void sample_infohashes_observer::reply(msg const& m)
|
void sample_infohashes_observer::reply(msg const& m)
|
||||||
{
|
{
|
||||||
|
|
|
@ -3372,7 +3372,7 @@ TORRENT_TEST(rpc_invalid_error_msg)
|
||||||
g_sent_packets.clear();
|
g_sent_packets.clear();
|
||||||
auto algo = std::make_shared<dht::traversal_algorithm>(node, node_id());
|
auto algo = std::make_shared<dht::traversal_algorithm>(node, node_id());
|
||||||
|
|
||||||
auto o = rpc.allocate_observer<null_observer>(algo, source, node_id());
|
auto o = rpc.allocate_observer<null_observer>(std::move(algo), source, node_id());
|
||||||
#if TORRENT_USE_ASSERTS
|
#if TORRENT_USE_ASSERTS
|
||||||
o->m_in_constructor = false;
|
o->m_in_constructor = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue