Browse Source

cleanup unused scenarios

Darien Raymond 7 years ago
parent
commit
c2566e1331
4 changed files with 23 additions and 41 deletions
  1. 2 3
      app/router/condition.go
  2. 21 3
      app/router/router.go
  3. 0 26
      proxy/context.go
  4. 0 9
      proxy/freedom/freedom.go

+ 2 - 3
app/router/condition.go

@@ -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() {

+ 21 - 3
app/router/router.go

@@ -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

+ 0 - 26
proxy/context.go

@@ -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
-}

+ 0 - 9
proxy/freedom/freedom.go

@@ -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))