parse real client IP
This commit is contained in:
+10
-12
@@ -2,10 +2,10 @@ package v5
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"math"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/go-gost/core/common/bufpool"
|
||||
"github.com/go-gost/core/logger"
|
||||
"github.com/go-gost/gosocks5"
|
||||
)
|
||||
@@ -25,18 +25,17 @@ func (c *bindConn) RemoteAddr() net.Addr {
|
||||
}
|
||||
|
||||
type udpRelayConn struct {
|
||||
udpConn *net.UDPConn
|
||||
tcpConn net.Conn
|
||||
taddr net.Addr
|
||||
bufferSize int
|
||||
logger logger.Logger
|
||||
udpConn *net.UDPConn
|
||||
tcpConn net.Conn
|
||||
taddr net.Addr
|
||||
rbuf [math.MaxUint16]byte
|
||||
wbuf [math.MaxInt16]byte
|
||||
logger logger.Logger
|
||||
}
|
||||
|
||||
func (c *udpRelayConn) ReadFrom(b []byte) (n int, addr net.Addr, err error) {
|
||||
buf := bufpool.Get(c.bufferSize)
|
||||
defer bufpool.Put(buf)
|
||||
|
||||
nn, err := c.udpConn.Read(buf)
|
||||
buf := c.rbuf[:]
|
||||
nn, err := c.udpConn.Read(buf[:])
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -82,8 +81,7 @@ func (c *udpRelayConn) WriteTo(b []byte, addr net.Addr) (n int, err error) {
|
||||
Data: b,
|
||||
}
|
||||
|
||||
buf := bufpool.Get(c.bufferSize)
|
||||
defer bufpool.Put(buf)
|
||||
buf := c.wbuf[:]
|
||||
|
||||
nn, err := dgram.WriteTo(bytes.NewBuffer(buf[:0]))
|
||||
if err != nil {
|
||||
|
||||
@@ -225,10 +225,9 @@ func (c *socks5Connector) relayUDP(ctx context.Context, conn net.Conn, addr net.
|
||||
}
|
||||
|
||||
return &udpRelayConn{
|
||||
udpConn: cc.(*net.UDPConn),
|
||||
tcpConn: conn,
|
||||
taddr: addr,
|
||||
bufferSize: c.md.udpBufferSize,
|
||||
logger: log,
|
||||
udpConn: cc.(*net.UDPConn),
|
||||
tcpConn: conn,
|
||||
taddr: addr,
|
||||
logger: log,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -4,19 +4,14 @@ import (
|
||||
"time"
|
||||
|
||||
mdata "github.com/go-gost/core/metadata"
|
||||
mdutil "github.com/go-gost/x/metadata/util"
|
||||
"github.com/go-gost/x/internal/util/mux"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultUDPBufferSize = 4096
|
||||
mdutil "github.com/go-gost/x/metadata/util"
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
connectTimeout time.Duration
|
||||
noTLS bool
|
||||
relay string
|
||||
udpBufferSize int
|
||||
udpTimeout time.Duration
|
||||
muxCfg *mux.Config
|
||||
}
|
||||
@@ -25,10 +20,6 @@ func (c *socks5Connector) parseMetadata(md mdata.Metadata) (err error) {
|
||||
c.md.connectTimeout = mdutil.GetDuration(md, "timeout")
|
||||
c.md.noTLS = mdutil.GetBool(md, "notls")
|
||||
c.md.relay = mdutil.GetString(md, "relay")
|
||||
c.md.udpBufferSize = mdutil.GetInt(md, "udp.bufferSize", "udpBufferSize")
|
||||
if c.md.udpBufferSize <= 0 {
|
||||
c.md.udpBufferSize = defaultUDPBufferSize
|
||||
}
|
||||
c.md.udpTimeout = mdutil.GetDuration(md, "udp.timeout")
|
||||
|
||||
c.md.muxCfg = &mux.Config{
|
||||
|
||||
Reference in New Issue
Block a user