1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 09:36:34 -05:00

Fix test break

This commit is contained in:
V2Ray 2015-09-20 00:11:14 +02:00
parent 075753c030
commit b40be74b86
15 changed files with 50 additions and 48 deletions

View File

@ -6,7 +6,7 @@ import (
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/log" "github.com/v2ray/v2ray-core/log"
"github.com/v2ray/v2ray-core/proxy/vmess/protocol" "github.com/v2ray/v2ray-core/proxy/vmess/protocol/user"
) )
type VMessUser struct { type VMessUser struct {
@ -14,9 +14,9 @@ type VMessUser struct {
Email string `json:"email"` Email string `json:"email"`
} }
func (u *VMessUser) ToUser() (protocol.User, error) { func (u *VMessUser) ToUser() (user.User, error) {
id, err := protocol.NewID(u.Id) id, err := user.NewID(u.Id)
return protocol.User{ return user.User{
Id: id, Id: id,
}, err }, err
} }
@ -38,7 +38,7 @@ type VNextConfig struct {
} }
func (config VNextConfig) ToVNextServer() VNextServer { func (config VNextConfig) ToVNextServer() VNextServer {
users := make([]protocol.User, 0, len(config.Users)) users := make([]user.User, 0, len(config.Users))
for _, user := range config.Users { for _, user := range config.Users {
vuser, err := user.ToUser() vuser, err := user.ToUser()
if err != nil { if err != nil {

View File

@ -1,4 +1,4 @@
package protocol package user
import ( import (
"crypto/md5" "crypto/md5"

View File

@ -1,4 +1,4 @@
package protocol package user
import ( import (
"testing" "testing"

View File

@ -1,4 +1,4 @@
package protocol package user
import ( import (
"crypto/hmac" "crypto/hmac"

View File

@ -1,4 +1,4 @@
package protocol package user
import ( import (
"crypto/md5" "crypto/md5"

View File

@ -1,4 +1,4 @@
package protocol package user
import ( import (
"math/rand" "math/rand"

View File

@ -1,4 +1,4 @@
package protocol package user
import ( import (
"testing" "testing"

View File

@ -1,4 +1,4 @@
package protocol package user
// User is the user account that is used for connection to a Point // User is the user account that is used for connection to a Point
type User struct { type User struct {

View File

@ -1,4 +1,4 @@
package protocol package user
import ( import (
"container/heap" "container/heap"

View File

@ -15,6 +15,7 @@ import (
v2io "github.com/v2ray/v2ray-core/common/io" v2io "github.com/v2ray/v2ray-core/common/io"
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/log" "github.com/v2ray/v2ray-core/log"
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user"
) )
const ( const (
@ -38,7 +39,7 @@ var (
type VMessRequest struct { type VMessRequest struct {
Version byte Version byte
UserId ID UserId user.ID
RequestIV [16]byte RequestIV [16]byte
RequestKey [16]byte RequestKey [16]byte
ResponseHeader [4]byte ResponseHeader [4]byte
@ -47,10 +48,10 @@ type VMessRequest struct {
} }
type VMessRequestReader struct { type VMessRequestReader struct {
vUserSet UserSet vUserSet user.UserSet
} }
func NewVMessRequestReader(vUserSet UserSet) *VMessRequestReader { func NewVMessRequestReader(vUserSet user.UserSet) *VMessRequestReader {
return &VMessRequestReader{ return &VMessRequestReader{
vUserSet: vUserSet, vUserSet: vUserSet,
} }
@ -59,7 +60,7 @@ func NewVMessRequestReader(vUserSet UserSet) *VMessRequestReader {
func (r *VMessRequestReader) Read(reader io.Reader) (*VMessRequest, error) { func (r *VMessRequestReader) Read(reader io.Reader) (*VMessRequest, error) {
buffer := make([]byte, 256) buffer := make([]byte, 256)
nBytes, err := reader.Read(buffer[:IDBytesLen]) nBytes, err := reader.Read(buffer[:user.IDBytesLen])
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -75,7 +76,7 @@ func (r *VMessRequestReader) Read(reader io.Reader) (*VMessRequest, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
aesStream := cipher.NewCFBDecrypter(aesCipher, Int64Hash(timeSec)) aesStream := cipher.NewCFBDecrypter(aesCipher, user.Int64Hash(timeSec))
decryptor := v2io.NewCryptionReader(aesStream, reader) decryptor := v2io.NewCryptionReader(aesStream, reader)
if err != nil { if err != nil {
@ -178,7 +179,7 @@ func (r *VMessRequestReader) Read(reader io.Reader) (*VMessRequest, error) {
return request, nil return request, nil
} }
func (request *VMessRequest) ToBytes(idHash CounterHash, randomRangeInt64 RandomInt64InRange) ([]byte, error) { func (request *VMessRequest) ToBytes(idHash user.CounterHash, randomRangeInt64 user.RandomInt64InRange) ([]byte, error) {
buffer := make([]byte, 0, 300) buffer := make([]byte, 0, 300)
counter := randomRangeInt64(time.Now().UTC().Unix(), 30) counter := randomRangeInt64(time.Now().UTC().Unix(), 30)
@ -235,7 +236,7 @@ func (request *VMessRequest) ToBytes(idHash CounterHash, randomRangeInt64 Random
if err != nil { if err != nil {
return nil, err return nil, err
} }
aesStream := cipher.NewCFBEncrypter(aesCipher, Int64Hash(counter)) aesStream := cipher.NewCFBEncrypter(aesCipher, user.Int64Hash(counter))
aesStream.XORKeyStream(buffer[encryptionBegin:encryptionEnd], buffer[encryptionBegin:encryptionEnd]) aesStream.XORKeyStream(buffer[encryptionBegin:encryptionEnd], buffer[encryptionBegin:encryptionEnd])
return buffer, nil return buffer, nil

View File

@ -5,8 +5,8 @@ import (
"crypto/rand" "crypto/rand"
"testing" "testing"
"github.com/v2ray/v2ray-core"
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user"
"github.com/v2ray/v2ray-core/testing/mocks" "github.com/v2ray/v2ray-core/testing/mocks"
"github.com/v2ray/v2ray-core/testing/unit" "github.com/v2ray/v2ray-core/testing/unit"
) )
@ -14,13 +14,13 @@ import (
func TestVMessSerialization(t *testing.T) { func TestVMessSerialization(t *testing.T) {
assert := unit.Assert(t) assert := unit.Assert(t)
userId, err := core.NewID("2b2966ac-16aa-4fbf-8d81-c5f172a3da51") userId, err := user.NewID("2b2966ac-16aa-4fbf-8d81-c5f172a3da51")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
userSet := mocks.MockUserSet{[]core.ID{}, make(map[string]int), make(map[string]int64)} userSet := mocks.MockUserSet{[]user.ID{}, make(map[string]int), make(map[string]int64)}
userSet.AddUser(core.User{userId}) userSet.AddUser(user.User{userId})
request := new(VMessRequest) request := new(VMessRequest)
request.Version = byte(0x01) request.Version = byte(0x01)
@ -45,7 +45,7 @@ func TestVMessSerialization(t *testing.T) {
request.Address = v2net.DomainAddress("v2ray.com", 80) request.Address = v2net.DomainAddress("v2ray.com", 80)
mockTime := int64(1823730) mockTime := int64(1823730)
buffer, err := request.ToBytes(NewTimeHash(HMACHash{}), func(base int64, delta int) int64 { return mockTime }) buffer, err := request.ToBytes(user.NewTimeHash(user.HMACHash{}), func(base int64, delta int) int64 { return mockTime })
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -69,9 +69,9 @@ func TestVMessSerialization(t *testing.T) {
} }
func BenchmarkVMessRequestWriting(b *testing.B) { func BenchmarkVMessRequestWriting(b *testing.B) {
userId, _ := core.NewID("2b2966ac-16aa-4fbf-8d81-c5f172a3da51") userId, _ := user.NewID("2b2966ac-16aa-4fbf-8d81-c5f172a3da51")
userSet := mocks.MockUserSet{[]core.ID{}, make(map[string]int), make(map[string]int64)} userSet := mocks.MockUserSet{[]user.ID{}, make(map[string]int), make(map[string]int64)}
userSet.AddUser(core.User{userId}) userSet.AddUser(user.User{userId})
request := new(VMessRequest) request := new(VMessRequest)
request.Version = byte(0x01) request.Version = byte(0x01)
@ -85,6 +85,6 @@ func BenchmarkVMessRequestWriting(b *testing.B) {
request.Address = v2net.DomainAddress("v2ray.com", 80) request.Address = v2net.DomainAddress("v2ray.com", 80)
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
request.ToBytes(NewTimeHash(HMACHash{}), GenerateRandomInt64InRange) request.ToBytes(user.NewTimeHash(user.HMACHash{}), user.GenerateRandomInt64InRange)
} }
} }

View File

@ -10,16 +10,17 @@ import (
v2io "github.com/v2ray/v2ray-core/common/io" v2io "github.com/v2ray/v2ray-core/common/io"
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/log" "github.com/v2ray/v2ray-core/log"
protocol "github.com/v2ray/v2ray-core/proxy/vmess/protocol" "github.com/v2ray/v2ray-core/proxy/vmess/protocol"
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user"
) )
type VMessInboundHandler struct { type VMessInboundHandler struct {
vPoint *core.Point vPoint *core.Point
clients protocol.UserSet clients user.UserSet
accepting bool accepting bool
} }
func NewVMessInboundHandler(vp *core.Point, clients protocol.UserSet) *VMessInboundHandler { func NewVMessInboundHandler(vp *core.Point, clients user.UserSet) *VMessInboundHandler {
return &VMessInboundHandler{ return &VMessInboundHandler{
vPoint: vp, vPoint: vp,
clients: clients, clients: clients,
@ -123,7 +124,7 @@ func (factory *VMessInboundHandlerFactory) Create(vp *core.Point, rawConfig []by
if err != nil { if err != nil {
panic(log.Error("VMessIn: Failed to load VMess inbound config: %v", err)) panic(log.Error("VMessIn: Failed to load VMess inbound config: %v", err))
} }
allowedClients := protocol.NewTimedUserSet() allowedClients := user.NewTimedUserSet()
for _, client := range config.AllowedClients { for _, client := range config.AllowedClients {
user, err := client.ToUser() user, err := client.ToUser()
if err != nil { if err != nil {

View File

@ -11,13 +11,14 @@ import (
v2io "github.com/v2ray/v2ray-core/common/io" v2io "github.com/v2ray/v2ray-core/common/io"
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/log" "github.com/v2ray/v2ray-core/log"
protocol "github.com/v2ray/v2ray-core/proxy/vmess/protocol" "github.com/v2ray/v2ray-core/proxy/vmess/protocol"
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user"
) )
// VNext is the next Point server in the connection chain. // VNext is the next Point server in the connection chain.
type VNextServer struct { type VNextServer struct {
Address v2net.Address // Address of VNext server Address v2net.Address // Address of VNext server
Users []protocol.User // User accounts for accessing VNext. Users []user.User // User accounts for accessing VNext.
} }
type VMessOutboundHandler struct { type VMessOutboundHandler struct {
@ -34,7 +35,7 @@ func NewVMessOutboundHandler(vp *core.Point, vNextList []VNextServer, dest v2net
} }
} }
func (handler *VMessOutboundHandler) pickVNext() (v2net.Address, protocol.User) { func (handler *VMessOutboundHandler) pickVNext() (v2net.Address, user.User) {
vNextLen := len(handler.vNextList) vNextLen := len(handler.vNextList)
if vNextLen == 0 { if vNextLen == 0 {
panic("VMessOut: Zero vNext is configured.") panic("VMessOut: Zero vNext is configured.")
@ -101,7 +102,7 @@ func handleRequest(conn *net.TCPConn, request *protocol.VMessRequest, input <-ch
return return
} }
buffer, err := request.ToBytes(protocol.NewTimeHash(protocol.HMACHash{}), protocol.GenerateRandomInt64InRange) buffer, err := request.ToBytes(user.NewTimeHash(user.HMACHash{}), user.GenerateRandomInt64InRange)
if err != nil { if err != nil {
log.Error("VMessOut: Failed to serialize VMess request: %v", err) log.Error("VMessOut: Failed to serialize VMess request: %v", err)
return return

View File

@ -19,13 +19,12 @@ function test_package {
echo "mode: set" > coverall.out echo "mode: set" > coverall.out
test_package "." "." test_package "common/net" "common/net"
test_package "io/socks" "io/socks" test_package "proxy/socks" "proxy/socks,proxy/socks/protocol"
test_package "io/vmess" "hash,io,io/vmess" test_package "proxy/socks/protocol" "proxy/socks/protocol"
test_package "math" "math" test_package "proxy/vmess" "common/io,common/net,proxy/vmess,proxy/vmess/protocol,proxy/vmess/protocol/user"
test_package "net" "net" test_package "proxy/vmess/protocol" "proxy/vmess/protocol,proxy/vmess/protocol/user"
test_package "net/socks" ".,io/socks,net,net/socks" test_package "proxy/vmess/protocol/user" "proxy/vmess/protocol/user"
test_package "net/vmess" ".,io,math,net,net/vmess"
if [ "$FAIL" -eq 0 ]; then if [ "$FAIL" -eq 0 ]; then
$HOME/gopath/bin/goveralls -v -coverprofile=coverall.out -service=travis-ci -repotoken $COVERALLS_TOKEN $HOME/gopath/bin/goveralls -v -coverprofile=coverall.out -service=travis-ci -repotoken $COVERALLS_TOKEN

View File

@ -1,21 +1,21 @@
package mocks package mocks
import ( import (
"github.com/v2ray/v2ray-core/proxy/vmess/protocol" "github.com/v2ray/v2ray-core/proxy/vmess/protocol/user"
) )
type MockUserSet struct { type MockUserSet struct {
UserIds []protocol.ID UserIds []user.ID
UserHashes map[string]int UserHashes map[string]int
Timestamps map[string]int64 Timestamps map[string]int64
} }
func (us *MockUserSet) AddUser(user protocol.User) error { func (us *MockUserSet) AddUser(user user.User) error {
us.UserIds = append(us.UserIds, user.Id) us.UserIds = append(us.UserIds, user.Id)
return nil return nil
} }
func (us *MockUserSet) GetUser(userhash []byte) (*protocol.ID, int64, bool) { func (us *MockUserSet) GetUser(userhash []byte) (*user.ID, int64, bool) {
idx, found := us.UserHashes[string(userhash)] idx, found := us.UserHashes[string(userhash)]
if found { if found {
return &us.UserIds[idx], us.Timestamps[string(userhash)], true return &us.UserIds[idx], us.Timestamps[string(userhash)], true