Browse Source

Evade networking crash.

cl-refactor
Gav Wood 10 years ago
parent
commit
2102ab2870
  1. 43
      libp2p/Host.cpp

43
libp2p/Host.cpp

@ -447,26 +447,31 @@ void Host::connect(std::shared_ptr<Node> const& _n)
_n->failedAttempts++; _n->failedAttempts++;
m_ready -= _n->index; m_ready -= _n->index;
bi::tcp::socket* s = new bi::tcp::socket(m_ioService); bi::tcp::socket* s = new bi::tcp::socket(m_ioService);
s->async_connect(_n->address, [=](boost::system::error_code const& ec)
{ auto n = node(_n->id);
if (ec) if (n)
{ s->async_connect(_n->address, [=](boost::system::error_code const& ec)
clog(NetConnect) << "Connection refused to node" << _n->id.abridged() << "@" << _n->address << "(" << ec.message() << ")";
_n->lastDisconnect = TCPError;
_n->lastAttempted = std::chrono::system_clock::now();
m_ready += _n->index;
}
else
{ {
clog(NetConnect) << "Connected to" << _n->id.abridged() << "@" << _n->address; if (ec)
_n->lastConnected = std::chrono::system_clock::now(); {
auto p = make_shared<Session>(this, std::move(*s), node(_n->id), true); // true because we don't care about ids matched for now. Once we have permenant IDs this will matter a lot more and we can institute a safer mechanism. clog(NetConnect) << "Connection refused to node" << _n->id.abridged() << "@" << _n->address << "(" << ec.message() << ")";
p->start(); _n->lastDisconnect = TCPError;
} _n->lastAttempted = std::chrono::system_clock::now();
delete s; m_ready += _n->index;
Guard l(x_pendingNodeConns); }
m_pendingNodeConns.erase(nptr); else
}); {
clog(NetConnect) << "Connected to" << _n->id.abridged() << "@" << _n->address;
_n->lastConnected = std::chrono::system_clock::now();
auto p = make_shared<Session>(this, std::move(*s), n, true); // true because we don't care about ids matched for now. Once we have permenant IDs this will matter a lot more and we can institute a safer mechanism.
p->start();
}
delete s;
Guard l(x_pendingNodeConns);
m_pendingNodeConns.erase(nptr);
});
else
clog(NetWarn) << "Trying to connect to node not in node table.";
} }
bool Host::havePeer(NodeId _id) const bool Host::havePeer(NodeId _id) const

Loading…
Cancel
Save