From 6f5b54747e4bda09512dfa8b3476f93063bf079b Mon Sep 17 00:00:00 2001 From: v2ray Date: Sat, 23 Jul 2016 13:17:51 +0200 Subject: [PATCH] move encoding to vmess --- common/protocol/encoding.go | 25 ------------------- .../raw => proxy/vmess/encoding}/auth.go | 2 +- .../raw => proxy/vmess/encoding}/client.go | 2 +- .../raw => proxy/vmess/encoding}/commands.go | 2 +- .../vmess/encoding}/commands_test.go | 4 +-- .../raw => proxy/vmess/encoding}/const.go | 2 +- .../vmess/encoding}/encoding_test.go | 4 +-- .../raw => proxy/vmess/encoding}/server.go | 2 +- proxy/vmess/inbound/inbound.go | 4 +-- proxy/vmess/outbound/outbound.go | 10 ++++---- 10 files changed, 16 insertions(+), 41 deletions(-) delete mode 100644 common/protocol/encoding.go rename {common/protocol/raw => proxy/vmess/encoding}/auth.go (88%) rename {common/protocol/raw => proxy/vmess/encoding}/client.go (99%) rename {common/protocol/raw => proxy/vmess/encoding}/commands.go (99%) rename {common/protocol/raw => proxy/vmess/encoding}/commands_test.go (92%) rename {common/protocol/raw => proxy/vmess/encoding}/const.go (87%) rename {common/protocol/raw => proxy/vmess/encoding}/encoding_test.go (95%) rename {common/protocol/raw => proxy/vmess/encoding}/server.go (99%) diff --git a/common/protocol/encoding.go b/common/protocol/encoding.go deleted file mode 100644 index b3f4da62..00000000 --- a/common/protocol/encoding.go +++ /dev/null @@ -1,25 +0,0 @@ -package protocol - -import ( - "io" -) - -type RequestEncoder interface { - EncodeRequestHeader(*RequestHeader, io.Writer) - EncodeRequestBody(io.Writer) io.Writer -} - -type RequestDecoder interface { - DecodeRequestHeader(io.Reader) (*RequestHeader, error) - DecodeRequestBody(io.Reader) io.Reader -} - -type ResponseEncoder interface { - EncodeResponseHeader(*ResponseHeader, io.Writer) - EncodeResponseBody(io.Writer) io.Writer -} - -type ResponseDecoder interface { - DecodeResponseHeader(io.Reader) (*ResponseHeader, error) - DecodeResponseBody(io.Reader) io.Reader -} diff --git a/common/protocol/raw/auth.go b/proxy/vmess/encoding/auth.go similarity index 88% rename from common/protocol/raw/auth.go rename to proxy/vmess/encoding/auth.go index 1e3725fd..885c7252 100644 --- a/common/protocol/raw/auth.go +++ b/proxy/vmess/encoding/auth.go @@ -1,4 +1,4 @@ -package raw +package encoding import ( "hash/fnv" diff --git a/common/protocol/raw/client.go b/proxy/vmess/encoding/client.go similarity index 99% rename from common/protocol/raw/client.go rename to proxy/vmess/encoding/client.go index 8f89d3f3..c0432585 100644 --- a/common/protocol/raw/client.go +++ b/proxy/vmess/encoding/client.go @@ -1,4 +1,4 @@ -package raw +package encoding import ( "crypto/md5" diff --git a/common/protocol/raw/commands.go b/proxy/vmess/encoding/commands.go similarity index 99% rename from common/protocol/raw/commands.go rename to proxy/vmess/encoding/commands.go index 1e632299..af45ed42 100644 --- a/common/protocol/raw/commands.go +++ b/proxy/vmess/encoding/commands.go @@ -1,4 +1,4 @@ -package raw +package encoding import ( "errors" diff --git a/common/protocol/raw/commands_test.go b/proxy/vmess/encoding/commands_test.go similarity index 92% rename from common/protocol/raw/commands_test.go rename to proxy/vmess/encoding/commands_test.go index ab334e2d..93615c8d 100644 --- a/common/protocol/raw/commands_test.go +++ b/proxy/vmess/encoding/commands_test.go @@ -1,12 +1,12 @@ -package raw_test +package encoding_test import ( "testing" "github.com/v2ray/v2ray-core/common/alloc" "github.com/v2ray/v2ray-core/common/protocol" - . "github.com/v2ray/v2ray-core/common/protocol/raw" "github.com/v2ray/v2ray-core/common/uuid" + . "github.com/v2ray/v2ray-core/proxy/vmess/encoding" "github.com/v2ray/v2ray-core/testing/assert" ) diff --git a/common/protocol/raw/const.go b/proxy/vmess/encoding/const.go similarity index 87% rename from common/protocol/raw/const.go rename to proxy/vmess/encoding/const.go index 6731f5c3..3f2a1503 100644 --- a/common/protocol/raw/const.go +++ b/proxy/vmess/encoding/const.go @@ -1,4 +1,4 @@ -package raw +package encoding const ( Version = byte(1) diff --git a/common/protocol/raw/encoding_test.go b/proxy/vmess/encoding/encoding_test.go similarity index 95% rename from common/protocol/raw/encoding_test.go rename to proxy/vmess/encoding/encoding_test.go index 19c7e3e5..9cc0b225 100644 --- a/common/protocol/raw/encoding_test.go +++ b/proxy/vmess/encoding/encoding_test.go @@ -1,4 +1,4 @@ -package raw_test +package encoding_test import ( "testing" @@ -6,8 +6,8 @@ import ( "github.com/v2ray/v2ray-core/common/alloc" v2net "github.com/v2ray/v2ray-core/common/net" "github.com/v2ray/v2ray-core/common/protocol" - . "github.com/v2ray/v2ray-core/common/protocol/raw" "github.com/v2ray/v2ray-core/common/uuid" + . "github.com/v2ray/v2ray-core/proxy/vmess/encoding" "github.com/v2ray/v2ray-core/testing/assert" ) diff --git a/common/protocol/raw/server.go b/proxy/vmess/encoding/server.go similarity index 99% rename from common/protocol/raw/server.go rename to proxy/vmess/encoding/server.go index 24799040..f63de500 100644 --- a/common/protocol/raw/server.go +++ b/proxy/vmess/encoding/server.go @@ -1,4 +1,4 @@ -package raw +package encoding import ( "crypto/md5" diff --git a/proxy/vmess/inbound/inbound.go b/proxy/vmess/inbound/inbound.go index b71090c5..1479b0fd 100644 --- a/proxy/vmess/inbound/inbound.go +++ b/proxy/vmess/inbound/inbound.go @@ -12,10 +12,10 @@ import ( "github.com/v2ray/v2ray-core/common/log" v2net "github.com/v2ray/v2ray-core/common/net" "github.com/v2ray/v2ray-core/common/protocol" - "github.com/v2ray/v2ray-core/common/protocol/raw" "github.com/v2ray/v2ray-core/common/uuid" "github.com/v2ray/v2ray-core/proxy" "github.com/v2ray/v2ray-core/proxy/internal" + "github.com/v2ray/v2ray-core/proxy/vmess/encoding" vmessio "github.com/v2ray/v2ray-core/proxy/vmess/io" "github.com/v2ray/v2ray-core/transport/internet" ) @@ -142,7 +142,7 @@ func (this *VMessInboundHandler) HandleConnection(connection internet.Connection this.RUnlock() return } - session := raw.NewServerSession(this.clients) + session := encoding.NewServerSession(this.clients) defer session.Release() request, err := session.DecodeRequestHeader(reader) diff --git a/proxy/vmess/outbound/outbound.go b/proxy/vmess/outbound/outbound.go index b6b7cdc3..55e9aa80 100644 --- a/proxy/vmess/outbound/outbound.go +++ b/proxy/vmess/outbound/outbound.go @@ -10,10 +10,10 @@ import ( "github.com/v2ray/v2ray-core/common/log" v2net "github.com/v2ray/v2ray-core/common/net" "github.com/v2ray/v2ray-core/common/protocol" - "github.com/v2ray/v2ray-core/common/protocol/raw" "github.com/v2ray/v2ray-core/common/retry" "github.com/v2ray/v2ray-core/proxy" "github.com/v2ray/v2ray-core/proxy/internal" + "github.com/v2ray/v2ray-core/proxy/vmess/encoding" vmessio "github.com/v2ray/v2ray-core/proxy/vmess/io" "github.com/v2ray/v2ray-core/transport/internet" "github.com/v2ray/v2ray-core/transport/ray" @@ -52,7 +52,7 @@ func (this *VMessOutboundHandler) Dispatch(target v2net.Destination, payload *al command = protocol.RequestCommandUDP } request := &protocol.RequestHeader{ - Version: raw.Version, + Version: encoding.Version, User: rec.PickUser(), Command: command, Address: target.Address(), @@ -74,7 +74,7 @@ func (this *VMessOutboundHandler) Dispatch(target v2net.Destination, payload *al requestFinish.Lock() responseFinish.Lock() - session := raw.NewClientSession(protocol.DefaultIDHash) + session := encoding.NewClientSession(protocol.DefaultIDHash) go this.handleRequest(session, conn, request, payload, input, &requestFinish) go this.handleResponse(session, conn, request, rec.Destination, output, &responseFinish) @@ -84,7 +84,7 @@ func (this *VMessOutboundHandler) Dispatch(target v2net.Destination, payload *al return nil } -func (this *VMessOutboundHandler) handleRequest(session *raw.ClientSession, conn internet.Connection, request *protocol.RequestHeader, payload *alloc.Buffer, input v2io.Reader, finish *sync.Mutex) { +func (this *VMessOutboundHandler) handleRequest(session *encoding.ClientSession, conn internet.Connection, request *protocol.RequestHeader, payload *alloc.Buffer, input v2io.Reader, finish *sync.Mutex) { defer finish.Unlock() writer := v2io.NewBufferedWriter(conn) @@ -116,7 +116,7 @@ func (this *VMessOutboundHandler) handleRequest(session *raw.ClientSession, conn return } -func (this *VMessOutboundHandler) handleResponse(session *raw.ClientSession, conn internet.Connection, request *protocol.RequestHeader, dest v2net.Destination, output v2io.Writer, finish *sync.Mutex) { +func (this *VMessOutboundHandler) handleResponse(session *encoding.ClientSession, conn internet.Connection, request *protocol.RequestHeader, dest v2net.Destination, output v2io.Writer, finish *sync.Mutex) { defer finish.Unlock() reader := v2io.NewBufferedReader(conn)