mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 15:36:41 -05:00
refactor
This commit is contained in:
parent
3aa5343722
commit
326a54baea
@ -32,8 +32,7 @@ func ReadTCPSession(user *protocol.User, reader io.Reader) (*protocol.RequestHea
|
|||||||
defer buffer.Release()
|
defer buffer.Release()
|
||||||
|
|
||||||
ivLen := account.Cipher.IVSize()
|
ivLen := account.Cipher.IVSize()
|
||||||
err = buffer.AppendSupplier(buf.ReadFullFrom(reader, ivLen))
|
if err := buffer.AppendSupplier(buf.ReadFullFrom(reader, ivLen)); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, nil, newError("failed to read IV").Base(err)
|
return nil, nil, newError("failed to read IV").Base(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,15 +51,13 @@ func ReadTCPSession(user *protocol.User, reader io.Reader) (*protocol.RequestHea
|
|||||||
Command: protocol.RequestCommandTCP,
|
Command: protocol.RequestCommandTCP,
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.Clear()
|
if err := buffer.Reset(buf.ReadFullFrom(reader, 1)); err != nil {
|
||||||
err = buffer.AppendSupplier(buf.ReadFullFrom(reader, 1))
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, newError("failed to read address type").Base(err)
|
return nil, nil, newError("failed to read address type").Base(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
addrType := (buffer.Byte(0) & 0x0F)
|
addrType := (buffer.Byte(0) & 0x0F)
|
||||||
if (buffer.Byte(0) & 0x10) == 0x10 {
|
if (buffer.Byte(0) & 0x10) == 0x10 {
|
||||||
request.Option |= RequestOptionOneTimeAuth
|
request.Option.Set(RequestOptionOneTimeAuth)
|
||||||
}
|
}
|
||||||
|
|
||||||
if request.Option.Has(RequestOptionOneTimeAuth) && account.OneTimeAuth == Account_Disabled {
|
if request.Option.Has(RequestOptionOneTimeAuth) && account.OneTimeAuth == Account_Disabled {
|
||||||
@ -73,20 +70,17 @@ func ReadTCPSession(user *protocol.User, reader io.Reader) (*protocol.RequestHea
|
|||||||
|
|
||||||
switch addrType {
|
switch addrType {
|
||||||
case AddrTypeIPv4:
|
case AddrTypeIPv4:
|
||||||
err := buffer.AppendSupplier(buf.ReadFullFrom(reader, 4))
|
if err := buffer.AppendSupplier(buf.ReadFullFrom(reader, 4)); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, nil, newError("failed to read IPv4 address").Base(err)
|
return nil, nil, newError("failed to read IPv4 address").Base(err)
|
||||||
}
|
}
|
||||||
request.Address = v2net.IPAddress(buffer.BytesFrom(-4))
|
request.Address = v2net.IPAddress(buffer.BytesFrom(-4))
|
||||||
case AddrTypeIPv6:
|
case AddrTypeIPv6:
|
||||||
err := buffer.AppendSupplier(buf.ReadFullFrom(reader, 16))
|
if err := buffer.AppendSupplier(buf.ReadFullFrom(reader, 16)); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, nil, newError("failed to read IPv6 address").Base(err)
|
return nil, nil, newError("failed to read IPv6 address").Base(err)
|
||||||
}
|
}
|
||||||
request.Address = v2net.IPAddress(buffer.BytesFrom(-16))
|
request.Address = v2net.IPAddress(buffer.BytesFrom(-16))
|
||||||
case AddrTypeDomain:
|
case AddrTypeDomain:
|
||||||
err := buffer.AppendSupplier(buf.ReadFullFrom(reader, 1))
|
if err := buffer.AppendSupplier(buf.ReadFullFrom(reader, 1)); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, nil, newError("failed to read domain lenth.").Base(err)
|
return nil, nil, newError("failed to read domain lenth.").Base(err)
|
||||||
}
|
}
|
||||||
domainLength := int(buffer.BytesFrom(-1)[0])
|
domainLength := int(buffer.BytesFrom(-1)[0])
|
||||||
|
Loading…
Reference in New Issue
Block a user