File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change
1
+ use std:: io:: Write ;
1
2
use std:: net:: SocketAddr ;
2
3
use std:: time:: Instant ;
3
4
@@ -33,6 +34,7 @@ pub struct Connection {
33
34
backend : Option < Box < dyn Backend > > ,
34
35
closing : bool ,
35
36
target_addr : Option < SocketAddr > ,
37
+ data : Vec < u8 > ,
36
38
}
37
39
38
40
impl Connection {
@@ -48,6 +50,7 @@ impl Connection {
48
50
backend : None ,
49
51
closing : false ,
50
52
target_addr : None ,
53
+ data : Vec :: new ( ) ,
51
54
}
52
55
}
53
56
@@ -207,12 +210,22 @@ impl Connection {
207
210
}
208
211
Status :: DnsWait => {
209
212
if self . command == CONNECT {
213
+ //if dns query is not done, cache data now
214
+ if let Err ( err) = self . data . write ( buffer) {
215
+ log:: warn!( "connection:{} cache data failed" , self . index) ;
216
+ self . closing = true ;
217
+ return ;
218
+ } else {
219
+ buffer = & [ ] ;
220
+ }
221
+
210
222
if self . target_addr . is_none ( ) {
211
223
log:: warn!( "connection:{} dns query not done yet" , self . index) ;
212
224
return ;
213
225
}
214
226
215
227
if self . try_setup_tcp_target ( opts, poll) {
228
+ buffer = self . data . as_slice ( ) ;
216
229
self . status = Status :: TCPForward ;
217
230
} else {
218
231
return ;
You can’t perform that action at this time.
0 commit comments