lt sync 2926
This commit is contained in:
parent
5150d38f9c
commit
2ed7b5b747
|
@ -71,7 +71,8 @@ namespace libtorrent { namespace dht
|
||||||
{
|
{
|
||||||
friend void intrusive_ptr_add_ref(dht_tracker const*);
|
friend void intrusive_ptr_add_ref(dht_tracker const*);
|
||||||
friend void intrusive_ptr_release(dht_tracker const*);
|
friend void intrusive_ptr_release(dht_tracker const*);
|
||||||
dht_tracker(udp_socket& sock, dht_settings const& settings);
|
dht_tracker(udp_socket& sock, dht_settings const& settings
|
||||||
|
, entry const* state);
|
||||||
|
|
||||||
void start(entry const& bootstrap);
|
void start(entry const& bootstrap);
|
||||||
void stop();
|
void stop();
|
||||||
|
|
|
@ -161,7 +161,7 @@ class node_impl : boost::noncopyable
|
||||||
typedef std::map<node_id, torrent_entry> table_t;
|
typedef std::map<node_id, torrent_entry> table_t;
|
||||||
public:
|
public:
|
||||||
node_impl(boost::function<void(msg const&)> const& f
|
node_impl(boost::function<void(msg const&)> const& f
|
||||||
, dht_settings const& settings);
|
, dht_settings const& settings, boost::optional<node_id> nid);
|
||||||
|
|
||||||
virtual ~node_impl() {}
|
virtual ~node_impl() {}
|
||||||
|
|
||||||
|
@ -186,7 +186,6 @@ public:
|
||||||
|
|
||||||
typedef table_t::iterator data_iterator;
|
typedef table_t::iterator data_iterator;
|
||||||
|
|
||||||
void set_node_id(node_id const& nid) { m_id = nid; }
|
|
||||||
node_id const& nid() const { return m_id; }
|
node_id const& nid() const { return m_id; }
|
||||||
|
|
||||||
boost::tuple<int, int> size() const{ return m_table.size(); }
|
boost::tuple<int, int> size() const{ return m_table.size(); }
|
||||||
|
|
|
@ -73,9 +73,9 @@ namespace libtorrent
|
||||||
// uses username and password
|
// uses username and password
|
||||||
http_pw
|
http_pw
|
||||||
};
|
};
|
||||||
|
|
||||||
proxy_type type;
|
proxy_type type;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TORRENT_EXPORT session_settings
|
struct TORRENT_EXPORT session_settings
|
||||||
|
@ -153,7 +153,7 @@ namespace libtorrent
|
||||||
// the number of seconds to wait until giving up on a
|
// the number of seconds to wait until giving up on a
|
||||||
// tracker request if it hasn't finished
|
// tracker request if it hasn't finished
|
||||||
int tracker_completion_timeout;
|
int tracker_completion_timeout;
|
||||||
|
|
||||||
// the number of seconds where no data is received
|
// the number of seconds where no data is received
|
||||||
// from the tracker until it should be considered
|
// from the tracker until it should be considered
|
||||||
// as timed out
|
// as timed out
|
||||||
|
@ -183,7 +183,7 @@ namespace libtorrent
|
||||||
// all the pieces. i.e. the actual number of requests
|
// all the pieces. i.e. the actual number of requests
|
||||||
// depends on the download rate and this number.
|
// depends on the download rate and this number.
|
||||||
float request_queue_time;
|
float request_queue_time;
|
||||||
|
|
||||||
// the number of outstanding block requests a peer is
|
// the number of outstanding block requests a peer is
|
||||||
// allowed to queue up in the client. If a peer sends
|
// allowed to queue up in the client. If a peer sends
|
||||||
// more requests than this (before the first one has
|
// more requests than this (before the first one has
|
||||||
|
@ -191,7 +191,7 @@ namespace libtorrent
|
||||||
// the higher this is, the faster upload speeds the
|
// the higher this is, the faster upload speeds the
|
||||||
// client can get to a single peer.
|
// client can get to a single peer.
|
||||||
int max_allowed_in_request_queue;
|
int max_allowed_in_request_queue;
|
||||||
|
|
||||||
// the maximum number of outstanding requests to
|
// the maximum number of outstanding requests to
|
||||||
// send to a peer. This limit takes precedence over
|
// send to a peer. This limit takes precedence over
|
||||||
// request_queue_time.
|
// request_queue_time.
|
||||||
|
@ -204,23 +204,23 @@ namespace libtorrent
|
||||||
// doing localized accesses and also to make it easier
|
// doing localized accesses and also to make it easier
|
||||||
// to identify bad peers if a piece fails the hash check.
|
// to identify bad peers if a piece fails the hash check.
|
||||||
int whole_pieces_threshold;
|
int whole_pieces_threshold;
|
||||||
|
|
||||||
// the number of seconds to wait for any activity on
|
// the number of seconds to wait for any activity on
|
||||||
// the peer wire before closing the connectiong due
|
// the peer wire before closing the connectiong due
|
||||||
// to time out.
|
// to time out.
|
||||||
int peer_timeout;
|
int peer_timeout;
|
||||||
|
|
||||||
// same as peer_timeout, but only applies to url-seeds.
|
// same as peer_timeout, but only applies to url-seeds.
|
||||||
// this is usually set lower, because web servers are
|
// this is usually set lower, because web servers are
|
||||||
// expected to be more reliable.
|
// expected to be more reliable.
|
||||||
int urlseed_timeout;
|
int urlseed_timeout;
|
||||||
|
|
||||||
// controls the pipelining size of url-seeds
|
// controls the pipelining size of url-seeds
|
||||||
int urlseed_pipeline_size;
|
int urlseed_pipeline_size;
|
||||||
|
|
||||||
// time to wait until a new retry takes place
|
// time to wait until a new retry takes place
|
||||||
int urlseed_wait_retry;
|
int urlseed_wait_retry;
|
||||||
|
|
||||||
// sets the upper limit on the total number of files this
|
// sets the upper limit on the total number of files this
|
||||||
// session will keep open. The reason why files are
|
// session will keep open. The reason why files are
|
||||||
// left open at all is that some anti virus software
|
// left open at all is that some anti virus software
|
||||||
|
@ -234,7 +234,7 @@ namespace libtorrent
|
||||||
// number of connections and the number of files
|
// number of connections and the number of files
|
||||||
// limits so their sum is slightly below it.
|
// limits so their sum is slightly below it.
|
||||||
int file_pool_size;
|
int file_pool_size;
|
||||||
|
|
||||||
// false to not allow multiple connections from the same
|
// false to not allow multiple connections from the same
|
||||||
// IP address. true will allow it.
|
// IP address. true will allow it.
|
||||||
bool allow_multiple_connections_per_ip;
|
bool allow_multiple_connections_per_ip;
|
||||||
|
@ -242,7 +242,7 @@ namespace libtorrent
|
||||||
// the number of times we can fail to connect to a peer
|
// the number of times we can fail to connect to a peer
|
||||||
// before we stop retrying it.
|
// before we stop retrying it.
|
||||||
int max_failcount;
|
int max_failcount;
|
||||||
|
|
||||||
// the number of seconds to wait to reconnect to a peer.
|
// the number of seconds to wait to reconnect to a peer.
|
||||||
// this time is multiplied with the failcount.
|
// this time is multiplied with the failcount.
|
||||||
int min_reconnect_time;
|
int min_reconnect_time;
|
||||||
|
@ -391,7 +391,7 @@ namespace libtorrent
|
||||||
// the number of seconds in between recalculating which
|
// the number of seconds in between recalculating which
|
||||||
// torrents to activate and which ones to queue
|
// torrents to activate and which ones to queue
|
||||||
int auto_manage_interval;
|
int auto_manage_interval;
|
||||||
|
|
||||||
// when a seeding torrent reaches eaither the share ratio
|
// when a seeding torrent reaches eaither the share ratio
|
||||||
// (bytes up / bytes down) or the seed time ratio
|
// (bytes up / bytes down) or the seed time ratio
|
||||||
// (seconds as seed / seconds as downloader) or the seed
|
// (seconds as seed / seconds as downloader) or the seed
|
||||||
|
@ -461,7 +461,7 @@ namespace libtorrent
|
||||||
, service_port(0)
|
, service_port(0)
|
||||||
, max_fail_count(20)
|
, max_fail_count(20)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
// the maximum number of peers to send in a
|
// the maximum number of peers to send in a
|
||||||
// reply to get_peers
|
// reply to get_peers
|
||||||
int max_peers_reply;
|
int max_peers_reply;
|
||||||
|
@ -469,11 +469,11 @@ namespace libtorrent
|
||||||
// the number of simultanous "connections" when
|
// the number of simultanous "connections" when
|
||||||
// searching the DHT.
|
// searching the DHT.
|
||||||
int search_branching;
|
int search_branching;
|
||||||
|
|
||||||
// the listen port for the dht. This is a UDP port.
|
// the listen port for the dht. This is a UDP port.
|
||||||
// zero means use the same as the tcp interface
|
// zero means use the same as the tcp interface
|
||||||
int service_port;
|
int service_port;
|
||||||
|
|
||||||
// the maximum number of times a node can fail
|
// the maximum number of times a node can fail
|
||||||
// in a row before it is removed from the table.
|
// in a row before it is removed from the table.
|
||||||
int max_fail_count;
|
int max_fail_count;
|
||||||
|
@ -501,7 +501,7 @@ namespace libtorrent
|
||||||
enum enc_level
|
enum enc_level
|
||||||
{
|
{
|
||||||
plaintext, // use only plaintext encryption
|
plaintext, // use only plaintext encryption
|
||||||
rc4, // use only rc4 encryption
|
rc4, // use only rc4 encryption
|
||||||
both // allow both
|
both // allow both
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -88,6 +88,9 @@ namespace libtorrent
|
||||||
l.unlock();
|
l.unlock();
|
||||||
|
|
||||||
m_disk_io_thread.join();
|
m_disk_io_thread.join();
|
||||||
|
l.lock();
|
||||||
|
TORRENT_ASSERT(m_abort == true);
|
||||||
|
m_jobs.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void disk_io_thread::get_cache_info(sha1_hash const& ih, std::vector<cached_piece_info>& ret) const
|
void disk_io_thread::get_cache_info(sha1_hash const& ih, std::vector<cached_piece_info>& ret) const
|
||||||
|
|
|
@ -127,10 +127,20 @@ namespace libtorrent { namespace dht
|
||||||
TORRENT_DEFINE_LOG(dht_tracker)
|
TORRENT_DEFINE_LOG(dht_tracker)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
boost::optional<node_id> extract_node_id(entry const* e)
|
||||||
|
{
|
||||||
|
if (e == 0 || e->type() != entry::dictionary_t) return boost::optional<node_id>();
|
||||||
|
entry const* nid = e->find_key("node-id");
|
||||||
|
if (nid == 0 || nid->type() != entry::string_t || nid->string().length() != 20)
|
||||||
|
return boost::optional<node_id>();
|
||||||
|
return boost::optional<node_id>(node_id(nid->string().c_str()));
|
||||||
|
}
|
||||||
|
|
||||||
// class that puts the networking and the kademlia node in a single
|
// class that puts the networking and the kademlia node in a single
|
||||||
// unit and connecting them together.
|
// unit and connecting them together.
|
||||||
dht_tracker::dht_tracker(udp_socket& sock, dht_settings const& settings)
|
dht_tracker::dht_tracker(udp_socket& sock, dht_settings const& settings
|
||||||
: m_dht(bind(&dht_tracker::send_packet, this, _1), settings)
|
, entry const* state)
|
||||||
|
: m_dht(bind(&dht_tracker::send_packet, this, _1), settings, extract_node_id(state))
|
||||||
, m_sock(sock)
|
, m_sock(sock)
|
||||||
, m_last_new_key(time_now() - minutes(key_refresh))
|
, m_last_new_key(time_now() - minutes(key_refresh))
|
||||||
, m_timer(sock.get_io_service())
|
, m_timer(sock.get_io_service())
|
||||||
|
@ -183,12 +193,6 @@ namespace libtorrent { namespace dht
|
||||||
if (entry const* nodes = bootstrap.find_key("nodes"))
|
if (entry const* nodes = bootstrap.find_key("nodes"))
|
||||||
read_endpoint_list<udp::endpoint>(nodes, initial_nodes);
|
read_endpoint_list<udp::endpoint>(nodes, initial_nodes);
|
||||||
} catch (std::exception&) {}
|
} catch (std::exception&) {}
|
||||||
|
|
||||||
entry const* nid = bootstrap.find_key("node-id");
|
|
||||||
if (nid
|
|
||||||
&& nid->type() == entry::string_t
|
|
||||||
&& nid->string().length() == 40)
|
|
||||||
m_dht.set_node_id(boost::lexical_cast<node_id>(nid->string()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
error_code ec;
|
error_code ec;
|
||||||
|
|
|
@ -139,7 +139,6 @@ void find_data::initiate(
|
||||||
, done_callback const& callback
|
, done_callback const& callback
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
std::cerr << "find_data::initiate, key: " << target << "\n";
|
|
||||||
new find_data(target, branch_factor, max_results, table, rpc, callback);
|
new find_data(target, branch_factor, max_results, table, rpc, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,9 +91,10 @@ void purge_peers(std::set<peer_entry>& peers)
|
||||||
void nop() {}
|
void nop() {}
|
||||||
|
|
||||||
node_impl::node_impl(boost::function<void(msg const&)> const& f
|
node_impl::node_impl(boost::function<void(msg const&)> const& f
|
||||||
, dht_settings const& settings)
|
, dht_settings const& settings
|
||||||
|
, boost::optional<node_id> nid)
|
||||||
: m_settings(settings)
|
: m_settings(settings)
|
||||||
, m_id(generate_id())
|
, m_id(nid ? *nid : generate_id())
|
||||||
, m_table(m_id, 8, settings)
|
, m_table(m_id, 8, settings)
|
||||||
, m_rpc(bind(&node_impl::incoming_request, this, _1)
|
, m_rpc(bind(&node_impl::incoming_request, this, _1)
|
||||||
, m_id, m_table, f)
|
, m_id, m_table, f)
|
||||||
|
|
|
@ -37,12 +37,9 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
enum
|
const float lazy_entry_grow_factor = 1.5f;
|
||||||
{
|
const int lazy_entry_dict_init = 5;
|
||||||
lazy_entry_grow_factor = 3,
|
const int lazy_entry_list_init = 5;
|
||||||
lazy_entry_dict_init = 30,
|
|
||||||
lazy_entry_list_init = 50
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace libtorrent
|
namespace libtorrent
|
||||||
|
|
|
@ -60,11 +60,13 @@ namespace libtorrent
|
||||||
address guess_local_address(io_service&);
|
address guess_local_address(io_service&);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static error_code ec;
|
||||||
|
|
||||||
lsd::lsd(io_service& ios, address const& listen_interface
|
lsd::lsd(io_service& ios, address const& listen_interface
|
||||||
, peer_callback_t const& cb)
|
, peer_callback_t const& cb)
|
||||||
: m_callback(cb)
|
: m_callback(cb)
|
||||||
, m_retry_count(1)
|
, m_retry_count(1)
|
||||||
, m_socket(ios, udp::endpoint(address_v4::from_string("239.192.152.143"), 6771)
|
, m_socket(ios, udp::endpoint(address_v4::from_string("239.192.152.143", ec), 6771)
|
||||||
, bind(&lsd::on_announce, self(), _1, _2, _3))
|
, bind(&lsd::on_announce, self(), _1, _2, _3))
|
||||||
, m_broadcast_timer(ios)
|
, m_broadcast_timer(ios)
|
||||||
, m_disabled(false)
|
, m_disabled(false)
|
||||||
|
|
|
@ -2920,8 +2920,7 @@ namespace libtorrent
|
||||||
// the minimum number of requests is 2 and the maximum is 48
|
// the minimum number of requests is 2 and the maximum is 48
|
||||||
// the block size doesn't have to be 16. So we first query the
|
// the block size doesn't have to be 16. So we first query the
|
||||||
// torrent for it
|
// torrent for it
|
||||||
const int block_size = m_request_large_blocks
|
const int block_size = t->block_size();
|
||||||
? t->torrent_file().piece_length() : t->block_size();
|
|
||||||
TORRENT_ASSERT(block_size > 0);
|
TORRENT_ASSERT(block_size > 0);
|
||||||
|
|
||||||
if (m_snubbed)
|
if (m_snubbed)
|
||||||
|
|
|
@ -157,7 +157,6 @@ namespace aux {
|
||||||
#endif
|
#endif
|
||||||
, m_tracker_manager(m_settings, m_tracker_proxy)
|
, m_tracker_manager(m_settings, m_tracker_proxy)
|
||||||
, m_listen_port_retries(listen_port_range.second - listen_port_range.first)
|
, m_listen_port_retries(listen_port_range.second - listen_port_range.first)
|
||||||
, m_listen_interface(address::from_string(listen_interface), listen_port_range.first)
|
|
||||||
, m_abort(false)
|
, m_abort(false)
|
||||||
, m_paused(false)
|
, m_paused(false)
|
||||||
, m_max_uploads(8)
|
, m_max_uploads(8)
|
||||||
|
@ -189,6 +188,10 @@ namespace aux {
|
||||||
, m_total_failed_bytes(0)
|
, m_total_failed_bytes(0)
|
||||||
, m_total_redundant_bytes(0)
|
, m_total_redundant_bytes(0)
|
||||||
{
|
{
|
||||||
|
error_code ec;
|
||||||
|
m_listen_interface = tcp::endpoint(address::from_string(listen_interface, ec), listen_port_range.first);
|
||||||
|
TORRENT_ASSERT(!ec);
|
||||||
|
|
||||||
m_tcp_mapping[0] = -1;
|
m_tcp_mapping[0] = -1;
|
||||||
m_tcp_mapping[1] = -1;
|
m_tcp_mapping[1] = -1;
|
||||||
m_udp_mapping[0] = -1;
|
m_udp_mapping[0] = -1;
|
||||||
|
@ -268,7 +271,6 @@ namespace aux {
|
||||||
*i = printable[rand() % (sizeof(printable)-1)];
|
*i = printable[rand() % (sizeof(printable)-1)];
|
||||||
}
|
}
|
||||||
|
|
||||||
error_code ec;
|
|
||||||
m_timer.expires_from_now(seconds(1), ec);
|
m_timer.expires_from_now(seconds(1), ec);
|
||||||
m_timer.async_wait(
|
m_timer.async_wait(
|
||||||
bind(&session_impl::second_tick, this, _1));
|
bind(&session_impl::second_tick, this, _1));
|
||||||
|
@ -1611,23 +1613,17 @@ namespace aux {
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
#ifndef BOOST_NO_EXCEPTIONS
|
error_code ec;
|
||||||
try
|
m_io_service.run(ec);
|
||||||
{
|
TORRENT_ASSERT(m_abort == true);
|
||||||
#endif
|
if (ec)
|
||||||
m_io_service.run();
|
|
||||||
TORRENT_ASSERT(m_abort == true);
|
|
||||||
#ifndef BOOST_NO_EXCEPTIONS
|
|
||||||
}
|
|
||||||
catch (std::exception& e)
|
|
||||||
{
|
{
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
std::cerr << e.what() << "\n";
|
std::cerr << ec.message() << "\n";
|
||||||
std::string err = e.what();
|
std::string err = ec.message();
|
||||||
#endif
|
#endif
|
||||||
TORRENT_ASSERT(false);
|
TORRENT_ASSERT(false);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
while (!m_abort);
|
while (!m_abort);
|
||||||
|
|
||||||
|
@ -1875,7 +1871,18 @@ namespace aux {
|
||||||
|
|
||||||
tcp::endpoint new_interface;
|
tcp::endpoint new_interface;
|
||||||
if (net_interface && std::strlen(net_interface) > 0)
|
if (net_interface && std::strlen(net_interface) > 0)
|
||||||
new_interface = tcp::endpoint(address::from_string(net_interface), port_range.first);
|
{
|
||||||
|
error_code ec;
|
||||||
|
new_interface = tcp::endpoint(address::from_string(net_interface, ec), port_range.first);
|
||||||
|
if (ec)
|
||||||
|
{
|
||||||
|
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||||
|
(*m_logger) << time_now_string() << "listen_on: " << net_interface
|
||||||
|
<< " failed: " << ec.message() << "\n";
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
new_interface = tcp::endpoint(address_v4::any(), port_range.first);
|
new_interface = tcp::endpoint(address_v4::any(), port_range.first);
|
||||||
|
|
||||||
|
@ -2083,7 +2090,7 @@ namespace aux {
|
||||||
, m_dht_settings.service_port
|
, m_dht_settings.service_port
|
||||||
, m_dht_settings.service_port);
|
, m_dht_settings.service_port);
|
||||||
}
|
}
|
||||||
m_dht = new dht::dht_tracker(m_dht_socket, m_dht_settings);
|
m_dht = new dht::dht_tracker(m_dht_socket, m_dht_settings, &startup_state);
|
||||||
if (!m_dht_socket.is_open() || m_dht_socket.local_port() != m_dht_settings.service_port)
|
if (!m_dht_socket.is_open() || m_dht_socket.local_port() != m_dht_settings.service_port)
|
||||||
{
|
{
|
||||||
m_dht_socket.bind(m_dht_settings.service_port);
|
m_dht_socket.bind(m_dht_settings.service_port);
|
||||||
|
|
|
@ -550,7 +550,9 @@ namespace libtorrent
|
||||||
std::string ip = e->dict_find_string_value("ip");
|
std::string ip = e->dict_find_string_value("ip");
|
||||||
int port = e->dict_find_int_value("port");
|
int port = e->dict_find_int_value("port");
|
||||||
if (ip.empty() || port == 0) continue;
|
if (ip.empty() || port == 0) continue;
|
||||||
tcp::endpoint a(address::from_string(ip), (unsigned short)port);
|
error_code ec;
|
||||||
|
tcp::endpoint a(address::from_string(ip, ec), (unsigned short)port);
|
||||||
|
if (ec) continue;
|
||||||
m_policy.peer_from_tracker(a, id, peer_info::resume_data, 0);
|
m_policy.peer_from_tracker(a, id, peer_info::resume_data, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -567,7 +569,9 @@ namespace libtorrent
|
||||||
std::string ip = e->dict_find_string_value("ip");
|
std::string ip = e->dict_find_string_value("ip");
|
||||||
int port = e->dict_find_int_value("port");
|
int port = e->dict_find_int_value("port");
|
||||||
if (ip.empty() || port == 0) continue;
|
if (ip.empty() || port == 0) continue;
|
||||||
tcp::endpoint a(address::from_string(ip), (unsigned short)port);
|
error_code ec;
|
||||||
|
tcp::endpoint a(address::from_string(ip, ec), (unsigned short)port);
|
||||||
|
if (ec) continue;
|
||||||
policy::peer* p = m_policy.peer_from_tracker(a, id, peer_info::resume_data, 0);
|
policy::peer* p = m_policy.peer_from_tracker(a, id, peer_info::resume_data, 0);
|
||||||
if (p) p->banned = true;
|
if (p) p->banned = true;
|
||||||
}
|
}
|
||||||
|
@ -769,7 +773,10 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
m_net_interface = tcp::endpoint(address::from_string(net_interface), 0);
|
error_code ec;
|
||||||
|
address a(address::from_string(net_interface, ec));
|
||||||
|
if (ec) return;
|
||||||
|
m_net_interface = tcp::endpoint(a, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void torrent::on_tracker_announce_disp(boost::weak_ptr<torrent> p
|
void torrent::on_tracker_announce_disp(boost::weak_ptr<torrent> p
|
||||||
|
|
|
@ -59,6 +59,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
using boost::bind;
|
using boost::bind;
|
||||||
using namespace libtorrent;
|
using namespace libtorrent;
|
||||||
|
|
||||||
|
static error_code ec;
|
||||||
|
|
||||||
upnp::upnp(io_service& ios, connection_queue& cc
|
upnp::upnp(io_service& ios, connection_queue& cc
|
||||||
, address const& listen_interface, std::string const& user_agent
|
, address const& listen_interface, std::string const& user_agent
|
||||||
, portmap_callback_t const& cb, bool ignore_nonrouters, void* state)
|
, portmap_callback_t const& cb, bool ignore_nonrouters, void* state)
|
||||||
|
@ -66,7 +68,7 @@ upnp::upnp(io_service& ios, connection_queue& cc
|
||||||
, m_callback(cb)
|
, m_callback(cb)
|
||||||
, m_retry_count(0)
|
, m_retry_count(0)
|
||||||
, m_io_service(ios)
|
, m_io_service(ios)
|
||||||
, m_socket(ios, udp::endpoint(address_v4::from_string("239.255.255.250"), 1900)
|
, m_socket(ios, udp::endpoint(address_v4::from_string("239.255.255.250", ec), 1900)
|
||||||
, bind(&upnp::on_reply, self(), _1, _2, _3), false)
|
, bind(&upnp::on_reply, self(), _1, _2, _3), false)
|
||||||
, m_broadcast_timer(ios)
|
, m_broadcast_timer(ios)
|
||||||
, m_refresh_timer(ios)
|
, m_refresh_timer(ios)
|
||||||
|
@ -114,7 +116,7 @@ void upnp::discover_device()
|
||||||
|
|
||||||
void upnp::discover_device_impl()
|
void upnp::discover_device_impl()
|
||||||
{
|
{
|
||||||
const char msearch[] =
|
const char msearch[] =
|
||||||
"M-SEARCH * HTTP/1.1\r\n"
|
"M-SEARCH * HTTP/1.1\r\n"
|
||||||
"HOST: 239.255.255.250:1900\r\n"
|
"HOST: 239.255.255.250:1900\r\n"
|
||||||
"ST:upnp:rootdevice\r\n"
|
"ST:upnp:rootdevice\r\n"
|
||||||
|
@ -220,7 +222,7 @@ void upnp::delete_mapping(int mapping)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (m.protocol == none) return;
|
if (m.protocol == none) return;
|
||||||
|
|
||||||
for (std::set<rootdevice>::iterator i = m_devices.begin()
|
for (std::set<rootdevice>::iterator i = m_devices.begin()
|
||||||
, end(m_devices.end()); i != end; ++i)
|
, end(m_devices.end()); i != end; ++i)
|
||||||
{
|
{
|
||||||
|
@ -257,7 +259,7 @@ void upnp::resend_request(error_code const& e)
|
||||||
disable("no UPnP router found");
|
disable("no UPnP router found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::set<rootdevice>::iterator i = m_devices.begin()
|
for (std::set<rootdevice>::iterator i = m_devices.begin()
|
||||||
, end(m_devices.end()); i != end; ++i)
|
, end(m_devices.end()); i != end; ++i)
|
||||||
{
|
{
|
||||||
|
@ -349,7 +351,7 @@ void upnp::on_reply(udp::endpoint const& from, char* buffer
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<ip_route> routes = enum_routes(m_io_service, ec);
|
std::vector<ip_route> routes = enum_routes(m_io_service, ec);
|
||||||
if (m_ignore_non_routers && std::find_if(routes.begin(), routes.end()
|
if (m_ignore_non_routers && std::find_if(routes.begin(), routes.end()
|
||||||
|
@ -559,7 +561,7 @@ void upnp::post(upnp::rootdevice const& d, std::string const& soap
|
||||||
TORRENT_ASSERT(d.upnp_connection);
|
TORRENT_ASSERT(d.upnp_connection);
|
||||||
|
|
||||||
std::stringstream header;
|
std::stringstream header;
|
||||||
|
|
||||||
header << "POST " << d.path << " HTTP/1.0\r\n"
|
header << "POST " << d.path << " HTTP/1.0\r\n"
|
||||||
"Host: " << d.hostname << ":" << d.port << "\r\n"
|
"Host: " << d.hostname << ":" << d.port << "\r\n"
|
||||||
"Content-Type: text/xml; charset=\"utf-8\"\r\n"
|
"Content-Type: text/xml; charset=\"utf-8\"\r\n"
|
||||||
|
@ -572,7 +574,7 @@ void upnp::post(upnp::rootdevice const& d, std::string const& soap
|
||||||
m_log << time_now_string()
|
m_log << time_now_string()
|
||||||
<< " ==> sending: " << header.str() << std::endl;
|
<< " ==> sending: " << header.str() << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void upnp::create_port_mapping(http_connection& c, rootdevice& d, int i)
|
void upnp::create_port_mapping(http_connection& c, rootdevice& d, int i)
|
||||||
|
@ -590,11 +592,11 @@ void upnp::create_port_mapping(http_connection& c, rootdevice& d, int i)
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string soap_action = "AddPortMapping";
|
std::string soap_action = "AddPortMapping";
|
||||||
|
|
||||||
std::stringstream soap;
|
std::stringstream soap;
|
||||||
|
|
||||||
soap << "<?xml version=\"1.0\"?>\n"
|
soap << "<?xml version=\"1.0\"?>\n"
|
||||||
"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" "
|
"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" "
|
||||||
"s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
|
"s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
|
||||||
|
@ -709,7 +711,7 @@ void upnp::delete_port_mapping(rootdevice& d, int i)
|
||||||
}
|
}
|
||||||
|
|
||||||
std::stringstream soap;
|
std::stringstream soap;
|
||||||
|
|
||||||
std::string soap_action = "DeletePortMapping";
|
std::string soap_action = "DeletePortMapping";
|
||||||
|
|
||||||
soap << "<?xml version=\"1.0\"?>\n"
|
soap << "<?xml version=\"1.0\"?>\n"
|
||||||
|
@ -721,7 +723,7 @@ void upnp::delete_port_mapping(rootdevice& d, int i)
|
||||||
"<NewExternalPort>" << d.mapping[i].external_port << "</NewExternalPort>"
|
"<NewExternalPort>" << d.mapping[i].external_port << "</NewExternalPort>"
|
||||||
"<NewProtocol>" << (d.mapping[i].protocol == udp ? "UDP" : "TCP") << "</NewProtocol>";
|
"<NewProtocol>" << (d.mapping[i].protocol == udp ? "UDP" : "TCP") << "</NewProtocol>";
|
||||||
soap << "</u:" << soap_action << "></s:Body></s:Envelope>";
|
soap << "</u:" << soap_action << "></s:Body></s:Envelope>";
|
||||||
|
|
||||||
post(d, soap.str(), soap_action);
|
post(d, soap.str(), soap_action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -738,7 +740,7 @@ namespace
|
||||||
dst.clear();
|
dst.clear();
|
||||||
while (*src) dst.push_back(tolower(*src++));
|
while (*src) dst.push_back(tolower(*src++));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool string_equal_nocase(char const* lhs, char const* rhs)
|
bool string_equal_nocase(char const* lhs, char const* rhs)
|
||||||
{
|
{
|
||||||
while (tolower(*lhs) == tolower(*rhs))
|
while (tolower(*lhs) == tolower(*rhs))
|
||||||
|
@ -900,10 +902,7 @@ void upnp::on_upnp_xml(error_code const& e
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s.url_base.empty()) d.control_url = s.control_url;
|
|
||||||
else d.control_url = s.url_base + s.control_url;
|
|
||||||
|
|
||||||
if (s.url_base.empty()) d.control_url = s.control_url;
|
if (s.url_base.empty()) d.control_url = s.control_url;
|
||||||
else d.control_url = s.url_base + s.control_url;
|
else d.control_url = s.url_base + s.control_url;
|
||||||
|
|
||||||
|
@ -952,7 +951,7 @@ void upnp::disable(char const* msg)
|
||||||
i->protocol = none;
|
i->protocol = none;
|
||||||
m_callback(i - m_mappings.begin(), 0, msg);
|
m_callback(i - m_mappings.begin(), 0, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_devices.clear();
|
m_devices.clear();
|
||||||
error_code ec;
|
error_code ec;
|
||||||
m_broadcast_timer.cancel(ec);
|
m_broadcast_timer.cancel(ec);
|
||||||
|
@ -969,7 +968,7 @@ namespace
|
||||||
bool exit;
|
bool exit;
|
||||||
int error_code;
|
int error_code;
|
||||||
};
|
};
|
||||||
|
|
||||||
void find_error_code(int type, char const* string, error_code_parse_state& state)
|
void find_error_code(int type, char const* string, error_code_parse_state& state)
|
||||||
{
|
{
|
||||||
if (state.exit) return;
|
if (state.exit) return;
|
||||||
|
@ -992,7 +991,7 @@ namespace
|
||||||
int code;
|
int code;
|
||||||
char const* msg;
|
char const* msg;
|
||||||
};
|
};
|
||||||
|
|
||||||
error_code_t error_codes[] =
|
error_code_t error_codes[] =
|
||||||
{
|
{
|
||||||
{402, "Invalid Arguments"}
|
{402, "Invalid Arguments"}
|
||||||
|
@ -1034,9 +1033,9 @@ void upnp::on_upnp_map_response(error_code const& e
|
||||||
d.disabled = true;
|
d.disabled = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_closing) return;
|
if (m_closing) return;
|
||||||
|
|
||||||
// error code response may look like this:
|
// error code response may look like this:
|
||||||
// <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
|
// <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
|
||||||
// s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
|
// s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
|
||||||
|
@ -1078,7 +1077,7 @@ void upnp::on_upnp_map_response(error_code const& e
|
||||||
<< " <== got error message: " << s.error_code << std::endl;
|
<< " <== got error message: " << s.error_code << std::endl;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mapping_t& m = d.mapping[mapping];
|
mapping_t& m = d.mapping[mapping];
|
||||||
|
|
||||||
if (s.error_code == 725)
|
if (s.error_code == 725)
|
||||||
|
|
Loading…
Reference in New Issue