merged RC_1_1 into master

This commit is contained in:
Arvid Norberg 2018-04-02 00:03:43 +02:00
commit 16f1deb3ec
10 changed files with 134 additions and 43 deletions

View File

@ -82,6 +82,7 @@
* resume data no longer has timestamps of files * resume data no longer has timestamps of files
* require C++11 to build libtorrent * require C++11 to build libtorrent
* don't perform DNS lookups for the DHT bootstrap unless DHT is enabled
* fix issue where setting file/piece priority would stop checking * fix issue where setting file/piece priority would stop checking
* expose post_dht_stats() to python binding * expose post_dht_stats() to python binding
* fix backwards compatibility to downloads without partfiles * fix backwards compatibility to downloads without partfiles

View File

@ -8,6 +8,8 @@ import modules ;
use-project /torrent : ../.. ; use-project /torrent : ../.. ;
BOOST_ROOT = [ modules.peek : BOOST_ROOT ] ; BOOST_ROOT = [ modules.peek : BOOST_ROOT ] ;
# this is used to make bjam use the same version of python which is executing setup.py
LIBTORRENT_PYTHON_INTERPRETER = [ modules.peek : LIBTORRENT_PYTHON_INTERPRETER ] ;
feature visibility : default hidden : composite ; feature visibility : default hidden : composite ;
feature.compose <visibility>hidden : <cflags>-fvisibility=hidden <cxxflags>-fvisibility-inlines-hidden ; feature.compose <visibility>hidden : <cflags>-fvisibility=hidden <cxxflags>-fvisibility-inlines-hidden ;
@ -16,10 +18,20 @@ feature libtorrent-link : shared static : composite propagated ;
feature libtorrent-python-pic : off on : composite propagated link-incompatible ; feature libtorrent-python-pic : off on : composite propagated link-incompatible ;
feature.compose <libtorrent-python-pic>on : <cflags>-fPIC ; feature.compose <libtorrent-python-pic>on : <cflags>-fPIC ;
# this is just to force boost build to pick the desired python target when using LIBTORRENT_PYTHON_INTERPRETER
feature libtorrent-python : on ;
if $(LIBTORRENT_PYTHON_INTERPRETER)
{
echo "using python interpreter at: " $(LIBTORRENT_PYTHON_INTERPRETER) ;
using python : : "$(LIBTORRENT_PYTHON_INTERPRETER)" : : : <libtorrent-python>on ;
}
if $(BOOST_ROOT) if $(BOOST_ROOT)
{ {
use-project /boost : $(BOOST_ROOT) ; use-project /boost : $(BOOST_ROOT) ;
alias boost_python : /boost/python//boost_python : : : <include>$(BOOST_ROOT) ; alias boost_python : /boost/python//boost_python : : : <include>$(BOOST_ROOT) ;
alias boost_python3 : /boost/python//boost_python3 : : : <include>$(BOOST_ROOT) ;
} }
else else
{ {
@ -40,9 +52,13 @@ else
# the names are decorated in MacPorts # the names are decorated in MacPorts
lib boost_python : : <target-os>darwin <name>boost_python-mt lib boost_python : : <target-os>darwin <name>boost_python-mt
: : $(boost-include-path) ; : : $(boost-include-path) ;
lib boost_python3 : : <target-os>darwin <name>boost_python3-mt
: : $(boost-include-path) ;
lib boost_python : : <name>boost_python lib boost_python : : <name>boost_python
: : $(boost-include-path) ; : : $(boost-include-path) ;
lib boost_python3 : : <name>boost_python3
: : $(boost-include-path) ;
} }
@ -80,16 +96,33 @@ rule libtorrent_linking ( properties * )
ECHO "WARNING: you cannot link statically against boost-python on linux, because it links against pthread statically in that case, which is not allowed" ; ECHO "WARNING: you cannot link statically against boost-python on linux, because it links against pthread statically in that case, which is not allowed" ;
} }
local boost_python_lib ;
for local prop in $(properties)
{
switch $(prop)
{
case <python>2.* : boost_python_lib = boost_python ;
case <python>3.* : boost_python_lib = boost_python3 ;
}
}
if ! $(boost_python_lib)
{
ECHO "WARNING: unknown python version" ;
boost_python_lib = boost_python ;
}
# linux must link dynamically against boost python because it pulls # linux must link dynamically against boost python because it pulls
# in libpthread, which must be linked dynamically since we're building a .so # in libpthread, which must be linked dynamically since we're building a .so
# (the static build of libpthread is not position independent) # (the static build of libpthread is not position independent)
if <boost-link>shared in $(properties) || <target-os>linux in $(properties) if <boost-link>shared in $(properties) || <target-os>linux in $(properties)
{ {
result += <library>boost_python/<link>shared/<warnings>off ; result += <library>$(boost_python_lib)/<link>shared/<warnings>off ;
} }
else else
{ {
result += <library>boost_python/<link>static/<warnings>off ; result += <library>$(boost_python_lib)/<link>static/<warnings>off ;
} }
if <libtorrent-link>shared in $(properties) if <libtorrent-link>shared in $(properties)
@ -169,6 +202,7 @@ install stage_module
install stage_dependencies install stage_dependencies
: /torrent//torrent : /torrent//torrent
boost_python boost_python
boost_python3
: <location>dependencies : <location>dependencies
<install-dependencies>on <install-dependencies>on
<install-type>SHARED_LIB <install-type>SHARED_LIB

