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 limiterOut limiter.Limiter
expIn int64 expIn int64
expOut int64 expOut int64
opts []limiter.Option
} }
func WrapConn(limiter limiter.TrafficLimiter, c net.Conn) net.Conn { func WrapConn(tlimiter limiter.TrafficLimiter, c net.Conn) net.Conn {
if limiter == nil { if tlimiter == nil {
return c return c
} }
return &serverConn{ return &serverConn{
Conn: c, 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" "io"
"time" "time"
"github.com/go-gost/core/limiter/traffic"
limiter "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 limiterOut limiter.Limiter
expIn int64 expIn int64
expOut int64 expOut int64
opts []traffic.Option opts []limiter.Option
key string 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 { if limiter == nil {
return rw 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 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 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 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 return
} }

View File

@ -36,7 +36,7 @@ func (l *tunListener) createTun() (ifce io.ReadWriteCloser, name string, ip net.
ip = ipNet.IP 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 return
} }