diff --git a/common/uot/resolver.go b/common/uot/resolver.go deleted file mode 100644 index 6c3a7fb..0000000 --- a/common/uot/resolver.go +++ /dev/null @@ -1,21 +0,0 @@ -package uot - -import ( - "context" - "net" - "time" -) - -var LookupAddress func(domain string) (net.IP, error) - -func init() { - LookupAddress = func(domain string) (net.IP, error) { - ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) - ips, err := net.DefaultResolver.LookupIP(ctx, "ip", domain) - cancel() - if err != nil { - return nil, err - } - return ips[0], nil - } -} diff --git a/common/uot/server.go b/common/uot/server.go index 2b61947..f5ff4e8 100644 --- a/common/uot/server.go +++ b/common/uot/server.go @@ -48,17 +48,18 @@ func (c *ServerConn) loopInput() { _buffer := buf.StackNew() defer common.KeepAlive(_buffer) buffer := common.Dup(_buffer) + defer buffer.Release() for { destination, err := AddrParser.ReadAddrPort(c.inputReader) if err != nil { break } if destination.Family().IsFqdn() { - ip, err := LookupAddress(destination.Fqdn) + addr, err := net.ResolveUDPAddr("udp", destination.String()) if err != nil { - break + continue } - destination.Addr = M.AddrFromIP(ip) + destination = M.SocksaddrFromNet(addr) } var length uint16 err = binary.Read(c.inputReader, binary.BigEndian, &length) @@ -82,6 +83,7 @@ func (c *ServerConn) loopOutput() { _buffer := buf.StackNew() defer common.KeepAlive(_buffer) buffer := common.Dup(_buffer) + defer buffer.Release() for { buffer.FullReset() n, addr, err := buffer.ReadPacketFrom(c) diff --git a/protocol/socks/packet.go b/protocol/socks/packet.go index 5e55c8c..374b0a6 100644 --- a/protocol/socks/packet.go +++ b/protocol/socks/packet.go @@ -58,6 +58,7 @@ func (c *AssociateConn) WriteTo(p []byte, addr net.Addr) (n int, err error) { _buffer := buf.StackNew() defer common.KeepAlive(_buffer) buffer := common.Dup(_buffer) + defer buffer.Release() common.Must(buffer.WriteZeroN(3)) err = M.SocksaddrSerializer.WriteAddrPort(buffer, M.SocksaddrFromNet(addr)) if err != nil { @@ -81,6 +82,7 @@ func (c *AssociateConn) Write(b []byte) (n int, err error) { _buffer := buf.StackNew() defer common.KeepAlive(_buffer) buffer := common.Dup(_buffer) + defer buffer.Release() common.Must(buffer.WriteZeroN(3)) err = M.SocksaddrSerializer.WriteAddrPort(buffer, c.dest) if err != nil { @@ -150,6 +152,7 @@ func (c *AssociatePacketConn) WriteTo(p []byte, addr net.Addr) (n int, err error _buffer := buf.StackNew() defer common.KeepAlive(_buffer) buffer := common.Dup(_buffer) + defer buffer.Release() common.Must(buffer.WriteZeroN(3)) err = M.SocksaddrSerializer.WriteAddrPort(buffer, M.SocksaddrFromNet(addr)) @@ -173,6 +176,7 @@ func (c *AssociatePacketConn) Write(b []byte) (n int, err error) { _buffer := buf.StackNew() defer common.KeepAlive(_buffer) buffer := common.Dup(_buffer) + defer buffer.Release() common.Must(buffer.WriteZeroN(3)) err = M.SocksaddrSerializer.WriteAddrPort(buffer, c.dest)