Przeglądaj źródła

Use native dialer for scout

tags/v2.2.0^2^2
9seconds 1 miesiąc temu
rodzic
commit
cc63e762e3

+ 6
- 1
mtglib/internal/doppel/init.go Wyświetl plik

@@ -2,6 +2,7 @@ package doppel
2 2
 
3 3
 import (
4 4
 	"context"
5
+	"net"
5 6
 	"net/http"
6 7
 	"time"
7 8
 
@@ -28,11 +29,15 @@ type Network interface {
28 29
 	// Dial establishes context-free TCP connections.
29 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 33
 	// establishing TCP connections.
33 34
 	DialContext(ctx context.Context, network, address string) (essentials.Conn, error)
34 35
 
35 36
 	// MakeHTTPClient build an HTTP client with given dial function. If nothing is
36 37
 	// provided, then DialContext of this interface is going to be used.
37 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 Wyświetl plik

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

+ 3
- 2
mtglib/internal/doppel/scout.go Wyświetl plik

@@ -79,18 +79,19 @@ func (s Scout) learn(ctx context.Context, url string) ([]time.Duration, error) {
79 79
 }
80 80
 
81 81
 func (s Scout) makeClient() (*http.Client, *ScoutConnCollected) {
82
+	dialer := s.network.NativeDialer()
82 83
 	collected := NewScoutConnCollected()
83 84
 	client := s.network.MakeHTTPClient(func(
84 85
 		ctx context.Context,
85 86
 		network string,
86 87
 		address string,
87 88
 	) (essentials.Conn, error) {
88
-		conn, err := s.network.DialContext(ctx, network, address)
89
+		conn, err := dialer.DialContext(ctx, network, address)
89 90
 		if err != nil {
90 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 97
 	return client, collected

Ładowanie…
Anuluj
Zapisz