1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-14 21:36:25 -05:00

move proxy.Dialer to internet.Dialer

This commit is contained in:
Darien Raymond 2018-10-22 22:12:50 +02:00
parent 07a7597ee8
commit 17e51b277b
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
10 changed files with 28 additions and 31 deletions

View File

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

View File

@ -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) { func (h *Handler) Dial(ctx context.Context, dest net.Destination) (internet.Connection, error) {
if h.senderSettings != nil { if h.senderSettings != nil {
if h.senderSettings.ProxySettings.HasTag() { if h.senderSettings.ProxySettings.HasTag() {

View File

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

View File

@ -87,7 +87,7 @@ func isValidAddress(addr *net.IPOrDomain) bool {
} }
// Process implements proxy.Outbound. // 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) outbound := session.OutboundFromContext(ctx)
if outbound == nil || !outbound.Target.IsValid() { if outbound == nil || !outbound.Target.IsValid() {
return newError("target not specified.") return newError("target not specified.")

View File

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

View File

@ -27,13 +27,7 @@ type Inbound interface {
// An Outbound process outbound connections. // An Outbound process outbound connections.
type Outbound interface { type Outbound interface {
// Process processes the given connection. The given dialer may be used to dial a system outbound connection. // Process processes the given connection. The given dialer may be used to dial a system outbound connection.
Process(context.Context, *vio.Link, Dialer) error Process(context.Context, *vio.Link, internet.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)
} }
// UserManager is the interface for Inbounds and Outbounds that can manage their users. // UserManager is the interface for Inbounds and Outbounds that can manage their users.

View File

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

View File

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

View File

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

View File

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