mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-06-12 03:19:36 +03:00
Add observatory / latestPing balancing strategy
Co-authored-by: Shelikhoo <xiaokangwang@outlook.com>
This commit is contained in:
@ -11,6 +11,7 @@ const (
|
||||
contentSessionKey
|
||||
muxPreferedSessionKey
|
||||
sockoptSessionKey
|
||||
trackedConnectionErrorKey
|
||||
)
|
||||
|
||||
// ContextWithID returns a new context with the given ID.
|
||||
@ -84,3 +85,33 @@ func SockoptFromContext(ctx context.Context) *Sockopt {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetForcedOutboundTagFromContext(ctx context.Context) string {
|
||||
if ContentFromContext(ctx) == nil {
|
||||
return ""
|
||||
}
|
||||
return ContentFromContext(ctx).Attribute("forcedOutboundTag")
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
type TrackedRequestErrorFeedback interface {
|
||||
SubmitError(err error)
|
||||
}
|
||||
|
||||
func SubmitOutboundErrorToOriginator(ctx context.Context, err error) {
|
||||
if errorTracker := ctx.Value(trackedConnectionErrorKey); errorTracker != nil {
|
||||
errorTracker := errorTracker.(TrackedRequestErrorFeedback)
|
||||
errorTracker.SubmitError(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TrackedConnectionError(ctx context.Context, tracker TrackedRequestErrorFeedback) context.Context {
|
||||
return context.WithValue(ctx, trackedConnectionErrorKey, tracker)
|
||||
}
|
||||
|
Reference in New Issue
Block a user