move back to serial

This commit is contained in:
Darien Raymond
2018-11-03 13:03:02 +01:00
parent 128a90b98b
commit 77c03f0da5
12 changed files with 31 additions and 32 deletions
+2 -2
View File
@@ -10,7 +10,7 @@ import (
"v2ray.com/core/common"
"v2ray.com/core/common/buf"
"v2ray.com/core/common/bytespool"
"v2ray.com/core/common/vio"
"v2ray.com/core/common/serial"
)
const (
@@ -70,7 +70,7 @@ func NewChunkReader(reader io.Reader, auth *Authenticator) *ChunkReader {
}
func (v *ChunkReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
size, err := vio.ReadUint16(v.reader)
size, err := serial.ReadUint16(v.reader)
if err != nil {
return nil, newError("failed to read size")
}
+2 -2
View File
@@ -7,7 +7,7 @@ import (
"v2ray.com/core/common/buf"
"v2ray.com/core/common/net"
"v2ray.com/core/common/protocol"
"v2ray.com/core/common/vio"
"v2ray.com/core/common/serial"
)
const (
@@ -260,7 +260,7 @@ func writeSocks4Response(writer io.Writer, errCode byte, address net.Address, po
defer buffer.Release()
common.Must2(buffer.WriteBytes(0x00, errCode))
common.Must2(vio.WriteUint16(buffer, port.Value()))
common.Must2(serial.WriteUint16(buffer, port.Value()))
common.Must2(buffer.Write(address.IP()))
return buf.WriteAllBytes(writer, buffer.Bytes())
}
+6 -6
View File
@@ -16,15 +16,15 @@ import (
"v2ray.com/core/common/crypto"
"v2ray.com/core/common/dice"
"v2ray.com/core/common/protocol"
"v2ray.com/core/common/vio"
"v2ray.com/core/common/serial"
"v2ray.com/core/proxy/vmess"
)
func hashTimestamp(h hash.Hash, t protocol.Timestamp) []byte {
vio.WriteUint64(h, uint64(t))
vio.WriteUint64(h, uint64(t))
vio.WriteUint64(h, uint64(t))
vio.WriteUint64(h, uint64(t))
serial.WriteUint64(h, uint64(t))
serial.WriteUint64(h, uint64(t))
serial.WriteUint64(h, uint64(t))
serial.WriteUint64(h, uint64(t))
return h.Sum(nil)
}
@@ -59,7 +59,7 @@ func (c *ClientSession) EncodeRequestHeader(header *protocol.RequestHeader, writ
timestamp := protocol.NewTimestampGenerator(protocol.NowTime(), 30)()
account := header.User.Account.(*vmess.MemoryAccount)
idHash := c.idHash(account.AnyValidID().Bytes())
common.Must2(vio.WriteUint64(idHash, uint64(timestamp)))
common.Must2(serial.WriteUint64(idHash, uint64(timestamp)))
common.Must2(writer.Write(idHash.Sum(nil)))
buffer := buf.New()
+3 -3
View File
@@ -8,8 +8,8 @@ import (
"v2ray.com/core/common/buf"
"v2ray.com/core/common/net"
"v2ray.com/core/common/protocol"
"v2ray.com/core/common/serial"
"v2ray.com/core/common/uuid"
"v2ray.com/core/common/vio"
)
var (
@@ -96,11 +96,11 @@ func (f *CommandSwitchAccountFactory) Marshal(command interface{}, writer io.Wri
common.Must2(writer.Write([]byte(hostStr)))
}
common.Must2(vio.WriteUint16(writer, cmd.Port.Value()))
common.Must2(serial.WriteUint16(writer, cmd.Port.Value()))
idBytes := cmd.ID.Bytes()
common.Must2(writer.Write(idBytes))
common.Must2(vio.WriteUint16(writer, cmd.AlterIds))
common.Must2(serial.WriteUint16(writer, cmd.AlterIds))
common.Must2(writer.Write([]byte{byte(cmd.Level)}))
common.Must2(writer.Write([]byte{cmd.ValidMin}))
+2 -3
View File
@@ -5,10 +5,9 @@ import (
"sync"
"time"
"v2ray.com/core/common/vio"
"v2ray.com/core/common"
"v2ray.com/core/common/protocol"
"v2ray.com/core/common/serial"
"v2ray.com/core/common/task"
)
@@ -66,7 +65,7 @@ func (v *TimedUserValidator) generateNewHashes(nowSec protocol.Timestamp, user *
genBeginSec = nowSec - cacheDurationSec
}
for ts := genBeginSec; ts <= genEndSec; ts++ {
common.Must2(vio.WriteUint64(idHash, uint64(ts)))
common.Must2(serial.WriteUint64(idHash, uint64(ts)))
idHash.Sum(hashValue[:0])
idHash.Reset()
+3 -3
View File
@@ -6,8 +6,8 @@ import (
"v2ray.com/core/common"
"v2ray.com/core/common/protocol"
"v2ray.com/core/common/serial"
"v2ray.com/core/common/uuid"
"v2ray.com/core/common/vio"
. "v2ray.com/core/proxy/vmess"
. "v2ray.com/ext/assert"
)
@@ -39,7 +39,7 @@ func TestUserValidator(t *testing.T) {
testSmallLag := func(lag time.Duration) {
ts := protocol.Timestamp(time.Now().Add(time.Second * lag).Unix())
idHash := hasher(id.Bytes())
common.Must2(vio.WriteUint64(idHash, uint64(ts)))
common.Must2(serial.WriteUint64(idHash, uint64(ts)))
userHash := idHash.Sum(nil)
euser, ets, found := v.Get(userHash)
@@ -61,7 +61,7 @@ func TestUserValidator(t *testing.T) {
testBigLag := func(lag time.Duration) {
ts := protocol.Timestamp(time.Now().Add(time.Second * lag).Unix())
idHash := hasher(id.Bytes())
common.Must2(vio.WriteUint64(idHash, uint64(ts)))
common.Must2(serial.WriteUint64(idHash, uint64(ts)))
userHash := idHash.Sum(nil)
euser, _, found := v.Get(userHash)