mirror of https://github.com/v2ray/v2ray-core
move encoding to vmess
parent
e304e2761d
commit
6f5b54747e
|
@ -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
|
|
||||||
}
|
|
|
@ -1,4 +1,4 @@
|
||||||
package raw
|
package encoding
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"hash/fnv"
|
"hash/fnv"
|
|
@ -1,4 +1,4 @@
|
||||||
package raw
|
package encoding
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
|
@ -1,4 +1,4 @@
|
||||||
package raw
|
package encoding
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
|
@ -1,12 +1,12 @@
|
||||||
package raw_test
|
package encoding_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/v2ray/v2ray-core/common/alloc"
|
"github.com/v2ray/v2ray-core/common/alloc"
|
||||||
"github.com/v2ray/v2ray-core/common/protocol"
|
"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/common/uuid"
|
||||||
|
. "github.com/v2ray/v2ray-core/proxy/vmess/encoding"
|
||||||
"github.com/v2ray/v2ray-core/testing/assert"
|
"github.com/v2ray/v2ray-core/testing/assert"
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package raw
|
package encoding
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Version = byte(1)
|
Version = byte(1)
|
|
@ -1,4 +1,4 @@
|
||||||
package raw_test
|
package encoding_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -6,8 +6,8 @@ import (
|
||||||
"github.com/v2ray/v2ray-core/common/alloc"
|
"github.com/v2ray/v2ray-core/common/alloc"
|
||||||
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"
|
||||||
. "github.com/v2ray/v2ray-core/common/protocol/raw"
|
|
||||||
"github.com/v2ray/v2ray-core/common/uuid"
|
"github.com/v2ray/v2ray-core/common/uuid"
|
||||||
|
. "github.com/v2ray/v2ray-core/proxy/vmess/encoding"
|
||||||
"github.com/v2ray/v2ray-core/testing/assert"
|
"github.com/v2ray/v2ray-core/testing/assert"
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package raw
|
package encoding
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
|
@ -12,10 +12,10 @@ 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/common/protocol"
|
"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/common/uuid"
|
||||||
"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"
|
||||||
|
"github.com/v2ray/v2ray-core/proxy/vmess/encoding"
|
||||||
vmessio "github.com/v2ray/v2ray-core/proxy/vmess/io"
|
vmessio "github.com/v2ray/v2ray-core/proxy/vmess/io"
|
||||||
"github.com/v2ray/v2ray-core/transport/internet"
|
"github.com/v2ray/v2ray-core/transport/internet"
|
||||||
)
|
)
|
||||||
|
@ -142,7 +142,7 @@ func (this *VMessInboundHandler) HandleConnection(connection internet.Connection
|
||||||
this.RUnlock()
|
this.RUnlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
session := raw.NewServerSession(this.clients)
|
session := encoding.NewServerSession(this.clients)
|
||||||
defer session.Release()
|
defer session.Release()
|
||||||
|
|
||||||
request, err := session.DecodeRequestHeader(reader)
|
request, err := session.DecodeRequestHeader(reader)
|
||||||
|
|
|
@ -10,10 +10,10 @@ 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/common/protocol"
|
"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/common/retry"
|
||||||
"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"
|
||||||
|
"github.com/v2ray/v2ray-core/proxy/vmess/encoding"
|
||||||
vmessio "github.com/v2ray/v2ray-core/proxy/vmess/io"
|
vmessio "github.com/v2ray/v2ray-core/proxy/vmess/io"
|
||||||
"github.com/v2ray/v2ray-core/transport/internet"
|
"github.com/v2ray/v2ray-core/transport/internet"
|
||||||
"github.com/v2ray/v2ray-core/transport/ray"
|
"github.com/v2ray/v2ray-core/transport/ray"
|
||||||
|
@ -52,7 +52,7 @@ func (this *VMessOutboundHandler) Dispatch(target v2net.Destination, payload *al
|
||||||
command = protocol.RequestCommandUDP
|
command = protocol.RequestCommandUDP
|
||||||
}
|
}
|
||||||
request := &protocol.RequestHeader{
|
request := &protocol.RequestHeader{
|
||||||
Version: raw.Version,
|
Version: encoding.Version,
|
||||||
User: rec.PickUser(),
|
User: rec.PickUser(),
|
||||||
Command: command,
|
Command: command,
|
||||||
Address: target.Address(),
|
Address: target.Address(),
|
||||||
|
@ -74,7 +74,7 @@ func (this *VMessOutboundHandler) Dispatch(target v2net.Destination, payload *al
|
||||||
requestFinish.Lock()
|
requestFinish.Lock()
|
||||||
responseFinish.Lock()
|
responseFinish.Lock()
|
||||||
|
|
||||||
session := raw.NewClientSession(protocol.DefaultIDHash)
|
session := encoding.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, rec.Destination, output, &responseFinish)
|
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
|
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()
|
defer finish.Unlock()
|
||||||
|
|
||||||
writer := v2io.NewBufferedWriter(conn)
|
writer := v2io.NewBufferedWriter(conn)
|
||||||
|
@ -116,7 +116,7 @@ func (this *VMessOutboundHandler) handleRequest(session *raw.ClientSession, conn
|
||||||
return
|
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()
|
defer finish.Unlock()
|
||||||
|
|
||||||
reader := v2io.NewBufferedReader(conn)
|
reader := v2io.NewBufferedReader(conn)
|
||||||
|
|
Loading…
Reference in New Issue