1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-05-25 13:39:17 -04:00

Cleanup root directory

This commit is contained in:
V2Ray
2015-10-14 14:51:19 +02:00
parent 1b80a1a85a
commit 890d185979
17 changed files with 152 additions and 103 deletions

View File

@@ -4,10 +4,10 @@ import (
"net"
"sync"
"github.com/v2ray/v2ray-core"
"github.com/v2ray/v2ray-core/common/alloc"
"github.com/v2ray/v2ray-core/common/log"
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/transport/ray"
)
type FreedomConnection struct {
@@ -17,7 +17,7 @@ func NewFreedomConnection() *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())
log.Info("Freedom: Opening connection to %s", firstPacket.Destination().String())
if err != nil {

View File

@@ -1,16 +1,16 @@
package freedom
import (
"github.com/v2ray/v2ray-core"
"github.com/v2ray/v2ray-core/proxy"
)
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
}
func init() {
core.RegisterOutboundConnectionHandlerFactory("freedom", FreedomFactory{})
proxy.RegisterOutboundConnectionHandlerFactory("freedom", FreedomFactory{})
}

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

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

View File

@@ -8,7 +8,7 @@ import (
"sync"
"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/log"
v2net "github.com/v2ray/v2ray-core/common/net"
@@ -24,15 +24,15 @@ var (
// SocksServer is a SOCKS 5 proxy server
type SocksServer struct {
accepting bool
vPoint *core.Point
config *jsonconfig.SocksConfig
accepting bool
dispatcher app.PacketDispatcher
config *jsonconfig.SocksConfig
}
func NewSocksServer(vp *core.Point, config *jsonconfig.SocksConfig) *SocksServer {
func NewSocksServer(dispatcher app.PacketDispatcher, config *jsonconfig.SocksConfig) *SocksServer {
return &SocksServer{
vPoint: vp,
config: config,
dispatcher: dispatcher,
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) {
ray := server.vPoint.DispatchToOutbound(firstPacket)
ray := server.dispatcher.DispatchToOutbound(firstPacket)
input := ray.InboundInput()
output := ray.InboundOutput()

View File

@@ -1,19 +1,20 @@
package socks
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"
)
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.Initialize()
return NewSocksServer(vp, config), nil
return NewSocksServer(dispatcher, config), nil
}
func init() {
core.RegisterInboundConnectionHandlerFactory("socks", SocksServerFactory{})
proxy.RegisterInboundConnectionHandlerFactory("socks", SocksServerFactory{})
}

View File

@@ -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) {
ray := server.vPoint.DispatchToOutbound(packet)
ray := server.dispatcher.DispatchToOutbound(packet)
close(ray.InboundInput())
for data := range ray.InboundOutput() {

View File

@@ -6,25 +6,26 @@ import (
"net"
"sync"
"github.com/v2ray/v2ray-core"
"github.com/v2ray/v2ray-core/app"
"github.com/v2ray/v2ray-core/common/alloc"
v2io "github.com/v2ray/v2ray-core/common/io"
"github.com/v2ray/v2ray-core/common/log"
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/user"
)
type VMessInboundHandler struct {
vPoint *core.Point
dispatcher app.PacketDispatcher
clients user.UserSet
accepting 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{
vPoint: vp,
dispatcher: dispatcher,
clients: clients,
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.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()
output := ray.InboundOutput()
var readFinish, writeFinish sync.Mutex
@@ -135,7 +136,7 @@ func handleOutput(request *protocol.VMessRequest, writer io.Writer, output <-cha
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)
allowedClients := user.NewTimedUserSet()
@@ -148,9 +149,9 @@ func (factory *VMessInboundHandlerFactory) Create(vp *core.Point, rawConfig inte
allowedClients.AddUser(user)
}
return NewVMessInboundHandler(vp, allowedClients, config.UDPEnabled), nil
return NewVMessInboundHandler(dispatcher, allowedClients, config.UDPEnabled), nil
}
func init() {
core.RegisterInboundConnectionHandlerFactory("vmess", &VMessInboundHandlerFactory{})
proxy.RegisterInboundConnectionHandlerFactory("vmess", &VMessInboundHandlerFactory{})
}

View File

@@ -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) {
ray := handler.vPoint.DispatchToOutbound(packet)
ray := handler.dispatcher.DispatchToOutbound(packet)
close(ray.InboundInput())
responseKey := md5.Sum(request.RequestKey)

View File

@@ -8,13 +8,14 @@ import (
"net"
"sync"
"github.com/v2ray/v2ray-core"
"github.com/v2ray/v2ray-core/common/alloc"
v2io "github.com/v2ray/v2ray-core/common/io"
"github.com/v2ray/v2ray-core/common/log"
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/user"
"github.com/v2ray/v2ray-core/transport/ray"
)
const (
@@ -28,14 +29,12 @@ type VNextServer struct {
}
type VMessOutboundHandler struct {
vPoint *core.Point
vNextList []*VNextServer
vNextListUDP []*VNextServer
}
func NewVMessOutboundHandler(vp *core.Point, vNextList, vNextListUDP []*VNextServer) *VMessOutboundHandler {
func NewVMessOutboundHandler(vNextList, vNextListUDP []*VNextServer) *VMessOutboundHandler {
return &VMessOutboundHandler{
vPoint: vp,
vNextList: vNextList,
vNextListUDP: vNextListUDP,
}
@@ -64,7 +63,7 @@ func pickVNext(serverList []*VNextServer) (v2net.Destination, user.User) {
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
if firstPacket.Destination().IsUDP() {
vNextList = handler.vNextListUDP
@@ -91,7 +90,7 @@ func (handler *VMessOutboundHandler) Dispatch(firstPacket v2net.Packet, ray core
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())
if err != nil {
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 {
}
func (factory *VMessOutboundHandlerFactory) Create(vp *core.Point, rawConfig interface{}) (core.OutboundConnectionHandler, error) {
func (factory *VMessOutboundHandlerFactory) Create(rawConfig interface{}) (proxy.OutboundConnectionHandler, error) {
config := rawConfig.(*VMessOutboundConfig)
servers := 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() {
core.RegisterOutboundConnectionHandlerFactory("vmess", &VMessOutboundHandlerFactory{})
proxy.RegisterOutboundConnectionHandlerFactory("vmess", &VMessOutboundHandlerFactory{})
}