pub trait Handshake: HandshakeImpl + HasHandshakeOutput<Self::Output> {
type Output: Debug;
// Provided methods
fn step<'b, P: ReadPrecision>(
&mut self,
buffer: &'b mut Buffer<P>,
) -> Result<NextStep<'b, <Self as Handshake>::Output, P>, Error> { ... }
fn handshake(&mut self, input: &[u8]) -> TResult<Action> { ... }
}
Available on crate features
proxy-handshake
or client-handshake
only.Expand description
Handshake
Required Associated Types§
Provided Methods§
Sourcefn step<'b, P: ReadPrecision>(
&mut self,
buffer: &'b mut Buffer<P>,
) -> Result<NextStep<'b, <Self as Handshake>::Output, P>, Error>
fn step<'b, P: ReadPrecision>( &mut self, buffer: &'b mut Buffer<P>, ) -> Result<NextStep<'b, <Self as Handshake>::Output, P>, Error>
Drive a handshake forward, determining what the next step is
use std::io::{Read as _, Write as _};
use tor_socksproto::{Handshake as _, SocksProxyHandshake, SocksRequest};
let socket: std::net::TcpStream = todo!();
let mut hs = SocksProxyHandshake::new();
let mut buf = tor_socksproto::Buffer::new();
let (request, data_read_ahead) = loop {
use tor_socksproto::NextStep;
match hs.step(&mut buf)? {
NextStep::Send(data) => socket.write_all(&data)?,
NextStep::Recv(recv) => {
let got = socket.read(recv.buf())?;
recv.note_received(got);
},
NextStep::Finished(request) => break request.into_output_and_vec(),
}
};
let _: SocksRequest = request;
let _: Vec<u8> = data_read_ahead;
// Or, with precise reading:
//...
let mut buf = tor_socksproto::Buffer::new_precise();
let request = loop {
use tor_socksproto::NextStep;
match hs.step(&mut buf)? {
//...
NextStep::Finished(request) => break request.into_output()?,
}
};
let _: SocksRequest = request;
See [ReadPrecision]
for information about read precision and the P
type parameter.
Sourcefn handshake(&mut self, input: &[u8]) -> TResult<Action>
👎Deprecated: use the new Handshake::step API instead
fn handshake(&mut self, input: &[u8]) -> TResult<Action>
Try to advance the handshake, given some peer input in
input
.
If there isn’t enough input, gives a Truncated
.
In this case, the caller must retain the input, and pass it to a later
invocation of handshake
. Input should only be regarded as consumed when
the Action::drain
field is nonzero.
Other errors (besides Truncated
) indicate a failure.
On success, return an Action describing what to tell the peer, and how much of its input to consume.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
Source§impl Handshake for SocksClientHandshake
Available on crate feature client-handshake
only.
impl Handshake for SocksClientHandshake
Available on crate feature
client-handshake
only.type Output = <Option<SocksReply> as IntoIterator>::Item
Source§impl Handshake for SocksProxyHandshake
Available on crate feature proxy-handshake
only.
impl Handshake for SocksProxyHandshake
Available on crate feature
proxy-handshake
only.