forked from premiere/premiere-libtorrent
merged RC_1_1 into master
This commit is contained in:
commit
7c108e6c19
|
@ -14,6 +14,9 @@
|
|||
|
||||
1.1.1 release
|
||||
|
||||
* make sure add_torrent_alert is always posted before other alerts for
|
||||
the torrent
|
||||
* fixed peer-class leak when settings per-torrent rate limits
|
||||
* added a new "preformatted" type to bencode entry variant type
|
||||
* improved Socks5 support and test coverage
|
||||
* fix set_settings in python binding
|
||||
|
|
|
@ -184,16 +184,44 @@ def html_sanitize(s):
|
|||
else: ret += i
|
||||
return ret
|
||||
|
||||
def looks_like_variable(line):
|
||||
def looks_like_namespace(line):
|
||||
line = line.strip()
|
||||
if line.startswith('namespace'): return True
|
||||
return False
|
||||
|
||||
def looks_like_blank(line):
|
||||
line = line.split('//')[0]
|
||||
line = line.replace('{', '')
|
||||
line = line.replace('}', '')
|
||||
line = line.replace('[', '')
|
||||
line = line.replace(']', '')
|
||||
line = line.replace(';', '')
|
||||
line = line.strip()
|
||||
return len(line) == 0
|
||||
|
||||
def looks_like_variable(line):
|
||||
line = line.split('//')[0]
|
||||
line = line.strip()
|
||||
if not line.endswith(';'): return False
|
||||
if not ' ' in line and not '\t' in line: return False
|
||||
if line.startswith('friend '): return False
|
||||
if line.startswith('enum '): return False
|
||||
if line.startswith(','): return False
|
||||
if line.startswith(':'): return False
|
||||
if line.startswith('typedef'): return False
|
||||
return True
|
||||
if ' = ' in line: return True
|
||||
if line.endswith(';'): return True
|
||||
return False
|
||||
|
||||
def looks_like_forward_decl(line):
|
||||
line = line.split('//')[0]
|
||||
line = line.strip()
|
||||
if not line.endswith(';'): return False
|
||||
if '{' in line: return False
|
||||
if '}' in line: return False
|
||||
if line.startswith('friend '): return True
|
||||
if line.startswith('struct '): return True
|
||||
if line.startswith('class '): return True
|
||||
return False
|
||||
|
||||
def looks_like_function(line):
|
||||
if line.startswith('friend'): return False
|
||||
|
@ -345,8 +373,10 @@ def parse_class(lno, lines, filename):
|
|||
continue
|
||||
|
||||
if looks_like_variable(l):
|
||||
if verbose: print 'var %s' % l
|
||||
if not is_visible(context):
|
||||
continue
|
||||
l = l.split('//')[0].strip()
|
||||
n = l.split(' ')[-1].split(':')[0].split(';')[0]
|
||||
if context == '' and blanks == 0 and len(fields):
|
||||
fields[-1]['names'].append(n)
|
||||
|
@ -361,6 +391,7 @@ def parse_class(lno, lines, filename):
|
|||
continue
|
||||
|
||||
if l.startswith('enum '):
|
||||
if verbose: print 'enum %s' % l
|
||||
if not is_visible(context):
|
||||
consume_block(lno - 1, lines)
|
||||
else:
|
||||
|
@ -375,7 +406,14 @@ def parse_class(lno, lines, filename):
|
|||
continue
|
||||
|
||||
context = ''
|
||||
if verbose: print '?? %s' % l
|
||||
|
||||
if verbose:
|
||||
if looks_like_forward_decl(l) \
|
||||
or looks_like_blank(l) \
|
||||
or looks_like_namespace(l):
|
||||
print '-- %s' % l
|
||||
else:
|
||||
print '?? %s' % l
|
||||
|
||||
if len(name) > 0:
|
||||
print '\x1b[31mFAILED TO PARSE CLASS\x1b[0m %s\nfile: %s:%d' % (name, filename, lno)
|
||||
|
@ -657,7 +695,13 @@ for filename in files:
|
|||
continue
|
||||
|
||||
blanks += 1
|
||||
if verbose: print '?? %s' % l
|
||||
if verbose:
|
||||
if looks_like_forward_decl(l) \
|
||||
or looks_like_blank(l) \
|
||||
or looks_like_namespace(l):
|
||||
print '-- %s' % l
|
||||
else:
|
||||
print '?? %s' % l
|
||||
|
||||
context = ''
|
||||
h.close()
|
||||
|
|
|
@ -62,7 +62,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
namespace libtorrent
|
||||
{
|
||||
#if defined TORRENT_BUILD_SIMULATOR
|
||||
using address = typedef sim::asio::ip::address;
|
||||
using address = sim::asio::ip::address;
|
||||
using address_v4 = sim::asio::ip::address_v4;
|
||||
#if TORRENT_USE_IPV6
|
||||
using address_v6 = sim::asio::ip::address_v6;
|
||||
|
|
|
@ -418,7 +418,7 @@ namespace libtorrent
|
|||
#endif
|
||||
|
||||
torrent_handle add_torrent(add_torrent_params const&, error_code& ec);
|
||||
torrent_handle add_torrent_impl(add_torrent_params const&, error_code& ec);
|
||||
boost::shared_ptr<torrent> add_torrent_impl(add_torrent_params& p, error_code& ec);
|
||||
void async_add_torrent(add_torrent_params* params);
|
||||
void on_async_load_torrent(disk_io_job const* j);
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit ad23c932ecd852f89c7d8b29dfe162e9ee073a1b
|
||||
Subproject commit ea3bffe3c53bca5e0976914ea951193ba43fbed6
|
|
@ -47,6 +47,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "setup_swarm.hpp"
|
||||
#include "setup_transfer.hpp" // for create_torrent
|
||||
#include "utils.hpp"
|
||||
#include "simulator/queue.hpp"
|
||||
|
||||
namespace lt = libtorrent;
|
||||
using namespace sim;
|
||||
|
|
|
@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "setup_swarm.hpp"
|
||||
#include "simulator/simulator.hpp"
|
||||
#include "libtorrent/alert_types.hpp"
|
||||
#include "libtorrent/settings_pack.hpp"
|
||||
|
||||
using namespace libtorrent;
|
||||
using namespace sim;
|
||||
|
@ -98,3 +99,45 @@ TORRENT_TEST(status_timers)
|
|||
});
|
||||
}
|
||||
|
||||
// This test makes sure that adding a torrent causes no torrent related alert to
|
||||
// be posted _before_ the add_torrent_alert, which is expected to always be the
|
||||
// first
|
||||
TORRENT_TEST(alert_order)
|
||||
{
|
||||
bool received_add_torrent_alert = false;
|
||||
int num_torrent_alerts = 0;
|
||||
|
||||
lt::torrent_handle handle;
|
||||
|
||||
setup_swarm(1, swarm_test::upload
|
||||
// add session
|
||||
, [](lt::settings_pack& sett) {
|
||||
sett.set_int(settings_pack::alert_mask, alert::all_categories);
|
||||
}
|
||||
// add torrent
|
||||
, [](lt::add_torrent_params& params) {}
|
||||
// on alert
|
||||
, [&](lt::alert const* a, lt::session& ses) {
|
||||
if (auto ta = alert_cast<add_torrent_alert>(a))
|
||||
{
|
||||
TEST_EQUAL(received_add_torrent_alert, false);
|
||||
received_add_torrent_alert = true;
|
||||
handle = ta->handle;
|
||||
}
|
||||
|
||||
if (auto ta = dynamic_cast<torrent_alert const*>(a))
|
||||
{
|
||||
TEST_EQUAL(received_add_torrent_alert, true);
|
||||
TEST_CHECK(handle == ta->handle);
|
||||
++num_torrent_alerts;
|
||||
}
|
||||
}
|
||||
// terminate
|
||||
, [&](int ticks, lt::session& ses) -> bool
|
||||
{ return ticks > 10; }
|
||||
);
|
||||
|
||||
TEST_EQUAL(received_add_torrent_alert, true);
|
||||
TEST_CHECK(num_torrent_alerts > 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -90,7 +90,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#if TORRENT_USE_IFADDRS || TORRENT_USE_IFCONF || TORRENT_USE_NETLINK || TORRENT_USE_SYSCTL
|
||||
// capture this here where warnings are disabled (the macro generates warnings)
|
||||
const int siocgifmtu = SIOCGIFMTU;
|
||||
const unsigned long siocgifmtu = SIOCGIFMTU;
|
||||
#endif
|
||||
|
||||
#include "libtorrent/aux_/disable_warnings_pop.hpp"
|
||||
|
|
|
@ -4670,119 +4670,20 @@ namespace aux {
|
|||
torrent_handle session_impl::add_torrent(add_torrent_params const& p
|
||||
, error_code& ec)
|
||||
{
|
||||
torrent_handle h = add_torrent_impl(p, ec);
|
||||
m_alerts.emplace_alert<add_torrent_alert>(h, p, ec);
|
||||
return h;
|
||||
}
|
||||
|
||||
torrent_handle session_impl::add_torrent_impl(add_torrent_params const& p
|
||||
, error_code& ec)
|
||||
{
|
||||
TORRENT_ASSERT(!p.save_path.empty());
|
||||
|
||||
// params is updated by add_torrent_impl()
|
||||
add_torrent_params params = p;
|
||||
if (string_begins_no_case("magnet:", params.url.c_str()))
|
||||
{
|
||||
parse_magnet_uri(params.url, params, ec);
|
||||
if (ec) return torrent_handle();
|
||||
params.url.clear();
|
||||
}
|
||||
boost::shared_ptr<torrent> const torrent_ptr = add_torrent_impl(params, ec);
|
||||
|
||||
if (string_begins_no_case("file://", params.url.c_str()) && !params.ti)
|
||||
{
|
||||
std::string filename = resolve_file_url(params.url);
|
||||
boost::shared_ptr<torrent_info> t = boost::make_shared<torrent_info>(filename, boost::ref(ec), 0);
|
||||
if (ec) return torrent_handle();
|
||||
params.url.clear();
|
||||
params.ti = t;
|
||||
}
|
||||
torrent_handle const handle(torrent_ptr);
|
||||
m_alerts.emplace_alert<add_torrent_alert>(handle, params, ec);
|
||||
|
||||
if (params.ti && params.ti->is_valid() && params.ti->num_files() == 0)
|
||||
{
|
||||
ec = errors::no_files_in_torrent;
|
||||
return torrent_handle();
|
||||
}
|
||||
if (!torrent_ptr) return handle;
|
||||
|
||||
#ifndef TORRENT_DISABLE_DHT
|
||||
// add p.dht_nodes to the DHT, if enabled
|
||||
if (!p.dht_nodes.empty())
|
||||
{
|
||||
for (std::vector<std::pair<std::string, int> >::const_iterator i = p.dht_nodes.begin()
|
||||
, end(p.dht_nodes.end()); i != end; ++i)
|
||||
{
|
||||
add_dht_node_name(*i);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
INVARIANT_CHECK;
|
||||
|
||||
if (is_aborted())
|
||||
{
|
||||
ec = errors::session_is_closing;
|
||||
return torrent_handle();
|
||||
}
|
||||
|
||||
// figure out the info hash of the torrent
|
||||
sha1_hash const* ih = 0;
|
||||
sha1_hash tmp;
|
||||
if (params.ti) ih = ¶ms.ti->info_hash();
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
//deprecated in 1.2
|
||||
else if (!params.url.empty())
|
||||
{
|
||||
// in order to avoid info-hash collisions, for
|
||||
// torrents where we don't have an info-hash, but
|
||||
// just a URL, set the temporary info-hash to the
|
||||
// hash of the URL. This will be changed once we
|
||||
// have the actual .torrent file
|
||||
tmp = hasher(¶ms.url[0], int(params.url.size())).final();
|
||||
ih = &tmp;
|
||||
}
|
||||
#endif
|
||||
else ih = ¶ms.info_hash;
|
||||
|
||||
// is the torrent already active?
|
||||
boost::shared_ptr<torrent> torrent_ptr = find_torrent(*ih).lock();
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
//deprecated in 1.2
|
||||
if (!torrent_ptr && !params.uuid.empty()) torrent_ptr = find_torrent(params.uuid).lock();
|
||||
// if we still can't find the torrent, look for it by url
|
||||
if (!torrent_ptr && !params.url.empty())
|
||||
{
|
||||
torrent_map::iterator i = std::find_if(m_torrents.begin()
|
||||
, m_torrents.end(), boost::bind(&torrent::url, boost::bind(&std::pair<const sha1_hash
|
||||
, boost::shared_ptr<torrent> >::second, _1)) == params.url);
|
||||
if (i != m_torrents.end())
|
||||
torrent_ptr = i->second;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (torrent_ptr)
|
||||
{
|
||||
if ((params.flags & add_torrent_params::flag_duplicate_is_error) == 0)
|
||||
{
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
//deprecated in 1.2
|
||||
if (!params.uuid.empty() && torrent_ptr->uuid().empty())
|
||||
torrent_ptr->set_uuid(params.uuid);
|
||||
if (!params.url.empty() && torrent_ptr->url().empty())
|
||||
torrent_ptr->set_url(params.url);
|
||||
#endif
|
||||
return torrent_handle(torrent_ptr);
|
||||
}
|
||||
|
||||
ec = errors::duplicate_torrent;
|
||||
return torrent_handle();
|
||||
}
|
||||
|
||||
int queue_pos = ++m_max_queue_pos;
|
||||
|
||||
torrent_ptr = boost::make_shared<torrent>(boost::ref(*this)
|
||||
, 16 * 1024, queue_pos, boost::cref(params), boost::cref(*ih));
|
||||
// params.info_hash should have been initialized by add_torrent_impl()
|
||||
TORRENT_ASSERT(params.info_hash != sha1_hash(0));
|
||||
|
||||
if (m_alerts.should_post<torrent_added_alert>())
|
||||
m_alerts.emplace_alert<torrent_added_alert>(torrent_ptr->get_handle());
|
||||
m_alerts.emplace_alert<torrent_added_alert>(handle);
|
||||
|
||||
torrent_ptr->set_ip_filter(m_ip_filter);
|
||||
torrent_ptr->start(params);
|
||||
|
@ -4795,8 +4696,7 @@ namespace aux {
|
|||
for (torrent_plugins_t::const_iterator i = params.extensions.begin()
|
||||
, end(params.extensions.end()); i != end; ++i)
|
||||
{
|
||||
torrent_ptr->add_extension((*i)(torrent_ptr->get_handle(),
|
||||
params.userdata));
|
||||
torrent_ptr->add_extension((*i)(handle, params.userdata));
|
||||
}
|
||||
|
||||
add_extensions_to_torrent(torrent_ptr, params.userdata);
|
||||
|
@ -4824,14 +4724,14 @@ namespace aux {
|
|||
#endif
|
||||
float load_factor = m_torrents.load_factor();
|
||||
|
||||
m_torrents.insert(std::make_pair(*ih, torrent_ptr));
|
||||
m_torrents.insert(std::make_pair(params.info_hash, torrent_ptr));
|
||||
|
||||
TORRENT_ASSERT(m_torrents.size() >= m_torrent_lru.size());
|
||||
|
||||
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
|
||||
hasher h;
|
||||
h.update("req2", 4);
|
||||
h.update(ih->data(), 20);
|
||||
h.update(params.info_hash.data(), 20);
|
||||
// this is SHA1("req2" + info-hash), used for
|
||||
// encrypted hand shakes
|
||||
m_obfuscated_torrents.insert(std::make_pair(h.final(), torrent_ptr));
|
||||
|
@ -4891,7 +4791,115 @@ namespace aux {
|
|||
}
|
||||
}
|
||||
|
||||
return torrent_handle(torrent_ptr);
|
||||
return handle;
|
||||
}
|
||||
|
||||
boost::shared_ptr<torrent> session_impl::add_torrent_impl(
|
||||
add_torrent_params& params
|
||||
, error_code& ec)
|
||||
{
|
||||
TORRENT_ASSERT(!params.save_path.empty());
|
||||
|
||||
typedef boost::shared_ptr<torrent> ptr_t;
|
||||
|
||||
if (string_begins_no_case("magnet:", params.url.c_str()))
|
||||
{
|
||||
parse_magnet_uri(params.url, params, ec);
|
||||
if (ec) return ptr_t();
|
||||
params.url.clear();
|
||||
}
|
||||
|
||||
if (string_begins_no_case("file://", params.url.c_str()) && !params.ti)
|
||||
{
|
||||
std::string filename = resolve_file_url(params.url);
|
||||
boost::shared_ptr<torrent_info> t = boost::make_shared<torrent_info>(filename, boost::ref(ec), 0);
|
||||
if (ec) return ptr_t();
|
||||
params.url.clear();
|
||||
params.ti = t;
|
||||
}
|
||||
|
||||
if (params.ti && params.ti->is_valid() && params.ti->num_files() == 0)
|
||||
{
|
||||
ec = errors::no_files_in_torrent;
|
||||
return ptr_t();
|
||||
}
|
||||
|
||||
#ifndef TORRENT_DISABLE_DHT
|
||||
// add params.dht_nodes to the DHT, if enabled
|
||||
if (!params.dht_nodes.empty())
|
||||
{
|
||||
for (std::vector<std::pair<std::string, int> >::const_iterator i = params.dht_nodes.begin()
|
||||
, end(params.dht_nodes.end()); i != end; ++i)
|
||||
{
|
||||
add_dht_node_name(*i);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
INVARIANT_CHECK;
|
||||
|
||||
if (is_aborted())
|
||||
{
|
||||
ec = errors::session_is_closing;
|
||||
return ptr_t();
|
||||
}
|
||||
|
||||
// figure out the info hash of the torrent and make sure params.info_hash
|
||||
// is set correctly
|
||||
if (params.ti) params.info_hash = params.ti->info_hash();
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
//deprecated in 1.2
|
||||
else if (!params.url.empty())
|
||||
{
|
||||
// in order to avoid info-hash collisions, for
|
||||
// torrents where we don't have an info-hash, but
|
||||
// just a URL, set the temporary info-hash to the
|
||||
// hash of the URL. This will be changed once we
|
||||
// have the actual .torrent file
|
||||
params.info_hash = hasher(¶ms.url[0], int(params.url.size())).final();
|
||||
}
|
||||
#endif
|
||||
|
||||
// is the torrent already active?
|
||||
boost::shared_ptr<torrent> torrent_ptr = find_torrent(params.info_hash).lock();
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
//deprecated in 1.2
|
||||
if (!torrent_ptr && !params.uuid.empty()) torrent_ptr = find_torrent(params.uuid).lock();
|
||||
// if we still can't find the torrent, look for it by url
|
||||
if (!torrent_ptr && !params.url.empty())
|
||||
{
|
||||
torrent_map::iterator i = std::find_if(m_torrents.begin()
|
||||
, m_torrents.end(), boost::bind(&torrent::url, boost::bind(&std::pair<const sha1_hash
|
||||
, boost::shared_ptr<torrent> >::second, _1)) == params.url);
|
||||
if (i != m_torrents.end())
|
||||
torrent_ptr = i->second;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (torrent_ptr)
|
||||
{
|
||||
if ((params.flags & add_torrent_params::flag_duplicate_is_error) == 0)
|
||||
{
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
//deprecated in 1.2
|
||||
if (!params.uuid.empty() && torrent_ptr->uuid().empty())
|
||||
torrent_ptr->set_uuid(params.uuid);
|
||||
if (!params.url.empty() && torrent_ptr->url().empty())
|
||||
torrent_ptr->set_url(params.url);
|
||||
#endif
|
||||
return torrent_ptr;
|
||||
}
|
||||
|
||||
ec = errors::duplicate_torrent;
|
||||
return ptr_t();
|
||||
}
|
||||
|
||||
int queue_pos = ++m_max_queue_pos;
|
||||
|
||||
torrent_ptr = boost::make_shared<torrent>(boost::ref(*this)
|
||||
, 16 * 1024, queue_pos, boost::cref(params), boost::cref(params.info_hash));
|
||||
|
||||
return torrent_ptr;
|
||||
}
|
||||
|
||||
void session_impl::update_outgoing_interfaces()
|
||||
|
|
Loading…
Reference in New Issue