From 8b00d6fc30cab7f80dcd554fa0cd96be9f516a20 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Sat, 14 Jan 2017 00:27:45 +0100 Subject: [PATCH] clean imports --- app/dispatcher/impl/default.go | 4 ++-- app/proxy/proxy_test.go | 4 ++-- app/receiver/receiver.go | 1 - app/router/router.go | 12 ++++++------ app/router/router_test.go | 8 ++++---- common/net/destination_test.go | 6 +++--- common/protocol/headers.go | 16 ++++++++-------- common/protocol/server_spec.go | 10 +++++----- config.go | 10 +++++----- inbound_detour_dynamic.go | 13 ++++++------- proxy/blackhole/blackhole.go | 4 ++-- proxy/dokodemo/config.go | 4 ++-- proxy/dokodemo/sockopt_linux.go | 14 +++++++------- proxy/dokodemo/sockopt_other.go | 6 +++--- proxy/proxy.go | 16 ++++++++-------- proxy/socks/config.go | 6 +++--- proxy/socks/server_udp.go | 6 +++--- testing/assert/address.go | 10 +++++----- testing/assert/destination.go | 14 +++++++------- testing/assert/port.go | 12 ++++++------ testing/scenarios/common.go | 3 +-- testing/scenarios/http_test.go | 6 +++--- transport/internet/dialer_test.go | 4 ++-- transport/internet/internal/pool_test.go | 1 + transport/internet/kcp/dialer.go | 3 +-- transport/internet/kcp/listener.go | 3 +-- 26 files changed, 96 insertions(+), 100 deletions(-) diff --git a/app/dispatcher/impl/default.go b/app/dispatcher/impl/default.go index 73d341857..5aa69f8ee 100644 --- a/app/dispatcher/impl/default.go +++ b/app/dispatcher/impl/default.go @@ -12,7 +12,7 @@ import ( "v2ray.com/core/common/buf" "v2ray.com/core/common/errors" "v2ray.com/core/common/log" - v2net "v2ray.com/core/common/net" + "v2ray.com/core/common/net" "v2ray.com/core/proxy" "v2ray.com/core/transport/ray" ) @@ -77,7 +77,7 @@ func (v *DefaultDispatcher) DispatchToOutbound(session *proxy.SessionInfo) ray.I return direct } -func (v *DefaultDispatcher) waitAndDispatch(wait func() error, destination v2net.Destination, link ray.OutboundRay, dispatcher proxy.OutboundHandler) { +func (v *DefaultDispatcher) waitAndDispatch(wait func() error, destination net.Destination, link ray.OutboundRay, dispatcher proxy.OutboundHandler) { if err := wait(); err != nil { log.Info("DefaultDispatcher: Failed precondition: ", err) link.OutboundInput().CloseError() diff --git a/app/proxy/proxy_test.go b/app/proxy/proxy_test.go index 79871a40d..f231f5249 100644 --- a/app/proxy/proxy_test.go +++ b/app/proxy/proxy_test.go @@ -9,7 +9,7 @@ import ( "v2ray.com/core/app/proxyman" _ "v2ray.com/core/app/proxyman/outbound" "v2ray.com/core/common" - v2net "v2ray.com/core/common/net" + "v2ray.com/core/common/net" "v2ray.com/core/proxy" "v2ray.com/core/proxy/freedom" "v2ray.com/core/testing/assert" @@ -50,7 +50,7 @@ func TestProxyDial(t *testing.T) { dest, err := tcpServer.Start() assert.Error(err).IsNil() - conn, err := proxy.Dial(v2net.LocalHostIP, dest, internet.DialerOptions{ + conn, err := proxy.Dial(net.LocalHostIP, dest, internet.DialerOptions{ Stream: &internet.StreamConfig{ Protocol: internet.TransportProtocol_TCP, }, diff --git a/app/receiver/receiver.go b/app/receiver/receiver.go index a3db71eb9..d99d5f1cc 100644 --- a/app/receiver/receiver.go +++ b/app/receiver/receiver.go @@ -2,7 +2,6 @@ package receiver import ( "net" - "time" v2net "v2ray.com/core/common/net" diff --git a/app/router/router.go b/app/router/router.go index b28fbd129..812880a3d 100644 --- a/app/router/router.go +++ b/app/router/router.go @@ -8,7 +8,7 @@ import ( "v2ray.com/core/common" "v2ray.com/core/common/errors" "v2ray.com/core/common/log" - v2net "v2ray.com/core/common/net" + "v2ray.com/core/common/net" "v2ray.com/core/proxy" ) @@ -55,17 +55,17 @@ func NewRouter(ctx context.Context, config *Config) (*Router, error) { } // Private: Visible for testing. -func (v *Router) ResolveIP(dest v2net.Destination) []v2net.Destination { +func (v *Router) ResolveIP(dest net.Destination) []net.Destination { ips := v.dnsServer.Get(dest.Address.Domain()) if len(ips) == 0 { return nil } - dests := make([]v2net.Destination, len(ips)) + dests := make([]net.Destination, len(ips)) for idx, ip := range ips { - if dest.Network == v2net.Network_TCP { - dests[idx] = v2net.TCPDestination(v2net.IPAddress(ip), dest.Port) + if dest.Network == net.Network_TCP { + dests[idx] = net.TCPDestination(net.IPAddress(ip), dest.Port) } else { - dests[idx] = v2net.UDPDestination(v2net.IPAddress(ip), dest.Port) + dests[idx] = net.UDPDestination(net.IPAddress(ip), dest.Port) } } return dests diff --git a/app/router/router_test.go b/app/router/router_test.go index d2f2a9133..629ae628e 100644 --- a/app/router/router_test.go +++ b/app/router/router_test.go @@ -12,7 +12,7 @@ import ( "v2ray.com/core/app/proxyman" _ "v2ray.com/core/app/proxyman/outbound" . "v2ray.com/core/app/router" - v2net "v2ray.com/core/common/net" + "v2ray.com/core/common/net" "v2ray.com/core/proxy" "v2ray.com/core/testing/assert" ) @@ -24,8 +24,8 @@ func TestSimpleRouter(t *testing.T) { Rule: []*RoutingRule{ { Tag: "test", - NetworkList: &v2net.NetworkList{ - Network: []v2net.Network{v2net.Network_TCP}, + NetworkList: &net.NetworkList{ + Network: []net.Network{net.Network_TCP}, }, }, }, @@ -41,7 +41,7 @@ func TestSimpleRouter(t *testing.T) { r := FromSpace(space) - tag, err := r.TakeDetour(&proxy.SessionInfo{Destination: v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), 80)}) + tag, err := r.TakeDetour(&proxy.SessionInfo{Destination: net.TCPDestination(net.DomainAddress("v2ray.com"), 80)}) assert.Error(err).IsNil() assert.String(tag).Equals("test") } diff --git a/common/net/destination_test.go b/common/net/destination_test.go index b13fd18db..463649fc3 100644 --- a/common/net/destination_test.go +++ b/common/net/destination_test.go @@ -3,14 +3,14 @@ package net_test import ( "testing" - v2net "v2ray.com/core/common/net" + "v2ray.com/core/common/net" "v2ray.com/core/testing/assert" ) func TestTCPDestination(t *testing.T) { assert := assert.On(t) - dest := v2net.TCPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80) + dest := net.TCPDestination(net.IPAddress([]byte{1, 2, 3, 4}), 80) assert.Destination(dest).IsTCP() assert.Destination(dest).IsNotUDP() assert.Destination(dest).EqualsString("tcp:1.2.3.4:80") @@ -19,7 +19,7 @@ func TestTCPDestination(t *testing.T) { func TestUDPDestination(t *testing.T) { assert := assert.On(t) - dest := v2net.UDPDestination(v2net.IPAddress([]byte{0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88}), 53) + dest := net.UDPDestination(net.IPAddress([]byte{0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88}), 53) assert.Destination(dest).IsNotTCP() assert.Destination(dest).IsUDP() assert.Destination(dest).EqualsString("udp:[2001:4860:4860::8888]:53") diff --git a/common/protocol/headers.go b/common/protocol/headers.go index 8fd667934..f4ad33ad6 100644 --- a/common/protocol/headers.go +++ b/common/protocol/headers.go @@ -3,7 +3,7 @@ package protocol import ( "runtime" - v2net "v2ray.com/core/common/net" + "v2ray.com/core/common/net" "v2ray.com/core/common/uuid" ) @@ -58,16 +58,16 @@ type RequestHeader struct { Command RequestCommand Option RequestOption Security Security - Port v2net.Port - Address v2net.Address + Port net.Port + Address net.Address User *User } -func (v *RequestHeader) Destination() v2net.Destination { +func (v *RequestHeader) Destination() net.Destination { if v.Command == RequestCommandUDP { - return v2net.UDPDestination(v.Address, v.Port) + return net.UDPDestination(v.Address, v.Port) } - return v2net.TCPDestination(v.Address, v.Port) + return net.TCPDestination(v.Address, v.Port) } type ResponseOption byte @@ -96,8 +96,8 @@ type ResponseHeader struct { } type CommandSwitchAccount struct { - Host v2net.Address - Port v2net.Port + Host net.Address + Port net.Port ID *uuid.UUID AlterIds uint16 Level uint32 diff --git a/common/protocol/server_spec.go b/common/protocol/server_spec.go index 583dbd224..c91425a66 100644 --- a/common/protocol/server_spec.go +++ b/common/protocol/server_spec.go @@ -5,7 +5,7 @@ import ( "time" "v2ray.com/core/common/dice" - v2net "v2ray.com/core/common/net" + "v2ray.com/core/common/net" ) type ValidationStrategy interface { @@ -45,12 +45,12 @@ func (v *TimeoutValidStrategy) Invalidate() { type ServerSpec struct { sync.RWMutex - dest v2net.Destination + dest net.Destination users []*User valid ValidationStrategy } -func NewServerSpec(dest v2net.Destination, valid ValidationStrategy, users ...*User) *ServerSpec { +func NewServerSpec(dest net.Destination, valid ValidationStrategy, users ...*User) *ServerSpec { return &ServerSpec{ dest: dest, users: users, @@ -59,11 +59,11 @@ func NewServerSpec(dest v2net.Destination, valid ValidationStrategy, users ...*U } func NewServerSpecFromPB(spec ServerEndpoint) *ServerSpec { - dest := v2net.TCPDestination(spec.Address.AsAddress(), v2net.Port(spec.Port)) + dest := net.TCPDestination(spec.Address.AsAddress(), net.Port(spec.Port)) return NewServerSpec(dest, AlwaysValid(), spec.User...) } -func (v *ServerSpec) Destination() v2net.Destination { +func (v *ServerSpec) Destination() net.Destination { return v.dest } diff --git a/config.go b/config.go index ae78e6a97..44318792a 100644 --- a/config.go +++ b/config.go @@ -2,7 +2,7 @@ package core import ( "v2ray.com/core/common" - v2net "v2ray.com/core/common/net" + "v2ray.com/core/common/net" ) func (v *AllocationStrategy) GetConcurrencyValue() uint32 { @@ -26,9 +26,9 @@ func (v *InboundConnectionConfig) GetAllocationStrategyValue() *AllocationStrate return v.AllocationStrategy } -func (v *InboundConnectionConfig) GetListenOnValue() v2net.Address { +func (v *InboundConnectionConfig) GetListenOnValue() net.Address { if v.GetListenOn() == nil { - return v2net.AnyIP + return net.AnyIP } return v.ListenOn.AsAddress() } @@ -47,9 +47,9 @@ func (v *OutboundConnectionConfig) GetTypedSettings() (interface{}, error) { return v.GetSettings().GetInstance() } -func (v *OutboundConnectionConfig) GetSendThroughValue() v2net.Address { +func (v *OutboundConnectionConfig) GetSendThroughValue() net.Address { if v.GetSendThrough() == nil { - return v2net.AnyIP + return net.AnyIP } return v.SendThrough.AsAddress() } diff --git a/inbound_detour_dynamic.go b/inbound_detour_dynamic.go index 9f43fd383..f033438da 100644 --- a/inbound_detour_dynamic.go +++ b/inbound_detour_dynamic.go @@ -1,15 +1,14 @@ package core import ( + "context" "sync" "time" - "context" - "v2ray.com/core/app" "v2ray.com/core/common/dice" "v2ray.com/core/common/log" - v2net "v2ray.com/core/common/net" + "v2ray.com/core/common/net" "v2ray.com/core/common/retry" "v2ray.com/core/proxy" ) @@ -18,7 +17,7 @@ type InboundDetourHandlerDynamic struct { sync.RWMutex space app.Space config *InboundConnectionConfig - portsInUse map[v2net.Port]bool + portsInUse map[net.Port]bool ichs []proxy.InboundHandler ich2Recyle []proxy.InboundHandler lastRefresh time.Time @@ -30,7 +29,7 @@ func NewInboundDetourHandlerDynamic(ctx context.Context, config *InboundConnecti handler := &InboundDetourHandlerDynamic{ space: space, config: config, - portsInUse: make(map[v2net.Port]bool), + portsInUse: make(map[net.Port]bool), ctx: ctx, } handler.ichs = make([]proxy.InboundHandler, config.GetAllocationStrategyValue().GetConcurrencyValue()) @@ -56,11 +55,11 @@ func NewInboundDetourHandlerDynamic(ctx context.Context, config *InboundConnecti return handler, nil } -func (v *InboundDetourHandlerDynamic) pickUnusedPort() v2net.Port { +func (v *InboundDetourHandlerDynamic) pickUnusedPort() net.Port { delta := int(v.config.PortRange.To) - int(v.config.PortRange.From) + 1 for { r := dice.Roll(delta) - port := v.config.PortRange.FromPort() + v2net.Port(r) + port := v.config.PortRange.FromPort() + net.Port(r) _, used := v.portsInUse[port] if !used { return port diff --git a/proxy/blackhole/blackhole.go b/proxy/blackhole/blackhole.go index 85f36eab3..445e96a6f 100644 --- a/proxy/blackhole/blackhole.go +++ b/proxy/blackhole/blackhole.go @@ -6,7 +6,7 @@ import ( "time" "v2ray.com/core/common" - v2net "v2ray.com/core/common/net" + "v2ray.com/core/common/net" "v2ray.com/core/transport/ray" ) @@ -27,7 +27,7 @@ func New(ctx context.Context, config *Config) (*Handler, error) { } // Dispatch implements OutboundHandler.Dispatch(). -func (v *Handler) Dispatch(destination v2net.Destination, ray ray.OutboundRay) { +func (v *Handler) Dispatch(destination net.Destination, ray ray.OutboundRay) { v.response.WriteTo(ray.OutboundOutput()) // CloseError() will immediately close the connection. // Sleep a little here to make sure the response is sent to client. diff --git a/proxy/dokodemo/config.go b/proxy/dokodemo/config.go index 33bd6b85e..84278afe4 100644 --- a/proxy/dokodemo/config.go +++ b/proxy/dokodemo/config.go @@ -1,11 +1,11 @@ package dokodemo import ( - v2net "v2ray.com/core/common/net" + "v2ray.com/core/common/net" ) // GetPredefinedAddress returns the defined address from proto config. Null if address is not valid. -func (v *Config) GetPredefinedAddress() v2net.Address { +func (v *Config) GetPredefinedAddress() net.Address { addr := v.Address.AsAddress() if addr == nil { return nil diff --git a/proxy/dokodemo/sockopt_linux.go b/proxy/dokodemo/sockopt_linux.go index 9517e3432..342b903e6 100644 --- a/proxy/dokodemo/sockopt_linux.go +++ b/proxy/dokodemo/sockopt_linux.go @@ -6,30 +6,30 @@ import ( "syscall" "v2ray.com/core/common/log" - v2net "v2ray.com/core/common/net" + "v2ray.com/core/common/net" "v2ray.com/core/transport/internet" ) const SO_ORIGINAL_DST = 80 -func GetOriginalDestination(conn internet.Connection) v2net.Destination { +func GetOriginalDestination(conn internet.Connection) net.Destination { tcpConn, ok := conn.(internet.SysFd) if !ok { log.Info("Dokodemo: Failed to get sys fd.") - return v2net.Destination{} + return net.Destination{} } fd, err := tcpConn.SysFd() if err != nil { log.Info("Dokodemo: Failed to get original destination: ", err) - return v2net.Destination{} + return net.Destination{} } addr, err := syscall.GetsockoptIPv6Mreq(fd, syscall.IPPROTO_IP, SO_ORIGINAL_DST) if err != nil { log.Info("Dokodemo: Failed to call getsockopt: ", err) - return v2net.Destination{} + return net.Destination{} } - ip := v2net.IPAddress(addr.Multiaddr[4:8]) + ip := net.IPAddress(addr.Multiaddr[4:8]) port := uint16(addr.Multiaddr[2])<<8 + uint16(addr.Multiaddr[3]) - return v2net.TCPDestination(ip, v2net.Port(port)) + return net.TCPDestination(ip, net.Port(port)) } diff --git a/proxy/dokodemo/sockopt_other.go b/proxy/dokodemo/sockopt_other.go index ac4bf9582..55c316c49 100644 --- a/proxy/dokodemo/sockopt_other.go +++ b/proxy/dokodemo/sockopt_other.go @@ -3,10 +3,10 @@ package dokodemo import ( - v2net "v2ray.com/core/common/net" + "v2ray.com/core/common/net" "v2ray.com/core/transport/internet" ) -func GetOriginalDestination(conn internet.Connection) v2net.Destination { - return v2net.Destination{} +func GetOriginalDestination(conn internet.Connection) net.Destination { + return net.Destination{} } diff --git a/proxy/proxy.go b/proxy/proxy.go index 2b322ddd3..8ee6e2d74 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -2,7 +2,7 @@ package proxy import ( - v2net "v2ray.com/core/common/net" + "v2ray.com/core/common/net" "v2ray.com/core/common/protocol" "v2ray.com/core/transport/internet" "v2ray.com/core/transport/ray" @@ -16,23 +16,23 @@ const ( ) type SessionInfo struct { - Source v2net.Destination - Destination v2net.Destination + Source net.Destination + Destination net.Destination User *protocol.User Inbound *InboundHandlerMeta } type InboundHandlerMeta struct { Tag string - Address v2net.Address - Port v2net.Port + Address net.Address + Port net.Port AllowPassiveConnection bool StreamSettings *internet.StreamConfig } type OutboundHandlerMeta struct { Tag string - Address v2net.Address + Address net.Address StreamSettings *internet.StreamConfig ProxySettings *internet.ProxyConfig } @@ -51,11 +51,11 @@ type InboundHandler interface { // Close stops the handler to accepting anymore inbound connections. Close() // Port returns the port that the handler is listening on. - Port() v2net.Port + Port() net.Port } // An OutboundHandler handles outbound network connection for V2Ray. type OutboundHandler interface { // Dispatch sends one or more Packets to its destination. - Dispatch(destination v2net.Destination, ray ray.OutboundRay) + Dispatch(destination net.Destination, ray ray.OutboundRay) } diff --git a/proxy/socks/config.go b/proxy/socks/config.go index b2806df0f..2fd575252 100644 --- a/proxy/socks/config.go +++ b/proxy/socks/config.go @@ -1,7 +1,7 @@ package socks import ( - v2net "v2ray.com/core/common/net" + "v2ray.com/core/common/net" "v2ray.com/core/common/protocol" ) @@ -27,9 +27,9 @@ func (v *ServerConfig) HasAccount(username, password string) bool { return storedPassed == password } -func (v *ServerConfig) GetNetAddress() v2net.Address { +func (v *ServerConfig) GetNetAddress() net.Address { if v.Address == nil { - return v2net.LocalHostIP + return net.LocalHostIP } return v.Address.AsAddress() } diff --git a/proxy/socks/server_udp.go b/proxy/socks/server_udp.go index 3677cdc3c..75344aa53 100644 --- a/proxy/socks/server_udp.go +++ b/proxy/socks/server_udp.go @@ -3,7 +3,7 @@ package socks import ( "v2ray.com/core/common/buf" "v2ray.com/core/common/log" - v2net "v2ray.com/core/common/net" + "v2ray.com/core/common/net" "v2ray.com/core/proxy" "v2ray.com/core/transport/internet/udp" ) @@ -16,7 +16,7 @@ func (v *Server) listenUDP() error { return err } v.udpMutex.Lock() - v.udpAddress = v2net.UDPDestination(v.config.GetNetAddress(), v.meta.Port) + v.udpAddress = net.UDPDestination(v.config.GetNetAddress(), v.meta.Port) v.udpHub = udpHub v.udpMutex.Unlock() return nil @@ -43,7 +43,7 @@ func (v *Server) handleUDPPayload(payload *buf.Buffer, session *proxy.SessionInf dataBuf := buf.NewSmall() dataBuf.Append(data) - v.udpServer.Dispatch(&proxy.SessionInfo{Source: source, Destination: request.Destination(), Inbound: v.meta}, dataBuf, func(destination v2net.Destination, payload *buf.Buffer) { + v.udpServer.Dispatch(&proxy.SessionInfo{Source: source, Destination: request.Destination(), Inbound: v.meta}, dataBuf, func(destination net.Destination, payload *buf.Buffer) { defer payload.Release() log.Info("Socks: Writing back UDP response with ", payload.Len(), " bytes to ", destination) diff --git a/testing/assert/address.go b/testing/assert/address.go index b9ee2a186..f104851ec 100644 --- a/testing/assert/address.go +++ b/testing/assert/address.go @@ -1,10 +1,10 @@ package assert import ( - v2net "v2ray.com/core/common/net" + "v2ray.com/core/common/net" ) -func (v *Assert) Address(value v2net.Address) *AddressSubject { +func (v *Assert) Address(value net.Address) *AddressSubject { return &AddressSubject{ Subject: Subject{ disp: value.String(), @@ -16,16 +16,16 @@ func (v *Assert) Address(value v2net.Address) *AddressSubject { type AddressSubject struct { Subject - value v2net.Address + value net.Address } -func (subject *AddressSubject) NotEquals(another v2net.Address) { +func (subject *AddressSubject) NotEquals(another net.Address) { if subject.value == another { subject.Fail("not equals to", another.String()) } } -func (subject *AddressSubject) Equals(another v2net.Address) { +func (subject *AddressSubject) Equals(another net.Address) { if subject.value != another { subject.Fail("equals to", another.String()) } diff --git a/testing/assert/destination.go b/testing/assert/destination.go index 0425654bd..581c08e07 100644 --- a/testing/assert/destination.go +++ b/testing/assert/destination.go @@ -1,10 +1,10 @@ package assert import ( - v2net "v2ray.com/core/common/net" + "v2ray.com/core/common/net" ) -func (v *Assert) Destination(value v2net.Destination) *DestinationSubject { +func (v *Assert) Destination(value net.Destination) *DestinationSubject { return &DestinationSubject{ Subject: Subject{ disp: value.String(), @@ -16,29 +16,29 @@ func (v *Assert) Destination(value v2net.Destination) *DestinationSubject { type DestinationSubject struct { Subject - value v2net.Destination + value net.Destination } func (v *DestinationSubject) IsTCP() { - if v.value.Network != v2net.Network_TCP { + if v.value.Network != net.Network_TCP { v.Fail("is", "a TCP destination") } } func (v *DestinationSubject) IsNotTCP() { - if v.value.Network == v2net.Network_TCP { + if v.value.Network == net.Network_TCP { v.Fail("is not", "a TCP destination") } } func (v *DestinationSubject) IsUDP() { - if v.value.Network != v2net.Network_UDP { + if v.value.Network != net.Network_UDP { v.Fail("is", "a UDP destination") } } func (v *DestinationSubject) IsNotUDP() { - if v.value.Network == v2net.Network_UDP { + if v.value.Network == net.Network_UDP { v.Fail("is not", "a UDP destination") } } diff --git a/testing/assert/port.go b/testing/assert/port.go index 5dd03a5d4..f53fa4e98 100644 --- a/testing/assert/port.go +++ b/testing/assert/port.go @@ -1,10 +1,10 @@ package assert import ( - v2net "v2ray.com/core/common/net" + "v2ray.com/core/common/net" ) -func (v *Assert) Port(value v2net.Port) *PortSubject { +func (v *Assert) Port(value net.Port) *PortSubject { return &PortSubject{ Subject: Subject{ a: v, @@ -16,22 +16,22 @@ func (v *Assert) Port(value v2net.Port) *PortSubject { type PortSubject struct { Subject - value v2net.Port + value net.Port } -func (subject *PortSubject) Equals(expectation v2net.Port) { +func (subject *PortSubject) Equals(expectation net.Port) { if subject.value.Value() != expectation.Value() { subject.Fail("is equal to", expectation.String()) } } -func (subject *PortSubject) GreaterThan(expectation v2net.Port) { +func (subject *PortSubject) GreaterThan(expectation net.Port) { if subject.value.Value() <= expectation.Value() { subject.Fail("is greater than", expectation.String()) } } -func (subject *PortSubject) LessThan(expectation v2net.Port) { +func (subject *PortSubject) LessThan(expectation net.Port) { if subject.value.Value() >= expectation.Value() { subject.Fail("is less than", expectation.String()) } diff --git a/testing/scenarios/common.go b/testing/scenarios/common.go index 345c0742b..84c0c8d31 100644 --- a/testing/scenarios/common.go +++ b/testing/scenarios/common.go @@ -1,11 +1,10 @@ package scenarios import ( + "net" "sync/atomic" "time" - "net" - "github.com/golang/protobuf/proto" "v2ray.com/core" v2net "v2ray.com/core/common/net" diff --git a/testing/scenarios/http_test.go b/testing/scenarios/http_test.go index d471a3432..e39fc1aaa 100644 --- a/testing/scenarios/http_test.go +++ b/testing/scenarios/http_test.go @@ -6,7 +6,7 @@ import ( "net/url" "testing" - v2net "v2ray.com/core/common/net" + "v2ray.com/core/common/net" "v2ray.com/core/testing/assert" v2http "v2ray.com/core/testing/servers/http" ) @@ -15,7 +15,7 @@ func TestHttpProxy(t *testing.T) { assert := assert.On(t) httpServer := &v2http.Server{ - Port: v2net.Port(50042), + Port: net.Port(50042), PathHandler: make(map[string]http.HandlerFunc), } _, err := httpServer.Start() @@ -49,7 +49,7 @@ func TestBlockHTTP(t *testing.T) { assert := assert.On(t) httpServer := &v2http.Server{ - Port: v2net.Port(50042), + Port: net.Port(50042), PathHandler: make(map[string]http.HandlerFunc), } _, err := httpServer.Start() diff --git a/transport/internet/dialer_test.go b/transport/internet/dialer_test.go index 56f500649..41858065e 100644 --- a/transport/internet/dialer_test.go +++ b/transport/internet/dialer_test.go @@ -3,7 +3,7 @@ package internet_test import ( "testing" - v2net "v2ray.com/core/common/net" + "v2ray.com/core/common/net" "v2ray.com/core/testing/assert" "v2ray.com/core/testing/servers/tcp" . "v2ray.com/core/transport/internet" @@ -17,7 +17,7 @@ func TestDialWithLocalAddr(t *testing.T) { assert.Error(err).IsNil() defer server.Close() - conn, err := DialSystem(v2net.LocalHostIP, v2net.TCPDestination(v2net.LocalHostIP, dest.Port)) + conn, err := DialSystem(net.LocalHostIP, net.TCPDestination(net.LocalHostIP, dest.Port)) assert.Error(err).IsNil() assert.String(conn.RemoteAddr().String()).Equals("127.0.0.1:" + dest.Port.String()) conn.Close() diff --git a/transport/internet/internal/pool_test.go b/transport/internet/internal/pool_test.go index 65f5a6d0d..ceec14b51 100644 --- a/transport/internet/internal/pool_test.go +++ b/transport/internet/internal/pool_test.go @@ -4,6 +4,7 @@ import ( "net" "testing" "time" + v2net "v2ray.com/core/common/net" "v2ray.com/core/testing/assert" . "v2ray.com/core/transport/internet/internal" diff --git a/transport/internet/kcp/dialer.go b/transport/internet/kcp/dialer.go index e672397fa..254aea627 100644 --- a/transport/internet/kcp/dialer.go +++ b/transport/internet/kcp/dialer.go @@ -1,13 +1,12 @@ package kcp import ( + "crypto/cipher" "crypto/tls" "net" "sync" "sync/atomic" - "crypto/cipher" - "v2ray.com/core/common" "v2ray.com/core/common/buf" "v2ray.com/core/common/dice" diff --git a/transport/internet/kcp/listener.go b/transport/internet/kcp/listener.go index 1a57f4b9c..e94bfefb4 100644 --- a/transport/internet/kcp/listener.go +++ b/transport/internet/kcp/listener.go @@ -1,14 +1,13 @@ package kcp import ( + "crypto/cipher" "crypto/tls" "io" "net" "sync" "time" - "crypto/cipher" - "v2ray.com/core/common" "v2ray.com/core/common/buf" "v2ray.com/core/common/errors"