|
|
|
@ -241,7 +241,7 @@ func writeSocks5Response(writer io.Writer, errCode byte, address net.Address, po
|
|
|
|
|
buffer := buf.New() |
|
|
|
|
defer buffer.Release() |
|
|
|
|
|
|
|
|
|
common.Must2(buffer.AppendBytes(socks5Version, errCode, 0x00 /* reserved */)) |
|
|
|
|
common.Must2(buffer.WriteBytes(socks5Version, errCode, 0x00 /* reserved */)) |
|
|
|
|
if err := addrParser.WriteAddressPort(buffer, address, port); err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
@ -253,7 +253,7 @@ func writeSocks4Response(writer io.Writer, errCode byte, address net.Address, po
|
|
|
|
|
buffer := buf.New() |
|
|
|
|
defer buffer.Release() |
|
|
|
|
|
|
|
|
|
common.Must2(buffer.AppendBytes(0x00, errCode)) |
|
|
|
|
common.Must2(buffer.WriteBytes(0x00, errCode)) |
|
|
|
|
common.Must(buffer.AppendSupplier(serial.WriteUint16(port.Value()))) |
|
|
|
|
common.Must2(buffer.Write(address.IP())) |
|
|
|
|
return buf.WriteAllBytes(writer, buffer.Bytes()) |
|
|
|
@ -286,7 +286,7 @@ func DecodeUDPPacket(packet *buf.Buffer) (*protocol.RequestHeader, error) {
|
|
|
|
|
|
|
|
|
|
func EncodeUDPPacket(request *protocol.RequestHeader, data []byte) (*buf.Buffer, error) { |
|
|
|
|
b := buf.New() |
|
|
|
|
common.Must2(b.AppendBytes(0, 0, 0 /* Fragment */)) |
|
|
|
|
common.Must2(b.WriteBytes(0, 0, 0 /* Fragment */)) |
|
|
|
|
if err := addrParser.WriteAddressPort(b, request.Address, request.Port); err != nil { |
|
|
|
|
b.Release() |
|
|
|
|
return nil, err |
|
|
|
@ -348,7 +348,7 @@ func ClientHandshake(request *protocol.RequestHeader, reader io.Reader, writer i
|
|
|
|
|
b := buf.New() |
|
|
|
|
defer b.Release() |
|
|
|
|
|
|
|
|
|
common.Must2(b.AppendBytes(socks5Version, 0x01, authByte)) |
|
|
|
|
common.Must2(b.WriteBytes(socks5Version, 0x01, authByte)) |
|
|
|
|
if authByte == authPassword { |
|
|
|
|
rawAccount, err := request.User.GetTypedAccount() |
|
|
|
|
if err != nil { |
|
|
|
@ -356,9 +356,9 @@ func ClientHandshake(request *protocol.RequestHeader, reader io.Reader, writer i
|
|
|
|
|
} |
|
|
|
|
account := rawAccount.(*Account) |
|
|
|
|
|
|
|
|
|
common.Must2(b.AppendBytes(0x01, byte(len(account.Username)))) |
|
|
|
|
common.Must2(b.WriteBytes(0x01, byte(len(account.Username)))) |
|
|
|
|
common.Must2(b.Write([]byte(account.Username))) |
|
|
|
|
common.Must2(b.AppendBytes(byte(len(account.Password)))) |
|
|
|
|
common.Must2(b.WriteBytes(byte(len(account.Password)))) |
|
|
|
|
common.Must2(b.Write([]byte(account.Password))) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -392,7 +392,7 @@ func ClientHandshake(request *protocol.RequestHeader, reader io.Reader, writer i
|
|
|
|
|
if request.Command == protocol.RequestCommandUDP { |
|
|
|
|
command = byte(cmdUDPPort) |
|
|
|
|
} |
|
|
|
|
common.Must2(b.AppendBytes(socks5Version, command, 0x00 /* reserved */)) |
|
|
|
|
common.Must2(b.WriteBytes(socks5Version, command, 0x00 /* reserved */)) |
|
|
|
|
if err := addrParser.WriteAddressPort(b, request.Address, request.Port); err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|