1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-10 01:40:44 +00: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/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()

View File

@ -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,
},

View File

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

View File

@ -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

View File

@ -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")
}

View File

@ -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")

View File

@ -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

View File

@ -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
}

View File

@ -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()
}

View File

@ -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

View File

@ -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.

View File

@ -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

View File

@ -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))
}

View File

@ -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{}
}

View File

@ -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)
}

View File

@ -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()
}

View File

@ -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)

View File

@ -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())
}

View File

@ -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")
}
}

View File

@ -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())
}

View File

@ -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"

View File

@ -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()

View File

@ -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()

View File

@ -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"

View File

@ -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"

View File

@ -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"