Improve: UDP relay refactor (#441)

Co-authored-by: Dreamacro <Dreamacro@vip.qq.com>
This commit is contained in:
Comzyh
2019-12-28 18:44:01 +08:00
committed by Dreamacro
parent 3f592988a9
commit 93ea037230
11 changed files with 202 additions and 52 deletions

View File

@ -201,8 +201,13 @@ func (uc *ssUDPConn) WriteTo(b []byte, addr net.Addr) (n int, err error) {
}
func (uc *ssUDPConn) ReadFrom(b []byte) (int, net.Addr, error) {
n, a, e := uc.PacketConn.ReadFrom(b)
n, _, e := uc.PacketConn.ReadFrom(b)
addr := socks5.SplitAddr(b[:n])
var from net.Addr
if e == nil {
// Get the source IP/Port of packet.
from = addr.UDPAddr()
}
copy(b, b[len(addr):])
return n - len(addr), a, e
return n - len(addr), from, e
}