improved support for out-of-memory conditions, fix pe-crypto error handling and add some dht asserts

This commit is contained in:
Marcos Pinto 2008-02-09 22:02:14 +00:00
parent f940a4c4db
commit 6322115fef
7 changed files with 36 additions and 6 deletions

View File

@ -56,9 +56,16 @@ struct observer : boost::noncopyable
: sent(time_now())
, pool_allocator(p)
, m_refs(0)
{}
{
#ifndef NDEBUG
m_in_constructor = true;
#endif
}
virtual ~observer() {}
virtual ~observer()
{
TORRENT_ASSERT(!m_in_constructor);
}
// these two callbacks lets the observer add
// information to the message before it's sent
@ -79,6 +86,9 @@ struct observer : boost::noncopyable
udp::endpoint target_addr;
ptime sent;
#ifndef NDEBUG
bool m_in_constructor;
#endif
private:
boost::pool<>& pool_allocator;
// reference counter for intrusive_ptr

View File

@ -101,6 +101,9 @@ closest_nodes::closest_nodes(
void closest_nodes::invoke(node_id const& id, udp::endpoint addr)
{
observer_ptr o(new (m_rpc.allocator().malloc()) closest_nodes_observer(this, id, m_target));
#ifndef NDEBUG
o->m_in_constructor = false;
#endif
m_rpc.invoke(messages::find_node, addr, o);
}

View File

@ -110,6 +110,9 @@ void find_data::invoke(node_id const& id, asio::ip::udp::endpoint addr)
}
observer_ptr o(new (m_rpc.allocator().malloc()) find_data_observer(this, id, m_target));
#ifndef NDEBUG
o->m_in_constructor = false;
#endif
m_rpc.invoke(messages::get_peers, addr, o);
}

View File

@ -274,8 +274,11 @@ namespace
for (std::vector<node_entry>::const_iterator i = v.begin()
, end(v.end()); i != end; ++i)
{
rpc.invoke(messages::get_peers, i->addr, observer_ptr(
new (rpc.allocator().malloc()) get_peers_observer(ih, listen_port, rpc, f)));
observer_ptr o(new (rpc.allocator().malloc()) get_peers_observer(ih, listen_port, rpc, f));
#ifndef NDEBUG
o->m_in_constructor = false;
#endif
rpc.invoke(messages::get_peers, i->addr, o);
nodes = true;
}
}
@ -291,6 +294,9 @@ void node_impl::add_node(udp::endpoint node)
// ping the node, and if we get a reply, it
// will be added to the routing table
observer_ptr o(new (m_rpc.allocator().malloc()) null_observer(m_rpc.allocator()));
#ifndef NDEBUG
o->m_in_constructor = false;
#endif
m_rpc.invoke(messages::ping, node, o);
}

View File

@ -105,6 +105,9 @@ void refresh::invoke(node_id const& nid, udp::endpoint addr)
{
observer_ptr o(new (m_rpc.allocator().malloc()) refresh_observer(
this, nid, m_target));
#ifndef NDEBUG
o->m_in_constructor = false;
#endif
m_rpc.invoke(messages::find_node, addr, o);
}
@ -156,6 +159,9 @@ void refresh::invoke_pings_or_finish(bool prevent_request)
{
observer_ptr o(new (m_rpc.allocator().malloc()) ping_observer(
this, node.id));
#ifndef NDEBUG
o->m_in_constructor = false;
#endif
m_rpc.invoke(messages::ping, node.addr, o);
++m_active_pings;
++m_leftover_nodes_iterator;

View File

@ -430,6 +430,9 @@ void rpc_manager::reply_with_ping(msg& m)
io::write_uint16(m_next_transaction_id, out);
observer_ptr o(new (allocator().malloc()) null_observer(allocator()));
#ifndef NDEBUG
o->m_in_constructor = false;
#endif
TORRENT_ASSERT(!m_transactions[m_next_transaction_id]);
o->sent = time_now();
o->target_addr = m.addr;

View File

@ -61,8 +61,7 @@ namespace libtorrent
TORRENT_ASSERT(sizeof(m_dh_prime) == DH_size(m_DH));
DH_generate_key(m_DH);
if (m_DH->pub_key == 0)
if (DH_generate_key(m_DH) == 0 || m_DH->pub_key == 0)
{
DH_free(m_DH);
throw std::bad_alloc();