2022-10-06 11:23:38 +00:00
|
|
|
package sing_tun
|
|
|
|
|
2022-10-14 00:27:34 +00:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/Dreamacro/clash/log"
|
|
|
|
|
2022-12-05 03:03:28 +00:00
|
|
|
tun "github.com/metacubex/sing-tun"
|
2022-10-14 00:27:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func tunOpen(options tun.Options) (tunIf tun.Tun, err error) {
|
|
|
|
maxRetry := 3
|
|
|
|
for i := 0; i < maxRetry; i++ {
|
|
|
|
timeBegin := time.Now()
|
|
|
|
tunIf, err = tun.Open(options)
|
|
|
|
if err == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
timeEnd := time.Now()
|
|
|
|
if timeEnd.Sub(timeBegin) < 1*time.Second { // retrying for "Cannot create a file when that file already exists."
|
|
|
|
return
|
|
|
|
}
|
|
|
|
log.Warnln("Start Tun interface timeout: %s [retrying %d/%d]", err, i+1, maxRetry)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2022-10-06 11:23:38 +00:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
tun.TunnelType = InterfaceName
|
|
|
|
}
|