| 1 | package daemon |
| 2 | |
| 3 | import ( |
| 4 | "net/http" |
| 5 | "sync" |
| 6 | |
| 7 | "github.com/FelineStateMachine/tinyrelay/internal/catalog" |
| 8 | "github.com/FelineStateMachine/tinyrelay/internal/community" |
| 9 | "github.com/FelineStateMachine/tinyrelay/internal/gates" |
| 10 | "github.com/FelineStateMachine/tinyrelay/internal/policy" |
| 11 | "github.com/FelineStateMachine/tinyrelay/internal/storage" |
| 12 | "github.com/FelineStateMachine/tinyrelay/internal/telemetry" |
| 13 | ) |
| 14 | |
| 15 | // callbackService owns callback registration, matching and durable delivery. |
| 16 | // It borrows the tenant store, community and gate. Per-registration locks |
| 17 | // serialize remote delivery; the daemon owns worker startup and shutdown. |
| 18 | type callbackService struct { |
| 19 | store *storage.Store |
| 20 | community *community.Service |
| 21 | gate *gates.Gate |
| 22 | policy func() policy.Policy |
| 23 | publicURL string |
| 24 | relayURL string |
| 25 | tenant catalog.Tenant |
| 26 | telemetry *telemetry.Telemetry |
| 27 | |
| 28 | callbackMu sync.Mutex |
| 29 | callbackIndex map[int][]callbackRecord |
| 30 | callbackLocks map[string]*sync.Mutex |
| 31 | callbackClient *http.Client |
| 32 | } |
| 33 | |
| 34 | // callbackServiceConfig binds storage, current policy and visibility checks. |
| 35 | // PublicURL identifies the HTTP relay in deliveries; RelayURL supplies the |
| 36 | // WebSocket address used by event visibility checks. |
| 37 | type callbackServiceConfig struct { |
| 38 | Store *storage.Store |
| 39 | Community *community.Service |
| 40 | Gate *gates.Gate |
| 41 | Policy func() policy.Policy |
| 42 | PublicURL string |
| 43 | RelayURL string |
| 44 | Tenant catalog.Tenant |
| 45 | Telemetry *telemetry.Telemetry |
| 46 | } |
| 47 | |
| 48 | func newCallbackService(cfg callbackServiceConfig) *callbackService { |
| 49 | return &callbackService{ |
| 50 | store: cfg.Store, community: cfg.Community, gate: cfg.Gate, |
| 51 | policy: cfg.Policy, publicURL: cfg.PublicURL, relayURL: cfg.RelayURL, |
| 52 | tenant: cfg.Tenant, telemetry: cfg.Telemetry, |
| 53 | } |
| 54 | } |