pub struct FramedTransport<T> {
    pub backup: Backup,
    /* private fields */
}
Expand description

Represents a wrapper around a Transport that reads and writes using frames defined by a Codec.

Fields

backup: Backup

Stores outgoing frames in case of transmission issues

Implementations

Creates a new FramedTransport using the PlainCodec

Replaces the current codec with the provided codec. Note that any bytes in the incoming or outgoing buffers will remain in the transport, meaning that this can cause corruption if the bytes in the buffers do not match the new codec.

For safety, use clear to wipe the buffers before further use.

Returns a reference to the codec used by the transport.

Note

Be careful when accessing the codec to avoid corrupting it through unexpected modifications as this will place the transport in an undefined state.

Returns a mutable reference to the codec used by the transport.

Note

Be careful when accessing the codec to avoid corrupting it through unexpected modifications as this will place the transport in an undefined state.

Clears the internal transport buffers.

Returns a reference to the inner value this transport wraps.

Returns a mutable reference to the inner value this transport wraps.

Consumes this transport, returning the inner value that it wraps.

Converts this instance to a FramedTransport whose inner Transport is Boxed.

Waits for the transport to be ready based on the given interest, returning the ready status

Waits for the transport to be readable to follow up with try_read_frame.

Waits for the transport to be writeable to follow up with try_write_frame.

Waits for the transport to be readable or writeable, returning the Ready status.

Attempts to flush any remaining bytes in the outgoing queue, returning the total bytes written as a result of the flush. Note that a return of 0 bytes does not indicate that the underlying transport has closed, but rather that no bytes were flushed such as when the outgoing queue is empty.

This is accomplished by continually calling the inner transport’s try_write. If 0 is returned from a call to try_write, this will fail with [ErrorKind::WriteZero].

This call may return an error with ErrorKind::WouldBlock in the case that the transport is not ready to write data.

Flushes all buffered, outgoing bytes using repeated calls to try_flush.

Reads a frame of bytes by using the Codec tied to this transport. Returns Ok(Some(frame)) upon reading a frame, or Ok(None) if the underlying transport has closed.

This call may return an error with ErrorKind::WouldBlock in the case that the transport is not ready to read data or has not received a full frame before waiting.

Reads a frame using try_read_frame and then deserializes the bytes into D.

Continues to invoke try_read_frame until a frame is successfully read, an error is encountered that is not ErrorKind::WouldBlock, or the underlying transport has closed.

Reads a frame using read_frame and then deserializes the bytes into D.

Writes a frame of bytes by using the Codec tied to this transport.

This is accomplished by continually calling the inner transport’s try_write. If 0 is returned from a call to try_write, this will fail with ErrorKind::WriteZero.

This call may return an error with ErrorKind::WouldBlock in the case that the transport is not ready to write data or has not written the entire frame before waiting.

Serializes value into bytes and passes them to try_write_frame.

Invokes try_write_frame followed by a continuous calls to try_flush until a frame is successfully written, an error is encountered that is not ErrorKind::WouldBlock, or the underlying transport has closed.

Serializes value into bytes and passes them to write_frame.

Executes the async function while the Backup of this transport is frozen.

Places the transport in synchronize mode where it communicates with the other side how many frames have been sent and received. From there, any frames not received by the other side are sent again and then this transport waits for any missing frames that it did not receive from the other side.

Note

This will clear the internal incoming and outgoing buffers, so any frame that was in transit in either direction will be dropped.

Shorthand for creating a FramedTransport with a PlainCodec and then immediately performing a client_handshake, returning the updated FramedTransport on success.

Perform the client-side of a handshake. See handshake for more details.

Shorthand for creating a FramedTransport with a PlainCodec and then immediately performing a [server_handshake], returning the updated FramedTransport on success.

Perform the server-side of a handshake. See handshake for more details.

Performs a handshake in order to establish a new codec to use between this transport and the other side. The parameter handshake defines how the transport will handle the handshake with Client being used to pick the compression and encryption used while Server defines what the choices are for compression and encryption.

This will reset the framed transport’s codec to PlainCodec in order to communicate which compression and encryption to use. Upon selecting an encryption type, a shared secret key will be derived on both sides and used to establish the EncryptionCodec, which in combination with the CompressionCodec (if any) will replace this transport’s codec.

Client
  1. Wait for options from server
  2. Send to server a compression and encryption choice
  3. Configure framed transport using selected choices
  4. Invoke on_handshake function
Server
  1. Send options to client
  2. Receive choices from client
  3. Configure framed transport using client’s choices
  4. Invoke on_handshake function
Failure

The handshake will fail in several cases:

  • If any frame during the handshake fails to be serialized
  • If any unexpected frame is received during the handshake
  • If using encryption and unable to derive a shared secret key

If a failure happens, the codec will be reset to what it was prior to the handshake request, and all internal buffers will be cleared to avoid corruption.

Places the transport into key-exchange mode where it attempts to derive a shared secret key with the other transport.

Produces a pair of inmemory transports that are connected to each other using a PlainCodec.

Sets the buffer for message passing for each underlying transport to the given buffer size.

Links the underlying transports together using InmemoryTransport::link.

Trait Implementations

Performs authentication by leveraging the handler for any received challenge.
Issues an initialization notice and returns the response indicating which authentication methods to pursue Read more
Issues a challenge and returns the answers to the questions asked.
Requests verification of some kind and text, returning true if passed verification.
Reports information with no response expected.
Reports an error occurred during authentication, consuming the authenticator since no more challenges should be issued. Read more
Reports that the authentication has started for a specific method.
Reports that the authentication has finished successfully, consuming the authenticator since no more challenges should be issued. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Attempts to reconnect an already-established connection.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.