mirror of
https://github.com/SagerNet/sing-mux.git
synced 2025-04-03 20:07:41 +03:00
Fix WriteAddrPort usage
This commit is contained in:
parent
2a10ebd53b
commit
7befbadbf3
3 changed files with 28 additions and 14 deletions
|
@ -56,7 +56,10 @@ func (c *clientConn) Write(b []byte) (n int, err error) {
|
||||||
}
|
}
|
||||||
buffer := buf.NewSize(streamRequestLen(request) + len(b))
|
buffer := buf.NewSize(streamRequestLen(request) + len(b))
|
||||||
defer buffer.Release()
|
defer buffer.Release()
|
||||||
EncodeStreamRequest(request, buffer)
|
err = EncodeStreamRequest(request, buffer)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
buffer.Write(b)
|
buffer.Write(b)
|
||||||
_, err = c.Conn.Write(buffer.Bytes())
|
_, err = c.Conn.Write(buffer.Bytes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -143,7 +146,10 @@ func (c *clientPacketConn) writeRequest(payload []byte) (n int, err error) {
|
||||||
}
|
}
|
||||||
buffer := buf.NewSize(rLen)
|
buffer := buf.NewSize(rLen)
|
||||||
defer buffer.Release()
|
defer buffer.Release()
|
||||||
EncodeStreamRequest(request, buffer)
|
err = EncodeStreamRequest(request, buffer)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
if len(payload) > 0 {
|
if len(payload) > 0 {
|
||||||
common.Must(
|
common.Must(
|
||||||
binary.Write(buffer, binary.BigEndian, uint16(len(payload))),
|
binary.Write(buffer, binary.BigEndian, uint16(len(payload))),
|
||||||
|
@ -340,10 +346,16 @@ func (c *clientPacketAddrConn) writeRequest(payload []byte, destination M.Socksa
|
||||||
}
|
}
|
||||||
buffer := buf.NewSize(rLen)
|
buffer := buf.NewSize(rLen)
|
||||||
defer buffer.Release()
|
defer buffer.Release()
|
||||||
EncodeStreamRequest(request, buffer)
|
err = EncodeStreamRequest(request, buffer)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
if len(payload) > 0 {
|
if len(payload) > 0 {
|
||||||
|
err = M.SocksaddrSerializer.WriteAddrPort(buffer, destination)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
common.Must(
|
common.Must(
|
||||||
M.SocksaddrSerializer.WriteAddrPort(buffer, destination),
|
|
||||||
binary.Write(buffer, binary.BigEndian, uint16(len(payload))),
|
binary.Write(buffer, binary.BigEndian, uint16(len(payload))),
|
||||||
common.Error(buffer.Write(payload)),
|
common.Error(buffer.Write(payload)),
|
||||||
)
|
)
|
||||||
|
@ -411,10 +423,11 @@ func (c *clientPacketAddrConn) WritePacket(buffer *buf.Buffer, destination M.Soc
|
||||||
}
|
}
|
||||||
bLen := buffer.Len()
|
bLen := buffer.Len()
|
||||||
header := buf.With(buffer.ExtendHeader(M.SocksaddrSerializer.AddrPortLen(destination) + 2))
|
header := buf.With(buffer.ExtendHeader(M.SocksaddrSerializer.AddrPortLen(destination) + 2))
|
||||||
common.Must(
|
err := M.SocksaddrSerializer.WriteAddrPort(header, destination)
|
||||||
M.SocksaddrSerializer.WriteAddrPort(header, destination),
|
if err != nil {
|
||||||
binary.Write(header, binary.BigEndian, uint16(bLen)),
|
return err
|
||||||
)
|
}
|
||||||
|
common.Must(binary.Write(header, binary.BigEndian, uint16(bLen)))
|
||||||
return c.ExtendedConn.WriteBuffer(buffer)
|
return c.ExtendedConn.WriteBuffer(buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -143,7 +143,7 @@ func streamRequestLen(request StreamRequest) int {
|
||||||
return rLen
|
return rLen
|
||||||
}
|
}
|
||||||
|
|
||||||
func EncodeStreamRequest(request StreamRequest, buffer *buf.Buffer) {
|
func EncodeStreamRequest(request StreamRequest, buffer *buf.Buffer) error {
|
||||||
destination := request.Destination
|
destination := request.Destination
|
||||||
var flags uint16
|
var flags uint16
|
||||||
if request.Network == N.NetworkUDP {
|
if request.Network == N.NetworkUDP {
|
||||||
|
@ -155,10 +155,8 @@ func EncodeStreamRequest(request StreamRequest, buffer *buf.Buffer) {
|
||||||
destination = Destination
|
destination = Destination
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
common.Must(
|
common.Must(binary.Write(buffer, binary.BigEndian, flags))
|
||||||
binary.Write(buffer, binary.BigEndian, flags),
|
return M.SocksaddrSerializer.WriteAddrPort(buffer, destination)
|
||||||
M.SocksaddrSerializer.WriteAddrPort(buffer, destination),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type StreamResponse struct {
|
type StreamResponse struct {
|
||||||
|
|
|
@ -276,7 +276,10 @@ func (c *serverPacketAddrConn) ReadPacket(buffer *buf.Buffer) (destination M.Soc
|
||||||
func (c *serverPacketAddrConn) WritePacket(buffer *buf.Buffer, destination M.Socksaddr) error {
|
func (c *serverPacketAddrConn) WritePacket(buffer *buf.Buffer, destination M.Socksaddr) error {
|
||||||
pLen := buffer.Len()
|
pLen := buffer.Len()
|
||||||
common.Must(binary.Write(buf.With(buffer.ExtendHeader(2)), binary.BigEndian, uint16(pLen)))
|
common.Must(binary.Write(buf.With(buffer.ExtendHeader(2)), binary.BigEndian, uint16(pLen)))
|
||||||
common.Must(M.SocksaddrSerializer.WriteAddrPort(buf.With(buffer.ExtendHeader(M.SocksaddrSerializer.AddrPortLen(destination))), destination))
|
err := M.SocksaddrSerializer.WriteAddrPort(buf.With(buffer.ExtendHeader(M.SocksaddrSerializer.AddrPortLen(destination))), destination)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if !c.responseWritten {
|
if !c.responseWritten {
|
||||||
c.access.Lock()
|
c.access.Lock()
|
||||||
if c.responseWritten {
|
if c.responseWritten {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue