mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-07-14 11:59:43 +03:00
Add NDIS inbound
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user