From 1c2af535eb3052405503f136578e30b24a8e18ae Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sun, 8 Nov 2026 20:08:44 +0100 Subject: Retire the busy network tracker. /24 networks don't say anything anymore in 2026 and in v6 it was broken from the beginning --- src/ot_http.c | 1 - src/ot_stats.c | 56 ++--------------------------------- src/ot_workqueue.h | 1 - tests/integration/test_concurrency.py | 2 +- tests/integration/test_stats.py | 47 +---------------------------- 5 files changed, 5 insertions(+), 102 deletions(-) diff --git a/src/ot_http.c b/src/ot_http.c index 262936e..70176c3 100644 --- a/src/ot_http.c +++ b/src/ot_http.c @@ -279,7 +279,6 @@ static ssize_t http_handle_stats(const int64_t sock, struct ot_workstruct *ws, c {"tcp4", TASK_STATS_TCP}, {"torr", TASK_STATS_TORRENTS}, {"fscr", TASK_STATS_FULLSCRAPE}, - {"s24s", TASK_STATS_SLASH24S}, {"tpbs", TASK_STATS_TPB}, {"herr", TASK_STATS_HTTPERRORS}, {"completed", TASK_STATS_COMPLETED}, diff --git a/src/ot_stats.c b/src/ot_stats.c index 15c06b2..ba780d3 100644 --- a/src/ot_stats.c +++ b/src/ot_stats.c @@ -91,12 +91,13 @@ static const char *ot_failed_request_names[] = { static time_t ot_start_time; +#ifdef WANT_SPOT_WOODPECKER #define STATS_NETWORK_NODE_BITWIDTH 4 #define STATS_NETWORK_NODE_COUNT (1 << STATS_NETWORK_NODE_BITWIDTH) -#define __BYTE(P, D) (((uint8_t *)P)[D / 8]) +#define __BYTE(P, D) (((uint8_t *)(P))[(D) / 8]) #define __MSK (STATS_NETWORK_NODE_COUNT - 1) -#define __SHFT(D) ((D ^ STATS_NETWORK_NODE_BITWIDTH) & STATS_NETWORK_NODE_BITWIDTH) +#define __SHFT(D) (((D) ^ STATS_NETWORK_NODE_BITWIDTH) & STATS_NETWORK_NODE_BITWIDTH) #define __LDR(P, D) ((__BYTE((P), (D)) >> __SHFT((D))) & __MSK) #define __STR(P, D, V) __BYTE((P), (D)) = (__BYTE((P), (D)) & ~(__MSK << __SHFT((D)))) | ((V) << __SHFT((D))) @@ -236,54 +237,6 @@ static void stats_return_busy_networks(char **reply, const char *reply_end, stat fmt_append(reply, reply_end, "\n"); } -static void stats_slash24s_txt(char **reply, const char *reply_end, size_t amount) { - stats_network_node *slash24s_network_counters_root = NULL; - size_t i, bucket, peer_size = OT_PEER_SIZE4; - - for (bucket = 0; bucket < OT_BUCKET_COUNT; ++bucket) { - ot_vector *torrents_list = mutex_bucket_lock(bucket); - for (i = 0; i < torrents_list->size; ++i) { - ot_peerlist *peer_list = (((ot_torrent *)(torrents_list->data))[i]).peer_list; - ot_vector *bucket_list; - int num_buckets = 1; - - if (!peer_list) - continue; - bucket_list = &peer_list->peers4; /* /24 networks are an IPv4 notion */ - - if (OT_VECTOR_HASBUCKETS(bucket_list)) { - num_buckets = bucket_list->size; - bucket_list = (ot_vector *)bucket_list->data; - } - - while (num_buckets--) { - ot_peer *peers = (ot_peer *)bucket_list->data; - size_t numpeers = bucket_list->size; - while (numpeers--) { - if (stat_increase_network_count(&slash24s_network_counters_root, 0, (uintptr_t)(peers))) - goto bailout_unlock; - peers += peer_size; - } - ++bucket_list; - } - } - mutex_bucket_unlock(bucket, 0); - if (!g_opentracker_running) - goto done; - } - - /* The tree is built. Now analyze */ - stats_return_busy_networks(reply, reply_end, slash24s_network_counters_root, amount, STATS_NETWORK_NODE_MAXDEPTH); - stats_return_busy_networks(reply, reply_end, slash24s_network_counters_root, amount, STATS_NETWORK_NODE_LIMIT); - goto done; - -bailout_unlock: - mutex_bucket_unlock(bucket, 0); -done: - stats_shift_down_network_count(&slash24s_network_counters_root, 0, sizeof(int) * 8 - 1); -} - -#ifdef WANT_SPOT_WOODPECKER static stats_network_node *stats_woodpeckers_tree; static pthread_mutex_t g_woodpeckers_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -699,9 +652,6 @@ static void stats_make(size_t *iovec_entries, struct iovec **iovector, ot_taskty case TASK_STATS_PEERS: stats_peers_mrtg(&r, r_end); break; - case TASK_STATS_SLASH24S: - stats_slash24s_txt(&r, r_end, 128); - break; case TASK_STATS_TOP10: stats_top_txt(&r, r_end, 10); break; diff --git a/src/ot_workqueue.h b/src/ot_workqueue.h index 82ae29b..d8f30d6 100644 --- a/src/ot_workqueue.h +++ b/src/ot_workqueue.h @@ -29,7 +29,6 @@ typedef enum { TASK_STATS = 0x0100, /* Mask */ TASK_STATS_TORRENTS = 0x0101, TASK_STATS_PEERS = 0x0102, - TASK_STATS_SLASH24S = 0x0103, TASK_STATS_TOP10 = 0x0104, TASK_STATS_TOP100 = 0x0105, TASK_STATS_EVERYTHING = 0x0106, diff --git a/tests/integration/test_concurrency.py b/tests/integration/test_concurrency.py index 1374852..528992d 100644 --- a/tests/integration/test_concurrency.py +++ b/tests/integration/test_concurrency.py @@ -148,7 +148,7 @@ class ConcurrentWorkerTasks(TrackerTestCase): def poll(index): for _ in range(10): - for mode in ("everything", "top100", "peer", "torr", "s24s"): + for mode in ("everything", "top100", "peer", "torr"): self.tracker.stats(mode) threads = [threading.Thread(target=announce, args=(i,)) for i in range(THREADS // 2)] diff --git a/tests/integration/test_stats.py b/tests/integration/test_stats.py index c4ac95a..46ca39b 100644 --- a/tests/integration/test_stats.py +++ b/tests/integration/test_stats.py @@ -5,9 +5,7 @@ every one of them and, where the number means something, that it moves when the thing it counts happens. """ -import ipaddress import re -import socket import unittest import urllib.error import xml.etree.ElementTree @@ -18,7 +16,7 @@ from harness import TrackerTestCase # and belong to test_fullscrape; "woodpeckers" sits behind a # feature flag this build does not set. MRTG_MODES = ["peer", "conn", "scrp", "udp4", "tcp4", "torr", "fscr", "completed", "syncs"] -TEXT_MODES = ["herr", "s24s", "top10", "top100", "renew"] +TEXT_MODES = ["herr", "top10", "top100", "renew"] class StatsShape(TrackerTestCase): @@ -144,48 +142,5 @@ class StatsTop(TrackerTestCase): self.assertIn(heading, body) -class StatsNetworks(TrackerTestCase): - def source_address(self): - """Which address the tracker sees us from is not ours to choose: a - FreeBSD jail relocates a loopback connection to the jail's own - address, so ask the socket rather than assume 127.0.0.1.""" - probe = socket.create_connection(("127.0.0.1", self.tracker.port), timeout=5) - try: - return probe.getsockname()[0] - finally: - probe.close() - - def test_the_slash24_report_names_the_announcing_network(self): - source = self.source_address() - self.tracker.announce(self.hash_for("s24"), port=6001, left=0) - body = self.tracker.stats("s24s") - self.assertIn(b"Networks, limit /28:", body) - self.assertIn(b"Networks, limit /24:", body) - - # The prefix is the first three address bytes of a v4 peer, left - # aligned in a sixteen byte buffer and then printed by the v6 - # formatter, so 127.0.0.0/24 reads as "7f00::" rather than as the - # network an operator asked about. Pinned as it is, not blessed. - prefix = socket.inet_aton(source)[:3] + b"\0" * 13 - self.assertIn(str(ipaddress.IPv6Address(prefix)).encode(), body) - - def test_the_report_counts_one_network_per_announcing_address(self): - for port in (6001, 6002, 6003): - self.tracker.announce(self.hash_for("s24count"), port=port, left=0) - lines = [line for line in self.tracker.stats("s24s").splitlines() if b":" in line and b"limit" not in line] - self.assertEqual(len(lines), 2, "one line under each of the two limits") - for line in lines: - self.assertEqual(int(line.split(b":")[0]), 3, "three peers from the one network") - - def test_the_report_survives_a_torrent_with_no_v4_peers(self): - # A torrent whose only peer is v6 has no v4 peer list once the lists - # are allocated on demand. The s24 report walks the v4 list of every - # torrent, so it has to skip the absent one rather than follow a null - # pointer. Needs WANT_IP_FROM_QUERY_STRING to force the family; without - # it the peer is loopback v4 and the walk is never asked to skip. - self.tracker.announce(self.hash_for("s24v6only"), ip="2001:db8::1", port=6001, left=0) - self.assertIn(b"Networks, limit /24:", self.tracker.stats("s24s")) - - if __name__ == "__main__": unittest.main() -- cgit v1.3