mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-17 23:06:30 -05:00
check ctx to fix. (#841)
This commit is contained in:
parent
3476a0e1d1
commit
44151f3420
12
functions.go
12
functions.go
@ -47,15 +47,15 @@ func StartInstance(configFormat string, configBytes []byte) (*Instance, error) {
|
|||||||
//
|
//
|
||||||
// v2ray:api:stable
|
// v2ray:api:stable
|
||||||
func Dial(ctx context.Context, v *Instance, dest net.Destination) (net.Conn, error) {
|
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())
|
dispatcher := v.GetFeature(routing.DispatcherType())
|
||||||
if dispatcher == nil {
|
if dispatcher == nil {
|
||||||
return nil, newError("routing.Dispatcher is not registered in V2Ray core")
|
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)
|
r, err := dispatcher.(routing.Dispatcher).Dispatch(ctx, dest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -76,6 +76,10 @@ func Dial(ctx context.Context, v *Instance, dest net.Destination) (net.Conn, err
|
|||||||
//
|
//
|
||||||
// v2ray:api:beta
|
// v2ray:api:beta
|
||||||
func DialUDP(ctx context.Context, v *Instance) (net.PacketConn, error) {
|
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())
|
dispatcher := v.GetFeature(routing.DispatcherType())
|
||||||
if dispatcher == nil {
|
if dispatcher == nil {
|
||||||
return nil, newError("routing.Dispatcher is not registered in V2Ray core")
|
return nil, newError("routing.Dispatcher is not registered in V2Ray core")
|
||||||
|
Loading…
Reference in New Issue
Block a user