pub struct TcpServerHandshake { /* private fields */ }
Expand description

Handles the server-side of the VBus-over-TCP handshake.

Examples

This example simulates a RESOL DL2 by accepting TCP connections on port 7053, requiring the client to provide a password and then switch the connection into raw VBus data mode.

use tokio::prelude::*;
use tokio::net::TcpListener;
use tokio_resol_vbus::TcpServerHandshake;

let addr = "127.0.0.1:7053".parse().expect("Unable to parse address");
let listener = TcpListener::bind(&addr).expect("Unable to bind listener");

let server = listener
    .incoming()
    .map_err(|err| eprintln!("{}", err))
    .for_each(|socket| {
        let conn = TcpServerHandshake::start(socket)
            .and_then(|hs| hs.receive_pass_command_and_verify_password(|password| {
                if password == "vbus" {
                    Ok(Some(password))
                } else {
                    Ok(None)
                }
            }))
            .and_then(|(hs, _)| hs.receive_data_command())
            .and_then(|socket| {
                // do something with the socket
            })
            .map_err(|err| eprintln!("Server error: {}", err));
        tokio::spawn(conn)
    });

tokio::run(server);

Implementations§

Start the VBus-over-TCP handshake as the client side connecting to a server.

Consume self and return the underlying TcpStream.

Receive a command and verify it and its provided arguments. The command reception is repeated as long as the verification fails.

The preferred way to receive commands documented in the VBus-over-TCP specification is through the receive_xxx_command and receive_xxx_command_and_verify_yyy methods which use the receive_command method internally.

This method takes a validator function that is called with the received command and its optional arguments. The validator returns a Future that can resolve into an std::result::Result<T, &'static str>. It can either be:

  • Ok(value) if the validation succeeded. The value is used to resolve the receive_command Future.
  • Err(reply) if the validation failed. The reply is send back to the client and the command reception is repeated.

Wait for a CONNECT <via_tag> command. The via tag argument is returned.

Wait for a CONNECT <via_tag> command.

Wait for a PASS <password> command.

Wait for a PASS <password> command and validate the provided password.

Wait for a CHANNEL <channel> command.

Wait for CHANNEL <channel> command and validate the provided channel

Wait for a DATA command.

Trait Implementations§

Formats the value using the given formatter. Read more

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.

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.