View File

@ -84,39 +84,59 @@ packages = None
if '--bjam' in sys.argv: if '--bjam' in sys.argv:
del sys.argv[sys.argv.index('--bjam')] del sys.argv[sys.argv.index('--bjam')]
if '--help' not in sys.argv and '--help-commands' not in sys.argv: if '--help' not in sys.argv \
if platform.system() == 'Windows': and '--help-commands' not in sys.argv:
file_ext = '.pyd'
else: toolset = ''
file_ext = '.so' file_ext = '.so'
if platform.system() == 'Windows':
file_ext = '.pyd'
# See https://wiki.python.org/moin/WindowsCompilers for a table of msvc versions
# used for each python version
# Specify the full version number for 9.0 and 10.0 because apparently
# older versions of boost don't support only specifying the major number and
# there was only one version of msvc with those majors.
# Only specify the major for msvc-14 so that 14.1, 14.11, etc can be used.
# Hopefully people building with msvc-14 are using a new enough version of boost
# for this to work.
if sys.version_info[0:2] in ((2, 6), (2, 7), (3, 0), (3, 1), (3, 2)):
toolset = ' toolset=msvc-9.0'
elif sys.version_info[0:2] in ((3, 3), (3, 4)):
toolset = ' toolset=msvc-10.0'
elif sys.version_info[0:2] in ((3, 5), (3, 6)):
toolset = ' toolset=msvc-14'
else:
# unknown python version, lets hope the user has the right version of msvc configured
toolset = ' toolset=msvc'
parallel_builds = ' -j%d' % multiprocessing.cpu_count() parallel_builds = ' -j%d' % multiprocessing.cpu_count()
if sys.maxsize > 2**32:
address_model = ' address-model=64'
else:
address_model = ' address-model=32'
# add extra quoting around the path to prevent bjam from parsing it as a list
# if the path has spaces
os.environ['LIBTORRENT_PYTHON_INTERPRETER'] = '"' + sys.executable + '"'
# build libtorrent using bjam and build the installer with distutils # build libtorrent using bjam and build the installer with distutils
cmdline = ('b2 libtorrent-link=static boost-link=static release ' cmdline = ('b2 libtorrent-link=static boost-link=static release '
'optimization=space stage_module --abbreviate-paths' + 'optimization=space stage_module --abbreviate-paths' +
parallel_builds) address_model + toolset + parallel_builds)
print(cmdline) print(cmdline)
if os.system(cmdline) != 0: if os.system(cmdline) != 0:
print('build failed') print('build failed')
sys.exit(1) sys.exit(1)
try: try: os.mkdir('build')
os.mkdir('build') except: pass
except: try: shutil.rmtree('build/lib')
pass except: pass
try: try: os.mkdir('build/lib')
shutil.rmtree('build/lib') except: pass
except: try: os.mkdir('libtorrent')
pass except: pass
try:
os.mkdir('build/lib')
except:
pass
try:
os.mkdir('libtorrent')
except:
pass
shutil.copyfile('libtorrent' + file_ext, shutil.copyfile('libtorrent' + file_ext,
'build/lib/libtorrent' + file_ext) 'build/lib/libtorrent' + file_ext)

