Expand description
§The snaptun server.
This module contains the snaptun-Server. The QUIC-connection handling is left to the caller. That is, after accepting a QUIC-connection, Server::accept_with_timeout will establish an snaptun with a client, provided the peer behaves as expected and sends the required control requests.
The Server::accept_with_timeout method produces three different objects: Receiver, Sender, and Control. The first is used to receive packets from the peer, the second to send packets to the peer. The third is used to drive the control state of the connection.
Server::accept_with_timeout expects the client to first send a update token request followed by an address assignment request. If the client doesn’t do so within ACCEPT_TIMEOUT, a AcceptError::Timeout error is returned and the connection closed. The rationale behind this is that bogus client connections should be closed as quickly as possible.
§Synopsis
loop {
let quic_conn = endpoint.accept().await?;
let (sender, receiver, control) = snaptun_server.accept(quic_conn)?;
let _ = tokio::spawn(control); // drive control state
let _ = tokio::spawn(async move {
while Ok(p) = receiver.receive().await {
// process incoming packet
}
});
// send an outgoing packet
sender.send(p);
}Structs§
- Control
- Control is used to handle control requests from the client. It is returned by Server::accept_with_timeout and must be polled to process control requests.
- Receiver
- Receiver can be used to receive packets from the client. It is returned by Server::accept_with_timeout.
- Sender
- Sender can be used to send packets to the client. It is returned by Server::accept_with_timeout.
- Server
- The snaptun server accepts connections from clients and provides them with an address assignment.
- Tunnel
State Machine - The state transitions of an snap-tun connection.
Enums§
- Accept
Error - Accept errors.
- Address
Assignment Error - Address assignment error.
- Control
Error - Control errors.
- Parse
Control Request Error - Error parsing control request.
- Receive
Packet Error - Packet receive error.
- Send
Control Response Error - Error when sending a control response.
- Send
Packet Error - Send packet error.
- Snaptun
Conn Errors - SNAP tunnel connection errors.
Constants§
- ACCEPT_
TIMEOUT - A client MUST first send a token update request, followed by an address assignment request
within the
ACCEPT_TIMEOUT. - SEND_
TIMEOUT - Sending a control response to the client may take no longer than
SEND_TIMEOUT.
Traits§
- Snap
TunToken - Deserializable SNAP token trait.