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
//! # SuperTunnel
//!
//! A modular, asynchronous networking framework designed for building stateful TCP
//! tunnels that make network disruptions transparent to application streams.
//! Super Tunnel enables you to route application connections through a proxy server
//! while adding resiliency features that enable your tunnels to survive network
//! disconnections. Specifically, you can build resilient tunnels by stacking Super
//! Tunnel's framing, reliability, session resumption, and stream multiplexing
//! layers with your own security protocol implementation.
//!
//! SuperTunnel is designed to be composed with a security protocol that provides
//! security features such as encryption and resistance to network traffic analysis.
//! SuperTunnel itself does NOT provide security; it provides stateful session
//! resumption and stream multiplexing features while allowing you to focus on
//! developing strong security protocols.
//!
//! ## For Protocol Integrators
//!
//! If your goal is to integrate SuperTunnel into your existing applications
//! without writing custom protocol logic, you can leverage the pre-built layers
//! provided in the [`proto`] module.
//!
//! The standard SuperTunnel stack generally consists of:
//! * **Payload ([`proto::payload`])**: Chunks raw application data into
//! discrete messages.
//! * **Routing ([`proto::routing`])**: Multiplexes multiple distinct logical
//! sessions over a single tunnel.
//! * **Reliability ([`proto::reliability`])**: Guarantees ordered delivery and
//! handles retransmissions.
//! * **Resumption ([`proto::resumption`])**: Manages session identifiers and
//! facilitates seamless reconnection.
//! * **Framing ([`proto::framing`])**: Encapsulates messages into a continuous
//! byte stream for transport.
//!
//! **Getting Started:** The best way to understand how to wire these layers
//! together is to review the internal source code of the [reference
//! implementation examples]:
//! * See `examples/client.rs` for establishing a multiplexed outbound tunnel.
//! * See `examples/server.rs` for accepting, demultiplexing, and routing
//! inbound tunnel connections.
//!
//! ## For Protocol Implementors
//!
//! SuperTunnel is designed to be extensible. You can write your own protocol
//! layers by implementing the [`Protocol`] trait and injecting them anywhere in
//! a SuperTunnel stack.
//!
//! #### The [`Protocol`] Trait
//!
//! The [`Protocol`] trait represents a single transformation layer. It
//! typically takes an underlying asynchronous stream and sink (representing the
//! layer above it) and returns a new upgraded stream and sink (representing
//! this layer's interface to the layer below).
//!
//! #### Building Custom Protocols
//!
//! When writing a new [`Protocol`] implementation, you will often need to
//! manage concurrent state, encode/decode messages, or handle multiple inner
//! streams. The library provides utilities to make this easier:
//!
//! * **The [`util`] Module**: Contains abstractions for I/O transformation.
//! * Use [`EncodedStream`](crate::util::EncodedStream) and
//! [`DecodedSink`](crate::util::DecodedSink) to bridge between raw bytes
//! and your typed Rust structs using a Codec.
//! * Use [`MuxedEncodedStream`](crate::util::MuxedEncodedStream) and
//! [`DemuxedDecodedSink`](crate::util::DemuxedDecodedSink) if your protocol
//! needs to funnel multiple logical data flows into a single transport
//! layer.
//!
//! * **The [`sync`] Module**: Contains synchronization primitives for
//! asynchronous state machines where standard locks are unsuitable.
//! * Use [`PollMutex`](crate::sync::PollMutex) to safely share state between
//! the split read and write halves of your protocol. It provides a
//! poll-based lock that integrates cleanly with `Stream` and `Sink`
//! implementations.
//! * Use [`SharedStream`](crate::sync::SharedStream) or
//! [`SharedSink`](crate::sync::SharedSink) when multiple asynchronous tasks
//! need safe, concurrent access to a single underlying I/O resource.
//!
//! **Getting Started:** To see these utilities applied in concrete
//! implementations, you can study the internal source code of the [reference
//! implementation protocols] provided in this library:
//!
//! * **State Sharing**: See [`proto::reliability`]. Its `SharedReliabilityState`
//! demonstrates how to use [`PollMutex`](sync::PollMutex) to safely share
//! sequence numbers and acknowledgment tracking between the concurrent read
//! and write halves of the reliability layer.
//! * **Multiplexing**: See [`proto::routing`]. Both the client and server routing
//! implementations heavily rely on
//! [`MuxedEncodedStream`](util::MuxedEncodedStream) and
//! [`DemuxedDecodedSink`](util::DemuxedDecodedSink) to multiplex numerous
//! dynamic client sessions into a single underlying transport stream.
//! * **Codec Bridging**: See [`proto::framing`]. It contains a straightforward
//! example of using [`EncodedStream`](util::EncodedStream) and
//! [`DecodedSink`](util::DecodedSink) to apply a `Codec` directly to raw byte
//! streams.
//!
//! [reference implementation examples]: <https://github.com/unblockable/supertunnel/examples>
//! [reference implementation protocols]: <https://github.com/unblockable/supertunnel/src/proto>
use ;
use ;
use crateNetworkTarget;
/// Trait defining the size constraints for the framing protocol.
///
/// Dictates the maximum allowable payload sizes to ensure frames do not exceed
/// buffer capacities or network MTUs.
/// The core trait defining a discrete layer in the protocol stack.
///
/// Implementors of this trait wrap an underlying stream/sink and provide
/// an upgraded interface (e.g., adding encryption, framing, or reliability).
/// Trait for objects that possess a unique identifier.
///
/// Used extensively by multiplexers and demultiplexers to route packets to the correct session.
/// Trait for establishing outbound network connections.
///
/// Implemented by the server's routing layer to instantiate new outbound streams
/// based on client routing commands. This is a protocol factory: if the connection
/// succeeds, it will return a new instance of an object that implements the
/// protocol defined by the `Item` type.`