proxie/sync/
mod.rs

1mod http;
2mod socks5;
3
4use std::{
5    net::TcpStream,
6    io::{Read, Write, Result as IOResult},
7};
8use crate::{
9    prelude::*,
10    target::ToTarget,
11};
12
13pub trait SyncProxy {
14    fn connect(&self, addr: impl ToTarget) -> Result<ProxyTcpStream>;
15}
16
17pub struct ProxyTcpStream {
18    stream: TcpStream,
19}
20
21impl ProxyTcpStream {
22    pub fn into_tcpstream(self) -> TcpStream {
23        self.stream
24    }
25}
26
27impl Read for ProxyTcpStream {
28    fn read(&mut self, buf: &mut [u8]) -> IOResult<usize> {
29        self.stream.read(buf)
30    }
31}
32
33impl Write for ProxyTcpStream {
34    fn write(&mut self, buf: &[u8]) -> IOResult<usize> {
35        self.stream.write(buf)
36    }
37
38    fn flush(&mut self) -> IOResult<()> {
39        self.stream.flush()
40    }
41}
42
43impl Read for &ProxyTcpStream {
44    fn read(&mut self, buf: &mut [u8]) -> IOResult<usize> {
45        (&self.stream).read(buf)
46    }
47}
48
49impl Write for &ProxyTcpStream {
50    fn write(&mut self, buf: &[u8]) -> IOResult<usize> {
51        (&self.stream).write(buf)
52    }
53
54    fn flush(&mut self) -> IOResult<()> {
55        (&self.stream).flush()
56    }
57}