removed spaces in template types and more c++11 auto/loop refactor
This commit is contained in:
parent
f2efee4477
commit
6751a1eeb1
|
@ -72,7 +72,7 @@ struct tuple_to_pair
|
||||||
tuple_to_pair()
|
tuple_to_pair()
|
||||||
{
|
{
|
||||||
converter::registry::push_back(
|
converter::registry::push_back(
|
||||||
&convertible, &construct, type_id<std::pair<T1, T2> >()
|
&convertible, &construct, type_id<std::pair<T1, T2>>()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ struct tuple_to_pair
|
||||||
static void construct(PyObject* x, converter::rvalue_from_python_stage1_data* data)
|
static void construct(PyObject* x, converter::rvalue_from_python_stage1_data* data)
|
||||||
{
|
{
|
||||||
void* storage = ((converter::rvalue_from_python_storage<
|
void* storage = ((converter::rvalue_from_python_storage<
|
||||||
std::pair<T1, T2> >*)data)->storage.bytes;
|
std::pair<T1, T2>>*)data)->storage.bytes;
|
||||||
|
|
||||||
object o(borrowed(x));
|
object o(borrowed(x));
|
||||||
std::pair<T1, T2> p;
|
std::pair<T1, T2> p;
|
||||||
|
@ -115,7 +115,7 @@ struct list_to_vector
|
||||||
list_to_vector()
|
list_to_vector()
|
||||||
{
|
{
|
||||||
converter::registry::push_back(
|
converter::registry::push_back(
|
||||||
&convertible, &construct, type_id<std::vector<T> >()
|
&convertible, &construct, type_id<std::vector<T>>()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ struct list_to_vector
|
||||||
static void construct(PyObject* x, converter::rvalue_from_python_stage1_data* data)
|
static void construct(PyObject* x, converter::rvalue_from_python_stage1_data* data)
|
||||||
{
|
{
|
||||||
void* storage = ((converter::rvalue_from_python_storage<
|
void* storage = ((converter::rvalue_from_python_storage<
|
||||||
std::vector<T> >*)data)->storage.bytes;
|
std::vector<T>>*)data)->storage.bytes;
|
||||||
|
|
||||||
std::vector<T> p;
|
std::vector<T> p;
|
||||||
int const size = int(PyList_Size(x));
|
int const size = int(PyList_Size(x));
|
||||||
|
@ -146,16 +146,16 @@ struct list_to_vector
|
||||||
void bind_converters()
|
void bind_converters()
|
||||||
{
|
{
|
||||||
// C++ -> python conversions
|
// C++ -> python conversions
|
||||||
to_python_converter<std::pair<int, int>, pair_to_tuple<int, int> >();
|
to_python_converter<std::pair<int, int>, pair_to_tuple<int, int>>();
|
||||||
to_python_converter<std::pair<std::string, int>, pair_to_tuple<std::string, int> >();
|
to_python_converter<std::pair<std::string, int>, pair_to_tuple<std::string, int>>();
|
||||||
to_python_converter<lt::tcp::endpoint, endpoint_to_tuple<lt::tcp::endpoint> >();
|
to_python_converter<lt::tcp::endpoint, endpoint_to_tuple<lt::tcp::endpoint>>();
|
||||||
to_python_converter<lt::udp::endpoint, endpoint_to_tuple<lt::udp::endpoint> >();
|
to_python_converter<lt::udp::endpoint, endpoint_to_tuple<lt::udp::endpoint>>();
|
||||||
to_python_converter<std::vector<std::string>, vector_to_list<std::string> >();
|
to_python_converter<std::vector<std::string>, vector_to_list<std::string>>();
|
||||||
to_python_converter<std::vector<int>, vector_to_list<int> >();
|
to_python_converter<std::vector<int>, vector_to_list<int>>();
|
||||||
to_python_converter<std::vector<std::uint8_t>, vector_to_list<std::uint8_t> >();
|
to_python_converter<std::vector<std::uint8_t>, vector_to_list<std::uint8_t>>();
|
||||||
to_python_converter<std::vector<lt::tcp::endpoint>, vector_to_list<lt::tcp::endpoint> >();
|
to_python_converter<std::vector<lt::tcp::endpoint>, vector_to_list<lt::tcp::endpoint>>();
|
||||||
to_python_converter<std::vector<lt::udp::endpoint>, vector_to_list<lt::udp::endpoint> >();
|
to_python_converter<std::vector<lt::udp::endpoint>, vector_to_list<lt::udp::endpoint>>();
|
||||||
to_python_converter<std::vector<std::pair<std::string, int> >, vector_to_list<std::pair<std::string, int> > >();
|
to_python_converter<std::vector<std::pair<std::string, int>>, vector_to_list<std::pair<std::string, int>>>();
|
||||||
|
|
||||||
// python -> C++ conversions
|
// python -> C++ conversions
|
||||||
tuple_to_pair<int, int>();
|
tuple_to_pair<int, int>();
|
||||||
|
@ -167,6 +167,5 @@ void bind_converters()
|
||||||
list_to_vector<std::string>();
|
list_to_vector<std::string>();
|
||||||
list_to_vector<lt::tcp::endpoint>();
|
list_to_vector<lt::tcp::endpoint>();
|
||||||
list_to_vector<lt::udp::endpoint>();
|
list_to_vector<lt::udp::endpoint>();
|
||||||
list_to_vector<std::pair<std::string, int> >();
|
list_to_vector<std::pair<std::string, int>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@ struct allow_threading
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class F>
|
template <class F>
|
||||||
struct visitor : boost::python::def_visitor<visitor<F> >
|
struct visitor : boost::python::def_visitor<visitor<F>>
|
||||||
{
|
{
|
||||||
visitor(F fn)
|
visitor(F fn)
|
||||||
: fn(fn)
|
: fn(fn)
|
||||||
|
@ -145,4 +145,3 @@ visitor<F> allow_threads(F fn)
|
||||||
//}} // namespace libtorrent::python
|
//}} // namespace libtorrent::python
|
||||||
|
|
||||||
#endif // GIL_070107_HPP
|
#endif // GIL_070107_HPP
|
||||||
|
|
||||||
|
|
|
@ -54,9 +54,8 @@ namespace {
|
||||||
ret["trackers"] = tracker_list;
|
ret["trackers"] = tracker_list;
|
||||||
|
|
||||||
list nodes_list;
|
list nodes_list;
|
||||||
for (std::vector<std::pair<std::string, int> >::const_iterator i = p.dht_nodes.begin()
|
for (auto const& i : p.dht_nodes)
|
||||||
, end(p.dht_nodes.end()); i != end; ++i)
|
tracker_list.append(boost::python::make_tuple(i.first, i.second));
|
||||||
tracker_list.append(boost::python::make_tuple(i->first, i->second));
|
|
||||||
ret["dht_nodes"] = nodes_list;
|
ret["dht_nodes"] = nodes_list;
|
||||||
ret["info_hash"] = p.info_hash;
|
ret["info_hash"] = p.info_hash;
|
||||||
ret["name"] = p.name;
|
ret["name"] = p.name;
|
||||||
|
@ -83,4 +82,3 @@ void bind_magnet_uri()
|
||||||
def("make_magnet_uri", make_magnet_uri1);
|
def("make_magnet_uri", make_magnet_uri1);
|
||||||
def("parse_magnet_uri", parse_magnet_uri_wrap);
|
def("parse_magnet_uri", parse_magnet_uri_wrap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -238,7 +238,7 @@ namespace
|
||||||
list l = extract<list>(params["dht_nodes"]);
|
list l = extract<list>(params["dht_nodes"]);
|
||||||
int const n = int(boost::python::len(l));
|
int const n = int(boost::python::len(l));
|
||||||
for(int i = 0; i < n; i++)
|
for(int i = 0; i < n; i++)
|
||||||
p.dht_nodes.push_back(extract<std::pair<std::string, int> >(l[i]));
|
p.dht_nodes.push_back(extract<std::pair<std::string, int>>(l[i]));
|
||||||
}
|
}
|
||||||
if (params.has_key("flags"))
|
if (params.has_key("flags"))
|
||||||
p.flags = extract<std::uint64_t>(params["flags"]);
|
p.flags = extract<std::uint64_t>(params["flags"]);
|
||||||
|
@ -854,4 +854,3 @@ void bind_session()
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -144,13 +144,13 @@ void prioritize_pieces(torrent_handle& info, object o)
|
||||||
|
|
||||||
// determine which overload should be selected. the one taking a list of
|
// determine which overload should be selected. the one taking a list of
|
||||||
// priorities or the one taking a list of piece -> priority mappings
|
// priorities or the one taking a list of piece -> priority mappings
|
||||||
bool const is_piece_list = extract<std::pair<int, int> >(*begin).check();
|
bool const is_piece_list = extract<std::pair<int, int>>(*begin).check();
|
||||||
|
|
||||||
if (is_piece_list)
|
if (is_piece_list)
|
||||||
{
|
{
|
||||||
std::vector<std::pair<int, int> > piece_list;
|
std::vector<std::pair<int, int>> piece_list;
|
||||||
std::transform(begin, end, std::back_inserter(piece_list)
|
std::transform(begin, end, std::back_inserter(piece_list)
|
||||||
, &extract_fn<std::pair<int, int> >);
|
, &extract_fn<std::pair<int, int>>);
|
||||||
info.prioritize_pieces(piece_list);
|
info.prioritize_pieces(piece_list);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -503,4 +503,3 @@ void bind_torrent_handle()
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -43,12 +43,8 @@ namespace
|
||||||
{
|
{
|
||||||
list result;
|
list result;
|
||||||
|
|
||||||
typedef std::vector<std::pair<std::string, int> > list_type;
|
for (auto const& i : ti.nodes())
|
||||||
|
result.append(boost::python::make_tuple(i.first, i.second));
|
||||||
for (list_type::const_iterator i = ti.nodes().begin(); i != ti.nodes().end(); ++i)
|
|
||||||
{
|
|
||||||
result.append(boost::python::make_tuple(i->first, i->second));
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -212,7 +208,7 @@ void bind_torrent_info()
|
||||||
.def_readwrite("size", &file_slice::size)
|
.def_readwrite("size", &file_slice::size)
|
||||||
;
|
;
|
||||||
|
|
||||||
class_<torrent_info, std::shared_ptr<torrent_info> >("torrent_info", no_init)
|
class_<torrent_info, std::shared_ptr<torrent_info>>("torrent_info", no_init)
|
||||||
.def(init<sha1_hash const&, int>((arg("info_hash"), arg("flags") = 0)))
|
.def(init<sha1_hash const&, int>((arg("info_hash"), arg("flags") = 0)))
|
||||||
.def("__init__", make_constructor(&bencoded_constructor0))
|
.def("__init__", make_constructor(&bencoded_constructor0))
|
||||||
.def("__init__", make_constructor(&bencoded_constructor1))
|
.def("__init__", make_constructor(&bencoded_constructor1))
|
||||||
|
@ -319,4 +315,3 @@ void bind_torrent_info()
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -818,7 +818,7 @@ void generate_torrent(std::vector<char>& buf, int size, int num_files
|
||||||
t3.join();
|
t3.join();
|
||||||
t4.join();
|
t4.join();
|
||||||
|
|
||||||
std::back_insert_iterator<std::vector<char> > out(buf);
|
std::back_insert_iterator<std::vector<char>> out(buf);
|
||||||
|
|
||||||
bencode(out, t.generate());
|
bencode(out, t.generate());
|
||||||
}
|
}
|
||||||
|
@ -990,7 +990,7 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
|
|
||||||
buf.clear();
|
buf.clear();
|
||||||
std::back_insert_iterator<std::vector<char> > out(buf);
|
std::back_insert_iterator<std::vector<char>> out(buf);
|
||||||
bencode(out, t.generate());
|
bencode(out, t.generate());
|
||||||
FILE* f = std::fopen(torrent_name, "w+");
|
FILE* f = std::fopen(torrent_name, "w+");
|
||||||
if (f == nullptr)
|
if (f == nullptr)
|
||||||
|
|
|
@ -159,20 +159,12 @@ int main(int argc, char* argv[])
|
||||||
// print info about torrent
|
// print info about torrent
|
||||||
std::printf("\n\n----- torrent file info -----\n\n"
|
std::printf("\n\n----- torrent file info -----\n\n"
|
||||||
"nodes:\n");
|
"nodes:\n");
|
||||||
|
for (auto const& i : t.nodes())
|
||||||
|
std::printf("%s: %d\n", i.first.c_str(), i.second);
|
||||||
|
|
||||||
typedef std::vector<std::pair<std::string, int> > node_vec;
|
|
||||||
node_vec const& nodes = t.nodes();
|
|
||||||
for (node_vec::const_iterator i = nodes.begin(), end(nodes.end());
|
|
||||||
i != end; ++i)
|
|
||||||
{
|
|
||||||
std::printf("%s: %d\n", i->first.c_str(), i->second);
|
|
||||||
}
|
|
||||||
puts("trackers:\n");
|
puts("trackers:\n");
|
||||||
for (std::vector<announce_entry>::const_iterator i = t.trackers().begin();
|
for (auto const& i : t.trackers())
|
||||||
i != t.trackers().end(); ++i)
|
std::printf("%2d: %s\n", i.tier, i.url.c_str());
|
||||||
{
|
|
||||||
std::printf("%2d: %s\n", i->tier, i->url.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
std::stringstream ih;
|
std::stringstream ih;
|
||||||
ih << t.info_hash();
|
ih << t.info_hash();
|
||||||
|
@ -226,4 +218,3 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,4 +47,3 @@ namespace libtorrent { namespace aux
|
||||||
} }
|
} }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -35,13 +35,15 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "libtorrent/file.hpp"
|
#include "libtorrent/file.hpp"
|
||||||
#include "libtorrent/time.hpp"
|
|
||||||
#include "libtorrent/file_storage.hpp"
|
|
||||||
#include "libtorrent/aux_/time.hpp"
|
#include "libtorrent/aux_/time.hpp"
|
||||||
|
|
||||||
namespace libtorrent
|
namespace libtorrent
|
||||||
{
|
{
|
||||||
|
class file_storage;
|
||||||
|
|
||||||
struct pool_file_status
|
struct pool_file_status
|
||||||
{
|
{
|
||||||
// the index of the file this entry refers to into the ``file_storage``
|
// the index of the file this entry refers to into the ``file_storage``
|
||||||
|
@ -136,11 +138,9 @@ namespace libtorrent
|
||||||
|
|
||||||
// maps storage pointer, file index pairs to the
|
// maps storage pointer, file index pairs to the
|
||||||
// lru entry for the file
|
// lru entry for the file
|
||||||
using file_set = std::map<std::pair<void*, int>, lru_file_entry>;
|
std::map<std::pair<void*, int>, lru_file_entry> m_files;
|
||||||
|
|
||||||
file_set m_files;
|
|
||||||
#if TORRENT_USE_ASSERTS
|
#if TORRENT_USE_ASSERTS
|
||||||
std::vector<std::pair<std::string, void const*> > m_deleted_storages;
|
std::vector<std::pair<std::string, void const*>> m_deleted_storages;
|
||||||
#endif
|
#endif
|
||||||
mutable std::mutex m_mutex;
|
mutable std::mutex m_mutex;
|
||||||
};
|
};
|
||||||
|
|
|
@ -136,7 +136,7 @@ namespace libtorrent
|
||||||
span<char const> m_recv_buffer;
|
span<char const> m_recv_buffer;
|
||||||
// contains offsets of the first and one-past-end of
|
// contains offsets of the first and one-past-end of
|
||||||
// each chunked range in the response
|
// each chunked range in the response
|
||||||
std::vector<std::pair<std::int64_t, std::int64_t> > m_chunked_ranges;
|
std::vector<std::pair<std::int64_t, std::int64_t>> m_chunked_ranges;
|
||||||
|
|
||||||
// while reading a chunk, this is the offset where the
|
// while reading a chunk, this is the offset where the
|
||||||
// current chunk will end (it refers to the first character
|
// current chunk will end (it refers to the first character
|
||||||
|
@ -167,4 +167,3 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // TORRENT_HTTP_PARSER_HPP_INCLUDED
|
#endif // TORRENT_HTTP_PARSER_HPP_INCLUDED
|
||||||
|
|
||||||
|
|
|
@ -207,9 +207,9 @@ namespace detail
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ExternalAddressType>
|
template <class ExternalAddressType>
|
||||||
std::vector<ip_range<ExternalAddressType> > export_filter() const
|
std::vector<ip_range<ExternalAddressType>> export_filter() const
|
||||||
{
|
{
|
||||||
std::vector<ip_range<ExternalAddressType> > ret;
|
std::vector<ip_range<ExternalAddressType>> ret;
|
||||||
ret.reserve(m_access_list.size());
|
ret.reserve(m_access_list.size());
|
||||||
|
|
||||||
for (typename range_t::const_iterator i = m_access_list.begin()
|
for (typename range_t::const_iterator i = m_access_list.begin()
|
||||||
|
@ -288,10 +288,10 @@ struct TORRENT_EXPORT ip_filter
|
||||||
int access(address const& addr) const;
|
int access(address const& addr) const;
|
||||||
|
|
||||||
#if TORRENT_USE_IPV6
|
#if TORRENT_USE_IPV6
|
||||||
using filter_tuple_t = std::tuple<std::vector<ip_range<address_v4> >
|
using filter_tuple_t = std::tuple<std::vector<ip_range<address_v4>>
|
||||||
, std::vector<ip_range<address_v6> > >;
|
, std::vector<ip_range<address_v6>>>;
|
||||||
#else
|
#else
|
||||||
using filter_tuple_t = std::vector<ip_range<address_v4> >;
|
using filter_tuple_t = std::vector<ip_range<address_v4>>;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// This function will return the current state of the filter in the minimum number of
|
// This function will return the current state of the filter in the minimum number of
|
||||||
|
@ -348,4 +348,3 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -120,7 +120,9 @@ private:
|
||||||
std::unordered_multimap<int, observer_ptr> m_transactions;
|
std::unordered_multimap<int, observer_ptr> m_transactions;
|
||||||
|
|
||||||
udp_socket_interface* m_sock;
|
udp_socket_interface* m_sock;
|
||||||
|
#ifndef TORRENT_DISABLE_LOGGING
|
||||||
dht_logger* m_log;
|
dht_logger* m_log;
|
||||||
|
#endif
|
||||||
dht_settings const& m_settings;
|
dht_settings const& m_settings;
|
||||||
routing_table& m_table;
|
routing_table& m_table;
|
||||||
node_id m_our_id;
|
node_id m_our_id;
|
||||||
|
|
|
@ -87,7 +87,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
// virtual bool has_any_file() { return false; }
|
// virtual bool has_any_file() { return false; }
|
||||||
// virtual int read(char* buf, int piece, int offset, int size)
|
// virtual int read(char* buf, int piece, int offset, int size)
|
||||||
// {
|
// {
|
||||||
// std::map<int, std::vector<char> >::const_iterator i = m_file_data.find(piece);
|
// std::map<int, std::vector<char>>::const_iterator i = m_file_data.find(piece);
|
||||||
// if (i == m_file_data.end()) return 0;
|
// if (i == m_file_data.end()) return 0;
|
||||||
// int available = i->second.size() - offset;
|
// int available = i->second.size() - offset;
|
||||||
// if (available <= 0) return 0;
|
// if (available <= 0) return 0;
|
||||||
|
@ -129,7 +129,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
// virtual bool release_files() { return false; }
|
// virtual bool release_files() { return false; }
|
||||||
// virtual bool delete_files() { return false; }
|
// virtual bool delete_files() { return false; }
|
||||||
//
|
//
|
||||||
// std::map<int, std::vector<char> > m_file_data;
|
// std::map<int, std::vector<char>> m_file_data;
|
||||||
// file_storage m_files;
|
// file_storage m_files;
|
||||||
// };
|
// };
|
||||||
//
|
//
|
||||||
|
|
|
@ -55,7 +55,7 @@ namespace libtorrent
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct tailqueue_iterator
|
struct tailqueue_iterator
|
||||||
{
|
{
|
||||||
template <typename U> friend struct tailqueue;
|
template <typename U, typename Cond> friend struct tailqueue;
|
||||||
|
|
||||||
T* get() const { return m_current; }
|
T* get() const { return m_current; }
|
||||||
void next() { m_current = m_current->next; }
|
void next() { m_current = m_current->next; }
|
||||||
|
@ -67,8 +67,8 @@ namespace libtorrent
|
||||||
T* m_current;
|
T* m_current;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Cond = typename std::enable_if<
|
||||||
//#error boost::enable_if< is_base<T, tailqueue_node<T> > >
|
std::is_base_of<tailqueue_node<T>, T>::value>::type>
|
||||||
struct tailqueue
|
struct tailqueue
|
||||||
{
|
{
|
||||||
tailqueue(): m_first(nullptr), m_last(nullptr), m_size(0) {}
|
tailqueue(): m_first(nullptr), m_last(nullptr), m_size(0) {}
|
||||||
|
@ -185,4 +185,3 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // TAILQUEUE_HPP
|
#endif // TAILQUEUE_HPP
|
||||||
|
|
||||||
|
|
|
@ -526,7 +526,7 @@ namespace libtorrent
|
||||||
int piece_priority(int index) const;
|
int piece_priority(int index) const;
|
||||||
|
|
||||||
void prioritize_pieces(std::vector<int> const& pieces);
|
void prioritize_pieces(std::vector<int> const& pieces);
|
||||||
void prioritize_piece_list(std::vector<std::pair<int, int> > const& pieces);
|
void prioritize_piece_list(std::vector<std::pair<int, int>> const& pieces);
|
||||||
void piece_priorities(std::vector<int>*) const;
|
void piece_priorities(std::vector<int>*) const;
|
||||||
|
|
||||||
void set_file_priority(int index, int priority);
|
void set_file_priority(int index, int priority);
|
||||||
|
|
|
@ -1015,7 +1015,7 @@ namespace libtorrent
|
||||||
void piece_priority(int index, int priority) const;
|
void piece_priority(int index, int priority) const;
|
||||||
int piece_priority(int index) const;
|
int piece_priority(int index) const;
|
||||||
void prioritize_pieces(std::vector<int> const& pieces) const;
|
void prioritize_pieces(std::vector<int> const& pieces) const;
|
||||||
void prioritize_pieces(std::vector<std::pair<int, int> > const& pieces) const;
|
void prioritize_pieces(std::vector<std::pair<int, int>> const& pieces) const;
|
||||||
std::vector<int> piece_priorities() const;
|
std::vector<int> piece_priorities() const;
|
||||||
|
|
||||||
// ``index`` must be in the range [0, number_of_files).
|
// ``index`` must be in the range [0, number_of_files).
|
||||||
|
|
|
@ -104,7 +104,7 @@ add_torrent_params create_torrent(file_storage& fs, bool const pad_files = false
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<char> tmp;
|
std::vector<char> tmp;
|
||||||
std::back_insert_iterator<std::vector<char> > out(tmp);
|
std::back_insert_iterator<std::vector<char>> out(tmp);
|
||||||
|
|
||||||
entry tor = t.generate();
|
entry tor = t.generate();
|
||||||
|
|
||||||
|
|
|
@ -900,7 +900,7 @@ namespace libtorrent
|
||||||
DLOG("try_flush_write_blocks: %d\n", num);
|
DLOG("try_flush_write_blocks: %d\n", num);
|
||||||
|
|
||||||
list_iterator<cached_piece_entry> range = m_disk_cache.write_lru_pieces();
|
list_iterator<cached_piece_entry> range = m_disk_cache.write_lru_pieces();
|
||||||
std::vector<std::pair<piece_manager*, int> > pieces;
|
std::vector<std::pair<piece_manager*, int>> pieces;
|
||||||
pieces.reserve(m_disk_cache.num_write_lru_pieces());
|
pieces.reserve(m_disk_cache.num_write_lru_pieces());
|
||||||
|
|
||||||
for (list_iterator<cached_piece_entry> p = range; p.get() && num > 0; p.next())
|
for (list_iterator<cached_piece_entry> p = range; p.get() && num > 0; p.next())
|
||||||
|
@ -910,12 +910,11 @@ namespace libtorrent
|
||||||
pieces.push_back(std::make_pair(e->storage.get(), int(e->piece)));
|
pieces.push_back(std::make_pair(e->storage.get(), int(e->piece)));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::vector<std::pair<piece_manager*, int> >::iterator i = pieces.begin()
|
for (auto const& p : pieces)
|
||||||
, end(pieces.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
// TODO: instead of doing a lookup each time through the loop, save
|
// TODO: instead of doing a lookup each time through the loop, save
|
||||||
// cached_piece_entry pointers with piece_refcount incremented to pin them
|
// cached_piece_entry pointers with piece_refcount incremented to pin them
|
||||||
cached_piece_entry* pe = m_disk_cache.find_piece(i->first, i->second);
|
cached_piece_entry* pe = m_disk_cache.find_piece(p.first, p.second);
|
||||||
if (pe == nullptr) continue;
|
if (pe == nullptr) continue;
|
||||||
|
|
||||||
// another thread may flush this piece while we're looping and
|
// another thread may flush this piece while we're looping and
|
||||||
|
@ -942,10 +941,9 @@ namespace libtorrent
|
||||||
|
|
||||||
// if we still need to flush blocks, start over and flush
|
// if we still need to flush blocks, start over and flush
|
||||||
// everything in LRU order (degrade to lru cache eviction)
|
// everything in LRU order (degrade to lru cache eviction)
|
||||||
for (std::vector<std::pair<piece_manager*, int> >::iterator i = pieces.begin()
|
for (auto const& p : pieces)
|
||||||
, end(pieces.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
cached_piece_entry* pe = m_disk_cache.find_piece(i->first, i->second);
|
cached_piece_entry* pe = m_disk_cache.find_piece(p.first, p.second);
|
||||||
if (pe == nullptr) continue;
|
if (pe == nullptr) continue;
|
||||||
if (pe->num_dirty == 0) continue;
|
if (pe->num_dirty == 0) continue;
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "libtorrent/assert.hpp"
|
#include "libtorrent/assert.hpp"
|
||||||
#include "libtorrent/file_pool.hpp"
|
#include "libtorrent/file_pool.hpp"
|
||||||
#include "libtorrent/error_code.hpp"
|
#include "libtorrent/error_code.hpp"
|
||||||
#include "libtorrent/file_storage.hpp" // for file_entry
|
#include "libtorrent/file_storage.hpp"
|
||||||
#include "libtorrent/aux_/time.hpp"
|
|
||||||
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
|
@ -141,7 +140,7 @@ namespace libtorrent
|
||||||
TORRENT_ASSERT(is_complete(p));
|
TORRENT_ASSERT(is_complete(p));
|
||||||
TORRENT_ASSERT((m & file::rw_mask) == file::read_only
|
TORRENT_ASSERT((m & file::rw_mask) == file::read_only
|
||||||
|| (m & file::rw_mask) == file::read_write);
|
|| (m & file::rw_mask) == file::read_write);
|
||||||
file_set::iterator i = m_files.find(std::make_pair(st, file_index));
|
auto const i = m_files.find(std::make_pair(st, file_index));
|
||||||
if (i != m_files.end())
|
if (i != m_files.end())
|
||||||
{
|
{
|
||||||
lru_file_entry& e = i->second;
|
lru_file_entry& e = i->second;
|
||||||
|
@ -227,22 +226,21 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> l(m_mutex);
|
std::unique_lock<std::mutex> l(m_mutex);
|
||||||
|
|
||||||
auto start = m_files.lower_bound(std::make_pair(st, 0));
|
auto const start = m_files.lower_bound(std::make_pair(st, 0));
|
||||||
auto end = m_files.upper_bound(std::make_pair(st
|
auto const end = m_files.upper_bound(std::make_pair(st
|
||||||
, std::numeric_limits<int>::max()));
|
, std::numeric_limits<int>::max()));
|
||||||
|
|
||||||
for (file_set::const_iterator i = start; i != end; ++i)
|
for (auto i = start; i != end; ++i)
|
||||||
{
|
|
||||||
ret.push_back({i->first.second, i->second.mode, i->second.last_use});
|
ret.push_back({i->first.second, i->second.mode, i->second.last_use});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void file_pool::remove_oldest(std::unique_lock<std::mutex>& l)
|
void file_pool::remove_oldest(std::unique_lock<std::mutex>& l)
|
||||||
{
|
{
|
||||||
file_set::iterator i = std::min_element(m_files.begin(), m_files.end()
|
using value_type = std::map<std::pair<void*, int>, lru_file_entry>::value_type;
|
||||||
, [] (file_set::value_type const& lhs, file_set::value_type const& rhs)
|
auto const i = std::min_element(m_files.begin(), m_files.end()
|
||||||
|
, [] (value_type const& lhs, value_type const& rhs)
|
||||||
{ return lhs.second.last_use < rhs.second.last_use; });
|
{ return lhs.second.last_use < rhs.second.last_use; });
|
||||||
if (i == m_files.end()) return;
|
if (i == m_files.end()) return;
|
||||||
|
|
||||||
|
@ -259,7 +257,7 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> l(m_mutex);
|
std::unique_lock<std::mutex> l(m_mutex);
|
||||||
|
|
||||||
file_set::iterator i = m_files.find(std::make_pair(st, file_index));
|
auto const i = m_files.find(std::make_pair(st, file_index));
|
||||||
if (i == m_files.end()) return;
|
if (i == m_files.end()) return;
|
||||||
|
|
||||||
file_handle file_ptr = i->second.file_ptr;
|
file_handle file_ptr = i->second.file_ptr;
|
||||||
|
@ -278,15 +276,14 @@ namespace libtorrent
|
||||||
|
|
||||||
if (st == nullptr)
|
if (st == nullptr)
|
||||||
{
|
{
|
||||||
file_set tmp;
|
std::map<std::pair<void*, int>, lru_file_entry> tmp;
|
||||||
tmp.swap(m_files);
|
tmp.swap(m_files);
|
||||||
l.unlock();
|
l.unlock();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<file_handle> to_close;
|
std::vector<file_handle> to_close;
|
||||||
for (file_set::iterator i = m_files.begin();
|
for (auto i = m_files.begin(); i != m_files.end();)
|
||||||
i != m_files.end();)
|
|
||||||
{
|
{
|
||||||
if (i->second.key == st)
|
if (i->second.key == st)
|
||||||
{
|
{
|
||||||
|
@ -314,10 +311,9 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> l(m_mutex);
|
std::unique_lock<std::mutex> l(m_mutex);
|
||||||
|
|
||||||
for (file_set::const_iterator i = m_files.begin();
|
for (auto const& i : m_files)
|
||||||
i != m_files.end(); ++i)
|
|
||||||
{
|
{
|
||||||
if (i->second.key == st && !i->second.file_ptr.unique())
|
if (i.second.key == st && !i.second.file_ptr.unique())
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -340,4 +336,3 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -565,8 +565,8 @@ void http_connection::connect()
|
||||||
#ifdef TORRENT_USE_OPENSSL
|
#ifdef TORRENT_USE_OPENSSL
|
||||||
if (m_ssl)
|
if (m_ssl)
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(m_sock.get<ssl_stream<socks5_stream> >());
|
TORRENT_ASSERT(m_sock.get<ssl_stream<socks5_stream>>());
|
||||||
m_sock.get<ssl_stream<socks5_stream> >()->next_layer().set_dst_name(m_hostname);
|
m_sock.get<ssl_stream<socks5_stream>>()->next_layer().set_dst_name(m_hostname);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -84,7 +84,9 @@ namespace libtorrent { namespace dht
|
||||||
, total_milliseconds((now - match->limit) + seconds(10)) / 1000.0
|
, total_milliseconds((now - match->limit) + seconds(10)) / 1000.0
|
||||||
, match->count);
|
, match->count);
|
||||||
}
|
}
|
||||||
#endif
|
#else
|
||||||
|
TORRENT_UNUSED(logger);
|
||||||
|
#endif // TORRENT_DISABLE_LOGGING
|
||||||
// we've received too many messages in less than 10 seconds
|
// we've received too many messages in less than 10 seconds
|
||||||
// from this node. Ignore it until it's silent for 5 minutes
|
// from this node. Ignore it until it's silent for 5 minutes
|
||||||
match->limit = now + seconds(m_block_timeout);
|
match->limit = now + seconds(m_block_timeout);
|
||||||
|
|
|
@ -2337,8 +2337,8 @@ namespace aux {
|
||||||
// use the generic m_ssl_ctx context. However, since it has
|
// use the generic m_ssl_ctx context. However, since it has
|
||||||
// the servername callback set on it, we will switch away from
|
// the servername callback set on it, we will switch away from
|
||||||
// this context into a specific torrent once we start handshaking
|
// this context into a specific torrent once we start handshaking
|
||||||
c->instantiate<ssl_stream<tcp::socket> >(m_io_service, &m_ssl_ctx);
|
c->instantiate<ssl_stream<tcp::socket>>(m_io_service, &m_ssl_ctx);
|
||||||
str = &c->get<ssl_stream<tcp::socket> >()->next_layer();
|
str = &c->get<ssl_stream<tcp::socket>>()->next_layer();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
|
@ -2952,8 +2952,7 @@ namespace aux {
|
||||||
// remove undead peers that only have this list as their reference keeping them alive
|
// remove undead peers that only have this list as their reference keeping them alive
|
||||||
if (!m_undead_peers.empty())
|
if (!m_undead_peers.empty())
|
||||||
{
|
{
|
||||||
std::vector<std::shared_ptr<peer_connection> >::iterator remove_it
|
auto const remove_it = std::remove_if(m_undead_peers.begin(), m_undead_peers.end()
|
||||||
= std::remove_if(m_undead_peers.begin(), m_undead_peers.end()
|
|
||||||
, std::bind(&std::shared_ptr<peer_connection>::unique, _1));
|
, std::bind(&std::shared_ptr<peer_connection>::unique, _1));
|
||||||
m_undead_peers.erase(remove_it, m_undead_peers.end());
|
m_undead_peers.erase(remove_it, m_undead_peers.end());
|
||||||
if (m_undead_peers.empty())
|
if (m_undead_peers.empty())
|
||||||
|
@ -3296,10 +3295,9 @@ namespace aux {
|
||||||
{
|
{
|
||||||
// if we haven't reached the global max. see if any torrent
|
// if we haven't reached the global max. see if any torrent
|
||||||
// has reached its local limit
|
// has reached its local limit
|
||||||
for (torrent_map::iterator i = m_torrents.begin()
|
for (auto const& pt : m_torrents)
|
||||||
, end(m_torrents.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
std::shared_ptr<torrent> t = i->second;
|
std::shared_ptr<torrent> t = pt.second;
|
||||||
|
|
||||||
// ths disconnect logic is disabled for torrents with
|
// ths disconnect logic is disabled for torrents with
|
||||||
// too low connection limit
|
// too low connection limit
|
||||||
|
@ -3308,11 +3306,10 @@ namespace aux {
|
||||||
|| t->max_connections() < 6)
|
|| t->max_connections() < 6)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int peers_to_disconnect = (std::min)((std::max)(int(t->num_peers()
|
int peers_to_disconnect = (std::min)((std::max)(t->num_peers()
|
||||||
* m_settings.get_int(settings_pack::peer_turnover) / 100), 1)
|
* m_settings.get_int(settings_pack::peer_turnover) / 100, 1)
|
||||||
, t->num_connect_candidates());
|
, t->num_connect_candidates());
|
||||||
t->disconnect_peers(peers_to_disconnect
|
t->disconnect_peers(peers_to_disconnect, errors::optimistic_disconnect);
|
||||||
, error_code(errors::optimistic_disconnect));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4312,22 +4309,20 @@ namespace aux {
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(is_single_thread());
|
TORRENT_ASSERT(is_single_thread());
|
||||||
|
|
||||||
std::map<std::string, std::shared_ptr<torrent> >::const_iterator i
|
auto const i = m_uuids.find(uuid);
|
||||||
= m_uuids.find(uuid);
|
|
||||||
if (i != m_uuids.end()) return i->second;
|
if (i != m_uuids.end()) return i->second;
|
||||||
return std::weak_ptr<torrent>();
|
return std::weak_ptr<torrent>();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef TORRENT_DISABLE_MUTABLE_TORRENTS
|
#ifndef TORRENT_DISABLE_MUTABLE_TORRENTS
|
||||||
std::vector<std::shared_ptr<torrent> > session_impl::find_collection(
|
std::vector<std::shared_ptr<torrent>> session_impl::find_collection(
|
||||||
std::string const& collection) const
|
std::string const& collection) const
|
||||||
{
|
{
|
||||||
std::vector<std::shared_ptr<torrent> > ret;
|
std::vector<std::shared_ptr<torrent>> ret;
|
||||||
for (session_impl::torrent_map::const_iterator i = m_torrents.begin()
|
for (auto const& tp : m_torrents)
|
||||||
, end(m_torrents.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
std::shared_ptr<torrent> t = i->second;
|
std::shared_ptr<torrent> t = tp.second;
|
||||||
if (!t) continue;
|
if (!t) continue;
|
||||||
std::vector<std::string> const& c = t->torrent_file().collections();
|
std::vector<std::string> const& c = t->torrent_file().collections();
|
||||||
if (std::find(c.begin(), c.end(), collection) == c.end()) continue;
|
if (std::find(c.begin(), c.end(), collection) == c.end()) continue;
|
||||||
|
@ -4729,11 +4724,8 @@ namespace aux {
|
||||||
// add params.dht_nodes to the DHT, if enabled
|
// add params.dht_nodes to the DHT, if enabled
|
||||||
if (!params.dht_nodes.empty())
|
if (!params.dht_nodes.empty())
|
||||||
{
|
{
|
||||||
for (std::vector<std::pair<std::string, int> >::const_iterator i = params.dht_nodes.begin()
|
for (auto const& n : params.dht_nodes)
|
||||||
, end(params.dht_nodes.end()); i != end; ++i)
|
add_dht_node_name(n);
|
||||||
{
|
|
||||||
add_dht_node_name(*i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -4936,14 +4928,12 @@ namespace aux {
|
||||||
// remove from uuid list
|
// remove from uuid list
|
||||||
if (!tptr->uuid().empty())
|
if (!tptr->uuid().empty())
|
||||||
{
|
{
|
||||||
std::map<std::string, std::shared_ptr<torrent> >::iterator j
|
auto const j = m_uuids.find(tptr->uuid());
|
||||||
= m_uuids.find(tptr->uuid());
|
|
||||||
if (j != m_uuids.end()) m_uuids.erase(j);
|
if (j != m_uuids.end()) m_uuids.erase(j);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
torrent_map::iterator i =
|
auto i = m_torrents.find(tptr->torrent_file().info_hash());
|
||||||
m_torrents.find(tptr->torrent_file().info_hash());
|
|
||||||
|
|
||||||
#ifndef TORRENT_NO_DEPRECATE
|
#ifndef TORRENT_NO_DEPRECATE
|
||||||
// deprecated in 1.2
|
// deprecated in 1.2
|
||||||
|
@ -6746,10 +6736,8 @@ namespace aux {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::vector<std::shared_ptr<peer_connection> >::const_iterator i
|
for (auto const& p : m_undead_peers)
|
||||||
= m_undead_peers.begin(); i != m_undead_peers.end(); ++i)
|
|
||||||
{
|
{
|
||||||
peer_connection* p = i->get();
|
|
||||||
if (p->ignore_unchoke_slots())
|
if (p->ignore_unchoke_slots())
|
||||||
{
|
{
|
||||||
if (!p->is_choked()) ++unchokes_all;
|
if (!p->is_choked()) ++unchokes_all;
|
||||||
|
|
|
@ -436,7 +436,7 @@ namespace libtorrent
|
||||||
async_call(&torrent::prioritize_pieces, pieces);
|
async_call(&torrent::prioritize_pieces, pieces);
|
||||||
}
|
}
|
||||||
|
|
||||||
void torrent_handle::prioritize_pieces(std::vector<std::pair<int, int> > const& pieces) const
|
void torrent_handle::prioritize_pieces(std::vector<std::pair<int, int>> const& pieces) const
|
||||||
{
|
{
|
||||||
async_call(&torrent::prioritize_piece_list, pieces);
|
async_call(&torrent::prioritize_piece_list, pieces);
|
||||||
}
|
}
|
||||||
|
|
|
@ -818,7 +818,7 @@ namespace libtorrent
|
||||||
torrent_info::torrent_info(entry const& torrent_file)
|
torrent_info::torrent_info(entry const& torrent_file)
|
||||||
{
|
{
|
||||||
std::vector<char> tmp;
|
std::vector<char> tmp;
|
||||||
std::back_insert_iterator<std::vector<char> > out(tmp);
|
std::back_insert_iterator<std::vector<char>> out(tmp);
|
||||||
bencode(out, torrent_file);
|
bencode(out, torrent_file);
|
||||||
|
|
||||||
bdecode_node e;
|
bdecode_node e;
|
||||||
|
|
|
@ -57,7 +57,7 @@ std::shared_ptr<libtorrent::torrent_info> make_test_torrent(
|
||||||
|
|
||||||
// torrent offset ranges where the pad files are
|
// torrent offset ranges where the pad files are
|
||||||
// used when generating hashes
|
// used when generating hashes
|
||||||
std::deque<std::pair<int,int> > pad_files;
|
std::deque<std::pair<int,int>> pad_files;
|
||||||
|
|
||||||
int const piece_length = 32768;
|
int const piece_length = 32768;
|
||||||
info["piece length"] = piece_length;
|
info["piece length"] = piece_length;
|
||||||
|
@ -152,7 +152,7 @@ std::shared_ptr<libtorrent::torrent_info> make_test_torrent(
|
||||||
info["pieces"] = piece_hashes;
|
info["pieces"] = piece_hashes;
|
||||||
|
|
||||||
std::vector<char> tmp;
|
std::vector<char> tmp;
|
||||||
std::back_insert_iterator<std::vector<char> > out(tmp);
|
std::back_insert_iterator<std::vector<char>> out(tmp);
|
||||||
bencode(out, e);
|
bencode(out, e);
|
||||||
|
|
||||||
FILE* f = fopen("test.torrent", "w+");
|
FILE* f = fopen("test.torrent", "w+");
|
||||||
|
@ -198,5 +198,3 @@ void generate_files(libtorrent::torrent_info const& ti, std::string const& path
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@ void node_push_back(void* userdata, libtorrent::dht::node_entry const& n)
|
||||||
void nop(void* userdata, libtorrent::dht::node_entry const& n) {}
|
void nop(void* userdata, libtorrent::dht::node_entry const& n) {}
|
||||||
void nop_node() {}
|
void nop_node() {}
|
||||||
|
|
||||||
std::list<std::pair<udp::endpoint, entry> > g_sent_packets;
|
std::list<std::pair<udp::endpoint, entry>> g_sent_packets;
|
||||||
|
|
||||||
struct mock_socket final : udp_socket_interface
|
struct mock_socket final : udp_socket_interface
|
||||||
{
|
{
|
||||||
|
@ -125,7 +125,7 @@ sha1_hash generate_next()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<std::pair<udp::endpoint, entry> >::iterator
|
std::list<std::pair<udp::endpoint, entry>>::iterator
|
||||||
find_packet(udp::endpoint ep)
|
find_packet(udp::endpoint ep)
|
||||||
{
|
{
|
||||||
return std::find_if(g_sent_packets.begin(), g_sent_packets.end()
|
return std::find_if(g_sent_packets.begin(), g_sent_packets.end()
|
||||||
|
@ -242,7 +242,7 @@ void send_dht_request(node& node, char const* msg, udp::endpoint const& ep
|
||||||
|
|
||||||
// If the request is supposed to get a response, by now the node should have
|
// If the request is supposed to get a response, by now the node should have
|
||||||
// invoked the send function and put the response in g_sent_packets
|
// invoked the send function and put the response in g_sent_packets
|
||||||
std::list<std::pair<udp::endpoint, entry> >::iterator i = find_packet(ep);
|
auto const i = find_packet(ep);
|
||||||
if (has_response)
|
if (has_response)
|
||||||
{
|
{
|
||||||
if (i == g_sent_packets.end())
|
if (i == g_sent_packets.end())
|
||||||
|
@ -1977,21 +1977,20 @@ void test_get_peers(address(&rand_addr)())
|
||||||
send_dht_response(t.dht_node, response, next_node
|
send_dht_response(t.dht_node, response, next_node
|
||||||
, msg_args().token("11").port(1234).peers(peers[1]));
|
, msg_args().token("11").port(1234).peers(peers[1]));
|
||||||
|
|
||||||
for (std::list<std::pair<udp::endpoint, entry> >::iterator i = g_sent_packets.begin()
|
for (auto const& p : g_sent_packets)
|
||||||
, end(g_sent_packets.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
// std::printf(" %s:%d: %s\n", i->first.address().to_string(ec).c_str()
|
// std::printf(" %s:%d: %s\n", i->first.address().to_string(ec).c_str()
|
||||||
// , i->first.port(), i->second.to_string().c_str());
|
// , i->first.port(), i->second.to_string().c_str());
|
||||||
TEST_EQUAL(i->second["q"].string(), "announce_peer");
|
TEST_EQUAL(p.second["q"].string(), "announce_peer");
|
||||||
}
|
}
|
||||||
|
|
||||||
g_sent_packets.clear();
|
g_sent_packets.clear();
|
||||||
|
|
||||||
for (int i = 0; i < 2; ++i)
|
for (int i = 0; i < 2; ++i)
|
||||||
{
|
{
|
||||||
for (std::set<tcp::endpoint>::iterator peer = peers[i].begin(); peer != peers[i].end(); ++peer)
|
for (auto const& peer : peers[i])
|
||||||
{
|
{
|
||||||
TEST_CHECK(std::find(g_got_peers.begin(), g_got_peers.end(), *peer) != g_got_peers.end());
|
TEST_CHECK(std::find(g_got_peers.begin(), g_got_peers.end(), peer) != g_got_peers.end());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_got_peers.clear();
|
g_got_peers.clear();
|
||||||
|
@ -2212,7 +2211,7 @@ TORRENT_TEST(immutable_put)
|
||||||
|
|
||||||
for (int i = 0; i < 8; ++i)
|
for (int i = 0; i < 8; ++i)
|
||||||
{
|
{
|
||||||
std::list<std::pair<udp::endpoint, entry> >::iterator packet = find_packet(nodes[i].ep());
|
auto const packet = find_packet(nodes[i].ep());
|
||||||
TEST_CHECK(packet != g_sent_packets.end());
|
TEST_CHECK(packet != g_sent_packets.end());
|
||||||
if (packet == g_sent_packets.end()) continue;
|
if (packet == g_sent_packets.end()) continue;
|
||||||
|
|
||||||
|
@ -2241,7 +2240,7 @@ TORRENT_TEST(immutable_put)
|
||||||
|
|
||||||
for (int i = 0; i < 8; ++i)
|
for (int i = 0; i < 8; ++i)
|
||||||
{
|
{
|
||||||
std::list<std::pair<udp::endpoint, entry> >::iterator packet = find_packet(nodes[i].ep());
|
auto const packet = find_packet(nodes[i].ep());
|
||||||
TEST_CHECK(packet != g_sent_packets.end());
|
TEST_CHECK(packet != g_sent_packets.end());
|
||||||
if (packet == g_sent_packets.end()) continue;
|
if (packet == g_sent_packets.end()) continue;
|
||||||
|
|
||||||
|
@ -2313,7 +2312,7 @@ TORRENT_TEST(mutable_put)
|
||||||
|
|
||||||
for (int i = 0; i < 8; ++i)
|
for (int i = 0; i < 8; ++i)
|
||||||
{
|
{
|
||||||
std::list<std::pair<udp::endpoint, entry> >::iterator packet = find_packet(nodes[i].ep());
|
auto const packet = find_packet(nodes[i].ep());
|
||||||
TEST_CHECK(packet != g_sent_packets.end());
|
TEST_CHECK(packet != g_sent_packets.end());
|
||||||
if (packet == g_sent_packets.end()) continue;
|
if (packet == g_sent_packets.end()) continue;
|
||||||
|
|
||||||
|
@ -2342,7 +2341,7 @@ TORRENT_TEST(mutable_put)
|
||||||
|
|
||||||
for (int i = 0; i < 8; ++i)
|
for (int i = 0; i < 8; ++i)
|
||||||
{
|
{
|
||||||
std::list<std::pair<udp::endpoint, entry> >::iterator packet = find_packet(nodes[i].ep());
|
auto const packet = find_packet(nodes[i].ep());
|
||||||
TEST_CHECK(packet != g_sent_packets.end());
|
TEST_CHECK(packet != g_sent_packets.end());
|
||||||
if (packet == g_sent_packets.end()) continue;
|
if (packet == g_sent_packets.end()) continue;
|
||||||
|
|
||||||
|
@ -2428,7 +2427,7 @@ TORRENT_TEST(traversal_done)
|
||||||
// get_item_cb
|
// get_item_cb
|
||||||
if (i == num_test_nodes) i = 0;
|
if (i == num_test_nodes) i = 0;
|
||||||
|
|
||||||
std::list<std::pair<udp::endpoint, entry> >::iterator packet = find_packet(nodes[i].ep());
|
auto const packet = find_packet(nodes[i].ep());
|
||||||
TEST_CHECK(packet != g_sent_packets.end());
|
TEST_CHECK(packet != g_sent_packets.end());
|
||||||
if (packet == g_sent_packets.end()) continue;
|
if (packet == g_sent_packets.end()) continue;
|
||||||
|
|
||||||
|
|
|
@ -61,9 +61,9 @@ bool compare(ip_range<Addr> const& lhs
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void test_rules_invariant(std::vector<ip_range<T> > const& r, ip_filter const& f)
|
void test_rules_invariant(std::vector<ip_range<T>> const& r, ip_filter const& f)
|
||||||
{
|
{
|
||||||
typedef typename std::vector<ip_range<T> >::const_iterator iterator;
|
typedef typename std::vector<ip_range<T>>::const_iterator iterator;
|
||||||
TEST_CHECK(!r.empty());
|
TEST_CHECK(!r.empty());
|
||||||
if (r.empty()) return;
|
if (r.empty()) return;
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ TORRENT_TEST(ip_filter)
|
||||||
{
|
{
|
||||||
using namespace libtorrent;
|
using namespace libtorrent;
|
||||||
|
|
||||||
std::vector<ip_range<address_v4> > range;
|
std::vector<ip_range<address_v4>> range;
|
||||||
error_code ec;
|
error_code ec;
|
||||||
|
|
||||||
// **** test joining of ranges at the end ****
|
// **** test joining of ranges at the end ****
|
||||||
|
@ -268,7 +268,7 @@ TORRENT_TEST(ip_filter)
|
||||||
f.add_rule(addr("2::1"), addr("3::"), ip_filter::blocked);
|
f.add_rule(addr("2::1"), addr("3::"), ip_filter::blocked);
|
||||||
f.add_rule(addr("1::"), addr("2::"), ip_filter::blocked);
|
f.add_rule(addr("1::"), addr("2::"), ip_filter::blocked);
|
||||||
|
|
||||||
std::vector<ip_range<address_v6> > range;
|
std::vector<ip_range<address_v6>> range;
|
||||||
range = std::get<1>(f.export_filter());
|
range = std::get<1>(f.export_filter());
|
||||||
test_rules_invariant(range, f);
|
test_rules_invariant(range, f);
|
||||||
|
|
||||||
|
@ -297,4 +297,3 @@ TORRENT_TEST(ip_filter)
|
||||||
TEST_CHECK(pf.access(6881) == 0);
|
TEST_CHECK(pf.access(6881) == 0);
|
||||||
TEST_CHECK(pf.access(65535) == 0);
|
TEST_CHECK(pf.access(65535) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -143,15 +143,14 @@ struct mock_torrent
|
||||||
|
|
||||||
peer_list* m_p;
|
peer_list* m_p;
|
||||||
torrent_state* m_state;
|
torrent_state* m_state;
|
||||||
std::vector<std::shared_ptr<mock_peer_connection> > m_connections;
|
std::vector<std::shared_ptr<mock_peer_connection>> m_connections;
|
||||||
};
|
};
|
||||||
|
|
||||||
void mock_peer_connection::disconnect(error_code const& ec
|
void mock_peer_connection::disconnect(error_code const& ec
|
||||||
, operation_t op, int error)
|
, operation_t op, int error)
|
||||||
{
|
{
|
||||||
m_torrent.m_p->connection_closed(*this, 0, m_torrent.m_state);
|
m_torrent.m_p->connection_closed(*this, 0, m_torrent.m_state);
|
||||||
std::vector<std::shared_ptr<mock_peer_connection> >::iterator i
|
auto const i = std::find(m_torrent.m_connections.begin(), m_torrent.m_connections.end()
|
||||||
= std::find(m_torrent.m_connections.begin(), m_torrent.m_connections.end()
|
|
||||||
, std::static_pointer_cast<mock_peer_connection>(shared_from_this()));
|
, std::static_pointer_cast<mock_peer_connection>(shared_from_this()));
|
||||||
if (i != m_torrent.m_connections.end()) m_torrent.m_connections.erase(i);
|
if (i != m_torrent.m_connections.end()) m_torrent.m_connections.erase(i);
|
||||||
|
|
||||||
|
@ -161,8 +160,7 @@ void mock_peer_connection::disconnect(error_code const& ec
|
||||||
|
|
||||||
bool has_peer(peer_list const& p, tcp::endpoint const& ep)
|
bool has_peer(peer_list const& p, tcp::endpoint const& ep)
|
||||||
{
|
{
|
||||||
std::pair<peer_list::const_iterator, peer_list::const_iterator> its
|
auto const its = p.find_peers(ep.address());
|
||||||
= p.find_peers(ep.address());
|
|
||||||
return its.first != its.second;
|
return its.first != its.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -939,4 +937,3 @@ TORRENT_TEST(new_peer_size_limit)
|
||||||
// TODO: test connect_to_peer() failing
|
// TODO: test connect_to_peer() failing
|
||||||
// TODO: test connection_closed
|
// TODO: test connection_closed
|
||||||
// TODO: connect candidates recalculation when incrementing failcount
|
// TODO: connect candidates recalculation when incrementing failcount
|
||||||
|
|
||||||
|
|
|
@ -225,7 +225,7 @@ bool verify_pick(std::shared_ptr<piece_picker> p
|
||||||
// make sure there are no duplicated
|
// make sure there are no duplicated
|
||||||
std::set<piece_block> blocks;
|
std::set<piece_block> blocks;
|
||||||
std::copy(picked.begin(), picked.end()
|
std::copy(picked.begin(), picked.end()
|
||||||
, std::insert_iterator<std::set<piece_block> >(blocks, blocks.end()));
|
, std::insert_iterator<std::set<piece_block>>(blocks, blocks.end()));
|
||||||
std::cout << " verify: " << picked.size() << " " << blocks.size() << std::endl;
|
std::cout << " verify: " << picked.size() << " " << blocks.size() << std::endl;
|
||||||
return picked.size() == blocks.size();
|
return picked.size() == blocks.size();
|
||||||
}
|
}
|
||||||
|
@ -1979,4 +1979,3 @@ TORRENT_TEST(download_filtered_piece)
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: 2 test picking with partial pieces and other peers present so that both backup_pieces and backup_pieces2 are used
|
//TODO: 2 test picking with partial pieces and other peers present so that both backup_pieces and backup_pieces2 are used
|
||||||
|
|
||||||
|
|
|
@ -1049,7 +1049,7 @@ struct test_fileop : fileop
|
||||||
}
|
}
|
||||||
|
|
||||||
int m_stripe_size;
|
int m_stripe_size;
|
||||||
std::vector<std::vector<char> > m_file_data;
|
std::vector<std::vector<char>> m_file_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct test_read_fileop : fileop
|
struct test_read_fileop : fileop
|
||||||
|
|
|
@ -269,7 +269,7 @@ TORRENT_TEST(torrent)
|
||||||
t.set_hash(i, ph);
|
t.set_hash(i, ph);
|
||||||
|
|
||||||
std::vector<char> tmp;
|
std::vector<char> tmp;
|
||||||
std::back_insert_iterator<std::vector<char> > out(tmp);
|
std::back_insert_iterator<std::vector<char>> out(tmp);
|
||||||
bencode(out, t.generate());
|
bencode(out, t.generate());
|
||||||
error_code ec;
|
error_code ec;
|
||||||
auto info = std::make_shared<torrent_info>(&tmp[0], int(tmp.size()), std::ref(ec), 0);
|
auto info = std::make_shared<torrent_info>(&tmp[0], int(tmp.size()), std::ref(ec), 0);
|
||||||
|
@ -340,7 +340,7 @@ TORRENT_TEST(duplicate_is_not_error)
|
||||||
t.set_hash(i, ph);
|
t.set_hash(i, ph);
|
||||||
|
|
||||||
std::vector<char> tmp;
|
std::vector<char> tmp;
|
||||||
std::back_insert_iterator<std::vector<char> > out(tmp);
|
std::back_insert_iterator<std::vector<char>> out(tmp);
|
||||||
bencode(out, t.generate());
|
bencode(out, t.generate());
|
||||||
error_code ec;
|
error_code ec;
|
||||||
|
|
||||||
|
@ -411,4 +411,3 @@ TORRENT_TEST(rename_file)
|
||||||
|
|
||||||
TEST_EQUAL(info->files().file_path(0), "tmp1");
|
TEST_EQUAL(info->files().file_path(0), "tmp1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ TORRENT_TEST(mutable_torrents)
|
||||||
t.add_similar_torrent(sha1_hash("babababababababababa"));
|
t.add_similar_torrent(sha1_hash("babababababababababa"));
|
||||||
|
|
||||||
std::vector<char> tmp;
|
std::vector<char> tmp;
|
||||||
std::back_insert_iterator<std::vector<char> > out(tmp);
|
std::back_insert_iterator<std::vector<char>> out(tmp);
|
||||||
|
|
||||||
entry tor = t.generate();
|
entry tor = t.generate();
|
||||||
bencode(out, tor);
|
bencode(out, tor);
|
||||||
|
@ -798,7 +798,7 @@ void test_resolve_duplicates(int test_case)
|
||||||
t.set_hash(i, ph);
|
t.set_hash(i, ph);
|
||||||
|
|
||||||
std::vector<char> tmp;
|
std::vector<char> tmp;
|
||||||
std::back_insert_iterator<std::vector<char> > out(tmp);
|
std::back_insert_iterator<std::vector<char>> out(tmp);
|
||||||
|
|
||||||
entry tor = t.generate();
|
entry tor = t.generate();
|
||||||
bencode(out, tor);
|
bencode(out, tor);
|
||||||
|
|
Loading…
Reference in New Issue