2026-01-17 21:29:50 +08:00
|
|
|
package ctx
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2026-02-12 22:56:06 +08:00
|
|
|
|
|
|
|
|
"github.com/xtls/xray-core/proxy/hysteria/account"
|
2026-01-17 21:29:50 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type key int
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
requireDatagram key = iota
|
2026-02-12 22:56:06 +08:00
|
|
|
validator
|
2026-01-17 21:29:50 +08:00
|
|
|
)
|
|
|
|
|
|
2026-01-18 12:25:36 +08:00
|
|
|
func ContextWithRequireDatagram(ctx context.Context, udp bool) context.Context {
|
|
|
|
|
if !udp {
|
|
|
|
|
return ctx
|
|
|
|
|
}
|
2026-01-17 21:29:50 +08:00
|
|
|
return context.WithValue(ctx, requireDatagram, struct{}{})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func RequireDatagramFromContext(ctx context.Context) bool {
|
|
|
|
|
_, ok := ctx.Value(requireDatagram).(struct{})
|
|
|
|
|
return ok
|
|
|
|
|
}
|
2026-02-12 22:56:06 +08:00
|
|
|
|
|
|
|
|
func ContextWithValidator(ctx context.Context, v *account.Validator) context.Context {
|
|
|
|
|
return context.WithValue(ctx, validator, v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ValidatorFromContext(ctx context.Context) *account.Validator {
|
|
|
|
|
v, _ := ctx.Value(validator).(*account.Validator)
|
|
|
|
|
return v
|
|
|
|
|
}
|