Revert "Add new TCPBufferSize parameter to network"

This reverts commit 57cb1b5aa0.
This commit is contained in:
9seconds
2021-03-17 22:03:36 +03:00
parent 83eeedc008
commit adf4ab1a35
11 changed files with 3 additions and 54 deletions
-1
View File
@@ -27,7 +27,6 @@ type Network interface {
DialContext(ctx context.Context, network, address string) (net.Conn, error)
MakeHTTPClient(func(ctx context.Context, network, address string) (net.Conn, error)) *http.Client
IdleTimeout() time.Duration
TCPBufferSize() int
}
type AntiReplayCache interface {
-4
View File
@@ -60,10 +60,6 @@ func (d *defaultDialer) DialContext(ctx context.Context, network, address string
return tcpConn, nil
}
func (d *defaultDialer) TCPBufferSize() int {
return d.bufferSize
}
func NewDefaultDialer(timeout time.Duration, bufferSize int) (Dialer, error) {
switch {
case timeout < 0:
-4
View File
@@ -71,10 +71,6 @@ func (suite *DefaultDialerTestSuite) TestHTTPRequest() {
suite.Equal(http.StatusOK, resp.StatusCode)
}
func (suite *DefaultDialerTestSuite) TestTCPBufferSize() {
suite.Equal(network.DefaultBufferSize, suite.d.TCPBufferSize())
}
func TestDefaultDialer(t *testing.T) {
t.Parallel()
suite.Run(t, &DefaultDialerTestSuite{})
-1
View File
@@ -29,5 +29,4 @@ var (
type Dialer interface {
Dial(network, address string) (net.Conn, error)
DialContext(ctx context.Context, network, address string) (net.Conn, error)
TCPBufferSize() int
}
-4
View File
@@ -22,7 +22,3 @@ func (d *DialerMock) DialContext(ctx context.Context, network, address string) (
return args.Get(0).(net.Conn), args.Error(1)
}
func (d *DialerMock) TCPBufferSize() int {
return d.Called().Int(0)
}
-4
View File
@@ -30,10 +30,6 @@ func (d *DialerMock) DialContext(ctx context.Context, network, address string) (
return args.Get(0).(net.Conn), args.Error(1)
}
func (d *DialerMock) TCPBufferSize() int {
return d.Called().Int(0)
}
type HTTPServerTestSuite struct {
httpServer *httptest.Server
}
+2 -8
View File
@@ -9,18 +9,13 @@ import (
)
type loadBalancedSocks5Dialer struct {
dialers []Dialer
bufferSize int
dialers []Dialer
}
func (l loadBalancedSocks5Dialer) Dial(network, address string) (net.Conn, error) {
return l.DialContext(context.Background(), network, address)
}
func (l loadBalancedSocks5Dialer) TCPBufferSize() int {
return l.bufferSize
}
func (l loadBalancedSocks5Dialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
length := len(l.dialers)
start := rand.Intn(length)
@@ -50,7 +45,6 @@ func NewLoadBalancedSocks5Dialer(baseDialer Dialer, proxyURLs []*url.URL) (Diale
}
return loadBalancedSocks5Dialer{
dialers: dialers,
bufferSize: baseDialer.TCPBufferSize(),
dialers: dialers,
}, nil
}
-1
View File
@@ -57,7 +57,6 @@ func (suite *LoadBalancedSocks5TestSuite) TestCannotDial() {
baseDialer.On("DialContext", mock.Anything, "tcp", "127.0.0.2:1080").
Times(network.ProxyDialerOpenThreshold).
Return(&net.TCPConn{}, io.EOF)
baseDialer.On("TCPBufferSize").Return(network.DefaultBufferSize)
lbDialer, err := network.NewLoadBalancedSocks5Dialer(baseDialer, []*url.URL{
{Scheme: "socks5", User: url.UserPassword("user", "password"), Host: "127.0.0.1:1080"},
-4
View File
@@ -75,10 +75,6 @@ func (n *network) IdleTimeout() time.Duration {
return n.idleTimeout
}
func (n *network) TCPBufferSize() int {
return n.dialer.TCPBufferSize()
}
func (n *network) dnsResolve(protocol, address string) ([]string, error) {
if net.ParseIP(address) != nil {
return []string{address}, nil
+1 -19
View File
@@ -2,34 +2,16 @@ package network
import (
"fmt"
"net"
"net/url"
"golang.org/x/net/proxy"
)
type socks5Dialer struct {
proxy.ContextDialer
bufferSize int
}
func (s socks5Dialer) Dial(protocol, address string) (net.Conn, error) {
return s.ContextDialer.(proxy.Dialer).Dial(protocol, address)
}
func (s socks5Dialer) TCPBufferSize() int {
return s.bufferSize
}
func NewSocks5Dialer(baseDialer Dialer, proxyURL *url.URL) (Dialer, error) {
rv, err := proxy.FromURL(proxyURL, baseDialer)
if err != nil {
return nil, fmt.Errorf("cannot initialize socks5 proxy dialer: %w", err)
}
return socks5Dialer{
ContextDialer: rv.(proxy.ContextDialer),
bufferSize: baseDialer.TCPBufferSize(),
}, nil
return rv.(Dialer), nil
}
-4
View File
@@ -33,7 +33,3 @@ func (m *MtglibNetworkMock) MakeHTTPClient(dialFunc func(ctx context.Context,
func (m *MtglibNetworkMock) IdleTimeout() time.Duration {
return m.Called().Get(0).(time.Duration)
}
func (m *MtglibNetworkMock) TCPBufferSize() int {
return m.Called().Int(0)
}