Browse Source

Manage dead nodes.

cl-refactor
Gav Wood 10 years ago
parent
commit
5d2238d179
  1. 5
      alethzero/MainWin.cpp
  2. 11
      libp2p/Host.cpp
  3. 1
      libp2p/Host.h
  4. 25
      libp2p/Session.cpp

5
alethzero/MainWin.cpp

@ -766,10 +766,11 @@ void Main::refreshNetwork()
auto ns = web3()->nodes();
ui->nodes->clear();
for (p2p::Node const& i: ns)
ui->nodes->addItem(QString("[%1%3] %2 - ( =%5s | /%4s | %6 | %7x ) - *%8 $%9")
if (!i.dead)
ui->nodes->addItem(QString("[%1%3] %2 - ( =%5s | /%4s | %6 | %7x ) - *%8 $%9")
.arg(QString::fromStdString(i.id.abridged()))
.arg(QString::fromStdString(toString(i.address)))
.arg(i.id == web3()->id() ? " self" : i.isOffline() ? "" : " PEER")
.arg(i.id == web3()->id() ? " self" : i.isOffline() ? " ripe" : " ----")
.arg(i.secondsSinceLastAttempted())
.arg(i.secondsSinceLastConnected())
.arg(QString::fromStdString(reasonOf(i.lastDisconnect)))

11
libp2p/Host.cpp

@ -354,24 +354,21 @@ shared_ptr<Node> Host::noteNode(NodeId _id, bi::tcp::endpoint const& _a, Origin
unsigned i;
if (!m_nodes.count(_id))
{
shared_ptr<Node> old;
if (m_nodes.count(_oldId))
{
old = m_nodes[_oldId];
i = old->index;
i = m_nodes[_oldId]->index;
m_nodes.erase(_oldId);
m_nodesList[i] = _id;
m_nodes[id()] = make_shared<Node>();
}
else
{
i = m_nodesList.size();
m_nodesList.push_back(_id);
m_nodes[_id] = make_shared<Node>();
}
m_nodes[_id] = make_shared<Node>();
m_nodes[_id]->id = _id;
m_nodes[_id]->address = _a;
m_nodes[_id]->index = i;
m_nodes[_id]->id = _id;
m_nodes[_id]->idOrigin = _o;
}
else
@ -665,7 +662,7 @@ bytes Host::saveNodes() const
for (auto const& i: m_nodes)
{
Node const& n = *(i.second);
if (n.id != id() && !isPrivateAddress(n.address.address()))
if (!n.dead && n.id != id() && !isPrivateAddress(n.address.address()))
{
nodes.appendList(10);
if (n.address.address().is_v4())

1
libp2p/Host.h

@ -64,6 +64,7 @@ struct Node
bi::tcp::endpoint address; ///< As reported from the node itself.
int score = 0; ///< All time cumulative.
int rating = 0; ///< Trending.
bool dead = false; ///< If true, we believe this node is permanently dead - forget all about it.
std::chrono::system_clock::time_point lastConnected;
std::chrono::system_clock::time_point lastAttempted;
unsigned failedAttempts = 0;

25
libp2p/Session.cpp

@ -62,7 +62,7 @@ Session::Session(Host* _s, bi::tcp::socket _socket, std::shared_ptr<Node> const&
Session::~Session()
{
if (id() && !isPermanentProblem(m_node->lastDisconnect))
if (id() && (!m_node || (!isPermanentProblem(m_node->lastDisconnect) && !m_node->dead)))
m_server->m_ready += m_node->index;
// Read-chain finished for one reason or another.
@ -201,14 +201,6 @@ bool Session::interpret(RLP const& _r)
return false;
}
if (m_server->havePeer(id))
{
// Already connected.
clogS(NetWarn) << "Already connected to a peer with id" << id.abridged();
disconnect(DuplicatePeer);
return false;
}
if (m_node && m_node->id != id)
{
if (m_force || m_node->idOrigin <= Origin::SelfThird)
@ -220,6 +212,21 @@ bool Session::interpret(RLP const& _r)
disconnect(UnexpectedIdentity);
return false;
}
if (m_server->havePeer(id))
{
m_node->dead = true;
disconnect(DuplicatePeer);
return false;
}
}
if (m_server->havePeer(id))
{
// Already connected.
clogS(NetWarn) << "Already connected to a peer with id" << id.abridged();
disconnect(DuplicatePeer);
return false;
}
if (!id)

Loading…
Cancel
Save