View File

@ -505,13 +505,14 @@ class test_session(unittest.TestCase):
s.post_session_stats() s.post_session_stats()
alerts = [] alerts = []
# first the stats headers log line. but not if logging is disabled # first the stats headers log line. but not if logging is disabled
while len(alerts) == 0:
s.wait_for_alert(1000) s.wait_for_alert(1000)
alerts = s.pop_alerts() alerts = s.pop_alerts()
a = alerts.pop(0) a = alerts.pop(0)
print(a) print(a)
self.assertTrue(isinstance(a, lt.session_stats_header_alert)) self.assertTrue(isinstance(a, lt.session_stats_header_alert))
# then the actual stats values # then the actual stats values
if len(alerts) == 0: while len(alerts) == 0:
s.wait_for_alert(1000) s.wait_for_alert(1000)
alerts = s.pop_alerts() alerts = s.pop_alerts()
a = alerts.pop(0) a = alerts.pop(0)
@ -525,12 +526,16 @@ class test_session(unittest.TestCase):
s.post_dht_stats() s.post_dht_stats()
alerts = [] alerts = []
# first the stats headers log line. but not if logging is disabled # first the stats headers log line. but not if logging is disabled
time.sleep(1) while len(alerts) == 0:
s.wait_for_alert(1000)
alerts = s.pop_alerts()
a = alerts.pop(0)
self.assertTrue(isinstance(a, lt.session_stats_header_alert))
print(a.message())
while len(alerts) == 0:
s.wait_for_alert(1000)
alerts = s.pop_alerts() alerts = s.pop_alerts()
a = alerts.pop(0) a = alerts.pop(0)
while not isinstance(a, lt.dht_stats_alert):
a = alerts.pop(0
)
self.assertTrue(isinstance(a, lt.dht_stats_alert)) self.assertTrue(isinstance(a, lt.dht_stats_alert))
self.assertTrue(isinstance(a.active_requests, list)) self.assertTrue(isinstance(a.active_requests, list))
self.assertTrue(isinstance(a.routing_table, list)) self.assertTrue(isinstance(a.routing_table, list))

3
setup.py Executable file → Normal file
View File

@ -3,5 +3,4 @@
import os import os
os.chdir('bindings/python') os.chdir('bindings/python')
with open('setup.py') as filename: exec(open('setup.py').read())
exec(filename.read())

@ -1 +1 @@
Subproject commit 26c08bd1dd6e3d7ff7b22aae3be43addcd6cd584 Subproject commit 8905f8a0faec37ea0655fc2e7921fad40e904749

View File

@ -286,7 +286,7 @@ TORRENT_EXPORT void assert_print(char const* fmt, ...)
if (assert_counter > 500) return; if (assert_counter > 500) return;
FILE* out = fopen(libtorrent_assert_log, "a+"); FILE* out = fopen(libtorrent_assert_log, "a+");
if (out == 0) out = stderr; if (out == nullptr) out = stderr;
#else #else
FILE* out = stderr; FILE* out = stderr;
#endif #endif

View File

