1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -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
}
type Account interface {
CryptionKey() []byte
}

View File

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

View File

@ -5,7 +5,7 @@ package inbound
import (
"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"
)
@ -46,16 +46,16 @@ func (this *DefaultConfig) UnmarshalJSON(data []byte) error {
if this.AlterIDs == 0 {
this.AlterIDs = 32
}
this.Level = proto.UserLevel(jsonConfig.Level)
this.Level = protocol.UserLevel(jsonConfig.Level)
return nil
}
func (this *Config) UnmarshalJSON(data []byte) error {
type JsonConfig struct {
Users []*proto.User `json:"clients"`
Features *FeaturesConfig `json:"features"`
Defaults *DefaultConfig `json:"default"`
DetourConfig *DetourConfig `json:"detour"`
Users []*protocol.User `json:"clients"`
Features *FeaturesConfig `json:"features"`
Defaults *DefaultConfig `json:"default"`
DetourConfig *DetourConfig `json:"detour"`
}
jsonConfig := new(JsonConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
@ -66,7 +66,7 @@ func (this *Config) UnmarshalJSON(data []byte) error {
this.Defaults = jsonConfig.Defaults
if this.Defaults == nil {
this.Defaults = &DefaultConfig{
Level: proto.UserLevel(0),
Level: protocol.UserLevel(0),
AlterIDs: 32,
}
}

View File

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

View File

@ -3,11 +3,10 @@ package outbound
import (
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/common/protocol"
proto "github.com/v2ray/v2ray-core/common/protocol"
)
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)
this.receiverManager.AddDetour(NewReceiver(dest, user), cmd.ValidMin)
}

View File

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

View File

@ -6,23 +6,23 @@ import (
"github.com/v2ray/v2ray-core/common/dice"
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 {
sync.RWMutex
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{
Destination: dest,
Accounts: users,
}
}
func (this *Receiver) HasUser(user *proto.User) bool {
func (this *Receiver) HasUser(user *protocol.User) bool {
this.RLock()
defer this.RUnlock()
for _, u := range this.Accounts {
@ -34,7 +34,7 @@ func (this *Receiver) HasUser(user *proto.User) bool {
return false
}
func (this *Receiver) AddUser(user *proto.User) {
func (this *Receiver) AddUser(user *protocol.User) {
if this.HasUser(user) {
return
}
@ -43,7 +43,7 @@ func (this *Receiver) AddUser(user *proto.User) {
this.Unlock()
}
func (this *Receiver) PickUser() *proto.User {
func (this *Receiver) PickUser() *protocol.User {
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))]
}
func (this *ReceiverManager) PickReceiver() (v2net.Destination, *proto.User) {
func (this *ReceiverManager) PickReceiver() (v2net.Destination, *protocol.User) {
rec := this.pickDetour()
if rec == nil {
rec = this.pickStdReceiver()

View File

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

View File

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

View File

@ -8,7 +8,7 @@ import (
"github.com/v2ray/v2ray-core/app/dispatcher"
v2net "github.com/v2ray/v2ray-core/common/net"
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/proxy"
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")
assert.Error(err).IsNil()
testAccount := proto.NewID(id)
testAccount := protocol.NewID(id)
portA := v2nettesting.PickPort()
portB := v2nettesting.PickPort()