1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 10:08:15 -05:00

remove unnecessary package alias

This commit is contained in:
v2ray 2016-05-07 20:26:29 +02:00
parent 73e84b1e06
commit 8a07534586
10 changed files with 51 additions and 56 deletions

View File

@ -57,7 +57,3 @@ func GetUserSettings(level UserLevel) UserSettings {
} }
return settings return settings
} }
type Account interface {
CryptionKey() []byte
}

View File

@ -1,7 +1,7 @@
package inbound package inbound
import ( import (
proto "github.com/v2ray/v2ray-core/common/protocol" "github.com/v2ray/v2ray-core/common/protocol"
) )
type DetourConfig struct { type DetourConfig struct {
@ -14,11 +14,11 @@ type FeaturesConfig struct {
type DefaultConfig struct { type DefaultConfig struct {
AlterIDs uint16 AlterIDs uint16
Level proto.UserLevel Level protocol.UserLevel
} }
type Config struct { type Config struct {
AllowedUsers []*proto.User AllowedUsers []*protocol.User
Features *FeaturesConfig Features *FeaturesConfig
Defaults *DefaultConfig Defaults *DefaultConfig
DetourConfig *DetourConfig DetourConfig *DetourConfig

View File

@ -5,7 +5,7 @@ package inbound
import ( import (
"encoding/json" "encoding/json"
proto "github.com/v2ray/v2ray-core/common/protocol" "github.com/v2ray/v2ray-core/common/protocol"
"github.com/v2ray/v2ray-core/proxy/internal/config" "github.com/v2ray/v2ray-core/proxy/internal/config"
) )
@ -46,16 +46,16 @@ func (this *DefaultConfig) UnmarshalJSON(data []byte) error {
if this.AlterIDs == 0 { if this.AlterIDs == 0 {
this.AlterIDs = 32 this.AlterIDs = 32
} }
this.Level = proto.UserLevel(jsonConfig.Level) this.Level = protocol.UserLevel(jsonConfig.Level)
return nil return nil
} }
func (this *Config) UnmarshalJSON(data []byte) error { func (this *Config) UnmarshalJSON(data []byte) error {
type JsonConfig struct { type JsonConfig struct {
Users []*proto.User `json:"clients"` Users []*protocol.User `json:"clients"`
Features *FeaturesConfig `json:"features"` Features *FeaturesConfig `json:"features"`
Defaults *DefaultConfig `json:"default"` Defaults *DefaultConfig `json:"default"`
DetourConfig *DetourConfig `json:"detour"` DetourConfig *DetourConfig `json:"detour"`
} }
jsonConfig := new(JsonConfig) jsonConfig := new(JsonConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil { if err := json.Unmarshal(data, jsonConfig); err != nil {
@ -66,7 +66,7 @@ func (this *Config) UnmarshalJSON(data []byte) error {
this.Defaults = jsonConfig.Defaults this.Defaults = jsonConfig.Defaults
if this.Defaults == nil { if this.Defaults == nil {
this.Defaults = &DefaultConfig{ this.Defaults = &DefaultConfig{
Level: proto.UserLevel(0), Level: protocol.UserLevel(0),
AlterIDs: 32, AlterIDs: 32,
} }
} }

View File

@ -10,8 +10,8 @@ import (
v2io "github.com/v2ray/v2ray-core/common/io" v2io "github.com/v2ray/v2ray-core/common/io"
"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"
proto "github.com/v2ray/v2ray-core/common/protocol" "github.com/v2ray/v2ray-core/common/protocol"
raw "github.com/v2ray/v2ray-core/common/protocol/raw" "github.com/v2ray/v2ray-core/common/protocol/raw"
"github.com/v2ray/v2ray-core/common/serial" "github.com/v2ray/v2ray-core/common/serial"
"github.com/v2ray/v2ray-core/common/uuid" "github.com/v2ray/v2ray-core/common/uuid"
"github.com/v2ray/v2ray-core/proxy" "github.com/v2ray/v2ray-core/proxy"
@ -22,13 +22,13 @@ import (
type userByEmail struct { type userByEmail struct {
sync.RWMutex sync.RWMutex
cache map[string]*proto.User cache map[string]*protocol.User
defaultLevel proto.UserLevel defaultLevel protocol.UserLevel
defaultAlterIDs uint16 defaultAlterIDs uint16
} }
func NewUserByEmail(users []*proto.User, config *DefaultConfig) *userByEmail { func NewUserByEmail(users []*protocol.User, config *DefaultConfig) *userByEmail {
cache := make(map[string]*proto.User) cache := make(map[string]*protocol.User)
for _, user := range users { for _, user := range users {
cache[user.Email] = user cache[user.Email] = user
} }
@ -39,8 +39,8 @@ func NewUserByEmail(users []*proto.User, config *DefaultConfig) *userByEmail {
} }
} }
func (this *userByEmail) Get(email string) (*proto.User, bool) { func (this *userByEmail) Get(email string) (*protocol.User, bool) {
var user *proto.User var user *protocol.User
var found bool var found bool
this.RLock() this.RLock()
user, found = this.cache[email] user, found = this.cache[email]
@ -49,8 +49,8 @@ func (this *userByEmail) Get(email string) (*proto.User, bool) {
this.Lock() this.Lock()
user, found = this.cache[email] user, found = this.cache[email]
if !found { if !found {
id := proto.NewID(uuid.New()) id := protocol.NewID(uuid.New())
user = proto.NewUser(id, this.defaultLevel, this.defaultAlterIDs, email) user = protocol.NewUser(id, this.defaultLevel, this.defaultAlterIDs, email)
this.cache[email] = user this.cache[email] = user
} }
this.Unlock() this.Unlock()
@ -63,7 +63,7 @@ type VMessInboundHandler struct {
sync.Mutex sync.Mutex
packetDispatcher dispatcher.PacketDispatcher packetDispatcher dispatcher.PacketDispatcher
inboundHandlerManager proxyman.InboundHandlerManager inboundHandlerManager proxyman.InboundHandlerManager
clients proto.UserValidator clients protocol.UserValidator
usersByEmail *userByEmail usersByEmail *userByEmail
accepting bool accepting bool
listener *hub.TCPHub listener *hub.TCPHub
@ -85,7 +85,7 @@ func (this *VMessInboundHandler) Close() {
} }
} }
func (this *VMessInboundHandler) GetUser(email string) *proto.User { func (this *VMessInboundHandler) GetUser(email string) *protocol.User {
user, existing := this.usersByEmail.Get(email) user, existing := this.usersByEmail.Get(email)
if !existing { if !existing {
this.clients.Add(user) this.clients.Add(user)
@ -146,7 +146,7 @@ func (this *VMessInboundHandler) HandleConnection(connection *hub.Connection) {
readFinish.Lock() readFinish.Lock()
writeFinish.Lock() writeFinish.Lock()
userSettings := proto.GetUserSettings(request.User.Level) userSettings := protocol.GetUserSettings(request.User.Level)
connReader.SetTimeOut(userSettings.PayloadReadTimeout) connReader.SetTimeOut(userSettings.PayloadReadTimeout)
reader.SetCached(false) reader.SetCached(false)
go func() { go func() {
@ -166,7 +166,7 @@ func (this *VMessInboundHandler) HandleConnection(connection *hub.Connection) {
writer := v2io.NewBufferedWriter(connection) writer := v2io.NewBufferedWriter(connection)
defer writer.Release() defer writer.Release()
response := &proto.ResponseHeader{ response := &protocol.ResponseHeader{
Command: this.generateCommand(request), Command: this.generateCommand(request),
} }
@ -209,7 +209,7 @@ func init() {
} }
config := rawConfig.(*Config) config := rawConfig.(*Config)
allowedClients := proto.NewTimedUserValidator(proto.DefaultIDHash) allowedClients := protocol.NewTimedUserValidator(protocol.DefaultIDHash)
for _, user := range config.AllowedUsers { for _, user := range config.AllowedUsers {
allowedClients.Add(user) allowedClients.Add(user)
} }

View File

@ -3,11 +3,10 @@ package outbound
import ( import (
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/common/protocol" "github.com/v2ray/v2ray-core/common/protocol"
proto "github.com/v2ray/v2ray-core/common/protocol"
) )
func (this *VMessOutboundHandler) handleSwitchAccount(cmd *protocol.CommandSwitchAccount) { func (this *VMessOutboundHandler) handleSwitchAccount(cmd *protocol.CommandSwitchAccount) {
user := proto.NewUser(proto.NewID(cmd.ID), cmd.Level, cmd.AlterIds.Value(), "") user := protocol.NewUser(protocol.NewID(cmd.ID), cmd.Level, cmd.AlterIds.Value(), "")
dest := v2net.TCPDestination(cmd.Host, cmd.Port) dest := v2net.TCPDestination(cmd.Host, cmd.Port)
this.receiverManager.AddDetour(NewReceiver(dest, user), cmd.ValidMin) this.receiverManager.AddDetour(NewReceiver(dest, user), cmd.ValidMin)
} }

View File

@ -9,8 +9,8 @@ import (
v2io "github.com/v2ray/v2ray-core/common/io" v2io "github.com/v2ray/v2ray-core/common/io"
"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"
proto "github.com/v2ray/v2ray-core/common/protocol" "github.com/v2ray/v2ray-core/common/protocol"
raw "github.com/v2ray/v2ray-core/common/protocol/raw" "github.com/v2ray/v2ray-core/common/protocol/raw"
"github.com/v2ray/v2ray-core/proxy" "github.com/v2ray/v2ray-core/proxy"
"github.com/v2ray/v2ray-core/proxy/internal" "github.com/v2ray/v2ray-core/proxy/internal"
vmessio "github.com/v2ray/v2ray-core/proxy/vmess/io" vmessio "github.com/v2ray/v2ray-core/proxy/vmess/io"
@ -28,17 +28,17 @@ func (this *VMessOutboundHandler) Dispatch(target v2net.Destination, payload *al
destination, vNextUser := this.receiverManager.PickReceiver() destination, vNextUser := this.receiverManager.PickReceiver()
command := proto.RequestCommandTCP command := protocol.RequestCommandTCP
if target.IsUDP() { if target.IsUDP() {
command = proto.RequestCommandUDP command = protocol.RequestCommandUDP
} }
request := &proto.RequestHeader{ request := &protocol.RequestHeader{
Version: raw.Version, Version: raw.Version,
User: vNextUser, User: vNextUser,
Command: command, Command: command,
Address: target.Address(), Address: target.Address(),
Port: target.Port(), Port: target.Port(),
Option: proto.RequestOptionChunkStream, Option: protocol.RequestOptionChunkStream,
} }
conn, err := dialer.Dial(destination) conn, err := dialer.Dial(destination)
@ -57,7 +57,7 @@ func (this *VMessOutboundHandler) Dispatch(target v2net.Destination, payload *al
requestFinish.Lock() requestFinish.Lock()
responseFinish.Lock() responseFinish.Lock()
session := raw.NewClientSession(proto.DefaultIDHash) session := raw.NewClientSession(protocol.DefaultIDHash)
go this.handleRequest(session, conn, request, payload, input, &requestFinish) go this.handleRequest(session, conn, request, payload, input, &requestFinish)
go this.handleResponse(session, conn, request, destination, output, &responseFinish) go this.handleResponse(session, conn, request, destination, output, &responseFinish)
@ -67,7 +67,7 @@ func (this *VMessOutboundHandler) Dispatch(target v2net.Destination, payload *al
return nil return nil
} }
func (this *VMessOutboundHandler) handleRequest(session *raw.ClientSession, conn net.Conn, request *proto.RequestHeader, payload *alloc.Buffer, input v2io.Reader, finish *sync.Mutex) { func (this *VMessOutboundHandler) handleRequest(session *raw.ClientSession, conn net.Conn, request *protocol.RequestHeader, payload *alloc.Buffer, input v2io.Reader, finish *sync.Mutex) {
defer finish.Unlock() defer finish.Unlock()
defer payload.Release() defer payload.Release()
@ -96,7 +96,7 @@ func (this *VMessOutboundHandler) handleRequest(session *raw.ClientSession, conn
return return
} }
func (this *VMessOutboundHandler) handleResponse(session *raw.ClientSession, conn net.Conn, request *proto.RequestHeader, dest v2net.Destination, output v2io.Writer, finish *sync.Mutex) { func (this *VMessOutboundHandler) handleResponse(session *raw.ClientSession, conn net.Conn, request *protocol.RequestHeader, dest v2net.Destination, output v2io.Writer, finish *sync.Mutex) {
defer finish.Unlock() defer finish.Unlock()
reader := v2io.NewBufferedReader(conn) reader := v2io.NewBufferedReader(conn)

View File

@ -6,23 +6,23 @@ import (
"github.com/v2ray/v2ray-core/common/dice" "github.com/v2ray/v2ray-core/common/dice"
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
proto "github.com/v2ray/v2ray-core/common/protocol" "github.com/v2ray/v2ray-core/common/protocol"
) )
type Receiver struct { type Receiver struct {
sync.RWMutex sync.RWMutex
Destination v2net.Destination Destination v2net.Destination
Accounts []*proto.User Accounts []*protocol.User
} }
func NewReceiver(dest v2net.Destination, users ...*proto.User) *Receiver { func NewReceiver(dest v2net.Destination, users ...*protocol.User) *Receiver {
return &Receiver{ return &Receiver{
Destination: dest, Destination: dest,
Accounts: users, Accounts: users,
} }
} }
func (this *Receiver) HasUser(user *proto.User) bool { func (this *Receiver) HasUser(user *protocol.User) bool {
this.RLock() this.RLock()
defer this.RUnlock() defer this.RUnlock()
for _, u := range this.Accounts { for _, u := range this.Accounts {
@ -34,7 +34,7 @@ func (this *Receiver) HasUser(user *proto.User) bool {
return false return false
} }
func (this *Receiver) AddUser(user *proto.User) { func (this *Receiver) AddUser(user *protocol.User) {
if this.HasUser(user) { if this.HasUser(user) {
return return
} }
@ -43,7 +43,7 @@ func (this *Receiver) AddUser(user *proto.User) {
this.Unlock() this.Unlock()
} }
func (this *Receiver) PickUser() *proto.User { func (this *Receiver) PickUser() *protocol.User {
return this.Accounts[dice.Roll(len(this.Accounts))] return this.Accounts[dice.Roll(len(this.Accounts))]
} }
@ -125,7 +125,7 @@ func (this *ReceiverManager) pickStdReceiver() *Receiver {
return this.receivers[dice.Roll(len(this.receivers))] return this.receivers[dice.Roll(len(this.receivers))]
} }
func (this *ReceiverManager) PickReceiver() (v2net.Destination, *proto.User) { func (this *ReceiverManager) PickReceiver() (v2net.Destination, *protocol.User) {
rec := this.pickDetour() rec := this.pickDetour()
if rec == nil { if rec == nil {
rec = this.pickStdReceiver() rec = this.pickStdReceiver()

View File

@ -7,7 +7,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"
proto "github.com/v2ray/v2ray-core/common/protocol" "github.com/v2ray/v2ray-core/common/protocol"
"github.com/v2ray/v2ray-core/proxy/internal" "github.com/v2ray/v2ray-core/proxy/internal"
) )
@ -15,7 +15,7 @@ func (this *Receiver) UnmarshalJSON(data []byte) error {
type RawConfigTarget struct { type RawConfigTarget struct {
Address *v2net.AddressJson `json:"address"` Address *v2net.AddressJson `json:"address"`
Port v2net.Port `json:"port"` Port v2net.Port `json:"port"`
Users []*proto.User `json:"users"` Users []*protocol.User `json:"users"`
} }
var rawConfig RawConfigTarget var rawConfig RawConfigTarget
if err := json.Unmarshal(data, &rawConfig); err != nil { if err := json.Unmarshal(data, &rawConfig); err != nil {

View File

@ -4,7 +4,7 @@ import (
"testing" "testing"
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
proto "github.com/v2ray/v2ray-core/common/protocol" "github.com/v2ray/v2ray-core/common/protocol"
"github.com/v2ray/v2ray-core/common/uuid" "github.com/v2ray/v2ray-core/common/uuid"
. "github.com/v2ray/v2ray-core/proxy/vmess/outbound" . "github.com/v2ray/v2ray-core/proxy/vmess/outbound"
v2testing "github.com/v2ray/v2ray-core/testing" v2testing "github.com/v2ray/v2ray-core/testing"
@ -14,14 +14,14 @@ import (
func TestReceiverUser(t *testing.T) { func TestReceiverUser(t *testing.T) {
v2testing.Current(t) v2testing.Current(t)
id := proto.NewID(uuid.New()) id := protocol.NewID(uuid.New())
user := proto.NewUser(id, proto.UserLevel(0), 100, "") user := protocol.NewUser(id, protocol.UserLevel(0), 100, "")
rec := NewReceiver(v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), 80), user) rec := NewReceiver(v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), 80), user)
assert.Bool(rec.HasUser(user)).IsTrue() assert.Bool(rec.HasUser(user)).IsTrue()
assert.Int(len(rec.Accounts)).Equals(1) assert.Int(len(rec.Accounts)).Equals(1)
id2 := proto.NewID(uuid.New()) id2 := protocol.NewID(uuid.New())
user2 := proto.NewUser(id2, proto.UserLevel(0), 100, "") user2 := protocol.NewUser(id2, protocol.UserLevel(0), 100, "")
assert.Bool(rec.HasUser(user2)).IsFalse() assert.Bool(rec.HasUser(user2)).IsFalse()
rec.AddUser(user2) rec.AddUser(user2)

View File

@ -8,7 +8,7 @@ import (
"github.com/v2ray/v2ray-core/app/dispatcher" "github.com/v2ray/v2ray-core/app/dispatcher"
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing" v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
proto "github.com/v2ray/v2ray-core/common/protocol" "github.com/v2ray/v2ray-core/common/protocol"
"github.com/v2ray/v2ray-core/common/uuid" "github.com/v2ray/v2ray-core/common/uuid"
"github.com/v2ray/v2ray-core/proxy" "github.com/v2ray/v2ray-core/proxy"
proxytesting "github.com/v2ray/v2ray-core/proxy/testing" proxytesting "github.com/v2ray/v2ray-core/proxy/testing"
@ -26,7 +26,7 @@ func TestVMessInAndOut(t *testing.T) {
id, err := uuid.ParseString("ad937d9d-6e23-4a5a-ba23-bce5092a7c51") id, err := uuid.ParseString("ad937d9d-6e23-4a5a-ba23-bce5092a7c51")
assert.Error(err).IsNil() assert.Error(err).IsNil()
testAccount := proto.NewID(id) testAccount := protocol.NewID(id)
portA := v2nettesting.PickPort() portA := v2nettesting.PickPort()
portB := v2nettesting.PickPort() portB := v2nettesting.PickPort()