mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-02 22:48:40 +00:00
lt sync 2726
This commit is contained in:
parent
26d58d4057
commit
c432b82e69
22 changed files with 329 additions and 73 deletions
|
@ -49,6 +49,13 @@ struct entry_to_python
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PyObject* convert(boost::shared_ptr<entry> const& e)
|
||||||
|
{
|
||||||
|
if (!e)
|
||||||
|
return incref(Py_None);
|
||||||
|
return convert(*e);
|
||||||
|
}
|
||||||
|
|
||||||
static PyObject* convert(entry const& e)
|
static PyObject* convert(entry const& e)
|
||||||
{
|
{
|
||||||
return incref(convert0(e).ptr());
|
return incref(convert0(e).ptr());
|
||||||
|
@ -126,6 +133,7 @@ struct entry_from_python
|
||||||
|
|
||||||
void bind_entry()
|
void bind_entry()
|
||||||
{
|
{
|
||||||
|
to_python_converter<boost::shared_ptr<libtorrent::entry>, entry_to_python>();
|
||||||
to_python_converter<entry, entry_to_python>();
|
to_python_converter<entry, entry_to_python>();
|
||||||
entry_from_python();
|
entry_from_python();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <libtorrent/peer_connection.hpp>
|
#include <libtorrent/peer_connection.hpp>
|
||||||
#include <libtorrent/extensions/ut_pex.hpp>
|
#include <libtorrent/extensions/ut_pex.hpp>
|
||||||
#include <libtorrent/extensions/metadata_transfer.hpp>
|
#include <libtorrent/extensions/metadata_transfer.hpp>
|
||||||
|
#include <libtorrent/extensions/ut_metadata.hpp>
|
||||||
#include <boost/python.hpp>
|
#include <boost/python.hpp>
|
||||||
#include "gil.hpp"
|
#include "gil.hpp"
|
||||||
|
|
||||||
|
@ -114,6 +115,10 @@ boost::shared_ptr<torrent_plugin> create_metadata_plugin_wrapper(torrent* t) {
|
||||||
return create_metadata_plugin(t, NULL);
|
return create_metadata_plugin(t, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boost::shared_ptr<torrent_plugin> create_ut_metadata_plugin_wrapper(torrent *t) {
|
||||||
|
return create_ut_metadata_plugin(t, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
boost::shared_ptr<torrent_plugin> create_ut_pex_plugin_wrapper(torrent* t) {
|
boost::shared_ptr<torrent_plugin> create_ut_pex_plugin_wrapper(torrent* t) {
|
||||||
return create_ut_pex_plugin(t, NULL);
|
return create_ut_pex_plugin(t, NULL);
|
||||||
}
|
}
|
||||||
|
@ -154,6 +159,7 @@ void bind_extensions()
|
||||||
class_<torrent_plugin, boost::shared_ptr<torrent_plugin> >("torrent_plugin", no_init);
|
class_<torrent_plugin, boost::shared_ptr<torrent_plugin> >("torrent_plugin", no_init);
|
||||||
def("create_ut_pex_plugin", create_ut_pex_plugin_wrapper);
|
def("create_ut_pex_plugin", create_ut_pex_plugin_wrapper);
|
||||||
def("create_metadata_plugin", create_metadata_plugin_wrapper);
|
def("create_metadata_plugin", create_metadata_plugin_wrapper);
|
||||||
|
def("create_ut_metadata_plugin", create_ut_metadata_plugin_wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ void bind_peer_plugin();
|
||||||
void bind_torrent();
|
void bind_torrent();
|
||||||
void bind_peer_info();
|
void bind_peer_info();
|
||||||
void bind_ip_filter();
|
void bind_ip_filter();
|
||||||
|
void bind_magnet_uri();
|
||||||
|
|
||||||
BOOST_PYTHON_MODULE(libtorrent)
|
BOOST_PYTHON_MODULE(libtorrent)
|
||||||
{
|
{
|
||||||
|
@ -46,5 +47,6 @@ BOOST_PYTHON_MODULE(libtorrent)
|
||||||
bind_torrent();
|
bind_torrent();
|
||||||
bind_peer_info();
|
bind_peer_info();
|
||||||
bind_ip_filter();
|
bind_ip_filter();
|
||||||
|
bind_magnet_uri();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,6 +89,7 @@ void bind_peer_info()
|
||||||
.def_readonly("send_quota", &peer_info::send_quota)
|
.def_readonly("send_quota", &peer_info::send_quota)
|
||||||
.def_readonly("receive_quota", &peer_info::receive_quota)
|
.def_readonly("receive_quota", &peer_info::receive_quota)
|
||||||
.def_readonly("rtt", &peer_info::rtt)
|
.def_readonly("rtt", &peer_info::rtt)
|
||||||
|
.def_readonly("progress", &peer_info::progress)
|
||||||
;
|
;
|
||||||
|
|
||||||
// flags
|
// flags
|
||||||
|
|
|
@ -68,7 +68,14 @@ namespace
|
||||||
allow_threading_guard guard;
|
allow_threading_guard guard;
|
||||||
return s.listen_on(std::make_pair(min_, max_), interface);
|
return s.listen_on(std::make_pair(min_, max_), interface);
|
||||||
}
|
}
|
||||||
|
void outgoing_ports(session& s, int _min, int _max)
|
||||||
|
{
|
||||||
|
allow_threading_guard guard;
|
||||||
|
session_settings settings = s.settings();
|
||||||
|
settings.outgoing_ports = std::make_pair(_min, _max);
|
||||||
|
s.set_settings(settings);
|
||||||
|
return;
|
||||||
|
}
|
||||||
#ifndef TORRENT_DISABLE_DHT
|
#ifndef TORRENT_DISABLE_DHT
|
||||||
void add_dht_router(session& s, std::string router_, int port_)
|
void add_dht_router(session& s, std::string router_, int port_)
|
||||||
{
|
{
|
||||||
|
@ -257,6 +264,7 @@ void bind_session()
|
||||||
, (arg("min"), "max", arg("interface") = (char const*)0)
|
, (arg("min"), "max", arg("interface") = (char const*)0)
|
||||||
, session_listen_on_doc
|
, session_listen_on_doc
|
||||||
)
|
)
|
||||||
|
.def("outgoing_ports", &outgoing_ports)
|
||||||
.def("is_listening", allow_threads(&session::is_listening), session_is_listening_doc)
|
.def("is_listening", allow_threads(&session::is_listening), session_is_listening_doc)
|
||||||
.def("listen_port", allow_threads(&session::listen_port), session_listen_port_doc)
|
.def("listen_port", allow_threads(&session::listen_port), session_listen_port_doc)
|
||||||
.def("status", allow_threads(&session::status), session_status_m_doc)
|
.def("status", allow_threads(&session::status), session_status_m_doc)
|
||||||
|
|
|
@ -43,6 +43,7 @@ void bind_session_settings()
|
||||||
.def_readwrite("seed_time_ratio_limit", &session_settings::seed_time_ratio_limit)
|
.def_readwrite("seed_time_ratio_limit", &session_settings::seed_time_ratio_limit)
|
||||||
.def_readwrite("seed_time_limit", &session_settings::seed_time_limit)
|
.def_readwrite("seed_time_limit", &session_settings::seed_time_limit)
|
||||||
.def_readwrite("auto_scraped_interval", &session_settings::auto_scrape_interval)
|
.def_readwrite("auto_scraped_interval", &session_settings::auto_scrape_interval)
|
||||||
|
.def_readwrite("peer_tos", &session_settings::peer_tos)
|
||||||
#ifndef TORRENT_DISABLE_DHT
|
#ifndef TORRENT_DISABLE_DHT
|
||||||
.def_readwrite("use_dht_as_fallback", &session_settings::use_dht_as_fallback)
|
.def_readwrite("use_dht_as_fallback", &session_settings::use_dht_as_fallback)
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -196,6 +196,9 @@ namespace libtorrent
|
||||||
// the highest transfer rates seen for this peer
|
// the highest transfer rates seen for this peer
|
||||||
int download_rate_peak;
|
int download_rate_peak;
|
||||||
int upload_rate_peak;
|
int upload_rate_peak;
|
||||||
|
|
||||||
|
// the peers progress
|
||||||
|
float progress;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TORRENT_EXPORT peer_list_entry
|
struct TORRENT_EXPORT peer_list_entry
|
||||||
|
|
|
@ -155,6 +155,7 @@ namespace libtorrent
|
||||||
|
|
||||||
session(fingerprint const& print = fingerprint("LT"
|
session(fingerprint const& print = fingerprint("LT"
|
||||||
, LIBTORRENT_VERSION_MAJOR, LIBTORRENT_VERSION_MINOR, 0, 0)
|
, LIBTORRENT_VERSION_MAJOR, LIBTORRENT_VERSION_MINOR, 0, 0)
|
||||||
|
, int flags = start_default_features | add_default_plugins
|
||||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||||
, fs::path logpath = "."
|
, fs::path logpath = "."
|
||||||
#endif
|
#endif
|
||||||
|
@ -163,6 +164,7 @@ namespace libtorrent
|
||||||
fingerprint const& print
|
fingerprint const& print
|
||||||
, std::pair<int, int> listen_port_range
|
, std::pair<int, int> listen_port_range
|
||||||
, char const* listen_interface = "0.0.0.0"
|
, char const* listen_interface = "0.0.0.0"
|
||||||
|
, int flags = start_default_features | add_default_plugins
|
||||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||||
, fs::path logpath = "."
|
, fs::path logpath = "."
|
||||||
#endif
|
#endif
|
||||||
|
@ -290,6 +292,12 @@ namespace libtorrent
|
||||||
delete_files = 1
|
delete_files = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum session_flags_t
|
||||||
|
{
|
||||||
|
add_default_plugins = 1,
|
||||||
|
start_default_features = 2
|
||||||
|
};
|
||||||
|
|
||||||
void remove_torrent(const torrent_handle& h, int options = none);
|
void remove_torrent(const torrent_handle& h, int options = none);
|
||||||
|
|
||||||
void set_settings(session_settings const& s);
|
void set_settings(session_settings const& s);
|
||||||
|
|
|
@ -130,8 +130,6 @@ namespace libtorrent
|
||||||
|
|
||||||
~torrent();
|
~torrent();
|
||||||
|
|
||||||
void parse_resume_data(std::vector<char>* resume_data);
|
|
||||||
|
|
||||||
#ifndef TORRENT_DISABLE_ENCRYPTION
|
#ifndef TORRENT_DISABLE_ENCRYPTION
|
||||||
sha1_hash const& obfuscated_hash() const
|
sha1_hash const& obfuscated_hash() const
|
||||||
{ return m_obfuscated_hash; }
|
{ return m_obfuscated_hash; }
|
||||||
|
|
|
@ -197,8 +197,6 @@ namespace libtorrent
|
||||||
nodes_t m_nodes;
|
nodes_t m_nodes;
|
||||||
|
|
||||||
// the hash that identifies this torrent
|
// the hash that identifies this torrent
|
||||||
// is mutable because it's calculated
|
|
||||||
// lazily
|
|
||||||
sha1_hash m_info_hash;
|
sha1_hash m_info_hash;
|
||||||
|
|
||||||
// if a creation date is found in the torrent file
|
// if a creation date is found in the torrent file
|
||||||
|
|
|
@ -64,6 +64,10 @@ namespace libtorrent
|
||||||
void set_proxy_settings(proxy_settings const& ps);
|
void set_proxy_settings(proxy_settings const& ps);
|
||||||
proxy_settings const& get_proxy_settings() { return m_proxy_settings; }
|
proxy_settings const& get_proxy_settings() { return m_proxy_settings; }
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
~udp_socket() { m_magic = 0; }
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
callback_t m_callback;
|
callback_t m_callback;
|
||||||
|
@ -94,6 +98,7 @@ namespace libtorrent
|
||||||
char m_v4_buf[1600];
|
char m_v4_buf[1600];
|
||||||
char m_v6_buf[1600];
|
char m_v6_buf[1600];
|
||||||
int m_bind_port;
|
int m_bind_port;
|
||||||
|
char m_outstanding;
|
||||||
|
|
||||||
tcp::socket m_socks5_sock;
|
tcp::socket m_socks5_sock;
|
||||||
int m_connection_ticket;
|
int m_connection_ticket;
|
||||||
|
@ -103,6 +108,9 @@ namespace libtorrent
|
||||||
char m_tmp_buf[100];
|
char m_tmp_buf[100];
|
||||||
bool m_tunnel_packets;
|
bool m_tunnel_packets;
|
||||||
udp::endpoint m_proxy_addr;
|
udp::endpoint m_proxy_addr;
|
||||||
|
#ifndef NDEBUG
|
||||||
|
int m_magic;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -170,7 +170,7 @@ namespace libtorrent
|
||||||
, end(interfaces.end()); i != end; ++i)
|
, end(interfaces.end()); i != end; ++i)
|
||||||
{
|
{
|
||||||
// only broadcast to IPv4 addresses that are not local
|
// only broadcast to IPv4 addresses that are not local
|
||||||
if (!is_local(i->interface_address)) continue;
|
if (is_local(i->interface_address)) continue;
|
||||||
// only multicast on compatible networks
|
// only multicast on compatible networks
|
||||||
if (i->interface_address.is_v4() != multicast_endpoint.address().is_v4()) continue;
|
if (i->interface_address.is_v4() != multicast_endpoint.address().is_v4()) continue;
|
||||||
// ignore any loopback interface
|
// ignore any loopback interface
|
||||||
|
|
|
@ -95,7 +95,7 @@ namespace
|
||||||
std::string ret;
|
std::string ret;
|
||||||
ret.resize(size);
|
ret.resize(size);
|
||||||
size = wcstombs(&ret[0], ws.c_str(), size + 1);
|
size = wcstombs(&ret[0], ws.c_str(), size + 1);
|
||||||
if (size == wchar_t(-1)) return s;
|
if (size == std::size_t(-1)) return s;
|
||||||
ret.resize(size);
|
ret.resize(size);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,11 @@ namespace
|
||||||
|
|
||||||
namespace libtorrent
|
namespace libtorrent
|
||||||
{
|
{
|
||||||
int fail_bdecode() { return -1; }
|
int fail_bdecode(lazy_entry& ret)
|
||||||
|
{
|
||||||
|
ret = lazy_entry();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// fills in 'val' with what the string between start and the
|
// fills in 'val' with what the string between start and the
|
||||||
// first occurance of the delimiter is interpreted as an int.
|
// first occurance of the delimiter is interpreted as an int.
|
||||||
|
@ -58,7 +62,7 @@ namespace libtorrent
|
||||||
while (start < end && *start != delimiter)
|
while (start < end && *start != delimiter)
|
||||||
{
|
{
|
||||||
using namespace std;
|
using namespace std;
|
||||||
if (!isdigit(*start)) { fail_bdecode(); return 0; }
|
if (!isdigit(*start)) { return 0; }
|
||||||
val *= 10;
|
val *= 10;
|
||||||
val += *start - '0';
|
val += *start - '0';
|
||||||
++start;
|
++start;
|
||||||
|
@ -87,11 +91,11 @@ namespace libtorrent
|
||||||
|
|
||||||
lazy_entry* top = stack.back();
|
lazy_entry* top = stack.back();
|
||||||
|
|
||||||
if (int(stack.size()) > depth_limit) return fail_bdecode();
|
if (int(stack.size()) > depth_limit) return fail_bdecode(ret);
|
||||||
if (start >= end) return fail_bdecode();
|
if (start >= end) return fail_bdecode(ret);
|
||||||
char t = *start;
|
char t = *start;
|
||||||
++start;
|
++start;
|
||||||
if (start >= end && t != 'e') return fail_bdecode();
|
if (start >= end && t != 'e') return fail_bdecode(ret);
|
||||||
|
|
||||||
switch (top->type())
|
switch (top->type())
|
||||||
{
|
{
|
||||||
|
@ -105,12 +109,12 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
boost::int64_t len = t - '0';
|
boost::int64_t len = t - '0';
|
||||||
start = parse_int(start, end, ':', len);
|
start = parse_int(start, end, ':', len);
|
||||||
if (start == 0 || start + len + 3 > end || *start != ':') return fail_bdecode();
|
if (start == 0 || start + len + 3 > end || *start != ':') return fail_bdecode(ret);
|
||||||
++start;
|
++start;
|
||||||
if (start == end) fail_bdecode();
|
if (start == end) fail_bdecode(ret);
|
||||||
lazy_entry* ent = top->dict_append(start);
|
lazy_entry* ent = top->dict_append(start);
|
||||||
start += len;
|
start += len;
|
||||||
if (start >= end) fail_bdecode();
|
if (start >= end) fail_bdecode(ret);
|
||||||
stack.push_back(ent);
|
stack.push_back(ent);
|
||||||
t = *start;
|
t = *start;
|
||||||
++start;
|
++start;
|
||||||
|
@ -145,7 +149,7 @@ namespace libtorrent
|
||||||
char const* int_start = start;
|
char const* int_start = start;
|
||||||
start = find_char(start, end, 'e');
|
start = find_char(start, end, 'e');
|
||||||
top->construct_int(int_start, start - int_start);
|
top->construct_int(int_start, start - int_start);
|
||||||
if (start == end) return fail_bdecode();
|
if (start == end) return fail_bdecode(ret);
|
||||||
TORRENT_ASSERT(*start == 'e');
|
TORRENT_ASSERT(*start == 'e');
|
||||||
++start;
|
++start;
|
||||||
stack.pop_back();
|
stack.pop_back();
|
||||||
|
@ -154,11 +158,11 @@ namespace libtorrent
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
using namespace std;
|
using namespace std;
|
||||||
if (!isdigit(t)) return fail_bdecode();
|
if (!isdigit(t)) return fail_bdecode(ret);
|
||||||
|
|
||||||
boost::int64_t len = t - '0';
|
boost::int64_t len = t - '0';
|
||||||
start = parse_int(start, end, ':', len);
|
start = parse_int(start, end, ':', len);
|
||||||
if (start == 0 || start + len + 1 > end || *start != ':') return fail_bdecode();
|
if (start == 0 || start + len + 1 > end || *start != ':') return fail_bdecode(ret);
|
||||||
++start;
|
++start;
|
||||||
top->construct_string(start, int(len));
|
top->construct_string(start, int(len));
|
||||||
stack.pop_back();
|
stack.pop_back();
|
||||||
|
@ -391,11 +395,12 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
os << "[";
|
os << "[";
|
||||||
bool one_liner = (e.list_size() == 0
|
bool one_liner = (e.list_size() == 0
|
||||||
|| e.list_at(0)->type() == lazy_entry::int_t
|
|| (e.list_at(0)->type() == lazy_entry::int_t
|
||||||
|
&& e.list_size() < 20)
|
||||||
|| (e.list_at(0)->type() == lazy_entry::string_t
|
|| (e.list_at(0)->type() == lazy_entry::string_t
|
||||||
&& (e.list_at(0)->string_length() < 10
|
&& (e.list_at(0)->string_length() < 10
|
||||||
|| e.list_size() < 2)))
|
|| e.list_size() < 2))
|
||||||
&& e.list_size() < 5;
|
&& e.list_size() < 5);
|
||||||
if (!one_liner) os << "\n";
|
if (!one_liner) os << "\n";
|
||||||
for (int i = 0; i < e.list_size(); ++i)
|
for (int i = 0; i < e.list_size(); ++i)
|
||||||
{
|
{
|
||||||
|
|
|
@ -226,6 +226,20 @@ void natpmp::try_next_mapping(int i)
|
||||||
|
|
||||||
void natpmp::update_mapping(int i)
|
void natpmp::update_mapping(int i)
|
||||||
{
|
{
|
||||||
|
if (i == m_mappings.size())
|
||||||
|
{
|
||||||
|
if (m_abort)
|
||||||
|
{
|
||||||
|
error_code ec;
|
||||||
|
m_send_timer.cancel(ec);
|
||||||
|
m_socket.close(ec);
|
||||||
|
}
|
||||||
|
#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING)
|
||||||
|
m_log << " done" << (m_abort?" shutting down":"") << std::endl;
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
natpmp::mapping_t& m = m_mappings[i];
|
natpmp::mapping_t& m = m_mappings[i];
|
||||||
if (m.action == mapping_t::action_none
|
if (m.action == mapping_t::action_none
|
||||||
|| m.protocol == none)
|
|| m.protocol == none)
|
||||||
|
|
|
@ -1693,6 +1693,9 @@ namespace libtorrent
|
||||||
send_block_requests();
|
send_block_requests();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#ifndef NDEBUG
|
||||||
|
pending_block pending_b = *b;
|
||||||
|
#endif
|
||||||
|
|
||||||
int block_index = b - m_download_queue.begin() - 1;
|
int block_index = b - m_download_queue.begin() - 1;
|
||||||
for (int i = 0; i < block_index; ++i)
|
for (int i = 0; i < block_index; ++i)
|
||||||
|
@ -1721,6 +1724,9 @@ namespace libtorrent
|
||||||
--block_index;
|
--block_index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
TORRENT_ASSERT(int(m_download_queue.size()) > block_index + 1);
|
||||||
|
b = m_download_queue.begin() + (block_index + 1);
|
||||||
|
TORRENT_ASSERT(b->block == pending_b.block);
|
||||||
|
|
||||||
// if the block we got is already finished, then ignore it
|
// if the block we got is already finished, then ignore it
|
||||||
if (picker.is_downloaded(block_finished))
|
if (picker.is_downloaded(block_finished))
|
||||||
|
@ -2666,6 +2672,8 @@ namespace libtorrent
|
||||||
p.used_receive_buffer = m_recv_pos;
|
p.used_receive_buffer = m_recv_pos;
|
||||||
p.write_state = m_channel_state[upload_channel];
|
p.write_state = m_channel_state[upload_channel];
|
||||||
p.read_state = m_channel_state[download_channel];
|
p.read_state = m_channel_state[download_channel];
|
||||||
|
|
||||||
|
p.progress = (float)p.pieces.count() / (float)p.pieces.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
// allocates a disk buffer of size 'disk_buffer_size' and replaces the
|
// allocates a disk buffer of size 'disk_buffer_size' and replaces the
|
||||||
|
@ -3625,7 +3633,22 @@ namespace libtorrent
|
||||||
disconnect(ec.message().c_str());
|
disconnect(ec.message().c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_socket->bind(t->get_interface(), ec);
|
|
||||||
|
tcp::endpoint bind_interface = t->get_interface();
|
||||||
|
|
||||||
|
std::pair<int, int> const& out_ports = m_ses.settings().outgoing_ports;
|
||||||
|
if (out_ports.first > 0 && out_ports.second >= out_ports.first)
|
||||||
|
{
|
||||||
|
m_socket->set_option(socket_acceptor::reuse_address(true), ec);
|
||||||
|
if (ec)
|
||||||
|
{
|
||||||
|
disconnect(ec.message().c_str());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bind_interface.port(m_ses.next_port());
|
||||||
|
}
|
||||||
|
|
||||||
|
m_socket->bind(bind_interface, ec);
|
||||||
if (ec)
|
if (ec)
|
||||||
{
|
{
|
||||||
disconnect(ec.message().c_str());
|
disconnect(ec.message().c_str());
|
||||||
|
@ -3818,7 +3841,7 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t->ready_for_connections() && m_initialized)
|
if (t->ready_for_connections() && m_initialized)
|
||||||
TORRENT_ASSERT(t->torrent_file().num_pieces() == m_have_piece.size());
|
TORRENT_ASSERT(t->torrent_file().num_pieces() == int(m_have_piece.size()));
|
||||||
|
|
||||||
if (m_ses.settings().close_redundant_connections)
|
if (m_ses.settings().close_redundant_connections)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1304,6 +1304,9 @@ namespace libtorrent
|
||||||
, int prefer_whole_pieces, void* peer, piece_state_t speed
|
, int prefer_whole_pieces, void* peer, piece_state_t speed
|
||||||
, int options, std::vector<int> const& suggested_pieces) const
|
, int options, std::vector<int> const& suggested_pieces) const
|
||||||
{
|
{
|
||||||
|
// prevent the number of partial pieces to grow indefinitely
|
||||||
|
if (m_downloads.size() > 20) options |= prioritize_partials;
|
||||||
|
|
||||||
// only one of rarest_first and sequential can be set.
|
// only one of rarest_first and sequential can be set.
|
||||||
TORRENT_ASSERT(bool(options & rarest_first)
|
TORRENT_ASSERT(bool(options & rarest_first)
|
||||||
+ bool(options & sequential) <= 1);
|
+ bool(options & sequential) <= 1);
|
||||||
|
|
|
@ -991,6 +991,7 @@ namespace libtorrent
|
||||||
++p->second.failcount;
|
++p->second.failcount;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
TORRENT_ASSERT(p->second.connection);
|
||||||
TORRENT_ASSERT(!is_connect_candidate(p->second, m_torrent->is_finished()));
|
TORRENT_ASSERT(!is_connect_candidate(p->second, m_torrent->is_finished()));
|
||||||
--m_num_connect_candidates;
|
--m_num_connect_candidates;
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -56,6 +56,9 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "libtorrent/extensions/ut_pex.hpp"
|
||||||
|
#include "libtorrent/extensions/ut_metadata.hpp"
|
||||||
|
#include "libtorrent/extensions/smart_ban.hpp"
|
||||||
#include "libtorrent/peer_id.hpp"
|
#include "libtorrent/peer_id.hpp"
|
||||||
#include "libtorrent/torrent_info.hpp"
|
#include "libtorrent/torrent_info.hpp"
|
||||||
#include "libtorrent/tracker_manager.hpp"
|
#include "libtorrent/tracker_manager.hpp"
|
||||||
|
@ -112,6 +115,7 @@ namespace libtorrent
|
||||||
fingerprint const& id
|
fingerprint const& id
|
||||||
, std::pair<int, int> listen_port_range
|
, std::pair<int, int> listen_port_range
|
||||||
, char const* listen_interface
|
, char const* listen_interface
|
||||||
|
, int flags
|
||||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||||
, fs::path logpath
|
, fs::path logpath
|
||||||
#endif
|
#endif
|
||||||
|
@ -120,7 +124,7 @@ namespace libtorrent
|
||||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||||
, logpath
|
, logpath
|
||||||
#endif
|
#endif
|
||||||
))
|
))
|
||||||
{
|
{
|
||||||
#ifdef TORRENT_MEMDEBUG
|
#ifdef TORRENT_MEMDEBUG
|
||||||
start_malloc_debug();
|
start_malloc_debug();
|
||||||
|
@ -135,9 +139,23 @@ namespace libtorrent
|
||||||
boost::function0<void> test = boost::ref(*m_impl);
|
boost::function0<void> test = boost::ref(*m_impl);
|
||||||
TORRENT_ASSERT(!test.empty());
|
TORRENT_ASSERT(!test.empty());
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef TORRENT_DISABLE_EXTENSIONS
|
||||||
|
if (flags & add_default_plugins)
|
||||||
|
{
|
||||||
|
add_extension(create_ut_pex_plugin);
|
||||||
|
add_extension(create_ut_metadata_plugin);
|
||||||
|
add_extension(create_smart_ban_plugin);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (flags & start_default_features)
|
||||||
|
{
|
||||||
|
start_upnp();
|
||||||
|
start_upnp();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
session::session(fingerprint const& id
|
session::session(fingerprint const& id
|
||||||
|
, int flags
|
||||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||||
, fs::path logpath
|
, fs::path logpath
|
||||||
#endif
|
#endif
|
||||||
|
@ -155,6 +173,19 @@ namespace libtorrent
|
||||||
boost::function0<void> test = boost::ref(*m_impl);
|
boost::function0<void> test = boost::ref(*m_impl);
|
||||||
TORRENT_ASSERT(!test.empty());
|
TORRENT_ASSERT(!test.empty());
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef TORRENT_DISABLE_EXTENSIONS
|
||||||
|
if (flags & add_default_plugins)
|
||||||
|
{
|
||||||
|
add_extension(create_ut_pex_plugin);
|
||||||
|
add_extension(create_ut_metadata_plugin);
|
||||||
|
add_extension(create_smart_ban_plugin);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (flags & start_default_features)
|
||||||
|
{
|
||||||
|
start_upnp();
|
||||||
|
start_natpmp();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
session::~session()
|
session::~session()
|
||||||
|
@ -170,10 +201,12 @@ namespace libtorrent
|
||||||
m_impl->abort();
|
m_impl->abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef TORRENT_DISABLE_EXTENSIONS
|
||||||
void session::add_extension(boost::function<boost::shared_ptr<torrent_plugin>(torrent*, void*)> ext)
|
void session::add_extension(boost::function<boost::shared_ptr<torrent_plugin>(torrent*, void*)> ext)
|
||||||
{
|
{
|
||||||
m_impl->add_extension(ext);
|
m_impl->add_extension(ext);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef TORRENT_DISABLE_GEO_IP
|
#ifndef TORRENT_DISABLE_GEO_IP
|
||||||
bool session::load_asnum_db(char const* file)
|
bool session::load_asnum_db(char const* file)
|
||||||
|
|
|
@ -51,6 +51,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <boost/filesystem/exception.hpp>
|
#include <boost/filesystem/exception.hpp>
|
||||||
#include <boost/limits.hpp>
|
#include <boost/limits.hpp>
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
|
#include <boost/function_equal.hpp>
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
|
@ -386,6 +387,17 @@ namespace aux {
|
||||||
void session_impl::add_extension(
|
void session_impl::add_extension(
|
||||||
boost::function<boost::shared_ptr<torrent_plugin>(torrent*, void*)> ext)
|
boost::function<boost::shared_ptr<torrent_plugin>(torrent*, void*)> ext)
|
||||||
{
|
{
|
||||||
|
TORRENT_ASSERT(ext);
|
||||||
|
|
||||||
|
typedef boost::shared_ptr<torrent_plugin>(*function_t)(torrent*, void*);
|
||||||
|
function_t const* f = ext.target<function_t>();
|
||||||
|
|
||||||
|
if (f)
|
||||||
|
{
|
||||||
|
for (extension_list_t::iterator i = m_extensions.begin(); i != m_extensions.end(); ++i)
|
||||||
|
if (function_equal(*i, *f)) return;
|
||||||
|
}
|
||||||
|
|
||||||
m_extensions.push_back(ext);
|
m_extensions.push_back(ext);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -2469,7 +2481,7 @@ namespace aux {
|
||||||
++total_downloaders;
|
++total_downloaders;
|
||||||
unique.insert(i->second->queue_position());
|
unique.insert(i->second->queue_position());
|
||||||
}
|
}
|
||||||
TORRENT_ASSERT(unique.size() == total_downloaders);
|
TORRENT_ASSERT(int(unique.size()) == total_downloaders);
|
||||||
|
|
||||||
TORRENT_ASSERT(m_max_connections > 0);
|
TORRENT_ASSERT(m_max_connections > 0);
|
||||||
TORRENT_ASSERT(m_max_uploads > 0);
|
TORRENT_ASSERT(m_max_uploads > 0);
|
||||||
|
|
|
@ -205,7 +205,7 @@ namespace libtorrent
|
||||||
, m_start_sent(false)
|
, m_start_sent(false)
|
||||||
, m_complete_sent(false)
|
, m_complete_sent(false)
|
||||||
{
|
{
|
||||||
parse_resume_data(resume_data);
|
if (resume_data) m_resume_data.swap(*resume_data);
|
||||||
|
|
||||||
#ifndef TORRENT_DISABLE_ENCRYPTION
|
#ifndef TORRENT_DISABLE_ENCRYPTION
|
||||||
hasher h;
|
hasher h;
|
||||||
|
@ -286,7 +286,7 @@ namespace libtorrent
|
||||||
, m_start_sent(false)
|
, m_start_sent(false)
|
||||||
, m_complete_sent(false)
|
, m_complete_sent(false)
|
||||||
{
|
{
|
||||||
parse_resume_data(resume_data);
|
if (resume_data) m_resume_data.swap(*resume_data);
|
||||||
|
|
||||||
#ifndef TORRENT_DISABLE_ENCRYPTION
|
#ifndef TORRENT_DISABLE_ENCRYPTION
|
||||||
hasher h;
|
hasher h;
|
||||||
|
@ -309,27 +309,25 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void torrent::parse_resume_data(std::vector<char>* resume_data)
|
|
||||||
{
|
|
||||||
if (!resume_data) return;
|
|
||||||
m_resume_data.swap(*resume_data);
|
|
||||||
if (lazy_bdecode(&m_resume_data[0], &m_resume_data[0]
|
|
||||||
+ m_resume_data.size(), m_resume_entry) != 0)
|
|
||||||
{
|
|
||||||
std::vector<char>().swap(m_resume_data);
|
|
||||||
if (m_ses.m_alerts.should_post<fastresume_rejected_alert>())
|
|
||||||
{
|
|
||||||
m_ses.m_alerts.post_alert(fastresume_rejected_alert(get_handle(), "parse failed"));
|
|
||||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
|
||||||
(*m_ses.m_logger) << "fastresume data for "
|
|
||||||
<< torrent_file().name() << " rejected: parse failed\n";
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void torrent::start()
|
void torrent::start()
|
||||||
{
|
{
|
||||||
|
if (!m_resume_data.empty())
|
||||||
|
{
|
||||||
|
if (lazy_bdecode(&m_resume_data[0], &m_resume_data[0]
|
||||||
|
+ m_resume_data.size(), m_resume_entry) != 0)
|
||||||
|
{
|
||||||
|
std::vector<char>().swap(m_resume_data);
|
||||||
|
if (m_ses.m_alerts.should_post<fastresume_rejected_alert>())
|
||||||
|
{
|
||||||
|
m_ses.m_alerts.post_alert(fastresume_rejected_alert(get_handle(), "parse failed"));
|
||||||
|
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||||
|
(*m_ses.m_logger) << "fastresume data for "
|
||||||
|
<< torrent_file().name() << " rejected: parse failed\n";
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// we need to start announcing since we don't have any
|
// we need to start announcing since we don't have any
|
||||||
// metadata. To receive peers to ask for it.
|
// metadata. To receive peers to ask for it.
|
||||||
if (m_torrent_file->is_valid()) init();
|
if (m_torrent_file->is_valid()) init();
|
||||||
|
@ -1998,6 +1996,8 @@ namespace libtorrent
|
||||||
if (m_currently_trying_tracker >= (int)m_trackers.size())
|
if (m_currently_trying_tracker >= (int)m_trackers.size())
|
||||||
m_currently_trying_tracker = (int)m_trackers.size()-1;
|
m_currently_trying_tracker = (int)m_trackers.size()-1;
|
||||||
m_last_working_tracker = -1;
|
m_last_working_tracker = -1;
|
||||||
|
if (!m_trackers.empty()) start_announcing();
|
||||||
|
else stop_announcing();
|
||||||
}
|
}
|
||||||
|
|
||||||
void torrent::choke_peer(peer_connection& c)
|
void torrent::choke_peer(peer_connection& c)
|
||||||
|
@ -2306,11 +2306,6 @@ namespace libtorrent
|
||||||
s->get<http_stream>().set_no_connect(true);
|
s->get<http_stream>().set_no_connect(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<int, int> const& out_ports = m_settings.outgoing_ports;
|
|
||||||
error_code ec;
|
|
||||||
if (out_ports.first > 0 && out_ports.second >= out_ports.first)
|
|
||||||
s->bind(tcp::endpoint(address(), m_ses.next_port()), ec);
|
|
||||||
|
|
||||||
boost::intrusive_ptr<peer_connection> c(new (std::nothrow) web_peer_connection(
|
boost::intrusive_ptr<peer_connection> c(new (std::nothrow) web_peer_connection(
|
||||||
m_ses, shared_from_this(), s, a, url, 0));
|
m_ses, shared_from_this(), s, a, url, 0));
|
||||||
if (!c) return;
|
if (!c) return;
|
||||||
|
@ -2520,8 +2515,50 @@ namespace libtorrent
|
||||||
m_picker->set_piece_priority(i, p[i]);
|
m_picker->set_piece_priority(i, p[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rd.dict_find_int_value("auto_managed")) auto_managed(true);
|
int auto_managed_ = rd.dict_find_int_value("auto_managed", -1);
|
||||||
if (rd.dict_find_int_value("paused")) pause();
|
if (auto_managed_ != -1) auto_managed(auto_managed_);
|
||||||
|
|
||||||
|
int sequential_ = rd.dict_find_int_value("sequential_download", -1);
|
||||||
|
if (sequential_ != -1) set_sequential_download(sequential_);
|
||||||
|
|
||||||
|
int paused_ = rd.dict_find_int_value("paused", -1);
|
||||||
|
if (paused_ == 1) pause();
|
||||||
|
else if (paused_ == 0) resume();
|
||||||
|
|
||||||
|
lazy_entry const* trackers = rd.dict_find_list("trackers");
|
||||||
|
if (trackers)
|
||||||
|
{
|
||||||
|
int tier = 0;
|
||||||
|
for (int i = 0; i < trackers->list_size(); ++i)
|
||||||
|
{
|
||||||
|
lazy_entry const* tier_list = trackers->list_at(i);
|
||||||
|
if (tier_list == 0 || tier_list->type() != lazy_entry::list_t)
|
||||||
|
continue;
|
||||||
|
for (int j = 0; j < tier_list->list_size(); ++j)
|
||||||
|
{
|
||||||
|
announce_entry e(tier_list->list_string_value_at(j));
|
||||||
|
if (std::find_if(m_trackers.begin(), m_trackers.end()
|
||||||
|
, boost::bind(&announce_entry::url, _1) == e.url) != m_trackers.end())
|
||||||
|
continue;
|
||||||
|
e.tier = tier;
|
||||||
|
m_trackers.push_back(e);
|
||||||
|
}
|
||||||
|
++tier;
|
||||||
|
}
|
||||||
|
std::sort(m_trackers.begin(), m_trackers.end(), boost::bind(&announce_entry::tier, _1)
|
||||||
|
< boost::bind(&announce_entry::tier, _2));
|
||||||
|
}
|
||||||
|
|
||||||
|
lazy_entry const* url_list = rd.dict_find_list("url-list");
|
||||||
|
if (url_list)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < url_list->list_size(); ++i)
|
||||||
|
{
|
||||||
|
std::string url = url_list->list_string_value_at(i);
|
||||||
|
if (url.empty()) continue;
|
||||||
|
m_web_seeds.insert(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void torrent::write_resume_data(entry& ret) const
|
void torrent::write_resume_data(entry& ret) const
|
||||||
|
@ -2544,6 +2581,8 @@ namespace libtorrent
|
||||||
|
|
||||||
ret["num_seeds"] = seeds;
|
ret["num_seeds"] = seeds;
|
||||||
ret["num_downloaders"] = downloaders;
|
ret["num_downloaders"] = downloaders;
|
||||||
|
|
||||||
|
ret["sequential_download"] = m_sequential_download;
|
||||||
|
|
||||||
const sha1_hash& info_hash = torrent_file().info_hash();
|
const sha1_hash& info_hash = torrent_file().info_hash();
|
||||||
ret["info-hash"] = std::string((char*)info_hash.begin(), (char*)info_hash.end());
|
ret["info-hash"] = std::string((char*)info_hash.begin(), (char*)info_hash.end());
|
||||||
|
@ -2595,6 +2634,39 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// save trackers
|
||||||
|
if (!m_trackers.empty())
|
||||||
|
{
|
||||||
|
entry::list_type& tr_list = ret["trackers"].list();
|
||||||
|
tr_list.push_back(entry::list_type());
|
||||||
|
int tier = 0;
|
||||||
|
for (std::vector<announce_entry>::const_iterator i = m_trackers.begin()
|
||||||
|
, end(m_trackers.end()); i != end; ++i)
|
||||||
|
{
|
||||||
|
if (i->tier == tier)
|
||||||
|
{
|
||||||
|
tr_list.back().list().push_back(i->url);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tr_list.push_back(entry::list_t);
|
||||||
|
tr_list.back().list().push_back(i->url);
|
||||||
|
tier = i->tier;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// save web seeds
|
||||||
|
if (!m_web_seeds.empty())
|
||||||
|
{
|
||||||
|
entry::list_type& url_list = ret["url-list"].list();
|
||||||
|
for (std::set<std::string>::const_iterator i = m_web_seeds.begin()
|
||||||
|
, end(m_web_seeds.end()); i != end; ++i)
|
||||||
|
{
|
||||||
|
url_list.push_back(*i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// write have bitmask
|
// write have bitmask
|
||||||
entry::string_type& pieces = ret["pieces"].string();
|
entry::string_type& pieces = ret["pieces"].string();
|
||||||
pieces.resize(m_torrent_file->num_pieces());
|
pieces.resize(m_torrent_file->num_pieces());
|
||||||
|
@ -2812,10 +2884,6 @@ namespace libtorrent
|
||||||
bool ret = instantiate_connection(m_ses.m_io_service, m_ses.peer_proxy(), *s);
|
bool ret = instantiate_connection(m_ses.m_io_service, m_ses.peer_proxy(), *s);
|
||||||
(void)ret;
|
(void)ret;
|
||||||
TORRENT_ASSERT(ret);
|
TORRENT_ASSERT(ret);
|
||||||
std::pair<int, int> const& out_ports = m_ses.settings().outgoing_ports;
|
|
||||||
error_code ec;
|
|
||||||
if (out_ports.first > 0 && out_ports.second >= out_ports.first)
|
|
||||||
s->bind(tcp::endpoint(address(), m_ses.next_port()), ec);
|
|
||||||
|
|
||||||
boost::intrusive_ptr<peer_connection> c(new bt_peer_connection(
|
boost::intrusive_ptr<peer_connection> c(new bt_peer_connection(
|
||||||
m_ses, shared_from_this(), s, a, peerinfo));
|
m_ses, shared_from_this(), s, a, peerinfo));
|
||||||
|
@ -2871,7 +2939,8 @@ namespace libtorrent
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return true;
|
|
||||||
|
return peerinfo->connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool torrent::set_metadata(lazy_entry const& metadata, std::string& error)
|
bool torrent::set_metadata(lazy_entry const& metadata, std::string& error)
|
||||||
|
|
|
@ -18,20 +18,33 @@ udp_socket::udp_socket(asio::io_service& ios, udp_socket::callback_t const& c
|
||||||
, m_ipv4_sock(ios)
|
, m_ipv4_sock(ios)
|
||||||
, m_ipv6_sock(ios)
|
, m_ipv6_sock(ios)
|
||||||
, m_bind_port(0)
|
, m_bind_port(0)
|
||||||
|
, m_outstanding(0)
|
||||||
, m_socks5_sock(ios)
|
, m_socks5_sock(ios)
|
||||||
, m_connection_ticket(-1)
|
, m_connection_ticket(-1)
|
||||||
, m_cc(cc)
|
, m_cc(cc)
|
||||||
, m_resolver(ios)
|
, m_resolver(ios)
|
||||||
, m_tunnel_packets(false)
|
, m_tunnel_packets(false)
|
||||||
{
|
{
|
||||||
|
#ifndef NDEBUG
|
||||||
|
m_magic = 0x1337;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
#define CHECK_MAGIC check_magic_ cm_(m_magic)
|
||||||
|
struct check_magic_
|
||||||
|
{
|
||||||
|
check_magic_(int& m_): m(m_) { TORRENT_ASSERT(m == 0x1337); }
|
||||||
|
~check_magic_() { TORRENT_ASSERT(m == 0x1337); }
|
||||||
|
int& m;
|
||||||
|
};
|
||||||
|
#else
|
||||||
|
#define CHECK_MAGIC do {} while (false)
|
||||||
|
#endif
|
||||||
|
|
||||||
void udp_socket::send(udp::endpoint const& ep, char const* p, int len, error_code& ec)
|
void udp_socket::send(udp::endpoint const& ep, char const* p, int len, error_code& ec)
|
||||||
{
|
{
|
||||||
if (ec == asio::error::operation_aborted) return;
|
CHECK_MAGIC;
|
||||||
|
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
|
||||||
|
|
||||||
if (m_tunnel_packets)
|
if (m_tunnel_packets)
|
||||||
{
|
{
|
||||||
// send udp packets through SOCKS5 server
|
// send udp packets through SOCKS5 server
|
||||||
|
@ -47,10 +60,26 @@ void udp_socket::send(udp::endpoint const& ep, char const* p, int len, error_cod
|
||||||
|
|
||||||
void udp_socket::on_read(udp::socket* s, error_code const& e, std::size_t bytes_transferred)
|
void udp_socket::on_read(udp::socket* s, error_code const& e, std::size_t bytes_transferred)
|
||||||
{
|
{
|
||||||
if (e == asio::error::operation_aborted) return;
|
TORRENT_ASSERT(m_magic == 0x1337);
|
||||||
|
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
||||||
|
TORRENT_ASSERT(m_outstanding > 0);
|
||||||
|
--m_outstanding;
|
||||||
|
|
||||||
|
if (e == asio::error::operation_aborted)
|
||||||
|
{
|
||||||
|
if (m_outstanding == 0)
|
||||||
|
{
|
||||||
|
// "this" may be destructed in the callback
|
||||||
|
// that's why we need to unlock
|
||||||
|
l.unlock();
|
||||||
|
callback_t tmp = m_callback;
|
||||||
|
m_callback.clear();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CHECK_MAGIC;
|
||||||
if (!m_callback) return;
|
if (!m_callback) return;
|
||||||
|
|
||||||
if (e)
|
if (e)
|
||||||
|
@ -59,9 +88,9 @@ void udp_socket::on_read(udp::socket* s, error_code const& e, std::size_t bytes_
|
||||||
try {
|
try {
|
||||||
#endif
|
#endif
|
||||||
if (s == &m_ipv4_sock)
|
if (s == &m_ipv4_sock)
|
||||||
get_io_service().post(boost::bind(m_callback, e, m_v4_ep, (char*)0, 0));
|
m_callback(e, m_v4_ep, 0, 0);
|
||||||
else
|
else
|
||||||
get_io_service().post(boost::bind(m_callback, e, m_v6_ep, (char*)0, 0));
|
m_callback(e, m_v6_ep, 0, 0);
|
||||||
#ifndef BOOST_NO_EXCEPTIONS
|
#ifndef BOOST_NO_EXCEPTIONS
|
||||||
} catch(std::exception&) {}
|
} catch(std::exception&) {}
|
||||||
#endif
|
#endif
|
||||||
|
@ -94,7 +123,7 @@ void udp_socket::on_read(udp::socket* s, error_code const& e, std::size_t bytes_
|
||||||
if (m_tunnel_packets && m_v4_ep == m_proxy_addr)
|
if (m_tunnel_packets && m_v4_ep == m_proxy_addr)
|
||||||
unwrap(e, m_v4_buf, bytes_transferred);
|
unwrap(e, m_v4_buf, bytes_transferred);
|
||||||
else
|
else
|
||||||
get_io_service().post(boost::bind(m_callback, e, m_v4_ep, m_v4_buf, bytes_transferred));
|
m_callback(e, m_v4_ep, m_v4_buf, bytes_transferred);
|
||||||
|
|
||||||
#ifndef BOOST_NO_EXCEPTIONS
|
#ifndef BOOST_NO_EXCEPTIONS
|
||||||
} catch(std::exception&) {}
|
} catch(std::exception&) {}
|
||||||
|
@ -111,7 +140,7 @@ void udp_socket::on_read(udp::socket* s, error_code const& e, std::size_t bytes_
|
||||||
if (m_tunnel_packets && m_v6_ep == m_proxy_addr)
|
if (m_tunnel_packets && m_v6_ep == m_proxy_addr)
|
||||||
unwrap(e, m_v6_buf, bytes_transferred);
|
unwrap(e, m_v6_buf, bytes_transferred);
|
||||||
else
|
else
|
||||||
get_io_service().post(boost::bind(m_callback, e, m_v6_ep, m_v6_buf, bytes_transferred));
|
m_callback(e, m_v6_ep, m_v6_buf, bytes_transferred);
|
||||||
|
|
||||||
#ifndef BOOST_NO_EXCEPTIONS
|
#ifndef BOOST_NO_EXCEPTIONS
|
||||||
} catch(std::exception&) {}
|
} catch(std::exception&) {}
|
||||||
|
@ -119,10 +148,12 @@ void udp_socket::on_read(udp::socket* s, error_code const& e, std::size_t bytes_
|
||||||
s->async_receive_from(asio::buffer(m_v6_buf, sizeof(m_v6_buf))
|
s->async_receive_from(asio::buffer(m_v6_buf, sizeof(m_v6_buf))
|
||||||
, m_v6_ep, boost::bind(&udp_socket::on_read, this, s, _1, _2));
|
, m_v6_ep, boost::bind(&udp_socket::on_read, this, s, _1, _2));
|
||||||
}
|
}
|
||||||
|
++m_outstanding;
|
||||||
}
|
}
|
||||||
|
|
||||||
void udp_socket::wrap(udp::endpoint const& ep, char const* p, int len, error_code& ec)
|
void udp_socket::wrap(udp::endpoint const& ep, char const* p, int len, error_code& ec)
|
||||||
{
|
{
|
||||||
|
CHECK_MAGIC;
|
||||||
using namespace libtorrent::detail;
|
using namespace libtorrent::detail;
|
||||||
|
|
||||||
char header[20];
|
char header[20];
|
||||||
|
@ -147,6 +178,7 @@ void udp_socket::wrap(udp::endpoint const& ep, char const* p, int len, error_cod
|
||||||
// unwrap the UDP packet from the SOCKS5 header
|
// unwrap the UDP packet from the SOCKS5 header
|
||||||
void udp_socket::unwrap(error_code const& e, char const* buf, int size)
|
void udp_socket::unwrap(error_code const& e, char const* buf, int size)
|
||||||
{
|
{
|
||||||
|
CHECK_MAGIC;
|
||||||
using namespace libtorrent::detail;
|
using namespace libtorrent::detail;
|
||||||
|
|
||||||
// the minimum socks5 header size
|
// the minimum socks5 header size
|
||||||
|
@ -177,27 +209,34 @@ void udp_socket::unwrap(error_code const& e, char const* buf, int size)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
get_io_service().post(boost::bind(m_callback, e, sender, p, size - (p - buf)));
|
m_callback(e, sender, p, size - (p - buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
void udp_socket::close()
|
void udp_socket::close()
|
||||||
{
|
{
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
TORRENT_ASSERT(m_magic == 0x1337);
|
||||||
|
|
||||||
error_code ec;
|
error_code ec;
|
||||||
m_ipv4_sock.close(ec);
|
m_ipv4_sock.close(ec);
|
||||||
m_ipv6_sock.close(ec);
|
m_ipv6_sock.close(ec);
|
||||||
m_socks5_sock.close(ec);
|
m_socks5_sock.close(ec);
|
||||||
m_callback.clear();
|
|
||||||
if (m_connection_ticket >= 0)
|
if (m_connection_ticket >= 0)
|
||||||
{
|
{
|
||||||
m_cc.done(m_connection_ticket);
|
m_cc.done(m_connection_ticket);
|
||||||
m_connection_ticket = -1;
|
m_connection_ticket = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_outstanding == 0)
|
||||||
|
{
|
||||||
|
// "this" may be destructed in the callback
|
||||||
|
callback_t tmp = m_callback;
|
||||||
|
m_callback.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void udp_socket::bind(udp::endpoint const& ep, error_code& ec)
|
void udp_socket::bind(udp::endpoint const& ep, error_code& ec)
|
||||||
{
|
{
|
||||||
|
CHECK_MAGIC;
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
||||||
if (m_ipv4_sock.is_open()) m_ipv4_sock.close(ec);
|
if (m_ipv4_sock.is_open()) m_ipv4_sock.close(ec);
|
||||||
|
@ -221,11 +260,13 @@ void udp_socket::bind(udp::endpoint const& ep, error_code& ec)
|
||||||
m_ipv6_sock.async_receive_from(asio::buffer(m_v6_buf, sizeof(m_v6_buf))
|
m_ipv6_sock.async_receive_from(asio::buffer(m_v6_buf, sizeof(m_v6_buf))
|
||||||
, m_v6_ep, boost::bind(&udp_socket::on_read, this, &m_ipv6_sock, _1, _2));
|
, m_v6_ep, boost::bind(&udp_socket::on_read, this, &m_ipv6_sock, _1, _2));
|
||||||
}
|
}
|
||||||
|
++m_outstanding;
|
||||||
m_bind_port = ep.port();
|
m_bind_port = ep.port();
|
||||||
}
|
}
|
||||||
|
|
||||||
void udp_socket::bind(int port)
|
void udp_socket::bind(int port)
|
||||||
{
|
{
|
||||||
|
CHECK_MAGIC;
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
||||||
error_code ec;
|
error_code ec;
|
||||||
|
@ -239,6 +280,7 @@ void udp_socket::bind(int port)
|
||||||
m_ipv4_sock.bind(udp::endpoint(address_v4::any(), port), ec);
|
m_ipv4_sock.bind(udp::endpoint(address_v4::any(), port), ec);
|
||||||
m_ipv4_sock.async_receive_from(asio::buffer(m_v4_buf, sizeof(m_v4_buf))
|
m_ipv4_sock.async_receive_from(asio::buffer(m_v4_buf, sizeof(m_v4_buf))
|
||||||
, m_v4_ep, boost::bind(&udp_socket::on_read, this, &m_ipv4_sock, _1, _2));
|
, m_v4_ep, boost::bind(&udp_socket::on_read, this, &m_ipv4_sock, _1, _2));
|
||||||
|
++m_outstanding;
|
||||||
}
|
}
|
||||||
m_ipv6_sock.open(udp::v6(), ec);
|
m_ipv6_sock.open(udp::v6(), ec);
|
||||||
if (!ec)
|
if (!ec)
|
||||||
|
@ -247,12 +289,14 @@ void udp_socket::bind(int port)
|
||||||
m_ipv6_sock.bind(udp::endpoint(address_v6::any(), port), ec);
|
m_ipv6_sock.bind(udp::endpoint(address_v6::any(), port), ec);
|
||||||
m_ipv6_sock.async_receive_from(asio::buffer(m_v6_buf, sizeof(m_v6_buf))
|
m_ipv6_sock.async_receive_from(asio::buffer(m_v6_buf, sizeof(m_v6_buf))
|
||||||
, m_v6_ep, boost::bind(&udp_socket::on_read, this, &m_ipv6_sock, _1, _2));
|
, m_v6_ep, boost::bind(&udp_socket::on_read, this, &m_ipv6_sock, _1, _2));
|
||||||
|
++m_outstanding;
|
||||||
}
|
}
|
||||||
m_bind_port = port;
|
m_bind_port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
void udp_socket::set_proxy_settings(proxy_settings const& ps)
|
void udp_socket::set_proxy_settings(proxy_settings const& ps)
|
||||||
{
|
{
|
||||||
|
CHECK_MAGIC;
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
||||||
error_code ec;
|
error_code ec;
|
||||||
|
@ -275,6 +319,7 @@ void udp_socket::set_proxy_settings(proxy_settings const& ps)
|
||||||
void udp_socket::on_name_lookup(error_code const& e, tcp::resolver::iterator i)
|
void udp_socket::on_name_lookup(error_code const& e, tcp::resolver::iterator i)
|
||||||
{
|
{
|
||||||
if (e) return;
|
if (e) return;
|
||||||
|
CHECK_MAGIC;
|
||||||
|
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
||||||
|
@ -286,6 +331,7 @@ void udp_socket::on_name_lookup(error_code const& e, tcp::resolver::iterator i)
|
||||||
|
|
||||||
void udp_socket::on_timeout()
|
void udp_socket::on_timeout()
|
||||||
{
|
{
|
||||||
|
CHECK_MAGIC;
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
||||||
error_code ec;
|
error_code ec;
|
||||||
|
@ -295,6 +341,7 @@ void udp_socket::on_timeout()
|
||||||
|
|
||||||
void udp_socket::on_connect(int ticket)
|
void udp_socket::on_connect(int ticket)
|
||||||
{
|
{
|
||||||
|
CHECK_MAGIC;
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
||||||
m_connection_ticket = ticket;
|
m_connection_ticket = ticket;
|
||||||
|
@ -306,12 +353,13 @@ void udp_socket::on_connect(int ticket)
|
||||||
|
|
||||||
void udp_socket::on_connected(error_code const& e)
|
void udp_socket::on_connected(error_code const& e)
|
||||||
{
|
{
|
||||||
|
CHECK_MAGIC;
|
||||||
|
|
||||||
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
m_cc.done(m_connection_ticket);
|
m_cc.done(m_connection_ticket);
|
||||||
m_connection_ticket = -1;
|
m_connection_ticket = -1;
|
||||||
if (e) return;
|
if (e) return;
|
||||||
|
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
|
||||||
|
|
||||||
using namespace libtorrent::detail;
|
using namespace libtorrent::detail;
|
||||||
|
|
||||||
// send SOCKS5 authentication methods
|
// send SOCKS5 authentication methods
|
||||||
|
@ -335,6 +383,7 @@ void udp_socket::on_connected(error_code const& e)
|
||||||
|
|
||||||
void udp_socket::handshake1(error_code const& e)
|
void udp_socket::handshake1(error_code const& e)
|
||||||
{
|
{
|
||||||
|
CHECK_MAGIC;
|
||||||
if (e) return;
|
if (e) return;
|
||||||
|
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
@ -345,6 +394,7 @@ void udp_socket::handshake1(error_code const& e)
|
||||||
|
|
||||||
void udp_socket::handshake2(error_code const& e)
|
void udp_socket::handshake2(error_code const& e)
|
||||||
{
|
{
|
||||||
|
CHECK_MAGIC;
|
||||||
if (e) return;
|
if (e) return;
|
||||||
|
|
||||||
using namespace libtorrent::detail;
|
using namespace libtorrent::detail;
|
||||||
|
@ -390,6 +440,7 @@ void udp_socket::handshake2(error_code const& e)
|
||||||
|
|
||||||
void udp_socket::handshake3(error_code const& e)
|
void udp_socket::handshake3(error_code const& e)
|
||||||
{
|
{
|
||||||
|
CHECK_MAGIC;
|
||||||
if (e) return;
|
if (e) return;
|
||||||
|
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
@ -400,6 +451,7 @@ void udp_socket::handshake3(error_code const& e)
|
||||||
|
|
||||||
void udp_socket::handshake4(error_code const& e)
|
void udp_socket::handshake4(error_code const& e)
|
||||||
{
|
{
|
||||||
|
CHECK_MAGIC;
|
||||||
if (e) return;
|
if (e) return;
|
||||||
|
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
@ -418,6 +470,7 @@ void udp_socket::handshake4(error_code const& e)
|
||||||
|
|
||||||
void udp_socket::socks_forward_udp()
|
void udp_socket::socks_forward_udp()
|
||||||
{
|
{
|
||||||
|
CHECK_MAGIC;
|
||||||
using namespace libtorrent::detail;
|
using namespace libtorrent::detail;
|
||||||
|
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
@ -437,6 +490,7 @@ void udp_socket::socks_forward_udp()
|
||||||
|
|
||||||
void udp_socket::connect1(error_code const& e)
|
void udp_socket::connect1(error_code const& e)
|
||||||
{
|
{
|
||||||
|
CHECK_MAGIC;
|
||||||
if (e) return;
|
if (e) return;
|
||||||
|
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
@ -447,6 +501,7 @@ void udp_socket::connect1(error_code const& e)
|
||||||
|
|
||||||
void udp_socket::connect2(error_code const& e)
|
void udp_socket::connect2(error_code const& e)
|
||||||
{
|
{
|
||||||
|
CHECK_MAGIC;
|
||||||
if (e) return;
|
if (e) return;
|
||||||
|
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue