1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-09 01:10:44 +00:00

create session content in the context if do not exist yet

This commit is contained in:
Shelikhoo 2021-03-06 14:33:20 +00:00
parent b585f2283a
commit 867bbb429e
No known key found for this signature in database
GPG Key ID: C4D5E79D22B25316
3 changed files with 15 additions and 5 deletions

View File

@ -295,7 +295,7 @@ func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport.
var handler outbound.Handler
if forcedOutboundTag := session.GetForcedOutboundTagFromContext(ctx); forcedOutboundTag != "" {
session.SetForcedOutboundTagToContext(ctx, "")
ctx = session.SetForcedOutboundTagToContext(ctx, "")
if h := d.ohm.GetHandler(forcedOutboundTag); h != nil {
newError("taking platform initialized detour [", forcedOutboundTag, "] for [", destination, "]").WriteToLog(session.ExportIDToError(ctx))
handler = h

View File

@ -1,6 +1,8 @@
package session
import "context"
import (
"context"
)
type sessionKey int
@ -92,8 +94,12 @@ func GetTransportLayerProxyTagFromContext(ctx context.Context) string {
return ContentFromContext(ctx).Attribute("transportLayerOutgoingTag")
}
func SetTransportLayerProxyTagToContext(ctx context.Context, tag string) {
func SetTransportLayerProxyTagToContext(ctx context.Context, tag string) context.Context {
if contentFromContext := ContentFromContext(ctx); contentFromContext == nil {
ctx = ContextWithContent(ctx, &Content{})
}
ContentFromContext(ctx).SetAttribute("transportLayerOutgoingTag", tag)
return ctx
}
func GetForcedOutboundTagFromContext(ctx context.Context) string {
@ -103,6 +109,10 @@ func GetForcedOutboundTagFromContext(ctx context.Context) string {
return ContentFromContext(ctx).Attribute("forcedOutboundTag")
}
func SetForcedOutboundTagToContext(ctx context.Context, tag string) {
func SetForcedOutboundTagToContext(ctx context.Context, tag string) context.Context {
if contentFromContext := ContentFromContext(ctx); contentFromContext == nil {
ctx = ContextWithContent(ctx, &Content{})
}
ContentFromContext(ctx).SetAttribute("forcedOutboundTag", tag)
return ctx
}

View File

@ -26,7 +26,7 @@ func DialTaggedOutbound(ctx context.Context, dest net.Destination, tag string) (
content.SkipDNSResolve = true
ctx = session.ContextWithContent(ctx, content)
session.SetForcedOutboundTagToContext(ctx, tag)
ctx = session.SetForcedOutboundTagToContext(ctx, tag)
r, err := dispatcher.Dispatch(ctx, dest)
if err != nil {