Skip to content

Commit aa6de8b

Browse files
committed
Fix mixhandlering of SOCKS5 timeout
1 parent 31ce1c1 commit aa6de8b

File tree

1 file changed

+10
-34
lines changed

1 file changed

+10
-34
lines changed

application/network/dial_socks5.go

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,76 +20,52 @@ package network
2020
import (
2121
"context"
2222
"net"
23-
"time"
2423

2524
"golang.org/x/net/proxy"
2625
)
2726

2827
type socks5Dial struct {
29-
net.Dialer
30-
ctx context.Context
28+
dialer net.Dialer
29+
ctx context.Context
3130
}
3231

3332
func (s socks5Dial) Dial(
3433
network string,
3534
address string,
3635
) (net.Conn, error) {
37-
conn, dErr := s.Dialer.DialContext(s.ctx, network, address)
38-
39-
if dErr == nil {
40-
conn.SetReadDeadline(time.Now().Add(s.Dialer.Timeout))
41-
}
42-
43-
return conn, dErr
44-
}
45-
46-
func (s socks5Dial) DialContext(
47-
ctx context.Context, network, address string) (net.Conn, error) {
48-
conn, dErr := s.Dialer.DialContext(ctx, network, address)
49-
50-
if dErr == nil {
51-
conn.SetReadDeadline(time.Now().Add(s.Dialer.Timeout))
52-
}
53-
54-
return conn, dErr
36+
return s.dialer.DialContext(s.ctx, network, address)
5537
}
5638

5739
// BuildSocks5Dial builds a Socks5 dialer
5840
func BuildSocks5Dial(
59-
socks5Address string, userName string, password string) (Dial, error) {
41+
socks5Address string,
42+
userName string,
43+
password string,
44+
) (Dial, error) {
6045
var auth *proxy.Auth
61-
6246
if len(userName) > 0 || len(password) > 0 {
6347
auth = &proxy.Auth{
6448
User: userName,
6549
Password: password,
6650
}
6751
}
6852

69-
return func(
70-
ctx context.Context,
71-
network string,
72-
address string,
73-
) (net.Conn, error) {
53+
return func(ctx context.Context, n string, addr string) (net.Conn, error) {
7454
dialCfg := socks5Dial{
75-
Dialer: net.Dialer{},
55+
dialer: net.Dialer{},
7656
ctx: ctx,
7757
}
7858

7959
dial, dialErr := proxy.SOCKS5("tcp", socks5Address, auth, &dialCfg)
80-
8160
if dialErr != nil {
8261
return nil, dialErr
8362
}
8463

85-
dialConn, dialErr := dial.Dial(network, address)
86-
64+
dialConn, dialErr := dial.Dial(n, addr)
8765
if dialErr != nil {
8866
return nil, dialErr
8967
}
9068

91-
dialConn.SetReadDeadline(emptyTime)
92-
9369
return dialConn, nil
9470
}, nil
9571
}

0 commit comments

Comments
 (0)