merged RC_1_1 into master

This commit is contained in:
arvidn 2016-07-26 02:14:58 -04:00
commit 680a09cfa5
8 changed files with 244 additions and 17 deletions

View File

@ -28,6 +28,9 @@
1.1.1 release
* fix value of current_tracker when all tracker failed
* deprecate lt_trackers extension
* remove load_asnum_db and load_country_db from python bindings
* fix crash in session::get_ip_filter when not having set one
* fix filename escaping when repairing torrents with broken web seeds
* fix bug where file_completed_alert would not be posted unless file_progress
@ -52,6 +55,7 @@
* fix set_settings in python binding
* Added missing alert categories in python binding
* Added dht_get_peers_reply_alert alert in python binding
* fixed updating the node id reported to peers after changing IPs
1.1.0 release

View File

@ -398,9 +398,6 @@ namespace
}
return pieces;
}
void load_asnum_db(lt::session& s, std::string file) {}
void load_country_db(lt::session& s, std::string file) {}
#endif
entry save_state(lt::session const& s, std::uint32_t flags)
@ -812,8 +809,6 @@ void bind_session()
.def("set_max_connections", allow_threads(&lt::session::set_max_connections))
.def("max_connections", allow_threads(&lt::session::max_connections))
.def("num_connections", allow_threads(&lt::session::num_connections))
.def("load_asnum_db", &load_asnum_db)
.def("load_country_db", &load_country_db)
.def("set_max_half_open_connections", allow_threads(&lt::session::set_max_half_open_connections))
.def("set_severity_level", allow_threads(&lt::session::set_severity_level))
.def("set_alert_queue_size_limit", allow_threads(&lt::session::set_alert_queue_size_limit))

View File

@ -101,6 +101,8 @@ public:
int num_allocated_observers() const { return m_allocated_observers; }
void update_node_id(node_id const& id) { m_our_id = id; }
private:
std::uint32_t calc_connection_id(udp::endpoint addr);

View File

