mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-29 16:58:34 +00:00
Add observatory / latestPing balancing strategy
Co-authored-by: Shelikhoo <xiaokangwang@outlook.com>
This commit is contained in:
parent
77d0419aca
commit
5c366db847
21 changed files with 1127 additions and 31 deletions
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue