Projects STRLCPY sing-box Commits 11de271c
🤬
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■ ■
    box.go
    skipped 38 lines
    39 39   
    40 40  func New(ctx context.Context, options option.Options, platformInterface platform.Interface) (*Box, error) {
    41 41   createdAt := time.Now()
    42  - logOptions := common.PtrValueOrDefault(options.Log)
     42 + 
     43 + experimentalOptions := common.PtrValueOrDefault(options.Experimental)
     44 + applyDebugOptions(common.PtrValueOrDefault(experimentalOptions.Debug))
    43 45   
    44 46   var needClashAPI bool
    45 47   var needV2RayAPI bool
    46  - if options.Experimental != nil {
    47  - if options.Experimental.ClashAPI != nil && options.Experimental.ClashAPI.ExternalController != "" {
    48  - needClashAPI = true
    49  - }
    50  - if options.Experimental.V2RayAPI != nil && options.Experimental.V2RayAPI.Listen != "" {
    51  - needV2RayAPI = true
    52  - }
     48 + if experimentalOptions.ClashAPI != nil && experimentalOptions.ClashAPI.ExternalController != "" {
     49 + needClashAPI = true
     50 + }
     51 + if experimentalOptions.V2RayAPI != nil && experimentalOptions.V2RayAPI.Listen != "" {
     52 + needV2RayAPI = true
    53 53   }
     54 + 
     55 + logOptions := common.PtrValueOrDefault(options.Log)
    54 56   
    55 57   var logFactory log.Factory
    56 58   var observableLogFactory log.ObservableFactory
    skipped 256 lines
  • ■ ■ ■ ■ ■ ■
    debug.go
     1 +//go:build go1.19
     2 + 
     3 +package box
     4 + 
     5 +import (
     6 + "runtime/debug"
     7 + 
     8 + "github.com/sagernet/sing-box/common/dialer/conntrack"
     9 + "github.com/sagernet/sing-box/option"
     10 +)
     11 + 
     12 +func applyDebugOptions(options option.DebugOptions) {
     13 + if options.GCPercent != nil {
     14 + debug.SetGCPercent(*options.GCPercent)
     15 + }
     16 + if options.MaxStack != nil {
     17 + debug.SetMaxStack(*options.MaxStack)
     18 + }
     19 + if options.MaxThreads != nil {
     20 + debug.SetMaxThreads(*options.MaxThreads)
     21 + }
     22 + if options.PanicOnFault != nil {
     23 + debug.SetPanicOnFault(*options.PanicOnFault)
     24 + }
     25 + if options.TraceBack != "" {
     26 + debug.SetTraceback(options.TraceBack)
     27 + }
     28 + if options.MemoryLimit != 0 {
     29 + debug.SetMemoryLimit(int64(options.MemoryLimit))
     30 + conntrack.MemoryLimit = int64(options.MemoryLimit)
     31 + }
     32 + if options.OOMKiller != nil {
     33 + conntrack.KillerEnabled = *options.OOMKiller
     34 + }
     35 +}
     36 + 
  • ■ ■ ■ ■ ■ ■
    debug_go118.go
     1 +//go:build !go1.19
     2 + 
     3 +package box
     4 + 
     5 +import (
     6 + "runtime/debug"
     7 + 
     8 + "github.com/sagernet/sing-box/common/dialer/conntrack"
     9 + "github.com/sagernet/sing-box/option"
     10 +)
     11 + 
     12 +func applyDebugOptions(options option.DebugOptions) {
     13 + if options.GCPercent != nil {
     14 + debug.SetGCPercent(*options.GCPercent)
     15 + }
     16 + if options.MaxStack != nil {
     17 + debug.SetMaxStack(*options.MaxStack)
     18 + }
     19 + if options.MaxThreads != nil {
     20 + debug.SetMaxThreads(*options.MaxThreads)
     21 + }
     22 + if options.PanicOnFault != nil {
     23 + debug.SetPanicOnFault(*options.PanicOnFault)
     24 + }
     25 + if options.TraceBack != "" {
     26 + debug.SetTraceback(options.TraceBack)
     27 + }
     28 + if options.MemoryLimit != 0 {
     29 + // debug.SetMemoryLimit(int64(options.MemoryLimit))
     30 + conntrack.MemoryLimit = int64(options.MemoryLimit)
     31 + }
     32 + if options.OOMKiller != nil {
     33 + conntrack.KillerEnabled = *options.OOMKiller
     34 + }
     35 +}
     36 + 
  • ■ ■ ■ ■ ■ ■
    option/debug.go
     1 +package option
     2 + 
     3 +import (
     4 + "encoding/json"
     5 + 
     6 + "github.com/dustin/go-humanize"
     7 +)
     8 + 
     9 +type DebugOptions struct {
     10 + GCPercent *int `json:"gc_percent,omitempty"`
     11 + MaxStack *int `json:"max_stack,omitempty"`
     12 + MaxThreads *int `json:"max_threads,omitempty"`
     13 + PanicOnFault *bool `json:"panic_on_fault,omitempty"`
     14 + TraceBack string `json:"trace_back,omitempty"`
     15 + MemoryLimit BytesLength `json:"memory_limit,omitempty"`
     16 + OOMKiller *bool `json:"oom_killer,omitempty"`
     17 +}
     18 + 
     19 +type BytesLength int64
     20 + 
     21 +func (l BytesLength) MarshalJSON() ([]byte, error) {
     22 + return json.Marshal(humanize.IBytes(uint64(l)))
     23 +}
     24 + 
     25 +func (l *BytesLength) UnmarshalJSON(bytes []byte) error {
     26 + var valueInteger int64
     27 + err := json.Unmarshal(bytes, &valueInteger)
     28 + if err == nil {
     29 + *l = BytesLength(valueInteger)
     30 + return nil
     31 + }
     32 + var valueString string
     33 + err = json.Unmarshal(bytes, &valueString)
     34 + if err != nil {
     35 + return err
     36 + }
     37 + parsedValue, err := humanize.ParseBytes(valueString)
     38 + if err != nil {
     39 + return err
     40 + }
     41 + *l = BytesLength(parsedValue)
     42 + return nil
     43 +}
     44 + 
  • ■ ■ ■ ■ ■
    option/experimental.go
    skipped 2 lines
    3 3  type ExperimentalOptions struct {
    4 4   ClashAPI *ClashAPIOptions `json:"clash_api,omitempty"`
    5 5   V2RayAPI *V2RayAPIOptions `json:"v2ray_api,omitempty"`
     6 + Debug *DebugOptions `json:"debug,omitempty"`
    6 7  }
    7 8   
Please wait...
Page is in error, reload to recover