mirror of
https://github.com/nadoo/glider.git
synced 2026-11-19 07:09:42 +08:00
config: added tcpbufsize & udpbufsize(default: 2048)
This commit is contained in:
1 parent
41861ff48e
commit
d615dc087e
7 files changed
+32
-10
No files matched your search
+2
-2
@@ -13,12 +13,12 @@ import (
|
||||
"github.com/nadoo/glider/pool"
|
||||
)
|
||||
|
||||
const (
|
||||
var (
|
||||
// TCPBufSize is the size of tcp buffer.
|
||||
TCPBufSize = 32 << 10
|
||||
|
||||
// UDPBufSize is the size of udp buffer.
|
||||
UDPBufSize = 64 << 10
|
||||
UDPBufSize = 2 << 10
|
||||
)
|
||||
|
||||
// Conn is a connection with buffered reader.
|
||||
|
||||
@@ -67,6 +67,9 @@ func (a Addr) String() string {
|
||||
return net.JoinHostPort(host, port)
|
||||
}
|
||||
|
||||
// Network returns network name. Implements net.Addr interface.
|
||||
func (a Addr) Network() string { return "socks" }
|
||||
|
||||
// ReadAddrBuf reads just enough bytes from r to get a valid Addr.
|
||||
func ReadAddrBuf(r io.Reader, b []byte) (Addr, error) {
|
||||
if len(b) < MaxAddrLen {
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
"github.com/nadoo/glider/proxy/ssr/internal/protocol"
|
||||
)
|
||||
|
||||
const bufSize = proxy.TCPBufSize
|
||||
var bufSize = proxy.TCPBufSize
|
||||
|
||||
func init() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
|
||||
@@ -80,7 +80,7 @@ func (s *TProxy) ListenAndServeUDP() {
|
||||
}
|
||||
|
||||
var session *natEntry
|
||||
sessionKey := lraddr.String() + dstAddr.String()
|
||||
sessionKey := lraddr.String()
|
||||
|
||||
v, ok := nm.Load(sessionKey)
|
||||
if !ok && v == nil {
|
||||
@@ -115,7 +115,6 @@ func (s *TProxy) ListenAndServeUDP() {
|
||||
_, err = session.WriteTo(buf[:n], session.writeTo)
|
||||
if err != nil {
|
||||
log.F("[tproxyu] writeTo %s error: %v", session.writeTo, err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
// PktConn is a udp Packet.Conn.
|
||||
type PktConn struct {
|
||||
net.Conn
|
||||
|
||||
tgtAddr socks.Addr
|
||||
}
|
||||
|
||||
@@ -27,7 +26,8 @@ func NewPktConn(c net.Conn, tgtAddr socks.Addr) *PktConn {
|
||||
}
|
||||
|
||||
// ReadFrom implements the necessary function of net.PacketConn.
|
||||
// TODO: we know that we use it in proxy.RelayUDP and the length of b is enough, check it later.
|
||||
// NOTE: the underlying connection is not udp, we returned the target address here,
|
||||
// it's not the vless server's address, do not WriteTo it.
|
||||
func (pc *PktConn) ReadFrom(b []byte) (int, net.Addr, error) {
|
||||
// ATYP, DST.ADDR, DST.PORT
|
||||
_, err := socks.ReadAddr(pc.Conn)
|
||||
@@ -35,6 +35,7 @@ func (pc *PktConn) ReadFrom(b []byte) (int, net.Addr, error) {
|
||||
return 0, nil, err
|
||||
}
|
||||
|
||||
// TODO: we know that we use it in proxy.RelayUDP and the length of b is enough, check it later.
|
||||
if len(b) < 2 {
|
||||
return 0, nil, errors.New("buf size is not enough")
|
||||
}
|
||||
@@ -62,7 +63,7 @@ func (pc *PktConn) ReadFrom(b []byte) (int, net.Addr, error) {
|
||||
}
|
||||
|
||||
// TODO: check the addr in return value, it's a fake packetConn so the addr is not valid
|
||||
return n, nil, err
|
||||
return n, pc.tgtAddr, err
|
||||
}
|
||||
|
||||
// WriteTo implements the necessary function of net.PacketConn.
|
||||
|
||||
Reference in new issue
Block a user