Add NDIS inbound

This commit is contained in:
世界
2025-01-03 18:34:07 +08:00
parent e483c909b4
commit 79d3649a8b
32 changed files with 1339 additions and 572 deletions

View File

@@ -5,8 +5,6 @@ import (
"net"
runtimeDebug "runtime/debug"
"time"
"github.com/sagernet/sing-box/common/conntrack"
)
func (c *CommandClient) CloseConnections() error {
@@ -19,7 +17,7 @@ func (c *CommandClient) CloseConnections() error {
}
func (s *CommandServer) handleCloseConnections(conn net.Conn) error {
conntrack.Close()
tracker.Close()
go func() {
time.Sleep(time.Second)
runtimeDebug.FreeOSMemory()

View File

@@ -6,7 +6,6 @@ import (
"runtime"
"time"
"github.com/sagernet/sing-box/common/conntrack"
"github.com/sagernet/sing-box/experimental/clashapi"
E "github.com/sagernet/sing/common/exceptions"
"github.com/sagernet/sing/common/memory"
@@ -28,7 +27,7 @@ func (s *CommandServer) readStatus() StatusMessage {
var message StatusMessage
message.Memory = int64(memory.Inuse())
message.Goroutines = int32(runtime.NumGoroutine())
message.ConnectionsOut = int32(conntrack.Count())
message.ConnectionsOut = int32(tracker.Count())
if s.service != nil {
message.TrafficAvailable = true

View File

@@ -7,17 +7,21 @@ import (
"github.com/sagernet/sing-box/common/conntrack"
)
var tracker *conntrack.DefaultTracker
func SetMemoryLimit(enabled bool) {
if tracker != nil {
tracker.Close()
}
const memoryLimit = 45 * 1024 * 1024
const memoryLimitGo = memoryLimit / 1.5
if enabled {
runtimeDebug.SetGCPercent(10)
runtimeDebug.SetMemoryLimit(memoryLimitGo)
conntrack.KillerEnabled = true
conntrack.MemoryLimit = memoryLimit
tracker = conntrack.NewDefaultTracker(true, memoryLimit)
} else {
runtimeDebug.SetGCPercent(100)
runtimeDebug.SetMemoryLimit(math.MaxInt64)
conntrack.KillerEnabled = false
tracker = conntrack.NewDefaultTracker(false, 0)
}
}

View File

@@ -12,6 +12,7 @@ import (
"github.com/sagernet/sing-box"
"github.com/sagernet/sing-box/adapter"
"github.com/sagernet/sing-box/common/conntrack"
"github.com/sagernet/sing-box/common/process"
"github.com/sagernet/sing-box/common/urltest"
C "github.com/sagernet/sing-box/constant"
@@ -60,6 +61,7 @@ func NewService(configContent string, platformInterface PlatformInterface) (*Box
useProcFS: platformInterface.UseProcFS(),
}
service.MustRegister[platform.Interface](ctx, platformWrapper)
service.MustRegister[conntrack.Tracker](ctx, tracker)
instance, err := box.New(box.Options{
Context: ctx,
Options: options,