Projects STRLCPY sing-box Commits 4328c535
🤬
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■ ■
    common/canceler/instance.go
    1  -package canceler
    2  - 
    3  -import (
    4  - "context"
    5  - "time"
    6  -)
    7  - 
    8  -type Instance struct {
    9  - ctx context.Context
    10  - cancelFunc context.CancelFunc
    11  - timer *time.Timer
    12  - timeout time.Duration
    13  -}
    14  - 
    15  -func New(ctx context.Context, cancelFunc context.CancelFunc, timeout time.Duration) *Instance {
    16  - instance := &Instance{
    17  - ctx,
    18  - cancelFunc,
    19  - time.NewTimer(timeout),
    20  - timeout,
    21  - }
    22  - go instance.wait()
    23  - return instance
    24  -}
    25  - 
    26  -func (i *Instance) Update() bool {
    27  - if !i.timer.Stop() {
    28  - return false
    29  - }
    30  - if !i.timer.Reset(i.timeout) {
    31  - return false
    32  - }
    33  - return true
    34  -}
    35  - 
    36  -func (i *Instance) wait() {
    37  - select {
    38  - case <-i.timer.C:
    39  - case <-i.ctx.Done():
    40  - }
    41  - i.Close()
    42  -}
    43  - 
    44  -func (i *Instance) Close() error {
    45  - i.timer.Stop()
    46  - i.cancelFunc()
    47  - return nil
    48  -}
    49  - 
  • ■ ■ ■ ■ ■ ■
    common/canceler/packet.go
    1  -package canceler
    2  - 
    3  -import (
    4  - "context"
    5  - "time"
    6  - 
    7  - "github.com/sagernet/sing/common"
    8  - "github.com/sagernet/sing/common/buf"
    9  - M "github.com/sagernet/sing/common/metadata"
    10  - N "github.com/sagernet/sing/common/network"
    11  -)
    12  - 
    13  -type PacketConn struct {
    14  - N.PacketConn
    15  - instance *Instance
    16  -}
    17  - 
    18  -func NewPacketConn(ctx context.Context, conn N.PacketConn, timeout time.Duration) (context.Context, N.PacketConn) {
    19  - ctx, cancel := context.WithCancel(ctx)
    20  - instance := New(ctx, cancel, timeout)
    21  - return ctx, &PacketConn{conn, instance}
    22  -}
    23  - 
    24  -func (c *PacketConn) ReadPacket(buffer *buf.Buffer) (destination M.Socksaddr, err error) {
    25  - destination, err = c.PacketConn.ReadPacket(buffer)
    26  - if err == nil {
    27  - c.instance.Update()
    28  - }
    29  - return
    30  -}
    31  - 
    32  -func (c *PacketConn) WritePacket(buffer *buf.Buffer, destination M.Socksaddr) error {
    33  - err := c.PacketConn.WritePacket(buffer, destination)
    34  - if err == nil {
    35  - c.instance.Update()
    36  - }
    37  - return err
    38  -}
    39  - 
    40  -func (c *PacketConn) Close() error {
    41  - return common.Close(
    42  - c.PacketConn,
    43  - c.instance,
    44  - )
    45  -}
    46  - 
    47  -func (c *PacketConn) Upstream() any {
    48  - return c.PacketConn
    49  -}
    50  - 
  • ■ ■ ■ ■ ■ ■
    go.mod
    skipped 24 lines
    25 25   github.com/sagernet/gomobile v0.0.0-20221130124640-349ebaa752ca
    26 26   github.com/sagernet/quic-go v0.0.0-20230202071646-a8c8afb18b32
    27 27   github.com/sagernet/reality v0.0.0-20230312150606-35ea9af0e0b8
    28  - github.com/sagernet/sing v0.2.1-0.20230318094614-4bbf5f2c3046
     28 + github.com/sagernet/sing v0.2.1-0.20230323071235-f8038854d286
    29 29   github.com/sagernet/sing-dns v0.1.4
    30 30   github.com/sagernet/sing-shadowsocks v0.2.0
    31 31   github.com/sagernet/sing-shadowtls v0.1.0
    32  - github.com/sagernet/sing-tun v0.1.3-0.20230315134716-fe89bbded22d
     32 + github.com/sagernet/sing-tun v0.1.3-0.20230323073325-35d565af6515
    33 33   github.com/sagernet/sing-vmess v0.1.3
    34 34   github.com/sagernet/smux v0.0.0-20230312102458-337ec2a5af37
    35 35   github.com/sagernet/tfo-go v0.0.0-20230303015439-ffcfd8c41cf9
    skipped 60 lines
  • ■ ■ ■ ■ ■ ■
    go.sum
    skipped 110 lines
    111 111  github.com/sagernet/reality v0.0.0-20230312150606-35ea9af0e0b8/go.mod h1:B8lp4WkQ1PwNnrVMM6KyuFR20pU8jYBD+A4EhJovEXU=
    112 112  github.com/sagernet/sing v0.0.0-20220817130738-ce854cda8522/go.mod h1:QVsS5L/ZA2Q5UhQwLrn0Trw+msNd/NPGEhBKR/ioWiY=
    113 113  github.com/sagernet/sing v0.1.8/go.mod h1:jt1w2u7lJQFFSGLiRrRIs5YWmx4kAPfWuOejuDW9qMk=
    114  -github.com/sagernet/sing v0.2.1-0.20230318094614-4bbf5f2c3046 h1:/+ZWbxRvQmco9ES2qT5Eh/x/IiQRjAcUyRG/vQ4dpxc=
    115  -github.com/sagernet/sing v0.2.1-0.20230318094614-4bbf5f2c3046/go.mod h1:9uHswk2hITw8leDbiLS/xn0t9nzBcbePxzm9PJhwdlw=
     114 +github.com/sagernet/sing v0.2.1-0.20230323071235-f8038854d286 h1:0Td2b5l1KgrdlOnbRWgFFWsyb0TLoq/tP6j9Lut4JN0=
     115 +github.com/sagernet/sing v0.2.1-0.20230323071235-f8038854d286/go.mod h1:9uHswk2hITw8leDbiLS/xn0t9nzBcbePxzm9PJhwdlw=
    116 116  github.com/sagernet/sing-dns v0.1.4 h1:7VxgeoSCiiazDSaXXQVcvrTBxFpOePPq/4XdgnUDN+0=
    117 117  github.com/sagernet/sing-dns v0.1.4/go.mod h1:1+6pCa48B1AI78lD+/i/dLgpw4MwfnsSpZo0Ds8wzzk=
    118 118  github.com/sagernet/sing-shadowsocks v0.2.0 h1:ILDWL7pwWfkPLEbviE/MyCgfjaBmJY/JVVY+5jhSb58=
    119 119  github.com/sagernet/sing-shadowsocks v0.2.0/go.mod h1:ysYzszRLpNzJSorvlWRMuzU6Vchsp7sd52q+JNY4axw=
    120 120  github.com/sagernet/sing-shadowtls v0.1.0 h1:05MYce8aR5xfKIn+y7xRFsdKhKt44QZTSEQW+lG5IWQ=
    121 121  github.com/sagernet/sing-shadowtls v0.1.0/go.mod h1:Kn1VUIprdkwCgkS6SXYaLmIpKzQbqBIKJBMY+RvBhYc=
    122  -github.com/sagernet/sing-tun v0.1.3-0.20230315134716-fe89bbded22d h1:1gt4Hu2fHCrmL2NZYCNJ3nCgeczuhK09oCMni9mZmZk=
    123  -github.com/sagernet/sing-tun v0.1.3-0.20230315134716-fe89bbded22d/go.mod h1:KnRkwaDHbb06zgeNPu0LQ8A+vA9myMxKEgHN1brCPHg=
     122 +github.com/sagernet/sing-tun v0.1.3-0.20230323073325-35d565af6515 h1:r25BJqn3o34g+bDdhoRU65zimKPfGCTv7nHuysyJojo=
     123 +github.com/sagernet/sing-tun v0.1.3-0.20230323073325-35d565af6515/go.mod h1:1xzFt4zJ7CzXdbgPcy7+Lsg4ypZo0ivDNZ0oQdL3zEY=
    124 124  github.com/sagernet/sing-vmess v0.1.3 h1:q/+tsF46dvvapL6CpQBgPHJ6nQrDUZqEtLHCbsjO7iM=
    125 125  github.com/sagernet/sing-vmess v0.1.3/go.mod h1:GVXqAHwe9U21uS+Voh4YBIrADQyE4F9v0ayGSixSQAE=
    126 126  github.com/sagernet/smux v0.0.0-20230312102458-337ec2a5af37 h1:HuE6xSwco/Xed8ajZ+coeYLmioq0Qp1/Z2zczFaV8as=
    skipped 117 lines
  • ■ ■ ■ ■ ■
    inbound/tun.go
    skipped 4 lines
    5 5   "net"
    6 6   "strconv"
    7 7   "strings"
    8  - "time"
    9 8   
    10 9   "github.com/sagernet/sing-box/adapter"
    11  - "github.com/sagernet/sing-box/common/canceler"
    12 10   C "github.com/sagernet/sing-box/constant"
    13 11   "github.com/sagernet/sing-box/experimental/libbox/platform"
    14 12   "github.com/sagernet/sing-box/log"
    skipped 193 lines
    208 206   
    209 207  func (t *Tun) NewPacketConnection(ctx context.Context, conn N.PacketConn, upstreamMetadata M.Metadata) error {
    210 208   ctx = log.ContextWithNewID(ctx)
    211  - if tun.NeedTimeoutFromContext(ctx) {
    212  - ctx, conn = canceler.NewPacketConn(ctx, conn, time.Duration(t.udpTimeout)*time.Second)
    213  - }
    214 209   var metadata adapter.InboundContext
    215 210   metadata.Inbound = t.tag
    216 211   metadata.InboundType = C.TypeTun
    skipped 16 lines
  • ■ ■ ■ ■
    outbound/default.go
    skipped 7 lines
    8 8   "time"
    9 9   
    10 10   "github.com/sagernet/sing-box/adapter"
    11  - "github.com/sagernet/sing-box/common/canceler"
    12 11   C "github.com/sagernet/sing-box/constant"
    13 12   "github.com/sagernet/sing-box/log"
    14 13   "github.com/sagernet/sing/common"
    15 14   "github.com/sagernet/sing/common/buf"
    16 15   "github.com/sagernet/sing/common/bufio"
     16 + "github.com/sagernet/sing/common/canceler"
    17 17   E "github.com/sagernet/sing/common/exceptions"
    18 18   N "github.com/sagernet/sing/common/network"
    19 19  )
    skipped 98 lines
  • ■ ■ ■ ■
    outbound/dns.go
    skipped 6 lines
    7 7   "os"
    8 8   
    9 9   "github.com/sagernet/sing-box/adapter"
    10  - "github.com/sagernet/sing-box/common/canceler"
    11 10   C "github.com/sagernet/sing-box/constant"
    12 11   "github.com/sagernet/sing-dns"
    13 12   "github.com/sagernet/sing/common"
    14 13   "github.com/sagernet/sing/common/buf"
     14 + "github.com/sagernet/sing/common/canceler"
    15 15   M "github.com/sagernet/sing/common/metadata"
    16 16   N "github.com/sagernet/sing/common/network"
    17 17   "github.com/sagernet/sing/common/task"
    skipped 133 lines
Please wait...
Page is in error, reload to recover