@ -0,0 +1,162 @@
/*
Copyright (c) 2008-2015, Arvid Norberg
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include "test.hpp"
#ifndef TORRENT_NO_DEPRECATE
#include "setup_swarm.hpp"
#include "libtorrent/alert.hpp"
#include "libtorrent/announce_entry.hpp"
#include "libtorrent/settings_pack.hpp"
#include "libtorrent/add_torrent_params.hpp"
#include "libtorrent/alert_types.hpp"
#include "libtorrent/extensions/lt_trackers.hpp"
#include "libtorrent/session.hpp"
#include "settings.hpp"
using namespace libtorrent;
TORRENT_TEST(plain)
{
dsl_config network_cfg;
sim::simulation sim{network_cfg};
settings_pack pack = settings();
add_torrent_params p;
p.flags &= ~lt::add_torrent_params::flag_paused;
p.flags &= ~lt::add_torrent_params::flag_auto_managed;
// the default torrent has one tracker
// we remove this from session 0 (the one under test)
p.trackers.push_back("http://test.non-existent.com/announce");
bool connected = false;
setup_swarm(2, swarm_test::upload
, sim , pack, p
// init session
, [](lt::session& ses) {
ses.add_extension(&create_lt_trackers_plugin);
}
// add session
, [](lt::settings_pack& pack) {}
// add torrent
, [](lt::add_torrent_params& params) {
// make sure neither peer has any content
// TODO: it would be more efficient to not create the content in the first
// place
params.save_path = save_path(test_counter(), 1);
// the test is whether this peer will receive the tracker or not
params.trackers.clear();
}
// on alert
, [&](lt::alert const* a, lt::session& ses) {
if (alert_cast<lt::peer_connect_alert>(a))
connected = true;
}
// terminate
, [&](int ticks, lt::session& ses) -> bool {
if (ticks > 10)
{
TEST_ERROR("timeout");
return true;
}
return connected && ses.get_torrents()[0].trackers().size() > 0;
});
TEST_EQUAL(connected, true);
}
TORRENT_TEST(no_metadata)
{
dsl_config network_cfg;
sim::simulation sim{network_cfg};
settings_pack pack = settings();
add_torrent_params p;
p.flags &= ~lt::add_torrent_params::flag_paused;
p.flags &= ~lt::add_torrent_params::flag_auto_managed;
// the default torrent has one tracker
// we remove this from session 0 (the one under test)
p.trackers.push_back("http://test.non-existent.com/announce");
bool connected = false;
setup_swarm(2, swarm_test::upload
, sim , pack, p
// init session
, [](lt::session& ses) {
ses.add_extension(&create_lt_trackers_plugin);
}
// add session
, [](lt::settings_pack& pack) {}
// add torrent
, [](lt::add_torrent_params& params) {
// make sure neither peer has any content
// TODO: it would be more efficient to not create the content in the first
// place
params.save_path = save_path(test_counter(), 1);
// the test is whether this peer will receive the tracker or not
params.trackers.clear();
// if we don't have metadata, the other peer should not send the
// tracker to us
params.info_hash = sha1_hash("aaaaaaaaaaaaaaaaaaaa");
params.ti.reset();
}
// on alert
, [&](lt::alert const* a, lt::session& ses) {
if (alert_cast<lt::peer_connect_alert>(a))
connected = true;
}
// terminate
, [](int ticks, lt::session& ses) -> bool {
if (ticks < 10)
return false;
TEST_EQUAL(ses.get_torrents()[0].trackers().size(), 0);
return true;
});
TEST_EQUAL(connected, true);
}
#else
TORRENT_TEST(dummy) {}
#endif

View File

@ -143,6 +143,7 @@ void node::update_node_id()
m_id = generate_id(m_observer->external_address(protocol()));
m_table.update_node_id(m_id);
m_rpc.update_node_id(m_id);
}
bool node::verify_token(std::string const& token, sha1_hash const& info_hash

View File

@ -61,8 +61,8 @@ namespace libtorrent
{
namespace {
int render_lsd_packet(char* dst, int len, int listen_port
, char const* info_hash_hex, int m_cookie, char const* host)
int render_lsd_packet(char* dst, int const len, int const listen_port
, char const* info_hash_hex, int const cookie, char const* host)
{
TORRENT_ASSERT(len > 0);
return std::snprintf(dst, len,
@ -71,7 +71,7 @@ int render_lsd_packet(char* dst, int len, int listen_port
"Port: %d\r\n"
"Infohash: %s\r\n"
"cookie: %x\r\n"
"\r\n\r\n", host, listen_port, info_hash_hex, m_cookie);
"\r\n\r\n", host, listen_port, info_hash_hex, cookie);
}
} // anonymous namespace
@ -91,7 +91,7 @@ lsd::lsd(io_service& ios, peer_callback_t const& cb
, m_log_cb(log)
#endif
, m_broadcast_timer(ios)
, m_cookie(random() & 0x7fffffff)
, m_cookie((random() ^ boost::uintptr_t(this)) & 0x7fffffff)
, m_disabled(false)
#if TORRENT_USE_IPV6
, m_disabled6(false)
@ -132,8 +132,8 @@ void lsd::announce(sha1_hash const& ih, int listen_port, bool broadcast)
announce_impl(ih, listen_port, broadcast, 0);
}
void lsd::announce_impl(sha1_hash const& ih, int listen_port, bool broadcast
, int retry_count)
void lsd::announce_impl(sha1_hash const& ih, int const listen_port
, bool const broadcast, int retry_count)
{
#if TORRENT_USE_IPV6
if (m_disabled && m_disabled6) return;
@ -152,7 +152,7 @@ void lsd::announce_impl(sha1_hash const& ih, int listen_port, bool broadcast
error_code ec;
if (!m_disabled)
{
int msg_len = render_lsd_packet(msg, sizeof(msg), listen_port, ih_hex
int const msg_len = render_lsd_packet(msg, sizeof(msg), listen_port, ih_hex
, m_cookie, "239.192.152.143");
m_socket.send(msg, msg_len, ec, broadcast ? broadcast_socket::flag_broadcast : 0);
if (ec)
@ -168,7 +168,7 @@ void lsd::announce_impl(sha1_hash const& ih, int listen_port, bool broadcast
#if TORRENT_USE_IPV6
if (!m_disabled6)
{
int msg_len = render_lsd_packet(msg, sizeof(msg), listen_port, ih_hex
int const msg_len = render_lsd_packet(msg, sizeof(msg), listen_port, ih_hex
, m_cookie, "[ff15::efc0:988f]");
m_socket6.send(msg, msg_len, ec, broadcast ? broadcast_socket::flag_broadcast : 0);
if (ec)
@ -251,12 +251,12 @@ void lsd::on_announce(udp::endpoint const& from, char* buf
{
// we expect it to be hexadecimal
// if it isn't, it's not our cookie anyway
std::int32_t cookie = strtol(cookie_iter->second.c_str(), nullptr, 16);
std::int32_t const cookie = strtol(cookie_iter->second.c_str(), nullptr, 16);
if (cookie == m_cookie)
{
#ifndef TORRENT_DISABLE_LOGGING
debug_log("<== LSD: ignoring packet (cookie matched our own): %x == %x"
, cookie, m_cookie);
debug_log("<== LSD: ignoring packet (cookie matched our own): %x"
, cookie);
#endif
return;
}

View File

@ -11105,7 +11105,8 @@ namespace libtorrent
std::vector<announce_entry>::const_iterator i;
for (i = m_trackers.begin(); i != m_trackers.end(); ++i)
{
if (!i->updating) continue;
if (i->updating) continue;
if (!i->verified) continue;
st->current_tracker = i->url;
break;
}

View File

@ -422,9 +422,16 @@ TORRENT_TEST(http_peers)
addp.save_path = "tmp2_tracker";
torrent_handle h = s->add_torrent(addp);
libtorrent::torrent_status status = h.status();
TEST_CHECK(status.current_tracker.empty());
// wait to hit the tracker
wait_for_alert(*s, tracker_reply_alert::alert_type, "s");
status = h.status();
TEST_CHECK(!status.current_tracker.empty());
TEST_CHECK(status.current_tracker == tracker_url);
// we expect to have certain peers in our peer list now
// these peers are hard coded in web_server.py
std::vector<peer_list_entry> peers;
@ -456,6 +463,61 @@ TORRENT_TEST(http_peers)
std::fprintf(stderr, "done\n");
}
TORRENT_TEST(current_tracker)
{
// use a invalid tracker port
int http_port = 39527;
settings_pack pack = settings();
pack.set_bool(settings_pack::announce_to_all_trackers, true);
pack.set_bool(settings_pack::announce_to_all_tiers, false);
pack.set_int(settings_pack::tracker_completion_timeout, 2);
pack.set_int(settings_pack::tracker_receive_timeout, 1);
pack.set_str(settings_pack::listen_interfaces, "0.0.0.0:39775");
//pack.set_int(settings_pack::alert_mask, alert::tracker_notification);
boost::scoped_ptr<lt::session> s(new lt::session(pack));
error_code ec;
remove_all("tmp3_tracker", ec);
create_directory("tmp3_tracker", ec);
std::ofstream file(combine_path("tmp3_tracker", "temporary").c_str());
boost::shared_ptr<torrent_info> t = ::create_torrent(&file, "temporary", 16 * 1024, 13, false);
file.close();
char tracker_url[200];
snprintf(tracker_url, sizeof(tracker_url), "http://127.0.0.1:%d/announce"
, http_port);
t->add_tracker(tracker_url, 0);
add_torrent_params addp;
addp.flags &= ~add_torrent_params::flag_paused;
addp.flags &= ~add_torrent_params::flag_auto_managed;
addp.flags |= add_torrent_params::flag_seed_mode;
addp.ti = t;
addp.save_path = "tmp3_tracker";
torrent_handle h = s->add_torrent(addp);
libtorrent::torrent_status status = h.status();
TEST_CHECK(status.current_tracker.empty());
// wait to hit the tracker announce
wait_for_alert(*s, tracker_announce_alert::alert_type, "s");
status = h.status();
TEST_CHECK(status.current_tracker.empty());
// wait to hit the tracker error
wait_for_alert(*s, tracker_error_alert::alert_type, "s");
status = h.status();
TEST_CHECK(status.current_tracker.empty());
fprintf(stderr, "destructing session\n");
s.reset();
fprintf(stderr, "done\n");
}
void test_proxy(bool proxy_trackers)
{
int http_port = start_web_server();