github.com/metacubex/mihomo@v1.18.5/listener/sing_tun/server_windows.go (about) 1 package sing_tun 2 3 import ( 4 "time" 5 6 "github.com/metacubex/mihomo/constant/features" 7 "github.com/metacubex/mihomo/log" 8 9 tun "github.com/metacubex/sing-tun" 10 ) 11 12 func tunNew(options tun.Options) (tunIf tun.Tun, err error) { 13 maxRetry := 3 14 for i := 0; i < maxRetry; i++ { 15 timeBegin := time.Now() 16 tunIf, err = tun.New(options) 17 if err == nil { 18 return 19 } 20 timeEnd := time.Now() 21 if timeEnd.Sub(timeBegin) < 1*time.Second { // retrying for "Cannot create a file when that file already exists." 22 return 23 } 24 log.Warnln("Start Tun interface timeout: %s [retrying %d/%d]", err, i+1, maxRetry) 25 } 26 return 27 } 28 29 func init() { 30 tun.TunnelType = InterfaceName 31 32 if features.WindowsMajorVersion < 10 { 33 // to resolve "bind: The requested address is not valid in its context" 34 EnforceBindInterface = true 35 } 36 }