Struct FramedTransport

Source
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§

Source§

impl<T> FramedTransport<T>

Source

pub fn new(inner: T, codec: BoxedCodec) -> Self

Source

pub fn plain(inner: T) -> Self

Creates a new FramedTransport using the PlainCodec

Source

pub fn set_codec(&mut self, codec: BoxedCodec)

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.

Source

pub fn codec(&self) -> &dyn Codec

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.

Source

pub fn mut_codec(&mut self) -> &mut dyn Codec

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.

Source

pub fn clear(&mut self)

Clears the internal transport buffers.

Source

pub fn as_inner(&self) -> &T

Returns a reference to the inner value this transport wraps.

Source

pub fn as_mut_inner(&mut self) -> &mut T

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

Source

pub fn into_inner(self) -> T

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

Source§

impl<T: Transport + 'static> FramedTransport<T>

Source

pub fn into_boxed(self) -> FramedTransport<Box<dyn Transport>>

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

Source§

impl<T: Transport> FramedTransport<T>

Source

pub async fn ready(&self, interest: Interest) -> Result<Ready>

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

Source

pub async fn readable(&self) -> Result<()>

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

Source

pub async fn writeable(&self) -> Result<()>

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

Source

pub async fn readable_or_writeable(&self) -> Result<Ready>

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

Source

pub fn try_flush(&mut self) -> Result<usize>

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.

Source

pub async fn flush(&mut self) -> Result<()>

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

Source

pub fn try_read_frame(&mut self) -> Result<Option<OwnedFrame>>

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.

Source

pub fn try_read_frame_as<D: DeserializeOwned>(&mut self) -> Result<Option<D>>

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

Source

pub async fn read_frame(&mut self) -> Result<Option<OwnedFrame>>

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.

Source

pub async fn read_frame_as<D: DeserializeOwned>(&mut self) -> Result<Option<D>>

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

Source

pub fn try_write_frame<'a, F>(&mut self, frame: F) -> Result<()>
where F: TryInto<Frame<'a>>, F::Error: Into<Box<dyn Error + Send + Sync>>,

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.

Source

pub fn try_write_frame_for<D: Serialize>(&mut self, value: &D) -> Result<()>

Serializes value into bytes and passes them to try_write_frame.

Source

pub async fn write_frame<'a, F>(&mut self, frame: F) -> Result<()>
where F: TryInto<Frame<'a>>, F::Error: Into<Box<dyn Error + Send + Sync>>,

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.

Source

pub async fn write_frame_for<D: Serialize>(&mut self, value: &D) -> Result<()>

Serializes value into bytes and passes them to write_frame.

Source

pub async fn do_frozen<F, X>(&mut self, f: F) -> Result<()>
where F: FnMut(&mut Self) -> X, X: Future<Output = Result<()>>,

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

Source

pub async fn synchronize(&mut self) -> Result<()>

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.

Source

pub async fn from_client_handshake(transport: T) -> Result<Self>

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

Source

pub async fn client_handshake(&mut self) -> Result<()>

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

Source

pub async fn from_server_handshake(transport: T) -> Result<Self>

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

Source

pub async fn server_handshake(&mut self) -> Result<()>

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

Source

pub async fn handshake(&mut self, handshake: Handshake) -> Result<()>

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.

Source

pub async fn exchange_keys(&mut self) -> Result<SecretKey32>

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

Source§

impl FramedTransport<InmemoryTransport>

Source

pub fn pair( buffer: usize, ) -> (FramedTransport<InmemoryTransport>, FramedTransport<InmemoryTransport>)

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§

Source§

impl<T> Authenticate for FramedTransport<T>
where T: Transport,

Source§

fn authenticate<'life0, 'async_trait>( &'life0 mut self, handler: impl 'async_trait + AuthHandler + Send, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Performs authentication by leveraging the handler for any received challenge.
Source§

impl<T> Authenticator for FramedTransport<T>
where T: Transport,

Source§

fn initialize<'life0, 'async_trait>( &'life0 mut self, initialization: Initialization, ) -> Pin<Box<dyn Future<Output = Result<InitializationResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Issues an initialization notice and returns the response indicating which authentication methods to pursue
Source§

fn challenge<'life0, 'async_trait>( &'life0 mut self, challenge: Challenge, ) -> Pin<Box<dyn Future<Output = Result<ChallengeResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Issues a challenge and returns the answers to the questions asked.
Source§

fn verify<'life0, 'async_trait>( &'life0 mut self, verification: Verification, ) -> Pin<Box<dyn Future<Output = Result<VerificationResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Requests verification of some kind and text, returning true if passed verification.
Source§

fn info<'life0, 'async_trait>( &'life0 mut self, info: Info, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Reports information with no response expected.
Source§

fn error<'life0, 'async_trait>( &'life0 mut self, error: Error, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Reports an error occurred during authentication, consuming the authenticator since no more challenges should be issued.
Source§

fn start_method<'life0, 'async_trait>( &'life0 mut self, start_method: StartMethod, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Reports that the authentication has started for a specific method.
Source§

fn finished<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Reports that the authentication has finished successfully, consuming the authenticator since no more challenges should be issued.
Source§

impl<T: Clone> Clone for FramedTransport<T>

Source§

fn clone(&self) -> FramedTransport<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for FramedTransport<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Reconnectable for FramedTransport<T>
where T: Transport,

Source§

fn reconnect<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Attempts to reconnect an already-established connection.

Auto Trait Implementations§

§

impl<T> Freeze for FramedTransport<T>
where T: Freeze,

§

impl<T> !RefUnwindSafe for FramedTransport<T>

§

impl<T> Send for FramedTransport<T>
where T: Send,

§

impl<T> Sync for FramedTransport<T>
where T: Sync,

§

impl<T> Unpin for FramedTransport<T>
where T: Unpin,

§

impl<T> !UnwindSafe for FramedTransport<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsAny for T
where T: 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts reference to Any
Source§

fn as_mut_any(&mut self) -> &mut (dyn Any + 'static)

Converts mutable reference to Any
Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Consumes and produces Box<dyn Any>
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V