mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-17 14:57:44 -05:00
re-org vmess content
This commit is contained in:
parent
0a4d9fb037
commit
af8412175e
@ -1,5 +0,0 @@
|
|||||||
package config
|
|
||||||
|
|
||||||
type Inbound interface {
|
|
||||||
AllowedUsers() []User
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
package config
|
|
||||||
|
|
||||||
import (
|
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Receiver struct {
|
|
||||||
Address v2net.Address
|
|
||||||
Accounts []User
|
|
||||||
}
|
|
||||||
|
|
||||||
type Outbound interface {
|
|
||||||
Receivers() []*Receiver
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
package config
|
package vmess
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
@ -1,4 +1,4 @@
|
|||||||
package config
|
package vmess
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
9
proxy/vmess/inbound/config.go
Normal file
9
proxy/vmess/inbound/config.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package inbound
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/v2ray/v2ray-core/proxy/vmess"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Config interface {
|
||||||
|
AllowedUsers() []vmess.User
|
||||||
|
}
|
@ -13,7 +13,7 @@ import (
|
|||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
"github.com/v2ray/v2ray-core/common/retry"
|
"github.com/v2ray/v2ray-core/common/retry"
|
||||||
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
||||||
"github.com/v2ray/v2ray-core/proxy/vmess/config"
|
"github.com/v2ray/v2ray-core/proxy/vmess"
|
||||||
"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"
|
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user"
|
||||||
)
|
)
|
||||||
@ -85,7 +85,7 @@ func (this *VMessInboundHandler) HandleConnection(connection *net.TCPConn) error
|
|||||||
readFinish.Lock()
|
readFinish.Lock()
|
||||||
writeFinish.Lock()
|
writeFinish.Lock()
|
||||||
|
|
||||||
userSettings := config.GetUserSettings(request.User.Level())
|
userSettings := vmess.GetUserSettings(request.User.Level())
|
||||||
connReader.SetTimeOut(userSettings.PayloadReadTimeout)
|
connReader.SetTimeOut(userSettings.PayloadReadTimeout)
|
||||||
go handleInput(request, connReader, input, &readFinish)
|
go handleInput(request, connReader, input, &readFinish)
|
||||||
|
|
||||||
@ -143,7 +143,7 @@ type VMessInboundHandlerFactory struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *VMessInboundHandlerFactory) Create(space *app.Space, rawConfig interface{}) (connhandler.InboundConnectionHandler, error) {
|
func (this *VMessInboundHandlerFactory) Create(space *app.Space, rawConfig interface{}) (connhandler.InboundConnectionHandler, error) {
|
||||||
config := rawConfig.(config.Inbound)
|
config := rawConfig.(Config)
|
||||||
|
|
||||||
allowedClients := user.NewTimedUserSet()
|
allowedClients := user.NewTimedUserSet()
|
||||||
for _, user := range config.AllowedUsers() {
|
for _, user := range config.AllowedUsers() {
|
||||||
|
@ -2,15 +2,16 @@ package json
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/v2ray/v2ray-core/proxy/common/config/json"
|
"github.com/v2ray/v2ray-core/proxy/common/config/json"
|
||||||
vmessconfig "github.com/v2ray/v2ray-core/proxy/vmess/config"
|
"github.com/v2ray/v2ray-core/proxy/vmess"
|
||||||
|
vmessjson "github.com/v2ray/v2ray-core/proxy/vmess/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Inbound struct {
|
type Inbound struct {
|
||||||
AllowedClients []*ConfigUser `json:"clients"`
|
AllowedClients []*vmessjson.ConfigUser `json:"clients"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Inbound) AllowedUsers() []vmessconfig.User {
|
func (c *Inbound) AllowedUsers() []vmess.User {
|
||||||
users := make([]vmessconfig.User, 0, len(c.AllowedClients))
|
users := make([]vmess.User, 0, len(c.AllowedClients))
|
||||||
for _, rawUser := range c.AllowedClients {
|
for _, rawUser := range c.AllowedClients {
|
||||||
users = append(users, rawUser)
|
users = append(users, rawUser)
|
||||||
}
|
}
|
@ -3,14 +3,14 @@ package json
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/v2ray/v2ray-core/proxy/vmess/config"
|
"github.com/v2ray/v2ray-core/proxy/vmess"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ConfigUser is an user account in VMess configuration.
|
// ConfigUser is an user account in VMess configuration.
|
||||||
type ConfigUser struct {
|
type ConfigUser struct {
|
||||||
Id *config.ID
|
Id *vmess.ID
|
||||||
Email string
|
Email string
|
||||||
LevelValue config.UserLevel
|
LevelValue vmess.UserLevel
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *ConfigUser) UnmarshalJSON(data []byte) error {
|
func (u *ConfigUser) UnmarshalJSON(data []byte) error {
|
||||||
@ -23,20 +23,20 @@ func (u *ConfigUser) UnmarshalJSON(data []byte) error {
|
|||||||
if err := json.Unmarshal(data, &rawUserValue); err != nil {
|
if err := json.Unmarshal(data, &rawUserValue); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
id, err := config.NewID(rawUserValue.IdString)
|
id, err := vmess.NewID(rawUserValue.IdString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
u.Id = id
|
u.Id = id
|
||||||
u.Email = rawUserValue.EmailString
|
u.Email = rawUserValue.EmailString
|
||||||
u.LevelValue = config.UserLevel(rawUserValue.LevelInt)
|
u.LevelValue = vmess.UserLevel(rawUserValue.LevelInt)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *ConfigUser) ID() *config.ID {
|
func (u *ConfigUser) ID() *vmess.ID {
|
||||||
return u.Id
|
return u.Id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ConfigUser) Level() config.UserLevel {
|
func (this *ConfigUser) Level() vmess.UserLevel {
|
||||||
return this.LevelValue
|
return this.LevelValue
|
||||||
}
|
}
|
5
proxy/vmess/outbound/config.go
Normal file
5
proxy/vmess/outbound/config.go
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package outbound
|
||||||
|
|
||||||
|
type Config interface {
|
||||||
|
Receivers() []*Receiver
|
||||||
|
}
|
@ -8,19 +8,21 @@ import (
|
|||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
proxyconfig "github.com/v2ray/v2ray-core/proxy/common/config"
|
proxyconfig "github.com/v2ray/v2ray-core/proxy/common/config"
|
||||||
jsonconfig "github.com/v2ray/v2ray-core/proxy/common/config/json"
|
jsonconfig "github.com/v2ray/v2ray-core/proxy/common/config/json"
|
||||||
vmessconfig "github.com/v2ray/v2ray-core/proxy/vmess/config"
|
"github.com/v2ray/v2ray-core/proxy/vmess"
|
||||||
|
vmessjson "github.com/v2ray/v2ray-core/proxy/vmess/json"
|
||||||
|
"github.com/v2ray/v2ray-core/proxy/vmess/outbound"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ConfigTarget struct {
|
type ConfigTarget struct {
|
||||||
Address v2net.Address
|
Address v2net.Address
|
||||||
Users []*ConfigUser
|
Users []*vmessjson.ConfigUser
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ConfigTarget) UnmarshalJSON(data []byte) error {
|
func (t *ConfigTarget) UnmarshalJSON(data []byte) error {
|
||||||
type RawConfigTarget struct {
|
type RawConfigTarget struct {
|
||||||
Address string `json:"address"`
|
Address string `json:"address"`
|
||||||
Port v2net.Port `json:"port"`
|
Port v2net.Port `json:"port"`
|
||||||
Users []*ConfigUser `json:"users"`
|
Users []*vmessjson.ConfigUser `json:"users"`
|
||||||
}
|
}
|
||||||
var rawConfig RawConfigTarget
|
var rawConfig RawConfigTarget
|
||||||
if err := json.Unmarshal(data, &rawConfig); err != nil {
|
if err := json.Unmarshal(data, &rawConfig); err != nil {
|
||||||
@ -61,14 +63,14 @@ func (this *Outbound) UnmarshalJSON(data []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Outbound) Receivers() []*vmessconfig.Receiver {
|
func (o *Outbound) Receivers() []*outbound.Receiver {
|
||||||
targets := make([]*vmessconfig.Receiver, 0, 2*len(o.TargetList))
|
targets := make([]*outbound.Receiver, 0, 2*len(o.TargetList))
|
||||||
for _, rawTarget := range o.TargetList {
|
for _, rawTarget := range o.TargetList {
|
||||||
users := make([]vmessconfig.User, 0, len(rawTarget.Users))
|
users := make([]vmess.User, 0, len(rawTarget.Users))
|
||||||
for _, rawUser := range rawTarget.Users {
|
for _, rawUser := range rawTarget.Users {
|
||||||
users = append(users, rawUser)
|
users = append(users, rawUser)
|
||||||
}
|
}
|
||||||
targets = append(targets, &vmessconfig.Receiver{
|
targets = append(targets, &outbound.Receiver{
|
||||||
Address: rawTarget.Address,
|
Address: rawTarget.Address,
|
||||||
Accounts: users,
|
Accounts: users,
|
||||||
})
|
})
|
@ -4,7 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
jsonconfig "github.com/v2ray/v2ray-core/proxy/vmess/config/json"
|
jsonconfig "github.com/v2ray/v2ray-core/proxy/vmess/outbound/json"
|
||||||
v2testing "github.com/v2ray/v2ray-core/testing"
|
v2testing "github.com/v2ray/v2ray-core/testing"
|
||||||
"github.com/v2ray/v2ray-core/testing/assert"
|
"github.com/v2ray/v2ray-core/testing/assert"
|
||||||
)
|
)
|
@ -12,7 +12,6 @@ import (
|
|||||||
"github.com/v2ray/v2ray-core/common/log"
|
"github.com/v2ray/v2ray-core/common/log"
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
||||||
"github.com/v2ray/v2ray-core/proxy/vmess/config"
|
|
||||||
"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"
|
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user"
|
||||||
"github.com/v2ray/v2ray-core/transport/ray"
|
"github.com/v2ray/v2ray-core/transport/ray"
|
||||||
@ -177,7 +176,7 @@ type VMessOutboundHandlerFactory struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *VMessOutboundHandlerFactory) Create(space *app.Space, rawConfig interface{}) (connhandler.OutboundConnectionHandler, error) {
|
func (this *VMessOutboundHandlerFactory) Create(space *app.Space, rawConfig interface{}) (connhandler.OutboundConnectionHandler, error) {
|
||||||
vOutConfig := rawConfig.(config.Outbound)
|
vOutConfig := rawConfig.(Config)
|
||||||
return &VMessOutboundHandler{
|
return &VMessOutboundHandler{
|
||||||
space: space,
|
space: space,
|
||||||
receiverManager: NewReceiverManager(vOutConfig.Receivers()),
|
receiverManager: NewReceiverManager(vOutConfig.Receivers()),
|
||||||
|
@ -4,20 +4,25 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
|
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
"github.com/v2ray/v2ray-core/proxy/vmess/config"
|
"github.com/v2ray/v2ray-core/proxy/vmess"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ReceiverManager struct {
|
type Receiver struct {
|
||||||
receivers []*config.Receiver
|
Address v2net.Address
|
||||||
|
Accounts []vmess.User
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewReceiverManager(receivers []*config.Receiver) *ReceiverManager {
|
type ReceiverManager struct {
|
||||||
|
receivers []*Receiver
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewReceiverManager(receivers []*Receiver) *ReceiverManager {
|
||||||
return &ReceiverManager{
|
return &ReceiverManager{
|
||||||
receivers: receivers,
|
receivers: receivers,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ReceiverManager) PickReceiver() (v2net.Address, config.User) {
|
func (this *ReceiverManager) PickReceiver() (v2net.Address, vmess.User) {
|
||||||
receiverLen := len(this.receivers)
|
receiverLen := len(this.receivers)
|
||||||
receiverIdx := 0
|
receiverIdx := 0
|
||||||
if receiverLen > 1 {
|
if receiverLen > 1 {
|
@ -1,21 +1,21 @@
|
|||||||
package mocks
|
package mocks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/v2ray/v2ray-core/proxy/vmess/config"
|
"github.com/v2ray/v2ray-core/proxy/vmess"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MockUserSet struct {
|
type MockUserSet struct {
|
||||||
Users []config.User
|
Users []vmess.User
|
||||||
UserHashes map[string]int
|
UserHashes map[string]int
|
||||||
Timestamps map[string]int64
|
Timestamps map[string]int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us *MockUserSet) AddUser(user config.User) error {
|
func (us *MockUserSet) AddUser(user vmess.User) error {
|
||||||
us.Users = append(us.Users, user)
|
us.Users = append(us.Users, user)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us *MockUserSet) GetUser(userhash []byte) (config.User, int64, bool) {
|
func (us *MockUserSet) GetUser(userhash []byte) (vmess.User, int64, bool) {
|
||||||
idx, found := us.UserHashes[string(userhash)]
|
idx, found := us.UserHashes[string(userhash)]
|
||||||
if found {
|
if found {
|
||||||
return us.Users[idx], us.Timestamps[string(userhash)], true
|
return us.Users[idx], us.Timestamps[string(userhash)], true
|
||||||
|
@ -1,29 +1,29 @@
|
|||||||
package mocks
|
package mocks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/v2ray/v2ray-core/proxy/vmess/config"
|
"github.com/v2ray/v2ray-core/proxy/vmess"
|
||||||
)
|
)
|
||||||
|
|
||||||
type StaticUser struct {
|
type StaticUser struct {
|
||||||
id *config.ID
|
id *vmess.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *StaticUser) ID() *config.ID {
|
func (this *StaticUser) ID() *vmess.ID {
|
||||||
return this.id
|
return this.id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *StaticUser) Level() config.UserLevel {
|
func (this *StaticUser) Level() vmess.UserLevel {
|
||||||
return config.UserLevelUntrusted
|
return vmess.UserLevelUntrusted
|
||||||
}
|
}
|
||||||
|
|
||||||
type StaticUserSet struct {
|
type StaticUserSet struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us *StaticUserSet) AddUser(user config.User) error {
|
func (us *StaticUserSet) AddUser(user vmess.User) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us *StaticUserSet) GetUser(userhash []byte) (config.User, int64, bool) {
|
func (us *StaticUserSet) GetUser(userhash []byte) (vmess.User, int64, bool) {
|
||||||
id, _ := config.NewID("703e9102-eb57-499c-8b59-faf4f371bb21")
|
id, _ := vmess.NewID("703e9102-eb57-499c-8b59-faf4f371bb21")
|
||||||
return &StaticUser{id: id}, 0, true
|
return &StaticUser{id: id}, 0, true
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/v2ray/v2ray-core/common/collect"
|
"github.com/v2ray/v2ray-core/common/collect"
|
||||||
"github.com/v2ray/v2ray-core/proxy/vmess/config"
|
"github.com/v2ray/v2ray-core/proxy/vmess"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -14,12 +14,12 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type UserSet interface {
|
type UserSet interface {
|
||||||
AddUser(user config.User) error
|
AddUser(user vmess.User) error
|
||||||
GetUser(timeHash []byte) (config.User, int64, bool)
|
GetUser(timeHash []byte) (vmess.User, int64, bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
type TimedUserSet struct {
|
type TimedUserSet struct {
|
||||||
validUsers []config.User
|
validUsers []vmess.User
|
||||||
userHash map[string]indexTimePair
|
userHash map[string]indexTimePair
|
||||||
userHashDeleteQueue *collect.TimedQueue
|
userHashDeleteQueue *collect.TimedQueue
|
||||||
access sync.RWMutex
|
access sync.RWMutex
|
||||||
@ -32,7 +32,7 @@ type indexTimePair struct {
|
|||||||
|
|
||||||
func NewTimedUserSet() UserSet {
|
func NewTimedUserSet() UserSet {
|
||||||
tus := &TimedUserSet{
|
tus := &TimedUserSet{
|
||||||
validUsers: make([]config.User, 0, 16),
|
validUsers: make([]vmess.User, 0, 16),
|
||||||
userHash: make(map[string]indexTimePair, 512),
|
userHash: make(map[string]indexTimePair, 512),
|
||||||
userHashDeleteQueue: collect.NewTimedQueue(updateIntervalSec),
|
userHashDeleteQueue: collect.NewTimedQueue(updateIntervalSec),
|
||||||
access: sync.RWMutex{},
|
access: sync.RWMutex{},
|
||||||
@ -50,7 +50,7 @@ func (us *TimedUserSet) removeEntries(entries <-chan interface{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us *TimedUserSet) generateNewHashes(lastSec, nowSec int64, idx int, id *config.ID) {
|
func (us *TimedUserSet) generateNewHashes(lastSec, nowSec int64, idx int, id *vmess.ID) {
|
||||||
idHash := NewTimeHash(HMACHash{})
|
idHash := NewTimeHash(HMACHash{})
|
||||||
for lastSec < nowSec {
|
for lastSec < nowSec {
|
||||||
idHash := idHash.Hash(id.Bytes[:], lastSec)
|
idHash := idHash.Hash(id.Bytes[:], lastSec)
|
||||||
@ -74,7 +74,7 @@ func (us *TimedUserSet) updateUserHash(tick <-chan time.Time) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us *TimedUserSet) AddUser(user config.User) error {
|
func (us *TimedUserSet) AddUser(user vmess.User) error {
|
||||||
id := user.ID()
|
id := user.ID()
|
||||||
idx := len(us.validUsers)
|
idx := len(us.validUsers)
|
||||||
us.validUsers = append(us.validUsers, user)
|
us.validUsers = append(us.validUsers, user)
|
||||||
@ -86,7 +86,7 @@ func (us *TimedUserSet) AddUser(user config.User) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us *TimedUserSet) GetUser(userHash []byte) (config.User, int64, bool) {
|
func (us *TimedUserSet) GetUser(userHash []byte) (vmess.User, int64, bool) {
|
||||||
defer us.access.RUnlock()
|
defer us.access.RUnlock()
|
||||||
us.access.RLock()
|
us.access.RLock()
|
||||||
pair, found := us.userHash[string(userHash)]
|
pair, found := us.userHash[string(userHash)]
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
"github.com/v2ray/v2ray-core/common/log"
|
"github.com/v2ray/v2ray-core/common/log"
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
proxyerrors "github.com/v2ray/v2ray-core/proxy/common/errors"
|
proxyerrors "github.com/v2ray/v2ray-core/proxy/common/errors"
|
||||||
"github.com/v2ray/v2ray-core/proxy/vmess/config"
|
"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"
|
||||||
"github.com/v2ray/v2ray-core/transport"
|
"github.com/v2ray/v2ray-core/transport"
|
||||||
)
|
)
|
||||||
@ -35,7 +35,7 @@ const (
|
|||||||
// streaming.
|
// streaming.
|
||||||
type VMessRequest struct {
|
type VMessRequest struct {
|
||||||
Version byte
|
Version byte
|
||||||
User config.User
|
User vmess.User
|
||||||
RequestIV []byte
|
RequestIV []byte
|
||||||
RequestKey []byte
|
RequestKey []byte
|
||||||
ResponseHeader []byte
|
ResponseHeader []byte
|
||||||
@ -68,7 +68,7 @@ func NewVMessRequestReader(vUserSet user.UserSet) *VMessRequestReader {
|
|||||||
func (this *VMessRequestReader) Read(reader io.Reader) (*VMessRequest, error) {
|
func (this *VMessRequestReader) Read(reader io.Reader) (*VMessRequest, error) {
|
||||||
buffer := alloc.NewSmallBuffer()
|
buffer := alloc.NewSmallBuffer()
|
||||||
|
|
||||||
nBytes, err := v2net.ReadAllBytes(reader, buffer.Value[:config.IDBytesLen])
|
nBytes, err := v2net.ReadAllBytes(reader, buffer.Value[:vmess.IDBytesLen])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
"github.com/v2ray/v2ray-core/proxy/vmess/config"
|
"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"
|
||||||
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user/testing/mocks"
|
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user/testing/mocks"
|
||||||
v2testing "github.com/v2ray/v2ray-core/testing"
|
v2testing "github.com/v2ray/v2ray-core/testing"
|
||||||
@ -15,22 +15,22 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type TestUser struct {
|
type TestUser struct {
|
||||||
id *config.ID
|
id *vmess.ID
|
||||||
level config.UserLevel
|
level vmess.UserLevel
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *TestUser) ID() *config.ID {
|
func (u *TestUser) ID() *vmess.ID {
|
||||||
return u.id
|
return u.id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *TestUser) Level() config.UserLevel {
|
func (this *TestUser) Level() vmess.UserLevel {
|
||||||
return this.level
|
return this.level
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestVMessSerialization(t *testing.T) {
|
func TestVMessSerialization(t *testing.T) {
|
||||||
v2testing.Current(t)
|
v2testing.Current(t)
|
||||||
|
|
||||||
userId, err := config.NewID("2b2966ac-16aa-4fbf-8d81-c5f172a3da51")
|
userId, err := vmess.NewID("2b2966ac-16aa-4fbf-8d81-c5f172a3da51")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -39,7 +39,7 @@ func TestVMessSerialization(t *testing.T) {
|
|||||||
id: userId,
|
id: userId,
|
||||||
}
|
}
|
||||||
|
|
||||||
userSet := mocks.MockUserSet{[]config.User{}, make(map[string]int), make(map[string]int64)}
|
userSet := mocks.MockUserSet{[]vmess.User{}, make(map[string]int), make(map[string]int64)}
|
||||||
userSet.AddUser(testUser)
|
userSet.AddUser(testUser)
|
||||||
|
|
||||||
request := new(VMessRequest)
|
request := new(VMessRequest)
|
||||||
@ -90,8 +90,8 @@ func TestReadSingleByte(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkVMessRequestWriting(b *testing.B) {
|
func BenchmarkVMessRequestWriting(b *testing.B) {
|
||||||
userId, _ := config.NewID("2b2966ac-16aa-4fbf-8d81-c5f172a3da51")
|
userId, _ := vmess.NewID("2b2966ac-16aa-4fbf-8d81-c5f172a3da51")
|
||||||
userSet := mocks.MockUserSet{[]config.User{}, make(map[string]int), make(map[string]int64)}
|
userSet := mocks.MockUserSet{[]vmess.User{}, make(map[string]int), make(map[string]int64)}
|
||||||
|
|
||||||
testUser := &TestUser{
|
testUser := &TestUser{
|
||||||
id: userId,
|
id: userId,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package config
|
package vmess
|
||||||
|
|
||||||
type UserLevel int
|
type UserLevel int
|
||||||
|
|
@ -4,9 +4,3 @@
|
|||||||
// together with 'freedom' to talk to final destination, while VMess outbound is usually used on
|
// together with 'freedom' to talk to final destination, while VMess outbound is usually used on
|
||||||
// clients with 'socks' for proxying.
|
// clients with 'socks' for proxying.
|
||||||
package vmess
|
package vmess
|
||||||
|
|
||||||
// The actual implementation is in the following packages respectively.
|
|
||||||
import (
|
|
||||||
_ "github.com/v2ray/v2ray-core/proxy/vmess/inbound"
|
|
||||||
_ "github.com/v2ray/v2ray-core/proxy/vmess/outbound"
|
|
||||||
)
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package vmess
|
package vmess_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@ -8,8 +8,12 @@ import (
|
|||||||
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
|
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
|
||||||
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
||||||
proxymocks "github.com/v2ray/v2ray-core/proxy/testing/mocks"
|
proxymocks "github.com/v2ray/v2ray-core/proxy/testing/mocks"
|
||||||
"github.com/v2ray/v2ray-core/proxy/vmess/config"
|
vmess "github.com/v2ray/v2ray-core/proxy/vmess"
|
||||||
"github.com/v2ray/v2ray-core/proxy/vmess/config/json"
|
_ "github.com/v2ray/v2ray-core/proxy/vmess/inbound"
|
||||||
|
inboundjson "github.com/v2ray/v2ray-core/proxy/vmess/inbound/json"
|
||||||
|
vmessjson "github.com/v2ray/v2ray-core/proxy/vmess/json"
|
||||||
|
_ "github.com/v2ray/v2ray-core/proxy/vmess/outbound"
|
||||||
|
outboundjson "github.com/v2ray/v2ray-core/proxy/vmess/outbound/json"
|
||||||
"github.com/v2ray/v2ray-core/shell/point"
|
"github.com/v2ray/v2ray-core/shell/point"
|
||||||
"github.com/v2ray/v2ray-core/shell/point/testing/mocks"
|
"github.com/v2ray/v2ray-core/shell/point/testing/mocks"
|
||||||
v2testing "github.com/v2ray/v2ray-core/testing"
|
v2testing "github.com/v2ray/v2ray-core/testing"
|
||||||
@ -19,7 +23,7 @@ import (
|
|||||||
func TestVMessInAndOut(t *testing.T) {
|
func TestVMessInAndOut(t *testing.T) {
|
||||||
v2testing.Current(t)
|
v2testing.Current(t)
|
||||||
|
|
||||||
testAccount, err := config.NewID("ad937d9d-6e23-4a5a-ba23-bce5092a7c51")
|
testAccount, err := vmess.NewID("ad937d9d-6e23-4a5a-ba23-bce5092a7c51")
|
||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
|
|
||||||
portA := v2nettesting.PickPort()
|
portA := v2nettesting.PickPort()
|
||||||
@ -42,12 +46,12 @@ func TestVMessInAndOut(t *testing.T) {
|
|||||||
},
|
},
|
||||||
OutboundConfigValue: &mocks.ConnectionConfig{
|
OutboundConfigValue: &mocks.ConnectionConfig{
|
||||||
ProtocolValue: "vmess",
|
ProtocolValue: "vmess",
|
||||||
SettingsValue: &json.Outbound{
|
SettingsValue: &outboundjson.Outbound{
|
||||||
[]*json.ConfigTarget{
|
[]*outboundjson.ConfigTarget{
|
||||||
&json.ConfigTarget{
|
&outboundjson.ConfigTarget{
|
||||||
Address: v2net.IPAddress([]byte{127, 0, 0, 1}, portB),
|
Address: v2net.IPAddress([]byte{127, 0, 0, 1}, portB),
|
||||||
Users: []*json.ConfigUser{
|
Users: []*vmessjson.ConfigUser{
|
||||||
&json.ConfigUser{Id: testAccount},
|
&vmessjson.ConfigUser{Id: testAccount},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -74,9 +78,9 @@ func TestVMessInAndOut(t *testing.T) {
|
|||||||
PortValue: portB,
|
PortValue: portB,
|
||||||
InboundConfigValue: &mocks.ConnectionConfig{
|
InboundConfigValue: &mocks.ConnectionConfig{
|
||||||
ProtocolValue: "vmess",
|
ProtocolValue: "vmess",
|
||||||
SettingsValue: &json.Inbound{
|
SettingsValue: &inboundjson.Inbound{
|
||||||
AllowedClients: []*json.ConfigUser{
|
AllowedClients: []*vmessjson.ConfigUser{
|
||||||
&json.ConfigUser{Id: testAccount},
|
&vmessjson.ConfigUser{Id: testAccount},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -23,8 +23,10 @@ import (
|
|||||||
_ "github.com/v2ray/v2ray-core/proxy/freedom/json"
|
_ "github.com/v2ray/v2ray-core/proxy/freedom/json"
|
||||||
_ "github.com/v2ray/v2ray-core/proxy/socks"
|
_ "github.com/v2ray/v2ray-core/proxy/socks"
|
||||||
_ "github.com/v2ray/v2ray-core/proxy/socks/json"
|
_ "github.com/v2ray/v2ray-core/proxy/socks/json"
|
||||||
_ "github.com/v2ray/v2ray-core/proxy/vmess"
|
_ "github.com/v2ray/v2ray-core/proxy/vmess/inbound"
|
||||||
_ "github.com/v2ray/v2ray-core/proxy/vmess/config/json"
|
_ "github.com/v2ray/v2ray-core/proxy/vmess/inbound/json"
|
||||||
|
_ "github.com/v2ray/v2ray-core/proxy/vmess/outbound"
|
||||||
|
_ "github.com/v2ray/v2ray-core/proxy/vmess/outbound/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -9,7 +9,8 @@ import (
|
|||||||
_ "github.com/v2ray/v2ray-core/proxy/dokodemo/json"
|
_ "github.com/v2ray/v2ray-core/proxy/dokodemo/json"
|
||||||
_ "github.com/v2ray/v2ray-core/proxy/freedom/json"
|
_ "github.com/v2ray/v2ray-core/proxy/freedom/json"
|
||||||
_ "github.com/v2ray/v2ray-core/proxy/socks/json"
|
_ "github.com/v2ray/v2ray-core/proxy/socks/json"
|
||||||
_ "github.com/v2ray/v2ray-core/proxy/vmess/config/json"
|
_ "github.com/v2ray/v2ray-core/proxy/vmess/inbound/json"
|
||||||
|
_ "github.com/v2ray/v2ray-core/proxy/vmess/outbound/json"
|
||||||
"github.com/v2ray/v2ray-core/shell/point/json"
|
"github.com/v2ray/v2ray-core/shell/point/json"
|
||||||
|
|
||||||
v2testing "github.com/v2ray/v2ray-core/testing"
|
v2testing "github.com/v2ray/v2ray-core/testing"
|
||||||
|
@ -20,8 +20,10 @@ import (
|
|||||||
_ "github.com/v2ray/v2ray-core/proxy/freedom/json"
|
_ "github.com/v2ray/v2ray-core/proxy/freedom/json"
|
||||||
_ "github.com/v2ray/v2ray-core/proxy/socks"
|
_ "github.com/v2ray/v2ray-core/proxy/socks"
|
||||||
_ "github.com/v2ray/v2ray-core/proxy/socks/json"
|
_ "github.com/v2ray/v2ray-core/proxy/socks/json"
|
||||||
_ "github.com/v2ray/v2ray-core/proxy/vmess"
|
_ "github.com/v2ray/v2ray-core/proxy/vmess/inbound"
|
||||||
_ "github.com/v2ray/v2ray-core/proxy/vmess/config/json"
|
_ "github.com/v2ray/v2ray-core/proxy/vmess/inbound/json"
|
||||||
|
_ "github.com/v2ray/v2ray-core/proxy/vmess/outbound"
|
||||||
|
_ "github.com/v2ray/v2ray-core/proxy/vmess/outbound/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
Loading…
Reference in New Issue
Block a user