9seconds 4 лет назад
Родитель
Сommit
e0850869ba

+ 2
- 1
internal/cli/run_proxy.go Просмотреть файл

89
 func makeIPBlocklist(conf config.ListConfig,
89
 func makeIPBlocklist(conf config.ListConfig,
90
 	logger mtglib.Logger,
90
 	logger mtglib.Logger,
91
 	ntw mtglib.Network,
91
 	ntw mtglib.Network,
92
-	updateCallback ipblocklist.FireholUpdateCallback) (mtglib.IPBlocklist, error) {
92
+	updateCallback ipblocklist.FireholUpdateCallback,
93
+) (mtglib.IPBlocklist, error) {
93
 	if !conf.Enabled.Get(false) {
94
 	if !conf.Enabled.Get(false) {
94
 		return ipblocklist.NewNoop(), nil
95
 		return ipblocklist.NewNoop(), nil
95
 	}
96
 	}

+ 2
- 1
internal/testlib/mtglib_network_mock.go Просмотреть файл

25
 }
25
 }
26
 
26
 
27
 func (m *MtglibNetworkMock) MakeHTTPClient(dialFunc func(ctx context.Context,
27
 func (m *MtglibNetworkMock) MakeHTTPClient(dialFunc func(ctx context.Context,
28
-	network, address string) (essentials.Conn, error)) *http.Client {
28
+	network, address string) (essentials.Conn, error),
29
+) *http.Client {
29
 	return m.Called(dialFunc).Get(0).(*http.Client) // nolint: forcetypeassert
30
 	return m.Called(dialFunc).Get(0).(*http.Client) // nolint: forcetypeassert
30
 }
31
 }

+ 6
- 3
ipblocklist/firehol.go Просмотреть файл

155
 
155
 
