summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2026-11-03 06:02:47 +0100
committerDirk Engling <erdgeist@erdgeist.org>2026-11-03 06:02:47 +0100
commitf16ea39889c0fd65f3e533cf40cc3a0a33ac1c33 (patch)
treece43369ece6303d35737b95ed203936f1cb2eb73 /tests
parentb142979a036ac53c4e59e1906fed01a76198ba84 (diff)
Let a user pick their cluster's own multicast groupHEADmaster
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/harness.py4
-rw-r--r--tests/integration/test_livesync.py42
2 files changed, 44 insertions, 2 deletions
diff --git a/tests/integration/harness.py b/tests/integration/harness.py
index a9d38ca..10aa6de 100644
--- a/tests/integration/harness.py
+++ b/tests/integration/harness.py
@@ -192,7 +192,7 @@ class Tracker:
192 def torrent_count(self): 192 def torrent_count(self):
193 return int(self.stats("torr").split()[0]) 193 return int(self.stats("torr").split()[0])
194 194
195 def livesync_send(self, payload): 195 def livesync_send(self, payload, group=LIVESYNC_GROUP):
196 """Put a packet on the live sync group. 196 """Put a packet on the live sync group.
197 197
198 It has to go to the group rather than straight at the port: the 198 It has to go to the group rather than straight at the port: the
@@ -204,7 +204,7 @@ class Tracker:
204 sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_IF, socket.inet_aton("127.0.0.1")) 204 sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_IF, socket.inet_aton("127.0.0.1"))
205 sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_LOOP, 1) 205 sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_LOOP, 1)
206 sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 1) 206 sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 1)
207 sock.sendto(payload, (LIVESYNC_GROUP, self.livesync_port)) 207 sock.sendto(payload, (group, self.livesync_port))
208 finally: 208 finally:
209 sock.close() 209 sock.close()
210 210
diff --git a/tests/integration/test_livesync.py b/tests/integration/test_livesync.py
index 3a9ee58..52e871f 100644
--- a/tests/integration/test_livesync.py
+++ b/tests/integration/test_livesync.py
@@ -164,3 +164,45 @@ class LiveSyncUnconfigured(TrackerTestCase):
164 for i in range(200): 164 for i in range(200):
165 self.tracker.announce(self.hash_for("no-cluster-%d" % i), port=6881 + i, left=0) 165 self.tracker.announce(self.hash_for("no-cluster-%d" % i), port=6881 + i, left=0)
166 self.assertEqual(self.tracker.torrent_count(), 200) 166 self.assertEqual(self.tracker.torrent_count(), 200)
167
168
169# RFC 2365 sets 239.192.0.0/14 aside for exactly this kind of use
170OWN_GROUP = "239.192.0.7"
171
172
173@unittest.skipUnless(has_livesync(), "this build has no WANT_SYNC_LIVE")
174class LiveSyncGroup(TrackerTestCase):
175 config = ("livesync.cluster.group %s\n"
176 "livesync.cluster.listen 127.0.0.1:{livesync_port}\n"
177 "livesync.cluster.node_ip 127.0.0.1\n" % OWN_GROUP)
178
179 def test_the_configured_group_is_joined(self):
180 info_hash = self.hash_for("own-group")
181 self.tracker.livesync_send(packet(SYNC_PEER4, [(info_hash, peer4("10.1.3.1", 6881, FLAG_SEEDING))]),
182 group=OWN_GROUP)
183 self.assertTrue(self.tracker.wait_until(lambda: self.tracker.torrent_count() == 1))
184
185 def test_the_default_group_is_left_alone(self):
186 """A cluster that picked its own group should not hear the one every
187 other opentracker is on."""
188 info_hash = self.hash_for("not-our-group")
189 self.tracker.livesync_send(packet(SYNC_PEER4, [(info_hash, peer4("10.1.3.2", 6881, FLAG_SEEDING))]))
190 self.assertFalse(self.tracker.wait_until(lambda: self.tracker.torrent_count() != 0, timeout=1))
191
192
193@unittest.skipUnless(has_livesync(), "this build has no WANT_SYNC_LIVE")
194class LiveSyncGroupRefused(TrackerTestCase):
195 """A unicast address is not a group. The line is refused like any other
196 bad config line, which leaves the default standing."""
197
198 config = ("livesync.cluster.group 10.0.0.1\n"
199 "livesync.cluster.listen 127.0.0.1:{livesync_port}\n"
200 "livesync.cluster.node_ip 127.0.0.1\n")
201
202 def test_the_line_is_refused(self):
203 self.assertIn("Parse error", self.tracker.output())
204
205 def test_and_the_default_group_still_works(self):
206 info_hash = self.hash_for("fallback-group")
207 self.tracker.livesync_send(packet(SYNC_PEER4, [(info_hash, peer4("10.1.3.3", 6881, FLAG_SEEDING))]))
208 self.assertTrue(self.tracker.wait_until(lambda: self.tracker.torrent_count() == 1))