1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-30 11:05:24 +00:00

integrate mux in vmess server

This commit is contained in:
Darien Raymond 2017-05-17 21:13:01 +02:00
parent fcafd4e8f8
commit 06d4c37889
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
6 changed files with 60 additions and 44 deletions

View File

@ -82,12 +82,13 @@ type Client struct {
concurrency uint32
}
var muxCoolDestination = net.TCPDestination(net.DomainAddress("v1.mux.cool"), net.Port(9527))
var muxCoolAddress = net.DomainAddress("v1.mux.cool")
var muxCoolPort = net.Port(9527)
// NewClient creates a new mux.Client.
func NewClient(p proxy.Outbound, dialer proxy.Dialer, m *ClientManager) (*Client, error) {
ctx, cancel := context.WithCancel(context.Background())
ctx = proxy.ContextWithTarget(ctx, muxCoolDestination)
ctx = proxy.ContextWithTarget(ctx, net.TCPDestination(muxCoolAddress, muxCoolPort))
pipe := ray.NewRay(ctx)
go p.Process(ctx, pipe, dialer)
c := &Client{
@ -274,7 +275,7 @@ func NewServer(ctx context.Context) *Server {
}
func (s *Server) Dispatch(ctx context.Context, dest net.Destination) (ray.InboundRay, error) {
if dest != muxCoolDestination {
if dest.Address != muxCoolAddress {
return s.dispatcher.Dispatch(ctx, dest)
}

View File

@ -13,6 +13,7 @@ type RequestCommand byte
const (
RequestCommandTCP = RequestCommand(0x01)
RequestCommandUDP = RequestCommand(0x02)
RequestCommandMux = RequestCommand(0x03)
)
func (c RequestCommand) TransferType() TransferType {

View File

@ -81,6 +81,8 @@ func (v *ClientSession) EncodeRequestHeader(header *protocol.RequestHeader, writ
}
security := byte(padingLen<<4) | byte(header.Security)
buffer = append(buffer, security, byte(0), byte(header.Command))
if header.Command != protocol.RequestCommandMux {
buffer = header.Port.Bytes(buffer)
switch header.Address.Family() {
@ -94,6 +96,7 @@ func (v *ClientSession) EncodeRequestHeader(header *protocol.RequestHeader, writ
buffer = append(buffer, AddrTypeDomain, byte(len(header.Address.Domain())))
buffer = append(buffer, header.Address.Domain()...)
}
}
if padingLen > 0 {
pading := make([]byte, padingLen)

View File

@ -170,6 +170,7 @@ func (v *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
// 1 bytes reserved
request.Command = protocol.RequestCommand(buffer[37])
if request.Command != protocol.RequestCommandMux {
request.Port = net.PortFromBytes(buffer[38:40])
switch buffer[40] {
@ -203,6 +204,7 @@ func (v *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
bufferLen += 1 + domainLength
request.Address = net.DomainAddress(string(buffer[42 : 42+domainLength]))
}
}
if padingLen > 0 {
_, err = io.ReadFull(decryptor, buffer[bufferLen:bufferLen+padingLen])

View File

@ -185,6 +185,12 @@ func (v *Handler) Process(ctx context.Context, network net.Network, connection i
}
return err
}
if request.Command == protocol.RequestCommandMux {
request.Address = net.DomainAddress("v1.mux.com")
request.Port = net.Port(0)
}
log.Access(connection.RemoteAddr(), request.Destination(), log.AccessAccepted, "")
log.Trace(newError("received request for ", request.Destination()))

View File

@ -76,6 +76,9 @@ func (v *Handler) Process(ctx context.Context, outboundRay ray.OutboundRay, dial
if target.Network == net.Network_UDP {
command = protocol.RequestCommandUDP
}
//if target.Address.Family().IsDomain() && target.Address.Domain() == "v1.mux.com" {
// command = protocol.RequestCommandMux
//}
request := &protocol.RequestHeader{
Version: encoding.Version,
User: rec.PickUser(),