mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 01:57:12 -05:00
simplify import
This commit is contained in:
parent
88b607d31b
commit
b40a139310
@ -10,7 +10,7 @@ import (
|
|||||||
"v2ray.com/core/common/buf"
|
"v2ray.com/core/common/buf"
|
||||||
"v2ray.com/core/common/errors"
|
"v2ray.com/core/common/errors"
|
||||||
"v2ray.com/core/common/log"
|
"v2ray.com/core/common/log"
|
||||||
v2net "v2ray.com/core/common/net"
|
"v2ray.com/core/common/net"
|
||||||
"v2ray.com/core/common/signal"
|
"v2ray.com/core/common/signal"
|
||||||
"v2ray.com/core/proxy"
|
"v2ray.com/core/proxy"
|
||||||
"v2ray.com/core/transport/internet"
|
"v2ray.com/core/transport/internet"
|
||||||
@ -22,8 +22,8 @@ type DokodemoDoor struct {
|
|||||||
udpMutex sync.RWMutex
|
udpMutex sync.RWMutex
|
||||||
config *Config
|
config *Config
|
||||||
accepting bool
|
accepting bool
|
||||||
address v2net.Address
|
address net.Address
|
||||||
port v2net.Port
|
port net.Port
|
||||||
packetDispatcher dispatcher.Interface
|
packetDispatcher dispatcher.Interface
|
||||||
tcpListener *internet.TCPHub
|
tcpListener *internet.TCPHub
|
||||||
udpHub *udp.Hub
|
udpHub *udp.Hub
|
||||||
@ -43,7 +43,7 @@ func New(ctx context.Context, config *Config) (*DokodemoDoor, error) {
|
|||||||
d := &DokodemoDoor{
|
d := &DokodemoDoor{
|
||||||
config: config,
|
config: config,
|
||||||
address: config.GetPredefinedAddress(),
|
address: config.GetPredefinedAddress(),
|
||||||
port: v2net.Port(config.Port),
|
port: net.Port(config.Port),
|
||||||
meta: meta,
|
meta: meta,
|
||||||
}
|
}
|
||||||
space.OnInitialize(func() error {
|
space.OnInitialize(func() error {
|
||||||
@ -56,7 +56,7 @@ func New(ctx context.Context, config *Config) (*DokodemoDoor, error) {
|
|||||||
return d, nil
|
return d, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *DokodemoDoor) Port() v2net.Port {
|
func (v *DokodemoDoor) Port() net.Port {
|
||||||
return v.meta.Port
|
return v.meta.Port
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,13 +86,13 @@ func (v *DokodemoDoor) Start() error {
|
|||||||
return errors.New("DokodemoDoor: No network specified.")
|
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()
|
err := v.ListenTCP()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if v.config.NetworkList.HasNetwork(v2net.Network_UDP) {
|
if v.config.NetworkList.HasNetwork(net.Network_UDP) {
|
||||||
err := v.ListenUDP()
|
err := v.ListenUDP()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -120,10 +120,10 @@ func (v *DokodemoDoor) ListenUDP() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v *DokodemoDoor) handleUDPPackets(payload *buf.Buffer, session *proxy.SessionInfo) {
|
func (v *DokodemoDoor) handleUDPPackets(payload *buf.Buffer, session *proxy.SessionInfo) {
|
||||||
if session.Destination.Network == v2net.Network_Unknown && v.address != nil && v.port > 0 {
|
if session.Destination.Network == net.Network_Unknown && v.address != nil && v.port > 0 {
|
||||||
session.Destination = v2net.UDPDestination(v.address, v.port)
|
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...")
|
log.Info("Dokodemo: Unknown destination, stop forwarding...")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -131,7 +131,7 @@ func (v *DokodemoDoor) handleUDPPackets(payload *buf.Buffer, session *proxy.Sess
|
|||||||
v.udpServer.Dispatch(session, payload, v.handleUDPResponse)
|
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()
|
defer payload.Release()
|
||||||
v.udpMutex.RLock()
|
v.udpMutex.RLock()
|
||||||
defer v.udpMutex.RUnlock()
|
defer v.udpMutex.RUnlock()
|
||||||
@ -157,31 +157,31 @@ func (v *DokodemoDoor) HandleTCPConnection(conn internet.Connection) {
|
|||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
conn.SetReusable(false)
|
conn.SetReusable(false)
|
||||||
|
|
||||||
var dest v2net.Destination
|
var dest net.Destination
|
||||||
if v.config.FollowRedirect {
|
if v.config.FollowRedirect {
|
||||||
originalDest := GetOriginalDestination(conn)
|
originalDest := GetOriginalDestination(conn)
|
||||||
if originalDest.Network != v2net.Network_Unknown {
|
if originalDest.Network != net.Network_Unknown {
|
||||||
log.Info("Dokodemo: Following redirect to: ", originalDest)
|
log.Info("Dokodemo: Following redirect to: ", originalDest)
|
||||||
dest = originalDest
|
dest = originalDest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if dest.Network == v2net.Network_Unknown && v.address != nil && v.port > v2net.Port(0) {
|
if dest.Network == net.Network_Unknown && v.address != nil && v.port > net.Port(0) {
|
||||||
dest = v2net.TCPDestination(v.address, v.port)
|
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...")
|
log.Info("Dokodemo: Unknown destination, stop forwarding...")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Info("Dokodemo: Handling request to ", dest)
|
log.Info("Dokodemo: Handling request to ", dest)
|
||||||
|
|
||||||
ray := v.packetDispatcher.DispatchToOutbound(&proxy.SessionInfo{
|
ray := v.packetDispatcher.DispatchToOutbound(&proxy.SessionInfo{
|
||||||
Source: v2net.DestinationFromAddr(conn.RemoteAddr()),
|
Source: net.DestinationFromAddr(conn.RemoteAddr()),
|
||||||
Destination: dest,
|
Destination: dest,
|
||||||
Inbound: v.meta,
|
Inbound: v.meta,
|
||||||
})
|
})
|
||||||
|
|
||||||
reader := v2net.NewTimeOutReader(v.config.Timeout, conn)
|
reader := net.NewTimeOutReader(v.config.Timeout, conn)
|
||||||
|
|
||||||
requestDone := signal.ExecuteAsync(func() error {
|
requestDone := signal.ExecuteAsync(func() error {
|
||||||
defer ray.InboundInput().Close()
|
defer ray.InboundInput().Close()
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
"v2ray.com/core/common/dice"
|
"v2ray.com/core/common/dice"
|
||||||
"v2ray.com/core/common/errors"
|
"v2ray.com/core/common/errors"
|
||||||
"v2ray.com/core/common/log"
|
"v2ray.com/core/common/log"
|
||||||
v2net "v2ray.com/core/common/net"
|
"v2ray.com/core/common/net"
|
||||||
"v2ray.com/core/common/retry"
|
"v2ray.com/core/common/retry"
|
||||||
"v2ray.com/core/common/signal"
|
"v2ray.com/core/common/signal"
|
||||||
"v2ray.com/core/proxy"
|
"v2ray.com/core/proxy"
|
||||||
@ -53,7 +53,7 @@ func New(ctx context.Context, config *Config) (*Handler, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Private: Visible for testing.
|
// 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() {
|
if !destination.Address.Family().IsDomain() {
|
||||||
return destination
|
return destination
|
||||||
}
|
}
|
||||||
@ -65,17 +65,17 @@ func (v *Handler) ResolveIP(destination v2net.Destination) v2net.Destination {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ip := ips[dice.Roll(len(ips))]
|
ip := ips[dice.Roll(len(ips))]
|
||||||
var newDest v2net.Destination
|
var newDest net.Destination
|
||||||
if destination.Network == v2net.Network_TCP {
|
if destination.Network == net.Network_TCP {
|
||||||
newDest = v2net.TCPDestination(v2net.IPAddress(ip), destination.Port)
|
newDest = net.TCPDestination(net.IPAddress(ip), destination.Port)
|
||||||
} else {
|
} 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)
|
log.Info("Freedom: Changing destination from ", destination, " to ", newDest)
|
||||||
return 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)
|
log.Info("Freedom: Opening connection to ", destination)
|
||||||
|
|
||||||
input := ray.OutboundInput()
|
input := ray.OutboundInput()
|
||||||
@ -112,11 +112,11 @@ func (v *Handler) Dispatch(destination v2net.Destination, ray ray.OutboundRay) {
|
|||||||
var reader io.Reader = conn
|
var reader io.Reader = conn
|
||||||
|
|
||||||
timeout := v.timeout
|
timeout := v.timeout
|
||||||
if destination.Network == v2net.Network_UDP {
|
if destination.Network == net.Network_UDP {
|
||||||
timeout = 16
|
timeout = 16
|
||||||
}
|
}
|
||||||
if timeout > 0 {
|
if timeout > 0 {
|
||||||
reader = v2net.NewTimeOutReader(timeout /* seconds */, conn)
|
reader = net.NewTimeOutReader(timeout /* seconds */, conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
responseDone := signal.ExecuteAsync(func() error {
|
responseDone := signal.ExecuteAsync(func() error {
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
"v2ray.com/core/common/buf"
|
"v2ray.com/core/common/buf"
|
||||||
"v2ray.com/core/common/bufio"
|
"v2ray.com/core/common/bufio"
|
||||||
"v2ray.com/core/common/log"
|
"v2ray.com/core/common/log"
|
||||||
v2net "v2ray.com/core/common/net"
|
"v2ray.com/core/common/net"
|
||||||
"v2ray.com/core/common/protocol"
|
"v2ray.com/core/common/protocol"
|
||||||
"v2ray.com/core/common/retry"
|
"v2ray.com/core/common/retry"
|
||||||
"v2ray.com/core/common/signal"
|
"v2ray.com/core/common/signal"
|
||||||
@ -42,7 +42,7 @@ func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Dispatch implements OutboundHandler.Dispatch().
|
// 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
|
network := destination.Network
|
||||||
|
|
||||||
var server *protocol.ServerSpec
|
var server *protocol.ServerSpec
|
||||||
@ -73,7 +73,7 @@ func (v *Client) Dispatch(destination v2net.Destination, ray ray.OutboundRay) {
|
|||||||
Address: destination.Address,
|
Address: destination.Address,
|
||||||
Port: destination.Port,
|
Port: destination.Port,
|
||||||
}
|
}
|
||||||
if destination.Network == v2net.Network_TCP {
|
if destination.Network == net.Network_TCP {
|
||||||
request.Command = protocol.RequestCommandTCP
|
request.Command = protocol.RequestCommandTCP
|
||||||
} else {
|
} else {
|
||||||
request.Command = protocol.RequestCommandUDP
|
request.Command = protocol.RequestCommandUDP
|
||||||
@ -146,7 +146,7 @@ func (v *Client) Dispatch(destination v2net.Destination, ray ray.OutboundRay) {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
timedReader := v2net.NewTimeOutReader(16, conn)
|
timedReader := net.NewTimeOutReader(16, conn)
|
||||||
|
|
||||||
responseDone := signal.ExecuteAsync(func() error {
|
responseDone := signal.ExecuteAsync(func() error {
|
||||||
defer ray.OutboundOutput().Close()
|
defer ray.OutboundOutput().Close()
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
"v2ray.com/core/common/bufio"
|
"v2ray.com/core/common/bufio"
|
||||||
"v2ray.com/core/common/errors"
|
"v2ray.com/core/common/errors"
|
||||||
"v2ray.com/core/common/log"
|
"v2ray.com/core/common/log"
|
||||||
v2net "v2ray.com/core/common/net"
|
"v2ray.com/core/common/net"
|
||||||
"v2ray.com/core/common/protocol"
|
"v2ray.com/core/common/protocol"
|
||||||
"v2ray.com/core/common/signal"
|
"v2ray.com/core/common/signal"
|
||||||
"v2ray.com/core/proxy"
|
"v2ray.com/core/proxy"
|
||||||
@ -67,7 +67,7 @@ func NewServer(ctx context.Context, config *ServerConfig) (*Server, error) {
|
|||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Server) Port() v2net.Port {
|
func (v *Server) Port() net.Port {
|
||||||
return v.meta.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.Access(source, dest, log.AccessAccepted, "")
|
||||||
log.Info("Shadowsocks|Server: Tunnelling request to ", dest)
|
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()
|
defer payload.Release()
|
||||||
|
|
||||||
data, err := EncodeUDPPacket(request, payload)
|
data, err := EncodeUDPPacket(request, payload)
|
||||||
@ -156,7 +156,7 @@ func (v *Server) handleConnection(conn internet.Connection) {
|
|||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
conn.SetReusable(false)
|
conn.SetReusable(false)
|
||||||
|
|
||||||
timedReader := v2net.NewTimeOutReader(16, conn)
|
timedReader := net.NewTimeOutReader(16, conn)
|
||||||
bufferedReader := bufio.NewReader(timedReader)
|
bufferedReader := bufio.NewReader(timedReader)
|
||||||
request, bodyReader, err := ReadTCPSession(v.user, bufferedReader)
|
request, bodyReader, err := ReadTCPSession(v.user, bufferedReader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -175,7 +175,7 @@ func (v *Server) handleConnection(conn internet.Connection) {
|
|||||||
log.Info("Shadowsocks|Server: Tunnelling request to ", dest)
|
log.Info("Shadowsocks|Server: Tunnelling request to ", dest)
|
||||||
|
|
||||||
ray := v.packetDispatcher.DispatchToOutbound(&proxy.SessionInfo{
|
ray := v.packetDispatcher.DispatchToOutbound(&proxy.SessionInfo{
|
||||||
Source: v2net.DestinationFromAddr(conn.RemoteAddr()),
|
Source: net.DestinationFromAddr(conn.RemoteAddr()),
|
||||||
Destination: dest,
|
Destination: dest,
|
||||||
User: request.User,
|
User: request.User,
|
||||||
Inbound: v.meta,
|
Inbound: v.meta,
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
"v2ray.com/core/common/bufio"
|
"v2ray.com/core/common/bufio"
|
||||||
"v2ray.com/core/common/errors"
|
"v2ray.com/core/common/errors"
|
||||||
"v2ray.com/core/common/log"
|
"v2ray.com/core/common/log"
|
||||||
v2net "v2ray.com/core/common/net"
|
"v2ray.com/core/common/net"
|
||||||
"v2ray.com/core/common/protocol"
|
"v2ray.com/core/common/protocol"
|
||||||
"v2ray.com/core/common/signal"
|
"v2ray.com/core/common/signal"
|
||||||
"v2ray.com/core/proxy"
|
"v2ray.com/core/proxy"
|
||||||
@ -30,7 +30,7 @@ type Server struct {
|
|||||||
config *ServerConfig
|
config *ServerConfig
|
||||||
tcpListener *internet.TCPHub
|
tcpListener *internet.TCPHub
|
||||||
udpHub *udp.Hub
|
udpHub *udp.Hub
|
||||||
udpAddress v2net.Destination
|
udpAddress net.Destination
|
||||||
udpServer *udp.Server
|
udpServer *udp.Server
|
||||||
meta *proxy.InboundHandlerMeta
|
meta *proxy.InboundHandlerMeta
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ func NewServer(ctx context.Context, config *ServerConfig) (*Server, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Port implements InboundHandler.Port().
|
// Port implements InboundHandler.Port().
|
||||||
func (v *Server) Port() v2net.Port {
|
func (v *Server) Port() net.Port {
|
||||||
return v.meta.Port
|
return v.meta.Port
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ func (v *Server) handleConnection(connection internet.Connection) {
|
|||||||
|
|
||||||
connection.SetReusable(false)
|
connection.SetReusable(false)
|
||||||
|
|
||||||
timedReader := v2net.NewTimeOutReader(16 /* seconds, for handshake */, connection)
|
timedReader := net.NewTimeOutReader(16 /* seconds, for handshake */, connection)
|
||||||
reader := bufio.NewReader(timedReader)
|
reader := bufio.NewReader(timedReader)
|
||||||
|
|
||||||
session := &ServerSession{
|
session := &ServerSession{
|
||||||
@ -121,7 +121,7 @@ func (v *Server) handleConnection(connection internet.Connection) {
|
|||||||
meta: v.meta,
|
meta: v.meta,
|
||||||
}
|
}
|
||||||
|
|
||||||
clientAddr := v2net.DestinationFromAddr(connection.RemoteAddr())
|
clientAddr := net.DestinationFromAddr(connection.RemoteAddr())
|
||||||
|
|
||||||
request, err := session.Handshake(reader, connection)
|
request, err := session.Handshake(reader, connection)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
package encoding
|
package encoding
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"hash/fnv"
|
|
||||||
|
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
|
"hash/fnv"
|
||||||
|
|
||||||
"v2ray.com/core/common/crypto"
|
"v2ray.com/core/common/crypto"
|
||||||
"v2ray.com/core/common/serial"
|
"v2ray.com/core/common/serial"
|
||||||
|
@ -15,7 +15,7 @@ import (
|
|||||||
"v2ray.com/core/common/dice"
|
"v2ray.com/core/common/dice"
|
||||||
"v2ray.com/core/common/errors"
|
"v2ray.com/core/common/errors"
|
||||||
"v2ray.com/core/common/log"
|
"v2ray.com/core/common/log"
|
||||||
v2net "v2ray.com/core/common/net"
|
"v2ray.com/core/common/net"
|
||||||
"v2ray.com/core/common/protocol"
|
"v2ray.com/core/common/protocol"
|
||||||
"v2ray.com/core/common/serial"
|
"v2ray.com/core/common/serial"
|
||||||
"v2ray.com/core/proxy/vmess"
|
"v2ray.com/core/proxy/vmess"
|
||||||
@ -85,13 +85,13 @@ func (v *ClientSession) EncodeRequestHeader(header *protocol.RequestHeader, writ
|
|||||||
buffer = header.Port.Bytes(buffer)
|
buffer = header.Port.Bytes(buffer)
|
||||||
|
|
||||||
switch header.Address.Family() {
|
switch header.Address.Family() {
|
||||||
case v2net.AddressFamilyIPv4:
|
case net.AddressFamilyIPv4:
|
||||||
buffer = append(buffer, AddrTypeIPv4)
|
buffer = append(buffer, AddrTypeIPv4)
|
||||||
buffer = append(buffer, header.Address.IP()...)
|
buffer = append(buffer, header.Address.IP()...)
|
||||||
case v2net.AddressFamilyIPv6:
|
case net.AddressFamilyIPv6:
|
||||||
buffer = append(buffer, AddrTypeIPv6)
|
buffer = append(buffer, AddrTypeIPv6)
|
||||||
buffer = append(buffer, header.Address.IP()...)
|
buffer = append(buffer, header.Address.IP()...)
|
||||||
case v2net.AddressFamilyDomain:
|
case net.AddressFamilyDomain:
|
||||||
buffer = append(buffer, AddrTypeDomain, byte(len(header.Address.Domain())))
|
buffer = append(buffer, AddrTypeDomain, byte(len(header.Address.Domain())))
|
||||||
buffer = append(buffer, header.Address.Domain()...)
|
buffer = append(buffer, header.Address.Domain()...)
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
|
|
||||||
"v2ray.com/core/common/buf"
|
"v2ray.com/core/common/buf"
|
||||||
"v2ray.com/core/common/errors"
|
"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/protocol"
|
||||||
"v2ray.com/core/common/serial"
|
"v2ray.com/core/common/serial"
|
||||||
"v2ray.com/core/common/uuid"
|
"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.")
|
return nil, errors.New("VMess|SwitchAccountCommand: Insufficient length.")
|
||||||
}
|
}
|
||||||
if lenHost > 0 {
|
if lenHost > 0 {
|
||||||
cmd.Host = v2net.ParseAddress(string(data[1 : 1+lenHost]))
|
cmd.Host = net.ParseAddress(string(data[1 : 1+lenHost]))
|
||||||
}
|
}
|
||||||
portStart := 1 + lenHost
|
portStart := 1 + lenHost
|
||||||
if len(data) < portStart+2 {
|
if len(data) < portStart+2 {
|
||||||
return nil, errors.New("VMess|SwitchAccountCommand: Insufficient length.")
|
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
|
idStart := portStart + 2
|
||||||
if len(data) < idStart+16 {
|
if len(data) < idStart+16 {
|
||||||
return nil, errors.New("VMess|SwitchAccountCommand: Insufficient length.")
|
return nil, errors.New("VMess|SwitchAccountCommand: Insufficient length.")
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
"v2ray.com/core/common/crypto"
|
"v2ray.com/core/common/crypto"
|
||||||
"v2ray.com/core/common/errors"
|
"v2ray.com/core/common/errors"
|
||||||
"v2ray.com/core/common/log"
|
"v2ray.com/core/common/log"
|
||||||
v2net "v2ray.com/core/common/net"
|
"v2ray.com/core/common/net"
|
||||||
"v2ray.com/core/common/protocol"
|
"v2ray.com/core/common/protocol"
|
||||||
"v2ray.com/core/common/serial"
|
"v2ray.com/core/common/serial"
|
||||||
"v2ray.com/core/proxy/vmess"
|
"v2ray.com/core/proxy/vmess"
|
||||||
@ -86,7 +86,7 @@ func (v *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
|
|||||||
// 1 bytes reserved
|
// 1 bytes reserved
|
||||||
request.Command = protocol.RequestCommand(buffer[37])
|
request.Command = protocol.RequestCommand(buffer[37])
|
||||||
|
|
||||||
request.Port = v2net.PortFromBytes(buffer[38:40])
|
request.Port = net.PortFromBytes(buffer[38:40])
|
||||||
|
|
||||||
switch buffer[40] {
|
switch buffer[40] {
|
||||||
case AddrTypeIPv4:
|
case AddrTypeIPv4:
|
||||||
@ -95,14 +95,14 @@ func (v *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Base(err).Message("VMess|Server: Failed to read IPv4.")
|
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:
|
case AddrTypeIPv6:
|
||||||
_, err = io.ReadFull(decryptor, buffer[41:57]) // 16 bytes
|
_, err = io.ReadFull(decryptor, buffer[41:57]) // 16 bytes
|
||||||
bufferLen += 16
|
bufferLen += 16
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Base(err).Message("VMess|Server: Failed to read IPv6 address.")
|
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:
|
case AddrTypeDomain:
|
||||||
_, err = io.ReadFull(decryptor, buffer[41:42])
|
_, err = io.ReadFull(decryptor, buffer[41:42])
|
||||||
if err != nil {
|
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.")
|
return nil, errors.Base(err).Message("VMess|Server: Failed to read domain.")
|
||||||
}
|
}
|
||||||
bufferLen += 1 + domainLength
|
bufferLen += 1 + domainLength
|
||||||
request.Address = v2net.DomainAddress(string(buffer[42 : 42+domainLength]))
|
request.Address = net.DomainAddress(string(buffer[42 : 42+domainLength]))
|
||||||
}
|
}
|
||||||
|
|
||||||
if padingLen > 0 {
|
if padingLen > 0 {
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
package inbound
|
package inbound
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"io"
|
"io"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"v2ray.com/core/app"
|
"v2ray.com/core/app"
|
||||||
"v2ray.com/core/app/dispatcher"
|
"v2ray.com/core/app/dispatcher"
|
||||||
"v2ray.com/core/app/proxyman"
|
"v2ray.com/core/app/proxyman"
|
||||||
@ -14,7 +13,7 @@ import (
|
|||||||
"v2ray.com/core/common/bufio"
|
"v2ray.com/core/common/bufio"
|
||||||
"v2ray.com/core/common/errors"
|
"v2ray.com/core/common/errors"
|
||||||
"v2ray.com/core/common/log"
|
"v2ray.com/core/common/log"
|
||||||
v2net "v2ray.com/core/common/net"
|
"v2ray.com/core/common/net"
|
||||||
"v2ray.com/core/common/protocol"
|
"v2ray.com/core/common/protocol"
|
||||||
"v2ray.com/core/common/serial"
|
"v2ray.com/core/common/serial"
|
||||||
"v2ray.com/core/common/signal"
|
"v2ray.com/core/common/signal"
|
||||||
@ -121,7 +120,7 @@ func New(ctx context.Context, config *Config) (*VMessInboundHandler, error) {
|
|||||||
return handler, nil
|
return handler, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *VMessInboundHandler) Port() v2net.Port {
|
func (v *VMessInboundHandler) Port() net.Port {
|
||||||
return v.meta.Port
|
return v.meta.Port
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,7 +220,7 @@ func (v *VMessInboundHandler) HandleConnection(connection internet.Connection) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
connReader := v2net.NewTimeOutReader(8, connection)
|
connReader := net.NewTimeOutReader(8, connection)
|
||||||
reader := bufio.NewReader(connReader)
|
reader := bufio.NewReader(connReader)
|
||||||
v.RLock()
|
v.RLock()
|
||||||
if !v.accepting {
|
if !v.accepting {
|
||||||
@ -246,7 +245,7 @@ func (v *VMessInboundHandler) HandleConnection(connection internet.Connection) {
|
|||||||
connection.SetReusable(request.Option.Has(protocol.RequestOptionConnectionReuse))
|
connection.SetReusable(request.Option.Has(protocol.RequestOptionConnectionReuse))
|
||||||
|
|
||||||
ray := v.packetDispatcher.DispatchToOutbound(&proxy.SessionInfo{
|
ray := v.packetDispatcher.DispatchToOutbound(&proxy.SessionInfo{
|
||||||
Source: v2net.DestinationFromAddr(connection.RemoteAddr()),
|
Source: net.DestinationFromAddr(connection.RemoteAddr()),
|
||||||
Destination: request.Destination(),
|
Destination: request.Destination(),
|
||||||
User: request.User,
|
User: request.User,
|
||||||
Inbound: v.meta,
|
Inbound: v.meta,
|
||||||
|
@ -3,7 +3,7 @@ package outbound
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
v2net "v2ray.com/core/common/net"
|
"v2ray.com/core/common/net"
|
||||||
"v2ray.com/core/common/protocol"
|
"v2ray.com/core/common/protocol"
|
||||||
"v2ray.com/core/common/serial"
|
"v2ray.com/core/common/serial"
|
||||||
"v2ray.com/core/proxy/vmess"
|
"v2ray.com/core/proxy/vmess"
|
||||||
@ -20,12 +20,12 @@ func (v *VMessOutboundHandler) handleSwitchAccount(cmd *protocol.CommandSwitchAc
|
|||||||
Level: cmd.Level,
|
Level: cmd.Level,
|
||||||
Account: serial.ToTypedMessage(account),
|
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)
|
until := time.Now().Add(time.Duration(cmd.ValidMin) * time.Minute)
|
||||||
v.serverList.AddServer(protocol.NewServerSpec(dest, protocol.BeforeTime(until), user))
|
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) {
|
switch typedCommand := cmd.(type) {
|
||||||
case *protocol.CommandSwitchAccount:
|
case *protocol.CommandSwitchAccount:
|
||||||
if typedCommand.Host == nil {
|
if typedCommand.Host == nil {
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
package outbound
|
package outbound
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
|
|
||||||
"context"
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
"v2ray.com/core/app"
|
"v2ray.com/core/app"
|
||||||
"v2ray.com/core/common"
|
"v2ray.com/core/common"
|
||||||
@ -11,7 +10,7 @@ import (
|
|||||||
"v2ray.com/core/common/bufio"
|
"v2ray.com/core/common/bufio"
|
||||||
"v2ray.com/core/common/errors"
|
"v2ray.com/core/common/errors"
|
||||||
"v2ray.com/core/common/log"
|
"v2ray.com/core/common/log"
|
||||||
v2net "v2ray.com/core/common/net"
|
"v2ray.com/core/common/net"
|
||||||
"v2ray.com/core/common/protocol"
|
"v2ray.com/core/common/protocol"
|
||||||
"v2ray.com/core/common/retry"
|
"v2ray.com/core/common/retry"
|
||||||
"v2ray.com/core/common/signal"
|
"v2ray.com/core/common/signal"
|
||||||
@ -53,7 +52,7 @@ func New(ctx context.Context, config *Config) (*VMessOutboundHandler, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Dispatch implements OutboundHandler.Dispatch().
|
// 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 rec *protocol.ServerSpec
|
||||||
var conn internet.Connection
|
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())
|
log.Info("VMess|Outbound: Tunneling request to ", target, " via ", rec.Destination())
|
||||||
|
|
||||||
command := protocol.RequestCommandTCP
|
command := protocol.RequestCommandTCP
|
||||||
if target.Network == v2net.Network_UDP {
|
if target.Network == net.Network_UDP {
|
||||||
command = protocol.RequestCommandUDP
|
command = protocol.RequestCommandUDP
|
||||||
}
|
}
|
||||||
request := &protocol.RequestHeader{
|
request := &protocol.RequestHeader{
|
||||||
|
Loading…
Reference in New Issue
Block a user