diff --git a/Makefile b/Makefile index 73ded41..bd40f07 100644 --- a/Makefile +++ b/Makefile @@ -19,12 +19,15 @@ GO_BUILD = GO111MODULE=$(GO111MODULE) CGO_ENABLED=$(CGO_ENABLED) \ UNIX_ARCH_LIST = \ darwin-amd64 \ + darwin-amd64-v3 \ darwin-arm64 \ freebsd-386 \ freebsd-amd64 \ + freebsd-amd64-v3 \ freebsd-arm64 \ linux-386 \ linux-amd64 \ + linux-amd64-v3 \ linux-arm64 \ linux-armv5 \ linux-armv6 \ @@ -40,11 +43,13 @@ UNIX_ARCH_LIST = \ linux-s390x \ openbsd-386 \ openbsd-amd64 \ + openbsd-amd64-v3 \ openbsd-arm64 WINDOWS_ARCH_LIST = \ windows-386 \ windows-amd64 \ + windows-amd64-v3 \ windows-arm64 \ windows-arm32v7 @@ -54,11 +59,14 @@ debug: BUILD_TAGS += debug debug: all tun2socks: - $(GO_BUILD) -o $(BUILD_DIR)/$(BINARY) + GOAMD64=v3 $(GO_BUILD) -o $(BUILD_DIR)/$(BINARY) darwin-amd64: GOARCH=amd64 GOOS=darwin $(GO_BUILD) -o $(BUILD_DIR)/$(BINARY)-$@ +darwin-amd64-v3: + GOARCH=amd64 GOOS=darwin GOAMD64=v3 $(GO_BUILD) -o $(BUILD_DIR)/$(BINARY)-$@ + darwin-arm64: GOARCH=arm64 GOOS=darwin $(GO_BUILD) -o $(BUILD_DIR)/$(BINARY)-$@ @@ -68,6 +76,9 @@ freebsd-386: freebsd-amd64: GOARCH=amd64 GOOS=freebsd $(GO_BUILD) -o $(BUILD_DIR)/$(BINARY)-$@ +freebsd-amd64-v3: + GOARCH=amd64 GOOS=freebsd GOAMD64=v3 $(GO_BUILD) -o $(BUILD_DIR)/$(BINARY)-$@ + freebsd-arm64: GOARCH=arm64 GOOS=freebsd $(GO_BUILD) -o $(BUILD_DIR)/$(BINARY)-$@ @@ -77,6 +88,9 @@ linux-386: linux-amd64: GOARCH=amd64 GOOS=linux $(GO_BUILD) -o $(BUILD_DIR)/$(BINARY)-$@ +linux-amd64-v3: + GOARCH=amd64 GOOS=linux GOAMD64=v3 $(GO_BUILD) -o $(BUILD_DIR)/$(BINARY)-$@ + linux-arm64: GOARCH=arm64 GOOS=linux $(GO_BUILD) -o $(BUILD_DIR)/$(BINARY)-$@ @@ -122,6 +136,9 @@ openbsd-386: openbsd-amd64: GOARCH=amd64 GOOS=openbsd $(GO_BUILD) -o $(BUILD_DIR)/$(BINARY)-$@ +openbsd-amd64-v3: + GOARCH=amd64 GOOS=openbsd GOAMD64=v3 $(GO_BUILD) -o $(BUILD_DIR)/$(BINARY)-$@ + openbsd-arm64: GOARCH=arm64 GOOS=openbsd $(GO_BUILD) -o $(BUILD_DIR)/$(BINARY)-$@ @@ -131,6 +148,9 @@ windows-386: windows-amd64: GOARCH=amd64 GOOS=windows $(GO_BUILD) -o $(BUILD_DIR)/$(BINARY)-$@.exe +windows-amd64-v3: + GOARCH=amd64 GOOS=windows GOAMD64=v3 $(GO_BUILD) -o $(BUILD_DIR)/$(BINARY)-$@.exe + windows-arm64: GOARCH=arm64 GOOS=windows $(GO_BUILD) -o $(BUILD_DIR)/$(BINARY)-$@.exe diff --git a/common/automaxprocs/automaxprocs.go b/common/automaxprocs/automaxprocs.go index a8fa56d..293f4f6 100644 --- a/common/automaxprocs/automaxprocs.go +++ b/common/automaxprocs/automaxprocs.go @@ -7,5 +7,5 @@ import ( ) func init() { - maxprocs.Set(maxprocs.Logger(func(string, ...interface{}) {})) + maxprocs.Set(maxprocs.Logger(func(string, ...any) {})) } diff --git a/common/observable/iterable.go b/common/observable/iterable.go index ad0943b..2ac38b4 100644 --- a/common/observable/iterable.go +++ b/common/observable/iterable.go @@ -1,3 +1,3 @@ package observable -type Iterable <-chan interface{} +type Iterable <-chan any diff --git a/common/observable/observable_test.go b/common/observable/observable_test.go index ec3c3f5..f34b81f 100644 --- a/common/observable/observable_test.go +++ b/common/observable/observable_test.go @@ -9,8 +9,8 @@ import ( "go.uber.org/atomic" ) -func iterator(item []interface{}) chan interface{} { - ch := make(chan interface{}) +func iterator(item []any) chan any { + ch := make(chan any) go func() { time.Sleep(100 * time.Millisecond) for _, elm := range item { @@ -22,7 +22,7 @@ func iterator(item []interface{}) chan interface{} { } func TestObservable(t *testing.T) { - iter := iterator([]interface{}{1, 2, 3, 4, 5}) + iter := iterator([]any{1, 2, 3, 4, 5}) src := NewObservable(iter) data, err := src.Subscribe() assert.Nil(t, err) @@ -34,7 +34,7 @@ func TestObservable(t *testing.T) { } func TestObservable_MultiSubscribe(t *testing.T) { - iter := iterator([]interface{}{1, 2, 3, 4, 5}) + iter := iterator([]any{1, 2, 3, 4, 5}) src := NewObservable(iter) ch1, _ := src.Subscribe() ch2, _ := src.Subscribe() @@ -42,7 +42,7 @@ func TestObservable_MultiSubscribe(t *testing.T) { var wg sync.WaitGroup wg.Add(2) - waitCh := func(ch <-chan interface{}) { + waitCh := func(ch <-chan any) { for range ch { count.Inc() } @@ -55,7 +55,7 @@ func TestObservable_MultiSubscribe(t *testing.T) { } func TestObservable_UnSubscribe(t *testing.T) { - iter := iterator([]interface{}{1, 2, 3, 4, 5}) + iter := iterator([]any{1, 2, 3, 4, 5}) src := NewObservable(iter) data, err := src.Subscribe() assert.Nil(t, err) @@ -65,7 +65,7 @@ func TestObservable_UnSubscribe(t *testing.T) { } func TestObservable_SubscribeClosedSource(t *testing.T) { - iter := iterator([]interface{}{1}) + iter := iterator([]any{1}) src := NewObservable(iter) data, _ := src.Subscribe() <-data @@ -75,14 +75,14 @@ func TestObservable_SubscribeClosedSource(t *testing.T) { } func TestObservable_UnSubscribeWithNotExistSubscription(t *testing.T) { - sub := Subscription(make(chan interface{})) - iter := iterator([]interface{}{1}) + sub := Subscription(make(chan any)) + iter := iterator([]any{1}) src := NewObservable(iter) src.UnSubscribe(sub) } func TestObservable_SubscribeGoroutineLeak(t *testing.T) { - iter := iterator([]interface{}{1, 2, 3, 4, 5}) + iter := iterator([]any{1, 2, 3, 4, 5}) src := NewObservable(iter) max := 100 @@ -94,7 +94,7 @@ func TestObservable_SubscribeGoroutineLeak(t *testing.T) { var wg sync.WaitGroup wg.Add(max) - waitCh := func(ch <-chan interface{}) { + waitCh := func(ch <-chan any) { for range ch { } wg.Done() @@ -117,7 +117,7 @@ func TestObservable_SubscribeGoroutineLeak(t *testing.T) { } func Benchmark_Observable_1000(b *testing.B) { - ch := make(chan interface{}) + ch := make(chan any) o := NewObservable(ch) num := 1000 diff --git a/common/observable/subscriber.go b/common/observable/subscriber.go index cb2a70f..0d8559b 100644 --- a/common/observable/subscriber.go +++ b/common/observable/subscriber.go @@ -4,14 +4,14 @@ import ( "sync" ) -type Subscription <-chan interface{} +type Subscription <-chan any type Subscriber struct { - buffer chan interface{} + buffer chan any once sync.Once } -func (s *Subscriber) Emit(item interface{}) { +func (s *Subscriber) Emit(item any) { s.buffer <- item } @@ -27,7 +27,7 @@ func (s *Subscriber) Close() { func newSubscriber() *Subscriber { sub := &Subscriber{ - buffer: make(chan interface{}, 200), + buffer: make(chan any, 200), } return sub } diff --git a/common/pool/alloc.go b/common/pool/alloc.go index b395ad4..80f320f 100644 --- a/common/pool/alloc.go +++ b/common/pool/alloc.go @@ -22,7 +22,7 @@ func NewAllocator() *Allocator { alloc.buffers = make([]sync.Pool, 17) // 1B -> 64K for k := range alloc.buffers { i := k - alloc.buffers[k].New = func() interface{} { + alloc.buffers[k].New = func() any { return make([]byte, 1< _defaultLevel.Load() { return diff --git a/tunnel/statistic/manager.go b/tunnel/statistic/manager.go index df85b50..d9ff978 100644 --- a/tunnel/statistic/manager.go +++ b/tunnel/statistic/manager.go @@ -56,7 +56,7 @@ func (m *Manager) Now() (up int64, down int64) { func (m *Manager) Snapshot() *Snapshot { var connections []tracker - m.connections.Range(func(key, value interface{}) bool { + m.connections.Range(func(key, value any) bool { connections = append(connections, value.(tracker)) return true })