Improve conntrack

This commit is contained in:
世界
2023-09-20 14:12:08 +08:00
parent 85c8f00885
commit 12dd1ac87f
22 changed files with 223 additions and 57 deletions

View File

@@ -3,7 +3,7 @@ package option
import (
"encoding/json"
"github.com/dustin/go-humanize"
"github.com/sagernet/sing-box/common/humanize"
)
type DebugOptions struct {
@@ -13,21 +13,21 @@ type DebugOptions struct {
MaxThreads *int `json:"max_threads,omitempty"`
PanicOnFault *bool `json:"panic_on_fault,omitempty"`
TraceBack string `json:"trace_back,omitempty"`
MemoryLimit BytesLength `json:"memory_limit,omitempty"`
MemoryLimit MemoryBytes `json:"memory_limit,omitempty"`
OOMKiller *bool `json:"oom_killer,omitempty"`
}
type BytesLength int64
type MemoryBytes uint64
func (l BytesLength) MarshalJSON() ([]byte, error) {
return json.Marshal(humanize.IBytes(uint64(l)))
func (l MemoryBytes) MarshalJSON() ([]byte, error) {
return json.Marshal(humanize.MemoryBytes(uint64(l)))
}
func (l *BytesLength) UnmarshalJSON(bytes []byte) error {
func (l *MemoryBytes) UnmarshalJSON(bytes []byte) error {
var valueInteger int64
err := json.Unmarshal(bytes, &valueInteger)
if err == nil {
*l = BytesLength(valueInteger)
*l = MemoryBytes(valueInteger)
return nil
}
var valueString string
@@ -35,10 +35,10 @@ func (l *BytesLength) UnmarshalJSON(bytes []byte) error {
if err != nil {
return err
}
parsedValue, err := humanize.ParseBytes(valueString)
parsedValue, err := humanize.ParseMemoryBytes(valueString)
if err != nil {
return err
}
*l = BytesLength(parsedValue)
*l = MemoryBytes(parsedValue)
return nil
}