pub fn parse_client_request(buffer: &[u8]) -> Result<(u8, Command)>Examples found in repository?
examples/server.rs (line 46)
31async fn handle_client_connection(stream: &mut TcpStream) -> Result<()> {
32 // With buffered I/O it's important to call `.flush()` on stream
33 // after write operation to ensure the bytes reached to their destination.
34 let mut stream = BufStream::new(stream);
35
36 const BUFCAP: usize = 9000;
37 let mut buffer = [0_u8; BUFCAP];
38 let mut n = stream.read(&mut buffer[..BUFCAP]).await?;
39 let (_, _methods) = socks5rs::parse_client_methods(&buffer[..n])?;
40
41 stream.write_all(&[ consts::SOCKS5, consts::method::NO_AUTH ]).await?;
42 stream.flush().await?;
43
44 n = stream.read(&mut buffer[..BUFCAP]).await?;
45
46 let (_, command) = socks5rs::parse_client_request(&buffer[..n])?;
47
48 match command {
49 Command::Connect(r) => handle_connect_command(stream.get_mut(), r).await,
50 _ => Ok(()),
51 }
52}