mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-30 01:08:33 +00:00
parent
c0c23fdfeb
commit
3dd3bf94d4
3 changed files with 144 additions and 1 deletions
|
@ -40,6 +40,22 @@ func ContextWithOutbounds(ctx context.Context, outbounds []*Outbound) context.Co
|
|||
return context.WithValue(ctx, outboundSessionKey, outbounds)
|
||||
}
|
||||
|
||||
func ContextCloneOutbounds(ctx context.Context) context.Context {
|
||||
outbounds := OutboundsFromContext(ctx)
|
||||
newOutbounds := make([]*Outbound, len(outbounds))
|
||||
for i, ob := range outbounds {
|
||||
if ob == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// copy outbound by value
|
||||
v := *ob
|
||||
newOutbounds[i] = &v
|
||||
}
|
||||
|
||||
return ContextWithOutbounds(ctx, newOutbounds)
|
||||
}
|
||||
|
||||
func OutboundsFromContext(ctx context.Context) []*Outbound {
|
||||
if outbounds, ok := ctx.Value(outboundSessionKey).([]*Outbound); ok {
|
||||
return outbounds
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue