forked from premiere/premiere-libtorrent
pass the dht item object by const reference instead of by value
This commit is contained in:
parent
6d886f29a9
commit
164982c63a
|
@ -74,7 +74,7 @@ TORRENT_EXPORT signature sign_mutable_item(
|
|||
class TORRENT_EXTRA_EXPORT item
|
||||
{
|
||||
public:
|
||||
item() : m_seq(0), m_mutable(false) {}
|
||||
item() {}
|
||||
item(public_key const& pk, span<char const> salt);
|
||||
explicit item(entry v);
|
||||
item(entry v
|
||||
|
@ -117,8 +117,8 @@ private:
|
|||
std::string m_salt;
|
||||
public_key m_pk;
|
||||
signature m_sig;
|
||||
sequence_number m_seq;
|
||||
bool m_mutable;
|
||||
sequence_number m_seq{0};
|
||||
bool m_mutable = false;
|
||||
};
|
||||
|
||||
} } // namespace libtorrent::dht
|
||||
|
|
|
@ -54,7 +54,8 @@ struct put_data: traversal_algorithm
|
|||
char const* name() const override;
|
||||
void start() override;
|
||||
|
||||
void set_data(item const& data) { m_data = data; }
|
||||
void set_data(item&& data) { m_data = std::move(data); }
|
||||
void set_data(item const& data) = delete;
|
||||
|
||||
void set_targets(std::vector<std::pair<node_entry, std::string>> const& targets);
|
||||
|
||||
|
|
|
@ -516,15 +516,16 @@ void put(std::vector<std::pair<node_entry, std::string>> const& nodes
|
|||
ta->start();
|
||||
}
|
||||
|
||||
void put_data_cb(item i, bool auth
|
||||
void put_data_cb(item const& i, bool auth
|
||||
, std::shared_ptr<put_data> const& ta
|
||||
, std::function<void(item&)> const& f)
|
||||
{
|
||||
// call data_callback only when we got authoritative data.
|
||||
if (auth)
|
||||
{
|
||||
f(i);
|
||||
ta->set_data(i);
|
||||
item copy(i);
|
||||
f(copy);
|
||||
ta->set_data(std::move(copy));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -543,7 +544,7 @@ void node::put_item(sha1_hash const& target, entry const& data, std::function<vo
|
|||
item i;
|
||||
i.assign(data);
|
||||
auto put_ta = std::make_shared<dht::put_data>(*this, std::bind(f, _2));
|
||||
put_ta->set_data(i);
|
||||
put_ta->set_data(std::move(i));
|
||||
|
||||
auto ta = std::make_shared<dht::get_item>(*this, target
|
||||
, get_item::data_callback(), std::bind(&put, _1, put_ta));
|
||||
|
|
Loading…
Reference in New Issue