forked from premiere/premiere-libtorrent
don't load user_agent and peer_fingerprint from session_state (#1538)
don't load user_agent and peer_fingerprint from session_state
This commit is contained in:
parent
de499310f5
commit
04589f3bef
|
@ -1,3 +1,4 @@
|
||||||
|
* don't load user_agent and peer_fingerprint from session_state
|
||||||
* fix file rename issue with name prefix matching torrent name
|
* fix file rename issue with name prefix matching torrent name
|
||||||
* fix division by zero when setting tick_interval > 1000
|
* fix division by zero when setting tick_interval > 1000
|
||||||
* fix move_storage() to its own directory (would delete the files)
|
* fix move_storage() to its own directory (would delete the files)
|
||||||
|
|
|
@ -119,6 +119,11 @@ namespace libtorrent
|
||||||
// The ``flags`` argument is used to filter which parts of the session
|
// The ``flags`` argument is used to filter which parts of the session
|
||||||
// state to save or load. By default, all state is saved/restored (except
|
// state to save or load. By default, all state is saved/restored (except
|
||||||
// for the individual torrents). see save_state_flags_t
|
// for the individual torrents). see save_state_flags_t
|
||||||
|
//
|
||||||
|
// When saving settings, there are two fields that are *not* loaded.
|
||||||
|
// ``peer_fingerprint`` and ``user_agent``. Those are left as configured
|
||||||
|
// by the ``session_settings`` passed to the session constructor or
|
||||||
|
// subsequently set via apply_settings().
|
||||||
void save_state(entry& e, boost::uint32_t flags = 0xffffffff) const;
|
void save_state(entry& e, boost::uint32_t flags = 0xffffffff) const;
|
||||||
void load_state(bdecode_node const& e, boost::uint32_t flags = 0xffffffff);
|
void load_state(bdecode_node const& e, boost::uint32_t flags = 0xffffffff);
|
||||||
|
|
||||||
|
|
|
@ -89,8 +89,13 @@ namespace libtorrent
|
||||||
void set_int(int name, int val);
|
void set_int(int name, int val);
|
||||||
void set_bool(int name, bool val);
|
void set_bool(int name, bool val);
|
||||||
bool has_val(int name) const;
|
bool has_val(int name) const;
|
||||||
|
|
||||||
|
// clear the settings pack from all settings
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
|
// clear a specific setting from the pack
|
||||||
|
void clear(int name);
|
||||||
|
|
||||||
std::string get_str(int name) const;
|
std::string get_str(int name) const;
|
||||||
int get_int(int name) const;
|
int get_int(int name) const;
|
||||||
bool get_bool(int name) const;
|
bool get_bool(int name) const;
|
||||||
|
|
|
@ -908,6 +908,12 @@ namespace aux {
|
||||||
{
|
{
|
||||||
// apply_settings_pack will update dht and proxy
|
// apply_settings_pack will update dht and proxy
|
||||||
boost::shared_ptr<settings_pack> pack = load_pack_from_dict(settings);
|
boost::shared_ptr<settings_pack> pack = load_pack_from_dict(settings);
|
||||||
|
|
||||||
|
// these settings are not loaded from state
|
||||||
|
// they are set by the client software, not configured by users
|
||||||
|
pack->clear(settings_pack::user_agent);
|
||||||
|
pack->clear(settings_pack::peer_fingerprint);
|
||||||
|
|
||||||
apply_settings_pack(pack);
|
apply_settings_pack(pack);
|
||||||
#ifndef TORRENT_DISABLE_DHT
|
#ifndef TORRENT_DISABLE_DHT
|
||||||
need_update_dht = false;
|
need_update_dht = false;
|
||||||
|
|
|
@ -787,7 +787,7 @@ namespace libtorrent
|
||||||
std::pair<boost::uint16_t, bool> v(name, false);
|
std::pair<boost::uint16_t, bool> v(name, false);
|
||||||
std::vector<std::pair<boost::uint16_t, bool> >::const_iterator i
|
std::vector<std::pair<boost::uint16_t, bool> >::const_iterator i
|
||||||
= std::lower_bound(m_bools.begin(), m_bools.end(), v
|
= std::lower_bound(m_bools.begin(), m_bools.end(), v
|
||||||
, &compare_first<bool>);
|
, &compare_first<bool>);
|
||||||
if (i != m_bools.end() && i->first == name) return i->second;
|
if (i != m_bools.end() && i->first == name) return i->second;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -798,5 +798,39 @@ namespace libtorrent
|
||||||
m_ints.clear();
|
m_ints.clear();
|
||||||
m_bools.clear();
|
m_bools.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void settings_pack::clear(int const name)
|
||||||
|
{
|
||||||
|
switch (name & type_mask)
|
||||||
|
{
|
||||||
|
case string_type_base:
|
||||||
|
{
|
||||||
|
std::pair<boost::uint16_t, std::string> v(name, std::string());
|
||||||
|
std::vector<std::pair<boost::uint16_t, std::string> >::iterator i
|
||||||
|
= std::lower_bound(m_strings.begin(), m_strings.end(), v
|
||||||
|
, &compare_first<std::string>);
|
||||||
|
if (i != m_strings.end() && i->first == name) m_strings.erase(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case int_type_base:
|
||||||
|
{
|
||||||
|
std::pair<boost::uint16_t, int> v(name, 0);
|
||||||
|
std::vector<std::pair<boost::uint16_t, int> >::iterator i
|
||||||
|
= std::lower_bound(m_ints.begin(), m_ints.end(), v
|
||||||
|
, &compare_first<int>);
|
||||||
|
if (i != m_ints.end() && i->first == name) m_ints.erase(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case bool_type_base:
|
||||||
|
{
|
||||||
|
std::pair<boost::uint16_t, bool> v(name, false);
|
||||||
|
std::vector<std::pair<boost::uint16_t, bool> >::iterator i
|
||||||
|
= std::lower_bound(m_bools.begin(), m_bools.end(), v
|
||||||
|
, &compare_first<bool>);
|
||||||
|
if (i != m_bools.end() && i->first == name) m_bools.erase(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -262,5 +262,49 @@ TORRENT_TEST(session_shutdown)
|
||||||
lt::session ses(pack);
|
lt::session ses(pack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// make sure we don't restore peer_id from session state
|
||||||
|
TORRENT_TEST(save_state_peer_id)
|
||||||
|
{
|
||||||
|
lt::settings_pack pack;
|
||||||
|
pack.set_str(settings_pack::peer_fingerprint, "AAA");
|
||||||
|
lt::session ses(pack);
|
||||||
|
lt::peer_id const pid1 = ses.id();
|
||||||
|
TEST_CHECK(pid1[0] == 'A');
|
||||||
|
TEST_CHECK(pid1[1] == 'A');
|
||||||
|
TEST_CHECK(pid1[2] == 'A');
|
||||||
|
|
||||||
|
lt::entry st;
|
||||||
|
ses.save_state(st);
|
||||||
|
|
||||||
|
pack.set_str(settings_pack::peer_fingerprint, "foobar");
|
||||||
|
ses.apply_settings(pack);
|
||||||
|
|
||||||
|
lt::peer_id const pid2 = ses.id();
|
||||||
|
TEST_CHECK(pid2[0] == 'f');
|
||||||
|
TEST_CHECK(pid2[1] == 'o');
|
||||||
|
TEST_CHECK(pid2[2] == 'o');
|
||||||
|
TEST_CHECK(pid2[3] == 'b');
|
||||||
|
TEST_CHECK(pid2[4] == 'a');
|
||||||
|
TEST_CHECK(pid2[5] == 'r');
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<char> buf;
|
||||||
|
bencode(std::back_inserter(buf), st);
|
||||||
|
bdecode_node state;
|
||||||
|
error_code ec;
|
||||||
|
int ret = bdecode(buf.data(), buf.data() + buf.size()
|
||||||
|
, state, ec, nullptr, 100, 1000);
|
||||||
|
TEST_EQUAL(ret, 0);
|
||||||
|
ses.load_state(state);
|
||||||
|
|
||||||
|
lt::peer_id const pid3 = ses.id();
|
||||||
|
TEST_CHECK(pid3[0] == 'f');
|
||||||
|
TEST_CHECK(pid3[1] == 'o');
|
||||||
|
TEST_CHECK(pid3[2] == 'o');
|
||||||
|
TEST_CHECK(pid3[3] == 'b');
|
||||||
|
TEST_CHECK(pid3[4] == 'a');
|
||||||
|
TEST_CHECK(pid3[5] == 'r');
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -126,6 +126,42 @@ TORRENT_TEST(clear)
|
||||||
TEST_EQUAL(pack.has_val(settings_pack::lazy_bitfields), false);
|
TEST_EQUAL(pack.has_val(settings_pack::lazy_bitfields), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TORRENT_TEST(clear_single_int)
|
||||||
|
{
|
||||||
|
settings_pack sp;
|
||||||
|
sp.set_int(settings_pack::max_out_request_queue, 1337);
|
||||||
|
|
||||||
|
TEST_EQUAL(sp.get_int(settings_pack::max_out_request_queue), 1337);
|
||||||
|
|
||||||
|
sp.clear(settings_pack::max_out_request_queue);
|
||||||
|
|
||||||
|
TEST_EQUAL(sp.get_int(settings_pack::max_out_request_queue), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TORRENT_TEST(clear_single_bool)
|
||||||
|
{
|
||||||
|
settings_pack sp;
|
||||||
|
sp.set_bool(settings_pack::send_redundant_have, true);
|
||||||
|
|
||||||
|
TEST_EQUAL(sp.get_bool(settings_pack::send_redundant_have), true);
|
||||||
|
|
||||||
|
sp.clear(settings_pack::send_redundant_have);
|
||||||
|
|
||||||
|
TEST_EQUAL(sp.get_bool(settings_pack::send_redundant_have), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
TORRENT_TEST(clear_single_string)
|
||||||
|
{
|
||||||
|
settings_pack sp;
|
||||||
|
sp.set_str(settings_pack::user_agent, "foobar");
|
||||||
|
|
||||||
|
TEST_EQUAL(sp.get_str(settings_pack::user_agent), "foobar");
|
||||||
|
|
||||||
|
sp.clear(settings_pack::user_agent);
|
||||||
|
|
||||||
|
TEST_EQUAL(sp.get_str(settings_pack::user_agent), std::string());
|
||||||
|
}
|
||||||
|
|
||||||
TORRENT_TEST(duplicates)
|
TORRENT_TEST(duplicates)
|
||||||
{
|
{
|
||||||
settings_pack p;
|
settings_pack p;
|
||||||
|
|
Loading…
Reference in New Issue