| 1 | // Package daemon assembles the services of a multitenant Nostr relay. |
| 2 | // App owns the tenant catalog, telemetry and active Tenant instances. Each |
| 3 | // Tenant owns one store, its policy snapshot, protocol handlers and background |
| 4 | // services. HTTP, WebSocket and management requests reach domain services |
| 5 | // through these adapters. |
| 6 | // |
| 7 | // # Process and tenant lifetimes |
| 8 | // |
| 9 | // New opens the catalog and telemetry and attempts to resume incomplete tenant |
| 10 | // creation. |
| 11 | // Start acquires the serving process lock, opens ready tenants and starts |
| 12 | // catalog reconciliation. The caller serves App as an HTTP handler and calls |
| 13 | // Close after stopping its HTTP listeners. Close stops reconciliation, closes |
| 14 | // tenants, releases shared resources and releases the process lock. The |
| 15 | // optional peer monitor runs under the context passed to PeerMonitorRun. |
| 16 | // |
| 17 | // A tenant initializes community state and its admission gate before building |
| 18 | // the protocol and feature services. Custom-view storage is ready when Git |
| 19 | // initialization can promote repository events; the Git service is then bound |
| 20 | // to the view service. Handler registration completes before worker goroutines |
| 21 | // start. Tenant.Close stops new operations, cancels and joins background work, |
| 22 | // closes live connections and drains active operations before closing storage. |
| 23 | // |
| 24 | // # Admission and persistence |
| 25 | // |
| 26 | // Tenant implements the relay backend and the typed room reader used by the |
| 27 | // web UI. Execute dispatches management methods under the supplied actor's |
| 28 | // current authority. HTTP and WebSocket adapters establish that actor through |
| 29 | // request authentication. Policy returns a read-only snapshot; policy changes |
| 30 | // are serialized and replace the snapshot after persistence succeeds. |
| 31 | // |
| 32 | // Client publication and replication ingestion use eventCommitter to compose |
| 33 | // event storage, domain projections and durable intents. Client entry points |
| 34 | // also process membership, moderation and room actions. The relay router owns |
| 35 | // live event delivery. A repository state stays pending until Git promotion |
| 36 | // makes its referenced objects available. |
| 37 | // |
| 38 | // # Optional work and maintenance |
| 39 | // |
| 40 | // callbackService owns webhook registrations and delivery. customViewService |
| 41 | // owns transform definitions, requests and signed artifacts. eventFollowups |
| 42 | // captures matching registrations and persists planning work with accepted |
| 43 | // events. Planning checks current sources and registrations, uses stable work |
| 44 | // identities and retries within bounded attempts and age. Each feature's |
| 45 | // handler owns its remote delivery or transform policy. |
| 46 | // |
| 47 | // The maintenance gate admits ordinary operations while exclusive maintenance |
| 48 | // is idle. A maintenance operation blocks new admissions and drains active |
| 49 | // operations. Nested calls carry the admission in their context, and callers |
| 50 | // release it with the returned completion function. Workers use the same gate |
| 51 | // while operating on the tenant's services and store. |
| 52 | package daemon |