mirror of https://github.com/v2ray/v2ray-core
Simpilify configuration files
parent
78daf8a879
commit
72b4eeba8b
|
@ -1,8 +1,15 @@
|
||||||
package core
|
package config
|
||||||
|
|
||||||
|
type Type string
|
||||||
|
|
||||||
|
const (
|
||||||
|
TypeInbound = Type("inbound")
|
||||||
|
TypeOutbound = Type("outbound")
|
||||||
|
)
|
||||||
|
|
||||||
type ConnectionConfig interface {
|
type ConnectionConfig interface {
|
||||||
Protocol() string
|
Protocol() string
|
||||||
Content() []byte
|
Settings(configType Type) interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
type PointConfig interface {
|
type PointConfig interface {
|
|
@ -0,0 +1,20 @@
|
||||||
|
package json
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/v2ray/v2ray-core/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ConfigObjectCreator func() interface{}
|
||||||
|
|
||||||
|
var (
|
||||||
|
configCache = make(map[string]ConfigObjectCreator)
|
||||||
|
)
|
||||||
|
|
||||||
|
func getConfigKey(protocol string, cType config.Type) string {
|
||||||
|
return protocol + "_" + string(cType)
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterConfigType(protocol string, cType config.Type, creator ConfigObjectCreator) {
|
||||||
|
// TODO: check name
|
||||||
|
configCache[getConfigKey(protocol, cType)] = creator
|
||||||
|
}
|
|
@ -4,30 +4,32 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
"github.com/v2ray/v2ray-core"
|
|
||||||
"github.com/v2ray/v2ray-core/common/log"
|
"github.com/v2ray/v2ray-core/common/log"
|
||||||
|
"github.com/v2ray/v2ray-core/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ConnectionConfig struct {
|
type ConnectionConfig struct {
|
||||||
ProtocolString string `json:"protocol"`
|
ProtocolString string `json:"protocol"`
|
||||||
File string `json:"file"`
|
SettingsMessage json.RawMessage `json:"settings"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *ConnectionConfig) Protocol() string {
|
func (config *ConnectionConfig) Protocol() string {
|
||||||
return config.ProtocolString
|
return config.ProtocolString
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *ConnectionConfig) Content() []byte {
|
func (config *ConnectionConfig) Settings(configType config.Type) interface{} {
|
||||||
if len(config.File) == 0 {
|
creator, found := configCache[getConfigKey(config.Protocol(), configType)]
|
||||||
return nil
|
if !found {
|
||||||
|
panic("Unknown protocol " + config.Protocol())
|
||||||
}
|
}
|
||||||
content, err := ioutil.ReadFile(config.File)
|
configObj := creator()
|
||||||
|
err := json.Unmarshal(config.SettingsMessage, configObj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(log.Error("Failed to read config file (%s): %v", config.File, err))
|
log.Error("Unable to parse connection config: %v", err)
|
||||||
|
panic("Failed to parse connection config.")
|
||||||
}
|
}
|
||||||
return content
|
return configObj
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config is the config for Point server.
|
// Config is the config for Point server.
|
||||||
|
@ -41,11 +43,11 @@ func (config *Config) Port() uint16 {
|
||||||
return config.PortValue
|
return config.PortValue
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *Config) InboundConfig() core.ConnectionConfig {
|
func (config *Config) InboundConfig() config.ConnectionConfig {
|
||||||
return config.InboundConfigValue
|
return config.InboundConfigValue
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *Config) OutboundConfig() core.ConnectionConfig {
|
func (config *Config) OutboundConfig() config.ConnectionConfig {
|
||||||
return config.OutboundConfigValue
|
return config.OutboundConfigValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,24 +55,16 @@ func LoadConfig(file string) (*Config, error) {
|
||||||
fixedFile := os.ExpandEnv(file)
|
fixedFile := os.ExpandEnv(file)
|
||||||
rawConfig, err := ioutil.ReadFile(fixedFile)
|
rawConfig, err := ioutil.ReadFile(fixedFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed to read point config file (%s): %v", file, err)
|
log.Error("Failed to read server config file (%s): %v", file, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
config := &Config{}
|
config := &Config{}
|
||||||
err = json.Unmarshal(rawConfig, config)
|
err = json.Unmarshal(rawConfig, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed to load point config: %v", err)
|
log.Error("Failed to load server config: %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !filepath.IsAbs(config.InboundConfigValue.File) && len(config.InboundConfigValue.File) > 0 {
|
|
||||||
config.InboundConfigValue.File = filepath.Join(filepath.Dir(fixedFile), config.InboundConfigValue.File)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !filepath.IsAbs(config.OutboundConfigValue.File) && len(config.OutboundConfigValue.File) > 0 {
|
|
||||||
config.OutboundConfigValue.File = filepath.Join(filepath.Dir(fixedFile), config.OutboundConfigValue.File)
|
|
||||||
}
|
|
||||||
|
|
||||||
return config, err
|
return config, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,15 @@
|
||||||
package json
|
package json_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/v2ray/v2ray-core/config"
|
||||||
|
"github.com/v2ray/v2ray-core/config/json"
|
||||||
|
_ "github.com/v2ray/v2ray-core/proxy/freedom/config/json"
|
||||||
|
_ "github.com/v2ray/v2ray-core/proxy/socks/config/json"
|
||||||
|
_ "github.com/v2ray/v2ray-core/proxy/vmess"
|
||||||
|
|
||||||
"github.com/v2ray/v2ray-core/testing/unit"
|
"github.com/v2ray/v2ray-core/testing/unit"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -13,18 +19,18 @@ func TestClientSampleConfig(t *testing.T) {
|
||||||
// TODO: fix for Windows
|
// TODO: fix for Windows
|
||||||
baseDir := "$GOPATH/src/github.com/v2ray/v2ray-core/release/config"
|
baseDir := "$GOPATH/src/github.com/v2ray/v2ray-core/release/config"
|
||||||
|
|
||||||
config, err := LoadConfig(filepath.Join(baseDir, "vpoint_socks_vmess.json"))
|
pointConfig, err := json.LoadConfig(filepath.Join(baseDir, "vpoint_socks_vmess.json"))
|
||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
|
|
||||||
assert.Uint16(config.Port()).Positive()
|
assert.Uint16(pointConfig.Port()).Positive()
|
||||||
assert.Pointer(config.InboundConfig()).IsNotNil()
|
assert.Pointer(pointConfig.InboundConfig()).IsNotNil()
|
||||||
assert.Pointer(config.OutboundConfig()).IsNotNil()
|
assert.Pointer(pointConfig.OutboundConfig()).IsNotNil()
|
||||||
|
|
||||||
assert.String(config.InboundConfig().Protocol()).Equals("socks")
|
assert.String(pointConfig.InboundConfig().Protocol()).Equals("socks")
|
||||||
assert.Int(len(config.InboundConfig().Content())).GreaterThan(0)
|
assert.Pointer(pointConfig.InboundConfig().Settings(config.TypeInbound)).IsNotNil()
|
||||||
|
|
||||||
assert.String(config.OutboundConfig().Protocol()).Equals("vmess")
|
assert.String(pointConfig.OutboundConfig().Protocol()).Equals("vmess")
|
||||||
assert.Int(len(config.OutboundConfig().Content())).GreaterThan(0)
|
assert.Pointer(pointConfig.OutboundConfig().Settings(config.TypeOutbound)).IsNotNil()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServerSampleConfig(t *testing.T) {
|
func TestServerSampleConfig(t *testing.T) {
|
||||||
|
@ -33,16 +39,16 @@ func TestServerSampleConfig(t *testing.T) {
|
||||||
// TODO: fix for Windows
|
// TODO: fix for Windows
|
||||||
baseDir := "$GOPATH/src/github.com/v2ray/v2ray-core/release/config"
|
baseDir := "$GOPATH/src/github.com/v2ray/v2ray-core/release/config"
|
||||||
|
|
||||||
config, err := LoadConfig(filepath.Join(baseDir, "vpoint_vmess_freedom.json"))
|
pointConfig, err := json.LoadConfig(filepath.Join(baseDir, "vpoint_vmess_freedom.json"))
|
||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
|
|
||||||
assert.Uint16(config.Port()).Positive()
|
assert.Uint16(pointConfig.Port()).Positive()
|
||||||
assert.Pointer(config.InboundConfig()).IsNotNil()
|
assert.Pointer(pointConfig.InboundConfig()).IsNotNil()
|
||||||
assert.Pointer(config.OutboundConfig()).IsNotNil()
|
assert.Pointer(pointConfig.OutboundConfig()).IsNotNil()
|
||||||
|
|
||||||
assert.String(config.InboundConfig().Protocol()).Equals("vmess")
|
assert.String(pointConfig.InboundConfig().Protocol()).Equals("vmess")
|
||||||
assert.Int(len(config.InboundConfig().Content())).GreaterThan(0)
|
assert.Pointer(pointConfig.InboundConfig().Settings(config.TypeInbound)).IsNotNil()
|
||||||
|
|
||||||
assert.String(config.OutboundConfig().Protocol()).Equals("freedom")
|
assert.String(pointConfig.OutboundConfig().Protocol()).Equals("freedom")
|
||||||
assert.Int(len(config.OutboundConfig().Content())).Equals(0)
|
assert.Pointer(pointConfig.OutboundConfig().Settings(config.TypeOutbound)).IsNotNil()
|
||||||
}
|
}
|
||||||
|
|
30
point.go
30
point.go
|
@ -3,6 +3,7 @@ package core
|
||||||
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/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -26,37 +27,37 @@ func RegisterOutboundConnectionHandlerFactory(name string, factory OutboundConne
|
||||||
type Point struct {
|
type Point struct {
|
||||||
port uint16
|
port uint16
|
||||||
ichFactory InboundConnectionHandlerFactory
|
ichFactory InboundConnectionHandlerFactory
|
||||||
ichConfig []byte
|
ichConfig interface{}
|
||||||
ochFactory OutboundConnectionHandlerFactory
|
ochFactory OutboundConnectionHandlerFactory
|
||||||
ochConfig []byte
|
ochConfig interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPoint returns a new Point server based on given configuration.
|
// NewPoint returns a new Point server based on given configuration.
|
||||||
// The server is not started at this point.
|
// The server is not started at this point.
|
||||||
func NewPoint(config PointConfig) (*Point, error) {
|
func NewPoint(pConfig config.PointConfig) (*Point, error) {
|
||||||
var vpoint = new(Point)
|
var vpoint = new(Point)
|
||||||
vpoint.port = config.Port()
|
vpoint.port = pConfig.Port()
|
||||||
|
|
||||||
ichFactory, ok := inboundFactories[config.InboundConfig().Protocol()]
|
ichFactory, ok := inboundFactories[pConfig.InboundConfig().Protocol()]
|
||||||
if !ok {
|
if !ok {
|
||||||
panic(log.Error("Unknown inbound connection handler factory %s", config.InboundConfig().Protocol()))
|
panic(log.Error("Unknown inbound connection handler factory %s", pConfig.InboundConfig().Protocol()))
|
||||||
}
|
}
|
||||||
vpoint.ichFactory = ichFactory
|
vpoint.ichFactory = ichFactory
|
||||||
vpoint.ichConfig = config.InboundConfig().Content()
|
vpoint.ichConfig = pConfig.InboundConfig().Settings(config.TypeInbound)
|
||||||
|
|
||||||
ochFactory, ok := outboundFactories[config.OutboundConfig().Protocol()]
|
ochFactory, ok := outboundFactories[pConfig.OutboundConfig().Protocol()]
|
||||||
if !ok {
|
if !ok {
|
||||||
panic(log.Error("Unknown outbound connection handler factory %s", config.OutboundConfig().Protocol))
|
panic(log.Error("Unknown outbound connection handler factory %s", pConfig.OutboundConfig().Protocol))
|
||||||
}
|
}
|
||||||
|
|
||||||
vpoint.ochFactory = ochFactory
|
vpoint.ochFactory = ochFactory
|
||||||
vpoint.ochConfig = config.OutboundConfig().Content()
|
vpoint.ochConfig = pConfig.OutboundConfig().Settings(config.TypeOutbound)
|
||||||
|
|
||||||
return vpoint, nil
|
return vpoint, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type InboundConnectionHandlerFactory interface {
|
type InboundConnectionHandlerFactory interface {
|
||||||
Create(vp *Point, config []byte) (InboundConnectionHandler, error)
|
Create(vp *Point, config interface{}) (InboundConnectionHandler, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type InboundConnectionHandler interface {
|
type InboundConnectionHandler interface {
|
||||||
|
@ -64,8 +65,7 @@ type InboundConnectionHandler interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type OutboundConnectionHandlerFactory interface {
|
type OutboundConnectionHandlerFactory interface {
|
||||||
Initialize(config []byte) error
|
Create(VP *Point, config interface{}, firstPacket v2net.Packet) (OutboundConnectionHandler, error)
|
||||||
Create(VP *Point, firstPacket v2net.Packet) (OutboundConnectionHandler, error)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type OutboundConnectionHandler interface {
|
type OutboundConnectionHandler interface {
|
||||||
|
@ -79,8 +79,6 @@ func (vp *Point) Start() error {
|
||||||
return log.Error("Invalid port %d", vp.port)
|
return log.Error("Invalid port %d", vp.port)
|
||||||
}
|
}
|
||||||
|
|
||||||
vp.ochFactory.Initialize(vp.ochConfig)
|
|
||||||
|
|
||||||
inboundConnectionHandler, err := vp.ichFactory.Create(vp, vp.ichConfig)
|
inboundConnectionHandler, err := vp.ichFactory.Create(vp, vp.ichConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -92,7 +90,7 @@ func (vp *Point) Start() error {
|
||||||
func (p *Point) DispatchToOutbound(packet v2net.Packet) InboundRay {
|
func (p *Point) DispatchToOutbound(packet v2net.Packet) InboundRay {
|
||||||
ray := NewRay()
|
ray := NewRay()
|
||||||
// TODO: handle error
|
// TODO: handle error
|
||||||
och, _ := p.ochFactory.Create(p, packet)
|
och, _ := p.ochFactory.Create(p, p.ochConfig, packet)
|
||||||
_ = och.Start(ray)
|
_ = och.Start(ray)
|
||||||
return ray
|
return ray
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package json
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/v2ray/v2ray-core/config"
|
||||||
|
"github.com/v2ray/v2ray-core/config/json"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FreedomConfiguration struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
json.RegisterConfigType("freedom", config.TypeOutbound, func() interface{} {
|
||||||
|
return &FreedomConfiguration{}
|
||||||
|
})
|
||||||
|
}
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"github.com/v2ray/v2ray-core"
|
"github.com/v2ray/v2ray-core"
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
_ "github.com/v2ray/v2ray-core/proxy/socks"
|
_ "github.com/v2ray/v2ray-core/proxy/socks"
|
||||||
|
"github.com/v2ray/v2ray-core/proxy/socks/config/json"
|
||||||
"github.com/v2ray/v2ray-core/testing/mocks"
|
"github.com/v2ray/v2ray-core/testing/mocks"
|
||||||
"github.com/v2ray/v2ray-core/testing/servers/tcp"
|
"github.com/v2ray/v2ray-core/testing/servers/tcp"
|
||||||
"github.com/v2ray/v2ray-core/testing/servers/udp"
|
"github.com/v2ray/v2ray-core/testing/servers/udp"
|
||||||
|
@ -47,11 +48,11 @@ func TestUDPSend(t *testing.T) {
|
||||||
PortValue: pointPort,
|
PortValue: pointPort,
|
||||||
InboundConfigValue: &mocks.ConnectionConfig{
|
InboundConfigValue: &mocks.ConnectionConfig{
|
||||||
ProtocolValue: "mock_ich",
|
ProtocolValue: "mock_ich",
|
||||||
ContentValue: nil,
|
SettingsValue: nil,
|
||||||
},
|
},
|
||||||
OutboundConfigValue: &mocks.ConnectionConfig{
|
OutboundConfigValue: &mocks.ConnectionConfig{
|
||||||
ProtocolValue: "freedom",
|
ProtocolValue: "freedom",
|
||||||
ContentValue: nil,
|
SettingsValue: nil,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,11 +90,13 @@ func TestSocksTcpConnect(t *testing.T) {
|
||||||
PortValue: pointPort,
|
PortValue: pointPort,
|
||||||
InboundConfigValue: &mocks.ConnectionConfig{
|
InboundConfigValue: &mocks.ConnectionConfig{
|
||||||
ProtocolValue: "socks",
|
ProtocolValue: "socks",
|
||||||
ContentValue: []byte("{\"auth\": \"noauth\"}"),
|
SettingsValue: &json.SocksConfig{
|
||||||
|
AuthMethod: "auth",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
OutboundConfigValue: &mocks.ConnectionConfig{
|
OutboundConfigValue: &mocks.ConnectionConfig{
|
||||||
ProtocolValue: "freedom",
|
ProtocolValue: "freedom",
|
||||||
ContentValue: nil,
|
SettingsValue: nil,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,11 +8,7 @@ import (
|
||||||
type FreedomFactory struct {
|
type FreedomFactory struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (factory FreedomFactory) Initialize(config []byte) error {
|
func (factory FreedomFactory) Create(vp *core.Point, config interface{}, firstPacket v2net.Packet) (core.OutboundConnectionHandler, error) {
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (factory FreedomFactory) Create(vp *core.Point, firstPacket v2net.Packet) (core.OutboundConnectionHandler, error) {
|
|
||||||
return NewFreedomConnection(firstPacket), nil
|
return NewFreedomConnection(firstPacket), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
package json
|
package json
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"github.com/v2ray/v2ray-core/config"
|
||||||
|
"github.com/v2ray/v2ray-core/config/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -24,8 +25,8 @@ func (config SocksConfig) IsPassword() bool {
|
||||||
return config.AuthMethod == AuthMethodUserPass
|
return config.AuthMethod == AuthMethodUserPass
|
||||||
}
|
}
|
||||||
|
|
||||||
func Load(rawConfig []byte) (SocksConfig, error) {
|
func init() {
|
||||||
config := SocksConfig{}
|
json.RegisterConfigType("socks", config.TypeInbound, func() interface{} {
|
||||||
err := json.Unmarshal(rawConfig, &config)
|
return new(SocksConfig)
|
||||||
return config, err
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,15 +19,10 @@ import (
|
||||||
type SocksServer struct {
|
type SocksServer struct {
|
||||||
accepting bool
|
accepting bool
|
||||||
vPoint *core.Point
|
vPoint *core.Point
|
||||||
config jsonconfig.SocksConfig
|
config *jsonconfig.SocksConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSocksServer(vp *core.Point, rawConfig []byte) *SocksServer {
|
func NewSocksServer(vp *core.Point, config *jsonconfig.SocksConfig) *SocksServer {
|
||||||
config, err := jsonconfig.Load(rawConfig)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Unable to load socks config: %v", err)
|
|
||||||
panic(errors.NewConfigurationError())
|
|
||||||
}
|
|
||||||
return &SocksServer{
|
return &SocksServer{
|
||||||
vPoint: vp,
|
vPoint: vp,
|
||||||
config: config,
|
config: config,
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"golang.org/x/net/proxy"
|
"golang.org/x/net/proxy"
|
||||||
|
|
||||||
"github.com/v2ray/v2ray-core"
|
"github.com/v2ray/v2ray-core"
|
||||||
|
"github.com/v2ray/v2ray-core/proxy/socks/config/json"
|
||||||
"github.com/v2ray/v2ray-core/testing/mocks"
|
"github.com/v2ray/v2ray-core/testing/mocks"
|
||||||
"github.com/v2ray/v2ray-core/testing/unit"
|
"github.com/v2ray/v2ray-core/testing/unit"
|
||||||
)
|
)
|
||||||
|
@ -28,11 +29,13 @@ func TestSocksTcpConnect(t *testing.T) {
|
||||||
PortValue: port,
|
PortValue: port,
|
||||||
InboundConfigValue: &mocks.ConnectionConfig{
|
InboundConfigValue: &mocks.ConnectionConfig{
|
||||||
ProtocolValue: "socks",
|
ProtocolValue: "socks",
|
||||||
ContentValue: []byte("{\"auth\": \"noauth\"}"),
|
SettingsValue: &json.SocksConfig{
|
||||||
|
AuthMethod: "noauth",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
OutboundConfigValue: &mocks.ConnectionConfig{
|
OutboundConfigValue: &mocks.ConnectionConfig{
|
||||||
ProtocolValue: "mock_och",
|
ProtocolValue: "mock_och",
|
||||||
ContentValue: nil,
|
SettingsValue: nil,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,11 +82,15 @@ func TestSocksTcpConnectWithUserPass(t *testing.T) {
|
||||||
PortValue: port,
|
PortValue: port,
|
||||||
InboundConfigValue: &mocks.ConnectionConfig{
|
InboundConfigValue: &mocks.ConnectionConfig{
|
||||||
ProtocolValue: "socks",
|
ProtocolValue: "socks",
|
||||||
ContentValue: []byte("{\"auth\": \"password\",\"user\": \"userx\",\"pass\": \"passy\"}"),
|
SettingsValue: &json.SocksConfig{
|
||||||
|
AuthMethod: "noauth",
|
||||||
|
Username: "userx",
|
||||||
|
Password: "passy",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
OutboundConfigValue: &mocks.ConnectionConfig{
|
OutboundConfigValue: &mocks.ConnectionConfig{
|
||||||
ProtocolValue: "mock_och",
|
ProtocolValue: "mock_och",
|
||||||
ContentValue: nil,
|
SettingsValue: nil,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,11 +137,14 @@ func TestSocksUdpSend(t *testing.T) {
|
||||||
PortValue: port,
|
PortValue: port,
|
||||||
InboundConfigValue: &mocks.ConnectionConfig{
|
InboundConfigValue: &mocks.ConnectionConfig{
|
||||||
ProtocolValue: "socks",
|
ProtocolValue: "socks",
|
||||||
ContentValue: []byte("{\"auth\": \"noauth\", \"udp\": true}"),
|
SettingsValue: &json.SocksConfig{
|
||||||
|
AuthMethod: "noauth",
|
||||||
|
UDPEnabled: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
OutboundConfigValue: &mocks.ConnectionConfig{
|
OutboundConfigValue: &mocks.ConnectionConfig{
|
||||||
ProtocolValue: "mock_och",
|
ProtocolValue: "mock_och",
|
||||||
ContentValue: nil,
|
SettingsValue: nil,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,14 @@ package socks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/v2ray/v2ray-core"
|
"github.com/v2ray/v2ray-core"
|
||||||
|
"github.com/v2ray/v2ray-core/proxy/socks/config/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SocksServerFactory struct {
|
type SocksServerFactory struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (factory SocksServerFactory) Create(vp *core.Point, config []byte) (core.InboundConnectionHandler, error) {
|
func (factory SocksServerFactory) Create(vp *core.Point, config interface{}) (core.InboundConnectionHandler, error) {
|
||||||
return NewSocksServer(vp, config), nil
|
return NewSocksServer(vp, config.(*json.SocksConfig)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
package vmess
|
package vmess
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"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/config"
|
||||||
|
"github.com/v2ray/v2ray-core/config/json"
|
||||||
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user"
|
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -29,12 +30,6 @@ type VMessInboundConfig struct {
|
||||||
UDPEnabled bool `json:"udp"`
|
UDPEnabled bool `json:"udp"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadInboundConfig(rawConfig []byte) (VMessInboundConfig, error) {
|
|
||||||
config := VMessInboundConfig{}
|
|
||||||
err := json.Unmarshal(rawConfig, &config)
|
|
||||||
return config, err
|
|
||||||
}
|
|
||||||
|
|
||||||
type VNextConfig struct {
|
type VNextConfig struct {
|
||||||
Address string `json:"address"`
|
Address string `json:"address"`
|
||||||
Port uint16 `json:"port"`
|
Port uint16 `json:"port"`
|
||||||
|
@ -76,8 +71,12 @@ type VMessOutboundConfig struct {
|
||||||
VNextList []VNextConfig `json:"vnext"`
|
VNextList []VNextConfig `json:"vnext"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadOutboundConfig(rawConfig []byte) (VMessOutboundConfig, error) {
|
func init() {
|
||||||
config := VMessOutboundConfig{}
|
json.RegisterConfigType("vmess", config.TypeInbound, func() interface{} {
|
||||||
err := json.Unmarshal(rawConfig, &config)
|
return new(VMessInboundConfig)
|
||||||
return config, err
|
})
|
||||||
|
|
||||||
|
json.RegisterConfigType("vmess", config.TypeOutbound, func() interface{} {
|
||||||
|
return new(VMessOutboundConfig)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,11 +27,22 @@ func TestVMessInAndOut(t *testing.T) {
|
||||||
PortValue: portA,
|
PortValue: portA,
|
||||||
InboundConfigValue: &mocks.ConnectionConfig{
|
InboundConfigValue: &mocks.ConnectionConfig{
|
||||||
ProtocolValue: "mock_ich",
|
ProtocolValue: "mock_ich",
|
||||||
ContentValue: nil,
|
SettingsValue: nil,
|
||||||
},
|
},
|
||||||
OutboundConfigValue: &mocks.ConnectionConfig{
|
OutboundConfigValue: &mocks.ConnectionConfig{
|
||||||
ProtocolValue: "vmess",
|
ProtocolValue: "vmess",
|
||||||
ContentValue: []byte("{\"vnext\":[{\"address\": \"127.0.0.1\", \"network\": \"tcp\", \"port\": 13829, \"users\":[{\"id\": \"ad937d9d-6e23-4a5a-ba23-bce5092a7c51\"}]}]}"),
|
SettingsValue: &VMessOutboundConfig{
|
||||||
|
[]VNextConfig{
|
||||||
|
VNextConfig{
|
||||||
|
Address: "127.0.0.1",
|
||||||
|
Port: 13829,
|
||||||
|
Network: "tcp",
|
||||||
|
Users: []VMessUser{
|
||||||
|
VMessUser{Id: "ad937d9d-6e23-4a5a-ba23-bce5092a7c51"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,11 +65,15 @@ func TestVMessInAndOut(t *testing.T) {
|
||||||
PortValue: portB,
|
PortValue: portB,
|
||||||
InboundConfigValue: &mocks.ConnectionConfig{
|
InboundConfigValue: &mocks.ConnectionConfig{
|
||||||
ProtocolValue: "vmess",
|
ProtocolValue: "vmess",
|
||||||
ContentValue: []byte("{\"clients\": [{\"id\": \"ad937d9d-6e23-4a5a-ba23-bce5092a7c51\"}]}"),
|
SettingsValue: &VMessInboundConfig{
|
||||||
|
AllowedClients: []VMessUser{
|
||||||
|
VMessUser{Id: "ad937d9d-6e23-4a5a-ba23-bce5092a7c51"},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
OutboundConfigValue: &mocks.ConnectionConfig{
|
OutboundConfigValue: &mocks.ConnectionConfig{
|
||||||
ProtocolValue: "mock_och",
|
ProtocolValue: "mock_och",
|
||||||
ContentValue: nil,
|
SettingsValue: nil,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,11 +106,22 @@ func TestVMessInAndOutUDP(t *testing.T) {
|
||||||
PortValue: portA,
|
PortValue: portA,
|
||||||
InboundConfigValue: &mocks.ConnectionConfig{
|
InboundConfigValue: &mocks.ConnectionConfig{
|
||||||
ProtocolValue: "mock_ich",
|
ProtocolValue: "mock_ich",
|
||||||
ContentValue: nil,
|
SettingsValue: nil,
|
||||||
},
|
},
|
||||||
OutboundConfigValue: &mocks.ConnectionConfig{
|
OutboundConfigValue: &mocks.ConnectionConfig{
|
||||||
ProtocolValue: "vmess",
|
ProtocolValue: "vmess",
|
||||||
ContentValue: []byte("{\"vnext\":[{\"address\": \"127.0.0.1\", \"network\": \"udp\", \"port\": 13841, \"users\":[{\"id\": \"ad937d9d-6e23-4a5a-ba23-bce5092a7c51\"}]}]}"),
|
SettingsValue: &VMessOutboundConfig{
|
||||||
|
[]VNextConfig{
|
||||||
|
VNextConfig{
|
||||||
|
Address: "127.0.0.1",
|
||||||
|
Port: 13841,
|
||||||
|
Network: "udp",
|
||||||
|
Users: []VMessUser{
|
||||||
|
VMessUser{Id: "ad937d9d-6e23-4a5a-ba23-bce5092a7c51"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,11 +144,16 @@ func TestVMessInAndOutUDP(t *testing.T) {
|
||||||
PortValue: portB,
|
PortValue: portB,
|
||||||
InboundConfigValue: &mocks.ConnectionConfig{
|
InboundConfigValue: &mocks.ConnectionConfig{
|
||||||
ProtocolValue: "vmess",
|
ProtocolValue: "vmess",
|
||||||
ContentValue: []byte("{\"clients\": [{\"id\": \"ad937d9d-6e23-4a5a-ba23-bce5092a7c51\"}], \"udp\": true}"),
|
SettingsValue: &VMessInboundConfig{
|
||||||
|
AllowedClients: []VMessUser{
|
||||||
|
VMessUser{Id: "ad937d9d-6e23-4a5a-ba23-bce5092a7c51"},
|
||||||
|
},
|
||||||
|
UDPEnabled: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
OutboundConfigValue: &mocks.ConnectionConfig{
|
OutboundConfigValue: &mocks.ConnectionConfig{
|
||||||
ProtocolValue: "mock_och",
|
ProtocolValue: "mock_och",
|
||||||
ContentValue: nil,
|
SettingsValue: nil,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -136,11 +136,9 @@ func handleOutput(request *protocol.VMessRequest, writer io.Writer, output <-cha
|
||||||
type VMessInboundHandlerFactory struct {
|
type VMessInboundHandlerFactory struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (factory *VMessInboundHandlerFactory) Create(vp *core.Point, rawConfig []byte) (core.InboundConnectionHandler, error) {
|
func (factory *VMessInboundHandlerFactory) Create(vp *core.Point, rawConfig interface{}) (core.InboundConnectionHandler, error) {
|
||||||
config, err := loadInboundConfig(rawConfig)
|
config := rawConfig.(*VMessInboundConfig)
|
||||||
if err != nil {
|
|
||||||
panic(log.Error("VMessIn: Failed to load VMess inbound config: %v", err))
|
|
||||||
}
|
|
||||||
allowedClients := user.NewTimedUserSet()
|
allowedClients := user.NewTimedUserSet()
|
||||||
for _, client := range config.AllowedClients {
|
for _, client := range config.AllowedClients {
|
||||||
user, err := client.ToUser()
|
user, err := client.ToUser()
|
||||||
|
|
|
@ -193,16 +193,10 @@ func handleResponse(conn net.Conn, request *protocol.VMessRequest, output chan<-
|
||||||
}
|
}
|
||||||
|
|
||||||
type VMessOutboundHandlerFactory struct {
|
type VMessOutboundHandlerFactory struct {
|
||||||
servers []VNextServer
|
|
||||||
udpServers []VNextServer
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (factory *VMessOutboundHandlerFactory) Initialize(rawConfig []byte) error {
|
func (factory *VMessOutboundHandlerFactory) Create(vp *core.Point, rawConfig interface{}, firstPacket v2net.Packet) (core.OutboundConnectionHandler, error) {
|
||||||
config, err := loadOutboundConfig(rawConfig)
|
config := rawConfig.(*VMessOutboundConfig)
|
||||||
if err != nil {
|
|
||||||
panic(log.Error("Failed to load VMess outbound config: %v", err))
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
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))
|
||||||
for _, server := range config.VNextList {
|
for _, server := range config.VNextList {
|
||||||
|
@ -213,13 +207,7 @@ func (factory *VMessOutboundHandlerFactory) Initialize(rawConfig []byte) error {
|
||||||
udpServers = append(udpServers, server.ToVNextServer("udp"))
|
udpServers = append(udpServers, server.ToVNextServer("udp"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
factory.servers = servers
|
return NewVMessOutboundHandler(vp, servers, udpServers, firstPacket), nil
|
||||||
factory.udpServers = udpServers
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (factory *VMessOutboundHandlerFactory) Create(vp *core.Point, firstPacket v2net.Packet) (core.OutboundConnectionHandler, error) {
|
|
||||||
return NewVMessOutboundHandler(vp, factory.servers, factory.udpServers, firstPacket), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
{
|
|
||||||
"auth": "noauth",
|
|
||||||
"udp": false
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
{
|
|
||||||
"clients": [
|
|
||||||
{"id": "ad937d9d-6e23-4a5a-ba23-bce5092a7c51"}
|
|
||||||
],
|
|
||||||
"udp": false
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
{
|
|
||||||
"vnext": [
|
|
||||||
{
|
|
||||||
"address": "127.0.0.1",
|
|
||||||
"port": 27183,
|
|
||||||
"users": [
|
|
||||||
{"id": "ad937d9d-6e23-4a5a-ba23-bce5092a7c51"}
|
|
||||||
],
|
|
||||||
"network": "tcp"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -2,10 +2,24 @@
|
||||||
"port": 1080,
|
"port": 1080,
|
||||||
"inbound": {
|
"inbound": {
|
||||||
"protocol": "socks",
|
"protocol": "socks",
|
||||||
"file": "in_socks.json"
|
"settings": {
|
||||||
|
"auth": "noauth",
|
||||||
|
"udp": false
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"outbound": {
|
"outbound": {
|
||||||
"protocol": "vmess",
|
"protocol": "vmess",
|
||||||
"file": "out_vmess.json"
|
"settings": {
|
||||||
|
"vnext": [
|
||||||
|
{
|
||||||
|
"address": "127.0.0.1",
|
||||||
|
"port": 27183,
|
||||||
|
"users": [
|
||||||
|
{"id": "ad937d9d-6e23-4a5a-ba23-bce5092a7c51"}
|
||||||
|
],
|
||||||
|
"network": "tcp"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,15 @@
|
||||||
"port": 27183,
|
"port": 27183,
|
||||||
"inbound": {
|
"inbound": {
|
||||||
"protocol": "vmess",
|
"protocol": "vmess",
|
||||||
"file": "in_vmess.json"
|
"settings": {
|
||||||
|
"clients": [
|
||||||
|
{"id": "ad937d9d-6e23-4a5a-ba23-bce5092a7c51"}
|
||||||
|
],
|
||||||
|
"udp": false
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"outbound": {
|
"outbound": {
|
||||||
"protocol": "freedom",
|
"protocol": "freedom",
|
||||||
"file": ""
|
"settings": {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
jsonconf "github.com/v2ray/v2ray-core/config/json"
|
jsonconf "github.com/v2ray/v2ray-core/config/json"
|
||||||
|
|
||||||
// The following are neccesary as they register handlers in their init functions.
|
// The following are neccesary as they register handlers in their init functions.
|
||||||
|
_ "github.com/v2ray/v2ray-core/proxy/freedom/config/json"
|
||||||
_ "github.com/v2ray/v2ray-core/proxy/freedom"
|
_ "github.com/v2ray/v2ray-core/proxy/freedom"
|
||||||
_ "github.com/v2ray/v2ray-core/proxy/socks"
|
_ "github.com/v2ray/v2ray-core/proxy/socks"
|
||||||
_ "github.com/v2ray/v2ray-core/proxy/vmess"
|
_ "github.com/v2ray/v2ray-core/proxy/vmess"
|
||||||
|
|
|
@ -19,38 +19,27 @@
|
||||||
"port": 1080, // 监听端口
|
"port": 1080, // 监听端口
|
||||||
"inbound": {
|
"inbound": {
|
||||||
"protocol": "socks", // 传入数据所用协议
|
"protocol": "socks", // 传入数据所用协议
|
||||||
"file": "in_socks.json" // socks 配置文件
|
"settings": {
|
||||||
|
"auth": "noauth", // 认证方式,暂时只支持匿名
|
||||||
|
"udp": false // 如果要使用 UDP 转发,请改成 true
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"outbound": {
|
"outbound": {
|
||||||
"protocol": "vmess", // 中继协议
|
"protocol": "vmess", // 中继协议,暂时只有这个
|
||||||
"file": "out_vmess.json" // vmess 配置文件
|
"settings": {
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
另外还需要两个文件,保存于同一文件夹下:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
// in_socks.json
|
|
||||||
{
|
|
||||||
"auth": "noauth" // 认证方式,暂时只支持匿名
|
|
||||||
"udp": false // 如果要使用 UDP 转发,请改成 true
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
// out_vmess.json
|
|
||||||
{
|
|
||||||
"vnext": [
|
"vnext": [
|
||||||
{
|
{
|
||||||
"address": "127.0.0.1", // Point B 的 IP 地址,IPv4 或 IPv6,不支持域名
|
"address": "127.0.0.1", // Point B 的 IP 地址,IPv4 或 IPv6,不支持域名
|
||||||
"port": 27183, // Point B 的监听端口,请更换成其它的值
|
"port": 27183, // Point B 的监听端口,请更换成其它的值
|
||||||
"users": [
|
"users": [
|
||||||
{"id": "ad937d9d-6e23-4a5a-ba23-bce5092a7c51"} // 用户 ID,必须包含在 Point B 的配置文件中。此 ID 将被用于通信的认证,请自行更换随机的 ID,可以使用 https://www.uuidgenerator.net/ 来生成新的 ID。
|
// 用户 ID,必须包含在 Point B 的配置文件中。此 ID 将被用于通信的认证,请自行更换随机的 ID,可以使用 https://www.uuidgenerator.net/ 来生成新的 ID。
|
||||||
|
{"id": "ad937d9d-6e23-4a5a-ba23-bce5092a7c51"}
|
||||||
],
|
],
|
||||||
"network": "tcp" // 如果要使用 UDP 转发,请改成 "tcp,udp"
|
"network": "tcp" // 如果要使用 UDP 转发,请改成 "tcp,udp"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -58,29 +47,24 @@
|
||||||
示例配置保存于 vpoint_vmess_freedom.json 文件中,格式如下:
|
示例配置保存于 vpoint_vmess_freedom.json 文件中,格式如下:
|
||||||
```javascript
|
```javascript
|
||||||
{
|
{
|
||||||
"port": 27183, // 监听端口,必须和 out_vmess.json 中指定的一致
|
"port": 27183, // 监听端口,必须和 Point A 中指定的一致
|
||||||
"inbound": {
|
"inbound": {
|
||||||
"protocol": "vmess", // 中继协议,不用改
|
"protocol": "vmess", // 中继协议,不用改
|
||||||
"file": "in_vmess.json" // vmess 配置文件
|
"settings": {
|
||||||
|
"clients": [
|
||||||
|
// 认可的用户 ID,必须包含 Point A 中的用户 ID
|
||||||
|
{"id": "ad937d9d-6e23-4a5a-ba23-bce5092a7c51"}
|
||||||
|
],
|
||||||
|
"udp": false // 如果要使用 UDP 转发,请改成 true
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"outbound": {
|
"outbound": {
|
||||||
"protocol": "freedom", // 出口协议,不用改
|
"protocol": "freedom", // 出口协议,不用改
|
||||||
"file": "" // 暂无配置
|
"settings": {} // 暂无配置
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
另外还需要 in_vmess.json:
|
|
||||||
```javascript
|
|
||||||
// in_vmess.json
|
|
||||||
{
|
|
||||||
"clients": [
|
|
||||||
{"id": "ad937d9d-6e23-4a5a-ba23-bce5092a7c51"} // 认可的用户 ID,必须包含 out_vmess.json 中的用户 ID
|
|
||||||
],
|
|
||||||
"udp": false // 如果要使用 UDP 转发,请改成 true
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 其它
|
### 其它
|
||||||
* V2Ray 的用户验证基于时间,请确保 A 和 B 所在机器的系统时间误差在一分钟以内。
|
* V2Ray 的用户验证基于时间,请确保 A 和 B 所在机器的系统时间误差在一分钟以内。
|
||||||
* json 配置文件实际上不支持注释(即“//”之后的部分,在使用时请务必删去)。
|
* json 配置文件实际上不支持注释(即“//”之后的部分,在使用时请务必删去)。
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
package mocks
|
package mocks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/v2ray/v2ray-core"
|
"github.com/v2ray/v2ray-core/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ConnectionConfig struct {
|
type ConnectionConfig struct {
|
||||||
ProtocolValue string
|
ProtocolValue string
|
||||||
ContentValue []byte
|
SettingsValue interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *ConnectionConfig) Protocol() string {
|
func (config *ConnectionConfig) Protocol() string {
|
||||||
return config.ProtocolValue
|
return config.ProtocolValue
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *ConnectionConfig) Content() []byte {
|
func (config *ConnectionConfig) Settings(config.Type) interface{} {
|
||||||
return config.ContentValue
|
return config.SettingsValue
|
||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
@ -27,10 +27,10 @@ func (config *Config) Port() uint16 {
|
||||||
return config.PortValue
|
return config.PortValue
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *Config) InboundConfig() core.ConnectionConfig {
|
func (config *Config) InboundConfig() config.ConnectionConfig {
|
||||||
return config.InboundConfigValue
|
return config.InboundConfigValue
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *Config) OutboundConfig() core.ConnectionConfig {
|
func (config *Config) OutboundConfig() config.ConnectionConfig {
|
||||||
return config.OutboundConfigValue
|
return config.OutboundConfigValue
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ func (handler *InboundConnectionHandler) Communicate(packet v2net.Packet) error
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *InboundConnectionHandler) Create(point *core.Point, config []byte) (core.InboundConnectionHandler, error) {
|
func (handler *InboundConnectionHandler) Create(point *core.Point, config interface{}) (core.InboundConnectionHandler, error) {
|
||||||
handler.Server = point
|
handler.Server = point
|
||||||
return handler, nil
|
return handler, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,11 +34,7 @@ func (handler *OutboundConnectionHandler) Start(ray core.OutboundRay) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *OutboundConnectionHandler) Initialize(config []byte) error {
|
func (handler *OutboundConnectionHandler) Create(point *core.Point, config interface{}, packet v2net.Packet) (core.OutboundConnectionHandler, error) {
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (handler *OutboundConnectionHandler) Create(point *core.Point, packet v2net.Packet) (core.OutboundConnectionHandler, error) {
|
|
||||||
handler.Destination = packet.Destination()
|
handler.Destination = packet.Destination()
|
||||||
if packet.Chunk() != nil {
|
if packet.Chunk() != nil {
|
||||||
handler.Data2Send.Write(packet.Chunk())
|
handler.Data2Send.Write(packet.Chunk())
|
||||||
|
|
|
@ -22,7 +22,10 @@ func NewSubject(assert *Assertion) *Subject {
|
||||||
// decorate prefixes the string with the file and line of the call site
|
// decorate prefixes the string with the file and line of the call site
|
||||||
// and inserts the final newline if needed and indentation tabs for formatting.
|
// and inserts the final newline if needed and indentation tabs for formatting.
|
||||||
func decorate(s string) string {
|
func decorate(s string) string {
|
||||||
_, file, line, ok := runtime.Caller(4) // decorate + log + public function.
|
_, file, line, ok := runtime.Caller(3)
|
||||||
|
if strings.Contains(file, "testing") {
|
||||||
|
_, file, line, ok = runtime.Caller(4)
|
||||||
|
}
|
||||||
if ok {
|
if ok {
|
||||||
// Truncate file name at last file name separator.
|
// Truncate file name at last file name separator.
|
||||||
if index := strings.LastIndex(file, "/"); index >= 0 {
|
if index := strings.LastIndex(file, "/"); index >= 0 {
|
||||||
|
|
Loading…
Reference in New Issue