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_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 stop();
|
||||
|
|
|
@ -161,7 +161,7 @@ class node_impl : boost::noncopyable
|
|||
typedef std::map<node_id, torrent_entry> table_t;
|
||||
public:
|
||||
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() {}
|
||||
|
||||
|
@ -186,7 +186,6 @@ public:
|
|||
|
||||
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; }
|
||||
|
||||
boost::tuple<int, int> size() const{ return m_table.size(); }
|
||||
|
|
|
@ -88,6 +88,9 @@ namespace libtorrent
|
|||
l.unlock();
|
||||
|
||||
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
|
||||
|
|
|
@ -127,10 +127,20 @@ namespace libtorrent { namespace dht
|
|||
TORRENT_DEFINE_LOG(dht_tracker)
|
||||
#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
|
||||
// unit and connecting them together.
|
||||
dht_tracker::dht_tracker(udp_socket& sock, dht_settings const& settings)
|
||||
: m_dht(bind(&dht_tracker::send_packet, this, _1), settings)
|
||||
dht_tracker::dht_tracker(udp_socket& sock, dht_settings const& settings
|
||||
, entry const* state)
|
||||
: m_dht(bind(&dht_tracker::send_packet, this, _1), settings, extract_node_id(state))
|
||||
, m_sock(sock)
|
||||
, m_last_new_key(time_now() - minutes(key_refresh))
|
||||
, m_timer(sock.get_io_service())
|
||||
|
@ -183,12 +193,6 @@ namespace libtorrent { namespace dht
|
|||
if (entry const* nodes = bootstrap.find_key("nodes"))
|
||||
read_endpoint_list<udp::endpoint>(nodes, initial_nodes);
|
||||
} 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;
|
||||
|
|
|
@ -139,7 +139,6 @@ void find_data::initiate(
|
|||
, done_callback const& callback
|
||||
)
|
||||
{
|
||||
std::cerr << "find_data::initiate, key: " << target << "\n";
|
||||
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() {}
|
||||
|
||||
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_id(generate_id())
|
||||
, m_id(nid ? *nid : generate_id())
|
||||
, m_table(m_id, 8, settings)
|
||||
, m_rpc(bind(&node_impl::incoming_request, this, _1)
|
||||
, m_id, m_table, f)
|
||||
|
|
|
@ -37,12 +37,9 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
namespace
|
||||
{
|
||||
enum
|
||||
{
|
||||
lazy_entry_grow_factor = 3,
|
||||
lazy_entry_dict_init = 30,
|
||||
lazy_entry_list_init = 50
|
||||
};
|
||||
const float lazy_entry_grow_factor = 1.5f;
|
||||
const int lazy_entry_dict_init = 5;
|
||||
const int lazy_entry_list_init = 5;
|
||||
}
|
||||
|
||||
namespace libtorrent
|
||||
|
|
|
@ -60,11 +60,13 @@ namespace libtorrent
|
|||
address guess_local_address(io_service&);
|
||||
}
|
||||
|
||||
static error_code ec;
|
||||
|
||||
lsd::lsd(io_service& ios, address const& listen_interface
|
||||
, peer_callback_t const& cb)
|
||||
: m_callback(cb)
|
||||
, 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))
|
||||
, m_broadcast_timer(ios)
|
||||
, m_disabled(false)
|
||||
|
|
|
@ -2920,8 +2920,7 @@ namespace libtorrent
|
|||
// 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
|
||||
// torrent for it
|
||||
const int block_size = m_request_large_blocks
|
||||
? t->torrent_file().piece_length() : t->block_size();
|
||||
const int block_size = t->block_size();
|
||||
TORRENT_ASSERT(block_size > 0);
|
||||
|
||||
if (m_snubbed)
|
||||
|
|
|
@ -157,7 +157,6 @@ namespace aux {
|
|||
#endif
|
||||
, m_tracker_manager(m_settings, m_tracker_proxy)
|
||||
, 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_paused(false)
|
||||
, m_max_uploads(8)
|
||||
|
@ -189,6 +188,10 @@ namespace aux {
|
|||
, m_total_failed_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[1] = -1;
|
||||
m_udp_mapping[0] = -1;
|
||||
|
@ -268,7 +271,6 @@ namespace aux {
|
|||
*i = printable[rand() % (sizeof(printable)-1)];
|
||||
}
|
||||
|
||||
error_code ec;
|
||||
m_timer.expires_from_now(seconds(1), ec);
|
||||
m_timer.async_wait(
|
||||
bind(&session_impl::second_tick, this, _1));
|
||||
|
@ -1611,23 +1613,17 @@ namespace aux {
|
|||
|
||||
do
|
||||
{
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
try
|
||||
{
|
||||
#endif
|
||||
m_io_service.run();
|
||||
error_code ec;
|
||||
m_io_service.run(ec);
|
||||
TORRENT_ASSERT(m_abort == true);
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
}
|
||||
catch (std::exception& e)
|
||||
if (ec)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
std::cerr << e.what() << "\n";
|
||||
std::string err = e.what();
|
||||
std::cerr << ec.message() << "\n";
|
||||
std::string err = ec.message();
|
||||
#endif
|
||||
TORRENT_ASSERT(false);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
while (!m_abort);
|
||||
|
||||
|
@ -1875,7 +1871,18 @@ namespace aux {
|
|||
|
||||
tcp::endpoint new_interface;
|
||||
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
|
||||
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 = 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)
|
||||
{
|
||||
m_dht_socket.bind(m_dht_settings.service_port);
|
||||
|
|
|
@ -550,7 +550,9 @@ namespace libtorrent
|
|||
std::string ip = e->dict_find_string_value("ip");
|
||||
int port = e->dict_find_int_value("port");
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -567,7 +569,9 @@ namespace libtorrent
|
|||
std::string ip = e->dict_find_string_value("ip");
|
||||
int port = e->dict_find_int_value("port");
|
||||
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);
|
||||
if (p) p->banned = true;
|
||||
}
|
||||
|
@ -769,7 +773,10 @@ namespace libtorrent
|
|||
{
|
||||
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
|
||||
|
|
|
@ -59,6 +59,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
using boost::bind;
|
||||
using namespace libtorrent;
|
||||
|
||||
static error_code ec;
|
||||
|
||||
upnp::upnp(io_service& ios, connection_queue& cc
|
||||
, address const& listen_interface, std::string const& user_agent
|
||||
, 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_retry_count(0)
|
||||
, 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)
|
||||
, m_broadcast_timer(ios)
|
||||
, m_refresh_timer(ios)
|
||||
|
@ -904,9 +906,6 @@ void upnp::on_upnp_xml(error_code const& e
|
|||
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;
|
||||
else d.control_url = s.url_base + s.control_url;
|
||||
|
||||
std::string protocol;
|
||||
std::string auth;
|
||||
char const* error;
|
||||
|
|
Loading…
Reference in New Issue