1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 09:36:34 -05:00

clean imports

This commit is contained in:
Darien Raymond 2017-01-14 00:27:45 +01:00
parent b40a139310
commit 8b00d6fc30
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
26 changed files with 96 additions and 100 deletions

View File

@ -12,7 +12,7 @@ import (
"v2ray.com/core/common/buf" "v2ray.com/core/common/buf"
"v2ray.com/core/common/errors" "v2ray.com/core/common/errors"
"v2ray.com/core/common/log" "v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net" "v2ray.com/core/common/net"
"v2ray.com/core/proxy" "v2ray.com/core/proxy"
"v2ray.com/core/transport/ray" "v2ray.com/core/transport/ray"
) )
@ -77,7 +77,7 @@ func (v *DefaultDispatcher) DispatchToOutbound(session *proxy.SessionInfo) ray.I
return direct 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 { if err := wait(); err != nil {
log.Info("DefaultDispatcher: Failed precondition: ", err) log.Info("DefaultDispatcher: Failed precondition: ", err)
link.OutboundInput().CloseError() link.OutboundInput().CloseError()

View File

@ -9,7 +9,7 @@ import (
"v2ray.com/core/app/proxyman" "v2ray.com/core/app/proxyman"
_ "v2ray.com/core/app/proxyman/outbound" _ "v2ray.com/core/app/proxyman/outbound"
"v2ray.com/core/common" "v2ray.com/core/common"
v2net "v2ray.com/core/common/net" "v2ray.com/core/common/net"
"v2ray.com/core/proxy" "v2ray.com/core/proxy"
"v2ray.com/core/proxy/freedom" "v2ray.com/core/proxy/freedom"
"v2ray.com/core/testing/assert" "v2ray.com/core/testing/assert"
@ -50,7 +50,7 @@ func TestProxyDial(t *testing.T) {
dest, err := tcpServer.Start() dest, err := tcpServer.Start()
assert.Error(err).IsNil() 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{ Stream: &internet.StreamConfig{
Protocol: internet.TransportProtocol_TCP, Protocol: internet.TransportProtocol_TCP,
}, },

View File

@ -2,7 +2,6 @@ package receiver
import ( import (
"net" "net"
"time" "time"
v2net "v2ray.com/core/common/net" v2net "v2ray.com/core/common/net"

View File

@ -8,7 +8,7 @@ import (
"v2ray.com/core/common" "v2ray.com/core/common"
"v2ray.com/core/common/errors" "v2ray.com/core/common/errors"
"v2ray.com/core/common/log" "v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net" "v2ray.com/core/common/net"
"v2ray.com/core/proxy" "v2ray.com/core/proxy"
) )
@ -55,17 +55,17 @@ func NewRouter(ctx context.Context, config *Config) (*Router, error) {
} }
// Private: Visible for testing. // 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()) ips := v.dnsServer.Get(dest.Address.Domain())
if len(ips) == 0 { if len(ips) == 0 {
return nil return nil
} }
dests := make([]v2net.Destination, len(ips)) dests := make([]net.Destination, len(ips))
for idx, ip := range ips { for idx, ip := range ips {
if dest.Network == v2net.Network_TCP { if dest.Network == net.Network_TCP {
dests[idx] = v2net.TCPDestination(v2net.IPAddress(ip), dest.Port) dests[idx] = net.TCPDestination(net.IPAddress(ip), dest.Port)
} else { } else {
dests[idx] = v2net.UDPDestination(v2net.IPAddress(ip), dest.Port) dests[idx] = net.UDPDestination(net.IPAddress(ip), dest.Port)
} }
} }
return dests return dests

View File

@ -12,7 +12,7 @@ import (
"v2ray.com/core/app/proxyman" "v2ray.com/core/app/proxyman"
_ "v2ray.com/core/app/proxyman/outbound" _ "v2ray.com/core/app/proxyman/outbound"
. "v2ray.com/core/app/router" . "v2ray.com/core/app/router"
v2net "v2ray.com/core/common/net" "v2ray.com/core/common/net"
"v2ray.com/core/proxy" "v2ray.com/core/proxy"
"v2ray.com/core/testing/assert" "v2ray.com/core/testing/assert"
) )
@ -24,8 +24,8 @@ func TestSimpleRouter(t *testing.T) {
Rule: []*RoutingRule{ Rule: []*RoutingRule{
{ {
Tag: "test", Tag: "test",
NetworkList: &v2net.NetworkList{ NetworkList: &net.NetworkList{
Network: []v2net.Network{v2net.Network_TCP}, Network: []net.Network{net.Network_TCP},
}, },
}, },
}, },
@ -41,7 +41,7 @@ func TestSimpleRouter(t *testing.T) {
r := FromSpace(space) 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.Error(err).IsNil()
assert.String(tag).Equals("test") assert.String(tag).Equals("test")
} }

View File

@ -3,14 +3,14 @@ package net_test
import ( import (
"testing" "testing"
v2net "v2ray.com/core/common/net" "v2ray.com/core/common/net"
"v2ray.com/core/testing/assert" "v2ray.com/core/testing/assert"
) )
func TestTCPDestination(t *testing.T) { func TestTCPDestination(t *testing.T) {
assert := assert.On(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).IsTCP()
assert.Destination(dest).IsNotUDP() assert.Destination(dest).IsNotUDP()
assert.Destination(dest).EqualsString("tcp:1.2.3.4:80") assert.Destination(dest).EqualsString("tcp:1.2.3.4:80")
@ -19,7 +19,7 @@ func TestTCPDestination(t *testing.T) {
func TestUDPDestination(t *testing.T) { func TestUDPDestination(t *testing.T) {
assert := assert.On(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).IsNotTCP()
assert.Destination(dest).IsUDP() assert.Destination(dest).IsUDP()
assert.Destination(dest).EqualsString("udp:[2001:4860:4860::8888]:53") assert.Destination(dest).EqualsString("udp:[2001:4860:4860::8888]:53")

View File

@ -3,7 +3,7 @@ package protocol
import ( import (
"runtime" "runtime"
v2net "v2ray.com/core/common/net" "v2ray.com/core/common/net"
"v2ray.com/core/common/uuid" "v2ray.com/core/common/uuid"
) )
@ -58,16 +58,16 @@ type RequestHeader struct {
Command RequestCommand Command RequestCommand
Option RequestOption Option RequestOption
Security Security Security Security
Port v2net.Port Port net.Port
Address v2net.Address Address net.Address
User *User User *User
} }
func (v *RequestHeader) Destination() v2net.Destination { func (v *RequestHeader) Destination() net.Destination {
if v.Command == RequestCommandUDP { 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 type ResponseOption byte
@ -96,8 +96,8 @@ type ResponseHeader struct {
} }
type CommandSwitchAccount struct { type CommandSwitchAccount struct {
Host v2net.Address Host net.Address
Port v2net.Port Port net.Port
ID *uuid.UUID ID *uuid.UUID
AlterIds uint16 AlterIds uint16
Level uint32 Level uint32

View File

@ -5,7 +5,7 @@ import (
"time" "time"
"v2ray.com/core/common/dice" "v2ray.com/core/common/dice"
v2net "v2ray.com/core/common/net" "v2ray.com/core/common/net"
) )
type ValidationStrategy interface { type ValidationStrategy interface {
@ -45,12 +45,12 @@ func (v *TimeoutValidStrategy) Invalidate() {
type ServerSpec struct { type ServerSpec struct {
sync.RWMutex sync.RWMutex
dest v2net.Destination dest net.Destination
users []*User users []*User
valid ValidationStrategy valid ValidationStrategy
} }
func NewServerSpec(dest v2net.Destination, valid ValidationStrategy, users ...*User) *ServerSpec { func NewServerSpec(dest net.Destination, valid ValidationStrategy, users ...*User) *ServerSpec {
return &ServerSpec{ return &ServerSpec{
dest: dest, dest: dest,
users: users, users: users,
@ -59,11 +59,11 @@ func NewServerSpec(dest v2net.Destination, valid ValidationStrategy, users ...*U
} }
func NewServerSpecFromPB(spec ServerEndpoint) *ServerSpec { 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...) return NewServerSpec(dest, AlwaysValid(), spec.User...)
} }
func (v *ServerSpec) Destination() v2net.Destination { func (v *ServerSpec) Destination() net.Destination {
return v.dest return v.dest
} }

View File

@ -2,7 +2,7 @@ package core
import ( import (
"v2ray.com/core/common" "v2ray.com/core/common"
v2net "v2ray.com/core/common/net" "v2ray.com/core/common/net"
) )
func (v *AllocationStrategy) GetConcurrencyValue() uint32 { func (v *AllocationStrategy) GetConcurrencyValue() uint32 {
@ -26,9 +26,9 @@ func (v *InboundConnectionConfig) GetAllocationStrategyValue() *AllocationStrate
return v.AllocationStrategy return v.AllocationStrategy
} }
func (v *InboundConnectionConfig) GetListenOnValue() v2net.Address { func (v *InboundConnectionConfig) GetListenOnValue() net.Address {
if v.GetListenOn() == nil { if v.GetListenOn() == nil {
return v2net.AnyIP return net.AnyIP
} }
return v.ListenOn.AsAddress() return v.ListenOn.AsAddress()
} }
@ -47,9 +47,9 @@ func (v *OutboundConnectionConfig) GetTypedSettings() (interface{}, error) {
return v.GetSettings().GetInstance() return v.GetSettings().GetInstance()
} }
func (v *OutboundConnectionConfig) GetSendThroughValue() v2net.Address { func (v *OutboundConnectionConfig) GetSendThroughValue() net.Address {
if v.GetSendThrough() == nil { if v.GetSendThrough() == nil {
return v2net.AnyIP return net.AnyIP
} }
return v.SendThrough.AsAddress() return v.SendThrough.AsAddress()
} }

View File

@ -1,15 +1,14 @@
package core package core
import ( import (
"context"
"sync" "sync"
"time" "time"
"context"
"v2ray.com/core/app" "v2ray.com/core/app"
"v2ray.com/core/common/dice" "v2ray.com/core/common/dice"
"v2ray.com/core/common/log" "v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net" "v2ray.com/core/common/net"
"v2ray.com/core/common/retry" "v2ray.com/core/common/retry"
"v2ray.com/core/proxy" "v2ray.com/core/proxy"
) )
@ -18,7 +17,7 @@ type InboundDetourHandlerDynamic struct {
sync.RWMutex sync.RWMutex
space app.Space space app.Space
config *InboundConnectionConfig config *InboundConnectionConfig
portsInUse map[v2net.Port]bool portsInUse map[net.Port]bool
ichs []proxy.InboundHandler ichs []proxy.InboundHandler
ich2Recyle []proxy.InboundHandler ich2Recyle []proxy.InboundHandler
lastRefresh time.Time lastRefresh time.Time
@ -30,7 +29,7 @@ func NewInboundDetourHandlerDynamic(ctx context.Context, config *InboundConnecti
handler := &InboundDetourHandlerDynamic{ handler := &InboundDetourHandlerDynamic{
space: space, space: space,
config: config, config: config,
portsInUse: make(map[v2net.Port]bool), portsInUse: make(map[net.Port]bool),
ctx: ctx, ctx: ctx,
} }
handler.ichs = make([]proxy.InboundHandler, config.GetAllocationStrategyValue().GetConcurrencyValue()) handler.ichs = make([]proxy.InboundHandler, config.GetAllocationStrategyValue().GetConcurrencyValue())
@ -56,11 +55,11 @@ func NewInboundDetourHandlerDynamic(ctx context.Context, config *InboundConnecti
return handler, nil 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 delta := int(v.config.PortRange.To) - int(v.config.PortRange.From) + 1
for { for {
r := dice.Roll(delta) r := dice.Roll(delta)
port := v.config.PortRange.FromPort() + v2net.Port(r) port := v.config.PortRange.FromPort() + net.Port(r)
_, used := v.portsInUse[port] _, used := v.portsInUse[port]
if !used { if !used {
return port return port

View File

@ -6,7 +6,7 @@ import (
"time" "time"
"v2ray.com/core/common" "v2ray.com/core/common"
v2net "v2ray.com/core/common/net" "v2ray.com/core/common/net"
"v2ray.com/core/transport/ray" "v2ray.com/core/transport/ray"
) )
@ -27,7 +27,7 @@ func New(ctx context.Context, config *Config) (*Handler, error) {
} }
// Dispatch implements OutboundHandler.Dispatch(). // 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()) v.response.WriteTo(ray.OutboundOutput())
// CloseError() will immediately close the connection. // CloseError() will immediately close the connection.
// 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

@ -1,11 +1,11 @@
package dokodemo package dokodemo
import ( 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. // 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() addr := v.Address.AsAddress()
if addr == nil { if addr == nil {
return nil return nil

View File

@ -6,30 +6,30 @@ import (
"syscall" "syscall"
"v2ray.com/core/common/log" "v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net" "v2ray.com/core/common/net"
"v2ray.com/core/transport/internet" "v2ray.com/core/transport/internet"
) )
const SO_ORIGINAL_DST = 80 const SO_ORIGINAL_DST = 80
func GetOriginalDestination(conn internet.Connection) v2net.Destination { func GetOriginalDestination(conn internet.Connection) net.Destination {
tcpConn, ok := conn.(internet.SysFd) tcpConn, ok := conn.(internet.SysFd)
if !ok { if !ok {
log.Info("Dokodemo: Failed to get sys fd.") log.Info("Dokodemo: Failed to get sys fd.")
return v2net.Destination{} return net.Destination{}
} }
fd, err := tcpConn.SysFd() fd, err := tcpConn.SysFd()
if err != nil { if err != nil {
log.Info("Dokodemo: Failed to get original destination: ", err) 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) addr, err := syscall.GetsockoptIPv6Mreq(fd, syscall.IPPROTO_IP, SO_ORIGINAL_DST)
if err != nil { if err != nil {
log.Info("Dokodemo: Failed to call getsockopt: ", err) 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]) port := uint16(addr.Multiaddr[2])<<8 + uint16(addr.Multiaddr[3])
return v2net.TCPDestination(ip, v2net.Port(port)) return net.TCPDestination(ip, net.Port(port))
} }

View File

@ -3,10 +3,10 @@
package dokodemo package dokodemo
import ( import (
v2net "v2ray.com/core/common/net" "v2ray.com/core/common/net"
"v2ray.com/core/transport/internet" "v2ray.com/core/transport/internet"
) )
func GetOriginalDestination(conn internet.Connection) v2net.Destination { func GetOriginalDestination(conn internet.Connection) net.Destination {
return v2net.Destination{} return net.Destination{}
} }

View File

@ -2,7 +2,7 @@
package proxy package proxy
import ( import (
v2net "v2ray.com/core/common/net" "v2ray.com/core/common/net"
"v2ray.com/core/common/protocol" "v2ray.com/core/common/protocol"
"v2ray.com/core/transport/internet" "v2ray.com/core/transport/internet"
"v2ray.com/core/transport/ray" "v2ray.com/core/transport/ray"
@ -16,23 +16,23 @@ const (
) )
type SessionInfo struct { type SessionInfo struct {
Source v2net.Destination Source net.Destination
Destination v2net.Destination Destination net.Destination
User *protocol.User User *protocol.User
Inbound *InboundHandlerMeta Inbound *InboundHandlerMeta
} }
type InboundHandlerMeta struct { type InboundHandlerMeta struct {
Tag string Tag string
Address v2net.Address Address net.Address
Port v2net.Port Port net.Port
AllowPassiveConnection bool AllowPassiveConnection bool
StreamSettings *internet.StreamConfig StreamSettings *internet.StreamConfig
} }
type OutboundHandlerMeta struct { type OutboundHandlerMeta struct {
Tag string Tag string
Address v2net.Address Address net.Address
StreamSettings *internet.StreamConfig StreamSettings *internet.StreamConfig
ProxySettings *internet.ProxyConfig ProxySettings *internet.ProxyConfig
} }
@ -51,11 +51,11 @@ type InboundHandler interface {
// Close stops the handler to accepting anymore inbound connections. // Close stops the handler to accepting anymore inbound connections.
Close() Close()
// Port returns the port that the handler is listening on. // Port returns the port that the handler is listening on.
Port() v2net.Port Port() net.Port
} }
// An OutboundHandler handles outbound network connection for V2Ray. // An OutboundHandler handles outbound network connection for V2Ray.
type OutboundHandler interface { type OutboundHandler interface {
// Dispatch sends one or more Packets to its destination. // Dispatch sends one or more Packets to its destination.
Dispatch(destination v2net.Destination, ray ray.OutboundRay) Dispatch(destination net.Destination, ray ray.OutboundRay)
} }

View File

@ -1,7 +1,7 @@
package socks package socks
import ( import (
v2net "v2ray.com/core/common/net" "v2ray.com/core/common/net"
"v2ray.com/core/common/protocol" "v2ray.com/core/common/protocol"
) )
@ -27,9 +27,9 @@ func (v *ServerConfig) HasAccount(username, password string) bool {
return storedPassed == password return storedPassed == password
} }
func (v *ServerConfig) GetNetAddress() v2net.Address { func (v *ServerConfig) GetNetAddress() net.Address {
if v.Address == nil { if v.Address == nil {
return v2net.LocalHostIP return net.LocalHostIP
} }
return v.Address.AsAddress() return v.Address.AsAddress()
} }

View File

@ -3,7 +3,7 @@ package socks
import ( import (
"v2ray.com/core/common/buf" "v2ray.com/core/common/buf"
"v2ray.com/core/common/log" "v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net" "v2ray.com/core/common/net"
"v2ray.com/core/proxy" "v2ray.com/core/proxy"
"v2ray.com/core/transport/internet/udp" "v2ray.com/core/transport/internet/udp"
) )
@ -16,7 +16,7 @@ func (v *Server) listenUDP() error {
return err return err
} }
v.udpMutex.Lock() 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.udpHub = udpHub
v.udpMutex.Unlock() v.udpMutex.Unlock()
return nil return nil
@ -43,7 +43,7 @@ func (v *Server) handleUDPPayload(payload *buf.Buffer, session *proxy.SessionInf
dataBuf := buf.NewSmall() dataBuf := buf.NewSmall()
dataBuf.Append(data) 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() defer payload.Release()
log.Info("Socks: Writing back UDP response with ", payload.Len(), " bytes to ", destination) log.Info("Socks: Writing back UDP response with ", payload.Len(), " bytes to ", destination)

View File

@ -1,10 +1,10 @@
package assert package assert
import ( 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{ return &AddressSubject{
Subject: Subject{ Subject: Subject{
disp: value.String(), disp: value.String(),
@ -16,16 +16,16 @@ func (v *Assert) Address(value v2net.Address) *AddressSubject {
type AddressSubject struct { type AddressSubject struct {
Subject 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 { if subject.value == another {
subject.Fail("not equals to", another.String()) 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 { if subject.value != another {
subject.Fail("equals to", another.String()) subject.Fail("equals to", another.String())
} }

View File

@ -1,10 +1,10 @@
package assert package assert
import ( 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{ return &DestinationSubject{
Subject: Subject{ Subject: Subject{
disp: value.String(), disp: value.String(),
@ -16,29 +16,29 @@ func (v *Assert) Destination(value v2net.Destination) *DestinationSubject {
type DestinationSubject struct { type DestinationSubject struct {
Subject Subject
value v2net.Destination value net.Destination
} }
func (v *DestinationSubject) IsTCP() { func (v *DestinationSubject) IsTCP() {
if v.value.Network != v2net.Network_TCP { if v.value.Network != net.Network_TCP {
v.Fail("is", "a TCP destination") v.Fail("is", "a TCP destination")
} }
} }
func (v *DestinationSubject) IsNotTCP() { 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") v.Fail("is not", "a TCP destination")
} }
} }
func (v *DestinationSubject) IsUDP() { func (v *DestinationSubject) IsUDP() {
if v.value.Network != v2net.Network_UDP { if v.value.Network != net.Network_UDP {
v.Fail("is", "a UDP destination") v.Fail("is", "a UDP destination")
} }
} }
func (v *DestinationSubject) IsNotUDP() { 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") v.Fail("is not", "a UDP destination")
} }
} }

View File

@ -1,10 +1,10 @@
package assert package assert
import ( 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{ return &PortSubject{
Subject: Subject{ Subject: Subject{
a: v, a: v,
@ -16,22 +16,22 @@ func (v *Assert) Port(value v2net.Port) *PortSubject {
type PortSubject struct { type PortSubject struct {
Subject 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() { if subject.value.Value() != expectation.Value() {
subject.Fail("is equal to", expectation.String()) 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() { if subject.value.Value() <= expectation.Value() {
subject.Fail("is greater than", expectation.String()) 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() { if subject.value.Value() >= expectation.Value() {
subject.Fail("is less than", expectation.String()) subject.Fail("is less than", expectation.String())
} }

View File

@ -1,11 +1,10 @@
package scenarios package scenarios
import ( import (
"net"
"sync/atomic" "sync/atomic"
"time" "time"
"net"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"v2ray.com/core" "v2ray.com/core"
v2net "v2ray.com/core/common/net" v2net "v2ray.com/core/common/net"

View File

@ -6,7 +6,7 @@ import (
"net/url" "net/url"
"testing" "testing"
v2net "v2ray.com/core/common/net" "v2ray.com/core/common/net"
"v2ray.com/core/testing/assert" "v2ray.com/core/testing/assert"
v2http "v2ray.com/core/testing/servers/http" v2http "v2ray.com/core/testing/servers/http"
) )
@ -15,7 +15,7 @@ func TestHttpProxy(t *testing.T) {
assert := assert.On(t) assert := assert.On(t)
httpServer := &v2http.Server{ httpServer := &v2http.Server{
Port: v2net.Port(50042), Port: net.Port(50042),
PathHandler: make(map[string]http.HandlerFunc), PathHandler: make(map[string]http.HandlerFunc),
} }
_, err := httpServer.Start() _, err := httpServer.Start()
@ -49,7 +49,7 @@ func TestBlockHTTP(t *testing.T) {
assert := assert.On(t) assert := assert.On(t)
httpServer := &v2http.Server{ httpServer := &v2http.Server{
Port: v2net.Port(50042), Port: net.Port(50042),
PathHandler: make(map[string]http.HandlerFunc), PathHandler: make(map[string]http.HandlerFunc),
} }
_, err := httpServer.Start() _, err := httpServer.Start()

View File

@ -3,7 +3,7 @@ package internet_test
import ( import (
"testing" "testing"
v2net "v2ray.com/core/common/net" "v2ray.com/core/common/net"
"v2ray.com/core/testing/assert" "v2ray.com/core/testing/assert"
"v2ray.com/core/testing/servers/tcp" "v2ray.com/core/testing/servers/tcp"
. "v2ray.com/core/transport/internet" . "v2ray.com/core/transport/internet"
@ -17,7 +17,7 @@ func TestDialWithLocalAddr(t *testing.T) {
assert.Error(err).IsNil() assert.Error(err).IsNil()
defer server.Close() 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.Error(err).IsNil()
assert.String(conn.RemoteAddr().String()).Equals("127.0.0.1:" + dest.Port.String()) assert.String(conn.RemoteAddr().String()).Equals("127.0.0.1:" + dest.Port.String())
conn.Close() conn.Close()

View File

@ -4,6 +4,7 @@ import (
"net" "net"
"testing" "testing"
"time" "time"
v2net "v2ray.com/core/common/net" v2net "v2ray.com/core/common/net"
"v2ray.com/core/testing/assert" "v2ray.com/core/testing/assert"
. "v2ray.com/core/transport/internet/internal" . "v2ray.com/core/transport/internet/internal"

View File

@ -1,13 +1,12 @@
package kcp package kcp
import ( import (
"crypto/cipher"
"crypto/tls" "crypto/tls"
"net" "net"
"sync" "sync"
"sync/atomic" "sync/atomic"
"crypto/cipher"
"v2ray.com/core/common" "v2ray.com/core/common"
"v2ray.com/core/common/buf" "v2ray.com/core/common/buf"
"v2ray.com/core/common/dice" "v2ray.com/core/common/dice"

View File

@ -1,14 +1,13 @@
package kcp package kcp
import ( import (
"crypto/cipher"
"crypto/tls" "crypto/tls"
"io" "io"
"net" "net"
"sync" "sync"
"time" "time"
"crypto/cipher"
"v2ray.com/core/common" "v2ray.com/core/common"
"v2ray.com/core/common/buf" "v2ray.com/core/common/buf"
"v2ray.com/core/common/errors" "v2ray.com/core/common/errors"