156
 func (f *Firehol) updateFromFile(mutex sync.Locker,
156
 func (f *Firehol) updateFromFile(mutex sync.Locker,
157
 	ranger cidranger.Ranger,
157
 	ranger cidranger.Ranger,
158
-	scanner *bufio.Scanner) error {
158
+	scanner *bufio.Scanner,
159
+) error {
159
 	for scanner.Scan() {
160
 	for scanner.Scan() {
160
 		text := scanner.Text()
161
 		text := scanner.Text()
161
 		text = fireholRegexpComment.ReplaceAllLiteralString(text, "")
162
 		text = fireholRegexpComment.ReplaceAllLiteralString(text, "")
216
 	downloadConcurrency uint,
217
 	downloadConcurrency uint,
217
 	urls []string,
218
 	urls []string,
218
 	localFiles []string,
219
 	localFiles []string,
219
-	updateCallback FireholUpdateCallback) (*Firehol, error) {
220
+	updateCallback FireholUpdateCallback,
221
+) (*Firehol, error) {
220
 	blocklists := []files.File{}
222
 	blocklists := []files.File{}
221
 
223
 
222
 	for _, v := range localFiles {
224
 	for _, v := range localFiles {
245
 func NewFireholFromFiles(logger mtglib.Logger,
247
 func NewFireholFromFiles(logger mtglib.Logger,
246
 	downloadConcurrency uint,
248
 	downloadConcurrency uint,
247
 	blocklists []files.File,
249
 	blocklists []files.File,
248
-	updateCallback FireholUpdateCallback) (*Firehol, error) {
250
+	updateCallback FireholUpdateCallback,
251
+) (*Firehol, error) {
249
 	if downloadConcurrency == 0 {
252
 	if downloadConcurrency == 0 {
250
 		downloadConcurrency = DefaultFireholDownloadConcurrency
253
 		downloadConcurrency = DefaultFireholDownloadConcurrency
251
 	}
254
 	}

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

7
 	"github.com/stretchr/testify/require"
7
 	"github.com/stretchr/testify/require"
8
 )
8
 )
9
 
9
 
10
-var FuzzClientHandshakeSecret = []byte{1,2,3}
10
+var FuzzClientHandshakeSecret = []byte{1, 2, 3}
11
 
11
 
12
 func FuzzClientHandshake(f *testing.F) {
12
 func FuzzClientHandshake(f *testing.F) {
13
-	f.Add([]byte{1,2,3})
13
+	f.Add([]byte{1, 2, 3})
14
 
14
 
15
 	f.Fuzz(func(t *testing.T, frame []byte) {
15
 	f.Fuzz(func(t *testing.T, frame []byte) {
16
 		data := bytes.NewReader(frame)
16
 		data := bytes.NewReader(frame)

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

127
 	return ServerHandshakeTestData{
127
 	return ServerHandshakeTestData{
128
 		connMock: connMock,
128
 		connMock: connMock,
129
 		proxyConn: obfuscated2.Conn{
129
 		proxyConn: obfuscated2.Conn{
130
-			Conn: connMock,
130
+			Conn:      connMock,
131
 			Encryptor: handshakeEnc,
131
 			Encryptor: handshakeEnc,
132
 			Decryptor: handshakeDec,
132
 			Decryptor: handshakeDec,
133
 		},
133
 		},

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

23
 		assert.NotEqualValues(
23
 		assert.NotEqualValues(
24
 			t,
24
 			t,
25
 			0,
25
 			0,
26
-			frame.data[4] | frame.data[5] | frame.data[6] | frame.data[7])
26
+			frame.data[4]|frame.data[5]|frame.data[6]|frame.data[7])
27
 
27
 
28
 		assert.Equal(t, handshakeConnectionType, frame.connectionType())
28
 		assert.Equal(t, handshakeConnectionType, frame.connectionType())
29
 	})
29
 	})

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

8
 )
8
 )
9
 
9
 
10
 func FuzzServerSend(f *testing.F) {
10
 func FuzzServerSend(f *testing.F) {
11
-	f.Add([]byte{1,2,3,4,5})
11
+	f.Add([]byte{1, 2, 3, 4, 5})
12
 
12
 
13
 	f.Fuzz(func(t *testing.T, data []byte) {
13
 	f.Fuzz(func(t *testing.T, data []byte) {
14
 		handshakeData := NewServerHandshakeTestData(t)
14
 		handshakeData := NewServerHandshakeTestData(t)
32
 }
32
 }
33
 
33
 
34
 func FuzzServerReceive(f *testing.F) {
34
 func FuzzServerReceive(f *testing.F) {
35
-	f.Add([]byte{1,2,3,4,5})
35
+	f.Add([]byte{1, 2, 3, 4, 5})
36
 
36
 
37
 	f.Fuzz(func(t *testing.T, data []byte) {
37
 	f.Fuzz(func(t *testing.T, data []byte) {
38
 		handshakeData := NewServerHandshakeTestData(t)
38
 		handshakeData := NewServerHandshakeTestData(t)

+ 10
- 5
network/circuit_breaker.go Просмотреть файл

36
 }
36
 }
37
 
37
 
38
 func (c *circuitBreakerDialer) DialContext(ctx context.Context,
38
 func (c *circuitBreakerDialer) DialContext(ctx context.Context,
39
-	network, address string) (essentials.Conn, error) {
39
+	network, address string,
40
+) (essentials.Conn, error) {
40
 	switch atomic.LoadUint32(&c.state) {
41
 	switch atomic.LoadUint32(&c.state) {
41
 	case circuitBreakerStateClosed:
42
 	case circuitBreakerStateClosed:
42
 		return c.doClosed(ctx, network, address)
43
 		return c.doClosed(ctx, network, address)
48
 }
49
 }
49
 
50
 
50
 func (c *circuitBreakerDialer) doClosed(ctx context.Context,
51
 func (c *circuitBreakerDialer) doClosed(ctx context.Context,
51
-	network, address string) (essentials.Conn, error) {
52
+	network, address string,
53
+) (essentials.Conn, error) {
52
 	conn, err := c.Dialer.DialContext(ctx, network, address)
54
 	conn, err := c.Dialer.DialContext(ctx, network, address)
53
 
55
 
54
 	select {
56
 	select {
80
 }
82
 }
81
 
83
 
82
 func (c *circuitBreakerDialer) doHalfOpened(ctx context.Context,
84
 func (c *circuitBreakerDialer) doHalfOpened(ctx context.Context,
83
-	network, address string) (essentials.Conn, error) {
85
+	network, address string,
86
+) (essentials.Conn, error) {
84
 	if !atomic.CompareAndSwapUint32(&c.halfOpenAttempts, 0, 1) {
87
 	if !atomic.CompareAndSwapUint32(&c.halfOpenAttempts, 0, 1) {
85
 		return nil, ErrCircuitBreakerOpened
88
 		return nil, ErrCircuitBreakerOpened
86
 	}
89
 	}
174
 }
177
 }
175
 
178
 
176
 func (c *circuitBreakerDialer) ensureTimer(timerRef **time.Timer,
179
 func (c *circuitBreakerDialer) ensureTimer(timerRef **time.Timer,
177
-	timeout time.Duration, callback func()) {
180
+	timeout time.Duration, callback func(),
181
+) {
178
 	if *timerRef == nil {
182
 	if *timerRef == nil {
179
 		*timerRef = time.AfterFunc(timeout, callback)
183
 		*timerRef = time.AfterFunc(timeout, callback)
180
 	}
184
 	}
181
 }
185
 }
182
 
186
 
183
 func newCircuitBreakerDialer(baseDialer Dialer,
187
 func newCircuitBreakerDialer(baseDialer Dialer,
184
-	openThreshold uint32, halfOpenTimeout, resetFailuresTimeout time.Duration) Dialer {
188
+	openThreshold uint32, halfOpenTimeout, resetFailuresTimeout time.Duration,
189
+) Dialer {
185
 	cb := &circuitBreakerDialer{
190
 	cb := &circuitBreakerDialer{
186
 		Dialer:               baseDialer,
191
 		Dialer:               baseDialer,
187
 		stateMutexChan:       make(chan bool, 1),
192
 		stateMutexChan:       make(chan bool, 1),

+ 6
- 3
network/network.go Просмотреть файл

61
 }
61
 }
62
 
62
 
63
 func (n *network) MakeHTTPClient(dialFunc func(ctx context.Context,
63
 func (n *network) MakeHTTPClient(dialFunc func(ctx context.Context,
64
-	network, address string) (essentials.Conn, error)) *http.Client {
64
+	network, address string) (essentials.Conn, error),
65
+) *http.Client {
65
 	if dialFunc == nil {
66
 	if dialFunc == nil {
66
 		dialFunc = n.DialContext
67
 		dialFunc = n.DialContext
67
 	}
68
 	}
123
 // It brings simple DNS cache and DNS-Over-HTTPS when necessary.
124
 // It brings simple DNS cache and DNS-Over-HTTPS when necessary.
124
 func NewNetwork(dialer Dialer,
125
 func NewNetwork(dialer Dialer,
125
 	userAgent, dohHostname string,
126
 	userAgent, dohHostname string,
126
-	httpTimeout time.Duration) (mtglib.Network, error) {
127
+	httpTimeout time.Duration,
128
+) (mtglib.Network, error) {
127
 	switch {
129
 	switch {
128
 	case httpTimeout < 0:
130
 	case httpTimeout < 0:
129
 		return nil, fmt.Errorf("timeout should be positive number %s", httpTimeout)
131
 		return nil, fmt.Errorf("timeout should be positive number %s", httpTimeout)
146
 
148
 
147
 func makeHTTPClient(userAgent string,
149
 func makeHTTPClient(userAgent string,
148
 	timeout time.Duration,
150
 	timeout time.Duration,
149
-	dialFunc func(ctx context.Context, network, address string) (essentials.Conn, error)) *http.Client {
151
+	dialFunc func(ctx context.Context, network, address string) (essentials.Conn, error),
152
+) *http.Client {
150
 	return &http.Client{
153
 	return &http.Client{
151
 		Timeout: timeout,
154
 		Timeout: timeout,
152
 		Transport: networkHTTPTransport{
155
 		Transport: networkHTTPTransport{

+ 2
- 1
stats/statsd.go Просмотреть файл

171
 //
171
 //
172
 // Valid tagFormats are 'datadog', 'influxdb' and 'graphite'.
172
 // Valid tagFormats are 'datadog', 'influxdb' and 'graphite'.
173
 func NewStatsd(address string, log logger.StdLikeLogger,
173
 func NewStatsd(address string, log logger.StdLikeLogger,
174
-	metricPrefix, tagFormat string) (StatsdFactory, error) {
174
+	metricPrefix, tagFormat string,
175
+) (StatsdFactory, error) {
175
 	options := []statsd.Option{
176
 	options := []statsd.Option{
176
 		statsd.MetricPrefix(metricPrefix),
177
 		statsd.MetricPrefix(metricPrefix),
177
 		statsd.Logger(log),
178
 		statsd.Logger(log),

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