Просмотр исходного кода

Use native dialer for scout

tags/v2.2.0^2^2
9seconds 1 месяц назад
Родитель
Сommit
cc63e762e3
3 измененных файлов: 13 добавлений и 3 удалений
  1. 6
    1
      mtglib/internal/doppel/init.go
  2. 4
    0
      mtglib/internal/doppel/init_test.go
  3. 3
    2
      mtglib/internal/doppel/scout.go

+ 6
- 1
mtglib/internal/doppel/init.go Просмотреть файл

2
 
2
 
3
 import (
3
 import (
4
 	"context"
4
 	"context"
5
+	"net"
5
 	"net/http"
6
 	"net/http"
6
 	"time"
7
 	"time"
7
 
8
 
28
 	// Dial establishes context-free TCP connections.
29
 	// Dial establishes context-free TCP connections.
29
 	Dial(network, address string) (essentials.Conn, error)
30
 	Dial(network, address string) (essentials.Conn, error)
30
 
31
 
31
-	// DialContext dials using a context. This is a preferrable way of
32
+	// DialContext dials using a context. This is a preferable way of
32
 	// establishing TCP connections.
33
 	// establishing TCP connections.
33
 	DialContext(ctx context.Context, network, address string) (essentials.Conn, error)
34
 	DialContext(ctx context.Context, network, address string) (essentials.Conn, error)
34
 
35
 
35
 	// MakeHTTPClient build an HTTP client with given dial function. If nothing is
36
 	// MakeHTTPClient build an HTTP client with given dial function. If nothing is
36
 	// provided, then DialContext of this interface is going to be used.
37
 	// provided, then DialContext of this interface is going to be used.
37
 	MakeHTTPClient(func(ctx context.Context, network, address string) (essentials.Conn, error)) *http.Client
38
 	MakeHTTPClient(func(ctx context.Context, network, address string) (essentials.Conn, error)) *http.Client
39
+
40
+	// NativeDialer returns a configured instance of native dialer that
41
+	// skips proxy connections or any other irrelevant settings.
42
+	NativeDialer() *net.Dialer
38
 }
43
 }

+ 4
- 0
mtglib/internal/doppel/init_test.go Просмотреть файл

30
 	return conn.(*net.TCPConn), nil
30
 	return conn.(*net.TCPConn), nil
31
 }
31
 }
32
 
32
 
33
+func (s SimpleNetwork) NativeDialer() *net.Dialer {
34
+	return &net.Dialer{}
35
+}
36
+
33
 func (s SimpleNetwork) MakeHTTPClient(dialFunc func(ctx context.Context, network, address string) (essentials.Conn, error)) *http.Client {
37
 func (s SimpleNetwork) MakeHTTPClient(dialFunc func(ctx context.Context, network, address string) (essentials.Conn, error)) *http.Client {
34
 	if dialFunc == nil {
38
 	if dialFunc == nil {
35
 		dialFunc = s.DialContext
39
 		dialFunc = s.DialContext

+ 3
- 2
mtglib/internal/doppel/scout.go Просмотреть файл

79
 }
79
 }
80
 
80
 
81
 func (s Scout) makeClient() (*http.Client, *ScoutConnCollected) {
81
 func (s Scout) makeClient() (*http.Client, *ScoutConnCollected) {
82
+	dialer := s.network.NativeDialer()
82
 	collected := NewScoutConnCollected()
83
 	collected := NewScoutConnCollected()
83
 	client := s.network.MakeHTTPClient(func(
84
 	client := s.network.MakeHTTPClient(func(
84
 		ctx context.Context,
85
 		ctx context.Context,
85
 		network string,
86
 		network string,
86
 		address string,
87
 		address string,
87
 	) (essentials.Conn, error) {
88
 	) (essentials.Conn, error) {
88
-		conn, err := s.network.DialContext(ctx, network, address)
89
+		conn, err := dialer.DialContext(ctx, network, address)
89
 		if err != nil {
90
 		if err != nil {
90
 			return nil, err
91
 			return nil, err
91
 		}
92
 		}
92
 
93
 
93
-		return NewScoutConn(conn, collected), nil
94
+		return NewScoutConn(essentials.WrapNetConn(conn), collected), nil
94
 	})
95
 	})
95
 
96
 
96
 	return client, collected
97
 	return client, collected

Загрузка…
Отмена
Сохранить