Skip to content
Merged
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
4 changes: 2 additions & 2 deletions events/event_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package events

import (
"context"
"math/rand"
"math/rand/v2"
"runtime"

"github.com/9seconds/mtg/v2/mtglib"
Expand Down Expand Up @@ -64,7 +64,7 @@ func NewEventStream(observerFactories []ObserverFactory) EventStream {
chans: make([]chan mtglib.Event, runtime.NumCPU()),
}

for i := 0; i < runtime.NumCPU(); i++ {
for i := range runtime.NumCPU() {
rv.chans[i] = make(chan mtglib.Event, 1)

if len(observerFactories) == 1 {
Expand Down
81 changes: 27 additions & 54 deletions events/multi_observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,134 +12,107 @@ type multiObserver struct {

func (m multiObserver) EventStart(evt mtglib.EventStart) {
wg := &sync.WaitGroup{}
wg.Add(len(m.observers))

for _, v := range m.observers {
go func(obs Observer) {
defer wg.Done()

obs.EventStart(evt)
}(v)
wg.Go(func() {
v.EventStart(evt)
})
}

wg.Wait()
}

func (m multiObserver) EventConnectedToDC(evt mtglib.EventConnectedToDC) {
wg := &sync.WaitGroup{}
wg.Add(len(m.observers))

for _, v := range m.observers {
go func(obs Observer) {
defer wg.Done()

obs.EventConnectedToDC(evt)
}(v)
wg.Go(func() {
v.EventConnectedToDC(evt)
})
}

wg.Wait()
}

func (m multiObserver) EventDomainFronting(evt mtglib.EventDomainFronting) {
wg := &sync.WaitGroup{}
wg.Add(len(m.observers))

for _, v := range m.observers {
go func(obs Observer) {
defer wg.Done()

obs.EventDomainFronting(evt)
}(v)
wg.Go(func() {
v.EventDomainFronting(evt)
})
}

wg.Wait()
}

func (m multiObserver) EventTraffic(evt mtglib.EventTraffic) {
wg := &sync.WaitGroup{}
wg.Add(len(m.observers))

for _, v := range m.observers {
go func(obs Observer) {
defer wg.Done()

obs.EventTraffic(evt)
}(v)
wg.Go(func() {
v.EventTraffic(evt)
})
}

wg.Wait()
}

func (m multiObserver) EventFinish(evt mtglib.EventFinish) {
wg := &sync.WaitGroup{}
wg.Add(len(m.observers))

for _, v := range m.observers {
go func(obs Observer) {
defer wg.Done()

obs.EventFinish(evt)
}(v)
wg.Go(func() {
v.EventFinish(evt)
})
}

wg.Wait()
}

func (m multiObserver) EventConcurrencyLimited(evt mtglib.EventConcurrencyLimited) {
wg := &sync.WaitGroup{}
wg.Add(len(m.observers))

for _, v := range m.observers {
go func(obs Observer) {
defer wg.Done()

obs.EventConcurrencyLimited(evt)
}(v)
wg.Go(func() {
v.EventConcurrencyLimited(evt)
})
}

wg.Wait()
}

func (m multiObserver) EventIPBlocklisted(evt mtglib.EventIPBlocklisted) {
wg := &sync.WaitGroup{}
wg.Add(len(m.observers))

for _, v := range m.observers {
go func(obs Observer) {
defer wg.Done()

obs.EventIPBlocklisted(evt)
}(v)
wg.Go(func() {
v.EventIPBlocklisted(evt)
})
}

wg.Wait()
}

func (m multiObserver) EventReplayAttack(evt mtglib.EventReplayAttack) {
wg := &sync.WaitGroup{}
wg.Add(len(m.observers))

for _, v := range m.observers {
go func(obs Observer) {
defer wg.Done()

obs.EventReplayAttack(evt)
}(v)
wg.Go(func() {
v.EventReplayAttack(evt)
})
}

wg.Wait()
}

func (m multiObserver) EventIPListSize(evt mtglib.EventIPListSize) {
wg := &sync.WaitGroup{}
wg.Add(len(m.observers))

for _, v := range m.observers {
go func(obs Observer) {
defer wg.Done()

obs.EventIPListSize(evt)
}(v)
wg.Go(func() {
v.EventIPListSize(evt)
})
}

wg.Wait()
Expand Down
14 changes: 4 additions & 10 deletions internal/cli/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,8 @@ func (a *Access) Run(cli *CLI, version string) error {
}

wg := &sync.WaitGroup{}
wg.Add(2)

go func() {
defer wg.Done()

wg.Go(func() {
ip := a.PublicIPv4
if ip == nil {
ip = a.getIP(ntw, "tcp4")
Expand All @@ -76,11 +73,8 @@ func (a *Access) Run(cli *CLI, version string) error {
}

resp.IPv4 = a.makeURLs(conf, ip)
}()

go func() {
defer wg.Done()

})
wg.Go(func() {
ip := a.PublicIPv6
if ip == nil {
ip = a.getIP(ntw, "tcp6")
Expand All @@ -91,7 +85,7 @@ func (a *Access) Run(cli *CLI, version string) error {
}

resp.IPv6 = a.makeURLs(conf, ip)
}()
})

wg.Wait()

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
11 changes: 4 additions & 7 deletions ipblocklist/firehol.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,15 @@ func (f *Firehol) update() {
defer cancel()

wg := &sync.WaitGroup{}
wg.Add(len(f.blocklists))

mutex := &sync.Mutex{}
ranger := cidranger.NewPCTrieRanger()

for _, v := range f.blocklists {
go func(file files.File) {
defer wg.Done()
wg.Go(func() {
logger := f.logger.BindStr("filename", v.String())

logger := f.logger.BindStr("filename", file.String())

fileContent, err := file.Open(ctx)
fileContent, err := v.Open(ctx)
if err != nil {
logger.WarningError("update has failed", err)

Expand All @@ -135,7 +132,7 @@ func (f *Firehol) update() {
if err := f.updateFromFile(mutex, ranger, bufio.NewScanner(fileContent)); err != nil {
logger.WarningError("update has failed", err)
}
}(v)
})
}

wg.Wait()
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
14 changes: 7 additions & 7 deletions mise.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ version = "latest"
backend = "go:golang.org/x/pkgsite/cmd/pkgsite"

[[tools."go:golang.org/x/tools/gopls"]]
version = "0.21.0"
version = "0.21.1"
backend = "go:golang.org/x/tools/gopls"

[[tools."go:mvdan.cc/gofumpt"]]
version = "0.9.2"
backend = "go:mvdan.cc/gofumpt"

[[tools.golangci-lint]]
version = "2.9.0"
version = "2.10.1"
backend = "aqua:golangci/golangci-lint"
"platforms.linux-arm64" = { checksum = "sha256:94e80cdb51c73c20a313bd3afa1fb23137728813c19fd730248a1e8678fcc46d", url = "https://github.com/golangci/golangci-lint/releases/download/v2.9.0/golangci-lint-2.9.0-linux-arm64.tar.gz"}
"platforms.linux-x64" = { checksum = "sha256:493aaaca2eba6c8bcef847d92716bbd91bbac4b22cdbb0ab5b6a581b32946091", url = "https://github.com/golangci/golangci-lint/releases/download/v2.9.0/golangci-lint-2.9.0-linux-amd64.tar.gz"}
"platforms.macos-arm64" = { checksum = "sha256:a86eabba3507deddd21f2a01a1df2a0ee5bc5c8178d4165cdcaaad8597358760", url = "https://github.com/golangci/golangci-lint/releases/download/v2.9.0/golangci-lint-2.9.0-darwin-arm64.tar.gz"}
"platforms.macos-x64" = { checksum = "sha256:ba29a353be54a74c45946763983808dc8305eeeca73db1761b5ab112f87f8157", url = "https://github.com/golangci/golangci-lint/releases/download/v2.9.0/golangci-lint-2.9.0-darwin-amd64.tar.gz"}
"platforms.windows-x64" = { checksum = "sha256:130fca8fa959eb840267c5e231f030a948e0de1e768bf6a31785505d1061632c", url = "https://github.com/golangci/golangci-lint/releases/download/v2.9.0/golangci-lint-2.9.0-windows-amd64.zip"}
"platforms.linux-arm64" = { checksum = "sha256:6652b42ae02915eb2f9cb2a2e0cac99514c8eded8388d88ae3e06e1a52c00de8", url = "https://github.com/golangci/golangci-lint/releases/download/v2.10.1/golangci-lint-2.10.1-linux-arm64.tar.gz"}
"platforms.linux-x64" = { checksum = "sha256:dfa775874cf0561b404a02a8f4481fc69b28091da95aa697259820d429b09c99", url = "https://github.com/golangci/golangci-lint/releases/download/v2.10.1/golangci-lint-2.10.1-linux-amd64.tar.gz"}
"platforms.macos-arm64" = { checksum = "sha256:03bfadf67e52b441b7ec21305e501c717df93c959836d66c7f97312654acb297", url = "https://github.com/golangci/golangci-lint/releases/download/v2.10.1/golangci-lint-2.10.1-darwin-arm64.tar.gz"}
"platforms.macos-x64" = { checksum = "sha256:66fb0da81b8033b477f97eea420d4b46b230ca172b8bb87c6610109f3772b6b6", url = "https://github.com/golangci/golangci-lint/releases/download/v2.10.1/golangci-lint-2.10.1-darwin-amd64.tar.gz"}
"platforms.windows-x64" = { checksum = "sha256:c60c87695e79db8e320f0e5be885059859de52bb5ee5f11be5577828570bc2a3", url = "https://github.com/golangci/golangci-lint/releases/download/v2.10.1/golangci-lint-2.10.1-windows-amd64.zip"}

[[tools.goreleaser]]
version = "2.13.3"
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
4 changes: 2 additions & 2 deletions mtglib/internal/faketls/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package faketls
import (
"bytes"
"fmt"
"math/rand"
"math/rand/v2"

"github.com/9seconds/mtg/v2/essentials"
"github.com/9seconds/mtg/v2/mtglib/internal/faketls/record"
Expand Down Expand Up @@ -53,7 +53,7 @@ func (c *Conn) Write(p []byte) (int, error) {
lenP := len(p)

for len(p) > 0 {
chunkSize := rand.Intn(record.TLSMaxRecordSize)
chunkSize := rand.IntN(record.TLSMaxRecordSize)
if chunkSize > len(p) || chunkSize == 0 {
chunkSize = len(p)
}
Expand Down
Loading
Loading