context.go 451 B

1234567891011121314151617181920212223242526
  1. package proxy
  2. import (
  3. "context"
  4. "v2ray.com/core/common/net"
  5. )
  6. type key uint32
  7. const (
  8. resolvedIPsKey key = iota
  9. )
  10. type IPResolver interface {
  11. Resolve() []net.Address
  12. }
  13. func ContextWithResolveIPs(ctx context.Context, f IPResolver) context.Context {
  14. return context.WithValue(ctx, resolvedIPsKey, f)
  15. }
  16. func ResolvedIPsFromContext(ctx context.Context) (IPResolver, bool) {
  17. ips, ok := ctx.Value(resolvedIPsKey).(IPResolver)
  18. return ips, ok
  19. }