simplify import

pull/362/head
Darien Raymond 8 years ago
parent 88b607d31b
commit b40a139310
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

@ -10,7 +10,7 @@ import (
"v2ray.com/core/common/buf"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/common/net"
"v2ray.com/core/common/signal"
"v2ray.com/core/proxy"
"v2ray.com/core/transport/internet"
@ -22,8 +22,8 @@ type DokodemoDoor struct {
udpMutex sync.RWMutex
config *Config
accepting bool
address v2net.Address
port v2net.Port
address net.Address
port net.Port
packetDispatcher dispatcher.Interface
tcpListener *internet.TCPHub
udpHub *udp.Hub
@ -43,7 +43,7 @@ func New(ctx context.Context, config *Config) (*DokodemoDoor, error) {
d := &DokodemoDoor{
config: config,
address: config.GetPredefinedAddress(),
port: v2net.Port(config.Port),
port: net.Port(config.Port),
meta: meta,
}
space.OnInitialize(func() error {
@ -56,7 +56,7 @@ func New(ctx context.Context, config *Config) (*DokodemoDoor, error) {
return d, nil
}
func (v *DokodemoDoor) Port() v2net.Port {
func (v *DokodemoDoor) Port() net.Port {
return v.meta.Port
}
@ -86,13 +86,13 @@ func (v *DokodemoDoor) Start() error {
return errors.New("DokodemoDoor: No network specified.")
}
if v.config.NetworkList.HasNetwork(v2net.Network_TCP) {
if v.config.NetworkList.HasNetwork(net.Network_TCP) {
err := v.ListenTCP()
if err != nil {
return err
}
}
if v.config.NetworkList.HasNetwork(v2net.Network_UDP) {
if v.config.NetworkList.HasNetwork(net.Network_UDP) {
err := v.ListenUDP()
if err != nil {
return err
@ -120,10 +120,10 @@ func (v *DokodemoDoor) ListenUDP() error {
}
func (v *DokodemoDoor) handleUDPPackets(payload *buf.Buffer, session *proxy.SessionInfo) {
if session.Destination.Network == v2net.Network_Unknown && v.address != nil && v.port > 0 {
session.Destination = v2net.UDPDestination(v.address, v.port)
if session.Destination.Network == net.Network_Unknown && v.address != nil && v.port > 0 {
session.Destination = net.UDPDestination(v.address, v.port)
}
if session.Destination.Network == v2net.Network_Unknown {
if session.Destination.Network == net.Network_Unknown {
log.Info("Dokodemo: Unknown destination, stop forwarding...")
return
}
@ -131,7 +131,7 @@ func (v *DokodemoDoor) handleUDPPackets(payload *buf.Buffer, session *proxy.Sess
v.udpServer.Dispatch(session, payload, v.handleUDPResponse)
}
func (v *DokodemoDoor) handleUDPResponse(dest v2net.Destination, payload *buf.Buffer) {
func (v *DokodemoDoor) handleUDPResponse(dest net.Destination, payload *buf.Buffer) {
defer payload.Release()
v.udpMutex.RLock()
defer v.udpMutex.RUnlock()
@ -157,31 +157,31 @@ func (v *DokodemoDoor) HandleTCPConnection(conn internet.Connection) {
defer conn.Close()
conn.SetReusable(false)
var dest v2net.Destination
var dest net.Destination
if v.config.FollowRedirect {
originalDest := GetOriginalDestination(conn)
if originalDest.Network != v2net.Network_Unknown {
if originalDest.Network != net.Network_Unknown {
log.Info("Dokodemo: Following redirect to: ", originalDest)
dest = originalDest
}
}
if dest.Network == v2net.Network_Unknown && v.address != nil && v.port > v2net.Port(0) {
dest = v2net.TCPDestination(v.address, v.port)
if dest.Network == net.Network_Unknown && v.address != nil && v.port > net.Port(0) {
dest = net.TCPDestination(v.address, v.port)
}
if dest.Network == v2net.Network_Unknown {
if dest.Network == net.Network_Unknown {
log.Info("Dokodemo: Unknown destination, stop forwarding...")
return
}
log.Info("Dokodemo: Handling request to ", dest)
ray := v.packetDispatcher.DispatchToOutbound(&proxy.SessionInfo{
Source: v2net.DestinationFromAddr(conn.RemoteAddr()),
Source: net.DestinationFromAddr(conn.RemoteAddr()),
Destination: dest,
Inbound: v.meta,
})
reader := v2net.NewTimeOutReader(v.config.Timeout, conn)
reader := net.NewTimeOutReader(v.config.Timeout, conn)
requestDone := signal.ExecuteAsync(func() error {
defer ray.InboundInput().Close()

@ -11,7 +11,7 @@ import (
"v2ray.com/core/common/dice"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/common/net"
"v2ray.com/core/common/retry"
"v2ray.com/core/common/signal"
"v2ray.com/core/proxy"
@ -53,7 +53,7 @@ func New(ctx context.Context, config *Config) (*Handler, error) {
}
// Private: Visible for testing.
func (v *Handler) ResolveIP(destination v2net.Destination) v2net.Destination {
func (v *Handler) ResolveIP(destination net.Destination) net.Destination {
if !destination.Address.Family().IsDomain() {
return destination
}
@ -65,17 +65,17 @@ func (v *Handler) ResolveIP(destination v2net.Destination) v2net.Destination {
}
ip := ips[dice.Roll(len(ips))]
var newDest v2net.Destination
if destination.Network == v2net.Network_TCP {
newDest = v2net.TCPDestination(v2net.IPAddress(ip), destination.Port)
var newDest net.Destination
if destination.Network == net.Network_TCP {
newDest = net.TCPDestination(net.IPAddress(ip), destination.Port)
} else {
newDest = v2net.UDPDestination(v2net.IPAddress(ip), destination.Port)
newDest = net.UDPDestination(net.IPAddress(ip), destination.Port)
}
log.Info("Freedom: Changing destination from ", destination, " to ", newDest)
return newDest
}
func (v *Handler) Dispatch(destination v2net.Destination, ray ray.OutboundRay) {
func (v *Handler) Dispatch(destination net.Destination, ray ray.OutboundRay) {
log.Info("Freedom: Opening connection to ", destination)
input := ray.OutboundInput()
@ -112,11 +112,11 @@ func (v *Handler) Dispatch(destination v2net.Destination, ray ray.OutboundRay) {
var reader io.Reader = conn
timeout := v.timeout
if destination.Network == v2net.Network_UDP {
if destination.Network == net.Network_UDP {
timeout = 16
}
if timeout > 0 {
reader = v2net.NewTimeOutReader(timeout /* seconds */, conn)
reader = net.NewTimeOutReader(timeout /* seconds */, conn)
}
responseDone := signal.ExecuteAsync(func() error {

@ -8,7 +8,7 @@ import (
"v2ray.com/core/common/buf"
"v2ray.com/core/common/bufio"
"v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/common/net"
"v2ray.com/core/common/protocol"
"v2ray.com/core/common/retry"
"v2ray.com/core/common/signal"
@ -42,7 +42,7 @@ func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
}
// Dispatch implements OutboundHandler.Dispatch().
func (v *Client) Dispatch(destination v2net.Destination, ray ray.OutboundRay) {
func (v *Client) Dispatch(destination net.Destination, ray ray.OutboundRay) {
network := destination.Network
var server *protocol.ServerSpec
@ -73,7 +73,7 @@ func (v *Client) Dispatch(destination v2net.Destination, ray ray.OutboundRay) {
Address: destination.Address,
Port: destination.Port,
}
if destination.Network == v2net.Network_TCP {
if destination.Network == net.Network_TCP {
request.Command = protocol.RequestCommandTCP
} else {
request.Command = protocol.RequestCommandUDP
@ -146,7 +146,7 @@ func (v *Client) Dispatch(destination v2net.Destination, ray ray.OutboundRay) {
return nil
})
timedReader := v2net.NewTimeOutReader(16, conn)
timedReader := net.NewTimeOutReader(16, conn)
responseDone := signal.ExecuteAsync(func() error {
defer ray.OutboundOutput().Close()

@ -10,7 +10,7 @@ import (
"v2ray.com/core/common/bufio"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/common/net"
"v2ray.com/core/common/protocol"
"v2ray.com/core/common/signal"
"v2ray.com/core/proxy"
@ -67,7 +67,7 @@ func NewServer(ctx context.Context, config *ServerConfig) (*Server, error) {
return s, nil
}
func (v *Server) Port() v2net.Port {
func (v *Server) Port() net.Port {
return v.meta.Port
}
@ -138,7 +138,7 @@ func (v *Server) handlerUDPPayload(payload *buf.Buffer, session *proxy.SessionIn
log.Access(source, dest, log.AccessAccepted, "")
log.Info("Shadowsocks|Server: Tunnelling request to ", dest)
v.udpServer.Dispatch(&proxy.SessionInfo{Source: source, Destination: dest, User: request.User, Inbound: v.meta}, data, func(destination v2net.Destination, payload *buf.Buffer) {
v.udpServer.Dispatch(&proxy.SessionInfo{Source: source, Destination: dest, User: request.User, Inbound: v.meta}, data, func(destination net.Destination, payload *buf.Buffer) {
defer payload.Release()
data, err := EncodeUDPPacket(request, payload)
@ -156,7 +156,7 @@ func (v *Server) handleConnection(conn internet.Connection) {
defer conn.Close()
conn.SetReusable(false)
timedReader := v2net.NewTimeOutReader(16, conn)
timedReader := net.NewTimeOutReader(16, conn)
bufferedReader := bufio.NewReader(timedReader)
request, bodyReader, err := ReadTCPSession(v.user, bufferedReader)
if err != nil {
@ -175,7 +175,7 @@ func (v *Server) handleConnection(conn internet.Connection) {
log.Info("Shadowsocks|Server: Tunnelling request to ", dest)
ray := v.packetDispatcher.DispatchToOutbound(&proxy.SessionInfo{
Source: v2net.DestinationFromAddr(conn.RemoteAddr()),
Source: net.DestinationFromAddr(conn.RemoteAddr()),
Destination: dest,
User: request.User,
Inbound: v.meta,

@ -13,7 +13,7 @@ import (
"v2ray.com/core/common/bufio"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/common/net"
"v2ray.com/core/common/protocol"
"v2ray.com/core/common/signal"
"v2ray.com/core/proxy"
@ -30,7 +30,7 @@ type Server struct {
config *ServerConfig
tcpListener *internet.TCPHub
udpHub *udp.Hub
udpAddress v2net.Destination
udpAddress net.Destination
udpServer *udp.Server
meta *proxy.InboundHandlerMeta
}
@ -60,7 +60,7 @@ func NewServer(ctx context.Context, config *ServerConfig) (*Server, error) {
}
// Port implements InboundHandler.Port().
func (v *Server) Port() v2net.Port {
func (v *Server) Port() net.Port {
return v.meta.Port
}
@ -113,7 +113,7 @@ func (v *Server) handleConnection(connection internet.Connection) {
connection.SetReusable(false)
timedReader := v2net.NewTimeOutReader(16 /* seconds, for handshake */, connection)
timedReader := net.NewTimeOutReader(16 /* seconds, for handshake */, connection)
reader := bufio.NewReader(timedReader)
session := &ServerSession{
@ -121,7 +121,7 @@ func (v *Server) handleConnection(connection internet.Connection) {
meta: v.meta,
}
clientAddr := v2net.DestinationFromAddr(connection.RemoteAddr())
clientAddr := net.DestinationFromAddr(connection.RemoteAddr())
request, err := session.Handshake(reader, connection)
if err != nil {

@ -1,9 +1,8 @@
package encoding
import (
"hash/fnv"
"crypto/md5"
"hash/fnv"
"v2ray.com/core/common/crypto"
"v2ray.com/core/common/serial"

@ -15,7 +15,7 @@ import (
"v2ray.com/core/common/dice"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log"
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/vmess"
@ -85,13 +85,13 @@ func (v *ClientSession) EncodeRequestHeader(header *protocol.RequestHeader, writ
buffer = header.Port.Bytes(buffer)
switch header.Address.Family() {
case v2net.AddressFamilyIPv4:
case net.AddressFamilyIPv4:
buffer = append(buffer, AddrTypeIPv4)
buffer = append(buffer, header.Address.IP()...)
case v2net.AddressFamilyIPv6:
case net.AddressFamilyIPv6:
buffer = append(buffer, AddrTypeIPv6)
buffer = append(buffer, header.Address.IP()...)
case v2net.AddressFamilyDomain:
case net.AddressFamilyDomain:
buffer = append(buffer, AddrTypeDomain, byte(len(header.Address.Domain())))
buffer = append(buffer, header.Address.Domain()...)
}

@ -5,7 +5,7 @@ import (
"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/protocol"
"v2ray.com/core/common/serial"
"v2ray.com/core/common/uuid"
@ -117,13 +117,13 @@ func (v *CommandSwitchAccountFactory) Unmarshal(data []byte) (interface{}, error
return nil, errors.New("VMess|SwitchAccountCommand: Insufficient length.")
}
if lenHost > 0 {
cmd.Host = v2net.ParseAddress(string(data[1 : 1+lenHost]))
cmd.Host = net.ParseAddress(string(data[1 : 1+lenHost]))
}
portStart := 1 + lenHost
if len(data) < portStart+2 {
return nil, errors.New("VMess|SwitchAccountCommand: Insufficient length.")
}
cmd.Port = v2net.PortFromBytes(data[portStart : portStart+2])
cmd.Port = net.PortFromBytes(data[portStart : portStart+2])
idStart := portStart + 2
if len(data) < idStart+16 {
return nil, errors.New("VMess|SwitchAccountCommand: Insufficient length.")

@ -13,7 +13,7 @@ import (
"v2ray.com/core/common/crypto"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log"
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/vmess"
@ -86,7 +86,7 @@ func (v *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
// 1 bytes reserved
request.Command = protocol.RequestCommand(buffer[37])
request.Port = v2net.PortFromBytes(buffer[38:40])
request.Port = net.PortFromBytes(buffer[38:40])
switch buffer[40] {
case AddrTypeIPv4:
@ -95,14 +95,14 @@ func (v *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
if err != nil {
return nil, errors.Base(err).Message("VMess|Server: Failed to read IPv4.")
}
request.Address = v2net.IPAddress(buffer[41:45])
request.Address = net.IPAddress(buffer[41:45])
case AddrTypeIPv6:
_, err = io.ReadFull(decryptor, buffer[41:57]) // 16 bytes
bufferLen += 16
if err != nil {
return nil, errors.Base(err).Message("VMess|Server: Failed to read IPv6 address.")
}
request.Address = v2net.IPAddress(buffer[41:57])
request.Address = net.IPAddress(buffer[41:57])
case AddrTypeDomain:
_, err = io.ReadFull(decryptor, buffer[41:42])
if err != nil {
@ -117,7 +117,7 @@ func (v *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
return nil, errors.Base(err).Message("VMess|Server: Failed to read domain.")
}
bufferLen += 1 + domainLength
request.Address = v2net.DomainAddress(string(buffer[42 : 42+domainLength]))
request.Address = net.DomainAddress(string(buffer[42 : 42+domainLength]))
}
if padingLen > 0 {

@ -1,11 +1,10 @@
package inbound
import (
"context"
"io"
"sync"
"context"
"v2ray.com/core/app"
"v2ray.com/core/app/dispatcher"
"v2ray.com/core/app/proxyman"
@ -14,7 +13,7 @@ import (
"v2ray.com/core/common/bufio"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log"
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/signal"
@ -121,7 +120,7 @@ func New(ctx context.Context, config *Config) (*VMessInboundHandler, error) {
return handler, nil
}
func (v *VMessInboundHandler) Port() v2net.Port {
func (v *VMessInboundHandler) Port() net.Port {
return v.meta.Port
}
@ -221,7 +220,7 @@ func (v *VMessInboundHandler) HandleConnection(connection internet.Connection) {
return
}
connReader := v2net.NewTimeOutReader(8, connection)
connReader := net.NewTimeOutReader(8, connection)
reader := bufio.NewReader(connReader)
v.RLock()
if !v.accepting {
@ -246,7 +245,7 @@ func (v *VMessInboundHandler) HandleConnection(connection internet.Connection) {
connection.SetReusable(request.Option.Has(protocol.RequestOptionConnectionReuse))
ray := v.packetDispatcher.DispatchToOutbound(&proxy.SessionInfo{
Source: v2net.DestinationFromAddr(connection.RemoteAddr()),
Source: net.DestinationFromAddr(connection.RemoteAddr()),
Destination: request.Destination(),
User: request.User,
Inbound: v.meta,

@ -3,7 +3,7 @@ package outbound
import (
"time"
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/vmess"
@ -20,12 +20,12 @@ func (v *VMessOutboundHandler) handleSwitchAccount(cmd *protocol.CommandSwitchAc
Level: cmd.Level,
Account: serial.ToTypedMessage(account),
}
dest := v2net.TCPDestination(cmd.Host, cmd.Port)
dest := net.TCPDestination(cmd.Host, cmd.Port)
until := time.Now().Add(time.Duration(cmd.ValidMin) * time.Minute)
v.serverList.AddServer(protocol.NewServerSpec(dest, protocol.BeforeTime(until), user))
}
func (v *VMessOutboundHandler) handleCommand(dest v2net.Destination, cmd protocol.ResponseCommand) {
func (v *VMessOutboundHandler) handleCommand(dest net.Destination, cmd protocol.ResponseCommand) {
switch typedCommand := cmd.(type) {
case *protocol.CommandSwitchAccount:
if typedCommand.Host == nil {

@ -1,9 +1,8 @@
package outbound
import (
"time"
"context"
"time"
"v2ray.com/core/app"
"v2ray.com/core/common"
@ -11,7 +10,7 @@ import (
"v2ray.com/core/common/bufio"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/common/net"
"v2ray.com/core/common/protocol"
"v2ray.com/core/common/retry"
"v2ray.com/core/common/signal"
@ -53,7 +52,7 @@ func New(ctx context.Context, config *Config) (*VMessOutboundHandler, error) {
}
// Dispatch implements OutboundHandler.Dispatch().
func (v *VMessOutboundHandler) Dispatch(target v2net.Destination, outboundRay ray.OutboundRay) {
func (v *VMessOutboundHandler) Dispatch(target net.Destination, outboundRay ray.OutboundRay) {
var rec *protocol.ServerSpec
var conn internet.Connection
@ -74,7 +73,7 @@ func (v *VMessOutboundHandler) Dispatch(target v2net.Destination, outboundRay ra
log.Info("VMess|Outbound: Tunneling request to ", target, " via ", rec.Destination())
command := protocol.RequestCommandTCP
if target.Network == v2net.Network_UDP {
if target.Network == net.Network_UDP {
command = protocol.RequestCommandUDP
}
request := &protocol.RequestHeader{

Loading…
Cancel
Save