Xray-core/transport/internet/tagged/taggedimpl/impl.go
yuhan6665 e93da4bd02
Fix some tests and format code (#830)
* Increase some tls test timeout

* Fix TestUserValidator

* Change all tests to VMessAEAD

Old VMess MD5 tests will be rejected and fail in 2022

* Chore: auto format code
2021-12-14 19:28:47 -05:00

47 lines
1.3 KiB
Go

package taggedimpl
import (
"context"
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/common/net/cnc"
"github.com/xtls/xray-core/common/session"
"github.com/xtls/xray-core/core"
"github.com/xtls/xray-core/features/routing"
"github.com/xtls/xray-core/transport/internet/tagged"
)
func DialTaggedOutbound(ctx context.Context, dest net.Destination, tag string) (net.Conn, error) {
var dispatcher routing.Dispatcher
if core.FromContext(ctx) == nil {
return nil, newError("Instance context variable is not in context, dial denied. ")
}
if err := core.RequireFeatures(ctx, func(dispatcherInstance routing.Dispatcher) {
dispatcher = dispatcherInstance
}); err != nil {
return nil, newError("Required Feature dispatcher not resolved").Base(err)
}
content := new(session.Content)
content.SkipDNSResolve = true
ctx = session.ContextWithContent(ctx, content)
ctx = session.SetForcedOutboundTagToContext(ctx, tag)
r, err := dispatcher.Dispatch(ctx, dest)
if err != nil {
return nil, err
}
var readerOpt cnc.ConnectionOption
if dest.Network == net.Network_TCP {
readerOpt = cnc.ConnectionOutputMulti(r.Reader)
} else {
readerOpt = cnc.ConnectionOutputMultiUDP(r.Reader)
}
return cnc.NewConnection(cnc.ConnectionInputMulti(r.Writer), readerOpt), nil
}
func init() {
tagged.Dialer = DialTaggedOutbound
}