check ctx to fix. (#841)

This commit is contained in:
rurirei 2021-04-02 20:11:07 +08:00 committed by GitHub
parent 3476a0e1d1
commit 44151f3420
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 4 deletions

View File

@ -47,15 +47,15 @@ func StartInstance(configFormat string, configBytes []byte) (*Instance, error) {
//
// v2ray:api:stable
func Dial(ctx context.Context, v *Instance, dest net.Destination) (net.Conn, error) {
if FromContext(ctx) == nil {
ctx = context.WithValue(ctx, v2rayKey, v)
}
dispatcher := v.GetFeature(routing.DispatcherType())
if dispatcher == nil {
return nil, newError("routing.Dispatcher is not registered in V2Ray core")
}
if ctx.Value(v2rayKey) == nil {
ctx = context.WithValue(ctx, v2rayKey, v)
}
r, err := dispatcher.(routing.Dispatcher).Dispatch(ctx, dest)
if err != nil {
return nil, err
@ -76,6 +76,10 @@ func Dial(ctx context.Context, v *Instance, dest net.Destination) (net.Conn, err
//
// v2ray:api:beta
func DialUDP(ctx context.Context, v *Instance) (net.PacketConn, error) {
if FromContext(ctx) == nil {
ctx = context.WithValue(ctx, v2rayKey, v)
}
dispatcher := v.GetFeature(routing.DispatcherType())
if dispatcher == nil {
return nil, newError("routing.Dispatcher is not registered in V2Ray core")