mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 17:46:58 -05:00
Cleanup root directory
This commit is contained in:
parent
1b80a1a85a
commit
890d185979
10
app/packet_dispatcher.go
Normal file
10
app/packet_dispatcher.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
|
"github.com/v2ray/v2ray-core/transport/ray"
|
||||||
|
)
|
||||||
|
|
||||||
|
type PacketDispatcher interface {
|
||||||
|
DispatchToOutbound(packet v2net.Packet) ray.InboundRay
|
||||||
|
}
|
@ -1,34 +1,19 @@
|
|||||||
package core
|
package point
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/v2ray/v2ray-core/common/log"
|
"github.com/v2ray/v2ray-core/common/log"
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
"github.com/v2ray/v2ray-core/common/retry"
|
"github.com/v2ray/v2ray-core/common/retry"
|
||||||
"github.com/v2ray/v2ray-core/config"
|
"github.com/v2ray/v2ray-core/config"
|
||||||
|
"github.com/v2ray/v2ray-core/proxy"
|
||||||
|
"github.com/v2ray/v2ray-core/transport/ray"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
inboundFactories = make(map[string]InboundConnectionHandlerFactory)
|
|
||||||
outboundFactories = make(map[string]OutboundConnectionHandlerFactory)
|
|
||||||
)
|
|
||||||
|
|
||||||
func RegisterInboundConnectionHandlerFactory(name string, factory InboundConnectionHandlerFactory) error {
|
|
||||||
// TODO check name
|
|
||||||
inboundFactories[name] = factory
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func RegisterOutboundConnectionHandlerFactory(name string, factory OutboundConnectionHandlerFactory) error {
|
|
||||||
// TODO check name
|
|
||||||
outboundFactories[name] = factory
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Point is an single server in V2Ray system.
|
// Point is an single server in V2Ray system.
|
||||||
type Point struct {
|
type Point struct {
|
||||||
port uint16
|
port uint16
|
||||||
ich InboundConnectionHandler
|
ich proxy.InboundConnectionHandler
|
||||||
och OutboundConnectionHandler
|
och proxy.OutboundConnectionHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPoint returns a new Point server based on given configuration.
|
// NewPoint returns a new Point server based on given configuration.
|
||||||
@ -37,8 +22,8 @@ func NewPoint(pConfig config.PointConfig) (*Point, error) {
|
|||||||
var vpoint = new(Point)
|
var vpoint = new(Point)
|
||||||
vpoint.port = pConfig.Port()
|
vpoint.port = pConfig.Port()
|
||||||
|
|
||||||
ichFactory, ok := inboundFactories[pConfig.InboundConfig().Protocol()]
|
ichFactory := proxy.GetInboundConnectionHandlerFactory(pConfig.InboundConfig().Protocol())
|
||||||
if !ok {
|
if ichFactory == nil {
|
||||||
log.Error("Unknown inbound connection handler factory %s", pConfig.InboundConfig().Protocol())
|
log.Error("Unknown inbound connection handler factory %s", pConfig.InboundConfig().Protocol())
|
||||||
return nil, config.BadConfiguration
|
return nil, config.BadConfiguration
|
||||||
}
|
}
|
||||||
@ -50,13 +35,13 @@ func NewPoint(pConfig config.PointConfig) (*Point, error) {
|
|||||||
}
|
}
|
||||||
vpoint.ich = ich
|
vpoint.ich = ich
|
||||||
|
|
||||||
ochFactory, ok := outboundFactories[pConfig.OutboundConfig().Protocol()]
|
ochFactory := proxy.GetOutboundConnectionHandlerFactory(pConfig.OutboundConfig().Protocol())
|
||||||
if !ok {
|
if ochFactory == nil {
|
||||||
log.Error("Unknown outbound connection handler factory %s", pConfig.OutboundConfig().Protocol())
|
log.Error("Unknown outbound connection handler factory %s", pConfig.OutboundConfig().Protocol())
|
||||||
return nil, config.BadConfiguration
|
return nil, config.BadConfiguration
|
||||||
}
|
}
|
||||||
ochConfig := pConfig.OutboundConfig().Settings(config.TypeOutbound)
|
ochConfig := pConfig.OutboundConfig().Settings(config.TypeOutbound)
|
||||||
och, err := ochFactory.Create(vpoint, ochConfig)
|
och, err := ochFactory.Create(ochConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed to create outbound connection handler: %v", err)
|
log.Error("Failed to create outbound connection handler: %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -66,22 +51,6 @@ func NewPoint(pConfig config.PointConfig) (*Point, error) {
|
|||||||
return vpoint, nil
|
return vpoint, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type InboundConnectionHandlerFactory interface {
|
|
||||||
Create(vp *Point, config interface{}) (InboundConnectionHandler, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type InboundConnectionHandler interface {
|
|
||||||
Listen(port uint16) error
|
|
||||||
}
|
|
||||||
|
|
||||||
type OutboundConnectionHandlerFactory interface {
|
|
||||||
Create(VP *Point, config interface{}) (OutboundConnectionHandler, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type OutboundConnectionHandler interface {
|
|
||||||
Dispatch(firstPacket v2net.Packet, ray OutboundRay) error
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start starts the Point server, and return any error during the process.
|
// Start starts the Point server, and return any error during the process.
|
||||||
// In the case of any errors, the state of the server is unpredicatable.
|
// In the case of any errors, the state of the server is unpredicatable.
|
||||||
func (vp *Point) Start() error {
|
func (vp *Point) Start() error {
|
||||||
@ -100,8 +69,8 @@ func (vp *Point) Start() error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Point) DispatchToOutbound(packet v2net.Packet) InboundRay {
|
func (p *Point) DispatchToOutbound(packet v2net.Packet) ray.InboundRay {
|
||||||
ray := NewRay()
|
direct := ray.NewRay()
|
||||||
go p.och.Dispatch(packet, ray)
|
go p.och.Dispatch(packet, direct)
|
||||||
return ray
|
return direct
|
||||||
}
|
}
|
@ -4,10 +4,10 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/v2ray/v2ray-core"
|
|
||||||
"github.com/v2ray/v2ray-core/common/alloc"
|
"github.com/v2ray/v2ray-core/common/alloc"
|
||||||
"github.com/v2ray/v2ray-core/common/log"
|
"github.com/v2ray/v2ray-core/common/log"
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
|
"github.com/v2ray/v2ray-core/transport/ray"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FreedomConnection struct {
|
type FreedomConnection struct {
|
||||||
@ -17,7 +17,7 @@ func NewFreedomConnection() *FreedomConnection {
|
|||||||
return &FreedomConnection{}
|
return &FreedomConnection{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vconn *FreedomConnection) Dispatch(firstPacket v2net.Packet, ray core.OutboundRay) error {
|
func (vconn *FreedomConnection) Dispatch(firstPacket v2net.Packet, ray ray.OutboundRay) error {
|
||||||
conn, err := net.Dial(firstPacket.Destination().Network(), firstPacket.Destination().Address().String())
|
conn, err := net.Dial(firstPacket.Destination().Network(), firstPacket.Destination().Address().String())
|
||||||
log.Info("Freedom: Opening connection to %s", firstPacket.Destination().String())
|
log.Info("Freedom: Opening connection to %s", firstPacket.Destination().String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
package freedom
|
package freedom
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/v2ray/v2ray-core"
|
"github.com/v2ray/v2ray-core/proxy"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FreedomFactory struct {
|
type FreedomFactory struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (factory FreedomFactory) Create(vp *core.Point, config interface{}) (core.OutboundConnectionHandler, error) {
|
func (factory FreedomFactory) Create(config interface{}) (proxy.OutboundConnectionHandler, error) {
|
||||||
return NewFreedomConnection(), nil
|
return NewFreedomConnection(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
core.RegisterOutboundConnectionHandlerFactory("freedom", FreedomFactory{})
|
proxy.RegisterOutboundConnectionHandlerFactory("freedom", FreedomFactory{})
|
||||||
}
|
}
|
||||||
|
13
proxy/inbound_connection.go
Normal file
13
proxy/inbound_connection.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package proxy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/v2ray/v2ray-core/app"
|
||||||
|
)
|
||||||
|
|
||||||
|
type InboundConnectionHandlerFactory interface {
|
||||||
|
Create(dispatch app.PacketDispatcher, config interface{}) (InboundConnectionHandler, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type InboundConnectionHandler interface {
|
||||||
|
Listen(port uint16) error
|
||||||
|
}
|
14
proxy/outbound_connection.go
Normal file
14
proxy/outbound_connection.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package proxy
|
||||||
|
|
||||||
|
import (
|
||||||
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
|
"github.com/v2ray/v2ray-core/transport/ray"
|
||||||
|
)
|
||||||
|
|
||||||
|
type OutboundConnectionHandlerFactory interface {
|
||||||
|
Create(config interface{}) (OutboundConnectionHandler, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type OutboundConnectionHandler interface {
|
||||||
|
Dispatch(firstPacket v2net.Packet, ray ray.OutboundRay) error
|
||||||
|
}
|
34
proxy/proxy_cache.go
Normal file
34
proxy/proxy_cache.go
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package proxy
|
||||||
|
|
||||||
|
var (
|
||||||
|
inboundFactories = make(map[string]InboundConnectionHandlerFactory)
|
||||||
|
outboundFactories = make(map[string]OutboundConnectionHandlerFactory)
|
||||||
|
)
|
||||||
|
|
||||||
|
func RegisterInboundConnectionHandlerFactory(name string, factory InboundConnectionHandlerFactory) error {
|
||||||
|
// TODO check name
|
||||||
|
inboundFactories[name] = factory
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterOutboundConnectionHandlerFactory(name string, factory OutboundConnectionHandlerFactory) error {
|
||||||
|
// TODO check name
|
||||||
|
outboundFactories[name] = factory
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetInboundConnectionHandlerFactory(name string) InboundConnectionHandlerFactory {
|
||||||
|
factory, found := inboundFactories[name]
|
||||||
|
if !found {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return factory
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetOutboundConnectionHandlerFactory(name string) OutboundConnectionHandlerFactory {
|
||||||
|
factory, found := outboundFactories[name]
|
||||||
|
if !found {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return factory
|
||||||
|
}
|
@ -8,7 +8,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/v2ray/v2ray-core"
|
"github.com/v2ray/v2ray-core/app"
|
||||||
"github.com/v2ray/v2ray-core/common/alloc"
|
"github.com/v2ray/v2ray-core/common/alloc"
|
||||||
"github.com/v2ray/v2ray-core/common/log"
|
"github.com/v2ray/v2ray-core/common/log"
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
@ -25,13 +25,13 @@ var (
|
|||||||
// SocksServer is a SOCKS 5 proxy server
|
// SocksServer is a SOCKS 5 proxy server
|
||||||
type SocksServer struct {
|
type SocksServer struct {
|
||||||
accepting bool
|
accepting bool
|
||||||
vPoint *core.Point
|
dispatcher app.PacketDispatcher
|
||||||
config *jsonconfig.SocksConfig
|
config *jsonconfig.SocksConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSocksServer(vp *core.Point, config *jsonconfig.SocksConfig) *SocksServer {
|
func NewSocksServer(dispatcher app.PacketDispatcher, config *jsonconfig.SocksConfig) *SocksServer {
|
||||||
return &SocksServer{
|
return &SocksServer{
|
||||||
vPoint: vp,
|
dispatcher: dispatcher,
|
||||||
config: config,
|
config: config,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -249,7 +249,7 @@ func (server *SocksServer) handleSocks4(reader io.Reader, writer io.Writer, auth
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (server *SocksServer) transport(reader io.Reader, writer io.Writer, firstPacket v2net.Packet) {
|
func (server *SocksServer) transport(reader io.Reader, writer io.Writer, firstPacket v2net.Packet) {
|
||||||
ray := server.vPoint.DispatchToOutbound(firstPacket)
|
ray := server.dispatcher.DispatchToOutbound(firstPacket)
|
||||||
input := ray.InboundInput()
|
input := ray.InboundInput()
|
||||||
output := ray.InboundOutput()
|
output := ray.InboundOutput()
|
||||||
|
|
||||||
|
@ -1,19 +1,20 @@
|
|||||||
package socks
|
package socks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/v2ray/v2ray-core"
|
"github.com/v2ray/v2ray-core/app"
|
||||||
|
"github.com/v2ray/v2ray-core/proxy"
|
||||||
"github.com/v2ray/v2ray-core/proxy/socks/config/json"
|
"github.com/v2ray/v2ray-core/proxy/socks/config/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SocksServerFactory struct {
|
type SocksServerFactory struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (factory SocksServerFactory) Create(vp *core.Point, rawConfig interface{}) (core.InboundConnectionHandler, error) {
|
func (factory SocksServerFactory) Create(dispatcher app.PacketDispatcher, rawConfig interface{}) (proxy.InboundConnectionHandler, error) {
|
||||||
config := rawConfig.(*json.SocksConfig)
|
config := rawConfig.(*json.SocksConfig)
|
||||||
config.Initialize()
|
config.Initialize()
|
||||||
return NewSocksServer(vp, config), nil
|
return NewSocksServer(dispatcher, config), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
core.RegisterInboundConnectionHandlerFactory("socks", SocksServerFactory{})
|
proxy.RegisterInboundConnectionHandlerFactory("socks", SocksServerFactory{})
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ func (server *SocksServer) AcceptPackets(conn *net.UDPConn) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (server *SocksServer) handlePacket(conn *net.UDPConn, packet v2net.Packet, clientAddr *net.UDPAddr, targetAddr v2net.Address) {
|
func (server *SocksServer) handlePacket(conn *net.UDPConn, packet v2net.Packet, clientAddr *net.UDPAddr, targetAddr v2net.Address) {
|
||||||
ray := server.vPoint.DispatchToOutbound(packet)
|
ray := server.dispatcher.DispatchToOutbound(packet)
|
||||||
close(ray.InboundInput())
|
close(ray.InboundInput())
|
||||||
|
|
||||||
for data := range ray.InboundOutput() {
|
for data := range ray.InboundOutput() {
|
||||||
|
@ -6,25 +6,26 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/v2ray/v2ray-core"
|
"github.com/v2ray/v2ray-core/app"
|
||||||
"github.com/v2ray/v2ray-core/common/alloc"
|
"github.com/v2ray/v2ray-core/common/alloc"
|
||||||
v2io "github.com/v2ray/v2ray-core/common/io"
|
v2io "github.com/v2ray/v2ray-core/common/io"
|
||||||
"github.com/v2ray/v2ray-core/common/log"
|
"github.com/v2ray/v2ray-core/common/log"
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
|
"github.com/v2ray/v2ray-core/proxy"
|
||||||
"github.com/v2ray/v2ray-core/proxy/vmess/protocol"
|
"github.com/v2ray/v2ray-core/proxy/vmess/protocol"
|
||||||
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user"
|
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user"
|
||||||
)
|
)
|
||||||
|
|
||||||
type VMessInboundHandler struct {
|
type VMessInboundHandler struct {
|
||||||
vPoint *core.Point
|
dispatcher app.PacketDispatcher
|
||||||
clients user.UserSet
|
clients user.UserSet
|
||||||
accepting bool
|
accepting bool
|
||||||
udpEnabled bool
|
udpEnabled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewVMessInboundHandler(vp *core.Point, clients user.UserSet, udpEnabled bool) *VMessInboundHandler {
|
func NewVMessInboundHandler(dispatcher app.PacketDispatcher, clients user.UserSet, udpEnabled bool) *VMessInboundHandler {
|
||||||
return &VMessInboundHandler{
|
return &VMessInboundHandler{
|
||||||
vPoint: vp,
|
dispatcher: dispatcher,
|
||||||
clients: clients,
|
clients: clients,
|
||||||
udpEnabled: udpEnabled,
|
udpEnabled: udpEnabled,
|
||||||
}
|
}
|
||||||
@ -77,7 +78,7 @@ func (handler *VMessInboundHandler) HandleConnection(connection *net.TCPConn) er
|
|||||||
log.Access(connection.RemoteAddr().String(), request.Address.String(), log.AccessAccepted, "")
|
log.Access(connection.RemoteAddr().String(), request.Address.String(), log.AccessAccepted, "")
|
||||||
log.Debug("VMessIn: Received request for %s", request.Address.String())
|
log.Debug("VMessIn: Received request for %s", request.Address.String())
|
||||||
|
|
||||||
ray := handler.vPoint.DispatchToOutbound(v2net.NewPacket(request.Destination(), nil, true))
|
ray := handler.dispatcher.DispatchToOutbound(v2net.NewPacket(request.Destination(), nil, true))
|
||||||
input := ray.InboundInput()
|
input := ray.InboundInput()
|
||||||
output := ray.InboundOutput()
|
output := ray.InboundOutput()
|
||||||
var readFinish, writeFinish sync.Mutex
|
var readFinish, writeFinish sync.Mutex
|
||||||
@ -135,7 +136,7 @@ func handleOutput(request *protocol.VMessRequest, writer io.Writer, output <-cha
|
|||||||
type VMessInboundHandlerFactory struct {
|
type VMessInboundHandlerFactory struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (factory *VMessInboundHandlerFactory) Create(vp *core.Point, rawConfig interface{}) (core.InboundConnectionHandler, error) {
|
func (factory *VMessInboundHandlerFactory) Create(dispatcher app.PacketDispatcher, rawConfig interface{}) (proxy.InboundConnectionHandler, error) {
|
||||||
config := rawConfig.(*VMessInboundConfig)
|
config := rawConfig.(*VMessInboundConfig)
|
||||||
|
|
||||||
allowedClients := user.NewTimedUserSet()
|
allowedClients := user.NewTimedUserSet()
|
||||||
@ -148,9 +149,9 @@ func (factory *VMessInboundHandlerFactory) Create(vp *core.Point, rawConfig inte
|
|||||||
allowedClients.AddUser(user)
|
allowedClients.AddUser(user)
|
||||||
}
|
}
|
||||||
|
|
||||||
return NewVMessInboundHandler(vp, allowedClients, config.UDPEnabled), nil
|
return NewVMessInboundHandler(dispatcher, allowedClients, config.UDPEnabled), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
core.RegisterInboundConnectionHandlerFactory("vmess", &VMessInboundHandlerFactory{})
|
proxy.RegisterInboundConnectionHandlerFactory("vmess", &VMessInboundHandlerFactory{})
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ func (handler *VMessInboundHandler) AcceptPackets(conn *net.UDPConn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (handler *VMessInboundHandler) handlePacket(conn *net.UDPConn, request *protocol.VMessRequest, packet v2net.Packet, clientAddr *net.UDPAddr) {
|
func (handler *VMessInboundHandler) handlePacket(conn *net.UDPConn, request *protocol.VMessRequest, packet v2net.Packet, clientAddr *net.UDPAddr) {
|
||||||
ray := handler.vPoint.DispatchToOutbound(packet)
|
ray := handler.dispatcher.DispatchToOutbound(packet)
|
||||||
close(ray.InboundInput())
|
close(ray.InboundInput())
|
||||||
|
|
||||||
responseKey := md5.Sum(request.RequestKey)
|
responseKey := md5.Sum(request.RequestKey)
|
||||||
|
@ -8,13 +8,14 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/v2ray/v2ray-core"
|
|
||||||
"github.com/v2ray/v2ray-core/common/alloc"
|
"github.com/v2ray/v2ray-core/common/alloc"
|
||||||
v2io "github.com/v2ray/v2ray-core/common/io"
|
v2io "github.com/v2ray/v2ray-core/common/io"
|
||||||
"github.com/v2ray/v2ray-core/common/log"
|
"github.com/v2ray/v2ray-core/common/log"
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
|
"github.com/v2ray/v2ray-core/proxy"
|
||||||
"github.com/v2ray/v2ray-core/proxy/vmess/protocol"
|
"github.com/v2ray/v2ray-core/proxy/vmess/protocol"
|
||||||
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user"
|
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user"
|
||||||
|
"github.com/v2ray/v2ray-core/transport/ray"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -28,14 +29,12 @@ type VNextServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type VMessOutboundHandler struct {
|
type VMessOutboundHandler struct {
|
||||||
vPoint *core.Point
|
|
||||||
vNextList []*VNextServer
|
vNextList []*VNextServer
|
||||||
vNextListUDP []*VNextServer
|
vNextListUDP []*VNextServer
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewVMessOutboundHandler(vp *core.Point, vNextList, vNextListUDP []*VNextServer) *VMessOutboundHandler {
|
func NewVMessOutboundHandler(vNextList, vNextListUDP []*VNextServer) *VMessOutboundHandler {
|
||||||
return &VMessOutboundHandler{
|
return &VMessOutboundHandler{
|
||||||
vPoint: vp,
|
|
||||||
vNextList: vNextList,
|
vNextList: vNextList,
|
||||||
vNextListUDP: vNextListUDP,
|
vNextListUDP: vNextListUDP,
|
||||||
}
|
}
|
||||||
@ -64,7 +63,7 @@ func pickVNext(serverList []*VNextServer) (v2net.Destination, user.User) {
|
|||||||
return vNext.Destination, vNextUser
|
return vNext.Destination, vNextUser
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *VMessOutboundHandler) Dispatch(firstPacket v2net.Packet, ray core.OutboundRay) error {
|
func (handler *VMessOutboundHandler) Dispatch(firstPacket v2net.Packet, ray ray.OutboundRay) error {
|
||||||
vNextList := handler.vNextList
|
vNextList := handler.vNextList
|
||||||
if firstPacket.Destination().IsUDP() {
|
if firstPacket.Destination().IsUDP() {
|
||||||
vNextList = handler.vNextListUDP
|
vNextList = handler.vNextListUDP
|
||||||
@ -91,7 +90,7 @@ func (handler *VMessOutboundHandler) Dispatch(firstPacket v2net.Packet, ray core
|
|||||||
return startCommunicate(request, vNextAddress, ray, firstPacket)
|
return startCommunicate(request, vNextAddress, ray, firstPacket)
|
||||||
}
|
}
|
||||||
|
|
||||||
func startCommunicate(request *protocol.VMessRequest, dest v2net.Destination, ray core.OutboundRay, firstPacket v2net.Packet) error {
|
func startCommunicate(request *protocol.VMessRequest, dest v2net.Destination, ray ray.OutboundRay, firstPacket v2net.Packet) error {
|
||||||
conn, err := net.Dial(dest.Network(), dest.Address().String())
|
conn, err := net.Dial(dest.Network(), dest.Address().String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed to open %s: %v", dest.String(), err)
|
log.Error("Failed to open %s: %v", dest.String(), err)
|
||||||
@ -199,7 +198,7 @@ func handleResponse(conn net.Conn, request *protocol.VMessRequest, output chan<-
|
|||||||
type VMessOutboundHandlerFactory struct {
|
type VMessOutboundHandlerFactory struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (factory *VMessOutboundHandlerFactory) Create(vp *core.Point, rawConfig interface{}) (core.OutboundConnectionHandler, error) {
|
func (factory *VMessOutboundHandlerFactory) Create(rawConfig interface{}) (proxy.OutboundConnectionHandler, error) {
|
||||||
config := rawConfig.(*VMessOutboundConfig)
|
config := rawConfig.(*VMessOutboundConfig)
|
||||||
servers := make([]*VNextServer, 0, len(config.VNextList))
|
servers := make([]*VNextServer, 0, len(config.VNextList))
|
||||||
udpServers := make([]*VNextServer, 0, len(config.VNextList))
|
udpServers := make([]*VNextServer, 0, len(config.VNextList))
|
||||||
@ -222,9 +221,9 @@ func (factory *VMessOutboundHandlerFactory) Create(vp *core.Point, rawConfig int
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NewVMessOutboundHandler(vp, servers, udpServers), nil
|
return NewVMessOutboundHandler(servers, udpServers), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
core.RegisterOutboundConnectionHandlerFactory("vmess", &VMessOutboundHandlerFactory{})
|
proxy.RegisterOutboundConnectionHandlerFactory("vmess", &VMessOutboundHandlerFactory{})
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/v2ray/v2ray-core"
|
"github.com/v2ray/v2ray-core"
|
||||||
|
"github.com/v2ray/v2ray-core/app/point"
|
||||||
"github.com/v2ray/v2ray-core/common/log"
|
"github.com/v2ray/v2ray-core/common/log"
|
||||||
jsonconf "github.com/v2ray/v2ray-core/config/json"
|
jsonconf "github.com/v2ray/v2ray-core/config/json"
|
||||||
|
|
||||||
@ -58,7 +59,7 @@ func main() {
|
|||||||
log.InitAccessLogger(config.LogConfig().AccessLog())
|
log.InitAccessLogger(config.LogConfig().AccessLog())
|
||||||
}
|
}
|
||||||
|
|
||||||
vPoint, err := core.NewPoint(config)
|
vPoint, err := point.NewPoint(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed to create Point server: %v", err)
|
log.Error("Failed to create Point server: %v", err)
|
||||||
return
|
return
|
||||||
|
@ -3,16 +3,17 @@ package mocks
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|
||||||
"github.com/v2ray/v2ray-core"
|
"github.com/v2ray/v2ray-core/app"
|
||||||
"github.com/v2ray/v2ray-core/common/alloc"
|
"github.com/v2ray/v2ray-core/common/alloc"
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
|
"github.com/v2ray/v2ray-core/proxy"
|
||||||
)
|
)
|
||||||
|
|
||||||
type InboundConnectionHandler struct {
|
type InboundConnectionHandler struct {
|
||||||
Data2Send []byte
|
Data2Send []byte
|
||||||
DataReturned *bytes.Buffer
|
DataReturned *bytes.Buffer
|
||||||
Port uint16
|
Port uint16
|
||||||
Server *core.Point
|
Dispatcher app.PacketDispatcher
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *InboundConnectionHandler) Listen(port uint16) error {
|
func (handler *InboundConnectionHandler) Listen(port uint16) error {
|
||||||
@ -21,7 +22,7 @@ func (handler *InboundConnectionHandler) Listen(port uint16) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (handler *InboundConnectionHandler) Communicate(packet v2net.Packet) error {
|
func (handler *InboundConnectionHandler) Communicate(packet v2net.Packet) error {
|
||||||
ray := handler.Server.DispatchToOutbound(packet)
|
ray := handler.Dispatcher.DispatchToOutbound(packet)
|
||||||
|
|
||||||
input := ray.InboundInput()
|
input := ray.InboundInput()
|
||||||
output := ray.InboundOutput()
|
output := ray.InboundOutput()
|
||||||
@ -36,7 +37,7 @@ func (handler *InboundConnectionHandler) Communicate(packet v2net.Packet) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *InboundConnectionHandler) Create(point *core.Point, config interface{}) (core.InboundConnectionHandler, error) {
|
func (handler *InboundConnectionHandler) Create(dispatcher app.PacketDispatcher, config interface{}) (proxy.InboundConnectionHandler, error) {
|
||||||
handler.Server = point
|
handler.Dispatcher = dispatcher
|
||||||
return handler, nil
|
return handler, nil
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,10 @@ package mocks
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|
||||||
"github.com/v2ray/v2ray-core"
|
|
||||||
"github.com/v2ray/v2ray-core/common/alloc"
|
"github.com/v2ray/v2ray-core/common/alloc"
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
|
"github.com/v2ray/v2ray-core/proxy"
|
||||||
|
"github.com/v2ray/v2ray-core/transport/ray"
|
||||||
)
|
)
|
||||||
|
|
||||||
type OutboundConnectionHandler struct {
|
type OutboundConnectionHandler struct {
|
||||||
@ -14,7 +15,7 @@ type OutboundConnectionHandler struct {
|
|||||||
Destination v2net.Destination
|
Destination v2net.Destination
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *OutboundConnectionHandler) Dispatch(packet v2net.Packet, ray core.OutboundRay) error {
|
func (handler *OutboundConnectionHandler) Dispatch(packet v2net.Packet, ray ray.OutboundRay) error {
|
||||||
input := ray.OutboundInput()
|
input := ray.OutboundInput()
|
||||||
output := ray.OutboundOutput()
|
output := ray.OutboundOutput()
|
||||||
|
|
||||||
@ -42,6 +43,6 @@ func (handler *OutboundConnectionHandler) Dispatch(packet v2net.Packet, ray core
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *OutboundConnectionHandler) Create(point *core.Point, config interface{}) (core.OutboundConnectionHandler, error) {
|
func (handler *OutboundConnectionHandler) Create(config interface{}) (proxy.OutboundConnectionHandler, error) {
|
||||||
return handler, nil
|
return handler, nil
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package core
|
package ray
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/v2ray/v2ray-core/common/alloc"
|
"github.com/v2ray/v2ray-core/common/alloc"
|
||||||
@ -8,14 +8,8 @@ const (
|
|||||||
bufferSize = 16
|
bufferSize = 16
|
||||||
)
|
)
|
||||||
|
|
||||||
// Ray is an internal tranport channel bewteen inbound and outbound connection.
|
func NewRay() Ray {
|
||||||
type Ray struct {
|
return &directRay{
|
||||||
Input chan *alloc.Buffer
|
|
||||||
Output chan *alloc.Buffer
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewRay() *Ray {
|
|
||||||
return &Ray{
|
|
||||||
Input: make(chan *alloc.Buffer, bufferSize),
|
Input: make(chan *alloc.Buffer, bufferSize),
|
||||||
Output: make(chan *alloc.Buffer, bufferSize),
|
Output: make(chan *alloc.Buffer, bufferSize),
|
||||||
}
|
}
|
||||||
@ -46,18 +40,29 @@ type InboundRay interface {
|
|||||||
InboundOutput() <-chan *alloc.Buffer
|
InboundOutput() <-chan *alloc.Buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ray *Ray) OutboundInput() <-chan *alloc.Buffer {
|
// Ray is an internal tranport channel bewteen inbound and outbound connection.
|
||||||
|
type Ray interface {
|
||||||
|
InboundRay
|
||||||
|
OutboundRay
|
||||||
|
}
|
||||||
|
|
||||||
|
type directRay struct {
|
||||||
|
Input chan *alloc.Buffer
|
||||||
|
Output chan *alloc.Buffer
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ray *directRay) OutboundInput() <-chan *alloc.Buffer {
|
||||||
return ray.Input
|
return ray.Input
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ray *Ray) OutboundOutput() chan<- *alloc.Buffer {
|
func (ray *directRay) OutboundOutput() chan<- *alloc.Buffer {
|
||||||
return ray.Output
|
return ray.Output
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ray *Ray) InboundInput() chan<- *alloc.Buffer {
|
func (ray *directRay) InboundInput() chan<- *alloc.Buffer {
|
||||||
return ray.Input
|
return ray.Input
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ray *Ray) InboundOutput() <-chan *alloc.Buffer {
|
func (ray *directRay) InboundOutput() <-chan *alloc.Buffer {
|
||||||
return ray.Output
|
return ray.Output
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user