1
0
Эх сурвалжийг харах

platform: Fixes and improvements

世界 2 жил өмнө
parent
commit
8b64446274

+ 9 - 0
common/dialer/conntrack/track.go

@@ -14,10 +14,16 @@ var (
 )
 
 func Count() int {
+	if !Enabled {
+		return 0
+	}
 	return openConnection.Len()
 }
 
 func List() []io.Closer {
+	if !Enabled {
+		return nil
+	}
 	connAccess.RLock()
 	defer connAccess.RUnlock()
 	connList := make([]io.Closer, 0, openConnection.Len())
@@ -28,6 +34,9 @@ func List() []io.Closer {
 }
 
 func Close() {
+	if !Enabled {
+		return
+	}
 	connAccess.Lock()
 	defer connAccess.Unlock()
 	for element := openConnection.Front(); element != nil; element = element.Next() {

+ 0 - 2
experimental/libbox/command.go

@@ -1,5 +1,3 @@
-//go:build darwin
-
 package libbox
 
 const (

+ 1 - 2
experimental/libbox/command_client.go

@@ -1,5 +1,3 @@
-//go:build darwin
-
 package libbox
 
 import (
@@ -46,6 +44,7 @@ func clientConnect(sharedDirectory string) (net.Conn, error) {
 }
 
 func (c *CommandClient) Connect() error {
+	common.Close(c.conn)
 	conn, err := clientConnect(c.sharedDirectory)
 	if err != nil {
 		return err

+ 0 - 2
experimental/libbox/command_conntrack.go

@@ -1,5 +1,3 @@
-//go:build darwin
-
 package libbox
 
 import (

+ 0 - 2
experimental/libbox/command_log.go

@@ -1,5 +1,3 @@
-//go:build darwin
-
 package libbox
 
 import (

+ 0 - 2
experimental/libbox/command_reload.go

@@ -1,5 +1,3 @@
-//go:build darwin
-
 package libbox
 
 import (

+ 5 - 3
experimental/libbox/command_server.go

@@ -1,5 +1,3 @@
-//go:build darwin
-
 package libbox
 
 import (
@@ -10,6 +8,7 @@ import (
 	"sync"
 
 	"github.com/sagernet/sing-box/log"
+	"github.com/sagernet/sing/common"
 	E "github.com/sagernet/sing/common/exceptions"
 	"github.com/sagernet/sing/common/observable"
 	"github.com/sagernet/sing/common/x/list"
@@ -57,7 +56,10 @@ func (s *CommandServer) Start() error {
 }
 
 func (s *CommandServer) Close() error {
-	return s.listener.Close()
+	return common.Close(
+		s.listener,
+		s.observer,
+	)
 }
 
 func (s *CommandServer) loopConnection(listener net.Listener) {

+ 0 - 2
experimental/libbox/command_status.go

@@ -1,5 +1,3 @@
-//go:build darwin
-
 package libbox
 
 import (

+ 0 - 2
experimental/libbox/command_stop.go

@@ -1,5 +1,3 @@
-//go:build darwin
-
 package libbox
 
 import (

+ 18 - 2
experimental/libbox/config.go

@@ -1,9 +1,9 @@
-//go:build linux || darwin
-
 package libbox
 
 import (
+	"bytes"
 	"context"
+	"encoding/json"
 
 	"github.com/sagernet/sing-box"
 	"github.com/sagernet/sing-box/option"
@@ -35,3 +35,19 @@ func CheckConfig(configContent string) error {
 	}
 	return err
 }
+
+func FormatConfig(configContent string) (string, error) {
+	options, err := parseConfig(configContent)
+	if err != nil {
+		return "", err
+	}
+	var buffer bytes.Buffer
+	json.NewEncoder(&buffer)
+	encoder := json.NewEncoder(&buffer)
+	encoder.SetIndent("", "  ")
+	err = encoder.Encode(options)
+	if err != nil {
+		return "", err
+	}
+	return buffer.String(), nil
+}

+ 0 - 2
experimental/libbox/iterator.go

@@ -1,5 +1,3 @@
-//go:build linux || darwin
-
 package libbox
 
 import "github.com/sagernet/sing/common"

+ 0 - 2
experimental/libbox/platform.go

@@ -1,5 +1,3 @@
-//go:build linux || darwin
-
 package libbox
 
 import "github.com/sagernet/sing-box/option"

+ 0 - 2
experimental/libbox/pprof.go

@@ -1,5 +1,3 @@
-//go:build linux || darwin
-
 package libbox
 
 import (

+ 0 - 2
experimental/libbox/service.go

@@ -1,5 +1,3 @@
-//go:build linux || darwin
-
 package libbox
 
 import (

+ 0 - 2
experimental/libbox/setup.go

@@ -1,5 +1,3 @@
-//go:build linux || darwin
-
 package libbox
 
 import (

+ 0 - 2
experimental/libbox/tun.go

@@ -1,5 +1,3 @@
-//go:build linux || darwin
-
 package libbox
 
 import (