Sync: the app's side of the Messaging interface over an abstract transport

imsd keeps a received text it could store until the app deletes it and
sends its signals unicast to subscribers, so the logic is: Subscribe
whenever net.catcrafts.IMS1 appears (imsd's restart empties its list),
then GetStatus, whose answer ends the connecting state, and List, both
at once — a listed or signalled text keys itself by the number it
arrived for (imsd's `to`, the subscriber's own number at receipt) or,
lacking one, by the service centre that delivered it (Model's
MessageFromReceived), so no import waits for a status; import what the
store lacks, keyed by imsd's id (its run's token makes it unique across
imsd's runs, §8.4), and delete imsd's copy — again for a copy still
listed, so a delete that timed out gets another chance. A short message
type 0 (Model's IsType0) is not imported: imsd acknowledged it, and its
copy is deleted like any other. A copy polkit refused to delete is
counted on the banner and tried again at the next List imsd admits (one
polkit action gates List and Delete, so an admitted List means an
admitted Delete) and once imsd has restarted. A Received signal imports
and lists again, because a signal is queued for nobody. The listener is
called through a guard (GuardedListener): a throw out of a handler — a
logging failure, a bad_alloc — is caught and told once, so no handler
can stop Sync's own sequence, whatever the order of a word and the step
after it. A store that refuses a write (its disk full) is on the banner.
A listed text stays imsd's — nothing is deleted — and a signalled one is
held in memory and told through OnUnstored: imsd signals a text its own
store refused too, the signal then its only delivery, so no List may
ever carry it; the held text is tried again whenever a List comes back
with imsd's texts and at each Refresh, which is wanted while one is
held, until its row is in or a List carries it; one imsd did not store
is lost with a process that ends before then. Of the refusal itself the
store tells Sync of a refusal once and once of the next write that got
room (one that grew a file), every write but a Compact passing that one
gate, and the flag stays the store's — read again after the start's
sweep and after imsd's vanish; a send still goes, its own write a try —
refused, it answers kNotStored and the caller keeps the text; through,
it goes to imsd, and imsd's id lands in place (the store keeps it
inline) — a recovery lists at once and the Refresh lists meanwhile, so
the held imports are tried once there is room. A listener's call can
come from inside Sync's own (the store's word on a write, inside Send),
which the listener interface says. A Send stores the message pending
under its conversation key and asks imsd for the address as dialled (the
key groups; a country code completed for it is never dialled), the row
carrying the plan it is dialled under — the country code of the SIM's
own number, never the service centre's stand-in, and its operator, which
imsd's status gives — which a retry under another SIM's plan fails on,
since the address would reach another subscriber or another service
there (Number's AnotherPlan, here with its first caller: the same
operator is the same plan, a side's code known or not; under another
operator a national number means the same while both SIMs' own numbers
have one country code, and a short code is the operator's own; without
both operators the codes decide alone), and the StateChanged for its id
(unique across imsd's runs by the run's token, so it names one message)
moves it on — each word as it comes, imsd giving them in order (the
submission's first, a report's after sent; its AGENTS.md section 8.4) —
and a retry drops the failed attempt's imsd id (a row's id names its
current attempt); a Send's error fails the row and Retry sends the text
again, so the transport's contract (ImsdTransport's comment) is that a
Send is answered by imsd, or because imsd has left the bus, and never by
a clock of the transport's own, since imsd sends what it was asked once
its polkit prompt lets the call through, however late; imsd vanishing
fails what was in flight, and a message still pending from an earlier
run is failed at start, because its answer may have come while the app
was not running. A refused Subscribe or List is the degraded mode: the
banner says so and sending is off — until Refresh is admitted again,
since imsd asks polkit on every gated call and a refusal that held while
the session was inactive lifts when it is active (a List answered ends
it, a refused Subscribe is made again; every refusal is announced, and
RefreshWanted() asks for the Refresh). A Subscribe that fails otherwise,
a GetStatus or a List (one that timed out: the texts imsd holds would
wait for the next signal) is tried again by Refresh too, which
RefreshWanted() asks for — one Subscribe at a time, so a rule that
prompts is not asked again while that Subscribe waits on its prompt; a
registration change reads the status again, since imsd fills in the
subscriber's own number and the service centre's when it registers; the
own number's country code completes a typed national number (a received
one carries its own), the centre's stands in when the network gave no
tel: URI (an MVNO's centre can be abroad); without either a national
number stays as typed, since the store's correspondents do not say where
the subscriber is. The transport is an interface with callbacks, so the
tests' fake can stand in for the bus.

Tested: tests/Sync on a fake transport that records every call and
answers when told, the retries, the second GetStatus, the as-dialled
destination, a retry under another SIM (refused for a national number
under another country's and for a short code under another operator of
the same country; let through under the same operator, its own number
read or not, and for a national number under another operator of its
country), the plan's code the own number's or the constructor's override
and never the centre's, a short message type 0 left out of the store
with imsd's copy deleted, a text signalled before the status's answer
imported at once by the number it arrived for, a listener's throw at a
status — the constructor's among them, over a store that refuses — a log
line and a registration change caught and told, stopping no step, a
Refresh over an unanswered Subscribe sending none, a List that timed out
listed again, the words applied as they come, a retry under a new id,
and a refusal lifted among them; the store's refusal under the file-size
limit (the flag, the Refresh wanted and the log; a send answered
kNotStored with imsd asked nothing; an import refused leaving imsd's
copy with the banner up across imsd's restart; a short text sent through
the refusal, imsd's id landing in place and its `sent` with it, a failed
attempt's id dropped at the retry; then, room again, the send's own
write clearing the flag and the held text imported and deleted at the
List the recovery sends); a signalled text the store refuses that no
List carries (told as unstored once, unread though its conversation is
open, held across a List's answer and a Refresh, stored at the Refresh
after there is room, its delete answered NotFound), one a List does
carry (the copy held here dropped, the text imported by the next List),
and one still held when another write gives the store room (a Refresh
wanted for it alone until the recovery's List is answered); a listed
text the store refuses is not held.
This commit is contained in:
Jorijn van der Graaf 2026-10-17 23:36:20 +02:00
commit f70e9dc35b
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
5 changed files with 1272 additions and 0 deletions

View file

@ -138,6 +138,7 @@ extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> a
cfg.AddTest("Wrap").Dependencies({ Core.get() });
cfg.AddTest("Model").Dependencies({ Core.get() });
cfg.AddTest("Store").Dependencies({ Core.get(), db });
cfg.AddTest("Sync").Dependencies({ Core.get() });
LintRules::AddRules(cfg);
return cfg;