mirror of
https://github.com/v2ray/v2ray-core.git
synced 2026-11-18 23:00:12 +00:00
refactor bytes functions
This commit is contained in:
16 files changed
+78
-64
No files matched your search
@@ -14,12 +14,11 @@ import (
|
||||
)
|
||||
|
||||
func hashTimestamp(t protocol.Timestamp) []byte {
|
||||
once := t.Bytes()
|
||||
bytes := make([]byte, 0, 32)
|
||||
bytes = append(bytes, once...)
|
||||
bytes = append(bytes, once...)
|
||||
bytes = append(bytes, once...)
|
||||
bytes = append(bytes, once...)
|
||||
t.Bytes(bytes)
|
||||
t.Bytes(bytes)
|
||||
t.Bytes(bytes)
|
||||
t.Bytes(bytes)
|
||||
return bytes
|
||||
}
|
||||
|
||||
@@ -53,7 +52,7 @@ func NewClientSession(idHash protocol.IDHash) *ClientSession {
|
||||
func (this *ClientSession) EncodeRequestHeader(header *protocol.RequestHeader, writer io.Writer) {
|
||||
timestamp := protocol.NewTimestampGenerator(protocol.NowTime(), 30)()
|
||||
idHash := this.idHash(header.User.Account.(*protocol.VMessAccount).AnyValidID().Bytes())
|
||||
idHash.Write(timestamp.Bytes())
|
||||
idHash.Write(timestamp.Bytes(nil))
|
||||
writer.Write(idHash.Sum(nil))
|
||||
|
||||
buffer := alloc.NewSmallBuffer().Clear()
|
||||
@@ -64,7 +63,7 @@ func (this *ClientSession) EncodeRequestHeader(header *protocol.RequestHeader, w
|
||||
buffer.Append(this.requestBodyKey)
|
||||
buffer.AppendBytes(this.responseHeader, byte(header.Option), byte(0), byte(0))
|
||||
buffer.AppendBytes(byte(header.Command))
|
||||
buffer.Append(header.Port.Bytes())
|
||||
buffer.AppendUint16(header.Port.Value())
|
||||
|
||||
switch {
|
||||
case header.Address.IsIPv4():
|
||||
|
||||
@@ -94,12 +94,12 @@ func (this *CommandSwitchAccountFactory) Marshal(command interface{}, writer io.
|
||||
writer.Write([]byte(hostStr))
|
||||
}
|
||||
|
||||
writer.Write(cmd.Port.Bytes())
|
||||
writer.Write(cmd.Port.Bytes(nil))
|
||||
|
||||
idBytes := cmd.ID.Bytes()
|
||||
writer.Write(idBytes)
|
||||
|
||||
writer.Write(serial.Uint16ToBytes(cmd.AlterIds))
|
||||
writer.Write(serial.Uint16ToBytes(cmd.AlterIds, nil))
|
||||
writer.Write([]byte{byte(cmd.Level)})
|
||||
|
||||
writer.Write([]byte{cmd.ValidMin})
|
||||
|
||||
Reference in new issue
Block a user