@ -626,12 +626,18 @@ namespace libtorrent { namespace dht {
void dht_tracker::add_node(udp::endpoint const& node) void dht_tracker::add_node(udp::endpoint const& node)
{ {
#if !TORRENT_USE_IPV6
TORRENT_ASSERT(is_v4(node));
#endif
for (auto& n : m_nodes) for (auto& n : m_nodes)
n.second.dht.add_node(node); n.second.dht.add_node(node);
} }
void dht_tracker::add_router_node(udp::endpoint const& node) void dht_tracker::add_router_node(udp::endpoint const& node)
{ {
#if !TORRENT_USE_IPV6
TORRENT_ASSERT(is_v4(node));
#endif
for (auto& n : m_nodes) for (auto& n : m_nodes)
n.second.dht.add_router_node(node); n.second.dht.add_router_node(node);
} }

View File

@ -1021,6 +1021,9 @@ void routing_table::node_failed(node_id const& nid, udp::endpoint const& ep)
void routing_table::add_router_node(udp::endpoint const& router) void routing_table::add_router_node(udp::endpoint const& router)
{ {
#if !TORRENT_USE_IPV6
TORRENT_ASSERT(is_v4(router));
#endif
m_router_nodes.insert(router); m_router_nodes.insert(router);
} }

View File

@ -730,7 +730,7 @@ namespace aux {
} }
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
if (need_update_dht) update_dht(); if (need_update_dht) start_dht();
#endif #endif
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
if (need_update_proxy) update_proxy(); if (need_update_proxy) update_proxy();
@ -3533,6 +3533,9 @@ namespace aux {
void session_impl::add_dht_node(udp::endpoint const& n) void session_impl::add_dht_node(udp::endpoint const& n)
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
#if !TORRENT_USE_IPV6
if (!is_v4(n)) return;
#endif
if (m_dht) m_dht->add_node(n); if (m_dht) m_dht->add_node(n);
else m_dht_nodes.push_back(n); else m_dht_nodes.push_back(n);
@ -5303,7 +5306,20 @@ namespace aux {
{ {
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
if (m_settings.get_bool(settings_pack::enable_dht)) if (m_settings.get_bool(settings_pack::enable_dht))
{
if (!m_settings.get_str(settings_pack::dht_bootstrap_nodes).empty()
&& m_dht_router_nodes.empty())
{
// if we have bootstrap nodes configured, make sure we initiate host
// name lookups. once these complete, the DHT will be started.
// they are tracked by m_outstanding_router_lookups
update_dht_bootstrap_nodes();
}
else
{
start_dht(); start_dht();
}
}
else else
stop_dht(); stop_dht();
#endif #endif
@ -5312,6 +5328,8 @@ namespace aux {
void session_impl::update_dht_bootstrap_nodes() void session_impl::update_dht_bootstrap_nodes()
{ {
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
if (!m_settings.get_bool(settings_pack::enable_dht)) return;
std::string const& node_list = m_settings.get_str(settings_pack::dht_bootstrap_nodes); std::string const& node_list = m_settings.get_str(settings_pack::dht_bootstrap_nodes);
std::vector<std::pair<std::string, int>> nodes; std::vector<std::pair<std::string, int>> nodes;
parse_comma_separated_string_port(node_list, nodes); parse_comma_separated_string_port(node_list, nodes);
@ -5630,6 +5648,8 @@ namespace aux {
stop_dht(); stop_dht();
if (!m_settings.get_bool(settings_pack::enable_dht)) return;
// postpone starting the DHT if we're still resolving the DHT router // postpone starting the DHT if we're still resolving the DHT router
if (m_outstanding_router_lookups > 0) if (m_outstanding_router_lookups > 0)
{ {
@ -5795,20 +5815,23 @@ namespace aux {
m_alerts.emplace_alert<dht_error_alert>( m_alerts.emplace_alert<dht_error_alert>(
operation_t::hostname_lookup, e); operation_t::hostname_lookup, e);
if (m_outstanding_router_lookups == 0) update_dht(); if (m_outstanding_router_lookups == 0) start_dht();
return; return;
} }
for (auto const& addr : addresses) for (auto const& addr : addresses)
{ {
#if !TORRENT_USE_IPV6
if (!i->is_v4()) continue;
#endif
// router nodes should be added before the DHT is started (and bootstrapped) // router nodes should be added before the DHT is started (and bootstrapped)
udp::endpoint ep(addr, std::uint16_t(port)); udp::endpoint ep(addr, std::uint16_t(port));
if (m_dht) m_dht->add_router_node(ep); if (m_dht) m_dht->add_router_node(ep);
m_dht_router_nodes.push_back(ep); m_dht_router_nodes.push_back(ep);
} }
if (m_outstanding_router_lookups == 0) update_dht(); if (m_outstanding_router_lookups == 0) start_dht();
} }
// callback for dht_immutable_get // callback for dht_immutable_get