|
@ -81,7 +81,8 @@ shared_ptr<NodeEntry> NodeTable::addNode(Node const& _node, NodeRelation _relati |
|
|
{ |
|
|
{ |
|
|
shared_ptr<NodeEntry> ret(new NodeEntry(m_node, _node.id, _node.endpoint)); |
|
|
shared_ptr<NodeEntry> ret(new NodeEntry(m_node, _node.id, _node.endpoint)); |
|
|
ret->pending = false; |
|
|
ret->pending = false; |
|
|
m_nodes[_node.id] = ret; |
|
|
DEV_GUARDED(x_nodes) |
|
|
|
|
|
m_nodes[_node.id] = ret; |
|
|
noteActiveNode(_node.id, _node.endpoint); |
|
|
noteActiveNode(_node.id, _node.endpoint); |
|
|
return ret; |
|
|
return ret; |
|
|
} |
|
|
} |
|
@ -101,14 +102,13 @@ shared_ptr<NodeEntry> NodeTable::addNode(Node const& _node, NodeRelation _relati |
|
|
return move(shared_ptr<NodeEntry>()); |
|
|
return move(shared_ptr<NodeEntry>()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
{ |
|
|
DEV_GUARDED(x_nodes) |
|
|
Guard ln(x_nodes); |
|
|
|
|
|
if (m_nodes.count(_node.id)) |
|
|
if (m_nodes.count(_node.id)) |
|
|
return m_nodes[_node.id]; |
|
|
return m_nodes[_node.id]; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
shared_ptr<NodeEntry> ret(new NodeEntry(m_node, _node.id, _node.endpoint)); |
|
|
shared_ptr<NodeEntry> ret(new NodeEntry(m_node, _node.id, _node.endpoint)); |
|
|
m_nodes[_node.id] = ret; |
|
|
DEV_GUARDED(x_nodes) |
|
|
|
|
|
m_nodes[_node.id] = ret; |
|
|
clog(NodeTableConnect) << "addNode pending for" << _node.endpoint; |
|
|
clog(NodeTableConnect) << "addNode pending for" << _node.endpoint; |
|
|
ping(_node.endpoint); |
|
|
ping(_node.endpoint); |
|
|
return ret; |
|
|
return ret; |
|
@ -186,7 +186,8 @@ void NodeTable::discover(NodeId _node, unsigned _round, shared_ptr<set<shared_pt |
|
|
tried.push_back(r); |
|
|
tried.push_back(r); |
|
|
FindNode p(r->endpoint, _node); |
|
|
FindNode p(r->endpoint, _node); |
|
|
p.sign(m_secret); |
|
|
p.sign(m_secret); |
|
|
m_findNodeTimeout.push_back(make_pair(r->id, chrono::steady_clock::now())); |
|
|
DEV_GUARDED(x_findNodeTimeout) |
|
|
|
|
|
m_findNodeTimeout.push_back(make_pair(r->id, chrono::steady_clock::now())); |
|
|
m_socketPointer->send(p); |
|
|
m_socketPointer->send(p); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -447,17 +448,17 @@ void NodeTable::onReceived(UDPSocketFace*, bi::udp::endpoint const& _from, bytes |
|
|
{ |
|
|
{ |
|
|
if (auto n = nodeEntry(nodeid)) |
|
|
if (auto n = nodeEntry(nodeid)) |
|
|
n->pending = false; |
|
|
n->pending = false; |
|
|
else if (m_pubkDiscoverPings.count(_from.address())) |
|
|
else |
|
|
{ |
|
|
{ |
|
|
|
|
|
DEV_GUARDED(x_pubkDiscoverPings) |
|
|
{ |
|
|
{ |
|
|
Guard l(x_pubkDiscoverPings); |
|
|
if (!m_pubkDiscoverPings.count(_from.address())) |
|
|
|
|
|
return; // unsolicited pong; don't note node as active
|
|
|
m_pubkDiscoverPings.erase(_from.address()); |
|
|
m_pubkDiscoverPings.erase(_from.address()); |
|
|
} |
|
|
} |
|
|
if (!haveNode(nodeid)) |
|
|
if (!haveNode(nodeid)) |
|
|
addNode(Node(nodeid, NodeIPEndpoint(_from.address(), _from.port(), _from.port()))); |
|
|
addNode(Node(nodeid, NodeIPEndpoint(_from.address(), _from.port(), _from.port()))); |
|
|
} |
|
|
} |
|
|
else |
|
|
|
|
|
return; // unsolicited pong; don't note node as active
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// update our endpoint address and UDP port
|
|
|
// update our endpoint address and UDP port
|
|
@ -473,14 +474,15 @@ void NodeTable::onReceived(UDPSocketFace*, bi::udp::endpoint const& _from, bytes |
|
|
{ |
|
|
{ |
|
|
bool expected = false; |
|
|
bool expected = false; |
|
|
auto now = chrono::steady_clock::now(); |
|
|
auto now = chrono::steady_clock::now(); |
|
|
m_findNodeTimeout.remove_if([&](NodeIdTimePoint const& t) |
|
|
DEV_GUARDED(x_findNodeTimeout) |
|
|
{ |
|
|
m_findNodeTimeout.remove_if([&](NodeIdTimePoint const& t) |
|
|
if (t.first == nodeid && now - t.second < c_reqTimeout) |
|
|
{ |
|
|
expected = true; |
|
|
if (t.first == nodeid && now - t.second < c_reqTimeout) |
|
|
else if (t.first == nodeid) |
|
|
expected = true; |
|
|
return true; |
|
|
else if (t.first == nodeid) |
|
|
return false; |
|
|
return true; |
|
|
}); |
|
|
return false; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
if (!expected) |
|
|
if (!expected) |
|
|
{ |
|
|
{ |
|
|