Browse Source

move proxy.Dialer to internet.Dialer

Darien Raymond 7 years ago
parent
commit
17e51b277b

+ 4 - 3
app/proxyman/mux/mux.go

@@ -21,6 +21,7 @@ import (
 	"v2ray.com/core/common/vio"
 	"v2ray.com/core/features/routing"
 	"v2ray.com/core/proxy"
+	"v2ray.com/core/transport/internet"
 	"v2ray.com/core/transport/pipe"
 )
 
@@ -32,11 +33,11 @@ type ClientManager struct {
 	access  sync.Mutex
 	clients []*Client
 	proxy   proxy.Outbound
-	dialer  proxy.Dialer
+	dialer  internet.Dialer
 	config  *proxyman.MultiplexingConfig
 }
 
-func NewClientManager(p proxy.Outbound, d proxy.Dialer, c *proxyman.MultiplexingConfig) *ClientManager {
+func NewClientManager(p proxy.Outbound, d internet.Dialer, c *proxyman.MultiplexingConfig) *ClientManager {
 	return &ClientManager{
 		proxy:  p,
 		dialer: d,
@@ -89,7 +90,7 @@ var muxCoolAddress = net.DomainAddress("v1.mux.cool")
 var muxCoolPort = net.Port(9527)
 
 // NewClient creates a new mux.Client.
-func NewClient(pctx context.Context, p proxy.Outbound, dialer proxy.Dialer, m *ClientManager) (*Client, error) {
+func NewClient(pctx context.Context, p proxy.Outbound, dialer internet.Dialer, m *ClientManager) (*Client, error) {
 	ctx := session.ContextWithOutbound(context.Background(), &session.Outbound{
 		Target: net.TCPDestination(muxCoolAddress, muxCoolPort),
 	})

+ 1 - 1
app/proxyman/outbound/handler.go

@@ -103,7 +103,7 @@ func (h *Handler) Dispatch(ctx context.Context, link *vio.Link) {
 	}
 }
 
-// Dial implements proxy.Dialer.Dial().
+// Dial implements internet.Dialer.
 func (h *Handler) Dial(ctx context.Context, dest net.Destination) (internet.Connection, error) {
 	if h.senderSettings != nil {
 		if h.senderSettings.ProxySettings.HasTag() {

+ 2 - 2
proxy/blackhole/blackhole.go

@@ -9,7 +9,7 @@ import (
 
 	"v2ray.com/core/common"
 	"v2ray.com/core/common/vio"
-	"v2ray.com/core/proxy"
+	"v2ray.com/core/transport/internet"
 	"v2ray.com/core/transport/pipe"
 )
 
@@ -30,7 +30,7 @@ func New(ctx context.Context, config *Config) (*Handler, error) {
 }
 
 // Process implements OutboundHandler.Dispatch().
-func (h *Handler) Process(ctx context.Context, link *vio.Link, dialer proxy.Dialer) error {
+func (h *Handler) Process(ctx context.Context, link *vio.Link, dialer internet.Dialer) error {
 	nBytes := h.response.WriteTo(link.Writer)
 	if nBytes > 0 {
 		// Sleep a little here to make sure the response is sent to client.

+ 1 - 1
proxy/freedom/freedom.go

@@ -87,7 +87,7 @@ func isValidAddress(addr *net.IPOrDomain) bool {
 }
 
 // Process implements proxy.Outbound.
-func (h *Handler) Process(ctx context.Context, link *vio.Link, dialer proxy.Dialer) error {
+func (h *Handler) Process(ctx context.Context, link *vio.Link, dialer internet.Dialer) error {
 	outbound := session.OutboundFromContext(ctx)
 	if outbound == nil || !outbound.Target.IsValid() {
 		return newError("target not specified.")

+ 2 - 2
proxy/mtproto/client.go

@@ -10,7 +10,7 @@ import (
 	"v2ray.com/core/common/session"
 	"v2ray.com/core/common/task"
 	"v2ray.com/core/common/vio"
-	"v2ray.com/core/proxy"
+	"v2ray.com/core/transport/internet"
 )
 
 type Client struct {
@@ -20,7 +20,7 @@ func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
 	return &Client{}, nil
 }
 
-func (c *Client) Process(ctx context.Context, link *vio.Link, dialer proxy.Dialer) error {
+func (c *Client) Process(ctx context.Context, link *vio.Link, dialer internet.Dialer) error {
 	outbound := session.OutboundFromContext(ctx)
 	if outbound == nil || !outbound.Target.IsValid() {
 		return newError("unknown destination.")

+ 1 - 7
proxy/proxy.go

@@ -27,13 +27,7 @@ type Inbound interface {
 // An Outbound process outbound connections.
 type Outbound interface {
 	// Process processes the given connection. The given dialer may be used to dial a system outbound connection.
-	Process(context.Context, *vio.Link, Dialer) error
-}
-
-// Dialer is used by OutboundHandler for creating outbound connections.
-type Dialer interface {
-	// Dial dials a system connection to the given destination.
-	Dial(ctx context.Context, destination net.Destination) (internet.Connection, error)
+	Process(context.Context, *vio.Link, internet.Dialer) error
 }
 
 // UserManager is the interface for Inbounds and Outbounds that can manage their users.

+ 1 - 2
proxy/shadowsocks/client.go

@@ -14,7 +14,6 @@ import (
 	"v2ray.com/core/common/task"
 	"v2ray.com/core/common/vio"
 	"v2ray.com/core/features/policy"
-	"v2ray.com/core/proxy"
 	"v2ray.com/core/transport/internet"
 )
 
@@ -47,7 +46,7 @@ func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
 }
 
 // Process implements OutboundHandler.Process().
-func (c *Client) Process(ctx context.Context, link *vio.Link, dialer proxy.Dialer) error {
+func (c *Client) Process(ctx context.Context, link *vio.Link, dialer internet.Dialer) error {
 	outbound := session.OutboundFromContext(ctx)
 	if outbound == nil || !outbound.Target.IsValid() {
 		return newError("target not specified")

+ 5 - 7
proxy/socks/client.go

@@ -4,19 +4,17 @@ import (
 	"context"
 	"time"
 
-	"v2ray.com/core/common/session"
-	"v2ray.com/core/common/task"
-	"v2ray.com/core/common/vio"
-	"v2ray.com/core/features/policy"
-
 	"v2ray.com/core"
 	"v2ray.com/core/common"
 	"v2ray.com/core/common/buf"
 	"v2ray.com/core/common/net"
 	"v2ray.com/core/common/protocol"
 	"v2ray.com/core/common/retry"
+	"v2ray.com/core/common/session"
 	"v2ray.com/core/common/signal"
-	"v2ray.com/core/proxy"
+	"v2ray.com/core/common/task"
+	"v2ray.com/core/common/vio"
+	"v2ray.com/core/features/policy"
 	"v2ray.com/core/transport/internet"
 )
 
@@ -48,7 +46,7 @@ func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
 }
 
 // Process implements proxy.Outbound.Process.
-func (c *Client) Process(ctx context.Context, link *vio.Link, dialer proxy.Dialer) error {
+func (c *Client) Process(ctx context.Context, link *vio.Link, dialer internet.Dialer) error {
 	outbound := session.OutboundFromContext(ctx)
 	if outbound == nil || !outbound.Target.IsValid() {
 		return newError("target not specified.")

+ 1 - 2
proxy/vmess/outbound/outbound.go

@@ -18,7 +18,6 @@ import (
 	"v2ray.com/core/common/task"
 	"v2ray.com/core/common/vio"
 	"v2ray.com/core/features/policy"
-	"v2ray.com/core/proxy"
 	"v2ray.com/core/proxy/vmess"
 	"v2ray.com/core/proxy/vmess/encoding"
 	"v2ray.com/core/transport/internet"
@@ -53,7 +52,7 @@ func New(ctx context.Context, config *Config) (*Handler, error) {
 }
 
 // Process implements proxy.Outbound.Process().
-func (v *Handler) Process(ctx context.Context, link *vio.Link, dialer proxy.Dialer) error {
+func (v *Handler) Process(ctx context.Context, link *vio.Link, dialer internet.Dialer) error {
 	var rec *protocol.ServerSpec
 	var conn internet.Connection
 

+ 10 - 4
transport/internet/dialer.go

@@ -7,15 +7,21 @@ import (
 	"v2ray.com/core/common/session"
 )
 
-// Dialer is an interface to dial network connection to a specific destination.
-type Dialer func(ctx context.Context, dest net.Destination) (Connection, error)
+// Dialer is the interface for dialing outbound connections.
+type Dialer interface {
+	// Dial dials a system connection to the given destination.
+	Dial(ctx context.Context, destination net.Destination) (Connection, error)
+}
+
+// dialFunc is an interface to dial network connection to a specific destination.
+type dialFunc func(ctx context.Context, dest net.Destination) (Connection, error)
 
 var (
-	transportDialerCache = make(map[string]Dialer)
+	transportDialerCache = make(map[string]dialFunc)
 )
 
 // RegisterTransportDialer registers a Dialer with given name.
-func RegisterTransportDialer(protocol string, dialer Dialer) error {
+func RegisterTransportDialer(protocol string, dialer dialFunc) error {
 	if _, found := transportDialerCache[protocol]; found {
 		return newError(protocol, " dialer already registered").AtError()
 	}