|
|
@ -84,11 +84,14 @@ shared_ptr<NodeEntry> NodeTable::addNode(Node const& _node) |
|
|
|
return move(shared_ptr<NodeEntry>()); |
|
|
|
} |
|
|
|
|
|
|
|
// ping address if nodeid is empty
|
|
|
|
// ping address to recover nodeid if nodeid is empty
|
|
|
|
if (!_node.id) |
|
|
|
{ |
|
|
|
clog(NodeTableConnect) << "Sending public key discovery Ping to" << _node.endpoint.udp << "(Advertising:" << m_node.endpoint.udp << ")"; |
|
|
|
{ |
|
|
|
Guard l(x_pubkDiscoverPings); |
|
|
|
m_pubkDiscoverPings[_node.endpoint.udp.address()] = std::chrono::steady_clock::now(); |
|
|
|
} |
|
|
|
PingNode p(_node.endpoint.udp, m_node.endpoint.udp.address().to_string(), m_node.endpoint.udp.port()); |
|
|
|
p.sign(m_secret); |
|
|
|
m_socketPointer->send(p); |
|
|
@ -101,7 +104,11 @@ shared_ptr<NodeEntry> NodeTable::addNode(Node const& _node) |
|
|
|
return m_nodes[_node.id]; |
|
|
|
} |
|
|
|
|
|
|
|
shared_ptr<NodeEntry> ret(new NodeEntry(m_node, _node.id, NodeIPEndpoint(_node.endpoint.udp, _node.endpoint.tcp))); |
|
|
|
// TODO: SECURITY - Temporary until packets are updated.
|
|
|
|
NodeIPEndpoint ep(_node.endpoint.udp, _node.endpoint.tcp); |
|
|
|
if (!isPublicAddress(ep.tcp.address())) |
|
|
|
ep.tcp.address(_node.endpoint.udp.address()); |
|
|
|
shared_ptr<NodeEntry> ret(new NodeEntry(m_node, _node.id, ep)); |
|
|
|
m_nodes[_node.id] = ret; |
|
|
|
PingNode p(_node.endpoint.udp, m_node.endpoint.udp.address().to_string(), m_node.endpoint.udp.port()); |
|
|
|
p.sign(m_secret); |
|
|
@ -315,9 +322,13 @@ void NodeTable::noteActiveNode(Public const& _pubk, bi::udp::endpoint const& _en |
|
|
|
{ |
|
|
|
clog(NodeTableConnect) << "Noting active node:" << _pubk.abridged() << _endpoint.address().to_string() << ":" << _endpoint.port(); |
|
|
|
|
|
|
|
// update udp endpoint
|
|
|
|
// TODO: SECURITY - Temporary until packets are updated.
|
|
|
|
// update udp endpoint and override tcp endpoint if tcp endpoint isn't public
|
|
|
|
// (for the rare case where NAT port is mapped but
|
|
|
|
node->endpoint.udp.address(_endpoint.address()); |
|
|
|
node->endpoint.udp.port(_endpoint.port()); |
|
|
|
if (!isPublicAddress(node->endpoint.tcp.address())) |
|
|
|
node->endpoint.tcp.address(_endpoint.address()); |
|
|
|
|
|
|
|
shared_ptr<NodeEntry> contested; |
|
|
|
{ |
|
|
@ -399,7 +410,7 @@ void NodeTable::onReceived(UDPSocketFace*, bi::udp::endpoint const& _from, bytes |
|
|
|
|
|
|
|
bytesConstRef signedBytes(hashedBytes.cropped(Signature::size, hashedBytes.size() - Signature::size)); |
|
|
|
|
|
|
|
// todo: verify sig via known-nodeid and MDC, or, do ping/pong auth if node/endpoint is unknown/untrusted
|
|
|
|
// todo: verify sig via known-nodeid and MDC
|
|
|
|
|
|
|
|
bytesConstRef sigBytes(_packet.cropped(h256::size, Signature::size)); |
|
|
|
Public nodeid(dev::recover(*(Signature const*)sigBytes.data(), sha3(signedBytes))); |
|
|
@ -430,7 +441,6 @@ void NodeTable::onReceived(UDPSocketFace*, bi::udp::endpoint const& _from, bytes |
|
|
|
dropNode(n); |
|
|
|
|
|
|
|
if (auto n = nodeEntry(it->first.first)) |
|
|
|
if (m_nodeEventHandler && n->pending) |
|
|
|
n->pending = false; |
|
|
|
|
|
|
|
it = m_evictions.erase(it); |
|
|
@ -441,14 +451,18 @@ void NodeTable::onReceived(UDPSocketFace*, bi::udp::endpoint const& _from, bytes |
|
|
|
{ |
|
|
|
if (auto n = nodeEntry(nodeid)) |
|
|
|
n->pending = false; |
|
|
|
} |
|
|
|
else if (m_pubkDiscoverPings.count(_from.address())) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Guard l(x_pubkDiscoverPings); |
|
|
|
m_pubkDiscoverPings.erase(_from.address()); |
|
|
|
} |
|
|
|
if (!haveNode(nodeid)) |
|
|
|
addNode(nodeid, _from, bi::tcp::endpoint(_from.address(), _from.port())); |
|
|
|
} |
|
|
|
else |
|
|
|
return; // unsolicited pong; don't note node as active
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|