Projects STRLCPY tun2socks Commits 7327f2c7
🤬
  • ■ ■ ■ ■ ■
    core/stack.go
    skipped 22 lines
    23 23   // stack to set transport handlers.
    24 24   TransportHandler adapter.TransportHandler
    25 25   
    26  - // PrintFunc is the function that will be called
    27  - // to print internal stack events.
    28  - PrintFunc func(string, ...any)
    29  - 
    30 26   // Options are supplement options to apply settings
    31 27   // for the internal stack.
    32 28   Options []option.Option
    skipped 1 lines
    34 30   
    35 31  // CreateStack creates *stack.Stack with given config.
    36 32  func CreateStack(cfg *Config) (*stack.Stack, error) {
    37  - if cfg.PrintFunc == nil {
    38  - cfg.PrintFunc = func(string, ...any) {}
    39  - }
    40  - 
    41 33   opts := []option.Option{option.WithDefault()}
    42 34   if len(opts) > 0 {
    43 35   opts = append(opts, cfg.Options...)
    skipped 20 lines
    64 56   // before creating NIC, otherwise NIC would dispatch packets
    65 57   // to stack and cause race condition.
    66 58   // Initiate transport protocol (TCP/UDP) with given handler.
    67  - withTCPHandler(cfg.TransportHandler.HandleTCP, cfg.PrintFunc),
    68  - withUDPHandler(cfg.TransportHandler.HandleUDP, cfg.PrintFunc),
     59 + withTCPHandler(cfg.TransportHandler.HandleTCP),
     60 + withUDPHandler(cfg.TransportHandler.HandleUDP),
    69 61   
    70 62   // Create stack NIC and then bind link endpoint to it.
    71 63   withCreatingNIC(nicID, cfg.LinkEndpoint),
    skipped 37 lines
  • ■ ■ ■ ■ ■
    core/tcp.go
    skipped 2 lines
    3 3  import (
    4 4   "time"
    5 5   
     6 + glog "gvisor.dev/gvisor/pkg/log"
    6 7   "gvisor.dev/gvisor/pkg/tcpip"
    7 8   "gvisor.dev/gvisor/pkg/tcpip/adapters/gonet"
    8 9   "gvisor.dev/gvisor/pkg/tcpip/header"
    skipped 31 lines
    40 41   tcpKeepaliveInterval = 30 * time.Second
    41 42  )
    42 43   
    43  -func withTCPHandler(handle func(adapter.TCPConn), printf func(string, ...any)) option.Option {
     44 +func withTCPHandler(handle func(adapter.TCPConn)) option.Option {
    44 45   return func(s *stack.Stack) error {
    45 46   tcpForwarder := tcp.NewForwarder(s, defaultWndSize, maxConnAttempts, func(r *tcp.ForwarderRequest) {
    46 47   var (
    skipped 5 lines
    52 53   
    53 54   defer func() {
    54 55   if err != nil {
    55  - printf("forward tcp request %s:%d->%s:%d: %s",
     56 + glog.Warningf("forward tcp request: %s:%d->%s:%d: %s",
    56 57   id.RemoteAddress, id.RemotePort, id.LocalAddress, id.LocalPort, err)
    57 58   }
    58 59   }()
    skipped 64 lines
  • ■ ■ ■ ■ ■
    core/udp.go
    1 1  package core
    2 2   
    3 3  import (
     4 + glog "gvisor.dev/gvisor/pkg/log"
    4 5   "gvisor.dev/gvisor/pkg/tcpip/adapters/gonet"
    5 6   "gvisor.dev/gvisor/pkg/tcpip/stack"
    6 7   "gvisor.dev/gvisor/pkg/tcpip/transport/udp"
    skipped 3 lines
    10 11   "github.com/xjasonlyu/tun2socks/v2/core/option"
    11 12  )
    12 13   
    13  -func withUDPHandler(handle func(adapter.UDPConn), printf func(string, ...any)) option.Option {
     14 +func withUDPHandler(handle func(adapter.UDPConn)) option.Option {
    14 15   return func(s *stack.Stack) error {
    15 16   udpForwarder := udp.NewForwarder(s, func(r *udp.ForwarderRequest) {
    16 17   var (
    skipped 2 lines
    19 20   )
    20 21   ep, err := r.CreateEndpoint(&wq)
    21 22   if err != nil {
    22  - printf("udp forwarder request %s:%d->%s:%d: %s",
     23 + glog.Warningf("forward udp request: %s:%d->%s:%d: %s",
    23 24   id.RemoteAddress, id.RemotePort, id.LocalAddress, id.LocalPort, err)
    24 25   return
    25 26   }
    skipped 21 lines
  • ■ ■ ■ ■ ■
    engine/engine.go
    skipped 1 lines
    2 2   
    3 3  import (
    4 4   "errors"
    5  - "fmt"
    6 5   "net"
    7 6   "sync"
    8 7   "time"
    skipped 183 lines
    192 191   if _defaultStack, err = core.CreateStack(&core.Config{
    193 192   LinkEndpoint: _defaultDevice,
    194 193   TransportHandler: &mirror.Tunnel{},
    195  - PrintFunc: func(format string, v ...any) {
    196  - log.Warnf("[STACK] %s", fmt.Sprintf(format, v...))
    197  - },
    198  - Options: opts,
     194 + Options: opts,
    199 195   }); err != nil {
    200 196   return
    201 197   }
    skipped 9 lines
Please wait...
Page is in error, reload to recover