added catch blocks to lsd. changed bind expressions to use operators
This commit is contained in:
parent
9f1a11aa50
commit
f41fd7d303
|
@ -244,8 +244,7 @@ int peer_index(libtorrent::tcp::endpoint addr, std::vector<libtorrent::peer_info
|
||||||
{
|
{
|
||||||
using namespace libtorrent;
|
using namespace libtorrent;
|
||||||
std::vector<peer_info>::const_iterator i = std::find_if(peers.begin()
|
std::vector<peer_info>::const_iterator i = std::find_if(peers.begin()
|
||||||
, peers.end(), boost::bind(std::equal_to<libtorrent::tcp::endpoint>()
|
, peers.end(), bind(&peer_info::ip, _1) == addr);
|
||||||
, bind(&peer_info::ip, _1), addr));
|
|
||||||
if (i == peers.end()) return -1;
|
if (i == peers.end()) return -1;
|
||||||
|
|
||||||
return i - peers.begin();
|
return i - peers.begin();
|
||||||
|
|
|
@ -170,11 +170,11 @@ bool routing_table::need_node(node_id const& id)
|
||||||
if ((int)rb.size() >= m_bucket_size) return false;
|
if ((int)rb.size() >= m_bucket_size) return false;
|
||||||
|
|
||||||
// if the node already exists, we don't need it
|
// if the node already exists, we don't need it
|
||||||
if (std::find_if(b.begin(), b.end(), bind(std::equal_to<node_id>()
|
if (std::find_if(b.begin(), b.end(), bind(&node_entry::id, _1) == id)
|
||||||
, bind(&node_entry::id, _1), id)) != b.end()) return false;
|
!= b.end()) return false;
|
||||||
|
|
||||||
if (std::find_if(rb.begin(), rb.end(), bind(std::equal_to<node_id>()
|
if (std::find_if(rb.begin(), rb.end(), bind(&node_entry::id, _1) == id)
|
||||||
, bind(&node_entry::id, _1), id)) != rb.end()) return false;
|
!= rb.end()) return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -188,8 +188,7 @@ void routing_table::node_failed(node_id const& id)
|
||||||
bucket_t& rb = m_buckets[bucket_index].second;
|
bucket_t& rb = m_buckets[bucket_index].second;
|
||||||
|
|
||||||
bucket_t::iterator i = std::find_if(b.begin(), b.end()
|
bucket_t::iterator i = std::find_if(b.begin(), b.end()
|
||||||
, bind(std::equal_to<node_id>()
|
, bind(&node_entry::id, _1) == id);
|
||||||
, bind(&node_entry::id, _1), id));
|
|
||||||
|
|
||||||
if (i == b.end()) return;
|
if (i == b.end()) return;
|
||||||
|
|
||||||
|
@ -238,8 +237,7 @@ bool routing_table::node_seen(node_id const& id, udp::endpoint addr)
|
||||||
bucket_t& b = m_buckets[bucket_index].first;
|
bucket_t& b = m_buckets[bucket_index].first;
|
||||||
|
|
||||||
bucket_t::iterator i = std::find_if(b.begin(), b.end()
|
bucket_t::iterator i = std::find_if(b.begin(), b.end()
|
||||||
, bind(std::equal_to<node_id>()
|
, bind(&node_entry::id, _1) == id);
|
||||||
, bind(&node_entry::id, _1), id));
|
|
||||||
|
|
||||||
bool ret = need_bootstrap();
|
bool ret = need_bootstrap();
|
||||||
|
|
||||||
|
@ -286,9 +284,8 @@ bool routing_table::node_seen(node_id const& id, udp::endpoint addr)
|
||||||
// with nodes from that cache.
|
// with nodes from that cache.
|
||||||
|
|
||||||
i = std::max_element(b.begin(), b.end()
|
i = std::max_element(b.begin(), b.end()
|
||||||
, bind(std::less<int>()
|
, bind(&node_entry::fail_count, _1)
|
||||||
, bind(&node_entry::fail_count, _1)
|
< bind(&node_entry::fail_count, _2));
|
||||||
, bind(&node_entry::fail_count, _2)));
|
|
||||||
|
|
||||||
if (i != b.end() && i->fail_count > 0)
|
if (i != b.end() && i->fail_count > 0)
|
||||||
{
|
{
|
||||||
|
@ -308,8 +305,7 @@ bool routing_table::node_seen(node_id const& id, udp::endpoint addr)
|
||||||
bucket_t& rb = m_buckets[bucket_index].second;
|
bucket_t& rb = m_buckets[bucket_index].second;
|
||||||
|
|
||||||
i = std::find_if(rb.begin(), rb.end()
|
i = std::find_if(rb.begin(), rb.end()
|
||||||
, bind(std::equal_to<node_id>()
|
, bind(&node_entry::id, _1) == id);
|
||||||
, bind(&node_entry::id, _1), id));
|
|
||||||
|
|
||||||
// if the node is already in the replacement bucket
|
// if the node is already in the replacement bucket
|
||||||
// just return.
|
// just return.
|
||||||
|
@ -351,8 +347,7 @@ void routing_table::find_node(node_id const& target
|
||||||
if ((int)l.size() == count)
|
if ((int)l.size() == count)
|
||||||
{
|
{
|
||||||
assert(std::count_if(l.begin(), l.end()
|
assert(std::count_if(l.begin(), l.end()
|
||||||
, boost::bind(std::not_equal_to<int>()
|
, boost::bind(&node_entry::fail_count, _1) != 0) == 0);
|
||||||
, boost::bind(&node_entry::fail_count, _1), 0)) == 0);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -384,8 +379,7 @@ void routing_table::find_node(node_id const& target
|
||||||
|| bucket_index == (int)m_buckets.size() - 1)
|
|| bucket_index == (int)m_buckets.size() - 1)
|
||||||
{
|
{
|
||||||
assert(std::count_if(l.begin(), l.end()
|
assert(std::count_if(l.begin(), l.end()
|
||||||
, boost::bind(std::not_equal_to<int>()
|
, boost::bind(&node_entry::fail_count, _1) != 0) == 0);
|
||||||
, boost::bind(&node_entry::fail_count, _1), 0)) == 0);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -399,8 +393,7 @@ void routing_table::find_node(node_id const& target
|
||||||
{
|
{
|
||||||
l.erase(l.begin() + count, l.end());
|
l.erase(l.begin() + count, l.end());
|
||||||
assert(std::count_if(l.begin(), l.end()
|
assert(std::count_if(l.begin(), l.end()
|
||||||
, boost::bind(std::not_equal_to<int>()
|
, boost::bind(&node_entry::fail_count, _1) != 0) == 0);
|
||||||
, boost::bind(&node_entry::fail_count, _1), 0)) == 0);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -409,8 +402,7 @@ void routing_table::find_node(node_id const& target
|
||||||
assert((int)l.size() <= count);
|
assert((int)l.size() <= count);
|
||||||
|
|
||||||
assert(std::count_if(l.begin(), l.end()
|
assert(std::count_if(l.begin(), l.end()
|
||||||
, boost::bind(std::not_equal_to<int>()
|
, boost::bind(&node_entry::fail_count, _1) != 0) == 0);
|
||||||
, boost::bind(&node_entry::fail_count, _1), 0)) == 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
routing_table::iterator routing_table::begin() const
|
routing_table::iterator routing_table::begin() const
|
||||||
|
|
|
@ -68,8 +68,7 @@ void traversal_algorithm::add_entry(node_id const& id, udp::endpoint addr, unsig
|
||||||
if (i == m_results.end() || i->id != id)
|
if (i == m_results.end() || i->id != id)
|
||||||
{
|
{
|
||||||
assert(std::find_if(m_results.begin(), m_results.end()
|
assert(std::find_if(m_results.begin(), m_results.end()
|
||||||
, bind(std::equal_to<node_id>()
|
, bind(&result::id, _1) == id) == m_results.end());
|
||||||
, bind(&result::id, _1), id)) == m_results.end());
|
|
||||||
#ifdef TORRENT_DHT_VERBOSE_LOGGING
|
#ifdef TORRENT_DHT_VERBOSE_LOGGING
|
||||||
TORRENT_LOG(traversal) << "adding result: " << id << " " << addr;
|
TORRENT_LOG(traversal) << "adding result: " << id << " " << addr;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -163,7 +163,7 @@ void lsd::announce(sha1_hash const& ih, int listen_port)
|
||||||
m_broadcast_timer.async_wait(bind(&lsd::resend_announce, this, _1, msg));
|
m_broadcast_timer.async_wait(bind(&lsd::resend_announce, this, _1, msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
void lsd::resend_announce(asio::error_code const& e, std::string msg)
|
void lsd::resend_announce(asio::error_code const& e, std::string msg) try
|
||||||
{
|
{
|
||||||
if (e) return;
|
if (e) return;
|
||||||
|
|
||||||
|
@ -177,6 +177,8 @@ void lsd::resend_announce(asio::error_code const& e, std::string msg)
|
||||||
m_broadcast_timer.expires_from_now(milliseconds(250 * m_retry_count));
|
m_broadcast_timer.expires_from_now(milliseconds(250 * m_retry_count));
|
||||||
m_broadcast_timer.async_wait(bind(&lsd::resend_announce, this, _1, msg));
|
m_broadcast_timer.async_wait(bind(&lsd::resend_announce, this, _1, msg));
|
||||||
}
|
}
|
||||||
|
catch (std::exception&)
|
||||||
|
{}
|
||||||
|
|
||||||
void lsd::on_announce(asio::error_code const& e
|
void lsd::on_announce(asio::error_code const& e
|
||||||
, std::size_t bytes_transferred)
|
, std::size_t bytes_transferred)
|
||||||
|
@ -235,7 +237,7 @@ void lsd::on_announce(asio::error_code const& e
|
||||||
setup_receive();
|
setup_receive();
|
||||||
}
|
}
|
||||||
|
|
||||||
void lsd::setup_receive()
|
void lsd::setup_receive() try
|
||||||
{
|
{
|
||||||
#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING)
|
#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING)
|
||||||
m_log << time_now_string()
|
m_log << time_now_string()
|
||||||
|
@ -245,6 +247,8 @@ void lsd::setup_receive()
|
||||||
m_socket.async_receive_from(asio::buffer(m_receive_buffer
|
m_socket.async_receive_from(asio::buffer(m_receive_buffer
|
||||||
, sizeof(m_receive_buffer)), m_remote, bind(&lsd::on_announce, this, _1, _2));
|
, sizeof(m_receive_buffer)), m_remote, bind(&lsd::on_announce, this, _1, _2));
|
||||||
}
|
}
|
||||||
|
catch (std::exception&)
|
||||||
|
{}
|
||||||
|
|
||||||
void lsd::close()
|
void lsd::close()
|
||||||
{
|
{
|
||||||
|
|
|
@ -435,6 +435,9 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
|
|
||||||
void torrent::on_announce()
|
void torrent::on_announce()
|
||||||
|
#ifndef NDEBUG
|
||||||
|
try
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
boost::weak_ptr<torrent> self(shared_from_this());
|
boost::weak_ptr<torrent> self(shared_from_this());
|
||||||
|
|
||||||
|
@ -458,6 +461,13 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#ifndef NDEBUG
|
||||||
|
catch (std::exception& e)
|
||||||
|
{
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef TORRENT_DISABLE_DHT
|
#ifndef TORRENT_DISABLE_DHT
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue