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
//! The embedding handle: a running liminal server with no listener, whose one
//! connection-granting surface is the in-process loopback
//! (design `docs/design/IN-PROCESS-TRANSPORT.md` §2, §4, §9 ruling 4).
//!
//! **What an [`EmbeddedServer`] secures is the RECORD PATH** (hardened
//! face-substrate draft r2 §5). A connection minted here is admitted by the
//! same door a socket connection is admitted by: the same
//! `try_reserve_admission` against the same slot pool, a real durable
//! connection incarnation from the same authority, the same registry record,
//! the same `Connect`/`ConnectAck` handshake with the same constant-time token
//! compare, the same frame preflight, the same participant gate, and the same
//! `apply_frame` seam. No append reaches the record except through that door,
//! and the door does not know which mount knocked. An embedded caller with the
//! wrong token is refused on its own loopback, and an embedded caller arriving
//! at capacity is refused exactly as a socket connect is.
//!
//! **What an [`EmbeddedServer`] does NOT secure is the mount.** A co-resident
//! caller is TRUSTED CODE: it reaches the host process's heap, its descriptors,
//! and its store handle without ever calling this type, so the record vouches
//! for a co-resident mount only as far as the host process itself is trusted.
//! That is inherent to the mount, not a defect of it. Every append admitted
//! here carries the mount fact the admitting door stamped
//! ([`MountKind::Loopback`](crate::server::mount::MountKind::Loopback), §10)
//! precisely because the mount is what a consumer must weigh; this type is not
//! a sandbox and must never be read as one.
//!
//! **The surface is deliberately one door wide.** This handle exposes no
//! supervisor, no services, no store, no handler, no registry, and no scheduler
//! — the module privacy that keeps those unreachable is the structural half of
//! the no-side-door guarantee, and a convenience accessor here would undo it as
//! surely as a public spawn seam would. `connect_loopback` is the whole grant.
use fmt;
use Arc;
use crateServerError;
use crateLimitsConfig;
use crate;
/// Bytes each direction of an embedded connection's duplex may hold.
///
/// 256 KiB, chosen to sit in the same order as the kernel socket buffers the
/// loopback replaces: a default `SO_SNDBUF`/`SO_RCVBUF` pair on Linux and macOS
/// is tens to a couple of hundred kilobytes, so an embedded writer meets
/// backpressure at roughly the point a socket writer meets it and the mount
/// does not quietly buy itself a deeper queue than every other mount has. It is
/// a BOUND, not a reservation — each ring is a `VecDeque` that grows toward
/// this ceiling only under load, so an idle embedded connection costs two empty
/// queues.
///
/// The value is per ring rather than shared, so a backed-up inbound direction
/// cannot starve the server's replies out of the outbound one.
const LOOPBACK_RING_CAPACITY_BYTES: usize = 256 * 1024;
/// A running liminal server with no listener, granting in-process connections.
///
/// Built from the same ingredients the production stack is built from —
/// services, an optional connection auth token, and the operational limits —
/// and torn down on drop, so an embedded server's lifetime is its handle's.