merged RC_1_1 into master

This commit is contained in:
arvidn 2018-01-23 23:06:12 +01:00
commit 4fef787212
15 changed files with 53 additions and 108 deletions

View File

@ -82,6 +82,7 @@
* resume data no longer has timestamps of files
* require C++11 to build libtorrent
* use unique peer_ids per connection
* fix iOS build on recent SDK
* fix tracker connection bind issue for IPv6 trackers
* fix error handling of some merkle torrents

View File

@ -989,7 +989,6 @@ void bind_session()
.def("pause", allow_threads(&lt::session::pause))
.def("resume", allow_threads(&lt::session::resume))
.def("is_paused", allow_threads(&lt::session::is_paused))
.def("id", allow_threads(&lt::session::id))
.def("get_cache_info", &get_cache_info1, (arg("handle") = torrent_handle(), arg("flags") = 0))
.def("add_port_mapping", allow_threads(&lt::session::add_port_mapping))
.def("delete_port_mapping", allow_threads(&lt::session::delete_port_mapping))
@ -1002,6 +1001,7 @@ void bind_session()
.def("set_peer_class", &set_peer_class)
#ifndef TORRENT_NO_DEPRECATE
.def("id", allow_threads(&lt::session::id))
.def(
"listen_on", &listen_on
, (arg("min"), "max", arg("interface") = (char const*)nullptr, arg("flags") = 0)

View File

@ -375,8 +375,6 @@ namespace aux {
, peer_connection* pc) override;
void set_queue_position(torrent* t, queue_position_t p) override;
peer_id const& get_peer_id() const override { return m_peer_id; }
void close_connection(peer_connection* p) noexcept override;
void apply_settings_pack(std::shared_ptr<settings_pack> pack) override;
@ -586,11 +584,11 @@ namespace aux {
#ifndef TORRENT_NO_DEPRECATE
session_status status() const;
peer_id deprecated_get_peer_id() const;
#endif
void get_cache_info(torrent_handle h, cache_status* ret, int flags) const;
void set_peer_id(peer_id const& id);
void set_key(std::uint32_t key);
std::uint16_t listen_port() const override;
std::uint16_t listen_port(listen_socket_t* sock) const;
@ -753,7 +751,6 @@ namespace aux {
void update_lsd();
void update_dht();
void update_count_slow();
void update_peer_fingerprint();
void update_dht_bootstrap_nodes();
void update_socket_buffer_size();
@ -921,9 +918,6 @@ namespace aux {
// filters outgoing connections
port_filter m_port_filter;
// the peer id that is generated at the start of the session
peer_id m_peer_id;
// posts a notification when the set of local IPs changes
std::unique_ptr<ip_change_notifier> m_ip_notifier;

View File

@ -34,7 +34,6 @@ POSSIBILITY OF SUCH DAMAGE.
#define TORRENT_SESSION_INTERFACE_HPP_INCLUDED
#include "libtorrent/config.hpp"
#include "libtorrent/peer_id.hpp"
#include "libtorrent/address.hpp"
#include "libtorrent/io_service.hpp"
#include "libtorrent/time.hpp"
@ -202,8 +201,6 @@ namespace libtorrent { namespace aux {
virtual void set_queue_position(torrent* t, queue_position_t p) = 0;
virtual int num_torrents() const = 0;
virtual peer_id const& get_peer_id() const = 0;
virtual void close_connection(peer_connection* p) noexcept = 0;
virtual int num_connections() const = 0;

View File

@ -90,8 +90,7 @@ namespace libtorrent {
// this is the constructor where the we are the active part.
// The peer_connection should handshake and verify that the
// other end has the correct id
bt_peer_connection(peer_connection_args const& pack
, peer_id const& pid);
explicit bt_peer_connection(peer_connection_args const& pack);
void start() override;

View File

@ -579,11 +579,11 @@ namespace libtorrent {
// deprecated in 1.1, use settings_pack::peer_fingerprint instead
TORRENT_DEPRECATED
void set_peer_id(peer_id const& pid);
#endif
// returns the raw peer ID used by libtorrent. When anonymous mode is set
// the peer ID is randomized per peer.
// deprecated in 1.1.7. read settings_pack::peer_fingerprint instead
TORRENT_DEPRECATED
peer_id id() const;
#endif
#ifndef TORRENT_NO_DEPRECATE
// deprecated in 1.2

View File

@ -223,7 +223,7 @@ namespace libtorrent {
// this is the fingerprint for the client. It will be used as the
// prefix to the peer_id. If this is 20 bytes (or longer) it will be
// truncated at 20 bytes and used as the entire peer-id
// truncated to 20 bytes and used as the entire peer-id
//
// There is a utility function, generate_fingerprint() that can be used
// to generate a standard client peer ID fingerprint prefix.
@ -503,10 +503,10 @@ namespace libtorrent {
no_recheck_incomplete_resume,
// ``anonymous_mode`` defaults to false. When set to true, the client
// tries to hide its identity to a certain degree. The peer-ID will no
// longer include the client's fingerprint. The user-agent will be
// reset to an empty string. Trackers will only be used if they are
// using a proxy server. The listen sockets are closed, and incoming
// tries to hide its identity to a certain degree. The user-agent will be
// reset to an empty string (except for private torrents). Trackers
// will only be used if they are using a proxy server.
// The listen sockets are closed, and incoming
// connections will only be accepted through a SOCKS5 or I2P proxy (if
// a peer proxy is set up and is run on the same machine as the
// tracker proxy). Since no incoming connections are accepted,

View File

@ -111,6 +111,8 @@ namespace libtorrent {
class bt_peer_connection;
struct listen_socket_t;
peer_id generate_peer_id(aux::session_settings const& sett);
enum class waste_reason
{
piece_timed_out, piece_cancelled, piece_unknown, piece_seed
@ -387,7 +389,7 @@ namespace libtorrent {
// if we're connected to a peer at ep, return its peer connection
// only count BitTorrent peers
bt_peer_connection* find_peer(tcp::endpoint const& ep) const;
peer_connection* find_peer(sha1_hash const& pid);
peer_connection* find_peer(peer_id const& pid);
void on_resume_data_checked(status_t status, storage_error const& error);
void on_force_recheck(status_t status, storage_error const& error);
@ -1443,6 +1445,12 @@ namespace libtorrent {
// connections (if we've reached the connection limit)
std::uint16_t m_num_connecting = 0;
// this is the peer id we generate when we add the torrent. Peers won't
// use this (they generate their own peer ids) but this is used in case
// the tracker returns peer IDs, to identify ourself in the peer list to
// avoid connecting back to it.
peer_id m_peer_id;
// ==============================
// The following members are specifically
// ordered to make the 24 bit members

View File

@ -141,8 +141,7 @@ namespace {
}
#endif // TORRENT_DISABLE_EXTENSIONS
bt_peer_connection::bt_peer_connection(peer_connection_args const& pack
, peer_id const& pid)
bt_peer_connection::bt_peer_connection(peer_connection_args const& pack)
: peer_connection(pack)
, m_supports_extensions(false)
, m_supports_dht_port(false)
@ -155,7 +154,7 @@ namespace {
, m_rc4_encrypted(false)
, m_recv_buffer(peer_connection::m_recv_buffer)
#endif
, m_our_peer_id(pid)
, m_our_peer_id(generate_peer_id(*pack.sett))
{
#ifndef TORRENT_DISABLE_LOGGING
peer_log(peer_log_alert::info, "CONSTRUCT", "bt_peer_connection");
@ -742,15 +741,7 @@ namespace {
std::memcpy(ptr, ih.data(), ih.size());
ptr += 20;
// peer id
if (m_settings.get_bool(settings_pack::anonymous_mode))
{
// in anonymous mode, every peer connection
// has a unique peer-id
aux::random_bytes(m_our_peer_id);
}
std::memcpy(ptr, m_our_peer_id.data(), 20);
std::memcpy(ptr, &m_our_peer_id[0], 20);
ptr += 20;
#ifndef TORRENT_DISABLE_LOGGING
@ -3212,16 +3203,6 @@ namespace {
}
set_pid(pid);
// disconnect if the peer has the same peer-id as ourself
// since it most likely is ourself then
if (pid == m_our_peer_id)
{
if (peer_info_struct()) t->ban_peer(peer_info_struct());
disconnect(errors::self_connection, operation_t::bittorrent, 1);
return;
}
m_client_version = identify_client(pid);
if (pid[0] == '-' && pid[1] == 'B' && pid[2] == 'C' && pid[7] == '-')
{

View File

@ -810,12 +810,11 @@ namespace {
// per listen interface
}
#endif
peer_id session_handle::id() const
{
return sync_call_ret<peer_id>(&session_impl::get_peer_id);
return sync_call_ret<peer_id>(&session_impl::deprecated_get_peer_id);
}
#endif
unsigned short session_handle::listen_port() const
{

View File

@ -537,7 +537,6 @@ namespace aux {
{
session_log(" max connections: %d", m_settings.get_int(settings_pack::connections_limit));
session_log(" max files: %d", max_files);
session_log(" generated peer ID: %s", m_peer_id.to_string().c_str());
}
#endif
@ -2944,7 +2943,7 @@ namespace {
pack.peerinfo = nullptr;
std::shared_ptr<peer_connection> c
= std::make_shared<bt_peer_connection>(pack, get_peer_id());
= std::make_shared<bt_peer_connection>(pack);
if (!c->is_disconnecting())
{
@ -2995,10 +2994,12 @@ namespace {
}
}
void session_impl::set_peer_id(peer_id const& id)
#ifndef TORRENT_NO_DEPRECATE
peer_id session_impl::deprecated_get_peer_id() const
{
m_peer_id = id;
return generate_peer_id(m_settings);
}
#endif
int session_impl::next_port() const
{
@ -5345,20 +5346,6 @@ namespace {
#endif
}
void session_impl::update_peer_fingerprint()
{
// ---- generate a peer id ----
std::string print = m_settings.get_str(settings_pack::peer_fingerprint);
if (print.size() > m_peer_id.size()) print.resize(m_peer_id.size());
// the client's fingerprint
std::copy(print.begin(), print.begin() + int(print.length()), m_peer_id.begin());
if (print.size() < m_peer_id.size())
{
url_random(span<char>(m_peer_id).subspan(print.length()));
}
}
void session_impl::update_dht_bootstrap_nodes()
{
#ifndef TORRENT_DISABLE_DHT
@ -6395,7 +6382,6 @@ namespace {
}
if (m_upnp) m_upnp->set_user_agent("");
url_random(m_peer_id);
}
void session_impl::update_force_proxy()

View File

@ -125,7 +125,7 @@ constexpr int CLOSE_FILE_INTERVAL = 0;
SET(proxy_username, "", &session_impl::update_proxy),
SET(proxy_password, "", &session_impl::update_proxy),
SET(i2p_hostname, "", &session_impl::update_i2p_bridge),
SET(peer_fingerprint, "-LT1200-", &session_impl::update_peer_fingerprint),
SET(peer_fingerprint, "-LT1200-", nullptr),
SET(dht_bootstrap_nodes, "dht.libtorrent.org:25401", &session_impl::update_dht_bootstrap_nodes)
}});

View File

@ -123,6 +123,19 @@ namespace libtorrent {
peer_info.web_seed = true;
}
peer_id generate_peer_id(aux::session_settings const& sett)
{
peer_id ret;
std::string print = sett.get_str(settings_pack::peer_fingerprint);
if (print.size() > ret.size()) print.resize(ret.size());
// the client's fingerprint
std::copy(print.begin(), print.end(), ret.begin());
if (print.length() < ret.size())
url_random(span<char>(ret).subspan(print.length()));
return ret;
}
torrent_hot_members::torrent_hot_members(aux::session_interface& ses
, add_torrent_params const& p, bool const session_paused)
: m_ses(ses)
@ -161,6 +174,7 @@ namespace libtorrent {
, m_info_hash(p.info_hash)
, m_error_file(torrent_status::error_file_none)
, m_sequence_number(-1)
, m_peer_id(generate_peer_id(settings()))
, m_announce_to_trackers(!(p.flags & torrent_flags::paused))
, m_announce_to_lsd(!(p.flags & torrent_flags::paused))
, m_has_incoming(false)
@ -1926,7 +1940,7 @@ namespace libtorrent {
return nullptr;
}
peer_connection* torrent::find_peer(sha1_hash const& pid)
peer_connection* torrent::find_peer(peer_id const& pid)
{
for (auto p : m_connections)
{
@ -2698,7 +2712,7 @@ namespace libtorrent {
req.private_torrent = m_torrent_file->priv();
req.info_hash = m_torrent_file->info_hash();
req.pid = m_ses.get_peer_id();
req.pid = m_peer_id;
req.downloaded = m_stat.total_payload_download() - m_total_failed_bytes;
req.uploaded = m_stat.total_payload_upload();
req.corrupt = m_total_failed_bytes;
@ -3148,7 +3162,7 @@ namespace libtorrent {
for (auto const& i : resp.peers)
{
// don't make connections to ourself
if (i.pid == m_ses.get_peer_id())
if (i.pid == m_peer_id)
continue;
#if TORRENT_USE_I2P
@ -6577,8 +6591,7 @@ namespace libtorrent {
pack.endp = a;
pack.peerinfo = peerinfo;
std::shared_ptr<peer_connection> c = std::make_shared<bt_peer_connection>(
pack, m_ses.get_peer_id());
std::shared_ptr<peer_connection> c = std::make_shared<bt_peer_connection>(pack);
#if TORRENT_USE_ASSERTS
c->m_in_constructor = false;

View File

@ -769,30 +769,13 @@ setup_transfer(lt::session* ses1, lt::session* ses2, lt::session* ses3
if (ses3) pack.set_bool(settings_pack::allow_multiple_connections_per_ip, true);
pack.set_int(settings_pack::mixed_mode_algorithm, settings_pack::prefer_tcp);
pack.set_int(settings_pack::max_failcount, 1);
peer_id pid;
std::generate(&pid[0], &pid[0] + 20, random_byte);
pack.set_str(settings_pack::peer_fingerprint, pid.to_string());
ses1->apply_settings(pack);
TORRENT_ASSERT(ses1->id() == pid);
std::generate(&pid[0], &pid[0] + 20, random_byte);
TORRENT_ASSERT(ses1->id() != pid);
pack.set_str(settings_pack::peer_fingerprint, pid.to_string());
ses2->apply_settings(pack);
TORRENT_ASSERT(ses2->id() == pid);
if (ses3)
{
std::generate(&pid[0], &pid[0] + 20, random_byte);
TORRENT_ASSERT(ses1->id() != pid);
TORRENT_ASSERT(ses2->id() != pid);
pack.set_str(settings_pack::peer_fingerprint, pid.to_string());
ses3->apply_settings(pack);
TORRENT_ASSERT(ses3->id() == pid);
}
TORRENT_ASSERT(ses1->id() != ses2->id());
if (ses3) TORRENT_ASSERT(ses3->id() != ses2->id());
std::shared_ptr<torrent_info> t;
if (torrent == nullptr)
{

View File

@ -402,10 +402,7 @@ 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');
TEST_EQUAL(ses.get_settings().get_str(settings_pack::peer_fingerprint), "AAA");
lt::entry st;
ses.save_state(st);
@ -413,14 +410,7 @@ TORRENT_TEST(save_state_peer_id)
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');
TEST_EQUAL(ses.get_settings().get_str(settings_pack::peer_fingerprint), "foobar");
std::vector<char> buf;
bencode(std::back_inserter(buf), st);
@ -431,13 +421,7 @@ TORRENT_TEST(save_state_peer_id)
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');
TEST_EQUAL(ses.get_settings().get_str(settings_pack::peer_fingerprint), "foobar");
}
#ifndef TORRENT_DISABLE_LOGGING