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
/*
* net_subnet.h — C SDK header for the subnet AUTHORITY surface
* (SUBNET_AUTH_SDK_PLAN.md S4c / §6.4).
*
* These symbols sit beside net_org.h's, in the org-ffi rlib that is
* linked into `libnet`. They are declared in a separate header only
* because they are a separate concept. Hosting them there reuses the org
* handler dispatcher, the net_org_caller_t projection, and the
* Arc<MeshNode> ownership contract: the base FFI inside the `net` crate
* cannot depend on `net-mesh-sdk`, while the subnet SDK
* (`net_sdk::subnet`) does, and the org surface already carries that
* dependency.
*
* Like every other header here, this one resolves out of one `libnet`:
*
* cargo build --release -p net-ffi
* gcc -o app app.c -L target/release -lnet -lpthread -ldl -lm
*
* # The subnet surface, in one paragraph
*
* Topology is not authority. This header authorizes protected transport:
* a GATEWAY installs credential sets, declares boundaries, and applies
* signed control facts; a PROVIDER serves an organization-protected nRPC
* service against one exact exported crossing; a CALLER invokes it with
* organization authority only (net_org_call_exported, in net_org.h) —
* never joining the provider's subnet. Every signed artifact is minted by
* `net-mesh subnet …` and crosses as opaque canonical wire bytes; nothing
* here signs, and no signing key crosses this boundary.
*
* # Error model
*
* `int` returns share the org surface's namespace. A subnet
* provisioning / configuration / serve failure returns
* NET_ORG_ERR_SUBNET (-13) and writes the stable `subnet:<kind>` wire
* string to `out_err` (free with net_org_free_cstring). It is a LOCAL,
* startup-shaped failure — never a call domain. Remote exported-call
* refusals surface through the org call domains (net_org.h).
*
* # Trust anchors
*
* Declaring which authorities a node trusts, its security attachment path,
* and its control channel is CONFIG-TIME state, supplied in the JSON
* `net_mesh_new` already takes:
*
* {
* "bind_addr": "127.0.0.1:0",
* "psk_hex": "…",
* "subnet_authorities": [
* { "authority_hex": "…",
* "root_hexes": ["…"],
* "maximum_grant_lifetime_secs": 604800 }
* ],
* "subnet_attachment": [3],
* "subnet_control_channel": "subnet.control"
* }
*
* Rust converts and validates these through the same frozen DTOs every
* other SDK uses, before the node exists: a duplicate authority, an empty
* or duplicated root set, a zero lifetime, a path deeper than four levels,
* or a malformed hex id all return NET_ERR_MESH_INIT. An absent or empty
* authority list means every protected subnet assertion fails closed.
*
* A standalone C program can therefore stand up a subnet GATEWAY on its
* own; it does not need a node handed to it from Rust, Node, or Python.
* (Until review-10 P1-7 this was impossible — the conversion lived in
* net-mesh-sdk, which base libnet's constructor cannot depend on.)
*
* # Handle & ownership model
*
* Identical to net_org.h: every mesh_arc comes from net_mesh_arc_clone
* and is CONSUMED (mint a fresh clone per call; do NOT free it — the node
* lives on via the Go MeshNode). Serve returns a NetOrgServeHandle (from
* net_org.h), freed with net_org_serve_handle_free. Wholesale-replace
* semantics: install/declare replace the whole set, so pass every
* currently-held artifact, not a delta.
*
* CONSUMED means consumed on EVERY path, including a refusal caused by
* some other malformed argument. The single exception is a NULL mesh_arc
* itself, which names nothing to consume. Do not reclaim the clone after
* an error return.
*
* # Array counts
*
* Every count below (set_count, boundary_count) is the exact number of
* elements behind its pointer. Counts whose total byte length would
* exceed the platform's maximum slice length are refused deterministically
* without the arrays being read, so a (size_t)-1 typo is an error return
* rather than undefined behavior — but a count that merely EXCEEDS the
* real array length is still a caller bug this ABI cannot detect.
*/
/* NetOrgServeHandle, net_org_caller_t, net_compute_mesh_arc_t, the
* NET_ORG_ERR_* codes, net_org_free_cstring, net_org_reserve_handler_id,
* net_org_set_handler_dispatcher, and net_org_call_exported all live in
* net_org.h — this header is a companion, not a replacement. */
extern "C" __cplusplus
} /* extern "C" */
/* NET_SUBNET_H */