@@ -4,19 +4,16 @@ pub use errors::*;
4
4
mod messages;
5
5
use messages:: * ;
6
6
7
- use std:: future:: Future ;
8
- use std:: pin:: Pin ;
9
- use std:: task:: { Context , Poll } ;
10
-
11
7
use std:: net:: { IpAddr , SocketAddr , SocketAddrV4 , ToSocketAddrs } ;
8
+ use std:: task:: { Context , Poll } ;
12
9
13
10
use http:: Uri ;
14
11
use hyper:: rt:: { Read , Write } ;
15
12
use tower_service:: Service ;
16
13
17
14
use bytes:: BytesMut ;
18
15
19
- use pin_project_lite :: pin_project ;
16
+ use super :: { Handshaking , SocksError } ;
20
17
21
18
/// Tunnel Proxy via SOCKSv4
22
19
///
@@ -35,23 +32,6 @@ struct SocksConfig {
35
32
local_dns : bool ,
36
33
}
37
34
38
- pin_project ! {
39
- // Not publicly exported (so missing_docs doesn't trigger).
40
- //
41
- // We return this `Future` instead of the `Pin<Box<dyn Future>>` directly
42
- // so that users don't rely on it fitting in a `Pin<Box<dyn Future>>` slot
43
- // (and thus we can change the type in the future).
44
- #[ must_use = "futures do nothing unless polled" ]
45
- #[ allow( missing_debug_implementations) ]
46
- pub struct Handshaking <F , T , E > {
47
- #[ pin]
48
- fut: BoxHandshaking <T , E >,
49
- _marker: std:: marker:: PhantomData <F >
50
- }
51
- }
52
-
53
- type BoxHandshaking < T , E > = Pin < Box < dyn Future < Output = Result < T , super :: SocksError < E > > > + Send > > ;
54
-
55
35
impl < C > SocksV4 < C > {
56
36
/// Create a new SOCKSv4 handshake service
57
37
///
@@ -86,12 +66,7 @@ impl SocksConfig {
86
66
}
87
67
}
88
68
89
- async fn execute < T , E > (
90
- self ,
91
- mut conn : T ,
92
- host : String ,
93
- port : u16 ,
94
- ) -> Result < T , super :: SocksError < E > >
69
+ async fn execute < T , E > ( self , mut conn : T , host : String , port : u16 ) -> Result < T , SocksError < E > >
95
70
where
96
71
T : Read + Write + Unpin ,
97
72
{
@@ -109,7 +84,7 @@ impl SocksConfig {
109
84
None
110
85
}
111
86
} )
112
- . ok_or ( super :: SocksError :: DnsFailure ) ?
87
+ . ok_or ( SocksError :: DnsFailure ) ?
113
88
} else {
114
89
Address :: Domain ( host, port)
115
90
}
@@ -142,11 +117,11 @@ where
142
117
C :: Error : Send + ' static ,
143
118
{
144
119
type Response = C :: Response ;
145
- type Error = super :: SocksError < C :: Error > ;
120
+ type Error = SocksError < C :: Error > ;
146
121
type Future = Handshaking < C :: Future , C :: Response , C :: Error > ;
147
122
148
123
fn poll_ready ( & mut self , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) , Self :: Error > > {
149
- self . inner . poll_ready ( cx) . map_err ( super :: SocksError :: Inner )
124
+ self . inner . poll_ready ( cx) . map_err ( SocksError :: Inner )
150
125
}
151
126
152
127
fn call ( & mut self , dst : Uri ) -> Self :: Future {
@@ -155,12 +130,9 @@ where
155
130
156
131
let fut = async move {
157
132
let port = dst. port ( ) . map ( |p| p. as_u16 ( ) ) . unwrap_or ( 443 ) ;
158
- let host = dst
159
- . host ( )
160
- . ok_or ( super :: SocksError :: MissingHost ) ?
161
- . to_string ( ) ;
133
+ let host = dst. host ( ) . ok_or ( SocksError :: MissingHost ) ?. to_string ( ) ;
162
134
163
- let conn = connecting. await . map_err ( super :: SocksError :: Inner ) ?;
135
+ let conn = connecting. await . map_err ( SocksError :: Inner ) ?;
164
136
config. execute ( conn, host, port) . await
165
137
} ;
166
138
@@ -170,14 +142,3 @@ where
170
142
}
171
143
}
172
144
}
173
-
174
- impl < F , T , E > Future for Handshaking < F , T , E >
175
- where
176
- F : Future < Output = Result < T , E > > ,
177
- {
178
- type Output = Result < T , super :: SocksError < E > > ;
179
-
180
- fn poll ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
181
- self . project ( ) . fut . poll ( cx)
182
- }
183
- }
0 commit comments