Feature: add an option to set udp timeout

This commit is contained in:
xjasonlyu
2021-02-26 14:22:16 +08:00
parent ec4d98c4bf
commit 9502706ed9
3 changed files with 30 additions and 15 deletions

View File

@@ -10,6 +10,7 @@ import (
"github.com/xjasonlyu/tun2socks/log"
"github.com/xjasonlyu/tun2socks/proxy"
"github.com/xjasonlyu/tun2socks/stats"
"github.com/xjasonlyu/tun2socks/tunnel"
)
var _engine = &engine{}
@@ -30,15 +31,16 @@ func Insert(k *Key) {
}
type Key struct {
MTU int
Mark int
Proxy string
Stats string
Token string
Device string
LogLevel string
Interface string
Version bool
MTU int
Mark int
UDPTimeout int
Proxy string
Stats string
Token string
Device string
LogLevel string
Interface string
Version bool
}
type engine struct {
@@ -64,6 +66,7 @@ func (e *engine) start() error {
e.setMark,
e.setInterface,
e.setStats,
e.setUDPTimeout,
e.setProxy,
e.setDevice,
e.setStack,
@@ -123,6 +126,13 @@ func (e *engine) setStats() error {
return nil
}
func (e *engine) setUDPTimeout() error {
if e.UDPTimeout > 0 {
tunnel.SetUDPTimeout(e.UDPTimeout)
}
return nil
}
func (e *engine) setProxy() (err error) {
if e.Proxy == "" {
return errors.New("empty proxy")