File tree Expand file tree Collapse file tree 4 files changed +16
-12
lines changed
src/client/legacy/connect/proxy/socks Expand file tree Collapse file tree 4 files changed +16
-12
lines changed Original file line number Diff line number Diff line change @@ -41,13 +41,11 @@ where
41
41
T : Read + Unpin ,
42
42
M : for < ' a > TryFrom < & ' a mut BytesMut , Error = ParsingError > ,
43
43
{
44
+ let mut tmp = [ 0 ; 513 ] ;
45
+
44
46
loop {
45
- let n = unsafe {
46
- let spare = & mut * ( buf. spare_capacity_mut ( ) as * mut _ as * mut [ u8 ] ) ;
47
- let n = crate :: rt:: read ( & mut conn, spare) . await ?;
48
- buf. set_len ( buf. len ( ) + n) ;
49
- n
50
- } ;
47
+ let n = crate :: rt:: read ( & mut conn, & mut tmp) . await ?;
48
+ buf. extend_from_slice ( & tmp[ ..n] ) ;
51
49
52
50
match M :: try_from ( buf) {
53
51
Err ( ParsingError :: Incomplete ) => {
Original file line number Diff line number Diff line change @@ -18,7 +18,11 @@ use bytes::BytesMut;
18
18
19
19
use pin_project_lite:: pin_project;
20
20
21
- /// TODO
21
+ /// Tunnel Proxy via SOCKSv4
22
+ ///
23
+ /// This is a connector that can be used by the `legacy::Client`. It wraps
24
+ /// another connector, and after getting an underlying connection, it established
25
+ /// a TCP tunnel over it using SOCKSv4.
22
26
#[ derive( Debug , Clone ) ]
23
27
pub struct SocksV4 < C > {
24
28
inner : C ,
Original file line number Diff line number Diff line change @@ -18,7 +18,11 @@ use bytes::BytesMut;
18
18
19
19
use pin_project_lite:: pin_project;
20
20
21
- /// TODO
21
+ /// Tunnel Proxy via SOCKSv5
22
+ ///
23
+ /// This is a connector that can be used by the `legacy::Client`. It wraps
24
+ /// another connector, and after getting an underlying connection, it established
25
+ /// a TCP tunnel over it using SOCKSv5.
22
26
#[ derive( Debug , Clone ) ]
23
27
pub struct SocksV5 < C > {
24
28
inner : C ,
@@ -154,8 +158,8 @@ impl SocksConfig {
154
158
AuthMethod :: NoAuth
155
159
} ;
156
160
157
- let mut recv_buf = BytesMut :: with_capacity ( 1024 ) ;
158
- let mut send_buf = BytesMut :: with_capacity ( 1024 ) ;
161
+ let mut recv_buf = BytesMut :: with_capacity ( 513 ) ; // Max length of valid recievable message is 513 from Auth Request
162
+ let mut send_buf = BytesMut :: with_capacity ( 262 ) ; // Max length of valid sendable message is 262 from Auth Response
159
163
let mut state = State :: SendingNegReq ;
160
164
161
165
loop {
Original file line number Diff line number Diff line change @@ -360,8 +360,6 @@ async fn test_socks_v4_works() {
360
360
let conn = connector. call ( target_dst) . await . expect ( "tunnel" ) ;
361
361
let mut tcp = conn. into_inner ( ) ;
362
362
363
- // TODO: broken here.
364
-
365
363
tcp. write_all ( b"Hello World!" ) . await . expect ( "write 1" ) ;
366
364
367
365
let mut buf = [ 0u8 ; 64 ] ;
You can’t perform that action at this time.
0 commit comments