Add observatory / latestPing balancing strategy

Co-authored-by: Shelikhoo <xiaokangwang@outlook.com>
This commit is contained in:
世界 2021-04-09 05:20:30 +08:00
parent 77d0419aca
commit 5c366db847
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
21 changed files with 1127 additions and 31 deletions

View file

@ -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)
}