mirror of
https://git.wownero.com/wowlet/wowlet.git
synced 2024-08-15 01:03:14 +00:00
Nodes: don't connect to out of sync nodes in wsmode
This commit is contained in:
parent
b66aceccc8
commit
2a03ca9eda
3 changed files with 47 additions and 12 deletions
|
@ -149,7 +149,7 @@ void Nodes::onConnectionTimer() {
|
||||||
QString msg;
|
QString msg;
|
||||||
Wallet::ConnectionStatus status = m_ctx->currentWallet->connected(true);
|
Wallet::ConnectionStatus status = m_ctx->currentWallet->connected(true);
|
||||||
NodeSource nodeSource = this->source();
|
NodeSource nodeSource = this->source();
|
||||||
auto wsMode = nodeSource == NodeSource::websocket;
|
auto wsMode = (nodeSource == NodeSource::websocket);
|
||||||
auto nodes = wsMode ? m_customNodes : m_websocketNodes;
|
auto nodes = wsMode ? m_customNodes : m_websocketNodes;
|
||||||
|
|
||||||
if (wsMode && !m_wsNodesReceived && m_websocketNodes.count() == 0) {
|
if (wsMode && !m_wsNodesReceived && m_websocketNodes.count() == 0) {
|
||||||
|
@ -224,6 +224,36 @@ FeatherNode Nodes::pickEligibleNode() {
|
||||||
return rtn;
|
return rtn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVector<int> heights;
|
||||||
|
for (const auto &node: nodes) {
|
||||||
|
heights.push_back(node.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::sort(heights.begin(), heights.end());
|
||||||
|
|
||||||
|
// Calculate mode of node heights
|
||||||
|
int max_count = 1, mode_height = heights[0], count = 1;
|
||||||
|
for (int i = 1; i < heights.count(); i++) {
|
||||||
|
if (heights[i] == 0) { // Don't consider 0 height nodes
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (heights[i] == heights[i - 1])
|
||||||
|
count++;
|
||||||
|
else {
|
||||||
|
if (count > max_count) {
|
||||||
|
max_count = count;
|
||||||
|
mode_height = heights[i - 1];
|
||||||
|
}
|
||||||
|
count = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (count > max_count)
|
||||||
|
{
|
||||||
|
max_count = count;
|
||||||
|
mode_height = heights[heights.count() - 1];
|
||||||
|
}
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
// keep track of nodes we have previously tried to connect to
|
// keep track of nodes we have previously tried to connect to
|
||||||
if (m_connectionAttempts.count() == nodes.count()) {
|
if (m_connectionAttempts.count() == nodes.count()) {
|
||||||
|
@ -240,6 +270,11 @@ FeatherNode Nodes::pickEligibleNode() {
|
||||||
|
|
||||||
if (wsMode && !node.online)
|
if (wsMode && !node.online)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// Ignore nodes that are more than 25 blocks behind mode
|
||||||
|
if (wsMode && node.height < (mode_height - 25))
|
||||||
|
continue;
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ struct FeatherNode {
|
||||||
_address = spl.at(1);
|
_address = spl.at(1);
|
||||||
}
|
}
|
||||||
if(!_address.contains(":"))
|
if(!_address.contains(":"))
|
||||||
_address += ":18089";
|
_address += ":18081";
|
||||||
this->address = _address;
|
this->address = _address;
|
||||||
if(this->address.contains(".onion"))
|
if(this->address.contains(".onion"))
|
||||||
tor = true;
|
tor = true;
|
||||||
|
|
Loading…
Reference in a new issue