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