Projects STRLCPY tun2socks Commits 680feede
🤬
  • ■ ■ ■ ■ ■ ■
    core/device/tun/tun_wireguard.go
    skipped 3 lines
    4 4   
    5 5  import (
    6 6   "fmt"
     7 + "sync"
    7 8   
    8 9   "golang.zx2c4.com/wireguard/tun"
    9 10   
    skipped 12 lines
    22 23   rSizes []int
    23 24   rBuffs [][]byte
    24 25   wBuffs [][]byte
     26 + rMutex sync.Mutex
     27 + wMutex sync.Mutex
    25 28  }
    26 29   
    27 30  func Open(name string, mtu uint32) (_ device.Device, err error) {
    skipped 39 lines
    67 70  }
    68 71   
    69 72  func (t *TUN) Read(packet []byte) (int, error) {
     73 + t.rMutex.Lock()
     74 + defer t.rMutex.Unlock()
    70 75   t.rBuffs[0] = packet
    71 76   _, err := t.nt.Read(t.rBuffs, t.rSizes, t.offset)
    72 77   return t.rSizes[0], err
    73 78  }
    74 79   
    75 80  func (t *TUN) Write(packet []byte) (int, error) {
     81 + t.wMutex.Lock()
     82 + defer t.wMutex.Unlock()
    76 83   t.wBuffs[0] = packet
    77 84   return t.nt.Write(t.wBuffs, t.offset)
    78 85  }
    skipped 11 lines
Please wait...
Page is in error, reload to recover