oxen-storage-server/httpserver/stats.cpp
Jason Rhinelander 60b18518b0 Remove storage-server blockchain testing
This is a mis-feature in the wrong place that doesn't protect against
anything malicious.

There is one comment (in oxen-core) that suggests the purpose here was
to be complex enough that the result couldn't be proxied to some other
node.  This does not accomplish that because:

- RPC requests are fast.  You *could* retrieve 1000 blocks quickly
enough from a high performance public RPC node to calculate the
checksum.
- Even if you couldn't, you could *easily* hack up oxend to proxy the
entire "test" request to some other node, thereby allowing you to run
multiple SNs without actually needing to store the blockchain.
- The testee gets I/O-trashed by having to go look up random blocks to
calculate the checksum for a test that really isn't useful.
- It is possible to abuse the blockchain test result feature by spamming
other storage servers to make other nodes waste significant resources to
compute these blockchain tests for random heights.
- The tests aren't actually *used* for anything: if you fail a test,
nothing happens.

Most importantly of all, this should never have been in storage server:
it has nothing at all to do with storing files, and is entirely outside
storage-server's purview to perform any such blockchain test: rather
that belongs in oxend (if it were to be performed at all).
2021-04-08 21:25:14 -03:00

41 lines
984 B
C++

#include "stats.h"
#include <algorithm>
#include <chrono>
#include <iostream>
using namespace std::chrono_literals;
namespace oxen {
static void cleanup_old(std::deque<test_result_t>& tests, time_t cutoff_time) {
const auto it = std::find_if(tests.begin(), tests.end(),
[cutoff_time](const test_result_t& res) {
return res.timestamp > cutoff_time;
});
tests.erase(tests.begin(), it);
}
static constexpr std::chrono::seconds ROLLING_WINDOW_SIZE = 120min;
void all_stats_t::cleanup() {
using std::chrono::duration_cast;
using std::chrono::seconds;
const auto cutoff = time(nullptr) - ROLLING_WINDOW_SIZE.count();
for (auto& kv : peer_report_) {
const sn_record_t& sn = kv.first;
cleanup_old(peer_report_[sn].storage_tests, cutoff);
}
/// updated stats for "previous period"
this->next_period();
}
} // namespace oxen