Skip to main content

euv_cli/update_server/
struct.rs

1use super::*;
2
3/// Configuration for the read-only Hyperlane HTTP + SSE update server (never holds signing keys).
4#[derive(Clone, Data, Debug, Deserialize, Eq, PartialEq, Serialize)]
5pub struct UpdateServerConfig {
6    /// Local filesystem store root containing `staging/`, `blobs/`, `releases/`, `channels/`, and `state/`.
7    pub(crate) store_root: PathBuf,
8    /// Bind host address (default `127.0.0.1`).
9    pub(crate) host: String,
10    /// Bind TCP port (`0` selects an ephemeral port).
11    #[get(type(copy))]
12    pub(crate) port: u16,
13    /// Optional external reverse-proxy base URL (e.g. `https://ota.example.com/euv`).
14    #[serde(default)]
15    pub(crate) proxy_base: String,
16    /// SSE keep-alive heartbeat interval in milliseconds.
17    #[get(type(copy))]
18    pub(crate) heartbeat_ms: u64,
19    /// SSE client reconnect retry hint in milliseconds.
20    #[get(type(copy))]
21    pub(crate) retry_ms: u64,
22    /// Bounded per-topic SSE `Last-Event-ID` replay buffer size.
23    #[get(type(copy))]
24    pub(crate) replay_capacity: usize,
25    /// Filesystem pointer watcher polling interval in milliseconds.
26    #[get(type(copy))]
27    pub(crate) watch_poll_ms: u64,
28    /// Maximum allowed artifact byte size enforced during staging and publishing.
29    #[get(type(copy))]
30    pub(crate) max_artifact_bytes: u64,
31    /// When `true`, initializes the store, validates bind readiness, and exits immediately.
32    #[get(type(copy))]
33    pub(crate) once: bool,
34}
35
36/// Atomically swapped active release pointer persisted in `channels/<project>/<channel>/active.json`.
37#[derive(Clone, Data, Debug, Default, Deserialize, Eq, New, PartialEq, Serialize)]
38pub struct ChannelPointer {
39    /// Logical project identifier.
40    pub(crate) project: String,
41    /// Release channel name.
42    pub(crate) channel: String,
43    /// Compatibility track label.
44    pub(crate) track: String,
45    /// Strictly monotonic active release sequence number.
46    #[get(type(copy))]
47    pub(crate) active_release_seq: u64,
48    /// SHA-256 hex digest of the active signed `ReleaseManifest`.
49    pub(crate) manifest_sha256: String,
50    /// UNIX epoch timestamp in seconds of the atomic pointer swap.
51    #[get(type(copy))]
52    pub(crate) updated_at_unix: u64,
53}
54
55/// Persisted bounded event record written to `state/events/<project>/<channel>.jsonl`.
56#[derive(Clone, Data, Debug, Deserialize, Eq, New, PartialEq, Serialize)]
57pub struct StoredReleaseEvent {
58    /// Monotonic event identifier matching `event.to_release`.
59    #[get(type(copy))]
60    pub(crate) event_id: u64,
61    /// Minimal `release.activated` metadata frame.
62    pub(crate) event: ReleaseActivatedEvent,
63}
64
65/// Local filesystem update store managing `staging/`, `blobs/sha256/`, `releases/`, `channels/`, and `state/`.
66#[derive(Clone, Data, Debug, Eq, New, PartialEq)]
67pub struct UpdateStore {
68    /// Root filesystem directory of the update store.
69    pub(crate) root: PathBuf,
70    /// Maximum allowed byte size for any single artifact (`0` disables cap).
71    #[new(skip)]
72    #[get(type(copy))]
73    pub(crate) max_artifact_bytes: u64,
74}
75
76/// RAII writer lock guard owning `state/writer.lock` across multi-process CLI publish/rollback operations.
77#[derive(Debug)]
78pub(crate) struct UpdateWriterLockGuard {
79    /// Lockfile path removed automatically on drop.
80    pub(crate) lock_path: PathBuf,
81}
82
83/// Summary report emitted by `euv update stage`.
84#[derive(Clone, Data, Debug, Deserialize, Eq, New, PartialEq, Serialize)]
85pub struct StageReport {
86    /// Stage identifier inside `staging/`.
87    pub(crate) stage_id: String,
88    /// Logical project identifier.
89    pub(crate) project: String,
90    /// Target release channel.
91    pub(crate) channel: String,
92    /// Number of verified blobs staged.
93    #[get(type(copy))]
94    pub(crate) blob_count: usize,
95    /// Total verified staged bytes.
96    #[get(type(copy))]
97    pub(crate) total_bytes: u64,
98}
99
100/// Summary report emitted by `euv update publish` and `euv update rollback`.
101#[derive(Clone, Data, Debug, Deserialize, Eq, New, PartialEq, Serialize)]
102pub struct PublishReport {
103    /// Logical project identifier.
104    pub(crate) project: String,
105    /// Release channel name.
106    pub(crate) channel: String,
107    /// Compatibility track name.
108    pub(crate) track: String,
109    /// Previous active release sequence (`0` if initial release).
110    #[get(type(copy))]
111    pub(crate) from_release: u64,
112    /// Newly activated strictly monotonic release sequence.
113    #[get(type(copy))]
114    pub(crate) to_release: u64,
115    /// Optional historical release sequence targeted when this publish is a rollback.
116    #[new(skip)]
117    #[get(skip)]
118    pub(crate) rollback_of: Option<u64>,
119    /// SHA-256 hex digest of the sealed signed manifest.
120    pub(crate) manifest_sha256: String,
121    /// Routes whose pinned dependency graphs changed.
122    #[new(skip)]
123    pub(crate) affected_routes: Vec<String>,
124    /// Number of new blobs written into `blobs/sha256/`.
125    #[new(skip)]
126    #[get(type(copy))]
127    pub(crate) blobs_written: usize,
128}
129
130/// Status summary for a single project/channel inside `UpdateStoreStatus`.
131#[derive(Clone, Data, Debug, Deserialize, Eq, New, PartialEq, Serialize)]
132pub struct ChannelStatusEntry {
133    /// Logical project identifier.
134    pub(crate) project: String,
135    /// Channel name.
136    pub(crate) channel: String,
137    /// Current active channel pointer.
138    pub(crate) pointer: ChannelPointer,
139    /// Number of immutable release manifests stored under this channel.
140    #[get(type(copy))]
141    pub(crate) release_count: usize,
142    /// Number of retained event log records under `state/events/`.
143    #[get(type(copy))]
144    pub(crate) event_count: usize,
145}
146
147/// Complete status snapshot emitted by `euv update status`.
148#[derive(Clone, Data, Debug, Deserialize, Eq, New, PartialEq, Serialize)]
149pub struct UpdateStoreStatus {
150    /// Store root path string.
151    pub(crate) store_root: String,
152    /// Total immutable blobs currently stored in `blobs/sha256/`.
153    #[get(type(copy))]
154    pub(crate) blob_count: usize,
155    /// Total disk bytes occupied by immutable blobs.
156    #[get(type(copy))]
157    pub(crate) blob_total_bytes: u64,
158    /// Active channel summaries.
159    pub(crate) channels: Vec<ChannelStatusEntry>,
160}
161
162/// Machine-readable report emitted by `euv update serve`.
163#[derive(Clone, Data, Debug, Deserialize, Eq, New, PartialEq, Serialize)]
164pub struct UpdateServerReport {
165    /// Store root directory served.
166    pub(crate) store_root: String,
167    /// Bound HTTP base URL (e.g. `http://127.0.0.1:8787`).
168    pub(crate) url: String,
169    /// Manifest endpoint route template.
170    pub(crate) manifest_route: String,
171    /// Blob endpoint route template.
172    pub(crate) blob_route: String,
173    /// SSE events endpoint route template.
174    pub(crate) events_route: String,
175    /// Whether the server exited immediately after readiness validation (`--once`).
176    #[get(type(copy))]
177    pub(crate) once: bool,
178}
179
180/// Shared state mounted into Hyperlane routes for read-only manifest, blob, and SSE delivery.
181#[cfg(feature = "update-server")]
182#[derive(Clone)]
183pub struct UpdateServerState {
184    /// Backing atomic local filesystem update store.
185    pub(crate) store: UpdateStore,
186    /// Shared Hyperlane SSE pub/sub hub with bounded `Last-Event-ID` replay.
187    pub(crate) sse_hub: SseHub,
188    /// SSE stream heartbeat and reconnect configuration.
189    pub(crate) sse_config: SseConfig,
190    /// Optional configured reverse-proxy base URL advertised to clients.
191    pub(crate) proxy_base: String,
192    /// Last release sequence dispatched per `(project, channel)` to ensure exactly-once SSE fan-out per sequence.
193    pub(crate) dispatched_seqs: Arc<Mutex<HashMap<(String, String), u64>>>,
194    /// Cooperative running flag shared with the background pointer watcher.
195    pub(crate) running: Arc<AtomicBool>,
196}
197
198/// Running handle to a live Hyperlane HTTP + SSE update server with clean programmatic shutdown.
199#[cfg(feature = "update-server")]
200pub struct UpdateServerHandle {
201    /// Bound socket address (`ip:port`).
202    pub(crate) address: SocketAddr,
203    /// Shared update server state (store + SSE hub).
204    pub(crate) state: Arc<UpdateServerState>,
205    /// Hyperlane shutdown control hook.
206    pub(crate) control: Option<ServerControlHook>,
207    /// Dedicated Tokio runtime hosting the Hyperlane server and pointer watcher.
208    pub(crate) runtime: Option<runtime::Runtime>,
209}
210
211/// Hyperlane `ServerHook` serving `GET /v1/projects/{project}/channels/{channel}/manifest`.
212#[cfg(feature = "update-server")]
213pub struct ManifestRouteHook;
214
215/// Hyperlane `ServerHook` serving `GET /v1/blobs/{sha256}` with Range resume support.
216#[cfg(feature = "update-server")]
217pub struct BlobRouteHook;
218
219/// Hyperlane `ServerHook` streaming `GET /v1/projects/{project}/channels/{channel}/events` via `hyperlane-plugin-sse`.
220#[cfg(feature = "update-server")]
221pub struct EventsRouteHook;