mirror of
https://github.com/wyx2685/V2bX.git
synced 2026-02-04 04:30:08 +00:00
support xtls-rprx-vision, support reality
This commit is contained in:
@@ -14,7 +14,6 @@ import (
|
||||
|
||||
type Controller struct {
|
||||
server *core.Core
|
||||
clientInfo panel.ClientInfo
|
||||
apiClient *panel.Client
|
||||
nodeInfo *panel.NodeInfo
|
||||
Tag string
|
||||
@@ -40,7 +39,6 @@ func NewController(server *core.Core, api *panel.Client, config *conf.Controller
|
||||
|
||||
// Start implement the Start() function of the service interface
|
||||
func (c *Controller) Start() error {
|
||||
c.clientInfo = c.apiClient.Describe()
|
||||
// First fetch Node Info
|
||||
var err error
|
||||
c.nodeInfo, err = c.apiClient.GetNodeInfo()
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
package node_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Yuzuki616/V2bX/api/panel"
|
||||
"github.com/Yuzuki616/V2bX/conf"
|
||||
"github.com/Yuzuki616/V2bX/core"
|
||||
_ "github.com/Yuzuki616/V2bX/core/distro/all"
|
||||
. "github.com/Yuzuki616/V2bX/node"
|
||||
xCore "github.com/xtls/xray-core/core"
|
||||
coreConf "github.com/xtls/xray-core/infra/conf"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
"syscall"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestController(t *testing.T) {
|
||||
serverConfig := &coreConf.Config{
|
||||
Stats: &coreConf.StatsConfig{},
|
||||
LogConfig: &coreConf.LogConfig{LogLevel: "debug"},
|
||||
}
|
||||
policyConfig := &coreConf.PolicyConfig{}
|
||||
policyConfig.Levels = map[uint32]*coreConf.Policy{0: &coreConf.Policy{
|
||||
StatsUserUplink: true,
|
||||
StatsUserDownlink: true,
|
||||
}}
|
||||
serverConfig.Policy = policyConfig
|
||||
config, _ := serverConfig.Build()
|
||||
|
||||
// config := &core.Config{
|
||||
// App: []*serial.TypedMessage{
|
||||
// serial.ToTypedMessage(&dispatcher.Config{}),
|
||||
// serial.ToTypedMessage(&proxyman.InboundConfig{}),
|
||||
// serial.ToTypedMessage(&proxyman.OutboundConfig{}),
|
||||
// serial.ToTypedMessage(&stats.Config{}),
|
||||
// }}
|
||||
|
||||
server, err := xCore.New(config)
|
||||
defer server.Close()
|
||||
if err != nil {
|
||||
t.Errorf("failed to create instance: %s", err)
|
||||
}
|
||||
if err = server.Start(); err != nil {
|
||||
t.Errorf("Failed to start instance: %s", err)
|
||||
}
|
||||
certConfig := &conf.CertConfig{
|
||||
CertMode: "http",
|
||||
CertDomain: "test.ss.tk",
|
||||
Provider: "alidns",
|
||||
Email: "ss@ss.com",
|
||||
}
|
||||
controlerconfig := &conf.ControllerConfig{
|
||||
UpdatePeriodic: 5,
|
||||
CertConfig: certConfig,
|
||||
}
|
||||
apiConfig := &conf.ApiConfig{
|
||||
APIHost: "http://127.0.0.1:667",
|
||||
Key: "123",
|
||||
NodeID: 41,
|
||||
NodeType: "V2ray",
|
||||
}
|
||||
apiclient := panel.New(apiConfig)
|
||||
c := &core.Core{Server: server}
|
||||
c.Start()
|
||||
node := New(c, apiclient, controlerconfig)
|
||||
fmt.Println("Sleep 1s")
|
||||
err = node.Start()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
//Explicitly triggering GC to remove garbage from config loading.
|
||||
runtime.GC()
|
||||
{
|
||||
osSignals := make(chan os.Signal, 1)
|
||||
signal.Notify(osSignals, syscall.SIGINT, syscall.SIGKILL, syscall.SIGTERM)
|
||||
<-osSignals
|
||||
}
|
||||
}
|
||||
@@ -15,8 +15,8 @@ import (
|
||||
coreConf "github.com/xtls/xray-core/infra/conf"
|
||||
)
|
||||
|
||||
// buildInbound build Inbound config for different protocol
|
||||
func buildInbound(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag string) (*core.InboundHandlerConfig, error) {
|
||||
// BuildInbound build Inbound config for different protocol
|
||||
func BuildInbound(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag string) (*core.InboundHandlerConfig, error) {
|
||||
inbound := &coreConf.InboundDetourConfig{}
|
||||
// Set network protocol
|
||||
t := coreConf.TransportProtocol(nodeInfo.Network)
|
||||
@@ -65,17 +65,39 @@ func buildInbound(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag s
|
||||
AcceptProxyProtocol: config.EnableProxyProtocol} //Enable proxy protocol
|
||||
}
|
||||
// Set TLS and XTLS settings
|
||||
if nodeInfo.Tls != 0 && config.CertConfig.CertMode != "none" {
|
||||
inbound.StreamSetting.Security = "tls"
|
||||
certFile, keyFile, err := getCertFile(config.CertConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if nodeInfo.Tls != 0 {
|
||||
if config.CertConfig.CertMode != "none" {
|
||||
// Normal tls
|
||||
inbound.StreamSetting.Security = "tls"
|
||||
certFile, keyFile, err := getCertFile(config.CertConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
inbound.StreamSetting.TLSSettings = &coreConf.TLSConfig{
|
||||
Certs: []*coreConf.TLSCertConfig{
|
||||
{
|
||||
CertFile: certFile,
|
||||
KeyFile: keyFile,
|
||||
OcspStapling: 3600,
|
||||
},
|
||||
},
|
||||
RejectUnknownSNI: config.CertConfig.RejectUnknownSni,
|
||||
}
|
||||
}
|
||||
tlsSettings := &coreConf.TLSConfig{
|
||||
RejectUnknownSNI: config.CertConfig.RejectUnknownSni,
|
||||
|
||||
} else if config.EnableReality {
|
||||
// Reality
|
||||
inbound.StreamSetting.Security = "reality"
|
||||
inbound.StreamSetting.REALITYSettings = &coreConf.REALITYConfig{
|
||||
Dest: config.RealityConfig.Dest,
|
||||
Xver: config.RealityConfig.Xver,
|
||||
ServerNames: config.RealityConfig.ServerNames,
|
||||
PrivateKey: config.RealityConfig.PrivateKey,
|
||||
MinClientVer: config.RealityConfig.MinClientVer,
|
||||
MaxClientVer: config.RealityConfig.MaxClientVer,
|
||||
MaxTimeDiff: config.RealityConfig.MaxTimeDiff,
|
||||
ShortIds: config.RealityConfig.ShortIds,
|
||||
}
|
||||
tlsSettings.Certs = append(tlsSettings.Certs, &coreConf.TLSCertConfig{CertFile: certFile, KeyFile: keyFile, OcspStapling: 3600})
|
||||
inbound.StreamSetting.TLSSettings = tlsSettings
|
||||
}
|
||||
// Support ProxyProtocol for any transport protocol
|
||||
if *inbound.StreamSetting.Network != "tcp" &&
|
||||
@@ -128,6 +150,9 @@ func buildV2ray(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, inbound
|
||||
}
|
||||
inbound.Settings = (*json.RawMessage)(&s)
|
||||
}
|
||||
if len(nodeInfo.NetworkSettings) == 0 {
|
||||
return nil
|
||||
}
|
||||
switch nodeInfo.Network {
|
||||
case "tcp":
|
||||
err := json.Unmarshal(nodeInfo.NetworkSettings, &inbound.StreamSetting.TCPSettings)
|
||||
|
||||
@@ -2,97 +2,32 @@ package node_test
|
||||
|
||||
import (
|
||||
"github.com/Yuzuki616/V2bX/api/panel"
|
||||
"github.com/Yuzuki616/V2bX/conf"
|
||||
. "github.com/Yuzuki616/V2bX/node"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBuildV2ray(t *testing.T) {
|
||||
nodeInfo := &panel.NodeInfo{
|
||||
NodeType: "V2ray",
|
||||
NodeID: 1,
|
||||
Port: 1145,
|
||||
SpeedLimit: 0,
|
||||
AlterID: 2,
|
||||
TransportProtocol: "ws",
|
||||
Host: "test.test.tk",
|
||||
Path: "v2ray",
|
||||
EnableTLS: false,
|
||||
TLSType: "tls",
|
||||
NodeType: "v2ray",
|
||||
NodeId: 1,
|
||||
ServerPort: 1145,
|
||||
Network: "ws",
|
||||
NetworkSettings: nil,
|
||||
Host: "test.test.tk",
|
||||
ServerName: "test.test.tk",
|
||||
}
|
||||
certConfig := &CertConfig{
|
||||
CertMode: "http",
|
||||
certConfig := &conf.CertConfig{
|
||||
CertMode: "none",
|
||||
CertDomain: "test.test.tk",
|
||||
Provider: "alidns",
|
||||
Email: "test@gmail.com",
|
||||
}
|
||||
config := &Config{
|
||||
config := &conf.ControllerConfig{
|
||||
ListenIP: "0.0.0.0",
|
||||
CertConfig: certConfig,
|
||||
}
|
||||
_, err := buildInbound(config, nodeInfo)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildTrojan(t *testing.T) {
|
||||
nodeInfo := &panel.NodeInfo{
|
||||
NodeType: "Trojan",
|
||||
NodeID: 1,
|
||||
Port: 1145,
|
||||
SpeedLimit: 0,
|
||||
AlterID: 2,
|
||||
TransportProtocol: "tcp",
|
||||
Host: "trojan.test.tk",
|
||||
Path: "v2ray",
|
||||
EnableTLS: false,
|
||||
TLSType: "tls",
|
||||
}
|
||||
DNSEnv := make(map[string]string)
|
||||
DNSEnv["ALICLOUD_ACCESS_KEY"] = "aaa"
|
||||
DNSEnv["ALICLOUD_SECRET_KEY"] = "bbb"
|
||||
certConfig := &CertConfig{
|
||||
CertMode: "dns",
|
||||
CertDomain: "trojan.test.tk",
|
||||
Provider: "alidns",
|
||||
Email: "test@gmail.com",
|
||||
DNSEnv: DNSEnv,
|
||||
}
|
||||
config := &Config{
|
||||
CertConfig: certConfig,
|
||||
}
|
||||
_, err := buildInbound(config, nodeInfo)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildSS(t *testing.T) {
|
||||
nodeInfo := &panel.NodeInfo{
|
||||
NodeType: "Shadowsocks",
|
||||
NodeID: 1,
|
||||
Port: 1145,
|
||||
SpeedLimit: 0,
|
||||
AlterID: 2,
|
||||
TransportProtocol: "tcp",
|
||||
Host: "test.test.tk",
|
||||
Path: "v2ray",
|
||||
EnableTLS: false,
|
||||
TLSType: "tls",
|
||||
}
|
||||
DNSEnv := make(map[string]string)
|
||||
DNSEnv["ALICLOUD_ACCESS_KEY"] = "aaa"
|
||||
DNSEnv["ALICLOUD_SECRET_KEY"] = "bbb"
|
||||
certConfig := &CertConfig{
|
||||
CertMode: "dns",
|
||||
CertDomain: "trojan.test.tk",
|
||||
Provider: "alidns",
|
||||
Email: "test@me.com",
|
||||
DNSEnv: DNSEnv,
|
||||
}
|
||||
config := &Config{
|
||||
CertConfig: certConfig,
|
||||
}
|
||||
_, err := buildInbound(config, nodeInfo)
|
||||
_, err := BuildInbound(config, nodeInfo, "11")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ func (c *Controller) removeOldNode(oldTag string) (err error) {
|
||||
}
|
||||
|
||||
func (c *Controller) addNewNode(newNodeInfo *panel.NodeInfo) (err error) {
|
||||
inboundConfig, err := buildInbound(c.ControllerConfig, newNodeInfo, c.Tag)
|
||||
inboundConfig, err := BuildInbound(c.ControllerConfig, newNodeInfo, c.Tag)
|
||||
if err != nil {
|
||||
return fmt.Errorf("build inbound error: %s", err)
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const xtlsFLow = "xtls-rprx-vision"
|
||||
|
||||
func (c *Controller) addNewUser(userInfo []panel.UserInfo, nodeInfo *panel.NodeInfo) (err error) {
|
||||
users := make([]*protocol.User, 0, len(userInfo))
|
||||
switch nodeInfo.NodeType {
|
||||
@@ -70,8 +72,10 @@ func (c *Controller) buildVlessUsers(userInfo []panel.UserInfo) (users []*protoc
|
||||
|
||||
func (c *Controller) buildVlessUser(userInfo *panel.UserInfo) (user *protocol.User) {
|
||||
vlessAccount := &vless.Account{
|
||||
Id: userInfo.Uuid,
|
||||
Flow: "xtls-rprx-direct",
|
||||
Id: userInfo.Uuid,
|
||||
}
|
||||
if c.EnableXtls {
|
||||
vlessAccount.Flow = xtlsFLow
|
||||
}
|
||||
return &protocol.User{
|
||||
Level: 0,
|
||||
@@ -91,7 +95,6 @@ func (c *Controller) buildTrojanUsers(userInfo []panel.UserInfo) (users []*proto
|
||||
func (c *Controller) buildTrojanUser(userInfo *panel.UserInfo) (user *protocol.User) {
|
||||
trojanAccount := &trojan.Account{
|
||||
Password: userInfo.Uuid,
|
||||
Flow: "xtls-rprx-direct",
|
||||
}
|
||||
return &protocol.User{
|
||||
Level: 0,
|
||||
|
||||
Reference in New Issue
Block a user