diff --git a/app/proxyman/mux/mux.go b/app/proxyman/mux/mux.go index c35984d2c..6c595754e 100644 --- a/app/proxyman/mux/mux.go +++ b/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), }) diff --git a/app/proxyman/outbound/handler.go b/app/proxyman/outbound/handler.go index 47d772a58..58d21c599 100644 --- a/app/proxyman/outbound/handler.go +++ b/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() { diff --git a/proxy/blackhole/blackhole.go b/proxy/blackhole/blackhole.go index 60806db23..e9d62a191 100644 --- a/proxy/blackhole/blackhole.go +++ b/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. diff --git a/proxy/freedom/freedom.go b/proxy/freedom/freedom.go index a530008f2..d3c575265 100644 --- a/proxy/freedom/freedom.go +++ b/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.") diff --git a/proxy/mtproto/client.go b/proxy/mtproto/client.go index ef1d55bd9..350c863a7 100644 --- a/proxy/mtproto/client.go +++ b/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.") diff --git a/proxy/proxy.go b/proxy/proxy.go index f47b82ab9..520e33431 100755 --- a/proxy/proxy.go +++ b/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. diff --git a/proxy/shadowsocks/client.go b/proxy/shadowsocks/client.go index eb9e58c18..9226ec128 100644 --- a/proxy/shadowsocks/client.go +++ b/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") diff --git a/proxy/socks/client.go b/proxy/socks/client.go index b1ffd341d..2ff173ec9 100644 --- a/proxy/socks/client.go +++ b/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.") diff --git a/proxy/vmess/outbound/outbound.go b/proxy/vmess/outbound/outbound.go index cd3fcd6b8..7917b5e3f 100644 --- a/proxy/vmess/outbound/outbound.go +++ b/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 diff --git a/transport/internet/dialer.go b/transport/internet/dialer.go index efe355228..ec4ead2be 100644 --- a/transport/internet/dialer.go +++ b/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() }