1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-17 13:05:24 +00:00

cleanup unused scenarios

This commit is contained in:
Darien Raymond 2018-10-22 22:40:53 +02:00
parent 17e51b277b
commit c2566e1331
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
4 changed files with 23 additions and 41 deletions

View File

@ -8,7 +8,6 @@ import (
"v2ray.com/core/common/net"
"v2ray.com/core/common/session"
"v2ray.com/core/common/strmatcher"
"v2ray.com/core/proxy"
)
type Condition interface {
@ -155,7 +154,7 @@ func targetFromContent(ctx context.Context) net.Destination {
func (v *CIDRMatcher) Apply(ctx context.Context) bool {
ips := make([]net.IP, 0, 4)
if resolver, ok := proxy.ResolvedIPsFromContext(ctx); ok {
if resolver, ok := ResolvedIPsFromContext(ctx); ok {
resolvedIPs := resolver.Resolve()
for _, rip := range resolvedIPs {
if !rip.Family().IsIPv6() {
@ -198,7 +197,7 @@ func NewIPv4Matcher(ipnet *net.IPNetTable, onSource bool) *IPv4Matcher {
func (v *IPv4Matcher) Apply(ctx context.Context) bool {
ips := make([]net.IP, 0, 4)
if resolver, ok := proxy.ResolvedIPsFromContext(ctx); ok {
if resolver, ok := ResolvedIPsFromContext(ctx); ok {
resolvedIPs := resolver.Resolve()
for _, rip := range resolvedIPs {
if !rip.Family().IsIPv4() {

View File

@ -11,9 +11,27 @@ import (
"v2ray.com/core/common/session"
"v2ray.com/core/features/dns"
"v2ray.com/core/features/routing"
"v2ray.com/core/proxy"
)
type key uint32
const (
resolvedIPsKey key = iota
)
type IPResolver interface {
Resolve() []net.Address
}
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)
return ips, ok
}
func init() {
common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
r := new(Router)
@ -89,7 +107,7 @@ func (r *Router) PickRoute(ctx context.Context) (string, error) {
if r.domainStrategy == Config_IpOnDemand {
if outbound != nil && outbound.Target.IsValid() && outbound.Target.Address.Family().IsDomain() {
resolver.domain = outbound.Target.Address.Domain()
ctx = proxy.ContextWithResolveIPs(ctx, resolver)
ctx = ContextWithResolveIPs(ctx, resolver)
}
}
@ -108,7 +126,7 @@ func (r *Router) PickRoute(ctx context.Context) (string, error) {
resolver.domain = dest.Address.Domain()
ips := resolver.Resolve()
if len(ips) > 0 {
ctx = proxy.ContextWithResolveIPs(ctx, resolver)
ctx = ContextWithResolveIPs(ctx, resolver)
for _, rule := range r.rules {
if rule.Apply(ctx) {
return rule.Tag, nil

View File

@ -1,26 +0,0 @@
package proxy
import (
"context"
"v2ray.com/core/common/net"
)
type key uint32
const (
resolvedIPsKey key = iota
)
type IPResolver interface {
Resolve() []net.Address
}
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)
return ips, ok
}

View File

@ -18,7 +18,6 @@ import (
"v2ray.com/core/common/vio"
"v2ray.com/core/features/dns"
"v2ray.com/core/features/policy"
"v2ray.com/core/proxy"
"v2ray.com/core/transport/internet"
)
@ -59,14 +58,6 @@ func (h *Handler) policy() policy.Session {
}
func (h *Handler) resolveIP(ctx context.Context, domain string) net.Address {
if resolver, ok := proxy.ResolvedIPsFromContext(ctx); ok {
ips := resolver.Resolve()
if len(ips) == 0 {
return nil
}
return ips[dice.Roll(len(ips))]
}
ips, err := h.dns.LookupIP(domain)
if err != nil {
newError("failed to get IP address for domain ", domain).Base(err).WriteToLog(session.ExportIDToError(ctx))