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.
BIP-173 restricts a bech32 string to printable US-ASCII (33..126). The
check has to run before the case test and before lowercase(): U+212A
KELVIN SIGN reads as uppercase, so an otherwise all-uppercase string
carrying one shows no mixed case, and lowercase() folds it to an ASCII
'k' -- an npub with a homoglyph in place of a K decoded to the same
pubkey as the genuine one.
The added test builds that exact string and expects a rejection; it
fails on the previous commit.
Uppercase decodes to the same payload as lowercase, mixed case is
rejected, a corrupted uppercase string still fails on the checksum rather
than on the charset, and encode/decode round-trips.
BIP-173 defines a bech32 string as all lowercase or all uppercase, and
declares mixed case invalid. The decoder only looked up lowercase
characters in the charset, so an all-uppercase npub - the form QR
encoders emit, because uppercase fits the denser alphanumeric mode -
failed with "Invalid character" before the checksum was ever checked.
Normalise case once, after rejecting a mixed-case string outright.
ContactIdentityResolver already worked around this by lowercasing at the
call site; NostrClient.sendPrivateMessage does not, so an npub that came
in uppercase could not be messaged.