remove proxy/vmess/protocol/user

pull/69/head
Darien Raymond 2016-01-12 10:52:40 +00:00
parent dc1fbecdfb
commit bed5235772
10 changed files with 29 additions and 34 deletions

View File

@ -16,19 +16,18 @@ import (
"github.com/v2ray/v2ray-core/proxy/internal"
"github.com/v2ray/v2ray-core/proxy/vmess"
"github.com/v2ray/v2ray-core/proxy/vmess/protocol"
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user"
)
// Inbound connection handler that handles messages in VMess format.
type VMessInboundHandler struct {
sync.Mutex
space app.Space
clients user.UserSet
clients protocol.UserSet
accepting bool
listener *net.TCPListener
}
func NewVMessInboundHandler(space app.Space, clients user.UserSet) *VMessInboundHandler {
func NewVMessInboundHandler(space app.Space, clients protocol.UserSet) *VMessInboundHandler {
return &VMessInboundHandler{
space: space,
clients: clients,
@ -170,7 +169,7 @@ func init() {
func(space app.Space, rawConfig interface{}) (proxy.InboundConnectionHandler, error) {
config := rawConfig.(Config)
allowedClients := user.NewTimedUserSet()
allowedClients := protocol.NewTimedUserSet()
for _, user := range config.AllowedUsers() {
allowedClients.AddUser(user)
}

View File

@ -15,7 +15,6 @@ import (
"github.com/v2ray/v2ray-core/proxy"
"github.com/v2ray/v2ray-core/proxy/internal"
"github.com/v2ray/v2ray-core/proxy/vmess/protocol"
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user"
"github.com/v2ray/v2ray-core/transport/ray"
)
@ -105,7 +104,7 @@ func handleRequest(conn net.Conn, request *protocol.VMessRequest, firstPacket v2
buffer := alloc.NewBuffer().Clear()
defer buffer.Release()
buffer, err = request.ToBytes(user.NewRandomTimestampGenerator(user.Timestamp(time.Now().Unix()), 30), buffer)
buffer, err = request.ToBytes(protocol.NewRandomTimestampGenerator(protocol.Timestamp(time.Now().Unix()), 30), buffer)
if err != nil {
log.Error("VMessOut: Failed to serialize VMess request: %v", err)
return

View File

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

View File

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

View File

@ -1,9 +1,10 @@
package user
package protocol_test
import (
"testing"
"time"
. "github.com/v2ray/v2ray-core/proxy/vmess/protocol"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert"
)
@ -13,10 +14,7 @@ func TestGenerateRandomInt64InRange(t *testing.T) {
base := time.Now().Unix()
delta := 100
generator := &RealRandomTimestampGenerator{
base: Timestamp(base),
delta: delta,
}
generator := NewRandomTimestampGenerator(Timestamp(base), delta)
for i := 0; i < 100; i++ {
v := int64(generator.Next())

View File

@ -2,13 +2,13 @@ package mocks
import (
"github.com/v2ray/v2ray-core/proxy/vmess"
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user"
"github.com/v2ray/v2ray-core/proxy/vmess/protocol"
)
type MockUserSet struct {
Users []vmess.User
UserHashes map[string]int
Timestamps map[string]user.Timestamp
Timestamps map[string]protocol.Timestamp
}
func (us *MockUserSet) AddUser(user vmess.User) error {
@ -16,7 +16,7 @@ func (us *MockUserSet) AddUser(user vmess.User) error {
return nil
}
func (us *MockUserSet) GetUser(userhash []byte) (vmess.User, user.Timestamp, bool) {
func (us *MockUserSet) GetUser(userhash []byte) (vmess.User, protocol.Timestamp, bool) {
idx, found := us.UserHashes[string(userhash)]
if found {
return us.Users[idx], us.Timestamps[string(userhash)], true

View File

@ -3,7 +3,7 @@ package mocks
import (
"github.com/v2ray/v2ray-core/common/uuid"
"github.com/v2ray/v2ray-core/proxy/vmess"
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user"
"github.com/v2ray/v2ray-core/proxy/vmess/protocol"
)
type StaticUser struct {
@ -33,7 +33,7 @@ func (us *StaticUserSet) AddUser(user vmess.User) error {
return nil
}
func (us *StaticUserSet) GetUser(userhash []byte) (vmess.User, user.Timestamp, bool) {
func (us *StaticUserSet) GetUser(userhash []byte) (vmess.User, protocol.Timestamp, bool) {
id, _ := uuid.ParseString("703e9102-eb57-499c-8b59-faf4f371bb21")
return &StaticUser{id: vmess.NewID(id)}, 0, true
}

View File

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

View File

@ -13,7 +13,6 @@ import (
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/proxy"
"github.com/v2ray/v2ray-core/proxy/vmess"
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user"
"github.com/v2ray/v2ray-core/transport"
)
@ -55,11 +54,11 @@ func (this *VMessRequest) Destination() v2net.Destination {
// VMessRequestReader is a parser to read VMessRequest from a byte stream.
type VMessRequestReader struct {
vUserSet user.UserSet
vUserSet UserSet
}
// NewVMessRequestReader creates a new VMessRequestReader with a given UserSet
func NewVMessRequestReader(vUserSet user.UserSet) *VMessRequestReader {
func NewVMessRequestReader(vUserSet UserSet) *VMessRequestReader {
return &VMessRequestReader{
vUserSet: vUserSet,
}
@ -81,7 +80,7 @@ func (this *VMessRequestReader) Read(reader io.Reader) (*VMessRequest, error) {
return nil, proxy.InvalidAuthentication
}
timestampHash := user.TimestampHash()
timestampHash := TimestampHash()
timestampHash.Write(timeSec.HashBytes())
iv := timestampHash.Sum(nil)
aesStream, err := v2crypto.NewAesDecryptionStream(userObj.ID().CmdKey(), iv)
@ -172,13 +171,13 @@ func (this *VMessRequestReader) Read(reader io.Reader) (*VMessRequest, error) {
}
// ToBytes returns a VMessRequest in the form of byte array.
func (this *VMessRequest) ToBytes(timestampGenerator user.RandomTimestampGenerator, buffer *alloc.Buffer) (*alloc.Buffer, error) {
func (this *VMessRequest) ToBytes(timestampGenerator RandomTimestampGenerator, buffer *alloc.Buffer) (*alloc.Buffer, error) {
if buffer == nil {
buffer = alloc.NewSmallBuffer().Clear()
}
timestamp := timestampGenerator.Next()
idHash := user.IDHash(this.User.AnyValidID().Bytes())
idHash := IDHash(this.User.AnyValidID().Bytes())
idHash.Write(timestamp.Bytes())
buffer.Append(idHash.Sum(nil))

View File

@ -1,4 +1,4 @@
package protocol
package protocol_test
import (
"bytes"
@ -10,17 +10,17 @@ import (
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/common/uuid"
"github.com/v2ray/v2ray-core/proxy/vmess"
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user"
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user/testing/mocks"
. "github.com/v2ray/v2ray-core/proxy/vmess/protocol"
protocoltesting "github.com/v2ray/v2ray-core/proxy/vmess/protocol/testing"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert"
)
type FakeTimestampGenerator struct {
timestamp user.Timestamp
timestamp Timestamp
}
func (this *FakeTimestampGenerator) Next() user.Timestamp {
func (this *FakeTimestampGenerator) Next() Timestamp {
return this.timestamp
}
@ -57,7 +57,7 @@ func TestVMessSerialization(t *testing.T) {
id: userId,
}
userSet := mocks.MockUserSet{[]vmess.User{}, make(map[string]int), make(map[string]user.Timestamp)}
userSet := protocoltesting.MockUserSet{[]vmess.User{}, make(map[string]int), make(map[string]Timestamp)}
userSet.AddUser(testUser)
request := new(VMessRequest)
@ -75,7 +75,7 @@ func TestVMessSerialization(t *testing.T) {
request.Address = v2net.DomainAddress("v2ray.com")
request.Port = v2net.Port(80)
mockTime := user.Timestamp(1823730)
mockTime := Timestamp(1823730)
buffer, err := request.ToBytes(&FakeTimestampGenerator{timestamp: mockTime}, nil)
if err != nil {
@ -113,7 +113,7 @@ func BenchmarkVMessRequestWriting(b *testing.B) {
assert.Error(err).IsNil()
userId := vmess.NewID(id)
userSet := mocks.MockUserSet{[]vmess.User{}, make(map[string]int), make(map[string]user.Timestamp)}
userSet := protocoltesting.MockUserSet{[]vmess.User{}, make(map[string]int), make(map[string]Timestamp)}
testUser := &TestUser{
id: userId,
@ -135,6 +135,6 @@ func BenchmarkVMessRequestWriting(b *testing.B) {
request.Port = v2net.Port(80)
for i := 0; i < b.N; i++ {
request.ToBytes(user.NewRandomTimestampGenerator(user.Timestamp(time.Now().Unix()), 30), nil)
request.ToBytes(NewRandomTimestampGenerator(Timestamp(time.Now().Unix()), 30), nil)
}
}