2017-01-12 23:56:21 +00:00
|
|
|
package proxy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2017-01-26 19:46:44 +00:00
|
|
|
|
|
|
|
"v2ray.com/core/common/net"
|
2017-01-12 23:56:21 +00:00
|
|
|
)
|
|
|
|
|
2018-09-18 21:09:54 +00:00
|
|
|
type key uint32
|
2017-01-12 23:56:21 +00:00
|
|
|
|
|
|
|
const (
|
2018-09-18 21:09:54 +00:00
|
|
|
resolvedIPsKey key = iota
|
2017-01-12 23:56:21 +00:00
|
|
|
)
|
|
|
|
|
2017-11-15 11:55:47 +00:00
|
|
|
type IPResolver interface {
|
|
|
|
Resolve() []net.Address
|
2017-01-26 19:46:44 +00:00
|
|
|
}
|
|
|
|
|
2017-11-15 11:55:47 +00: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 19:46:44 +00:00
|
|
|
return ips, ok
|
|
|
|
}
|