pub struct RawChannel { /* private fields */ }
Expand description
Represents a raw channel between a manager client and server. Underneath, this routes incoming and outgoing data from a proxied server to an inmemory transport.
Implementations§
Source§impl RawChannel
impl RawChannel
pub fn abort(&self)
Sourcepub fn into_client<T, U>(self) -> Client<T, U>
pub fn into_client<T, U>(self) -> Client<T, U>
Consumes this channel, returning a typed client wrapping the transport.
§Note
This does not perform any additional handshakes or authentication. All authentication was performed during separate connection and this merely wraps an inmemory transport that maps to the primary connection.
Sourcepub fn into_untyped_client(self) -> UntypedClient
pub fn into_untyped_client(self) -> UntypedClient
Consumes this channel, returning an untyped client wrapping the transport.
§Note
This does not perform any additional handshakes or authentication. All authentication was performed during separate connection and this merely wraps an inmemory transport that maps to the primary connection.
Sourcepub fn as_framed_transport(&self) -> &FramedTransport<InmemoryTransport>
pub fn as_framed_transport(&self) -> &FramedTransport<InmemoryTransport>
Returns reference to the underlying framed transport.
Sourcepub fn as_mut_framed_transport(
&mut self,
) -> &mut FramedTransport<InmemoryTransport>
pub fn as_mut_framed_transport( &mut self, ) -> &mut FramedTransport<InmemoryTransport>
Returns mutable reference to the underlying framed transport.
Sourcepub fn into_framed_transport(self) -> FramedTransport<InmemoryTransport>
pub fn into_framed_transport(self) -> FramedTransport<InmemoryTransport>
Consumes the channel, returning the underlying framed transport.
Methods from Deref<Target = FramedTransport<InmemoryTransport>>§
Sourcepub fn set_codec(&mut self, codec: BoxedCodec)
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.
Sourcepub fn codec(&self) -> &dyn Codec
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.
Sourcepub fn mut_codec(&mut self) -> &mut dyn Codec
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.
Sourcepub fn as_mut_inner(&mut self) -> &mut T
pub fn as_mut_inner(&mut self) -> &mut T
Returns a mutable reference to the inner value this transport wraps.
Sourcepub async fn ready(&self, interest: Interest) -> Result<Ready>
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
Sourcepub async fn readable(&self) -> Result<()>
pub async fn readable(&self) -> Result<()>
Waits for the transport to be readable to follow up with try_read_frame
.
Sourcepub async fn writeable(&self) -> Result<()>
pub async fn writeable(&self) -> Result<()>
Waits for the transport to be writeable to follow up with try_write_frame
.
Sourcepub async fn readable_or_writeable(&self) -> Result<Ready>
pub async fn readable_or_writeable(&self) -> Result<Ready>
Waits for the transport to be readable or writeable, returning the Ready
status.
Sourcepub fn try_flush(&mut self) -> Result<usize>
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.
Sourcepub async fn flush(&mut self) -> Result<()>
pub async fn flush(&mut self) -> Result<()>
Flushes all buffered, outgoing bytes using repeated calls to try_flush
.
Sourcepub fn try_read_frame(&mut self) -> Result<Option<OwnedFrame>>
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.
Sourcepub fn try_read_frame_as<D: DeserializeOwned>(&mut self) -> Result<Option<D>>
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
.
Sourcepub async fn read_frame(&mut self) -> Result<Option<OwnedFrame>>
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.
Sourcepub async fn read_frame_as<D: DeserializeOwned>(&mut self) -> Result<Option<D>>
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
.
Sourcepub fn try_write_frame<'a, F>(&mut self, frame: F) -> Result<()>
pub fn try_write_frame<'a, F>(&mut self, frame: F) -> Result<()>
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.
Sourcepub fn try_write_frame_for<D: Serialize>(&mut self, value: &D) -> Result<()>
pub fn try_write_frame_for<D: Serialize>(&mut self, value: &D) -> Result<()>
Serializes value
into bytes and passes them to try_write_frame
.
Sourcepub async fn write_frame<'a, F>(&mut self, frame: F) -> Result<()>
pub async fn write_frame<'a, F>(&mut self, frame: F) -> Result<()>
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.
Sourcepub async fn write_frame_for<D: Serialize>(&mut self, value: &D) -> Result<()>
pub async fn write_frame_for<D: Serialize>(&mut self, value: &D) -> Result<()>
Serializes value
into bytes and passes them to write_frame
.
Sourcepub async fn do_frozen<F, X>(&mut self, f: F) -> Result<()>
pub async fn do_frozen<F, X>(&mut self, f: F) -> Result<()>
Executes the async function while the Backup
of this transport is frozen.
Sourcepub async fn synchronize(&mut self) -> Result<()>
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.
Sourcepub async fn client_handshake(&mut self) -> Result<()>
pub async fn client_handshake(&mut self) -> Result<()>
Perform the client-side of a handshake. See handshake
for more details.
Sourcepub async fn server_handshake(&mut self) -> Result<()>
pub async fn server_handshake(&mut self) -> Result<()>
Perform the server-side of a handshake. See handshake
for more details.
Sourcepub async fn handshake(&mut self, handshake: Handshake) -> Result<()>
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
- Wait for options from server
- Send to server a compression and encryption choice
- Configure framed transport using selected choices
- Invoke on_handshake function
§Server
- Send options to client
- Receive choices from client
- Configure framed transport using client’s choices
- 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.
Sourcepub async fn exchange_keys(&mut self) -> Result<SecretKey32>
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.
Sourcepub fn link(&mut self, other: &mut Self, buffer: usize)
pub fn link(&mut self, other: &mut Self, buffer: usize)
Links the underlying transports together using InmemoryTransport::link
.