2017-01-12 18:56:21 -05:00
|
|
|
package proxy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2017-01-26 14:46:44 -05:00
|
|
|
|
|
|
|
"v2ray.com/core/common/net"
|
2017-01-12 18:56:21 -05:00
|
|
|
)
|
|
|
|
|
2018-09-18 17:09:54 -04:00
|
|
|
type key uint32
|
2017-01-12 18:56:21 -05:00
|
|
|
|
|
|
|
const (
|
2018-09-18 17:09:54 -04:00
|
|
|
resolvedIPsKey key = iota
|
2017-01-12 18:56:21 -05:00
|
|
|
)
|
|
|
|
|
2017-11-15 06:55:47 -05:00
|
|
|
type IPResolver interface {
|
|
|
|
Resolve() []net.Address
|
2017-01-26 14:46:44 -05:00
|
|
|
}
|
|
|
|
|
2017-11-15 06:55:47 -05:00
|
|
|
func ContextWithResolveIPs(ctx context.Context, f IPResolver) context.Context {
|
|
|
|
return context.WithValue(ctx, resolvedIPsKey, f)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ResolvedIPsFromContext(ctx context.Context) (IPResolver, bool) {
|
|
|
|
ips, ok := ctx.Value(resolvedIPsKey).(IPResolver)
|
2017-01-26 14:46:44 -05:00
|
|
|
return ips, ok
|
|
|
|
}
|