fix tun config

This commit is contained in:
ginuerzh 2023-11-20 20:42:29 +08:00
parent e8be8d625a
commit 9be710dc19
5 changed files with 14 additions and 9 deletions

View File

@ -29,16 +29,22 @@ type serverConn struct {
limiterOut limiter.Limiter
expIn int64
expOut int64
opts []limiter.Option
}
func WrapConn(limiter limiter.TrafficLimiter, c net.Conn) net.Conn {
if limiter == nil {
func WrapConn(tlimiter limiter.TrafficLimiter, c net.Conn) net.Conn {
if tlimiter == nil {
return c
}
return &serverConn{
Conn: c,
limiter: limiter,
limiter: tlimiter,
opts: []limiter.Option{
limiter.NetworkOption(c.LocalAddr().Network()),
limiter.SrcOption(c.RemoteAddr().String()),
limiter.AddrOption(c.LocalAddr().String()),
},
}
}

View File

@ -6,7 +6,6 @@ import (
"io"
"time"
"github.com/go-gost/core/limiter/traffic"
limiter "github.com/go-gost/core/limiter/traffic"
)
@ -19,11 +18,11 @@ type readWriter struct {
limiterOut limiter.Limiter
expIn int64
expOut int64
opts []traffic.Option
opts []limiter.Option
key string
}
func WrapReadWriter(limiter limiter.TrafficLimiter, rw io.ReadWriter, key string, opts ...traffic.Option) io.ReadWriter {
func WrapReadWriter(limiter limiter.TrafficLimiter, rw io.ReadWriter, key string, opts ...limiter.Option) io.ReadWriter {
if limiter == nil {
return rw
}

View File

@ -36,7 +36,7 @@ func (l *tunListener) createTun() (ifce io.ReadWriteCloser, name string, ip net.
ip = l.md.config.Net[0].IP
}
if err = l.addRoutes(name, l.md.config.Routes...); err != nil {
if err = l.addRoutes(name); err != nil {
return
}

View File

@ -36,7 +36,7 @@ func (l *tunListener) createTun() (ifce io.ReadWriteCloser, name string, ip net.
ip = l.md.config.Net[0].IP
}
if err = l.addRoutes(name, l.md.config.Routes...); err != nil {
if err = l.addRoutes(name); err != nil {
return
}

View File

@ -36,7 +36,7 @@ func (l *tunListener) createTun() (ifce io.ReadWriteCloser, name string, ip net.
ip = ipNet.IP
}
if err = l.addRoutes(name, l.md.config.Gateway, l.md.config.Routes...); err != nil {
if err = l.addRoutes(name, l.md.config.Gateway); err != nil {
return
}