Module server

Module server 

Source
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 session renew 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.
TunnelStateMachine
The state transitions of an edgetun connection.

Enums§

AcceptError
Accept errors.
AddressAssignmentError
Address assignment error.
ControlError
Control errors.
ParseControlRequestError
Error parsing control request.
ReceivePacketError
Packet receive error.
SendControlResponseError
Error when sending a control response.
SendPacketError
Send packet error.
SnaptunConnErrors
SNAP tunnel connection errors.

Constants§

ACCEPT_TIMEOUT
A client MUST first send a session renew 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§

SnapTunToken
Deserializable SNAP token trait.