Преглед на файлове

Revert "Add new TCPBufferSize parameter to network"

This reverts commit 57cb1b5aa0.
tags/v2.0.0-rc1
9seconds преди 5 години
родител
ревизия
adf4ab1a35

+ 0
- 1
mtglib/init.go Целия файл

27
 	DialContext(ctx context.Context, network, address string) (net.Conn, error)
27
 	DialContext(ctx context.Context, network, address string) (net.Conn, error)
28
 	MakeHTTPClient(func(ctx context.Context, network, address string) (net.Conn, error)) *http.Client
28
 	MakeHTTPClient(func(ctx context.Context, network, address string) (net.Conn, error)) *http.Client
29
 	IdleTimeout() time.Duration
29
 	IdleTimeout() time.Duration
30
-	TCPBufferSize() int
31
 }
30
 }
32
 
31
 
33
 type AntiReplayCache interface {
32
 type AntiReplayCache interface {

+ 0
- 4
network/default.go Целия файл

60
 	return tcpConn, nil
60
 	return tcpConn, nil
61
 }
61
 }
62
 
62
 
63
-func (d *defaultDialer) TCPBufferSize() int {
64
-	return d.bufferSize
65
-}
66
-
67
 func NewDefaultDialer(timeout time.Duration, bufferSize int) (Dialer, error) {
63
 func NewDefaultDialer(timeout time.Duration, bufferSize int) (Dialer, error) {
68
 	switch {
64
 	switch {
69
 	case timeout < 0:
65
 	case timeout < 0:

+ 0
- 4
network/default_test.go Целия файл

71
 	suite.Equal(http.StatusOK, resp.StatusCode)
71
 	suite.Equal(http.StatusOK, resp.StatusCode)
72
 }
72
 }
73
 
73
 
74
-func (suite *DefaultDialerTestSuite) TestTCPBufferSize() {
75
-	suite.Equal(network.DefaultBufferSize, suite.d.TCPBufferSize())
76
-}
77
-
78
 func TestDefaultDialer(t *testing.T) {
74
 func TestDefaultDialer(t *testing.T) {
79
 	t.Parallel()
75
 	t.Parallel()
80
 	suite.Run(t, &DefaultDialerTestSuite{})
76
 	suite.Run(t, &DefaultDialerTestSuite{})

+ 0
- 1
network/init.go Целия файл

29
 type Dialer interface {
29
 type Dialer interface {
30
 	Dial(network, address string) (net.Conn, error)
30
 	Dial(network, address string) (net.Conn, error)
31
 	DialContext(ctx context.Context, network, address string) (net.Conn, error)
31
 	DialContext(ctx context.Context, network, address string) (net.Conn, error)
32
-	TCPBufferSize() int
33
 }
32
 }

+ 0
- 4
network/init_internal_test.go Целия файл

22
 
22
 
23
 	return args.Get(0).(net.Conn), args.Error(1)
23
 	return args.Get(0).(net.Conn), args.Error(1)
24
 }
24
 }
25
-
26
-func (d *DialerMock) TCPBufferSize() int {
27
-	return d.Called().Int(0)
28
-}

+ 0
- 4
network/init_test.go Целия файл

30
 	return args.Get(0).(net.Conn), args.Error(1)
30
 	return args.Get(0).(net.Conn), args.Error(1)
31
 }
31
 }
32
 
32
 
33
-func (d *DialerMock) TCPBufferSize() int {
34
-	return d.Called().Int(0)
35
-}
36
-
37
 type HTTPServerTestSuite struct {
33
 type HTTPServerTestSuite struct {
38
 	httpServer *httptest.Server
34
 	httpServer *httptest.Server
39
 }
35
 }

+ 2
- 8
network/load_balanced_socks5.go Целия файл

9
 )
9
 )
10
 
10
 
11
 type loadBalancedSocks5Dialer struct {
11
 type loadBalancedSocks5Dialer struct {
12
-	dialers    []Dialer
13
-	bufferSize int
12
+	dialers []Dialer
14
 }
13
 }
15
 
14
 
16
 func (l loadBalancedSocks5Dialer) Dial(network, address string) (net.Conn, error) {
15
 func (l loadBalancedSocks5Dialer) Dial(network, address string) (net.Conn, error) {
17
 	return l.DialContext(context.Background(), network, address)
16
 	return l.DialContext(context.Background(), network, address)
18
 }
17
 }
19
 
18
 
20
-func (l loadBalancedSocks5Dialer) TCPBufferSize() int {
21
-	return l.bufferSize
22
-}
23
-
24
 func (l loadBalancedSocks5Dialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
19
 func (l loadBalancedSocks5Dialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
25
 	length := len(l.dialers)
20
 	length := len(l.dialers)
26
 	start := rand.Intn(length)
21
 	start := rand.Intn(length)
50
 	}
45
 	}
