Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/prometheus/procfs v0.19.2 // indirect
github.com/rs/zerolog v1.34.0
github.com/smira/go-statsd v1.3.4
github.com/stretchr/objx v0.5.2 // indirect
github.com/stretchr/objx v0.5.3 // indirect
github.com/stretchr/testify v1.11.1
github.com/tylertreat/BoomFilters v0.0.0-20251117164519-53813c36cc1b
golang.org/x/crypto v0.48.0
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ github.com/smira/go-statsd v1.3.4/go.mod h1:RjdsESPgDODtg1VpVVf9MJrEW2Hw0wtRNbmB
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/objx v0.5.3 h1:jmXUvGomnU1o3W/V5h2VEradbpJDwGrzugQQvL0POH4=
github.com/stretchr/objx v0.5.3/go.mod h1:rDQraq+vQZU7Fde9LOZLr8Tax6zZvy4kuNKF+QYS+U0=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (a *Access) getIP(ntw mtglib.Network, protocol string) net.IP {

defer func() {
io.Copy(io.Discard, resp.Body) //nolint: errcheck
resp.Body.Close() //nolint: errcheck
resp.Body.Close() //nolint: errcheck
}()

data, err := io.ReadAll(resp.Body)
Expand Down
4 changes: 2 additions & 2 deletions internal/config/type_bool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type TypeBoolTestSuite struct {
}

func (suite *TypeBoolTestSuite) TestUnmarshalFail() {
testData := []interface{}{
testData := []any{
"",
"np",
"нет",
Expand All @@ -29,7 +29,7 @@ func (suite *TypeBoolTestSuite) TestUnmarshalFail() {
}

for _, v := range testData {
data, err := json.Marshal(map[string]interface{}{
data, err := json.Marshal(map[string]any{
"value": v,
})
suite.NoError(err)
Expand Down
1 change: 0 additions & 1 deletion internal/utils/root_context.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !windows
// +build !windows

package utils

Expand Down
1 change: 0 additions & 1 deletion internal/utils/root_context_windows.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build windows
// +build windows

package utils

Expand Down
2 changes: 1 addition & 1 deletion ipblocklist/files/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (h httpFile) Open(ctx context.Context) (io.ReadCloser, error) {
if err != nil {
if response != nil {
io.Copy(io.Discard, response.Body) //nolint: errcheck
response.Body.Close() //nolint: errcheck
response.Body.Close() //nolint: errcheck
}

return nil, fmt.Errorf("cannot get url %s: %w", h.url, err)
Expand Down
2 changes: 1 addition & 1 deletion logger/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ package logger
// commonly used by many 3pp tools. While mtglib itself does not need it, it is
// always a good idea to support it and have a transient end to end logging.
type StdLikeLogger interface {
Printf(format string, args ...interface{})
Printf(format string, args ...any)
}
2 changes: 1 addition & 1 deletion logger/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ func (n noopLogger) Named(_ string) mtglib.Logger { return n }
func (n noopLogger) BindInt(_ string, _ int) mtglib.Logger { return n }
func (n noopLogger) BindStr(_, _ string) mtglib.Logger { return n }
func (n noopLogger) BindJSON(_, _ string) mtglib.Logger { return n }
func (n noopLogger) Printf(_ string, _ ...interface{}) {}
func (n noopLogger) Printf(_ string, _ ...any) {}
func (n noopLogger) Info(_ string) {}
func (n noopLogger) Warning(_ string) {}
func (n noopLogger) Debug(_ string) {}
Expand Down
2 changes: 1 addition & 1 deletion logger/zerolog.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (z *zeroLogContext) BindJSON(name, value string) mtglib.Logger {
}
}

func (z *zeroLogContext) Printf(format string, args ...interface{}) {
func (z *zeroLogContext) Printf(format string, args ...any) {
z.Debug(fmt.Sprintf(format, args...))
}

Expand Down
2 changes: 1 addition & 1 deletion mtglib/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ type Logger interface {
BindJSON(name, value string) Logger

// Printf is to support log.Logger behavior.
Printf(format string, args ...interface{})
Printf(format string, args ...any)

// Info puts a message about some normal situation.
Info(msg string)
Expand Down
22 changes: 11 additions & 11 deletions mtglib/init_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import (

type NoopLogger struct{}

func (n NoopLogger) Named(_ string) Logger { return n }
func (n NoopLogger) BindInt(_ string, _ int) Logger { return n }
func (n NoopLogger) BindStr(_, _ string) Logger { return n }
func (n NoopLogger) BindJSON(_, _ string) Logger { return n }
func (n NoopLogger) Printf(_ string, _ ...interface{}) {}
func (n NoopLogger) Info(_ string) {}
func (n NoopLogger) Warning(_ string) {}
func (n NoopLogger) Debug(_ string) {}
func (n NoopLogger) InfoError(_ string, _ error) {}
func (n NoopLogger) WarningError(_ string, _ error) {}
func (n NoopLogger) DebugError(_ string, _ error) {}
func (n NoopLogger) Named(_ string) Logger { return n }
func (n NoopLogger) BindInt(_ string, _ int) Logger { return n }
func (n NoopLogger) BindStr(_, _ string) Logger { return n }
func (n NoopLogger) BindJSON(_, _ string) Logger { return n }
func (n NoopLogger) Printf(_ string, _ ...any) {}
func (n NoopLogger) Info(_ string) {}
func (n NoopLogger) Warning(_ string) {}
func (n NoopLogger) Debug(_ string) {}
func (n NoopLogger) InfoError(_ string, _ error) {}
func (n NoopLogger) WarningError(_ string, _ error) {}
func (n NoopLogger) DebugError(_ string, _ error) {}

type EventStreamMock struct {
mock.Mock
Expand Down
2 changes: 1 addition & 1 deletion mtglib/internal/faketls/client_hello.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func ParseClientHello(secret, handshake []byte) (ClientHello, error) {

computedRandom := mac.Sum(nil)

for i := 0; i < RandomLen; i++ {
for i := range RandomLen {
computedRandom[i] ^= hello.Random[i]
}

Expand Down
2 changes: 1 addition & 1 deletion mtglib/internal/faketls/pools.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

var bytesBufferPool = sync.Pool{
New: func() interface{} {
New: func() any {
return &bytes.Buffer{}
},
}
Expand Down
2 changes: 1 addition & 1 deletion mtglib/internal/faketls/record/pools.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

var recordPool = sync.Pool{
New: func() interface{} {
New: func() any {
return &Record{}
},
}
Expand Down
2 changes: 1 addition & 1 deletion mtglib/internal/obfuscated2/handshake_frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (h *handshakeFrame) connectionType() []byte {
func (h *handshakeFrame) invert() handshakeFrame {
copyFrame := *h

for i := 0; i < handshakeFrameLenKey+handshakeFrameLenIV; i++ {
for i := range handshakeFrameLenKey + handshakeFrameLenIV {
copyFrame.data[handshakeFrameOffsetKey+i] = h.data[handshakeFrameOffsetConnectionType-1-i]
}

Expand Down
2 changes: 1 addition & 1 deletion mtglib/internal/obfuscated2/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func NewServerHandshakeTestData(t *testing.T) ServerHandshakeTestData {

serverEncryptedReverted := make([]byte, len(serverEncrypted))

for i := 0; i < 32+16; i++ {
for i := range 32 + 16 {
serverEncryptedReverted[8+i] = serverEncrypted[8+32+16-1-i]
}

Expand Down
4 changes: 2 additions & 2 deletions mtglib/internal/obfuscated2/pools.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (

var (
sha256HasherPool = sync.Pool{
New: func() interface{} {
New: func() any {
return sha256.New()
},
}
bytesBufferPool = sync.Pool{
New: func() interface{} {
New: func() any {
return &bytes.Buffer{}
},
}
Expand Down
2 changes: 1 addition & 1 deletion mtglib/internal/relay/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ const (
)

type Logger interface {
Printf(msg string, args ...interface{})
Printf(msg string, args ...any)
}
2 changes: 1 addition & 1 deletion mtglib/internal/relay/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package relay_test

type loggerMock struct{}

func (l loggerMock) Printf(format string, args ...interface{}) {}
func (l loggerMock) Printf(format string, args ...any) {}
2 changes: 1 addition & 1 deletion mtglib/internal/relay/pools.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package relay
import "sync"

var copyBufferPool = sync.Pool{
New: func() interface{} {
New: func() any {
rv := make([]byte, copyBufferSize)

return &rv
Expand Down
4 changes: 2 additions & 2 deletions mtglib/internal/relay/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import (

func Relay(ctx context.Context, log Logger, telegramConn, clientConn essentials.Conn) {
defer telegramConn.Close() //nolint: errcheck
defer clientConn.Close() //nolint: errcheck
defer clientConn.Close() //nolint: errcheck

ctx, cancel := context.WithCancel(ctx)
defer cancel()

go func() {
<-ctx.Done()
telegramConn.Close() //nolint: errcheck
clientConn.Close() //nolint: errcheck
clientConn.Close() //nolint: errcheck
}()

closeChan := make(chan struct{})
Expand Down
2 changes: 1 addition & 1 deletion mtglib/internal/telegram/telegram_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (suite *TelegramTestSuite) TestUnknownPreferIP() {
func (suite *TelegramTestSuite) TestFallbackDC() {
dcs := make([]int, 10)

for i := 0; i < len(dcs); i++ {
for i := range dcs {
dcs[i] = suite.t.GetFallbackDC()
}

Expand Down
2 changes: 1 addition & 1 deletion mtglib/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func NewProxy(opts ProxyOpts) (*Proxy, error) {
}

pool, err := ants.NewPoolWithFunc(opts.getConcurrency(),
func(arg interface{}) {
func(arg any) {
proxy.ServeConn(arg.(essentials.Conn)) //nolint: forcetypeassert
},
ants.WithLogger(opts.getLogger("ants")),
Expand Down
2 changes: 1 addition & 1 deletion mtglib/stream_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (s *streamContext) Err() error {
return s.ctx.Err() //nolint: wrapcheck
}

func (s *streamContext) Value(key interface{}) interface{} {
func (s *streamContext) Value(key any) any {
return s.ctx.Value(key)
}

Expand Down
2 changes: 1 addition & 1 deletion network/circuit_breaker_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (suite *CircuitBreakerTestSuite) TestMultipleRunsOk() {
suite.ctxCancel()
}()

for i := 0; i < 5; i++ {
for range 5 {
go func() {
defer wg.Done()

Expand Down
2 changes: 1 addition & 1 deletion network/load_balanced_socks5_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (suite *LoadBalancedSocks5TestSuite) TestCannotDial() {
})
suite.NoError(err)

for i := 0; i < network.ProxyDialerOpenThreshold*2; i++ {
for range network.ProxyDialerOpenThreshold * 2 {
_, err = lbDialer.Dial("tcp", "127.1.1.1:80")
suite.True(errors.Is(err, network.ErrCannotDialWithAllProxies))
}
Expand Down
12 changes: 4 additions & 8 deletions network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,32 +81,28 @@ func (n *network) dnsResolve(protocol, address string) ([]string, error) {

switch protocol {
case "tcp", "tcp4":
wg.Add(1)

go func() {
defer wg.Done()
wg.Go(func() {

resolved := n.dns.LookupA(address)

mutex.Lock()
ips = append(ips, resolved...)
mutex.Unlock()
}()
})
}

switch protocol {
case "tcp", "tcp6":
wg.Add(1)

go func() {
defer wg.Done()
wg.Go(func() {

resolved := n.dns.LookupAAAA(address)

mutex.Lock()
ips = append(ips, resolved...)
mutex.Unlock()
}()
})
}

wg.Wait()
Expand Down
1 change: 0 additions & 1 deletion network/sockopts_unix.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !windows
// +build !windows

package network

Expand Down
1 change: 0 additions & 1 deletion network/sockopts_windows.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build windows
// +build windows

package network

Expand Down
2 changes: 1 addition & 1 deletion stats/pools.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package stats
import "sync"

var streamInfoPool = sync.Pool{
New: func() interface{} {
New: func() any {
return &streamInfo{
tags: make(map[string]string),
}
Expand Down
2 changes: 1 addition & 1 deletion stats/statsd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (suite *StatsdTestSuite) SetupTest() {

func (suite *StatsdTestSuite) TearDownTest() {
suite.statsd.Shutdown()
suite.factory.Close() //nolint: errcheck
suite.factory.Close() //nolint: errcheck
suite.statsdServer.Close() //nolint: errcheck
}

Expand Down
Loading