diff --git a/net/address.go b/common/net/address.go similarity index 100% rename from net/address.go rename to common/net/address.go diff --git a/net/address_test.go b/common/net/address_test.go similarity index 100% rename from net/address_test.go rename to common/net/address_test.go diff --git a/net/transport.go b/common/net/transport.go similarity index 100% rename from net/transport.go rename to common/net/transport.go diff --git a/net/transport_test.go b/common/net/transport_test.go similarity index 100% rename from net/transport_test.go rename to common/net/transport_test.go diff --git a/config.go b/config.go index c714db3e0..bceee8504 100644 --- a/config.go +++ b/config.go @@ -1,10 +1,5 @@ package core -// User is the user account that is used for connection to a Point -type User struct { - Id ID `json:"id"` // The ID of this User. -} - type ConnectionConfig interface { Protocol() string Content() []byte diff --git a/io/config/json/json.go b/config/json/json.go similarity index 100% rename from io/config/json/json.go rename to config/json/json.go diff --git a/point.go b/point.go index f6a64e500..ec46a0deb 100644 --- a/point.go +++ b/point.go @@ -1,8 +1,8 @@ package core import ( + v2net "github.com/v2ray/v2ray-core/common/net" "github.com/v2ray/v2ray-core/log" - v2net "github.com/v2ray/v2ray-core/net" ) var ( diff --git a/net/freedom/freedom.go b/proxy/freedom/freedom.go similarity index 96% rename from net/freedom/freedom.go rename to proxy/freedom/freedom.go index ea14d51c8..99bdc90d9 100644 --- a/net/freedom/freedom.go +++ b/proxy/freedom/freedom.go @@ -4,8 +4,8 @@ import ( "net" "github.com/v2ray/v2ray-core" + v2net "github.com/v2ray/v2ray-core/common/net" "github.com/v2ray/v2ray-core/log" - v2net "github.com/v2ray/v2ray-core/net" ) type FreedomConnection struct { diff --git a/net/freedom/freedomfactory.go b/proxy/freedom/freedomfactory.go similarity index 88% rename from net/freedom/freedomfactory.go rename to proxy/freedom/freedomfactory.go index a1383fee8..a40bb3bbd 100644 --- a/net/freedom/freedomfactory.go +++ b/proxy/freedom/freedomfactory.go @@ -2,7 +2,7 @@ package freedom import ( "github.com/v2ray/v2ray-core" - v2net "github.com/v2ray/v2ray-core/net" + v2net "github.com/v2ray/v2ray-core/common/net" ) type FreedomFactory struct { diff --git a/net/socks/config.go b/proxy/socks/config.go similarity index 100% rename from net/socks/config.go rename to proxy/socks/config.go diff --git a/io/socks/socks.go b/proxy/socks/protocol/socks.go similarity index 98% rename from io/socks/socks.go rename to proxy/socks/protocol/socks.go index ea770b093..76803bf3d 100644 --- a/io/socks/socks.go +++ b/proxy/socks/protocol/socks.go @@ -1,5 +1,4 @@ -// Package socks contains protocol definition and io lib for SOCKS5 protocol -package socks +package protocol import ( "encoding/binary" @@ -7,8 +6,8 @@ import ( "fmt" "io" + v2net "github.com/v2ray/v2ray-core/common/net" "github.com/v2ray/v2ray-core/log" - v2net "github.com/v2ray/v2ray-core/net" ) const ( diff --git a/io/socks/socks_test.go b/proxy/socks/protocol/socks_test.go similarity index 99% rename from io/socks/socks_test.go rename to proxy/socks/protocol/socks_test.go index 357a8aecc..5551b9730 100644 --- a/io/socks/socks_test.go +++ b/proxy/socks/protocol/socks_test.go @@ -1,4 +1,4 @@ -package socks +package protocol import ( "bytes" diff --git a/io/socks/udp.go b/proxy/socks/protocol/udp.go similarity index 80% rename from io/socks/udp.go rename to proxy/socks/protocol/udp.go index 9180c5df2..371643b81 100644 --- a/io/socks/udp.go +++ b/proxy/socks/protocol/udp.go @@ -1,9 +1,9 @@ -package socks +package protocol import ( "io" - v2net "github.com/v2ray/v2ray-core/net" + v2net "github.com/v2ray/v2ray-core/common/net" ) type Socks5UDPRequest struct { diff --git a/net/socks/socks.go b/proxy/socks/socks.go similarity index 70% rename from net/socks/socks.go rename to proxy/socks/socks.go index c3474dda8..af0e97b8e 100644 --- a/net/socks/socks.go +++ b/proxy/socks/socks.go @@ -8,9 +8,9 @@ import ( "strconv" "github.com/v2ray/v2ray-core" - socksio "github.com/v2ray/v2ray-core/io/socks" + v2net "github.com/v2ray/v2ray-core/common/net" "github.com/v2ray/v2ray-core/log" - v2net "github.com/v2ray/v2ray-core/net" + protocol "github.com/v2ray/v2ray-core/proxy/socks/protocol" ) var ( @@ -64,8 +64,8 @@ func (server *SocksServer) HandleConnection(connection net.Conn) error { reader := connection.(io.Reader) - auth, auth4, err := socksio.ReadAuthentication(reader) - if err != nil && err != socksio.ErrorSocksVersion4 { + auth, auth4, err := protocol.ReadAuthentication(reader) + if err != nil && err != protocol.ErrorSocksVersion4 { log.Error("Error on reading authentication: %v", err) return err } @@ -73,28 +73,28 @@ func (server *SocksServer) HandleConnection(connection net.Conn) error { var dest v2net.Address // TODO refactor this part - if err == socksio.ErrorSocksVersion4 { - result := socksio.Socks4RequestGranted - if auth4.Command == socksio.CmdBind { - result = socksio.Socks4RequestRejected + if err == protocol.ErrorSocksVersion4 { + result := protocol.Socks4RequestGranted + if auth4.Command == protocol.CmdBind { + result = protocol.Socks4RequestRejected } - socks4Response := socksio.NewSocks4AuthenticationResponse(result, auth4.Port, auth4.IP[:]) - socksio.WriteSocks4AuthenticationResponse(connection, socks4Response) + socks4Response := protocol.NewSocks4AuthenticationResponse(result, auth4.Port, auth4.IP[:]) + protocol.WriteSocks4AuthenticationResponse(connection, socks4Response) - if result == socksio.Socks4RequestRejected { + if result == protocol.Socks4RequestRejected { return ErrorCommandNotSupported } dest = v2net.IPAddress(auth4.IP[:], auth4.Port) } else { - expectedAuthMethod := socksio.AuthNotRequired + expectedAuthMethod := protocol.AuthNotRequired if server.config.AuthMethod == JsonAuthMethodUserPass { - expectedAuthMethod = socksio.AuthUserPass + expectedAuthMethod = protocol.AuthUserPass } if !auth.HasAuthMethod(expectedAuthMethod) { - authResponse := socksio.NewAuthenticationResponse(socksio.AuthNoMatchingMethod) - err = socksio.WriteAuthentication(connection, authResponse) + authResponse := protocol.NewAuthenticationResponse(protocol.AuthNoMatchingMethod) + err = protocol.WriteAuthentication(connection, authResponse) if err != nil { log.Error("Error on socksio write authentication: %v", err) return err @@ -103,14 +103,14 @@ func (server *SocksServer) HandleConnection(connection net.Conn) error { return ErrorAuthenticationFailed } - authResponse := socksio.NewAuthenticationResponse(expectedAuthMethod) - err = socksio.WriteAuthentication(connection, authResponse) + authResponse := protocol.NewAuthenticationResponse(expectedAuthMethod) + err = protocol.WriteAuthentication(connection, authResponse) if err != nil { log.Error("Error on socksio write authentication: %v", err) return err } if server.config.AuthMethod == JsonAuthMethodUserPass { - upRequest, err := socksio.ReadUserPassRequest(reader) + upRequest, err := protocol.ReadUserPassRequest(reader) if err != nil { log.Error("Failed to read username and password: %v", err) return err @@ -119,8 +119,8 @@ func (server *SocksServer) HandleConnection(connection net.Conn) error { if !upRequest.IsValid(server.config.Username, server.config.Password) { status = byte(0xFF) } - upResponse := socksio.NewSocks5UserPassResponse(status) - err = socksio.WriteUserPassResponse(connection, upResponse) + upResponse := protocol.NewSocks5UserPassResponse(status) + err = protocol.WriteUserPassResponse(connection, upResponse) if err != nil { log.Error("Error on socksio write user pass response: %v", err) return err @@ -130,18 +130,18 @@ func (server *SocksServer) HandleConnection(connection net.Conn) error { } } - request, err := socksio.ReadRequest(reader) + request, err := protocol.ReadRequest(reader) if err != nil { log.Error("Error on reading socks request: %v", err) return err } - response := socksio.NewSocks5Response() + response := protocol.NewSocks5Response() - if request.Command == socksio.CmdBind || request.Command == socksio.CmdUdpAssociate { - response := socksio.NewSocks5Response() - response.Error = socksio.ErrorCommandNotSupported - err = socksio.WriteResponse(connection, response) + if request.Command == protocol.CmdBind || request.Command == protocol.CmdUdpAssociate { + response := protocol.NewSocks5Response() + response.Error = protocol.ErrorCommandNotSupported + err = protocol.WriteResponse(connection, response) if err != nil { log.Error("Error on socksio write response: %v", err) return err @@ -150,18 +150,18 @@ func (server *SocksServer) HandleConnection(connection net.Conn) error { return ErrorCommandNotSupported } - response.Error = socksio.ErrorSuccess + response.Error = protocol.ErrorSuccess response.Port = request.Port response.AddrType = request.AddrType switch response.AddrType { - case socksio.AddrTypeIPv4: + case protocol.AddrTypeIPv4: copy(response.IPv4[:], request.IPv4[:]) - case socksio.AddrTypeIPv6: + case protocol.AddrTypeIPv6: copy(response.IPv6[:], request.IPv6[:]) - case socksio.AddrTypeDomain: + case protocol.AddrTypeDomain: response.Domain = request.Domain } - err = socksio.WriteResponse(connection, response) + err = protocol.WriteResponse(connection, response) if err != nil { log.Error("Error on socksio write response: %v", err) return err diff --git a/net/socks/socks_test.go b/proxy/socks/socks_test.go similarity index 100% rename from net/socks/socks_test.go rename to proxy/socks/socks_test.go diff --git a/net/socks/socksfactory.go b/proxy/socks/socksfactory.go similarity index 100% rename from net/socks/socksfactory.go rename to proxy/socks/socksfactory.go diff --git a/net/vmess/config.go b/proxy/vmess/config.go similarity index 82% rename from net/vmess/config.go rename to proxy/vmess/config.go index 1beb4bb33..4c0788c1e 100644 --- a/net/vmess/config.go +++ b/proxy/vmess/config.go @@ -4,9 +4,9 @@ import ( "encoding/json" "net" - "github.com/v2ray/v2ray-core" + v2net "github.com/v2ray/v2ray-core/common/net" "github.com/v2ray/v2ray-core/log" - v2net "github.com/v2ray/v2ray-core/net" + "github.com/v2ray/v2ray-core/proxy/vmess/protocol" ) type VMessUser struct { @@ -14,9 +14,9 @@ type VMessUser struct { Email string `json:"email"` } -func (u *VMessUser) ToUser() (core.User, error) { - id, err := core.NewID(u.Id) - return core.User{ +func (u *VMessUser) ToUser() (protocol.User, error) { + id, err := protocol.NewID(u.Id) + return protocol.User{ Id: id, }, err } @@ -38,7 +38,7 @@ type VNextConfig struct { } func (config VNextConfig) ToVNextServer() VNextServer { - users := make([]core.User, 0, len(config.Users)) + users := make([]protocol.User, 0, len(config.Users)) for _, user := range config.Users { vuser, err := user.ToUser() if err != nil { diff --git a/id.go b/proxy/vmess/protocol/id.go similarity index 98% rename from id.go rename to proxy/vmess/protocol/id.go index ec178435b..92cfa1927 100644 --- a/id.go +++ b/proxy/vmess/protocol/id.go @@ -1,4 +1,4 @@ -package core +package protocol import ( "crypto/md5" diff --git a/id_test.go b/proxy/vmess/protocol/id_test.go similarity index 95% rename from id_test.go rename to proxy/vmess/protocol/id_test.go index 72fa958e0..4d6313963 100644 --- a/id_test.go +++ b/proxy/vmess/protocol/id_test.go @@ -1,4 +1,4 @@ -package core +package protocol import ( "testing" diff --git a/hash/id.go b/proxy/vmess/protocol/idhash.go similarity index 98% rename from hash/id.go rename to proxy/vmess/protocol/idhash.go index d1538889b..e382e792e 100644 --- a/hash/id.go +++ b/proxy/vmess/protocol/idhash.go @@ -1,4 +1,4 @@ -package hash +package protocol import ( "crypto/hmac" diff --git a/hash/int.go b/proxy/vmess/protocol/inthash.go similarity index 93% rename from hash/int.go rename to proxy/vmess/protocol/inthash.go index 431650350..41258da82 100644 --- a/hash/int.go +++ b/proxy/vmess/protocol/inthash.go @@ -1,4 +1,4 @@ -package hash +package protocol import ( "crypto/md5" diff --git a/math/rand.go b/proxy/vmess/protocol/rand.go similarity index 93% rename from math/rand.go rename to proxy/vmess/protocol/rand.go index 09bc122d0..af9e9b7b1 100644 --- a/math/rand.go +++ b/proxy/vmess/protocol/rand.go @@ -1,4 +1,4 @@ -package math +package protocol import ( "math/rand" diff --git a/math/rand_test.go b/proxy/vmess/protocol/rand_test.go similarity index 95% rename from math/rand_test.go rename to proxy/vmess/protocol/rand_test.go index 1d31e81ea..3a36a1968 100644 --- a/math/rand_test.go +++ b/proxy/vmess/protocol/rand_test.go @@ -1,4 +1,4 @@ -package math +package protocol import ( "testing" diff --git a/proxy/vmess/protocol/user.go b/proxy/vmess/protocol/user.go new file mode 100644 index 000000000..47c3e70cc --- /dev/null +++ b/proxy/vmess/protocol/user.go @@ -0,0 +1,6 @@ +package protocol + +// User is the user account that is used for connection to a Point +type User struct { + Id ID `json:"id"` // The ID of this User. +} diff --git a/userset.go b/proxy/vmess/protocol/userset.go similarity index 96% rename from userset.go rename to proxy/vmess/protocol/userset.go index 520105d08..20903907f 100644 --- a/userset.go +++ b/proxy/vmess/protocol/userset.go @@ -1,10 +1,9 @@ -package core +package protocol import ( "container/heap" "time" - v2hash "github.com/v2ray/v2ray-core/hash" "github.com/v2ray/v2ray-core/log" ) @@ -74,7 +73,7 @@ func NewTimedUserSet() UserSet { } func (us *TimedUserSet) generateNewHashes(lastSec, nowSec int64, idx int, id ID) { - idHash := v2hash.NewTimeHash(v2hash.HMACHash{}) + idHash := NewTimeHash(HMACHash{}) for lastSec < nowSec+cacheDurationSec { idHash := idHash.Hash(id.Bytes, lastSec) diff --git a/io/vmess/vmess.go b/proxy/vmess/protocol/vmess.go similarity index 89% rename from io/vmess/vmess.go rename to proxy/vmess/protocol/vmess.go index a7f7c6c7d..521a76d62 100644 --- a/io/vmess/vmess.go +++ b/proxy/vmess/protocol/vmess.go @@ -1,5 +1,5 @@ // Package vmess contains protocol definition, io lib for VMess. -package vmess +package protocol import ( "crypto/aes" @@ -12,12 +12,9 @@ import ( mrand "math/rand" "time" - "github.com/v2ray/v2ray-core" - v2hash "github.com/v2ray/v2ray-core/hash" - v2io "github.com/v2ray/v2ray-core/io" + v2io "github.com/v2ray/v2ray-core/common/io" + v2net "github.com/v2ray/v2ray-core/common/net" "github.com/v2ray/v2ray-core/log" - v2math "github.com/v2ray/v2ray-core/math" - v2net "github.com/v2ray/v2ray-core/net" ) const ( @@ -41,7 +38,7 @@ var ( type VMessRequest struct { Version byte - UserId core.ID + UserId ID RequestIV [16]byte RequestKey [16]byte ResponseHeader [4]byte @@ -50,10 +47,10 @@ type VMessRequest struct { } type VMessRequestReader struct { - vUserSet core.UserSet + vUserSet UserSet } -func NewVMessRequestReader(vUserSet core.UserSet) *VMessRequestReader { +func NewVMessRequestReader(vUserSet UserSet) *VMessRequestReader { return &VMessRequestReader{ vUserSet: vUserSet, } @@ -62,7 +59,7 @@ func NewVMessRequestReader(vUserSet core.UserSet) *VMessRequestReader { func (r *VMessRequestReader) Read(reader io.Reader) (*VMessRequest, error) { buffer := make([]byte, 256) - nBytes, err := reader.Read(buffer[:core.IDBytesLen]) + nBytes, err := reader.Read(buffer[:IDBytesLen]) if err != nil { return nil, err } @@ -78,7 +75,7 @@ func (r *VMessRequestReader) Read(reader io.Reader) (*VMessRequest, error) { if err != nil { return nil, err } - aesStream := cipher.NewCFBDecrypter(aesCipher, v2hash.Int64Hash(timeSec)) + aesStream := cipher.NewCFBDecrypter(aesCipher, Int64Hash(timeSec)) decryptor := v2io.NewCryptionReader(aesStream, reader) if err != nil { @@ -181,7 +178,7 @@ func (r *VMessRequestReader) Read(reader io.Reader) (*VMessRequest, error) { return request, nil } -func (request *VMessRequest) ToBytes(idHash v2hash.CounterHash, randomRangeInt64 v2math.RandomInt64InRange) ([]byte, error) { +func (request *VMessRequest) ToBytes(idHash CounterHash, randomRangeInt64 RandomInt64InRange) ([]byte, error) { buffer := make([]byte, 0, 300) counter := randomRangeInt64(time.Now().UTC().Unix(), 30) @@ -238,7 +235,7 @@ func (request *VMessRequest) ToBytes(idHash v2hash.CounterHash, randomRangeInt64 if err != nil { return nil, err } - aesStream := cipher.NewCFBEncrypter(aesCipher, v2hash.Int64Hash(counter)) + aesStream := cipher.NewCFBEncrypter(aesCipher, Int64Hash(counter)) aesStream.XORKeyStream(buffer[encryptionBegin:encryptionEnd], buffer[encryptionBegin:encryptionEnd]) return buffer, nil diff --git a/io/vmess/vmess_test.go b/proxy/vmess/protocol/vmess_test.go similarity index 86% rename from io/vmess/vmess_test.go rename to proxy/vmess/protocol/vmess_test.go index 1dd351406..13ff6e06f 100644 --- a/io/vmess/vmess_test.go +++ b/proxy/vmess/protocol/vmess_test.go @@ -1,4 +1,4 @@ -package vmess +package protocol import ( "bytes" @@ -6,9 +6,7 @@ import ( "testing" "github.com/v2ray/v2ray-core" - v2hash "github.com/v2ray/v2ray-core/hash" - v2math "github.com/v2ray/v2ray-core/math" - v2net "github.com/v2ray/v2ray-core/net" + v2net "github.com/v2ray/v2ray-core/common/net" "github.com/v2ray/v2ray-core/testing/mocks" "github.com/v2ray/v2ray-core/testing/unit" ) @@ -47,7 +45,7 @@ func TestVMessSerialization(t *testing.T) { request.Address = v2net.DomainAddress("v2ray.com", 80) mockTime := int64(1823730) - buffer, err := request.ToBytes(v2hash.NewTimeHash(v2hash.HMACHash{}), func(base int64, delta int) int64 { return mockTime }) + buffer, err := request.ToBytes(NewTimeHash(HMACHash{}), func(base int64, delta int) int64 { return mockTime }) if err != nil { t.Fatal(err) } @@ -87,6 +85,6 @@ func BenchmarkVMessRequestWriting(b *testing.B) { request.Address = v2net.DomainAddress("v2ray.com", 80) for i := 0; i < b.N; i++ { - request.ToBytes(v2hash.NewTimeHash(v2hash.HMACHash{}), v2math.GenerateRandomInt64InRange) + request.ToBytes(NewTimeHash(HMACHash{}), GenerateRandomInt64InRange) } } diff --git a/net/vmess/vmess_test.go b/proxy/vmess/vmess_test.go similarity index 97% rename from net/vmess/vmess_test.go rename to proxy/vmess/vmess_test.go index 35f2f97bd..f68fdb075 100644 --- a/net/vmess/vmess_test.go +++ b/proxy/vmess/vmess_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/v2ray/v2ray-core" - v2net "github.com/v2ray/v2ray-core/net" + v2net "github.com/v2ray/v2ray-core/common/net" "github.com/v2ray/v2ray-core/testing/mocks" "github.com/v2ray/v2ray-core/testing/unit" ) diff --git a/net/vmess/vmessin.go b/proxy/vmess/vmessin.go similarity index 82% rename from net/vmess/vmessin.go rename to proxy/vmess/vmessin.go index afaf409a2..40c735ff9 100644 --- a/net/vmess/vmessin.go +++ b/proxy/vmess/vmessin.go @@ -7,19 +7,19 @@ import ( "strconv" "github.com/v2ray/v2ray-core" - v2io "github.com/v2ray/v2ray-core/io" - vmessio "github.com/v2ray/v2ray-core/io/vmess" + v2io "github.com/v2ray/v2ray-core/common/io" + v2net "github.com/v2ray/v2ray-core/common/net" "github.com/v2ray/v2ray-core/log" - v2net "github.com/v2ray/v2ray-core/net" + protocol "github.com/v2ray/v2ray-core/proxy/vmess/protocol" ) type VMessInboundHandler struct { vPoint *core.Point - clients core.UserSet + clients protocol.UserSet accepting bool } -func NewVMessInboundHandler(vp *core.Point, clients core.UserSet) *VMessInboundHandler { +func NewVMessInboundHandler(vp *core.Point, clients protocol.UserSet) *VMessInboundHandler { return &VMessInboundHandler{ vPoint: vp, clients: clients, @@ -51,7 +51,7 @@ func (handler *VMessInboundHandler) AcceptConnections(listener net.Listener) err func (handler *VMessInboundHandler) HandleConnection(connection net.Conn) error { defer connection.Close() - reader := vmessio.NewVMessRequestReader(handler.clients) + reader := protocol.NewVMessRequestReader(handler.clients) request, err := reader.Read(connection) if err != nil { @@ -72,7 +72,7 @@ func (handler *VMessInboundHandler) HandleConnection(connection net.Conn) error responseKey := md5.Sum(request.RequestKey[:]) responseIV := md5.Sum(request.RequestIV[:]) - response := vmessio.NewVMessResponse(request) + response := protocol.NewVMessResponse(request) responseWriter, err := v2io.NewAesEncryptWriter(responseKey[:], responseIV[:], connection) if err != nil { return log.Error("VMessIn: Failed to create encrypt writer: %v", err) @@ -97,7 +97,7 @@ func (handler *VMessInboundHandler) HandleConnection(connection net.Conn) error return nil } -func handleInput(request *vmessio.VMessRequest, reader io.Reader, input chan<- []byte, finish chan<- bool) { +func handleInput(request *protocol.VMessRequest, reader io.Reader, input chan<- []byte, finish chan<- bool) { defer close(input) defer close(finish) @@ -110,7 +110,7 @@ func handleInput(request *vmessio.VMessRequest, reader io.Reader, input chan<- [ v2net.ReaderToChan(input, requestReader) } -func handleOutput(request *vmessio.VMessRequest, writer io.Writer, output <-chan []byte, finish chan<- bool) { +func handleOutput(request *protocol.VMessRequest, writer io.Writer, output <-chan []byte, finish chan<- bool) { v2net.ChanToWriter(writer, output) close(finish) } @@ -123,7 +123,7 @@ func (factory *VMessInboundHandlerFactory) Create(vp *core.Point, rawConfig []by if err != nil { panic(log.Error("VMessIn: Failed to load VMess inbound config: %v", err)) } - allowedClients := core.NewTimedUserSet() + allowedClients := protocol.NewTimedUserSet() for _, client := range config.AllowedClients { user, err := client.ToUser() if err != nil { diff --git a/net/vmess/vmessout.go b/proxy/vmess/vmessout.go similarity index 82% rename from net/vmess/vmessout.go rename to proxy/vmess/vmessout.go index cee2b8390..4ec59029a 100644 --- a/net/vmess/vmessout.go +++ b/proxy/vmess/vmessout.go @@ -8,18 +8,16 @@ import ( "net" "github.com/v2ray/v2ray-core" - v2hash "github.com/v2ray/v2ray-core/hash" - v2io "github.com/v2ray/v2ray-core/io" - vmessio "github.com/v2ray/v2ray-core/io/vmess" + v2io "github.com/v2ray/v2ray-core/common/io" + v2net "github.com/v2ray/v2ray-core/common/net" "github.com/v2ray/v2ray-core/log" - v2math "github.com/v2ray/v2ray-core/math" - v2net "github.com/v2ray/v2ray-core/net" + protocol "github.com/v2ray/v2ray-core/proxy/vmess/protocol" ) // VNext is the next Point server in the connection chain. type VNextServer struct { - Address v2net.Address // Address of VNext server - Users []core.User // User accounts for accessing VNext. + Address v2net.Address // Address of VNext server + Users []protocol.User // User accounts for accessing VNext. } type VMessOutboundHandler struct { @@ -36,7 +34,7 @@ func NewVMessOutboundHandler(vp *core.Point, vNextList []VNextServer, dest v2net } } -func (handler *VMessOutboundHandler) pickVNext() (v2net.Address, core.User) { +func (handler *VMessOutboundHandler) pickVNext() (v2net.Address, protocol.User) { vNextLen := len(handler.vNextList) if vNextLen == 0 { panic("VMessOut: Zero vNext is configured.") @@ -55,8 +53,8 @@ func (handler *VMessOutboundHandler) pickVNext() (v2net.Address, core.User) { func (handler *VMessOutboundHandler) Start(ray core.OutboundRay) error { vNextAddress, vNextUser := handler.pickVNext() - request := &vmessio.VMessRequest{ - Version: vmessio.Version, + request := &protocol.VMessRequest{ + Version: protocol.Version, UserId: vNextUser.Id, Command: byte(0x01), Address: handler.dest, @@ -69,7 +67,7 @@ func (handler *VMessOutboundHandler) Start(ray core.OutboundRay) error { return nil } -func startCommunicate(request *vmessio.VMessRequest, dest v2net.Address, ray core.OutboundRay) error { +func startCommunicate(request *protocol.VMessRequest, dest v2net.Address, ray core.OutboundRay) error { input := ray.OutboundInput() output := ray.OutboundOutput() @@ -95,7 +93,7 @@ func startCommunicate(request *vmessio.VMessRequest, dest v2net.Address, ray cor return nil } -func handleRequest(conn *net.TCPConn, request *vmessio.VMessRequest, input <-chan []byte, finish chan<- bool) { +func handleRequest(conn *net.TCPConn, request *protocol.VMessRequest, input <-chan []byte, finish chan<- bool) { defer close(finish) encryptRequestWriter, err := v2io.NewAesEncryptWriter(request.RequestKey[:], request.RequestIV[:], conn) if err != nil { @@ -103,7 +101,7 @@ func handleRequest(conn *net.TCPConn, request *vmessio.VMessRequest, input <-cha return } - buffer, err := request.ToBytes(v2hash.NewTimeHash(v2hash.HMACHash{}), v2math.GenerateRandomInt64InRange) + buffer, err := request.ToBytes(protocol.NewTimeHash(protocol.HMACHash{}), protocol.GenerateRandomInt64InRange) if err != nil { log.Error("VMessOut: Failed to serialize VMess request: %v", err) return @@ -126,7 +124,7 @@ func handleRequest(conn *net.TCPConn, request *vmessio.VMessRequest, input <-cha return } -func handleResponse(conn *net.TCPConn, request *vmessio.VMessRequest, output chan<- []byte, finish chan<- bool) { +func handleResponse(conn *net.TCPConn, request *protocol.VMessRequest, output chan<- []byte, finish chan<- bool) { defer close(finish) defer close(output) responseKey := md5.Sum(request.RequestKey[:]) @@ -138,7 +136,7 @@ func handleResponse(conn *net.TCPConn, request *vmessio.VMessRequest, output cha return } - response := vmessio.VMessResponse{} + response := protocol.VMessResponse{} nBytes, err := decryptResponseReader.Read(response[:]) if err != nil { log.Error("VMessOut: Failed to read VMess response (%d bytes): %v", nBytes, err) diff --git a/release/server/main.go b/release/server/main.go index 1eb410a83..74389b78e 100644 --- a/release/server/main.go +++ b/release/server/main.go @@ -5,13 +5,13 @@ import ( "fmt" "github.com/v2ray/v2ray-core" - jsonconf "github.com/v2ray/v2ray-core/io/config/json" + jsonconf "github.com/v2ray/v2ray-core/config/json" "github.com/v2ray/v2ray-core/log" // The following are neccesary as they register handlers in their init functions. - _ "github.com/v2ray/v2ray-core/net/freedom" - _ "github.com/v2ray/v2ray-core/net/socks" - _ "github.com/v2ray/v2ray-core/net/vmess" + _ "github.com/v2ray/v2ray-core/proxy/freedom" + _ "github.com/v2ray/v2ray-core/proxy/socks" + _ "github.com/v2ray/v2ray-core/proxy/vmess" ) var ( diff --git a/testing/mocks/inboundhandler.go b/testing/mocks/inboundhandler.go index 64abd7894..5a14bc295 100644 --- a/testing/mocks/inboundhandler.go +++ b/testing/mocks/inboundhandler.go @@ -4,7 +4,7 @@ import ( "bytes" "github.com/v2ray/v2ray-core" - v2net "github.com/v2ray/v2ray-core/net" + v2net "github.com/v2ray/v2ray-core/common/net" ) type InboundConnectionHandler struct { diff --git a/testing/mocks/mockuserset.go b/testing/mocks/mockuserset.go index 238c99c6a..53f125278 100644 --- a/testing/mocks/mockuserset.go +++ b/testing/mocks/mockuserset.go @@ -1,21 +1,21 @@ package mocks import ( - "github.com/v2ray/v2ray-core" + "github.com/v2ray/v2ray-core/proxy/vmess/protocol" ) type MockUserSet struct { - UserIds []core.ID + UserIds []protocol.ID UserHashes map[string]int Timestamps map[string]int64 } -func (us *MockUserSet) AddUser(user core.User) error { +func (us *MockUserSet) AddUser(user protocol.User) error { us.UserIds = append(us.UserIds, user.Id) return nil } -func (us *MockUserSet) GetUser(userhash []byte) (*core.ID, int64, bool) { +func (us *MockUserSet) GetUser(userhash []byte) (*protocol.ID, int64, bool) { idx, found := us.UserHashes[string(userhash)] if found { return &us.UserIds[idx], us.Timestamps[string(userhash)], true diff --git a/testing/mocks/outboundhandler.go b/testing/mocks/outboundhandler.go index 91aa72c5c..e5da7c723 100644 --- a/testing/mocks/outboundhandler.go +++ b/testing/mocks/outboundhandler.go @@ -4,7 +4,7 @@ import ( "bytes" "github.com/v2ray/v2ray-core" - v2net "github.com/v2ray/v2ray-core/net" + v2net "github.com/v2ray/v2ray-core/common/net" ) type OutboundConnectionHandler struct {