51
 
46
 
52
 	return loadBalancedSocks5Dialer{
47
 	return loadBalancedSocks5Dialer{
53
-		dialers:    dialers,
54
-		bufferSize: baseDialer.TCPBufferSize(),
48
+		dialers: dialers,
55
 	}, nil
49
 	}, nil
56
 }
50
 }

+ 0
- 1
network/load_balanced_socks5_test.go Целия файл

57
 	baseDialer.On("DialContext", mock.Anything, "tcp", "127.0.0.2:1080").
57
 	baseDialer.On("DialContext", mock.Anything, "tcp", "127.0.0.2:1080").
58
 		Times(network.ProxyDialerOpenThreshold).
58
 		Times(network.ProxyDialerOpenThreshold).
59
 		Return(&net.TCPConn{}, io.EOF)
59
 		Return(&net.TCPConn{}, io.EOF)
60
-	baseDialer.On("TCPBufferSize").Return(network.DefaultBufferSize)
61
 
60
 
62
 	lbDialer, err := network.NewLoadBalancedSocks5Dialer(baseDialer, []*url.URL{
61
 	lbDialer, err := network.NewLoadBalancedSocks5Dialer(baseDialer, []*url.URL{
63
 		{Scheme: "socks5", User: url.UserPassword("user", "password"), Host: "127.0.0.1:1080"},
62
 		{Scheme: "socks5", User: url.UserPassword("user", "password"), Host: "127.0.0.1:1080"},

+ 0
- 4
network/network.go Целия файл

75
 	return n.idleTimeout
75
 	return n.idleTimeout
76
 }
76
 }
77
 
77
 
78
-func (n *network) TCPBufferSize() int {
79
-	return n.dialer.TCPBufferSize()
80
-}
81
-
82
 func (n *network) dnsResolve(protocol, address string) ([]string, error) {
78
 func (n *network) dnsResolve(protocol, address string) ([]string, error) {
83
 	if net.ParseIP(address) != nil {
79
 	if net.ParseIP(address) != nil {
84
 		return []string{address}, nil
80
 		return []string{address}, nil

+ 1
- 19
network/socks5.go Целия файл

2
 
2
 
3
 import (
3
 import (
4
 	"fmt"
4
 	"fmt"
5
-	"net"
6
 	"net/url"
5
 	"net/url"
7
 
6
 
8
 	"golang.org/x/net/proxy"
7
 	"golang.org/x/net/proxy"
9
 )
8
 )
10
 
9
 
11
-type socks5Dialer struct {
12
-	proxy.ContextDialer
13
-
14
-	bufferSize int
15
-}
16
-
17
-func (s socks5Dialer) Dial(protocol, address string) (net.Conn, error) {
18
-	return s.ContextDialer.(proxy.Dialer).Dial(protocol, address)
19
-}
20
-
21
-func (s socks5Dialer) TCPBufferSize() int {
22
-	return s.bufferSize
23
-}
24
-
25
 func NewSocks5Dialer(baseDialer Dialer, proxyURL *url.URL) (Dialer, error) {
10
 func NewSocks5Dialer(baseDialer Dialer, proxyURL *url.URL) (Dialer, error) {
26
 	rv, err := proxy.FromURL(proxyURL, baseDialer)
11
 	rv, err := proxy.FromURL(proxyURL, baseDialer)
27
 	if err != nil {
12
 	if err != nil {
28
 		return nil, fmt.Errorf("cannot initialize socks5 proxy dialer: %w", err)
13
 		return nil, fmt.Errorf("cannot initialize socks5 proxy dialer: %w", err)
29
 	}
14
 	}
30
 
15
 
31
-	return socks5Dialer{
32
-		ContextDialer: rv.(proxy.ContextDialer),
33
-		bufferSize:    baseDialer.TCPBufferSize(),
34
-	}, nil
16
+	return rv.(Dialer), nil
35
 }
17
 }

+ 0
- 4
testlib/mtglib_network_mock.go Целия файл

33
 func (m *MtglibNetworkMock) IdleTimeout() time.Duration {
33
 func (m *MtglibNetworkMock) IdleTimeout() time.Duration {
34
 	return m.Called().Get(0).(time.Duration)
34
 	return m.Called().Get(0).(time.Duration)
35
 }
35
 }
36
-
37
-func (m *MtglibNetworkMock) TCPBufferSize() int {
38
-	return m.Called().Int(0)
39
-}

Loading…
Отказ
Запис