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
//! What an embedder may ask of the endpoint, without ever being handed one.
//!
//! Two capabilities live on the iroh endpoint and on nothing else: telling
//! it the network underneath it moved, and reading what the transport has
//! actually been doing. Both are wanted by an embedder — a phone client
//! needs the first on resume, and a status page needs the second to explain
//! a pipe that is slow rather than broken — and neither can be reached
//! without the endpoint.
//!
//! **An `endpoint()` accessor is therefore the one shape this module must
//! not be.** [`crate::transport`] states the promise it would break: no
//! iroh type reaches the public surface, checked rather than asserted by
//! `tests/api_surface.rs`. The manifest asks for `iroh = "1"`, a caret
//! major, precisely so that an iroh 2.0 is this crate's problem to absorb;
//! an `Endpoint` in one public signature would make it every dependent's,
//! and would do it at the moment they can least afford it — a phone binding
//! is generated code, and a type it cannot name is a type it cannot pass.
//! So each capability gets its own method, taking and returning values this
//! crate owns.
//!
//! It is also why this module borrows rather than holds. It names
//! [`Endpoint`] to spell two private helpers and keeps nothing past the end
//! of a call, which is the lifetime line [`crate::transport`] draws.
//!
//! The asymmetry between the two sides is [`crate::listener`] and
//! [`crate::peer`]'s, not this module's: the serve side keeps its endpoint
//! in `ServeState`, and the connect side keeps its in the `Peer` it dials
//! from. Both are reachable within the crate; neither is reachable outside
//! it.
use Endpoint;
use crateConnectHandle;
use crateServeHandle;
/// What the transport underneath a pipe has been doing, as plain numbers.
///
/// A snapshot taken at the moment it was asked for, and owned outright:
/// every field is a `u64` this crate copied out of iroh's counters, rather
/// than a borrow of them. That is the difference between a status page and
/// a leak — `Endpoint::metrics` hands back a reference to iroh's own
/// metrics types, and returning one would put both iroh and its metrics
/// crate in the signature of a method whose entire output is three
/// integers.
///
/// **Monotonic totals for the life of one endpoint, not rates and not
/// gauges.** They only ever climb, and they start at zero when the pipe is
/// created; what a caller wants is nearly always the difference between two
/// readings, or the ratio between two fields of one. A pipe that is torn
/// down and re-established starts a fresh endpoint and therefore fresh
/// counts.
///
/// `#[non_exhaustive]`, so fields can be added without breaking a caller,
/// and `Copy` so holding one in a UI's state costs nothing.
/// Push the notice in. Written once rather than twice because the two
/// handles owe the identical promise, and prose that is stated twice is
/// prose that drifts — the argument [`crate::lifecycle`] opens with.
async
/// Copy the three counters out of iroh's metrics into values this crate
/// owns.
///
/// `Endpoint::metrics` sits behind iroh's `metrics` feature. That feature
/// is one of iroh's defaults *and* is named explicitly in this crate's
/// manifest, for the reason the `tokio` entry beside it gives: a feature
/// that is used should be declared, rather than arriving free from a
/// dependency's private choice and disappearing in a release that changed
/// nothing here.