From 128a90b98bf381232504181a4c47393a90e6f09a Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Sat, 3 Nov 2018 12:36:29 +0100 Subject: [PATCH] move link to transport --- app/commander/outbound.go | 4 ++-- app/dispatcher/default.go | 11 ++++++----- app/proxyman/outbound/handler.go | 6 +++--- app/reverse/bridge.go | 10 +++++----- app/reverse/portal.go | 8 ++++---- app/router/config.pb.go | 3 --- common/mux/client.go | 16 ++++++++-------- common/mux/client_test.go | 2 +- common/mux/server.go | 12 ++++++------ common/net/system.go | 3 ++- features/outbound/outbound.go | 4 ++-- features/routing/dispatcher.go | 4 ++-- proxy/blackhole/blackhole.go | 4 ++-- proxy/blackhole/blackhole_test.go | 4 ++-- proxy/freedom/freedom.go | 4 ++-- proxy/mtproto/client.go | 4 ++-- proxy/proxy.go | 4 ++-- proxy/shadowsocks/client.go | 4 ++-- proxy/socks/client.go | 4 ++-- proxy/vmess/outbound/outbound.go | 4 ++-- testing/mocks/proxy.go | 4 ++-- transport/internet/udp/dispatcher.go | 4 ++-- transport/internet/udp/dispatcher_test.go | 10 +++++----- {common/vio => transport}/link.go | 2 +- 24 files changed, 67 insertions(+), 68 deletions(-) rename {common/vio => transport}/link.go (91%) diff --git a/app/commander/outbound.go b/app/commander/outbound.go index e69659c6..8cfba542 100644 --- a/app/commander/outbound.go +++ b/app/commander/outbound.go @@ -7,7 +7,7 @@ import ( "v2ray.com/core/common" "v2ray.com/core/common/net" "v2ray.com/core/common/signal/done" - "v2ray.com/core/common/vio" + "v2ray.com/core/transport" "v2ray.com/core/transport/pipe" ) @@ -69,7 +69,7 @@ type Outbound struct { } // Dispatch implements outbound.Handler. -func (co *Outbound) Dispatch(ctx context.Context, link *vio.Link) { +func (co *Outbound) Dispatch(ctx context.Context, link *transport.Link) { co.access.RLock() if co.closed { diff --git a/app/dispatcher/default.go b/app/dispatcher/default.go index 75c7d767..fead3c64 100644 --- a/app/dispatcher/default.go +++ b/app/dispatcher/default.go @@ -20,6 +20,7 @@ import ( "v2ray.com/core/features/policy" "v2ray.com/core/features/routing" "v2ray.com/core/features/stats" + "v2ray.com/core/transport" "v2ray.com/core/transport/pipe" ) @@ -124,17 +125,17 @@ func (*DefaultDispatcher) Start() error { // Close implements common.Closable. func (*DefaultDispatcher) Close() error { return nil } -func (d *DefaultDispatcher) getLink(ctx context.Context) (*vio.Link, *vio.Link) { +func (d *DefaultDispatcher) getLink(ctx context.Context) (*transport.Link, *transport.Link) { opt := pipe.OptionsFromContext(ctx) uplinkReader, uplinkWriter := pipe.New(opt...) downlinkReader, downlinkWriter := pipe.New(opt...) - inboundLink := &vio.Link{ + inboundLink := &transport.Link{ Reader: downlinkReader, Writer: uplinkWriter, } - outboundLink := &vio.Link{ + outboundLink := &transport.Link{ Reader: uplinkReader, Writer: downlinkWriter, } @@ -180,7 +181,7 @@ func shouldOverride(result SniffResult, domainOverride []string) bool { } // Dispatch implements routing.Dispatcher. -func (d *DefaultDispatcher) Dispatch(ctx context.Context, destination net.Destination) (*vio.Link, error) { +func (d *DefaultDispatcher) Dispatch(ctx context.Context, destination net.Destination) (*transport.Link, error) { if !destination.IsValid() { panic("Dispatcher: Invalid destination.") } @@ -245,7 +246,7 @@ func sniffer(ctx context.Context, cReader *cachedReader) (SniffResult, error) { } } -func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *vio.Link, destination net.Destination) { +func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport.Link, destination net.Destination) { dispatcher := d.ohm.GetDefaultHandler() if d.router != nil { if tag, err := d.router.PickRoute(ctx); err == nil { diff --git a/app/proxyman/outbound/handler.go b/app/proxyman/outbound/handler.go index c195d4a7..d79ff714 100644 --- a/app/proxyman/outbound/handler.go +++ b/app/proxyman/outbound/handler.go @@ -9,9 +9,9 @@ import ( "v2ray.com/core/common/mux" "v2ray.com/core/common/net" "v2ray.com/core/common/session" - "v2ray.com/core/common/vio" "v2ray.com/core/features/outbound" "v2ray.com/core/proxy" + "v2ray.com/core/transport" "v2ray.com/core/transport/internet" "v2ray.com/core/transport/pipe" ) @@ -96,7 +96,7 @@ func (h *Handler) Tag() string { } // Dispatch implements proxy.Outbound.Dispatch. -func (h *Handler) Dispatch(ctx context.Context, link *vio.Link) { +func (h *Handler) Dispatch(ctx context.Context, link *transport.Link) { if h.mux != nil { if err := h.mux.Dispatch(ctx, link); err != nil { newError("failed to process mux outbound traffic").Base(err).WriteToLog(session.ExportIDToError(ctx)) @@ -130,7 +130,7 @@ func (h *Handler) Dial(ctx context.Context, dest net.Destination) (internet.Conn uplinkReader, uplinkWriter := pipe.New(opts...) downlinkReader, downlinkWriter := pipe.New(opts...) - go handler.Dispatch(ctx, &vio.Link{Reader: uplinkReader, Writer: downlinkWriter}) + go handler.Dispatch(ctx, &transport.Link{Reader: uplinkReader, Writer: downlinkWriter}) return net.NewConnection(net.ConnectionInputMulti(uplinkWriter), net.ConnectionOutputMulti(downlinkReader)), nil } diff --git a/app/reverse/bridge.go b/app/reverse/bridge.go index 99c644e4..10268f1c 100644 --- a/app/reverse/bridge.go +++ b/app/reverse/bridge.go @@ -9,8 +9,8 @@ import ( "v2ray.com/core/common/net" "v2ray.com/core/common/session" "v2ray.com/core/common/task" - "v2ray.com/core/common/vio" "v2ray.com/core/features/routing" + "v2ray.com/core/transport" "v2ray.com/core/transport/pipe" ) @@ -144,7 +144,7 @@ func (w *BridgeWorker) Connections() uint32 { return w.worker.ActiveConnections() } -func (w *BridgeWorker) handleInternalConn(link vio.Link) { +func (w *BridgeWorker) handleInternalConn(link transport.Link) { go func() { reader := link.Reader for { @@ -166,7 +166,7 @@ func (w *BridgeWorker) handleInternalConn(link vio.Link) { }() } -func (w *BridgeWorker) Dispatch(ctx context.Context, dest net.Destination) (*vio.Link, error) { +func (w *BridgeWorker) Dispatch(ctx context.Context, dest net.Destination) (*transport.Link, error) { if !isInternalDomain(dest) { ctx = session.ContextWithInbound(ctx, &session.Inbound{ Tag: w.tag, @@ -178,12 +178,12 @@ func (w *BridgeWorker) Dispatch(ctx context.Context, dest net.Destination) (*vio uplinkReader, uplinkWriter := pipe.New(opt...) downlinkReader, downlinkWriter := pipe.New(opt...) - w.handleInternalConn(vio.Link{ + w.handleInternalConn(transport.Link{ Reader: downlinkReader, Writer: uplinkWriter, }) - return &vio.Link{ + return &transport.Link{ Reader: uplinkReader, Writer: downlinkWriter, }, nil diff --git a/app/reverse/portal.go b/app/reverse/portal.go index 2ef8c85e..22b6ecb0 100644 --- a/app/reverse/portal.go +++ b/app/reverse/portal.go @@ -12,8 +12,8 @@ import ( "v2ray.com/core/common/net" "v2ray.com/core/common/session" "v2ray.com/core/common/task" - "v2ray.com/core/common/vio" "v2ray.com/core/features/outbound" + "v2ray.com/core/transport" "v2ray.com/core/transport/pipe" ) @@ -61,7 +61,7 @@ func (p *Portal) Close() error { return p.ohm.RemoveHandler(context.Background(), p.tag) } -func (s *Portal) HandleConnection(ctx context.Context, link *vio.Link) error { +func (s *Portal) HandleConnection(ctx context.Context, link *transport.Link) error { outboundMeta := session.OutboundFromContext(ctx) if outboundMeta == nil { return newError("outbound metadata not found").AtError() @@ -94,7 +94,7 @@ func (o *Outbound) Tag() string { return o.tag } -func (o *Outbound) Dispatch(ctx context.Context, link *vio.Link) { +func (o *Outbound) Dispatch(ctx context.Context, link *transport.Link) { if err := o.portal.HandleConnection(ctx, link); err != nil { newError("failed to process reverse connection").Base(err).WriteToLog(session.ExportIDToError(ctx)) pipe.CloseError(link.Writer) @@ -206,7 +206,7 @@ func NewPortalWorker(client *mux.ClientWorker) (*PortalWorker, error) { ctx = session.ContextWithOutbound(ctx, &session.Outbound{ Target: net.UDPDestination(net.DomainAddress(internalDomain), 0), }) - f := client.Dispatch(ctx, &vio.Link{ + f := client.Dispatch(ctx, &transport.Link{ Reader: uplinkReader, Writer: downlinkWriter, }) diff --git a/app/router/config.pb.go b/app/router/config.pb.go index 0739b0d9..f7cb9160 100644 --- a/app/router/config.pb.go +++ b/app/router/config.pb.go @@ -372,15 +372,12 @@ type RoutingRule struct { // List of GeoIPs for target IP address matching. If this entry exists, the cidr above will have no effect. // GeoIP fields with the same country code are supposed to contain exactly same content. They will be merged during runtime. // For customized GeoIPs, please leave country code empty. - // The CIDR list in the GeoIP must be sorted beforehand. Geoip []*GeoIP `protobuf:"bytes,10,rep,name=geoip,proto3" json:"geoip,omitempty"` PortRange *net.PortRange `protobuf:"bytes,4,opt,name=port_range,json=portRange,proto3" json:"port_range,omitempty"` NetworkList *net.NetworkList `protobuf:"bytes,5,opt,name=network_list,json=networkList,proto3" json:"network_list,omitempty"` // List of CIDRs for source IP address matching. - // The list must be sorted beforehand. SourceCidr []*CIDR `protobuf:"bytes,6,rep,name=source_cidr,json=sourceCidr,proto3" json:"source_cidr,omitempty"` // Deprecated: Do not use. // List of GeoIPs for source IP address matching. If this entry exists, the source_cidr above will have no effect. - // The CIDR list in the GeoIP must be sorted beforehand. SourceGeoip []*GeoIP `protobuf:"bytes,11,rep,name=source_geoip,json=sourceGeoip,proto3" json:"source_geoip,omitempty"` UserEmail []string `protobuf:"bytes,7,rep,name=user_email,json=userEmail,proto3" json:"user_email,omitempty"` InboundTag []string `protobuf:"bytes,8,rep,name=inbound_tag,json=inboundTag,proto3" json:"inbound_tag,omitempty"` diff --git a/common/mux/client.go b/common/mux/client.go index 6df74a33..2fd2ee8c 100644 --- a/common/mux/client.go +++ b/common/mux/client.go @@ -14,8 +14,8 @@ import ( "v2ray.com/core/common/session" "v2ray.com/core/common/signal/done" "v2ray.com/core/common/task" - "v2ray.com/core/common/vio" "v2ray.com/core/proxy" + "v2ray.com/core/transport" "v2ray.com/core/transport/internet" "v2ray.com/core/transport/pipe" ) @@ -24,7 +24,7 @@ type ClientManager struct { Picker WorkerPicker } -func (m *ClientManager) Dispatch(ctx context.Context, link *vio.Link) error { +func (m *ClientManager) Dispatch(ctx context.Context, link *transport.Link) error { for { worker, err := m.Picker.PickAvailable() if err != nil { @@ -114,7 +114,7 @@ func (p *IncrementalWorkerPicker) pickInternal() (*ClientWorker, error, bool) { func (p *IncrementalWorkerPicker) PickAvailable() (*ClientWorker, error) { worker, err, start := p.pickInternal() if start { - p.cleanupTask.Start() + common.Must(p.cleanupTask.Start()) } return worker, err @@ -135,7 +135,7 @@ func (f *DialingWorkerFactory) Create() (*ClientWorker, error) { uplinkReader, upLinkWriter := pipe.New(opts...) downlinkReader, downlinkWriter := pipe.New(opts...) - c, err := NewClientWorker(vio.Link{ + c, err := NewClientWorker(transport.Link{ Reader: downlinkReader, Writer: upLinkWriter, }, f.Strategy) @@ -150,7 +150,7 @@ func (f *DialingWorkerFactory) Create() (*ClientWorker, error) { }) ctx, cancel := context.WithCancel(ctx) - if err := p.Process(ctx, &vio.Link{Reader: uplinkReader, Writer: downlinkWriter}, d); err != nil { + if err := p.Process(ctx, &transport.Link{Reader: uplinkReader, Writer: downlinkWriter}, d); err != nil { errors.New("failed to handler mux client connection").Base(err).WriteToLog() } common.Must(c.Close()) @@ -167,7 +167,7 @@ type ClientStrategy struct { type ClientWorker struct { sessionManager *SessionManager - link vio.Link + link transport.Link done *done.Instance strategy ClientStrategy } @@ -176,7 +176,7 @@ var muxCoolAddress = net.DomainAddress("v1.mux.cool") var muxCoolPort = net.Port(9527) // NewClientWorker creates a new mux.Client. -func NewClientWorker(stream vio.Link, s ClientStrategy) (*ClientWorker, error) { +func NewClientWorker(stream transport.Link, s ClientStrategy) (*ClientWorker, error) { c := &ClientWorker{ sessionManager: NewSessionManager(), link: stream, @@ -283,7 +283,7 @@ func (m *ClientWorker) IsFull() bool { return false } -func (m *ClientWorker) Dispatch(ctx context.Context, link *vio.Link) bool { +func (m *ClientWorker) Dispatch(ctx context.Context, link *transport.Link) bool { if m.IsFull() || m.Closed() { return false } diff --git a/common/mux/client_test.go b/common/mux/client_test.go index 86378d40..101ab301 100644 --- a/common/mux/client_test.go +++ b/common/mux/client_test.go @@ -35,7 +35,7 @@ func TestClientWorkerEOF(t *testing.T) { reader, writer := pipe.New(pipe.WithoutSizeLimit()) common.Must(writer.Close()) - worker, err := mux.NewClientWorker(vio.Link{Reader: reader, Writer: writer}, mux.ClientStrategy{}) + worker, err := mux.NewClientWorker(transport.Link{Reader: reader, Writer: writer}, mux.ClientStrategy{}) common.Must(err) time.Sleep(time.Millisecond * 500) diff --git a/common/mux/server.go b/common/mux/server.go index 979eeec7..b45e1315 100644 --- a/common/mux/server.go +++ b/common/mux/server.go @@ -11,8 +11,8 @@ import ( "v2ray.com/core/common/net" "v2ray.com/core/common/protocol" "v2ray.com/core/common/session" - "v2ray.com/core/common/vio" "v2ray.com/core/features/routing" + "v2ray.com/core/transport" "v2ray.com/core/transport/pipe" ) @@ -35,7 +35,7 @@ func (s *Server) Type() interface{} { } // Dispatch impliments routing.Dispatcher -func (s *Server) Dispatch(ctx context.Context, dest net.Destination) (*vio.Link, error) { +func (s *Server) Dispatch(ctx context.Context, dest net.Destination) (*transport.Link, error) { if dest.Address != muxCoolAddress { return s.dispatcher.Dispatch(ctx, dest) } @@ -44,7 +44,7 @@ func (s *Server) Dispatch(ctx context.Context, dest net.Destination) (*vio.Link, uplinkReader, uplinkWriter := pipe.New(opts...) downlinkReader, downlinkWriter := pipe.New(opts...) - _, err := NewServerWorker(ctx, s.dispatcher, &vio.Link{ + _, err := NewServerWorker(ctx, s.dispatcher, &transport.Link{ Reader: uplinkReader, Writer: downlinkWriter, }) @@ -52,7 +52,7 @@ func (s *Server) Dispatch(ctx context.Context, dest net.Destination) (*vio.Link, return nil, err } - return &vio.Link{Reader: downlinkReader, Writer: uplinkWriter}, nil + return &transport.Link{Reader: downlinkReader, Writer: uplinkWriter}, nil } // Start implements common.Runnable. @@ -67,11 +67,11 @@ func (s *Server) Close() error { type ServerWorker struct { dispatcher routing.Dispatcher - link *vio.Link + link *transport.Link sessionManager *SessionManager } -func NewServerWorker(ctx context.Context, d routing.Dispatcher, link *vio.Link) (*ServerWorker, error) { +func NewServerWorker(ctx context.Context, d routing.Dispatcher, link *transport.Link) (*ServerWorker, error) { worker := &ServerWorker{ dispatcher: d, link: link, diff --git a/common/net/system.go b/common/net/system.go index 721ad605..daf1d2e7 100644 --- a/common/net/system.go +++ b/common/net/system.go @@ -2,7 +2,7 @@ package net import "net" -// DialTCP is an injectable function. Default to net.DialTCP +// DialTCP is an alias of net.DialTCP. var DialTCP = net.DialTCP var DialUDP = net.DialUDP var DialUnix = net.DialUnix @@ -19,6 +19,7 @@ var LookupIP = net.LookupIP var FileConn = net.FileConn +// ParseIP is an alias of net.ParseIP var ParseIP = net.ParseIP var SplitHostPort = net.SplitHostPort diff --git a/features/outbound/outbound.go b/features/outbound/outbound.go index 781ab0c9..4e210ca9 100644 --- a/features/outbound/outbound.go +++ b/features/outbound/outbound.go @@ -4,15 +4,15 @@ import ( "context" "v2ray.com/core/common" - "v2ray.com/core/common/vio" "v2ray.com/core/features" + "v2ray.com/core/transport" ) // Handler is the interface for handlers that process outbound connections. type Handler interface { common.Runnable Tag() string - Dispatch(ctx context.Context, link *vio.Link) + Dispatch(ctx context.Context, link *transport.Link) } // Manager is a feature that manages outbound.Handlers. diff --git a/features/routing/dispatcher.go b/features/routing/dispatcher.go index 62ec5599..d44cc1f6 100644 --- a/features/routing/dispatcher.go +++ b/features/routing/dispatcher.go @@ -4,8 +4,8 @@ import ( "context" "v2ray.com/core/common/net" - "v2ray.com/core/common/vio" "v2ray.com/core/features" + "v2ray.com/core/transport" ) // Dispatcher is a feature that dispatches inbound requests to outbound handlers based on rules. @@ -14,7 +14,7 @@ type Dispatcher interface { features.Feature // Dispatch returns a Ray for transporting data for the given request. - Dispatch(ctx context.Context, dest net.Destination) (*vio.Link, error) + Dispatch(ctx context.Context, dest net.Destination) (*transport.Link, error) } // DispatcherType returns the type of Dispatcher interface. Can be used to implement common.HasType. diff --git a/proxy/blackhole/blackhole.go b/proxy/blackhole/blackhole.go index e9d62a19..571397d3 100644 --- a/proxy/blackhole/blackhole.go +++ b/proxy/blackhole/blackhole.go @@ -8,7 +8,7 @@ import ( "time" "v2ray.com/core/common" - "v2ray.com/core/common/vio" + "v2ray.com/core/transport" "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 internet.Dialer) error { +func (h *Handler) Process(ctx context.Context, link *transport.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/blackhole/blackhole_test.go b/proxy/blackhole/blackhole_test.go index 4c8bb1e3..860de9ee 100644 --- a/proxy/blackhole/blackhole_test.go +++ b/proxy/blackhole/blackhole_test.go @@ -7,8 +7,8 @@ import ( "v2ray.com/core/common" "v2ray.com/core/common/buf" "v2ray.com/core/common/serial" - "v2ray.com/core/common/vio" "v2ray.com/core/proxy/blackhole" + "v2ray.com/core/transport" "v2ray.com/core/transport/pipe" ) @@ -28,7 +28,7 @@ func TestBlackholeHTTPResponse(t *testing.T) { rerr = e }() - link := vio.Link{ + link := transport.Link{ Reader: reader, Writer: writer, } diff --git a/proxy/freedom/freedom.go b/proxy/freedom/freedom.go index 9552b0c0..dec43c19 100644 --- a/proxy/freedom/freedom.go +++ b/proxy/freedom/freedom.go @@ -15,9 +15,9 @@ import ( "v2ray.com/core/common/session" "v2ray.com/core/common/signal" "v2ray.com/core/common/task" - "v2ray.com/core/common/vio" "v2ray.com/core/features/dns" "v2ray.com/core/features/policy" + "v2ray.com/core/transport" "v2ray.com/core/transport/internet" ) @@ -78,7 +78,7 @@ func isValidAddress(addr *net.IPOrDomain) bool { } // Process implements proxy.Outbound. -func (h *Handler) Process(ctx context.Context, link *vio.Link, dialer internet.Dialer) error { +func (h *Handler) Process(ctx context.Context, link *transport.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 350c863a..77d4624a 100644 --- a/proxy/mtproto/client.go +++ b/proxy/mtproto/client.go @@ -9,7 +9,7 @@ import ( "v2ray.com/core/common/net" "v2ray.com/core/common/session" "v2ray.com/core/common/task" - "v2ray.com/core/common/vio" + "v2ray.com/core/transport" "v2ray.com/core/transport/internet" ) @@ -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 internet.Dialer) error { +func (c *Client) Process(ctx context.Context, link *transport.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 520e3343..eaf65e8f 100755 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -10,8 +10,8 @@ import ( "v2ray.com/core/common/net" "v2ray.com/core/common/protocol" - "v2ray.com/core/common/vio" "v2ray.com/core/features/routing" + "v2ray.com/core/transport" "v2ray.com/core/transport/internet" ) @@ -27,7 +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, internet.Dialer) error + Process(context.Context, *transport.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 9226ec12..bd3a4965 100644 --- a/proxy/shadowsocks/client.go +++ b/proxy/shadowsocks/client.go @@ -12,8 +12,8 @@ import ( "v2ray.com/core/common/session" "v2ray.com/core/common/signal" "v2ray.com/core/common/task" - "v2ray.com/core/common/vio" "v2ray.com/core/features/policy" + "v2ray.com/core/transport" "v2ray.com/core/transport/internet" ) @@ -46,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 internet.Dialer) error { +func (c *Client) Process(ctx context.Context, link *transport.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 2ff173ec..acd2cef3 100644 --- a/proxy/socks/client.go +++ b/proxy/socks/client.go @@ -13,8 +13,8 @@ import ( "v2ray.com/core/common/session" "v2ray.com/core/common/signal" "v2ray.com/core/common/task" - "v2ray.com/core/common/vio" "v2ray.com/core/features/policy" + "v2ray.com/core/transport" "v2ray.com/core/transport/internet" ) @@ -46,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 internet.Dialer) error { +func (c *Client) Process(ctx context.Context, link *transport.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 9c2f2f02..6ec89abe 100644 --- a/proxy/vmess/outbound/outbound.go +++ b/proxy/vmess/outbound/outbound.go @@ -16,10 +16,10 @@ import ( "v2ray.com/core/common/session" "v2ray.com/core/common/signal" "v2ray.com/core/common/task" - "v2ray.com/core/common/vio" "v2ray.com/core/features/policy" "v2ray.com/core/proxy/vmess" "v2ray.com/core/proxy/vmess/encoding" + "v2ray.com/core/transport" "v2ray.com/core/transport/internet" ) @@ -52,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 internet.Dialer) error { +func (v *Handler) Process(ctx context.Context, link *transport.Link, dialer internet.Dialer) error { var rec *protocol.ServerSpec var conn internet.Connection diff --git a/testing/mocks/proxy.go b/testing/mocks/proxy.go index 80b8bb73..60b84a05 100644 --- a/testing/mocks/proxy.go +++ b/testing/mocks/proxy.go @@ -9,8 +9,8 @@ import ( gomock "github.com/golang/mock/gomock" reflect "reflect" net "v2ray.com/core/common/net" - vio "v2ray.com/core/common/vio" routing "v2ray.com/core/features/routing" + transport "v2ray.com/core/transport" internet "v2ray.com/core/transport/internet" ) @@ -85,7 +85,7 @@ func (m *ProxyOutbound) EXPECT() *ProxyOutboundMockRecorder { } // Process mocks base method -func (m *ProxyOutbound) Process(arg0 context.Context, arg1 *vio.Link, arg2 internet.Dialer) error { +func (m *ProxyOutbound) Process(arg0 context.Context, arg1 *transport.Link, arg2 internet.Dialer) error { ret := m.ctrl.Call(m, "Process", arg0, arg1, arg2) ret0, _ := ret[0].(error) return ret0 diff --git a/transport/internet/udp/dispatcher.go b/transport/internet/udp/dispatcher.go index 07540621..b1818170 100644 --- a/transport/internet/udp/dispatcher.go +++ b/transport/internet/udp/dispatcher.go @@ -10,14 +10,14 @@ import ( "v2ray.com/core/common/net" "v2ray.com/core/common/session" "v2ray.com/core/common/signal" - "v2ray.com/core/common/vio" "v2ray.com/core/features/routing" + "v2ray.com/core/transport" ) type ResponseCallback func(ctx context.Context, payload *buf.Buffer) type connEntry struct { - link *vio.Link + link *transport.Link timer signal.ActivityUpdater cancel context.CancelFunc } diff --git a/transport/internet/udp/dispatcher_test.go b/transport/internet/udp/dispatcher_test.go index 8d43f469..0dd93ff7 100644 --- a/transport/internet/udp/dispatcher_test.go +++ b/transport/internet/udp/dispatcher_test.go @@ -8,18 +8,18 @@ import ( "v2ray.com/core/common/buf" "v2ray.com/core/common/net" - "v2ray.com/core/common/vio" "v2ray.com/core/features/routing" + "v2ray.com/core/transport" . "v2ray.com/core/transport/internet/udp" "v2ray.com/core/transport/pipe" . "v2ray.com/ext/assert" ) type TestDispatcher struct { - OnDispatch func(ctx context.Context, dest net.Destination) (*vio.Link, error) + OnDispatch func(ctx context.Context, dest net.Destination) (*transport.Link, error) } -func (d *TestDispatcher) Dispatch(ctx context.Context, dest net.Destination) (*vio.Link, error) { +func (d *TestDispatcher) Dispatch(ctx context.Context, dest net.Destination) (*transport.Link, error) { return d.OnDispatch(ctx, dest) } @@ -55,9 +55,9 @@ func TestSameDestinationDispatching(t *testing.T) { var count uint32 td := &TestDispatcher{ - OnDispatch: func(ctx context.Context, dest net.Destination) (*vio.Link, error) { + OnDispatch: func(ctx context.Context, dest net.Destination) (*transport.Link, error) { atomic.AddUint32(&count, 1) - return &vio.Link{Reader: downlinkReader, Writer: uplinkWriter}, nil + return &transport.Link{Reader: downlinkReader, Writer: uplinkWriter}, nil }, } dest := net.UDPDestination(net.LocalHostIP, 53) diff --git a/common/vio/link.go b/transport/link.go similarity index 91% rename from common/vio/link.go rename to transport/link.go index 2fe8dfd4..0a17f8db 100644 --- a/common/vio/link.go +++ b/transport/link.go @@ -1,4 +1,4 @@ -package vio +package transport import "v2ray.com/core/common/buf"