mirror of https://github.com/v2ray/v2ray-core
step 1 to remove reference to net package
parent
c33d7f0e21
commit
1c856a46ab
|
@ -1,9 +1,9 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
DirectPort v2net.Port
|
||||
DirectPort net.Port
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package server
|
|||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
@ -11,7 +10,7 @@ import (
|
|||
"v2ray.com/core/app/log"
|
||||
"v2ray.com/core/common/buf"
|
||||
"v2ray.com/core/common/dice"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/transport/internet/udp"
|
||||
)
|
||||
|
||||
|
@ -22,7 +21,7 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
pseudoDestination = v2net.UDPDestination(v2net.LocalHostIP, v2net.Port(53))
|
||||
pseudoDestination = net.UDPDestination(net.LocalHostIP, net.Port(53))
|
||||
)
|
||||
|
||||
type ARecord struct {
|
||||
|
@ -41,13 +40,13 @@ type PendingRequest struct {
|
|||
|
||||
type UDPNameServer struct {
|
||||
sync.Mutex
|
||||
address v2net.Destination
|
||||
address net.Destination
|
||||
requests map[uint16]*PendingRequest
|
||||
udpServer *udp.Dispatcher
|
||||
nextCleanup time.Time
|
||||
}
|
||||
|
||||
func NewUDPNameServer(address v2net.Destination, dispatcher dispatcher.Interface) *UDPNameServer {
|
||||
func NewUDPNameServer(address net.Destination, dispatcher dispatcher.Interface) *UDPNameServer {
|
||||
s := &UDPNameServer{
|
||||
address: address,
|
||||
requests: make(map[uint16]*PendingRequest),
|
||||
|
|
|
@ -4,7 +4,6 @@ package server
|
|||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
@ -14,7 +13,7 @@ import (
|
|||
"v2ray.com/core/app/dns"
|
||||
"v2ray.com/core/app/log"
|
||||
"v2ray.com/core/common"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -53,10 +52,10 @@ func NewCacheServer(ctx context.Context, config *dns.Config) (*CacheServer, erro
|
|||
server.servers[idx] = &LocalNameServer{}
|
||||
} else {
|
||||
dest := destPB.AsDestination()
|
||||
if dest.Network == v2net.Network_Unknown {
|
||||
dest.Network = v2net.Network_UDP
|
||||
if dest.Network == net.Network_Unknown {
|
||||
dest.Network = net.Network_UDP
|
||||
}
|
||||
if dest.Network == v2net.Network_UDP {
|
||||
if dest.Network == net.Network_UDP {
|
||||
server.servers[idx] = NewUDPNameServer(dest, disp)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"v2ray.com/core/app/proxyman"
|
||||
"v2ray.com/core/app/proxyman/mux"
|
||||
"v2ray.com/core/common/dice"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/proxy"
|
||||
)
|
||||
|
||||
|
@ -20,7 +20,7 @@ type DynamicInboundHandler struct {
|
|||
proxyConfig interface{}
|
||||
receiverConfig *proxyman.ReceiverConfig
|
||||
portMutex sync.Mutex
|
||||
portsInUse map[v2net.Port]bool
|
||||
portsInUse map[net.Port]bool
|
||||
workerMutex sync.RWMutex
|
||||
worker []worker
|
||||
lastRefresh time.Time
|
||||
|
@ -35,14 +35,14 @@ func NewDynamicInboundHandler(ctx context.Context, tag string, receiverConfig *p
|
|||
cancel: cancel,
|
||||
proxyConfig: proxyConfig,
|
||||
receiverConfig: receiverConfig,
|
||||
portsInUse: make(map[v2net.Port]bool),
|
||||
portsInUse: make(map[net.Port]bool),
|
||||
mux: mux.NewServer(ctx),
|
||||
}
|
||||
|
||||
return h, nil
|
||||
}
|
||||
|
||||
func (h *DynamicInboundHandler) allocatePort() v2net.Port {
|
||||
func (h *DynamicInboundHandler) allocatePort() net.Port {
|
||||
from := int(h.receiverConfig.PortRange.From)
|
||||
delta := int(h.receiverConfig.PortRange.To) - from + 1
|
||||
|
||||
|
@ -51,7 +51,7 @@ func (h *DynamicInboundHandler) allocatePort() v2net.Port {
|
|||
|
||||
for {
|
||||
r := dice.Roll(delta)
|
||||
port := v2net.Port(from + r)
|
||||
port := net.Port(from + r)
|
||||
_, used := h.portsInUse[port]
|
||||
if !used {
|
||||
h.portsInUse[port] = true
|
||||
|
@ -63,7 +63,7 @@ func (h *DynamicInboundHandler) allocatePort() v2net.Port {
|
|||
func (h *DynamicInboundHandler) waitAnyCloseWorkers(ctx context.Context, cancel context.CancelFunc, workers []worker, duration time.Duration) {
|
||||
time.Sleep(duration)
|
||||
cancel()
|
||||
ports2Del := make([]v2net.Port, len(workers))
|
||||
ports2Del := make([]net.Port, len(workers))
|
||||
for idx, worker := range workers {
|
||||
ports2Del[idx] = worker.Port()
|
||||
worker.Close()
|
||||
|
@ -86,7 +86,7 @@ func (h *DynamicInboundHandler) refresh() error {
|
|||
|
||||
address := h.receiverConfig.Listen.AsAddress()
|
||||
if address == nil {
|
||||
address = v2net.AnyIP
|
||||
address = net.AnyIP
|
||||
}
|
||||
for i := uint32(0); i < concurrency; i++ {
|
||||
port := h.allocatePort()
|
||||
|
@ -96,7 +96,7 @@ func (h *DynamicInboundHandler) refresh() error {
|
|||
continue
|
||||
}
|
||||
nl := p.Network()
|
||||
if nl.HasNetwork(v2net.Network_TCP) {
|
||||
if nl.HasNetwork(net.Network_TCP) {
|
||||
worker := &tcpWorker{
|
||||
tag: h.tag,
|
||||
address: address,
|
||||
|
@ -114,7 +114,7 @@ func (h *DynamicInboundHandler) refresh() error {
|
|||
workers = append(workers, worker)
|
||||
}
|
||||
|
||||
if nl.HasNetwork(v2net.Network_UDP) {
|
||||
if nl.HasNetwork(net.Network_UDP) {
|
||||
worker := &udpWorker{
|
||||
tag: h.tag,
|
||||
proxy: p,
|
||||
|
@ -164,7 +164,7 @@ func (h *DynamicInboundHandler) Close() {
|
|||
h.cancel()
|
||||
}
|
||||
|
||||
func (h *DynamicInboundHandler) GetRandomInboundProxy() (proxy.Inbound, v2net.Port, int) {
|
||||
func (h *DynamicInboundHandler) GetRandomInboundProxy() (proxy.Inbound, net.Port, int) {
|
||||
h.workerMutex.RLock()
|
||||
defer h.workerMutex.RUnlock()
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ package inbound
|
|||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
@ -12,7 +11,7 @@ import (
|
|||
"v2ray.com/core/app/log"
|
||||
"v2ray.com/core/app/proxyman"
|
||||
"v2ray.com/core/common/buf"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/proxy"
|
||||
"v2ray.com/core/transport/internet"
|
||||
"v2ray.com/core/transport/internet/tcp"
|
||||
|
@ -22,13 +21,13 @@ import (
|
|||
type worker interface {
|
||||
Start() error
|
||||
Close()
|
||||
Port() v2net.Port
|
||||
Port() net.Port
|
||||
Proxy() proxy.Inbound
|
||||
}
|
||||
|
||||
type tcpWorker struct {
|
||||
address v2net.Address
|
||||
port v2net.Port
|
||||
address net.Address
|
||||
port net.Port
|
||||
proxy proxy.Inbound
|
||||
stream *internet.StreamConfig
|
||||
recvOrigDest bool
|
||||
|
@ -55,12 +54,12 @@ func (w *tcpWorker) callback(conn internet.Connection) {
|
|||
if len(w.tag) > 0 {
|
||||
ctx = proxy.ContextWithInboundTag(ctx, w.tag)
|
||||
}
|
||||
ctx = proxy.ContextWithInboundEntryPoint(ctx, v2net.TCPDestination(w.address, w.port))
|
||||
ctx = proxy.ContextWithSource(ctx, v2net.DestinationFromAddr(conn.RemoteAddr()))
|
||||
ctx = proxy.ContextWithInboundEntryPoint(ctx, net.TCPDestination(w.address, w.port))
|
||||
ctx = proxy.ContextWithSource(ctx, net.DestinationFromAddr(conn.RemoteAddr()))
|
||||
if len(w.sniffers) > 0 {
|
||||
ctx = proxyman.ContextWithProtocolSniffers(ctx, w.sniffers)
|
||||
}
|
||||
if err := w.proxy.Process(ctx, v2net.Network_TCP, conn, w.dispatcher); err != nil {
|
||||
if err := w.proxy.Process(ctx, net.Network_TCP, conn, w.dispatcher); err != nil {
|
||||
log.Trace(newError("connection ends").Base(err))
|
||||
}
|
||||
cancel()
|
||||
|
@ -113,7 +112,7 @@ func (w *tcpWorker) Close() {
|
|||
}
|
||||
}
|
||||
|
||||
func (w *tcpWorker) Port() v2net.Port {
|
||||
func (w *tcpWorker) Port() net.Port {
|
||||
return w.port
|
||||
}
|
||||
|
||||
|
@ -178,18 +177,18 @@ type udpWorker struct {
|
|||
|
||||
proxy proxy.Inbound
|
||||
hub *udp.Hub
|
||||
address v2net.Address
|
||||
port v2net.Port
|
||||
address net.Address
|
||||
port net.Port
|
||||
recvOrigDest bool
|
||||
tag string
|
||||
dispatcher dispatcher.Interface
|
||||
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
activeConn map[v2net.Destination]*udpConn
|
||||
activeConn map[net.Destination]*udpConn
|
||||
}
|
||||
|
||||
func (w *udpWorker) getConnection(src v2net.Destination) (*udpConn, bool) {
|
||||
func (w *udpWorker) getConnection(src net.Destination) (*udpConn, bool) {
|
||||
w.Lock()
|
||||
defer w.Unlock()
|
||||
|
||||
|
@ -217,7 +216,7 @@ func (w *udpWorker) getConnection(src v2net.Destination) (*udpConn, bool) {
|
|||
return conn, false
|
||||
}
|
||||
|
||||
func (w *udpWorker) callback(b *buf.Buffer, source v2net.Destination, originalDest v2net.Destination) {
|
||||
func (w *udpWorker) callback(b *buf.Buffer, source net.Destination, originalDest net.Destination) {
|
||||
conn, existing := w.getConnection(source)
|
||||
select {
|
||||
case conn.input <- b:
|
||||
|
@ -237,8 +236,8 @@ func (w *udpWorker) callback(b *buf.Buffer, source v2net.Destination, originalDe
|
|||
ctx = proxy.ContextWithInboundTag(ctx, w.tag)
|
||||
}
|
||||
ctx = proxy.ContextWithSource(ctx, source)
|
||||
ctx = proxy.ContextWithInboundEntryPoint(ctx, v2net.UDPDestination(w.address, w.port))
|
||||
if err := w.proxy.Process(ctx, v2net.Network_UDP, conn, w.dispatcher); err != nil {
|
||||
ctx = proxy.ContextWithInboundEntryPoint(ctx, net.UDPDestination(w.address, w.port))
|
||||
if err := w.proxy.Process(ctx, net.Network_UDP, conn, w.dispatcher); err != nil {
|
||||
log.Trace(newError("connection ends").Base(err))
|
||||
}
|
||||
w.removeConn(source)
|
||||
|
@ -247,14 +246,14 @@ func (w *udpWorker) callback(b *buf.Buffer, source v2net.Destination, originalDe
|
|||
}
|
||||
}
|
||||
|
||||
func (w *udpWorker) removeConn(src v2net.Destination) {
|
||||
func (w *udpWorker) removeConn(src net.Destination) {
|
||||
w.Lock()
|
||||
delete(w.activeConn, src)
|
||||
w.Unlock()
|
||||
}
|
||||
|
||||
func (w *udpWorker) Start() error {
|
||||
w.activeConn = make(map[v2net.Destination]*udpConn)
|
||||
w.activeConn = make(map[net.Destination]*udpConn)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
w.ctx = ctx
|
||||
w.cancel = cancel
|
||||
|
@ -299,7 +298,7 @@ func (w *udpWorker) monitor() {
|
|||
}
|
||||
}
|
||||
|
||||
func (w *udpWorker) Port() v2net.Port {
|
||||
func (w *udpWorker) Port() net.Port {
|
||||
return w.port
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ package outbound
|
|||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"v2ray.com/core/app"
|
||||
|
@ -12,7 +11,7 @@ import (
|
|||
"v2ray.com/core/app/proxyman/mux"
|
||||
"v2ray.com/core/common/buf"
|
||||
"v2ray.com/core/common/errors"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/proxy"
|
||||
"v2ray.com/core/transport/internet"
|
||||
"v2ray.com/core/transport/ray"
|
||||
|
@ -94,7 +93,7 @@ func (h *Handler) Dispatch(ctx context.Context, outboundRay ray.OutboundRay) {
|
|||
}
|
||||
|
||||
// Dial implements proxy.Dialer.Dial().
|
||||
func (h *Handler) Dial(ctx context.Context, dest v2net.Destination) (internet.Connection, error) {
|
||||
func (h *Handler) Dial(ctx context.Context, dest net.Destination) (internet.Connection, error) {
|
||||
if h.senderSettings != nil {
|
||||
if h.senderSettings.ProxySettings.HasTag() {
|
||||
tag := h.senderSettings.ProxySettings.Tag
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package net
|
||||
|
||||
import "net"
|
||||
|
||||
var DialTCP = net.DialTCP
|
||||
var DialUDP = net.DialUDP
|
||||
|
||||
var Listen = net.Listen
|
||||
var ListenTCP = net.ListenTCP
|
||||
var ListenUDP = net.ListenUDP
|
||||
|
||||
var LookupIP = net.LookupIP
|
||||
|
||||
var SplitHostPort = net.SplitHostPort
|
||||
|
||||
type Addr = net.Addr
|
||||
type Conn = net.Conn
|
||||
|
||||
type TCPAddr = net.TCPAddr
|
||||
type TCPConn = net.TCPConn
|
||||
|
||||
type UDPAddr = net.UDPAddr
|
||||
type UDPConn = net.UDPConn
|
||||
|
||||
type UnixConn = net.UnixConn
|
||||
|
||||
type IP = net.IP
|
||||
|
||||
type Error = net.Error
|
||||
type AddrError = net.AddrError
|
||||
|
||||
type Dialer = net.Dialer
|
||||
type Listener = net.Listener
|
||||
type TCPListener = net.TCPListener
|
||||
type UDPListener = net.UDPListener
|
|
@ -4,7 +4,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
. "v2ray.com/core/common/protocol"
|
||||
"v2ray.com/core/testing/assert"
|
||||
)
|
||||
|
@ -13,9 +13,9 @@ func TestServerList(t *testing.T) {
|
|||
assert := assert.On(t)
|
||||
|
||||
list := NewServerList()
|
||||
list.AddServer(NewServerSpec(v2net.TCPDestination(v2net.LocalHostIP, v2net.Port(1)), AlwaysValid()))
|
||||
list.AddServer(NewServerSpec(net.TCPDestination(net.LocalHostIP, net.Port(1)), AlwaysValid()))
|
||||
assert.Uint32(list.Size()).Equals(1)
|
||||
list.AddServer(NewServerSpec(v2net.TCPDestination(v2net.LocalHostIP, v2net.Port(2)), BeforeTime(time.Now().Add(time.Second))))
|
||||
list.AddServer(NewServerSpec(net.TCPDestination(net.LocalHostIP, net.Port(2)), BeforeTime(time.Now().Add(time.Second))))
|
||||
assert.Uint32(list.Size()).Equals(2)
|
||||
|
||||
server := list.GetServer(1)
|
||||
|
@ -32,9 +32,9 @@ func TestServerPicker(t *testing.T) {
|
|||
assert := assert.On(t)
|
||||
|
||||
list := NewServerList()
|
||||
list.AddServer(NewServerSpec(v2net.TCPDestination(v2net.LocalHostIP, v2net.Port(1)), AlwaysValid()))
|
||||
list.AddServer(NewServerSpec(v2net.TCPDestination(v2net.LocalHostIP, v2net.Port(2)), BeforeTime(time.Now().Add(time.Second))))
|
||||
list.AddServer(NewServerSpec(v2net.TCPDestination(v2net.LocalHostIP, v2net.Port(3)), BeforeTime(time.Now().Add(time.Second))))
|
||||
list.AddServer(NewServerSpec(net.TCPDestination(net.LocalHostIP, net.Port(1)), AlwaysValid()))
|
||||
list.AddServer(NewServerSpec(net.TCPDestination(net.LocalHostIP, net.Port(2)), BeforeTime(time.Now().Add(time.Second))))
|
||||
list.AddServer(NewServerSpec(net.TCPDestination(net.LocalHostIP, net.Port(3)), BeforeTime(time.Now().Add(time.Second))))
|
||||
|
||||
picker := NewRoundRobinServerPicker(list)
|
||||
server := picker.PickServer()
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"bufio"
|
||||
"context"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"runtime"
|
||||
"strconv"
|
||||
|
@ -17,7 +16,7 @@ import (
|
|||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/buf"
|
||||
"v2ray.com/core/common/errors"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/signal"
|
||||
"v2ray.com/core/transport/internet"
|
||||
)
|
||||
|
@ -39,33 +38,30 @@ func NewServer(ctx context.Context, config *ServerConfig) (*Server, error) {
|
|||
return s, nil
|
||||
}
|
||||
|
||||
func (*Server) Network() v2net.NetworkList {
|
||||
return v2net.NetworkList{
|
||||
Network: []v2net.Network{v2net.Network_TCP},
|
||||
func (*Server) Network() net.NetworkList {
|
||||
return net.NetworkList{
|
||||
Network: []net.Network{net.Network_TCP},
|
||||
}
|
||||
}
|
||||
|
||||
func parseHost(rawHost string, defaultPort v2net.Port) (v2net.Destination, error) {
|
||||
func parseHost(rawHost string, defaultPort net.Port) (net.Destination, error) {
|
||||
port := defaultPort
|
||||
host, rawPort, err := net.SplitHostPort(rawHost)
|
||||
if err != nil {
|
||||
if addrError, ok := err.(*net.AddrError); ok && strings.Contains(addrError.Err, "missing port") {
|
||||
host = rawHost
|
||||
} else {
|
||||
return v2net.Destination{}, err
|
||||
return net.Destination{}, err
|
||||
}
|
||||
} else {
|
||||
intPort, err := strconv.Atoi(rawPort)
|
||||
if err != nil {
|
||||
return v2net.Destination{}, err
|
||||
return net.Destination{}, err
|
||||
}
|
||||
port = v2net.Port(intPort)
|
||||
port = net.Port(intPort)
|
||||
}
|
||||
|
||||
if ip := net.ParseIP(host); ip != nil {
|
||||
return v2net.TCPDestination(v2net.IPAddress(ip), port), nil
|
||||
}
|
||||
return v2net.TCPDestination(v2net.DomainAddress(host), port), nil
|
||||
return net.TCPDestination(net.ParseAddress(host), port), nil
|
||||
}
|
||||
|
||||
func isTimeout(err error) bool {
|
||||
|
@ -73,7 +69,7 @@ func isTimeout(err error) bool {
|
|||
return ok && nerr.Timeout()
|
||||
}
|
||||
|
||||
func (s *Server) Process(ctx context.Context, network v2net.Network, conn internet.Connection, dispatcher dispatcher.Interface) error {
|
||||
func (s *Server) Process(ctx context.Context, network net.Network, conn internet.Connection, dispatcher dispatcher.Interface) error {
|
||||
reader := bufio.NewReaderSize(conn, 2048)
|
||||
|
||||
Start:
|
||||
|
@ -90,9 +86,9 @@ Start:
|
|||
log.Trace(newError("request to Method [", request.Method, "] Host [", request.Host, "] with URL [", request.URL, "]"))
|
||||
conn.SetReadDeadline(time.Time{})
|
||||
|
||||
defaultPort := v2net.Port(80)
|
||||
defaultPort := net.Port(80)
|
||||
if strings.ToLower(request.URL.Scheme) == "https" {
|
||||
defaultPort = v2net.Port(443)
|
||||
defaultPort = net.Port(443)
|
||||
}
|
||||
host := request.Host
|
||||
if len(host) == 0 {
|
||||
|
@ -121,7 +117,7 @@ Start:
|
|||
return err
|
||||
}
|
||||
|
||||
func (s *Server) handleConnect(ctx context.Context, request *http.Request, reader io.Reader, writer io.Writer, dest v2net.Destination, dispatcher dispatcher.Interface) error {
|
||||
func (s *Server) handleConnect(ctx context.Context, request *http.Request, reader io.Reader, writer io.Writer, dest net.Destination, dispatcher dispatcher.Interface) error {
|
||||
_, err := writer.Write([]byte("HTTP/1.1 200 Connection established\r\n\r\n"))
|
||||
if err != nil {
|
||||
return newError("failed to write back OK response").Base(err)
|
||||
|
@ -192,7 +188,7 @@ func StripHopByHopHeaders(header http.Header) {
|
|||
|
||||
var errWaitAnother = newError("keep alive")
|
||||
|
||||
func (s *Server) handlePlainHTTP(ctx context.Context, request *http.Request, reader io.Reader, writer io.Writer, dest v2net.Destination, dispatcher dispatcher.Interface) error {
|
||||
func (s *Server) handlePlainHTTP(ctx context.Context, request *http.Request, reader io.Reader, writer io.Writer, dest net.Destination, dispatcher dispatcher.Interface) error {
|
||||
if len(request.URL.Host) <= 0 {
|
||||
response := &http.Response{
|
||||
Status: "Bad Request",
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
|
||||
"v2ray.com/core/common/buf"
|
||||
"v2ray.com/core/common/crypto"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/protocol"
|
||||
"v2ray.com/core/common/serial"
|
||||
)
|
||||
|
@ -73,12 +73,12 @@ func ReadTCPSession(user *protocol.User, reader io.Reader) (*protocol.RequestHea
|
|||
if err := buffer.AppendSupplier(buf.ReadFullFrom(reader, 4)); err != nil {
|
||||
return nil, nil, newError("failed to read IPv4 address").Base(err)
|
||||
}
|
||||
request.Address = v2net.IPAddress(buffer.BytesFrom(-4))
|
||||
request.Address = net.IPAddress(buffer.BytesFrom(-4))
|
||||
case AddrTypeIPv6:
|
||||
if err := buffer.AppendSupplier(buf.ReadFullFrom(reader, 16)); err != nil {
|
||||
return nil, nil, newError("failed to read IPv6 address").Base(err)
|
||||
}
|
||||
request.Address = v2net.IPAddress(buffer.BytesFrom(-16))
|
||||
request.Address = net.IPAddress(buffer.BytesFrom(-16))
|
||||
case AddrTypeDomain:
|
||||
if err := buffer.AppendSupplier(buf.ReadFullFrom(reader, 1)); err != nil {
|
||||
return nil, nil, newError("failed to read domain lenth.").Base(err)
|
||||
|
@ -88,7 +88,7 @@ func ReadTCPSession(user *protocol.User, reader io.Reader) (*protocol.RequestHea
|
|||
if err != nil {
|
||||
return nil, nil, newError("failed to read domain").Base(err)
|
||||
}
|
||||
request.Address = v2net.DomainAddress(string(buffer.BytesFrom(-domainLength)))
|
||||
request.Address = net.DomainAddress(string(buffer.BytesFrom(-domainLength)))
|
||||
default:
|
||||
// Check address validity after OTA verification.
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ func ReadTCPSession(user *protocol.User, reader io.Reader) (*protocol.RequestHea
|
|||
if err != nil {
|
||||
return nil, nil, newError("failed to read port").Base(err)
|
||||
}
|
||||
request.Port = v2net.PortFromBytes(buffer.BytesFrom(-2))
|
||||
request.Port = net.PortFromBytes(buffer.BytesFrom(-2))
|
||||
|
||||
if request.Option.Has(RequestOptionOneTimeAuth) {
|
||||
actualAuth := make([]byte, AuthSize)
|
||||
|
@ -152,13 +152,13 @@ func WriteTCPRequest(request *protocol.RequestHeader, writer io.Writer) (buf.Wri
|
|||
header := buf.NewLocal(512)
|
||||
|
||||
switch request.Address.Family() {
|
||||
case v2net.AddressFamilyIPv4:
|
||||
case net.AddressFamilyIPv4:
|
||||
header.AppendBytes(AddrTypeIPv4)
|
||||
header.Append([]byte(request.Address.IP()))
|
||||
case v2net.AddressFamilyIPv6:
|
||||
case net.AddressFamilyIPv6:
|
||||
header.AppendBytes(AddrTypeIPv6)
|
||||
header.Append([]byte(request.Address.IP()))
|
||||
case v2net.AddressFamilyDomain:
|
||||
case net.AddressFamilyDomain:
|
||||
header.AppendBytes(AddrTypeDomain, byte(len(request.Address.Domain())))
|
||||
header.Append([]byte(request.Address.Domain()))
|
||||
default:
|
||||
|
@ -246,13 +246,13 @@ func EncodeUDPPacket(request *protocol.RequestHeader, payload []byte) (*buf.Buff
|
|||
iv := buffer.Bytes()
|
||||
|
||||
switch request.Address.Family() {
|
||||
case v2net.AddressFamilyIPv4:
|
||||
case net.AddressFamilyIPv4:
|
||||
buffer.AppendBytes(AddrTypeIPv4)
|
||||
buffer.Append([]byte(request.Address.IP()))
|
||||
case v2net.AddressFamilyIPv6:
|
||||
case net.AddressFamilyIPv6:
|
||||
buffer.AppendBytes(AddrTypeIPv6)
|
||||
buffer.Append([]byte(request.Address.IP()))
|
||||
case v2net.AddressFamilyDomain:
|
||||
case net.AddressFamilyDomain:
|
||||
buffer.AppendBytes(AddrTypeDomain, byte(len(request.Address.Domain())))
|
||||
buffer.Append([]byte(request.Address.Domain()))
|
||||
default:
|
||||
|
@ -332,20 +332,20 @@ func DecodeUDPPacket(user *protocol.User, payload *buf.Buffer) (*protocol.Reques
|
|||
|
||||
switch addrType {
|
||||
case AddrTypeIPv4:
|
||||
request.Address = v2net.IPAddress(payload.BytesTo(4))
|
||||
request.Address = net.IPAddress(payload.BytesTo(4))
|
||||
payload.SliceFrom(4)
|
||||
case AddrTypeIPv6:
|
||||
request.Address = v2net.IPAddress(payload.BytesTo(16))
|
||||
request.Address = net.IPAddress(payload.BytesTo(16))
|
||||
payload.SliceFrom(16)
|
||||
case AddrTypeDomain:
|
||||
domainLength := int(payload.Byte(0))
|
||||
request.Address = v2net.DomainAddress(string(payload.BytesRange(1, 1+domainLength)))
|
||||
request.Address = net.DomainAddress(string(payload.BytesRange(1, 1+domainLength)))
|
||||
payload.SliceFrom(1 + domainLength)
|
||||
default:
|
||||
return nil, nil, newError("unknown address type: ", addrType).AtError()
|
||||
}
|
||||
|
||||
request.Port = v2net.PortFromBytes(payload.BytesTo(2))
|
||||
request.Port = net.PortFromBytes(payload.BytesTo(2))
|
||||
payload.SliceFrom(2)
|
||||
|
||||
return request, payload, nil
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"v2ray.com/core/common/buf"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/protocol"
|
||||
"v2ray.com/core/common/serial"
|
||||
. "v2ray.com/core/proxy/shadowsocks"
|
||||
|
@ -17,7 +17,7 @@ func TestUDPEncoding(t *testing.T) {
|
|||
request := &protocol.RequestHeader{
|
||||
Version: Version,
|
||||
Command: protocol.RequestCommandUDP,
|
||||
Address: v2net.LocalHostIP,
|
||||
Address: net.LocalHostIP,
|
||||
Port: 1234,
|
||||
User: &protocol.User{
|
||||
Email: "love@v2ray.com",
|
||||
|
@ -52,7 +52,7 @@ func TestTCPRequest(t *testing.T) {
|
|||
request: &protocol.RequestHeader{
|
||||
Version: Version,
|
||||
Command: protocol.RequestCommandTCP,
|
||||
Address: v2net.LocalHostIP,
|
||||
Address: net.LocalHostIP,
|
||||
Option: RequestOptionOneTimeAuth,
|
||||
Port: 1234,
|
||||
User: &protocol.User{
|
||||
|
@ -69,7 +69,7 @@ func TestTCPRequest(t *testing.T) {
|
|||
request: &protocol.RequestHeader{
|
||||
Version: Version,
|
||||
Command: protocol.RequestCommandTCP,
|
||||
Address: v2net.LocalHostIPv6,
|
||||
Address: net.LocalHostIPv6,
|
||||
Option: RequestOptionOneTimeAuth,
|
||||
Port: 1234,
|
||||
User: &protocol.User{
|
||||
|
@ -86,7 +86,7 @@ func TestTCPRequest(t *testing.T) {
|
|||
request: &protocol.RequestHeader{
|
||||
Version: Version,
|
||||
Command: protocol.RequestCommandTCP,
|
||||
Address: v2net.DomainAddress("v2ray.com"),
|
||||
Address: net.DomainAddress("v2ray.com"),
|
||||
Option: RequestOptionOneTimeAuth,
|
||||
Port: 1234,
|
||||
User: &protocol.User{
|
||||
|
@ -144,7 +144,7 @@ func TestUDPReaderWriter(t *testing.T) {
|
|||
Writer: cache,
|
||||
Request: &protocol.RequestHeader{
|
||||
Version: Version,
|
||||
Address: v2net.DomainAddress("v2ray.com"),
|
||||
Address: net.DomainAddress("v2ray.com"),
|
||||
Port: 123,
|
||||
User: user,
|
||||
Option: RequestOptionOneTimeAuth,
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"io"
|
||||
|
||||
"v2ray.com/core/common/buf"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/protocol"
|
||||
"v2ray.com/core/common/serial"
|
||||
)
|
||||
|
@ -35,7 +35,7 @@ const (
|
|||
|
||||
type ServerSession struct {
|
||||
config *ServerConfig
|
||||
port v2net.Port
|
||||
port net.Port
|
||||
}
|
||||
|
||||
func (s *ServerSession) Handshake(reader io.Reader, writer io.Writer) (*protocol.RequestHeader, error) {
|
||||
|
@ -51,8 +51,8 @@ func (s *ServerSession) Handshake(reader io.Reader, writer io.Writer) (*protocol
|
|||
if err := buffer.AppendSupplier(buf.ReadFullFrom(reader, 6)); err != nil {
|
||||
return nil, newError("insufficient header").Base(err)
|
||||
}
|
||||
port := v2net.PortFromBytes(buffer.BytesRange(2, 4))
|
||||
address := v2net.IPAddress(buffer.BytesRange(4, 8))
|
||||
port := net.PortFromBytes(buffer.BytesRange(2, 4))
|
||||
address := net.IPAddress(buffer.BytesRange(4, 8))
|
||||
_, err := readUntilNull(reader) // user id
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -62,7 +62,7 @@ func (s *ServerSession) Handshake(reader io.Reader, writer io.Writer) (*protocol
|
|||
if err != nil {
|
||||
return nil, newError("failed to read domain for socks 4a").Base(err)
|
||||
}
|
||||
address = v2net.DomainAddress(domain)
|
||||
address = net.DomainAddress(domain)
|
||||
}
|
||||
|
||||
switch buffer.Byte(1) {
|
||||
|
@ -71,12 +71,12 @@ func (s *ServerSession) Handshake(reader io.Reader, writer io.Writer) (*protocol
|
|||
request.Address = address
|
||||
request.Port = port
|
||||
request.Version = socks4Version
|
||||
if err := writeSocks4Response(writer, socks4RequestGranted, v2net.AnyIP, v2net.Port(0)); err != nil {
|
||||
if err := writeSocks4Response(writer, socks4RequestGranted, net.AnyIP, net.Port(0)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return request, nil
|
||||
default:
|
||||
writeSocks4Response(writer, socks4RequestRejected, v2net.AnyIP, v2net.Port(0))
|
||||
writeSocks4Response(writer, socks4RequestRejected, net.AnyIP, net.Port(0))
|
||||
return nil, newError("unsupported command: ", buffer.Byte(1))
|
||||
}
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ func (s *ServerSession) Handshake(reader io.Reader, writer io.Writer) (*protocol
|
|||
|
||||
cmd := buffer.Byte(1)
|
||||
if cmd == cmdTCPBind || (cmd == cmdUDPPort && !s.config.UdpEnabled) {
|
||||
writeSocks5Response(writer, statusCmdNotSupport, v2net.AnyIP, v2net.Port(0))
|
||||
writeSocks5Response(writer, statusCmdNotSupport, net.AnyIP, net.Port(0))
|
||||
return nil, newError("unsupported command: ", cmd)
|
||||
}
|
||||
|
||||
|
@ -143,12 +143,12 @@ func (s *ServerSession) Handshake(reader io.Reader, writer io.Writer) (*protocol
|
|||
if err := buffer.AppendSupplier(buf.ReadFullFrom(reader, 4)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
request.Address = v2net.IPAddress(buffer.Bytes())
|
||||
request.Address = net.IPAddress(buffer.Bytes())
|
||||
case addrTypeIPv6:
|
||||
if err := buffer.AppendSupplier(buf.ReadFullFrom(reader, 16)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
request.Address = v2net.IPAddress(buffer.Bytes())
|
||||
request.Address = net.IPAddress(buffer.Bytes())
|
||||
case addrTypeDomain:
|
||||
if err := buffer.AppendSupplier(buf.ReadFullFrom(reader, 1)); err != nil {
|
||||
return nil, err
|
||||
|
@ -157,7 +157,7 @@ func (s *ServerSession) Handshake(reader io.Reader, writer io.Writer) (*protocol
|
|||
if err := buffer.AppendSupplier(buf.ReadFullFrom(reader, domainLength)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
request.Address = v2net.ParseAddress(string(buffer.BytesFrom(-domainLength)))
|
||||
request.Address = net.ParseAddress(string(buffer.BytesFrom(-domainLength)))
|
||||
default:
|
||||
return nil, newError("Unknown address type: ", addrType)
|
||||
}
|
||||
|
@ -165,14 +165,14 @@ func (s *ServerSession) Handshake(reader io.Reader, writer io.Writer) (*protocol
|
|||
if err := buffer.AppendSupplier(buf.ReadFullFrom(reader, 2)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
request.Port = v2net.PortFromBytes(buffer.BytesFrom(-2))
|
||||
request.Port = net.PortFromBytes(buffer.BytesFrom(-2))
|
||||
|
||||
responseAddress := v2net.AnyIP
|
||||
responsePort := v2net.Port(1717)
|
||||
responseAddress := net.AnyIP
|
||||
responsePort := net.Port(1717)
|
||||
if request.Command == protocol.RequestCommandUDP {
|
||||
addr := s.config.Address.AsAddress()
|
||||
if addr == nil {
|
||||
addr = v2net.LocalHostIP
|
||||
addr = net.LocalHostIP
|
||||
}
|
||||
responseAddress = addr
|
||||
responsePort = s.port
|
||||
|
@ -244,22 +244,22 @@ func writeSocks5AuthenticationResponse(writer io.Writer, version byte, auth byte
|
|||
return err
|
||||
}
|
||||
|
||||
func appendAddress(buffer *buf.Buffer, address v2net.Address, port v2net.Port) {
|
||||
func appendAddress(buffer *buf.Buffer, address net.Address, port net.Port) {
|
||||
switch address.Family() {
|
||||
case v2net.AddressFamilyIPv4:
|
||||
case net.AddressFamilyIPv4:
|
||||
buffer.AppendBytes(0x01)
|
||||
buffer.Append(address.IP())
|
||||
case v2net.AddressFamilyIPv6:
|
||||
case net.AddressFamilyIPv6:
|
||||
buffer.AppendBytes(0x04)
|
||||
buffer.Append(address.IP())
|
||||
case v2net.AddressFamilyDomain:
|
||||
case net.AddressFamilyDomain:
|
||||
buffer.AppendBytes(0x03, byte(len(address.Domain())))
|
||||
buffer.AppendSupplier(serial.WriteString(address.Domain()))
|
||||
}
|
||||
buffer.AppendSupplier(serial.WriteUint16(port.Value()))
|
||||
}
|
||||
|
||||
func writeSocks5Response(writer io.Writer, errCode byte, address v2net.Address, port v2net.Port) error {
|
||||
func writeSocks5Response(writer io.Writer, errCode byte, address net.Address, port net.Port) error {
|
||||
buffer := buf.NewLocal(64)
|
||||
buffer.AppendBytes(socks5Version, errCode, 0x00 /* reserved */)
|
||||
appendAddress(buffer, address, port)
|
||||
|
@ -268,7 +268,7 @@ func writeSocks5Response(writer io.Writer, errCode byte, address v2net.Address,
|
|||
return err
|
||||
}
|
||||
|
||||
func writeSocks4Response(writer io.Writer, errCode byte, address v2net.Address, port v2net.Port) error {
|
||||
func writeSocks4Response(writer io.Writer, errCode byte, address net.Address, port net.Port) error {
|
||||
buffer := buf.NewLocal(32)
|
||||
buffer.AppendBytes(0x00, errCode)
|
||||
buffer.AppendSupplier(serial.WriteUint16(port.Value()))
|
||||
|
@ -300,16 +300,16 @@ func DecodeUDPPacket(packet []byte) (*protocol.RequestHeader, []byte, error) {
|
|||
return nil, nil, newError("insufficient length of packet")
|
||||
}
|
||||
ip := packet[4:8]
|
||||
request.Port = v2net.PortFromBytes(packet[8:10])
|
||||
request.Address = v2net.IPAddress(ip)
|
||||
request.Port = net.PortFromBytes(packet[8:10])
|
||||
request.Address = net.IPAddress(ip)
|
||||
dataBegin = 10
|
||||
case addrTypeIPv6:
|
||||
if len(packet) < 22 {
|
||||
return nil, nil, newError("insufficient length of packet")
|
||||
}
|
||||
ip := packet[4:20]
|
||||
request.Port = v2net.PortFromBytes(packet[20:22])
|
||||
request.Address = v2net.IPAddress(ip)
|
||||
request.Port = net.PortFromBytes(packet[20:22])
|
||||
request.Address = net.IPAddress(ip)
|
||||
dataBegin = 22
|
||||
case addrTypeDomain:
|
||||
domainLength := int(packet[4])
|
||||
|
@ -317,8 +317,8 @@ func DecodeUDPPacket(packet []byte) (*protocol.RequestHeader, []byte, error) {
|
|||
return nil, nil, newError("insufficient length of packet")
|
||||
}
|
||||
domain := string(packet[5 : 5+domainLength])
|
||||
request.Port = v2net.PortFromBytes(packet[5+domainLength : 5+domainLength+2])
|
||||
request.Address = v2net.ParseAddress(domain)
|
||||
request.Port = net.PortFromBytes(packet[5+domainLength : 5+domainLength+2])
|
||||
request.Address = net.ParseAddress(domain)
|
||||
dataBegin = 5 + domainLength + 2
|
||||
default:
|
||||
return nil, nil, newError("unknown address type ", addrType)
|
||||
|
@ -451,18 +451,18 @@ func ClientHandshake(request *protocol.RequestHeader, reader io.Reader, writer i
|
|||
|
||||
b.Clear()
|
||||
|
||||
var address v2net.Address
|
||||
var address net.Address
|
||||
switch addrType {
|
||||
case addrTypeIPv4:
|
||||
if err := b.AppendSupplier(buf.ReadFullFrom(reader, 4)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
address = v2net.IPAddress(b.Bytes())
|
||||
address = net.IPAddress(b.Bytes())
|
||||
case addrTypeIPv6:
|
||||
if err := b.AppendSupplier(buf.ReadFullFrom(reader, 16)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
address = v2net.IPAddress(b.Bytes())
|
||||
address = net.IPAddress(b.Bytes())
|
||||
case addrTypeDomain:
|
||||
if err := b.AppendSupplier(buf.ReadFullFrom(reader, 1)); err != nil {
|
||||
return nil, err
|
||||
|
@ -471,7 +471,7 @@ func ClientHandshake(request *protocol.RequestHeader, reader io.Reader, writer i
|
|||
if err := b.AppendSupplier(buf.ReadFullFrom(reader, domainLength)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
address = v2net.DomainAddress(string(b.BytesFrom(-domainLength)))
|
||||
address = net.DomainAddress(string(b.BytesFrom(-domainLength)))
|
||||
default:
|
||||
return nil, newError("unknown address type: ", addrType)
|
||||
}
|
||||
|
@ -479,7 +479,7 @@ func ClientHandshake(request *protocol.RequestHeader, reader io.Reader, writer i
|
|||
if err := b.AppendSupplier(buf.ReadFullFrom(reader, 2)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
port := v2net.PortFromBytes(b.BytesFrom(-2))
|
||||
port := net.PortFromBytes(b.BytesFrom(-2))
|
||||
|
||||
if request.Command == protocol.RequestCommandUDP {
|
||||
udpRequest := &protocol.RequestHeader{
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"v2ray.com/core/common/buf"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/protocol"
|
||||
"v2ray.com/core/common/serial"
|
||||
"v2ray.com/core/common/uuid"
|
||||
|
@ -31,8 +31,8 @@ func TestRequestSerialization(t *testing.T) {
|
|||
Version: 1,
|
||||
User: user,
|
||||
Command: protocol.RequestCommandTCP,
|
||||
Address: v2net.DomainAddress("www.v2ray.com"),
|
||||
Port: v2net.Port(443),
|
||||
Address: net.DomainAddress("www.v2ray.com"),
|
||||
Port: net.Port(443),
|
||||
Security: protocol.Security(protocol.SecurityType_AES128_GCM),
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
@ -17,29 +16,29 @@ import (
|
|||
"v2ray.com/core"
|
||||
"v2ray.com/core/app/log"
|
||||
"v2ray.com/core/common"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/retry"
|
||||
)
|
||||
|
||||
func pickPort() v2net.Port {
|
||||
func pickPort() net.Port {
|
||||
listener, err := net.Listen("tcp4", ":0")
|
||||
common.Must(err)
|
||||
defer listener.Close()
|
||||
|
||||
addr := listener.Addr().(*net.TCPAddr)
|
||||
return v2net.Port(addr.Port)
|
||||
return net.Port(addr.Port)
|
||||
}
|
||||
|
||||
func pickUDPPort() v2net.Port {
|
||||
func pickUDPPort() net.Port {
|
||||
conn, err := net.ListenUDP("udp4", &net.UDPAddr{
|
||||
IP: v2net.LocalHostIP.IP(),
|
||||
IP: net.LocalHostIP.IP(),
|
||||
Port: 0,
|
||||
})
|
||||
common.Must(err)
|
||||
defer conn.Close()
|
||||
|
||||
addr := conn.LocalAddr().(*net.UDPAddr)
|
||||
return v2net.Port(addr.Port)
|
||||
return net.Port(addr.Port)
|
||||
}
|
||||
|
||||
func xor(b []byte) []byte {
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"v2ray.com/core/app/dns"
|
||||
"v2ray.com/core/app/proxyman"
|
||||
"v2ray.com/core/app/router"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/serial"
|
||||
"v2ray.com/core/proxy/blackhole"
|
||||
"v2ray.com/core/proxy/freedom"
|
||||
|
@ -32,8 +32,8 @@ func TestResolveIP(t *testing.T) {
|
|||
serverConfig := &core.Config{
|
||||
App: []*serial.TypedMessage{
|
||||
serial.ToTypedMessage(&dns.Config{
|
||||
Hosts: map[string]*v2net.IPOrDomain{
|
||||
"google.com": v2net.NewIPOrDomain(dest.Address),
|
||||
Hosts: map[string]*net.IPOrDomain{
|
||||
"google.com": net.NewIPOrDomain(dest.Address),
|
||||
},
|
||||
}),
|
||||
serial.ToTypedMessage(&router.Config{
|
||||
|
@ -54,15 +54,15 @@ func TestResolveIP(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(serverPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(serverPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&socks.ServerConfig{
|
||||
AuthType: socks.AuthType_NO_AUTH,
|
||||
Accounts: map[string]string{
|
||||
"Test Account": "Test Password",
|
||||
},
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
UdpEnabled: false,
|
||||
}),
|
||||
},
|
||||
|
@ -84,7 +84,7 @@ func TestResolveIP(t *testing.T) {
|
|||
assert.Error(err).IsNil()
|
||||
|
||||
{
|
||||
noAuthDialer, err := xproxy.SOCKS5("tcp", v2net.TCPDestination(v2net.LocalHostIP, serverPort).NetAddr(), nil, xproxy.Direct)
|
||||
noAuthDialer, err := xproxy.SOCKS5("tcp", net.TCPDestination(net.LocalHostIP, serverPort).NetAddr(), nil, xproxy.Direct)
|
||||
assert.Error(err).IsNil()
|
||||
conn, err := noAuthDialer.Dial("tcp", fmt.Sprintf("google.com:%d", dest.Port))
|
||||
assert.Error(err).IsNil()
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
package scenarios
|
||||
|
||||
import (
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"v2ray.com/core"
|
||||
"v2ray.com/core/app/log"
|
||||
"v2ray.com/core/app/proxyman"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/protocol"
|
||||
"v2ray.com/core/common/serial"
|
||||
"v2ray.com/core/common/uuid"
|
||||
|
@ -37,8 +36,8 @@ func TestDokodemoTCP(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(serverPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(serverPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&inbound.Config{
|
||||
User: []*protocol.User{
|
||||
|
@ -70,14 +69,14 @@ func TestDokodemoTCP(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: &v2net.PortRange{From: clientPort, To: clientPort + clientPortRange},
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: &net.PortRange{From: clientPort, To: clientPort + clientPortRange},
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: v2net.NewIPOrDomain(dest.Address),
|
||||
Address: net.NewIPOrDomain(dest.Address),
|
||||
Port: uint32(dest.Port),
|
||||
NetworkList: &v2net.NetworkList{
|
||||
Network: []v2net.Network{v2net.Network_TCP},
|
||||
NetworkList: &net.NetworkList{
|
||||
Network: []net.Network{net.Network_TCP},
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
@ -87,7 +86,7 @@ func TestDokodemoTCP(t *testing.T) {
|
|||
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
||||
Receiver: []*protocol.ServerEndpoint{
|
||||
{
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
Port: uint32(serverPort),
|
||||
User: []*protocol.User{
|
||||
{
|
||||
|
@ -150,8 +149,8 @@ func TestDokodemoUDP(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(serverPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(serverPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&inbound.Config{
|
||||
User: []*protocol.User{
|
||||
|
@ -177,14 +176,14 @@ func TestDokodemoUDP(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: &v2net.PortRange{From: clientPort, To: clientPort + clientPortRange},
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: &net.PortRange{From: clientPort, To: clientPort + clientPortRange},
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: v2net.NewIPOrDomain(dest.Address),
|
||||
Address: net.NewIPOrDomain(dest.Address),
|
||||
Port: uint32(dest.Port),
|
||||
NetworkList: &v2net.NetworkList{
|
||||
Network: []v2net.Network{v2net.Network_UDP},
|
||||
NetworkList: &net.NetworkList{
|
||||
Network: []net.Network{net.Network_UDP},
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
@ -194,7 +193,7 @@ func TestDokodemoUDP(t *testing.T) {
|
|||
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
||||
Receiver: []*protocol.ServerEndpoint{
|
||||
{
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
Port: uint32(serverPort),
|
||||
User: []*protocol.User{
|
||||
{
|
||||
|
|
|
@ -2,7 +2,6 @@ package scenarios
|
|||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
@ -13,7 +12,7 @@ import (
|
|||
"v2ray.com/core/app/log"
|
||||
"v2ray.com/core/app/proxyman"
|
||||
"v2ray.com/core/app/router"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/protocol"
|
||||
"v2ray.com/core/common/serial"
|
||||
"v2ray.com/core/common/uuid"
|
||||
|
@ -47,14 +46,14 @@ func TestPassiveConnection(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(serverPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(serverPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: v2net.NewIPOrDomain(dest.Address),
|
||||
Address: net.NewIPOrDomain(dest.Address),
|
||||
Port: uint32(dest.Port),
|
||||
NetworkList: &v2net.NetworkList{
|
||||
Network: []v2net.Network{v2net.Network_TCP},
|
||||
NetworkList: &net.NetworkList{
|
||||
Network: []net.Network{net.Network_TCP},
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
@ -118,8 +117,8 @@ func TestProxy(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(serverPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(serverPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&inbound.Config{
|
||||
User: []*protocol.User{
|
||||
|
@ -145,8 +144,8 @@ func TestProxy(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(proxyPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(proxyPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&inbound.Config{
|
||||
User: []*protocol.User{
|
||||
|
@ -171,14 +170,14 @@ func TestProxy(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(clientPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(clientPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: v2net.NewIPOrDomain(dest.Address),
|
||||
Address: net.NewIPOrDomain(dest.Address),
|
||||
Port: uint32(dest.Port),
|
||||
NetworkList: &v2net.NetworkList{
|
||||
Network: []v2net.Network{v2net.Network_TCP},
|
||||
NetworkList: &net.NetworkList{
|
||||
Network: []net.Network{net.Network_TCP},
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
@ -188,7 +187,7 @@ func TestProxy(t *testing.T) {
|
|||
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
||||
Receiver: []*protocol.ServerEndpoint{
|
||||
{
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
Port: uint32(serverPort),
|
||||
User: []*protocol.User{
|
||||
{
|
||||
|
@ -211,7 +210,7 @@ func TestProxy(t *testing.T) {
|
|||
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
||||
Receiver: []*protocol.ServerEndpoint{
|
||||
{
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
Port: uint32(proxyPort),
|
||||
User: []*protocol.User{
|
||||
{
|
||||
|
@ -266,8 +265,8 @@ func TestProxyOverKCP(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(serverPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(serverPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
StreamSettings: &internet.StreamConfig{
|
||||
Protocol: internet.TransportProtocol_MKCP,
|
||||
},
|
||||
|
@ -296,8 +295,8 @@ func TestProxyOverKCP(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(proxyPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(proxyPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&inbound.Config{
|
||||
User: []*protocol.User{
|
||||
|
@ -327,14 +326,14 @@ func TestProxyOverKCP(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(clientPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(clientPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: v2net.NewIPOrDomain(dest.Address),
|
||||
Address: net.NewIPOrDomain(dest.Address),
|
||||
Port: uint32(dest.Port),
|
||||
NetworkList: &v2net.NetworkList{
|
||||
Network: []v2net.Network{v2net.Network_TCP},
|
||||
NetworkList: &net.NetworkList{
|
||||
Network: []net.Network{net.Network_TCP},
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
@ -344,7 +343,7 @@ func TestProxyOverKCP(t *testing.T) {
|
|||
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
||||
Receiver: []*protocol.ServerEndpoint{
|
||||
{
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
Port: uint32(serverPort),
|
||||
User: []*protocol.User{
|
||||
{
|
||||
|
@ -370,7 +369,7 @@ func TestProxyOverKCP(t *testing.T) {
|
|||
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
||||
Receiver: []*protocol.ServerEndpoint{
|
||||
{
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
Port: uint32(proxyPort),
|
||||
User: []*protocol.User{
|
||||
{
|
||||
|
@ -432,27 +431,27 @@ func TestBlackhole(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(serverPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(serverPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: v2net.NewIPOrDomain(dest.Address),
|
||||
Address: net.NewIPOrDomain(dest.Address),
|
||||
Port: uint32(dest.Port),
|
||||
NetworkList: &v2net.NetworkList{
|
||||
Network: []v2net.Network{v2net.Network_TCP},
|
||||
NetworkList: &net.NetworkList{
|
||||
Network: []net.Network{net.Network_TCP},
|
||||
},
|
||||
}),
|
||||
},
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(serverPort2),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(serverPort2),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: v2net.NewIPOrDomain(dest2.Address),
|
||||
Address: net.NewIPOrDomain(dest2.Address),
|
||||
Port: uint32(dest2.Port),
|
||||
NetworkList: &v2net.NetworkList{
|
||||
Network: []v2net.Network{v2net.Network_TCP},
|
||||
NetworkList: &net.NetworkList{
|
||||
Network: []net.Network{net.Network_TCP},
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
@ -472,7 +471,7 @@ func TestBlackhole(t *testing.T) {
|
|||
Rule: []*router.RoutingRule{
|
||||
{
|
||||
Tag: "blocked",
|
||||
PortRange: v2net.SinglePortRange(dest2.Port),
|
||||
PortRange: net.SinglePortRange(dest2.Port),
|
||||
},
|
||||
},
|
||||
}),
|
||||
|
@ -522,15 +521,15 @@ func TestForward(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(serverPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(serverPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&socks.ServerConfig{
|
||||
AuthType: socks.AuthType_NO_AUTH,
|
||||
Accounts: map[string]string{
|
||||
"Test Account": "Test Password",
|
||||
},
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
UdpEnabled: false,
|
||||
}),
|
||||
},
|
||||
|
@ -540,7 +539,7 @@ func TestForward(t *testing.T) {
|
|||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||
DestinationOverride: &freedom.DestinationOverride{
|
||||
Server: &protocol.ServerEndpoint{
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
Port: uint32(dest.Port),
|
||||
},
|
||||
},
|
||||
|
@ -553,7 +552,7 @@ func TestForward(t *testing.T) {
|
|||
assert.Error(err).IsNil()
|
||||
|
||||
{
|
||||
noAuthDialer, err := xproxy.SOCKS5("tcp", v2net.TCPDestination(v2net.LocalHostIP, serverPort).NetAddr(), nil, xproxy.Direct)
|
||||
noAuthDialer, err := xproxy.SOCKS5("tcp", net.TCPDestination(net.LocalHostIP, serverPort).NetAddr(), nil, xproxy.Direct)
|
||||
assert.Error(err).IsNil()
|
||||
conn, err := noAuthDialer.Dial("tcp", "google.com:80")
|
||||
assert.Error(err).IsNil()
|
||||
|
@ -588,14 +587,14 @@ func TestUDPConnection(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(clientPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(clientPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: v2net.NewIPOrDomain(dest.Address),
|
||||
Address: net.NewIPOrDomain(dest.Address),
|
||||
Port: uint32(dest.Port),
|
||||
NetworkList: &v2net.NetworkList{
|
||||
Network: []v2net.Network{v2net.Network_UDP},
|
||||
NetworkList: &net.NetworkList{
|
||||
Network: []net.Network{net.Network_UDP},
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
@ -666,25 +665,25 @@ func TestDomainSniffing(t *testing.T) {
|
|||
{
|
||||
Tag: "snif",
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(sniffingPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(sniffingPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
DomainOverride: []proxyman.KnownProtocols{
|
||||
proxyman.KnownProtocols_TLS,
|
||||
},
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
Port: 443,
|
||||
NetworkList: &v2net.NetworkList{
|
||||
Network: []v2net.Network{v2net.Network_TCP},
|
||||
NetworkList: &net.NetworkList{
|
||||
Network: []net.Network{net.Network_TCP},
|
||||
},
|
||||
}),
|
||||
},
|
||||
{
|
||||
Tag: "http",
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(httpPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(httpPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&v2http.ServerConfig{}),
|
||||
},
|
||||
|
@ -695,7 +694,7 @@ func TestDomainSniffing(t *testing.T) {
|
|||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||
DestinationOverride: &freedom.DestinationOverride{
|
||||
Server: &protocol.ServerEndpoint{
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
Port: uint32(sniffingPort),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
|
||||
"v2ray.com/core"
|
||||
"v2ray.com/core/app/proxyman"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/serial"
|
||||
"v2ray.com/core/proxy/freedom"
|
||||
v2http "v2ray.com/core/proxy/http"
|
||||
|
@ -33,8 +33,8 @@ func TestHttpConformance(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(serverPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(serverPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&v2http.ServerConfig{}),
|
||||
},
|
||||
|
|
|
@ -2,7 +2,6 @@ package scenarios
|
|||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"net"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -10,7 +9,7 @@ import (
|
|||
"v2ray.com/core"
|
||||
"v2ray.com/core/app/log"
|
||||
"v2ray.com/core/app/proxyman"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/protocol"
|
||||
"v2ray.com/core/common/serial"
|
||||
"v2ray.com/core/proxy/dokodemo"
|
||||
|
@ -42,8 +41,8 @@ func TestShadowsocksAES256TCP(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(serverPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(serverPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&shadowsocks.ServerConfig{
|
||||
User: &protocol.User{
|
||||
|
@ -71,14 +70,14 @@ func TestShadowsocksAES256TCP(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(clientPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(clientPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: v2net.NewIPOrDomain(dest.Address),
|
||||
Address: net.NewIPOrDomain(dest.Address),
|
||||
Port: uint32(dest.Port),
|
||||
NetworkList: &v2net.NetworkList{
|
||||
Network: []v2net.Network{v2net.Network_TCP},
|
||||
NetworkList: &net.NetworkList{
|
||||
Network: []net.Network{net.Network_TCP},
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
@ -88,7 +87,7 @@ func TestShadowsocksAES256TCP(t *testing.T) {
|
|||
ProxySettings: serial.ToTypedMessage(&shadowsocks.ClientConfig{
|
||||
Server: []*protocol.ServerEndpoint{
|
||||
{
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
Port: uint32(serverPort),
|
||||
User: []*protocol.User{
|
||||
{
|
||||
|
@ -160,8 +159,8 @@ func TestShadowsocksAES128UDP(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(serverPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(serverPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&shadowsocks.ServerConfig{
|
||||
UdpEnabled: true,
|
||||
|
@ -190,14 +189,14 @@ func TestShadowsocksAES128UDP(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(clientPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(clientPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: v2net.NewIPOrDomain(dest.Address),
|
||||
Address: net.NewIPOrDomain(dest.Address),
|
||||
Port: uint32(dest.Port),
|
||||
NetworkList: &v2net.NetworkList{
|
||||
Network: []v2net.Network{v2net.Network_UDP},
|
||||
NetworkList: &net.NetworkList{
|
||||
Network: []net.Network{net.Network_UDP},
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
@ -207,7 +206,7 @@ func TestShadowsocksAES128UDP(t *testing.T) {
|
|||
ProxySettings: serial.ToTypedMessage(&shadowsocks.ClientConfig{
|
||||
Server: []*protocol.ServerEndpoint{
|
||||
{
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
Port: uint32(serverPort),
|
||||
User: []*protocol.User{
|
||||
{
|
||||
|
@ -279,8 +278,8 @@ func TestShadowsocksChacha20TCP(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(serverPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(serverPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&shadowsocks.ServerConfig{
|
||||
User: &protocol.User{
|
||||
|
@ -308,14 +307,14 @@ func TestShadowsocksChacha20TCP(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(clientPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(clientPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: v2net.NewIPOrDomain(dest.Address),
|
||||
Address: net.NewIPOrDomain(dest.Address),
|
||||
Port: uint32(dest.Port),
|
||||
NetworkList: &v2net.NetworkList{
|
||||
Network: []v2net.Network{v2net.Network_TCP},
|
||||
NetworkList: &net.NetworkList{
|
||||
Network: []net.Network{net.Network_TCP},
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
@ -325,7 +324,7 @@ func TestShadowsocksChacha20TCP(t *testing.T) {
|
|||
ProxySettings: serial.ToTypedMessage(&shadowsocks.ClientConfig{
|
||||
Server: []*protocol.ServerEndpoint{
|
||||
{
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
Port: uint32(serverPort),
|
||||
User: []*protocol.User{
|
||||
{
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
package scenarios
|
||||
|
||||
import (
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
xproxy "golang.org/x/net/proxy"
|
||||
socks4 "h12.me/socks"
|
||||
"v2ray.com/core"
|
||||
"v2ray.com/core/app/proxyman"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/protocol"
|
||||
"v2ray.com/core/common/serial"
|
||||
"v2ray.com/core/proxy/dokodemo"
|
||||
|
@ -34,15 +33,15 @@ func TestSocksBridgeTCP(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(serverPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(serverPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&socks.ServerConfig{
|
||||
AuthType: socks.AuthType_PASSWORD,
|
||||
Accounts: map[string]string{
|
||||
"Test Account": "Test Password",
|
||||
},
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
UdpEnabled: false,
|
||||
}),
|
||||
},
|
||||
|
@ -59,14 +58,14 @@ func TestSocksBridgeTCP(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(clientPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(clientPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: v2net.NewIPOrDomain(dest.Address),
|
||||
Address: net.NewIPOrDomain(dest.Address),
|
||||
Port: uint32(dest.Port),
|
||||
NetworkList: &v2net.NetworkList{
|
||||
Network: []v2net.Network{v2net.Network_TCP},
|
||||
NetworkList: &net.NetworkList{
|
||||
Network: []net.Network{net.Network_TCP},
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
@ -76,7 +75,7 @@ func TestSocksBridgeTCP(t *testing.T) {
|
|||
ProxySettings: serial.ToTypedMessage(&socks.ClientConfig{
|
||||
Server: []*protocol.ServerEndpoint{
|
||||
{
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
Port: uint32(serverPort),
|
||||
User: []*protocol.User{
|
||||
{
|
||||
|
@ -131,15 +130,15 @@ func TestSocksBridageUDP(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(serverPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(serverPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&socks.ServerConfig{
|
||||
AuthType: socks.AuthType_PASSWORD,
|
||||
Accounts: map[string]string{
|
||||
"Test Account": "Test Password",
|
||||
},
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
UdpEnabled: true,
|
||||
}),
|
||||
},
|
||||
|
@ -156,14 +155,14 @@ func TestSocksBridageUDP(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(clientPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(clientPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: v2net.NewIPOrDomain(dest.Address),
|
||||
Address: net.NewIPOrDomain(dest.Address),
|
||||
Port: uint32(dest.Port),
|
||||
NetworkList: &v2net.NetworkList{
|
||||
Network: []v2net.Network{v2net.Network_TCP, v2net.Network_UDP},
|
||||
NetworkList: &net.NetworkList{
|
||||
Network: []net.Network{net.Network_TCP, net.Network_UDP},
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
@ -173,7 +172,7 @@ func TestSocksBridageUDP(t *testing.T) {
|
|||
ProxySettings: serial.ToTypedMessage(&socks.ClientConfig{
|
||||
Server: []*protocol.ServerEndpoint{
|
||||
{
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
Port: uint32(serverPort),
|
||||
User: []*protocol.User{
|
||||
{
|
||||
|
@ -229,29 +228,29 @@ func TestSocksConformance(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(authPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(authPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&socks.ServerConfig{
|
||||
AuthType: socks.AuthType_PASSWORD,
|
||||
Accounts: map[string]string{
|
||||
"Test Account": "Test Password",
|
||||
},
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
UdpEnabled: false,
|
||||
}),
|
||||
},
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(noAuthPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(noAuthPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&socks.ServerConfig{
|
||||
AuthType: socks.AuthType_NO_AUTH,
|
||||
Accounts: map[string]string{
|
||||
"Test Account": "Test Password",
|
||||
},
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
UdpEnabled: false,
|
||||
}),
|
||||
},
|
||||
|
@ -267,7 +266,7 @@ func TestSocksConformance(t *testing.T) {
|
|||
assert.Error(err).IsNil()
|
||||
|
||||
{
|
||||
noAuthDialer, err := xproxy.SOCKS5("tcp", v2net.TCPDestination(v2net.LocalHostIP, noAuthPort).NetAddr(), nil, xproxy.Direct)
|
||||
noAuthDialer, err := xproxy.SOCKS5("tcp", net.TCPDestination(net.LocalHostIP, noAuthPort).NetAddr(), nil, xproxy.Direct)
|
||||
assert.Error(err).IsNil()
|
||||
conn, err := noAuthDialer.Dial("tcp", dest.NetAddr())
|
||||
assert.Error(err).IsNil()
|
||||
|
@ -285,7 +284,7 @@ func TestSocksConformance(t *testing.T) {
|
|||
}
|
||||
|
||||
{
|
||||
authDialer, err := xproxy.SOCKS5("tcp", v2net.TCPDestination(v2net.LocalHostIP, authPort).NetAddr(), &xproxy.Auth{User: "Test Account", Password: "Test Password"}, xproxy.Direct)
|
||||
authDialer, err := xproxy.SOCKS5("tcp", net.TCPDestination(net.LocalHostIP, authPort).NetAddr(), &xproxy.Auth{User: "Test Account", Password: "Test Password"}, xproxy.Direct)
|
||||
assert.Error(err).IsNil()
|
||||
conn, err := authDialer.Dial("tcp", dest.NetAddr())
|
||||
assert.Error(err).IsNil()
|
||||
|
@ -303,7 +302,7 @@ func TestSocksConformance(t *testing.T) {
|
|||
}
|
||||
|
||||
{
|
||||
dialer := socks4.DialSocksProxy(socks4.SOCKS4, v2net.TCPDestination(v2net.LocalHostIP, noAuthPort).NetAddr())
|
||||
dialer := socks4.DialSocksProxy(socks4.SOCKS4, net.TCPDestination(net.LocalHostIP, noAuthPort).NetAddr())
|
||||
conn, err := dialer("tcp", dest.NetAddr())
|
||||
assert.Error(err).IsNil()
|
||||
|
||||
|
@ -320,8 +319,8 @@ func TestSocksConformance(t *testing.T) {
|
|||
}
|
||||
|
||||
{
|
||||
dialer := socks4.DialSocksProxy(socks4.SOCKS4A, v2net.TCPDestination(v2net.LocalHostIP, noAuthPort).NetAddr())
|
||||
conn, err := dialer("tcp", v2net.TCPDestination(v2net.LocalHostDomain, tcpServer.Port).NetAddr())
|
||||
dialer := socks4.DialSocksProxy(socks4.SOCKS4A, net.TCPDestination(net.LocalHostIP, noAuthPort).NetAddr())
|
||||
conn, err := dialer("tcp", net.TCPDestination(net.LocalHostDomain, tcpServer.Port).NetAddr())
|
||||
assert.Error(err).IsNil()
|
||||
|
||||
payload := "test payload"
|
||||
|
|
|
@ -2,13 +2,12 @@ package scenarios
|
|||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"v2ray.com/core"
|
||||
"v2ray.com/core/app/proxyman"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/protocol"
|
||||
"v2ray.com/core/common/serial"
|
||||
"v2ray.com/core/common/uuid"
|
||||
|
@ -41,8 +40,8 @@ func TestSimpleTLSConnection(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(serverPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(serverPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
StreamSettings: &internet.StreamConfig{
|
||||
SecurityType: serial.GetMessageType(&tls.Config{}),
|
||||
SecuritySettings: []*serial.TypedMessage{
|
||||
|
@ -75,14 +74,14 @@ func TestSimpleTLSConnection(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(clientPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(clientPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: v2net.NewIPOrDomain(dest.Address),
|
||||
Address: net.NewIPOrDomain(dest.Address),
|
||||
Port: uint32(dest.Port),
|
||||
NetworkList: &v2net.NetworkList{
|
||||
Network: []v2net.Network{v2net.Network_TCP},
|
||||
NetworkList: &net.NetworkList{
|
||||
Network: []net.Network{net.Network_TCP},
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
@ -92,7 +91,7 @@ func TestSimpleTLSConnection(t *testing.T) {
|
|||
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
||||
Receiver: []*protocol.ServerEndpoint{
|
||||
{
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
Port: uint32(serverPort),
|
||||
User: []*protocol.User{
|
||||
{
|
||||
|
@ -155,8 +154,8 @@ func TestTLSOverKCP(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(serverPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(serverPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
StreamSettings: &internet.StreamConfig{
|
||||
Protocol: internet.TransportProtocol_MKCP,
|
||||
SecurityType: serial.GetMessageType(&tls.Config{}),
|
||||
|
@ -190,14 +189,14 @@ func TestTLSOverKCP(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(clientPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(clientPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: v2net.NewIPOrDomain(dest.Address),
|
||||
Address: net.NewIPOrDomain(dest.Address),
|
||||
Port: uint32(dest.Port),
|
||||
NetworkList: &v2net.NetworkList{
|
||||
Network: []v2net.Network{v2net.Network_TCP},
|
||||
NetworkList: &net.NetworkList{
|
||||
Network: []net.Network{net.Network_TCP},
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
@ -207,7 +206,7 @@ func TestTLSOverKCP(t *testing.T) {
|
|||
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
||||
Receiver: []*protocol.ServerEndpoint{
|
||||
{
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
Port: uint32(serverPort),
|
||||
User: []*protocol.User{
|
||||
{
|
||||
|
@ -271,8 +270,8 @@ func TestTLSOverWebSocket(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(serverPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(serverPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
StreamSettings: &internet.StreamConfig{
|
||||
Protocol: internet.TransportProtocol_WebSocket,
|
||||
SecurityType: serial.GetMessageType(&tls.Config{}),
|
||||
|
@ -306,14 +305,14 @@ func TestTLSOverWebSocket(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(clientPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(clientPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: v2net.NewIPOrDomain(dest.Address),
|
||||
Address: net.NewIPOrDomain(dest.Address),
|
||||
Port: uint32(dest.Port),
|
||||
NetworkList: &v2net.NetworkList{
|
||||
Network: []v2net.Network{v2net.Network_TCP},
|
||||
NetworkList: &net.NetworkList{
|
||||
Network: []net.Network{net.Network_TCP},
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
@ -323,7 +322,7 @@ func TestTLSOverWebSocket(t *testing.T) {
|
|||
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
||||
Receiver: []*protocol.ServerEndpoint{
|
||||
{
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
Port: uint32(serverPort),
|
||||
User: []*protocol.User{
|
||||
{
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
package scenarios
|
||||
|
||||
import (
|
||||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"v2ray.com/core"
|
||||
"v2ray.com/core/app/proxyman"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/protocol"
|
||||
"v2ray.com/core/common/serial"
|
||||
"v2ray.com/core/common/uuid"
|
||||
|
@ -39,8 +38,8 @@ func TestHttpConnectionHeader(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(serverPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(serverPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
StreamSettings: &internet.StreamConfig{
|
||||
TransportSettings: []*internet.TransportConfig{
|
||||
{
|
||||
|
@ -75,14 +74,14 @@ func TestHttpConnectionHeader(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(clientPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(clientPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: v2net.NewIPOrDomain(dest.Address),
|
||||
Address: net.NewIPOrDomain(dest.Address),
|
||||
Port: uint32(dest.Port),
|
||||
NetworkList: &v2net.NetworkList{
|
||||
Network: []v2net.Network{v2net.Network_TCP},
|
||||
NetworkList: &net.NetworkList{
|
||||
Network: []net.Network{net.Network_TCP},
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
@ -92,7 +91,7 @@ func TestHttpConnectionHeader(t *testing.T) {
|
|||
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
||||
Receiver: []*protocol.ServerEndpoint{
|
||||
{
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
Port: uint32(serverPort),
|
||||
User: []*protocol.User{
|
||||
{
|
||||
|
|
|
@ -2,7 +2,6 @@ package scenarios
|
|||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"net"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -10,7 +9,7 @@ import (
|
|||
"v2ray.com/core"
|
||||
"v2ray.com/core/app/log"
|
||||
"v2ray.com/core/app/proxyman"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/protocol"
|
||||
"v2ray.com/core/common/serial"
|
||||
"v2ray.com/core/common/uuid"
|
||||
|
@ -41,8 +40,8 @@ func TestVMessDynamicPort(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(serverPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(serverPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&inbound.Config{
|
||||
User: []*protocol.User{
|
||||
|
@ -59,11 +58,11 @@ func TestVMessDynamicPort(t *testing.T) {
|
|||
},
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: &v2net.PortRange{
|
||||
PortRange: &net.PortRange{
|
||||
From: uint32(serverPort + 1),
|
||||
To: uint32(serverPort + 100),
|
||||
},
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
AllocationStrategy: &proxyman.AllocationStrategy{
|
||||
Type: proxyman.AllocationStrategy_Random,
|
||||
Concurrency: &proxyman.AllocationStrategy_AllocationStrategyConcurrency{
|
||||
|
@ -96,14 +95,14 @@ func TestVMessDynamicPort(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(clientPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(clientPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: v2net.NewIPOrDomain(dest.Address),
|
||||
Address: net.NewIPOrDomain(dest.Address),
|
||||
Port: uint32(dest.Port),
|
||||
NetworkList: &v2net.NetworkList{
|
||||
Network: []v2net.Network{v2net.Network_TCP},
|
||||
NetworkList: &net.NetworkList{
|
||||
Network: []net.Network{net.Network_TCP},
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
@ -113,7 +112,7 @@ func TestVMessDynamicPort(t *testing.T) {
|
|||
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
||||
Receiver: []*protocol.ServerEndpoint{
|
||||
{
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
Port: uint32(serverPort),
|
||||
User: []*protocol.User{
|
||||
{
|
||||
|
@ -176,8 +175,8 @@ func TestVMessGCM(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(serverPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(serverPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&inbound.Config{
|
||||
User: []*protocol.User{
|
||||
|
@ -209,14 +208,14 @@ func TestVMessGCM(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(clientPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(clientPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: v2net.NewIPOrDomain(dest.Address),
|
||||
Address: net.NewIPOrDomain(dest.Address),
|
||||
Port: uint32(dest.Port),
|
||||
NetworkList: &v2net.NetworkList{
|
||||
Network: []v2net.Network{v2net.Network_TCP},
|
||||
NetworkList: &net.NetworkList{
|
||||
Network: []net.Network{net.Network_TCP},
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
@ -226,7 +225,7 @@ func TestVMessGCM(t *testing.T) {
|
|||
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
||||
Receiver: []*protocol.ServerEndpoint{
|
||||
{
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
Port: uint32(serverPort),
|
||||
User: []*protocol.User{
|
||||
{
|
||||
|
@ -299,8 +298,8 @@ func TestVMessGCMUDP(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(serverPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(serverPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&inbound.Config{
|
||||
User: []*protocol.User{
|
||||
|
@ -332,14 +331,14 @@ func TestVMessGCMUDP(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(clientPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(clientPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: v2net.NewIPOrDomain(dest.Address),
|
||||
Address: net.NewIPOrDomain(dest.Address),
|
||||
Port: uint32(dest.Port),
|
||||
NetworkList: &v2net.NetworkList{
|
||||
Network: []v2net.Network{v2net.Network_UDP},
|
||||
NetworkList: &net.NetworkList{
|
||||
Network: []net.Network{net.Network_UDP},
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
@ -349,7 +348,7 @@ func TestVMessGCMUDP(t *testing.T) {
|
|||
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
||||
Receiver: []*protocol.ServerEndpoint{
|
||||
{
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
Port: uint32(serverPort),
|
||||
User: []*protocol.User{
|
||||
{
|
||||
|
@ -432,8 +431,8 @@ func TestVMessChacha20(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(serverPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(serverPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&inbound.Config{
|
||||
User: []*protocol.User{
|
||||
|
@ -465,14 +464,14 @@ func TestVMessChacha20(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(clientPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(clientPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: v2net.NewIPOrDomain(dest.Address),
|
||||
Address: net.NewIPOrDomain(dest.Address),
|
||||
Port: uint32(dest.Port),
|
||||
NetworkList: &v2net.NetworkList{
|
||||
Network: []v2net.Network{v2net.Network_TCP},
|
||||
NetworkList: &net.NetworkList{
|
||||
Network: []net.Network{net.Network_TCP},
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
@ -482,7 +481,7 @@ func TestVMessChacha20(t *testing.T) {
|
|||
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
||||
Receiver: []*protocol.ServerEndpoint{
|
||||
{
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
Port: uint32(serverPort),
|
||||
User: []*protocol.User{
|
||||
{
|
||||
|
@ -555,8 +554,8 @@ func TestVMessNone(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(serverPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(serverPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&inbound.Config{
|
||||
User: []*protocol.User{
|
||||
|
@ -588,14 +587,14 @@ func TestVMessNone(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(clientPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(clientPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: v2net.NewIPOrDomain(dest.Address),
|
||||
Address: net.NewIPOrDomain(dest.Address),
|
||||
Port: uint32(dest.Port),
|
||||
NetworkList: &v2net.NetworkList{
|
||||
Network: []v2net.Network{v2net.Network_TCP},
|
||||
NetworkList: &net.NetworkList{
|
||||
Network: []net.Network{net.Network_TCP},
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
@ -605,7 +604,7 @@ func TestVMessNone(t *testing.T) {
|
|||
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
||||
Receiver: []*protocol.ServerEndpoint{
|
||||
{
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
Port: uint32(serverPort),
|
||||
User: []*protocol.User{
|
||||
{
|
||||
|
@ -678,8 +677,8 @@ func TestVMessKCP(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(serverPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(serverPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
StreamSettings: &internet.StreamConfig{
|
||||
Protocol: internet.TransportProtocol_MKCP,
|
||||
},
|
||||
|
@ -714,14 +713,14 @@ func TestVMessKCP(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(clientPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(clientPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: v2net.NewIPOrDomain(dest.Address),
|
||||
Address: net.NewIPOrDomain(dest.Address),
|
||||
Port: uint32(dest.Port),
|
||||
NetworkList: &v2net.NetworkList{
|
||||
Network: []v2net.Network{v2net.Network_TCP},
|
||||
NetworkList: &net.NetworkList{
|
||||
Network: []net.Network{net.Network_TCP},
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
@ -731,7 +730,7 @@ func TestVMessKCP(t *testing.T) {
|
|||
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
||||
Receiver: []*protocol.ServerEndpoint{
|
||||
{
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
Port: uint32(serverPort),
|
||||
User: []*protocol.User{
|
||||
{
|
||||
|
@ -799,7 +798,7 @@ func TestVMessIPv6(t *testing.T) {
|
|||
|
||||
tcpServer := tcp.Server{
|
||||
MsgProcessor: xor,
|
||||
Listen: v2net.LocalHostIPv6,
|
||||
Listen: net.LocalHostIPv6,
|
||||
}
|
||||
dest, err := tcpServer.Start()
|
||||
assert.Error(err).IsNil()
|
||||
|
@ -811,8 +810,8 @@ func TestVMessIPv6(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(serverPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIPv6),
|
||||
PortRange: net.SinglePortRange(serverPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIPv6),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&inbound.Config{
|
||||
User: []*protocol.User{
|
||||
|
@ -844,14 +843,14 @@ func TestVMessIPv6(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(clientPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIPv6),
|
||||
PortRange: net.SinglePortRange(clientPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIPv6),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: v2net.NewIPOrDomain(dest.Address),
|
||||
Address: net.NewIPOrDomain(dest.Address),
|
||||
Port: uint32(dest.Port),
|
||||
NetworkList: &v2net.NetworkList{
|
||||
Network: []v2net.Network{v2net.Network_TCP},
|
||||
NetworkList: &net.NetworkList{
|
||||
Network: []net.Network{net.Network_TCP},
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
@ -861,7 +860,7 @@ func TestVMessIPv6(t *testing.T) {
|
|||
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
||||
Receiver: []*protocol.ServerEndpoint{
|
||||
{
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIPv6),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIPv6),
|
||||
Port: uint32(serverPort),
|
||||
User: []*protocol.User{
|
||||
{
|
||||
|
@ -891,7 +890,7 @@ func TestVMessIPv6(t *testing.T) {
|
|||
assert.Error(err).IsNil()
|
||||
|
||||
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
|
||||
IP: v2net.LocalHostIPv6.IP(),
|
||||
IP: net.LocalHostIPv6.IP(),
|
||||
Port: int(clientPort),
|
||||
})
|
||||
assert.Error(err).IsNil()
|
||||
|
@ -926,8 +925,8 @@ func TestVMessGCMMux(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(serverPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(serverPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&inbound.Config{
|
||||
User: []*protocol.User{
|
||||
|
@ -959,14 +958,14 @@ func TestVMessGCMMux(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(clientPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(clientPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: v2net.NewIPOrDomain(dest.Address),
|
||||
Address: net.NewIPOrDomain(dest.Address),
|
||||
Port: uint32(dest.Port),
|
||||
NetworkList: &v2net.NetworkList{
|
||||
Network: []v2net.Network{v2net.Network_TCP},
|
||||
NetworkList: &net.NetworkList{
|
||||
Network: []net.Network{net.Network_TCP},
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
@ -982,7 +981,7 @@ func TestVMessGCMMux(t *testing.T) {
|
|||
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
||||
Receiver: []*protocol.ServerEndpoint{
|
||||
{
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
Port: uint32(serverPort),
|
||||
User: []*protocol.User{
|
||||
{
|
||||
|
@ -1068,8 +1067,8 @@ func TestVMessGCMMuxUDP(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(serverPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(serverPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&inbound.Config{
|
||||
User: []*protocol.User{
|
||||
|
@ -1102,27 +1101,27 @@ func TestVMessGCMMuxUDP(t *testing.T) {
|
|||
Inbound: []*proxyman.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(clientPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(clientPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: v2net.NewIPOrDomain(dest.Address),
|
||||
Address: net.NewIPOrDomain(dest.Address),
|
||||
Port: uint32(dest.Port),
|
||||
NetworkList: &v2net.NetworkList{
|
||||
Network: []v2net.Network{v2net.Network_TCP},
|
||||
NetworkList: &net.NetworkList{
|
||||
Network: []net.Network{net.Network_TCP},
|
||||
},
|
||||
}),
|
||||
},
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: v2net.SinglePortRange(clientUDPPort),
|
||||
Listen: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
PortRange: net.SinglePortRange(clientUDPPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: v2net.NewIPOrDomain(udpDest.Address),
|
||||
Address: net.NewIPOrDomain(udpDest.Address),
|
||||
Port: uint32(udpDest.Port),
|
||||
NetworkList: &v2net.NetworkList{
|
||||
Network: []v2net.Network{v2net.Network_UDP},
|
||||
NetworkList: &net.NetworkList{
|
||||
Network: []net.Network{net.Network_UDP},
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
@ -1138,7 +1137,7 @@ func TestVMessGCMMuxUDP(t *testing.T) {
|
|||
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
||||
Receiver: []*protocol.ServerEndpoint{
|
||||
{
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
Port: uint32(serverPort),
|
||||
User: []*protocol.User{
|
||||
{
|
||||
|
|
|
@ -3,11 +3,11 @@ package tcp
|
|||
import (
|
||||
"net/http"
|
||||
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
Port v2net.Port
|
||||
Port net.Port
|
||||
PathHandler map[string]http.HandlerFunc
|
||||
accepting bool
|
||||
}
|
||||
|
@ -26,9 +26,9 @@ func (server *Server) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
func (server *Server) Start() (v2net.Destination, error) {
|
||||
func (server *Server) Start() (net.Destination, error) {
|
||||
go http.ListenAndServe("127.0.0.1:"+server.Port.String(), server)
|
||||
return v2net.TCPDestination(v2net.LocalHostIP, v2net.Port(server.Port)), nil
|
||||
return net.TCPDestination(net.LocalHostIP, net.Port(server.Port)), nil
|
||||
}
|
||||
|
||||
func (v *Server) Close() {
|
||||
|
|
|
@ -30,10 +30,10 @@ func (server *Server) Start() (v2net.Destination, error) {
|
|||
if err != nil {
|
||||
return v2net.Destination{}, err
|
||||
}
|
||||
server.Port = v2net.Port(listener.Addr().(*net.TCPAddr).Port)
|
||||
server.Port = v2net.Port(listener.Addr().(*v2net.TCPAddr).Port)
|
||||
server.listener = listener
|
||||
go server.acceptConnections(listener)
|
||||
localAddr := listener.Addr().(*net.TCPAddr)
|
||||
localAddr := listener.Addr().(*v2net.TCPAddr)
|
||||
return v2net.TCPDestination(v2net.IPAddress(localAddr.IP), v2net.Port(localAddr.Port)), nil
|
||||
}
|
||||
|
||||
|
|
|
@ -2,32 +2,31 @@ package udp
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
Port v2net.Port
|
||||
Port net.Port
|
||||
MsgProcessor func(msg []byte) []byte
|
||||
accepting bool
|
||||
conn *net.UDPConn
|
||||
}
|
||||
|
||||
func (server *Server) Start() (v2net.Destination, error) {
|
||||
func (server *Server) Start() (net.Destination, error) {
|
||||
conn, err := net.ListenUDP("udp", &net.UDPAddr{
|
||||
IP: []byte{127, 0, 0, 1},
|
||||
Port: int(server.Port),
|
||||
Zone: "",
|
||||
})
|
||||
if err != nil {
|
||||
return v2net.Destination{}, err
|
||||
return net.Destination{}, err
|
||||
}
|
||||
server.Port = v2net.Port(conn.LocalAddr().(*net.UDPAddr).Port)
|
||||
server.Port = net.Port(conn.LocalAddr().(*net.UDPAddr).Port)
|
||||
server.conn = conn
|
||||
go server.handleConnection(conn)
|
||||
localAddr := conn.LocalAddr().(*net.UDPAddr)
|
||||
return v2net.UDPDestination(v2net.IPAddress(localAddr.IP), v2net.Port(localAddr.Port)), nil
|
||||
return net.UDPDestination(net.IPAddress(localAddr.IP), net.Port(localAddr.Port)), nil
|
||||
}
|
||||
|
||||
func (server *Server) handleConnection(conn *net.UDPConn) {
|
||||
|
|
|
@ -2,12 +2,11 @@ package internet
|
|||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
)
|
||||
|
||||
type Dialer func(ctx context.Context, dest v2net.Destination) (Connection, error)
|
||||
type Dialer func(ctx context.Context, dest net.Destination) (Connection, error)
|
||||
|
||||
var (
|
||||
transportDialerCache = make(map[TransportProtocol]Dialer)
|
||||
|
@ -21,8 +20,8 @@ func RegisterTransportDialer(protocol TransportProtocol, dialer Dialer) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func Dial(ctx context.Context, dest v2net.Destination) (Connection, error) {
|
||||
if dest.Network == v2net.Network_TCP {
|
||||
func Dial(ctx context.Context, dest net.Destination) (Connection, error) {
|
||||
if dest.Network == net.Network_TCP {
|
||||
streamSettings := StreamSettingsFromContext(ctx)
|
||||
protocol := streamSettings.GetEffectiveProtocol()
|
||||
transportSettings, err := streamSettings.GetEffectiveTransportSettings()
|
||||
|
@ -52,6 +51,6 @@ func Dial(ctx context.Context, dest v2net.Destination) (Connection, error) {
|
|||
}
|
||||
|
||||
// DialSystem calls system dialer to create a network connection.
|
||||
func DialSystem(ctx context.Context, src v2net.Address, dest v2net.Destination) (net.Conn, error) {
|
||||
func DialSystem(ctx context.Context, src net.Address, dest net.Destination) (net.Conn, error) {
|
||||
return effectiveSystemDialer.Dial(ctx, src, dest)
|
||||
}
|
||||
|
|
|
@ -2,11 +2,11 @@ package http_test
|
|||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"v2ray.com/core/common/buf"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/serial"
|
||||
"v2ray.com/core/testing/assert"
|
||||
. "v2ray.com/core/transport/internet/headers/http"
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"crypto/cipher"
|
||||
"crypto/tls"
|
||||
"net"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
|
@ -12,7 +11,7 @@ import (
|
|||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/buf"
|
||||
"v2ray.com/core/common/dice"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/transport/internet"
|
||||
v2tls "v2ray.com/core/transport/internet/tls"
|
||||
)
|
||||
|
@ -102,8 +101,8 @@ func (c *ClientConnection) Run() {
|
|||
}
|
||||
}
|
||||
|
||||
func DialKCP(ctx context.Context, dest v2net.Destination) (internet.Connection, error) {
|
||||
dest.Network = v2net.Network_UDP
|
||||
func DialKCP(ctx context.Context, dest net.Destination) (internet.Connection, error) {
|
||||
dest.Network = net.Network_UDP
|
||||
log.Trace(newError("dialing mKCP to ", dest))
|
||||
|
||||
src := internet.DialerSourceFromContext(ctx)
|
||||
|
|
|
@ -4,12 +4,11 @@ import (
|
|||
"context"
|
||||
"crypto/rand"
|
||||
"io"
|
||||
"net"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/testing/assert"
|
||||
"v2ray.com/core/transport/internet"
|
||||
. "v2ray.com/core/transport/internet/kcp"
|
||||
|
@ -18,7 +17,7 @@ import (
|
|||
func TestDialAndListen(t *testing.T) {
|
||||
assert := assert.On(t)
|
||||
|
||||
listerner, err := NewListener(internet.ContextWithTransportSettings(context.Background(), &Config{}), v2net.LocalHostIP, v2net.Port(0), func(ctx context.Context, conn internet.Connection) bool {
|
||||
listerner, err := NewListener(internet.ContextWithTransportSettings(context.Background(), &Config{}), net.LocalHostIP, net.Port(0), func(ctx context.Context, conn internet.Connection) bool {
|
||||
go func(c internet.Connection) {
|
||||
payload := make([]byte, 4096)
|
||||
for {
|
||||
|
@ -36,12 +35,12 @@ func TestDialAndListen(t *testing.T) {
|
|||
return true
|
||||
})
|
||||
assert.Error(err).IsNil()
|
||||
port := v2net.Port(listerner.Addr().(*net.UDPAddr).Port)
|
||||
port := net.Port(listerner.Addr().(*net.UDPAddr).Port)
|
||||
|
||||
ctx := internet.ContextWithTransportSettings(context.Background(), &Config{})
|
||||
wg := new(sync.WaitGroup)
|
||||
for i := 0; i < 10; i++ {
|
||||
clientConn, err := DialKCP(ctx, v2net.UDPDestination(v2net.LocalHostIP, port))
|
||||
clientConn, err := DialKCP(ctx, net.UDPDestination(net.LocalHostIP, port))
|
||||
assert.Error(err).IsNil()
|
||||
wg.Add(1)
|
||||
|
||||
|
|
|
@ -5,22 +5,21 @@ import (
|
|||
"crypto/cipher"
|
||||
"crypto/tls"
|
||||
"io"
|
||||
"net"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"v2ray.com/core/app/log"
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/buf"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/transport/internet"
|
||||
v2tls "v2ray.com/core/transport/internet/tls"
|
||||
"v2ray.com/core/transport/internet/udp"
|
||||
)
|
||||
|
||||
type ConnectionID struct {
|
||||
Remote v2net.Address
|
||||
Port v2net.Port
|
||||
Remote net.Address
|
||||
Port net.Port
|
||||
Conv uint16
|
||||
}
|
||||
|
||||
|
@ -84,7 +83,7 @@ type Listener struct {
|
|||
addConn internet.AddConnection
|
||||
}
|
||||
|
||||
func NewListener(ctx context.Context, address v2net.Address, port v2net.Port, addConn internet.AddConnection) (*Listener, error) {
|
||||
func NewListener(ctx context.Context, address net.Address, port net.Port, addConn internet.AddConnection) (*Listener, error) {
|
||||
networkSettings := internet.TransportSettingsFromContext(ctx)
|
||||
kcpSettings := networkSettings.(*Config)
|
||||
|
||||
|
@ -126,7 +125,7 @@ func NewListener(ctx context.Context, address v2net.Address, port v2net.Port, ad
|
|||
return l, nil
|
||||
}
|
||||
|
||||
func (v *Listener) OnReceive(payload *buf.Buffer, src v2net.Destination, originalDest v2net.Destination) {
|
||||
func (v *Listener) OnReceive(payload *buf.Buffer, src net.Destination, originalDest net.Destination) {
|
||||
defer payload.Release()
|
||||
|
||||
segments := v.reader.Read(payload.Bytes())
|
||||
|
@ -237,7 +236,7 @@ func (v *Listener) Addr() net.Addr {
|
|||
|
||||
type Writer struct {
|
||||
id ConnectionID
|
||||
dest v2net.Destination
|
||||
dest net.Destination
|
||||
hub *udp.Hub
|
||||
listener *Listener
|
||||
}
|
||||
|
@ -251,7 +250,7 @@ func (v *Writer) Close() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func ListenKCP(ctx context.Context, address v2net.Address, port v2net.Port, addConn internet.AddConnection) (internet.Listener, error) {
|
||||
func ListenKCP(ctx context.Context, address net.Address, port net.Port, addConn internet.AddConnection) (internet.Listener, error) {
|
||||
return NewListener(ctx, address, port, addConn)
|
||||
}
|
||||
|
||||
|
|
|
@ -2,10 +2,9 @@ package internet
|
|||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -13,20 +12,20 @@ var (
|
|||
)
|
||||
|
||||
type SystemDialer interface {
|
||||
Dial(ctx context.Context, source v2net.Address, destination v2net.Destination) (net.Conn, error)
|
||||
Dial(ctx context.Context, source net.Address, destination net.Destination) (net.Conn, error)
|
||||
}
|
||||
|
||||
type DefaultSystemDialer struct {
|
||||
}
|
||||
|
||||
func (DefaultSystemDialer) Dial(ctx context.Context, src v2net.Address, dest v2net.Destination) (net.Conn, error) {
|
||||
func (DefaultSystemDialer) Dial(ctx context.Context, src net.Address, dest net.Destination) (net.Conn, error) {
|
||||
dialer := &net.Dialer{
|
||||
Timeout: time.Second * 60,
|
||||
DualStack: true,
|
||||
}
|
||||
if src != nil && src != v2net.AnyIP {
|
||||
if src != nil && src != net.AnyIP {
|
||||
var addr net.Addr
|
||||
if dest.Network == v2net.Network_TCP {
|
||||
if dest.Network == net.Network_TCP {
|
||||
addr = &net.TCPAddr{
|
||||
IP: src.IP(),
|
||||
Port: 0,
|
||||
|
@ -56,7 +55,7 @@ func WithAdapter(dialer SystemDialerAdapter) SystemDialer {
|
|||
}
|
||||
}
|
||||
|
||||
func (v *SimpleSystemDialer) Dial(ctx context.Context, src v2net.Address, dest v2net.Destination) (net.Conn, error) {
|
||||
func (v *SimpleSystemDialer) Dial(ctx context.Context, src net.Address, dest net.Destination) (net.Conn, error) {
|
||||
return v.adapter.Dial(dest.Network.SystemString(), dest.NetAddr())
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
|
||||
"v2ray.com/core/app/log"
|
||||
"v2ray.com/core/common"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/transport/internet"
|
||||
"v2ray.com/core/transport/internet/tls"
|
||||
)
|
||||
|
@ -18,7 +18,7 @@ func getTCPSettingsFromContext(ctx context.Context) *Config {
|
|||
return rawTCPSettings.(*Config)
|
||||
}
|
||||
|
||||
func Dial(ctx context.Context, dest v2net.Destination) (internet.Connection, error) {
|
||||
func Dial(ctx context.Context, dest net.Destination) (internet.Connection, error) {
|
||||
log.Trace(newError("dailing TCP to ", dest))
|
||||
src := internet.DialerSourceFromContext(ctx)
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ type TCPListener struct {
|
|||
}
|
||||
|
||||
func ListenTCP(ctx context.Context, address v2net.Address, port v2net.Port, addConn internet.AddConnection) (internet.Listener, error) {
|
||||
listener, err := net.ListenTCP("tcp", &net.TCPAddr{
|
||||
listener, err := net.ListenTCP("tcp", &v2net.TCPAddr{
|
||||
IP: address.IP(),
|
||||
Port: int(port),
|
||||
})
|
||||
|
|
|
@ -2,10 +2,9 @@ package internet
|
|||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -22,14 +21,14 @@ func RegisterTransportListener(protocol TransportProtocol, listener ListenFunc)
|
|||
|
||||
type AddConnection func(context.Context, Connection) bool
|
||||
|
||||
type ListenFunc func(ctx context.Context, address v2net.Address, port v2net.Port, addConn AddConnection) (Listener, error)
|
||||
type ListenFunc func(ctx context.Context, address net.Address, port net.Port, addConn AddConnection) (Listener, error)
|
||||
|
||||
type Listener interface {
|
||||
Close() error
|
||||
Addr() net.Addr
|
||||
}
|
||||
|
||||
func ListenTCP(ctx context.Context, address v2net.Address, port v2net.Port, conns chan<- Connection) (Listener, error) {
|
||||
func ListenTCP(ctx context.Context, address net.Address, port net.Port, conns chan<- Connection) (Listener, error) {
|
||||
settings := StreamSettingsFromContext(ctx)
|
||||
protocol := settings.GetEffectiveProtocol()
|
||||
transportSettings, err := settings.GetEffectiveTransportSettings()
|
||||
|
|
|
@ -4,13 +4,13 @@ import (
|
|||
"context"
|
||||
|
||||
"v2ray.com/core/common"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/transport/internet"
|
||||
)
|
||||
|
||||
func init() {
|
||||
common.Must(internet.RegisterTransportDialer(internet.TransportProtocol_UDP,
|
||||
func(ctx context.Context, dest v2net.Destination) (internet.Connection, error) {
|
||||
func(ctx context.Context, dest net.Destination) (internet.Connection, error) {
|
||||
src := internet.DialerSourceFromContext(ctx)
|
||||
conn, err := internet.DialSystem(ctx, src, dest)
|
||||
if err != nil {
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"v2ray.com/core/app/dispatcher"
|
||||
"v2ray.com/core/app/log"
|
||||
"v2ray.com/core/common/buf"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/transport/ray"
|
||||
)
|
||||
|
||||
|
@ -15,18 +15,18 @@ type ResponseCallback func(payload *buf.Buffer)
|
|||
|
||||
type Dispatcher struct {
|
||||
sync.RWMutex
|
||||
conns map[v2net.Destination]ray.InboundRay
|
||||
conns map[net.Destination]ray.InboundRay
|
||||
dispatcher dispatcher.Interface
|
||||
}
|
||||
|
||||
func NewDispatcher(dispatcher dispatcher.Interface) *Dispatcher {
|
||||
return &Dispatcher{
|
||||
conns: make(map[v2net.Destination]ray.InboundRay),
|
||||
conns: make(map[net.Destination]ray.InboundRay),
|
||||
dispatcher: dispatcher,
|
||||
}
|
||||
}
|
||||
|
||||
func (v *Dispatcher) RemoveRay(dest v2net.Destination) {
|
||||
func (v *Dispatcher) RemoveRay(dest net.Destination) {
|
||||
v.Lock()
|
||||
defer v.Unlock()
|
||||
if conn, found := v.conns[dest]; found {
|
||||
|
@ -36,7 +36,7 @@ func (v *Dispatcher) RemoveRay(dest v2net.Destination) {
|
|||
}
|
||||
}
|
||||
|
||||
func (v *Dispatcher) getInboundRay(ctx context.Context, dest v2net.Destination) (ray.InboundRay, bool) {
|
||||
func (v *Dispatcher) getInboundRay(ctx context.Context, dest net.Destination) (ray.InboundRay, bool) {
|
||||
v.Lock()
|
||||
defer v.Unlock()
|
||||
|
||||
|
@ -50,7 +50,7 @@ func (v *Dispatcher) getInboundRay(ctx context.Context, dest v2net.Destination)
|
|||
return inboundRay, false
|
||||
}
|
||||
|
||||
func (v *Dispatcher) Dispatch(ctx context.Context, destination v2net.Destination, payload *buf.Buffer, callback ResponseCallback) {
|
||||
func (v *Dispatcher) Dispatch(ctx context.Context, destination net.Destination, payload *buf.Buffer, callback ResponseCallback) {
|
||||
// TODO: Add user to destString
|
||||
log.Trace(newError("dispatch request to: ", destination).AtDebug())
|
||||
|
||||
|
|
|
@ -7,17 +7,17 @@ import (
|
|||
"time"
|
||||
|
||||
"v2ray.com/core/common/buf"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/testing/assert"
|
||||
. "v2ray.com/core/transport/internet/udp"
|
||||
"v2ray.com/core/transport/ray"
|
||||
)
|
||||
|
||||
type TestDispatcher struct {
|
||||
OnDispatch func(ctx context.Context, dest v2net.Destination) (ray.InboundRay, error)
|
||||
OnDispatch func(ctx context.Context, dest net.Destination) (ray.InboundRay, error)
|
||||
}
|
||||
|
||||
func (d *TestDispatcher) Dispatch(ctx context.Context, dest v2net.Destination) (ray.InboundRay, error) {
|
||||
func (d *TestDispatcher) Dispatch(ctx context.Context, dest net.Destination) (ray.InboundRay, error) {
|
||||
return d.OnDispatch(ctx, dest)
|
||||
}
|
||||
|
||||
|
@ -39,12 +39,12 @@ func TestSameDestinationDispatching(t *testing.T) {
|
|||
|
||||
var count uint32
|
||||
td := &TestDispatcher{
|
||||
OnDispatch: func(ctx context.Context, dest v2net.Destination) (ray.InboundRay, error) {
|
||||
OnDispatch: func(ctx context.Context, dest net.Destination) (ray.InboundRay, error) {
|
||||
atomic.AddUint32(&count, 1)
|
||||
return link, nil
|
||||
},
|
||||
}
|
||||
dest := v2net.UDPDestination(v2net.LocalHostIP, 53)
|
||||
dest := net.UDPDestination(net.LocalHostIP, 53)
|
||||
|
||||
b := buf.New()
|
||||
b.AppendBytes('a', 'b', 'c', 'd')
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
package udp
|
||||
|
||||
import (
|
||||
"net"
|
||||
"syscall"
|
||||
|
||||
v2net "v2ray.com/core/common/net"
|
||||
|
@ -38,6 +37,6 @@ func RetrieveOriginalDest(oob []byte) v2net.Destination {
|
|||
return v2net.Destination{}
|
||||
}
|
||||
|
||||
func ReadUDPMsg(conn *net.UDPConn, payload []byte, oob []byte) (int, int, int, *net.UDPAddr, error) {
|
||||
func ReadUDPMsg(conn *v2net.UDPConn, payload []byte, oob []byte) (int, int, int, *v2net.UDPAddr, error) {
|
||||
return conn.ReadMsgUDP(payload, oob)
|
||||
}
|
||||
|
|
|
@ -3,17 +3,15 @@
|
|||
package udp
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
)
|
||||
|
||||
func SetOriginalDestOptions(fd int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func RetrieveOriginalDest(oob []byte) v2net.Destination {
|
||||
return v2net.Destination{}
|
||||
func RetrieveOriginalDest(oob []byte) net.Destination {
|
||||
return net.Destination{}
|
||||
}
|
||||
|
||||
func ReadUDPMsg(conn *net.UDPConn, payload []byte, oob []byte) (int, int, int, *net.UDPAddr, error) {
|
||||
|
|
|
@ -2,18 +2,17 @@ package websocket
|
|||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"v2ray.com/core/app/log"
|
||||
"v2ray.com/core/common"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/transport/internet"
|
||||
"v2ray.com/core/transport/internet/tls"
|
||||
)
|
||||
|
||||
// Dial dials a WebSocket connection to the given destination.
|
||||
func Dial(ctx context.Context, dest v2net.Destination) (internet.Connection, error) {
|
||||
func Dial(ctx context.Context, dest net.Destination) (internet.Connection, error) {
|
||||
log.Trace(newError("creating connection to ", dest))
|
||||
|
||||
conn, err := dialWebsocket(ctx, dest)
|
||||
|
@ -27,7 +26,7 @@ func init() {
|
|||
common.Must(internet.RegisterTransportDialer(internet.TransportProtocol_WebSocket, Dial))
|
||||
}
|
||||
|
||||
func dialWebsocket(ctx context.Context, dest v2net.Destination) (net.Conn, error) {
|
||||
func dialWebsocket(ctx context.Context, dest net.Destination) (net.Conn, error) {
|
||||
src := internet.DialerSourceFromContext(ctx)
|
||||
wsSettings := internet.TransportSettingsFromContext(ctx).(*Config)
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ package websocket
|
|||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
@ -11,7 +10,7 @@ import (
|
|||
"github.com/gorilla/websocket"
|
||||
"v2ray.com/core/app/log"
|
||||
"v2ray.com/core/common"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/transport/internet"
|
||||
v2tls "v2ray.com/core/transport/internet/tls"
|
||||
)
|
||||
|
@ -44,7 +43,7 @@ type Listener struct {
|
|||
addConn internet.AddConnection
|
||||
}
|
||||
|
||||
func ListenWS(ctx context.Context, address v2net.Address, port v2net.Port, addConn internet.AddConnection) (internet.Listener, error) {
|
||||
func ListenWS(ctx context.Context, address net.Address, port net.Port, addConn internet.AddConnection) (internet.Listener, error) {
|
||||
networkSettings := internet.TransportSettingsFromContext(ctx)
|
||||
wsSettings := networkSettings.(*Config)
|
||||
|
||||
|
@ -65,7 +64,7 @@ func ListenWS(ctx context.Context, address v2net.Address, port v2net.Port, addCo
|
|||
return l, err
|
||||
}
|
||||
|
||||
func (ln *Listener) listenws(address v2net.Address, port v2net.Port) error {
|
||||
func (ln *Listener) listenws(address net.Address, port net.Port) error {
|
||||
netAddr := address.String() + ":" + strconv.Itoa(int(port.Value()))
|
||||
var listener net.Listener
|
||||
if ln.tlsConfig == nil {
|
||||
|
|
Loading…
Reference in New Issue