mirror of
https://github.com/Routstr/routstr-core.git
synced 2026-10-05 12:28:22 +00:00
fix: skip non-public analytics relays instead of disabling delivery
This commit is contained in:
@@ -1015,10 +1015,16 @@ class AnalyticsV2Delivery:
|
|||||||
if retry_seconds < 0 or timeout_seconds <= 0:
|
if retry_seconds < 0 or timeout_seconds <= 0:
|
||||||
raise AnalyticsV2DeliveryError("Delivery timing is invalid")
|
raise AnalyticsV2DeliveryError("Delivery timing is invalid")
|
||||||
self._session_factory = session_factory
|
self._session_factory = session_factory
|
||||||
relays = sorted({_normalize_public_wss_url(url) for url in operator_relays})
|
relays: set[str] = set()
|
||||||
|
for url in operator_relays:
|
||||||
|
try:
|
||||||
|
relays.add(_normalize_public_wss_url(url))
|
||||||
|
except AnalyticsV2DeliveryError as error:
|
||||||
|
# The URL itself may carry credentials, so only the reason is logged.
|
||||||
|
logger.warning("Skipping analytics relay", extra={"reason": str(error)})
|
||||||
if not relays:
|
if not relays:
|
||||||
raise AnalyticsV2DeliveryError("At least one analytics relay is required")
|
raise AnalyticsV2DeliveryError("At least one analytics relay is required")
|
||||||
self._targets = tuple(RelayTarget(url) for url in relays)
|
self._targets = tuple(RelayTarget(url) for url in sorted(relays))
|
||||||
self._quorum = min(ANALYTICS_RELAY_QUORUM, len(self._targets))
|
self._quorum = min(ANALYTICS_RELAY_QUORUM, len(self._targets))
|
||||||
self._retry_ms = int(retry_seconds * 1000)
|
self._retry_ms = int(retry_seconds * 1000)
|
||||||
self._timeout_seconds = timeout_seconds
|
self._timeout_seconds = timeout_seconds
|
||||||
|
|||||||
@@ -1079,6 +1079,22 @@ async def test_single_configured_relay_can_deliver_without_a_manifest(
|
|||||||
) == delivery_module.DeliveryPassResult(1, 1)
|
) == delivery_module.DeliveryPassResult(1, 1)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_non_public_relays_are_skipped_instead_of_disabling_delivery(
|
||||||
|
session_factory: async_sessionmaker[AsyncSession],
|
||||||
|
) -> None:
|
||||||
|
delivery = AnalyticsV2Delivery(
|
||||||
|
session_factory,
|
||||||
|
operator_relays=(RELAYS[0], "ws://umbrel.local:4848", "wss://relay.lan"),
|
||||||
|
)
|
||||||
|
assert delivery._targets == (RelayTarget(RELAYS[0]),)
|
||||||
|
|
||||||
|
with pytest.raises(AnalyticsV2DeliveryError, match="At least one"):
|
||||||
|
AnalyticsV2Delivery(
|
||||||
|
session_factory, operator_relays=("ws://umbrel.local:4848",)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_frame_limit_uses_the_required_relay_quorum_and_caches_each_pass(
|
async def test_frame_limit_uses_the_required_relay_quorum_and_caches_each_pass(
|
||||||
session_factory: async_sessionmaker[AsyncSession],
|
session_factory: async_sessionmaker[AsyncSession],
|
||||||
|
|||||||
Reference in New Issue
Block a user