If SQLite clearAll fails mid-panic, in-memory state was already cleared
but a process restart could reload encrypted history from disk (#699).
Fall back to deleting the database files before reporting failure.
A relay that fails is retried on an exponential backoff, then abandoned
for the lifetime of the process. Nothing brings it back: the relay layer
registers no connectivity callback, the periodic subscription validator
only repairs subscriptions on sockets that are already open (and returns
immediately when connectedRelayCount is 0, which is exactly the state
after an outage), and connect() runs once from NostrClient.initialize().
The remaining paths that reset reconnectAttempts are a manual retry, a
Tor state change, and a successful open.
Two ways a relay died permanently:
- Any error whose message mentioned DNS returned before scheduling
anything at all. "Unable to resolve host" is what this device reports
when it simply has no network, so a moment in a tunnel killed every
relay at once, with no retry ever.
- Otherwise the schedule stopped at MAX_RECONNECT_ATTEMPTS. With
INITIAL=1s and MULTIPLIER=2 that is nine waits totalling about eight
and a half minutes, after which the relay was dead. MAX_BACKOFF_INTERVAL
was unreachable: attempt 9 asks for 256s and attempt 10 gave up, so the
five-minute ceiling the constant defines never applied to anything.
Let the backoff saturate at MAX_BACKOFF_INTERVAL and keep retrying there.
A name-resolution failure now backs off like any other error. Steady state
costs one connection attempt per relay per five minutes; the previous
behaviour cost the user every internet DM, delivery receipt and geohash
channel until they noticed and restarted the app.
The schedule moves into RelayReconnectPolicy so it is unit-testable
without OkHttp or a Context.
Round trip with the built parameters, out-of-range p (0, 33, 64, 200,
255) decoding to nothing, and degenerate m (0, 1) decoding to nothing.
The p case fails without the guard: p = 0 yields 105 fabricated values.
decodeToSortedSet takes p and m straight off the wire - REQUEST_SYNC
carries P as a uint8, so 0..255 all arrive - and decodes with them
regardless. Kotlin's shift operators use the low 6 bits of the count, so
p >= 64 wraps and the decoder emits values that were never in the filter;
p = 0 turns every remainder into a zero-width read and manufactures a
value per bit. On today's 20-id filter, p = 0 decodes 105 values.
Those values are read as "the peer already has this packet", so the
responder withholds packets the peer actually lacks - the failure
direction that loses messages.
Guard the parameters as iOS does in GCSFilter.decodeToSortedSet: p in
1..32 and m > 1, otherwise decode to nothing, which callers read as "peer
has nothing" and answer by sending the data.