Function ssb_client::easy_ssb [] [src]

pub fn easy_ssb<T: AsyncRead + AsyncWrite>(
    transport: T
) -> Result<EasySsb<T>, KeyfileError>

Return a future for setting up an encrypted connection via the given transport (using keys from the ssb keyfile) and then calling ssb on the connection.

This function performs blocking file io (for reading the keyfile).

This function uses libsodium internally, so ensure that sodiumoxide::init() has been called before using this function.

Example

This example is not tested
sodiumoxide::init();
let addr = SocketAddr::new(Ipv6Addr::localhost().into(), DEFAULT_TCP_PORT);

current_thread::run(|_| {
    current_thread::spawn(TcpStream::connect(&addr)
    .and_then(|tcp| easy_ssb(tcp).unwrap().map_err(|err| panic!("{:?}", err)))
    .map_err(|err| panic!("{:?}", err))
    .map(|(mut client, receive, _)| {
        current_thread::spawn(receive.map_err(|err| panic!("{:?}", err)));

        let (send_request, response) = client.whoami();

        current_thread::spawn(send_request.map_err(|err| panic!("{:?}", err)));
        current_thread::spawn(response
                                  .map(|res| println!("{:?}", res))
                                  .map_err(|err| panic!("{:?}", err))
                                  .and_then(|_| {
                                                client.close().map_err(|err| panic!("{:?}", err))
                                            }));
    }))
});