1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
// This file is part of the Aurelia workspace.
// SPDX-FileCopyrightText: 2026 Zivatar Limited
// SPDX-License-Identifier: Apache-2.0
//! # Aurelia
//!
//! An embeddable service mesh for Rust applications. Aurelia gives a Rust
//! process a built-in, authenticated peer-to-peer fabric — no sidecar, no
//! control plane, no extra runtime to deploy.
//!
//! ## Layer model
//!
//! - **A0 — Transport authentication.** mTLS over TCP, or PKCS#8 certificate-backed
//! authentication over Unix domain sockets. A0 completes before any A1 frames are exchanged.
//! - **A1 — Message and blob transfer.** Delivery, callis (per-peer
//! connection flow), and taberna (named inbound endpoint) management.
//! - **A2 — Aurelia services.** Higher-level capabilities built on A1 (in
//! progress; the current release ships A0 and A1 with the wrapper API).
//! - **A3 — Application.** Your code. All A3-to-A3 traffic transits A1.
//!
//! ## Quick start
//!
//! Initialise the Aurelia runtime and build a [`Domus`] (the local peer)
//! bound to a TCP address with PKCS#8 mTLS material:
//!
//! ```no_run
//! use std::sync::Arc;
//! use aurelia::{Aurelia, DomusAddr, DomusConfigBuilder,
//! Pkcs8AuthConfig, Pkcs8PemConfig, SimpleResolver};
//!
//! # async fn run() -> Result<(), aurelia::AureliaError> {
//! let aurelia = Aurelia::new();
//!
//! let config = DomusConfigBuilder::new().build()?;
//! let auth = Pkcs8AuthConfig::Pkcs8Pem(Pkcs8PemConfig {
//! ca_pem: std::fs::read("ca.pem").unwrap(),
//! cert_pem: std::fs::read("cert.pem").unwrap(),
//! pkcs8_key_pem: std::fs::read("key.pem").unwrap().into(),
//! });
//!
//! let domus = aurelia
//! .domus_builder(
//! config,
//! DomusAddr::Tcp("127.0.0.1:7000".parse().unwrap()),
//! auth,
//! Arc::new(SimpleResolver::new()),
//! )
//! .build()
//! .await?;
//!
//! // Use `domus.taberna(...)` to register inbound endpoints, and
//! // `domus.send(...)` to dispatch messages to peers.
//! # Ok(()) }
//! ```
//!
//! ## Where to look next
//!
//! - [`Aurelia`] — runtime initializer and entry point.
//! - [`DomusBuilder`] — configures and builds a [`Domus`].
//! - [`Domus`] — the running local peer.
//! - [`Taberna`] — a named inbound endpoint on a domus.
//! - [`DomusConfig`] / [`DomusConfigBuilder`] — tuning knobs and validation.
//! - [`AureliaError`] / [`ErrorId`] — the single error type used across the API.
//! - [`DomusReporting`] / [`DomusReportingEvent`] — observability streams.
//! - [`a3_message_type`] — derives application message-type IDs in the A3 range.
use Arc;
pub use crate;
pub use crate;
/// Registration handle for an Actix-backed taberna.
///
/// Dropping the handle schedules deregistration from its parent domus. The taberna ID becomes
/// available for reuse once the spawned deregistration task completes.
///
/// # Example
///
/// ```no_run
/// use actix::{Actor, Context, Handler};
/// use aurelia::{
/// a3_message_type, ActixTabernaDelivery, AureliaError, Domus, EncodedMessage, ErrorId,
/// MessageCodec, MessageType, RouteResolver,
/// };
///
/// struct TextCodec;
///
/// impl MessageCodec for TextCodec {
/// type AppMessage = String;
///
/// fn encode_app(&self, msg: &Self::AppMessage) -> Result<EncodedMessage, AureliaError> {
/// Ok(EncodedMessage::new(
/// a3_message_type(0),
/// msg.as_bytes().to_vec().into(),
/// ))
/// }
///
/// fn decode_app(
/// &self,
/// msg_type: MessageType,
/// payload: &[u8],
/// ) -> Result<Self::AppMessage, AureliaError> {
/// if msg_type != a3_message_type(0) {
/// return Err(AureliaError::new(ErrorId::DecodeFailure));
/// }
/// String::from_utf8(payload.to_vec())
/// .map_err(|err| AureliaError::with_message(ErrorId::DecodeFailure, err.to_string()))
/// }
/// }
///
/// struct TextActor;
///
/// impl Actor for TextActor {
/// type Context = Context<Self>;
/// }
///
/// impl Handler<ActixTabernaDelivery<String>> for TextActor {
/// type Result = ();
///
/// fn handle(
/// &mut self,
/// delivery: ActixTabernaDelivery<String>,
/// _ctx: &mut Self::Context,
/// ) -> Self::Result {
/// let _message = delivery.message;
/// }
/// }
///
/// # async fn example<RR: RouteResolver>(domus: &Domus<RR>) -> Result<(), AureliaError> {
/// let recipient = TextActor.start().recipient();
/// let _taberna = domus.actix_taberna(42, TextCodec, recipient).await?;
/// # Ok(()) }
/// ```
pub use crateActixTaberna;
pub use crateActixTabernaDelivery;
pub use cratePeerIdentityReport;
pub use crate;
pub use crate;
pub use crate;
pub use crateSimpleResolver;
/// A running Aurelia domus: the local peer's representation in the mesh.
///
/// A [`Domus`] owns a single bound transport (TCP+mTLS or Unix socket)
/// and the registry of [`Taberna`]s hosted on this peer. Outbound traffic is
/// dispatched through the configured [`RouteResolver`]; inbound traffic is
/// delivered to the relevant taberna's inbox.
///
/// Construct one via [`Aurelia::domus_builder`] (recommended) or directly via
/// [`DomusBuilder`].
///
/// # Example
///
/// ```no_run
/// use std::sync::Arc;
/// use aurelia::{
/// Aurelia, DomusAddr, DomusConfigBuilder, Pkcs8AuthConfig, Pkcs8PemConfig,
/// SimpleResolver,
/// };
///
/// # async fn example() -> Result<(), aurelia::AureliaError> {
/// let aurelia = Aurelia::new();
/// let config = DomusConfigBuilder::new().build()?;
/// let auth = Pkcs8AuthConfig::Pkcs8Pem(Pkcs8PemConfig {
/// ca_pem: vec![],
/// cert_pem: vec![],
/// pkcs8_key_pem: vec![].into(),
/// });
/// let domus = aurelia
/// .domus_builder(
/// config,
/// DomusAddr::Tcp("127.0.0.1:7000".parse().unwrap()),
/// auth,
/// Arc::new(SimpleResolver::new()),
/// )
/// .build()
/// .await?;
/// # let _ = domus.local_addr();
/// # Ok(()) }
/// ```
///
/// Sending a typed application message:
///
/// ```no_run
/// use aurelia::{
/// a3_message_type, AureliaError, Domus, EncodedMessage, ErrorId, MessageCodec, MessageType,
/// RouteResolver, SendOptions, SendOutcome,
/// };
///
/// struct TextCodec;
///
/// impl MessageCodec for TextCodec {
/// type AppMessage = String;
///
/// fn encode_app(&self, msg: &Self::AppMessage) -> Result<EncodedMessage, AureliaError> {
/// Ok(EncodedMessage::new(
/// a3_message_type(0),
/// msg.as_bytes().to_vec().into(),
/// ))
/// }
///
/// fn decode_app(
/// &self,
/// msg_type: MessageType,
/// payload: &[u8],
/// ) -> Result<Self::AppMessage, AureliaError> {
/// if msg_type != a3_message_type(0) {
/// return Err(AureliaError::new(ErrorId::DecodeFailure));
/// }
/// String::from_utf8(payload.to_vec())
/// .map_err(|err| AureliaError::with_message(ErrorId::DecodeFailure, err.to_string()))
/// }
/// }
///
/// # async fn example<RR: RouteResolver>(domus: &Domus<RR>) -> Result<(), AureliaError> {
/// let outcome = domus
/// .send(
/// &TextCodec,
/// 42,
/// &"ping".to_owned(),
/// SendOptions::MESSAGE_ONLY,
/// )
/// .await?;
/// assert!(matches!(outcome, SendOutcome::MessageOnly));
/// # Ok(()) }
/// ```
///
/// Starting a blob transfer:
///
/// ```no_run
/// use tokio::io::AsyncWriteExt;
/// use aurelia::{
/// a3_message_type, AureliaError, Domus, EncodedMessage, ErrorId, MessageCodec, MessageType,
/// RouteResolver, SendOptions, SendOutcome,
/// };
///
/// struct TextCodec;
///
/// impl MessageCodec for TextCodec {
/// type AppMessage = String;
///
/// fn encode_app(&self, msg: &Self::AppMessage) -> Result<EncodedMessage, AureliaError> {
/// Ok(EncodedMessage::new(
/// a3_message_type(0),
/// msg.as_bytes().to_vec().into(),
/// ))
/// }
///
/// fn decode_app(
/// &self,
/// msg_type: MessageType,
/// payload: &[u8],
/// ) -> Result<Self::AppMessage, AureliaError> {
/// if msg_type != a3_message_type(0) {
/// return Err(AureliaError::new(ErrorId::DecodeFailure));
/// }
/// String::from_utf8(payload.to_vec())
/// .map_err(|err| AureliaError::with_message(ErrorId::DecodeFailure, err.to_string()))
/// }
/// }
///
/// # async fn example<RR: RouteResolver>(domus: &Domus<RR>) -> Result<(), AureliaError> {
/// let outcome = domus
/// .send(&TextCodec, 42, &"blob incoming".to_owned(), SendOptions::BLOB)
/// .await?;
/// let SendOutcome::Blob { mut sender } = outcome else {
/// unreachable!("BLOB send option returns a blob sender");
/// };
/// sender
/// .write_all(b"blob bytes")
/// .await
/// .map_err(|err| AureliaError::with_message(ErrorId::PeerUnavailable, err.to_string()))?;
/// sender
/// .shutdown()
/// .await
/// .map_err(|err| AureliaError::with_message(ErrorId::PeerUnavailable, err.to_string()))?;
/// # Ok(()) }
/// ```
pub use crateDomus;
/// A registered inbound endpoint on a [`Domus`].
///
/// Each taberna has a stable [`TabernaId`] and a typed [`MessageCodec`]; received
/// messages are decoded with that codec and surfaced as [`TabernaRequest`]s via
/// [`Taberna::next`].
///
/// Tabernas are constructed with [`Domus::taberna`]; dropping a [`Taberna`]
/// unregisters it from the parent domus.
///
/// # Example
///
/// ```no_run
/// use aurelia::{
/// a3_message_type, AureliaError, EncodedMessage, ErrorId, MessageCodec, MessageType,
/// };
///
/// struct TextCodec;
///
/// impl MessageCodec for TextCodec {
/// type AppMessage = String;
///
/// fn encode_app(&self, msg: &Self::AppMessage) -> Result<EncodedMessage, AureliaError> {
/// Ok(EncodedMessage::new(
/// a3_message_type(0),
/// msg.as_bytes().to_vec().into(),
/// ))
/// }
///
/// fn decode_app(
/// &self,
/// msg_type: MessageType,
/// payload: &[u8],
/// ) -> Result<Self::AppMessage, AureliaError> {
/// if msg_type != a3_message_type(0) {
/// return Err(AureliaError::new(ErrorId::DecodeFailure));
/// }
/// String::from_utf8(payload.to_vec())
/// .map_err(|err| AureliaError::with_message(ErrorId::DecodeFailure, err.to_string()))
/// }
/// }
///
/// # async fn example<RR: aurelia::RouteResolver>(
/// # domus: aurelia::Domus<RR>,
/// # ) -> Result<(), AureliaError> {
/// let taberna = domus.taberna(42, TextCodec).await?;
/// let request = taberna.next(None).await?;
/// request.accept();
/// # Ok(()) }
/// ```
pub use crateTaberna;
/// Runtime owner and entry point for the Aurelia library.
///
/// `Aurelia` initialises and owns the internal Tokio runtime that all
/// Aurelia background work runs on. The runtime handle is intentionally
/// not exposed: applications keep their own runtime for their own work and
/// interact with Aurelia only through this wrapper. Construct one via
/// [`Aurelia::new`] at program start, then build a [`Domus`] via
/// [`Aurelia::domus_builder`].
///
/// # Example
///
/// ```
/// use aurelia::Aurelia;
///
/// let aurelia = Aurelia::new();
/// // The Aurelia runtime is now ready; use `aurelia.domus_builder(...)`
/// // to construct domuses.
/// # let _ = aurelia;
/// ```
/// Builder for a [`Domus`] wired to the Aurelia runtime.
///
/// Obtain one via [`Aurelia::domus_builder`]. Calling [`DomusBuilder::build`]
/// validates the supplied [`DomusConfig`], performs the A0 bind (mTLS or
/// Unix socket), and resolves to a running [`Domus`]. Use
/// [`DomusBuilder::build_with_reporting`] to receive observability feeds
/// alongside the built domus.
///
/// # Example
///
/// ```no_run
/// use std::sync::Arc;
/// use aurelia::{Aurelia, DomusAddr, DomusConfigBuilder,
/// Pkcs8AuthConfig, Pkcs8PemConfig, SimpleResolver};
///
/// # async fn run() -> Result<(), aurelia::AureliaError> {
/// let aurelia = Aurelia::new();
/// let domus = aurelia
/// .domus_builder(
/// DomusConfigBuilder::new().build()?,
/// DomusAddr::Tcp("127.0.0.1:7001".parse().unwrap()),
/// Pkcs8AuthConfig::Pkcs8Pem(Pkcs8PemConfig {
/// ca_pem: vec![], cert_pem: vec![], pkcs8_key_pem: vec![].into(),
/// }),
/// Arc::new(SimpleResolver::new()),
/// )
/// .build()
/// .await?;
/// # let _ = domus;
/// # Ok(()) }
/// ```