Merge pull request 'ASMap Health Check' (#447) from asmaphealth into dev

Reviewed-on: https://git.hush.is/hush/hush3/pulls/447
This commit is contained in:
duke
2024-12-03 10:56:27 -06:00

View File

@@ -50,6 +50,9 @@ extern int32_t HUSH_TESTNODE;
// Satoshi originally used 10 seconds(!), did they know something Peter Wuille didn't?
#define DUMP_ADDRESSES_INTERVAL 300
// Run asmap health check every 24hr by default
#define ASMAP_HEALTHCHECK_INTERVAL 24*60*60
// This is every 2 blocks, on avg, on HUSH3
#define DUMP_ZINDEX_INTERVAL 150
@@ -1648,6 +1651,30 @@ int64_t PoissonNextSend(int64_t now, int average_interval_seconds)
return now + (int64_t)(log1p(GetRand(1ULL << 48) * -0.0000000000000035527136788 /* -1/2^48 */) * average_interval_seconds * -1000000.0 + 0.5);
}
void ASMapHealthCheck() {
std::set<uint32_t> clearnet_asns{};
int unmapped_count{0};
LOCK(cs_vNodes);
for (const auto& pnode : vNodes) {
auto address = pnode->addr;
if(address.IsTor() || address.IsI2P() || address.IsCJDNS()) {
// These networks do not have ASNs, skip them
continue;
}
uint32_t asn = address.GetMappedAS(addrman.m_asmap);
if (asn == 0) {
++unmapped_count;
continue;
}
clearnet_asns.insert(asn);
}
LogPrintf("ASMap Health Check: %i clearnet peers are mapped to %i ASNs with %i peers being unmapped\n", vNodes.size(), clearnet_asns.size(), unmapped_count);
}
void ThreadOpenConnections()
{
// Connect to specific addresses
@@ -1753,7 +1780,7 @@ void ThreadOpenConnections()
int64_t nNow = GetTime();
int nTries = 0;
LogPrint("net", "Resolving addrman collisions\n");
LogPrint("net", "Resolving addrman collisions\n");
addrman.ResolveCollisions();
while (true) {
@@ -2378,10 +2405,14 @@ void StartNode(boost::thread_group& threadGroup, CScheduler& scheduler)
scheduler.scheduleEvery(&DumpZindexStats, DUMP_ZINDEX_INTERVAL);
}
// Dump network addresses
scheduler.scheduleEvery(&DumpAddresses, DUMP_ADDRESSES_INTERVAL);
// Look for ~/.hush/AC_NAME/plz_stop
scheduler.scheduleEvery(&CheckIfWeShouldStop, CHECK_PLZ_STOP_INTERVAL);
// Schedule ASMap Health check to run regularly
scheduler.scheduleEvery(&ASMapHealthCheck, ASMAP_HEALTHCHECK_INTERVAL);
// and schedule it to run once in 5 mins when we hopefully have peers connected
scheduler.scheduleFromNow(&ASMapHealthCheck, 300);
}
bool StopNode()