async_proxy/clients/socks4.rs
1use std::fmt;
2
3/// Holds implementation of the actual socks4 protocol
4pub mod general;
5
6/// Holds implementation of the socks4 protocol but
7/// without ident being passed when establishing
8/// connection
9pub mod no_ident;
10
11pub use general::Socks4General;
12pub use no_ident::Socks4NoIdent;
13
14/// Represents a Socks4 protocol command
15#[repr(u8)]
16pub enum Command {
17 TcpConnectionEstablishment = 1,
18 TcpPortBinding
19}
20
21/// Represents a Socks4 protocol error
22/// that can occur when connecting to
23/// a destination
24pub enum ErrorKind {
25 /// Indicates that an error occured
26 /// during a native I/O operation,
27 /// such as writing to or reading from
28 /// a stream
29 IOError(std::io::Error),
30 /// Indicates that a bad (wrong, not readable by Socks4)
31 /// buffer is received
32 BadBuffer,
33 /// Indicates that the request (for ex., for connection)
34 /// is denied
35 RequestDenied,
36 /// Indicates that the `Ident` service
37 /// is not available on the server side
38 IdentIsUnavailable,
39 /// Indicates that a bad ident is passed
40 /// in a payload so that the server refused
41 /// a connection request
42 BadIdent,
43 /// Indicates that a timeouts has been reached
44 /// when connecting to a service
45 OperationTimeoutReached
46}
47
48impl fmt::Display for ErrorKind {
49 fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
50 match self {
51 ErrorKind::IOError(e)
52 => f.write_str(&format!("I/O error: {}", e)),
53 ErrorKind::BadBuffer => f.write_str("bad buffer has been received"),
54 ErrorKind::RequestDenied => f.write_str("request denied"),
55 ErrorKind::IdentIsUnavailable => f.write_str("ident is unavailable"),
56 ErrorKind::BadIdent => f.write_str("bad ident"),
57 ErrorKind::OperationTimeoutReached => f.write_str("operation timeout reached")
58 }
59 }
60}